-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMachineWithPLC.kt
136 lines (125 loc) · 3.84 KB
/
MachineWithPLC.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package sk.drevari.optitimb.repo.db.data
import android.content.Context
import androidx.room.Embedded
import androidx.room.Ignore
import androidx.room.Junction
import androidx.room.Relation
import sk.drevari.optitimb.OTApp
import sk.drevari.optitimb.R
import sk.drevari.optitimb.data.Dic
import sk.drevari.optitimb.data.OTSetting
import sk.drevari.optitimb.repo.db.entity.*
import java.text.DecimalFormat
/**
* Created by Sergii Volchenko on 25.02.2020.
* made in Ukraine
*/
data class MachineWithPLC(
@Embedded var machine: Machine,
@Relation(
parentColumn = "machineId",
entityColumn = "plcId",
associateBy = Junction(MachineAndPLC::class)
)
var plc: List<PLC>? = null
) {
@Ignore
private val diamFormat = DecimalFormat("#.#").apply {
maximumFractionDigits = 2
minimumIntegerDigits = 1
minimumFractionDigits = 0
}
private fun getValueWithUnitsLength(context: Context, value: Float) =
"${diamFormat.format(value)} ${context.getString(if (OTSetting.isSi) R.string.mm else R.string.inch)}"
private fun getValueWithUnitsLength(context: Context, value: Int) =
"$value ${context.getString(if (OTSetting.isSi) R.string.mm else R.string.inch)}"
fun convertToDic(app: OTApp): ArrayList<Dic<String, String>> {
val list = ArrayList<Dic<String, String>>()
/* list.add(
Dic(
app.getString(R.string.TYPE),
app.getString(machine.getTypeResourseId())
)
)*/
list.add(
Dic(
app.getString(R.string.MACHINE_PAR2),
getValueWithUnitsLength(app, machine.horizontalDiam ?: 0f)
)
)
list.add(
Dic(
app.getString(R.string.MACHINE_PAR3),
getValueWithUnitsLength(app, machine.horizontalKerf ?: 0f)
)
)
list.add(
Dic(
app.getString(R.string.MACHINE_PAR4),
getValueWithUnitsLength(app, machine.verticalDiam ?: 0f)
)
)
list.add(
Dic(
app.getString(R.string.MACHINE_PAR5),
getValueWithUnitsLength(app, machine.verticalKerf ?: 0f)
)
)
if (machine.horizontalCut != null) {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR9),
getValueWithUnitsLength(app, machine.horizontalCut!!)
)
)
}
machine.verticalCut?.let {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR8),
getValueWithUnitsLength(app, it)
)
)
}
machine.cutPlaneMax?.let {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR10),
getValueWithUnitsLength(app, it)
)
)
}
machine.cutPlaneMin?.let {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR11),
getValueWithUnitsLength(app, it)
)
)
}
machine.thickLastboard?.let {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR12),
getValueWithUnitsLength(app, it)
)
)
}
machine.logLifting?.let {
list.add(
Dic(
app.getString(R.string.MACHINE_PAR13),
getValueWithUnitsLength(app, it)
)
)
}
plc?.let {
it.forEach {plc ->
// list.add(Dic(null, null))
list.addAll(plc.paramsToDic(app))
}
}
return list
}
}