|
@@ -0,0 +1,216 @@
|
|
1
|
+package com.kfb.kfbv1;
|
|
2
|
+
|
|
3
|
+import android.content.Intent;
|
|
4
|
+import android.os.Bundle;
|
|
5
|
+import android.view.View;
|
|
6
|
+import android.widget.Button;
|
|
7
|
+import android.widget.ImageButton;
|
|
8
|
+import android.widget.Switch;
|
|
9
|
+import android.widget.TextView;
|
|
10
|
+
|
|
11
|
+import androidx.appcompat.app.AppCompatActivity;
|
|
12
|
+
|
|
13
|
+import com.kfb.kfbv1.db.DbManage;
|
|
14
|
+import com.kfb.kfbv1.db.Urzadzenia;
|
|
15
|
+import com.kfb.kfbv1.model.KfbModel;
|
|
16
|
+
|
|
17
|
+import java.util.List;
|
|
18
|
+
|
|
19
|
+public class ConfigActivity extends AppCompatActivity {
|
|
20
|
+ @Override
|
|
21
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
22
|
+ super.onCreate(savedInstanceState);
|
|
23
|
+ setContentView(R.layout.activity_config);
|
|
24
|
+
|
|
25
|
+ ImageButton btn = (ImageButton) findViewById(R.id.back);
|
|
26
|
+ btn.setOnClickListener(new View.OnClickListener() {
|
|
27
|
+
|
|
28
|
+ public void onClick(View v) {
|
|
29
|
+ onBack(v);
|
|
30
|
+ }
|
|
31
|
+ });
|
|
32
|
+ Button b1 = (Button)findViewById(R.id.idSave);
|
|
33
|
+ b1.setOnClickListener(new View.OnClickListener() {
|
|
34
|
+
|
|
35
|
+ public void onClick(View v) {
|
|
36
|
+ onSave(v);
|
|
37
|
+ }
|
|
38
|
+ });
|
|
39
|
+ TextView t1 = (TextView) findViewById(R.id.g1t);
|
|
40
|
+ t1.setText(KfbModel.getData().getGates().getmGate().get(0).getmAdres());
|
|
41
|
+ t1 = (TextView) findViewById(R.id.g2t);
|
|
42
|
+ t1.setText(KfbModel.getData().getGates().getmGate().get(1).getmAdres());
|
|
43
|
+ t1 = (TextView) findViewById(R.id.g3t);
|
|
44
|
+ t1.setText(KfbModel.getData().getGates().getmGate().get(2).getmAdres());
|
|
45
|
+ t1 = (TextView) findViewById(R.id.g4t);
|
|
46
|
+ t1.setText(KfbModel.getData().getGates().getmGate().get(3).getmAdres());
|
|
47
|
+ Switch s1 = (Switch) findViewById(R.id.g1s);
|
|
48
|
+ s1.setChecked(KfbModel.getData().getGates().getmGate().get(0).ismActive());
|
|
49
|
+ s1 = (Switch) findViewById(R.id.g2s);
|
|
50
|
+ s1.setChecked(KfbModel.getData().getGates().getmGate().get(1).ismActive());
|
|
51
|
+ s1 = (Switch) findViewById(R.id.g3s);
|
|
52
|
+ s1.setChecked(KfbModel.getData().getGates().getmGate().get(2).ismActive());
|
|
53
|
+ s1 = (Switch) findViewById(R.id.g4s);
|
|
54
|
+ s1.setChecked(KfbModel.getData().getGates().getmGate().get(3).ismActive());
|
|
55
|
+ DbManage dbRep = new DbManage(getApplicationContext());
|
|
56
|
+ Urzadzenia urzdb = dbRep.getUrzadzenie(4);
|
|
57
|
+ if(urzdb!=null) {
|
|
58
|
+ s1 = (Switch) findViewById(R.id.t1s);
|
|
59
|
+ s1.setChecked(urzdb.active);
|
|
60
|
+ t1 = (TextView) findViewById(R.id.t1t);
|
|
61
|
+ t1.setText(urzdb.adres);
|
|
62
|
+ }
|
|
63
|
+ urzdb = dbRep.getUrzadzenie(5);
|
|
64
|
+ if(urzdb!=null) {
|
|
65
|
+ s1 = (Switch) findViewById(R.id.t2s);
|
|
66
|
+ s1.setChecked(urzdb.active);
|
|
67
|
+ t1 = (TextView) findViewById(R.id.t2t);
|
|
68
|
+ t1.setText(urzdb.adres);
|
|
69
|
+ }
|
|
70
|
+ urzdb = dbRep.getUrzadzenie(6);
|
|
71
|
+ if(urzdb!=null) {
|
|
72
|
+ s1 = (Switch) findViewById(R.id.t3s);
|
|
73
|
+ s1.setChecked(urzdb.active);
|
|
74
|
+ t1 = (TextView) findViewById(R.id.t3t);
|
|
75
|
+ t1.setText(urzdb.adres);
|
|
76
|
+ }
|
|
77
|
+ urzdb = dbRep.getUrzadzenie(7);
|
|
78
|
+ if(urzdb!=null) {
|
|
79
|
+ s1 = (Switch) findViewById(R.id.t4s);
|
|
80
|
+ s1.setChecked(urzdb.active);
|
|
81
|
+ t1 = (TextView) findViewById(R.id.t4t);
|
|
82
|
+ t1.setText(urzdb.adres);
|
|
83
|
+ }
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ private void onBack(View v)
|
|
87
|
+ {
|
|
88
|
+ Intent intent = new Intent(this, GateActivity.class);
|
|
89
|
+ startActivityForResult(intent,1);
|
|
90
|
+ finish();
|
|
91
|
+ }
|
|
92
|
+ private void onSave(View v)
|
|
93
|
+ {
|
|
94
|
+ // aktualizuj baze
|
|
95
|
+ DbManage dbRep = new DbManage(getApplicationContext());
|
|
96
|
+ Urzadzenia urzdbe = new Urzadzenia();
|
|
97
|
+
|
|
98
|
+ TextView t1 = (TextView) findViewById(R.id.g1t);
|
|
99
|
+ String s = t1.getText().toString();
|
|
100
|
+ KfbModel.getData().getGates().getmGate().get(0).setmAdres(s);
|
|
101
|
+ Switch s1 = (Switch) findViewById(R.id.g1s);
|
|
102
|
+ KfbModel.getData().getGates().getmGate().get(0).setmActive(s1.isChecked());
|
|
103
|
+
|
|
104
|
+ urzdbe.active = s1.isChecked();
|
|
105
|
+ urzdbe.adres = t1.getText().toString();
|
|
106
|
+ urzdbe.ID = KfbModel.getData().getGates().getmGate().get(0).getId();
|
|
107
|
+ dbRep.updateUrzazenie(urzdbe);
|
|
108
|
+ urzdbe = new Urzadzenia();
|
|
109
|
+ t1 = (TextView) findViewById(R.id.g2t);
|
|
110
|
+ KfbModel.getData().getGates().getmGate().get(1).setmAdres( t1.getText().toString());
|
|
111
|
+ s1 = (Switch) findViewById(R.id.g2s);
|
|
112
|
+ KfbModel.getData().getGates().getmGate().get(1).setmActive(s1.isChecked());
|
|
113
|
+
|
|
114
|
+ urzdbe.active = s1.isChecked();
|
|
115
|
+ urzdbe.adres = t1.getText().toString();
|
|
116
|
+ urzdbe.ID = KfbModel.getData().getGates().getmGate().get(1).getId();
|
|
117
|
+ dbRep.updateUrzazenie(urzdbe);
|
|
118
|
+ urzdbe = new Urzadzenia();
|
|
119
|
+ t1 = (TextView) findViewById(R.id.g3t);
|
|
120
|
+ KfbModel.getData().getGates().getmGate().get(2).setmAdres(t1.getText().toString());
|
|
121
|
+ s1 = (Switch) findViewById(R.id.g3s);
|
|
122
|
+ KfbModel.getData().getGates().getmGate().get(2).setmActive(s1.isChecked());
|
|
123
|
+
|
|
124
|
+ urzdbe.active = s1.isChecked();
|
|
125
|
+ urzdbe.adres = t1.getText().toString();
|
|
126
|
+ urzdbe.ID = KfbModel.getData().getGates().getmGate().get(2).getId();
|
|
127
|
+ dbRep.updateUrzazenie(urzdbe);
|
|
128
|
+ urzdbe = new Urzadzenia();
|
|
129
|
+ t1 = (TextView) findViewById(R.id.g4t);
|
|
130
|
+ KfbModel.getData().getGates().getmGate().get(3).setmAdres( t1.getText().toString());
|
|
131
|
+ s1 = (Switch) findViewById(R.id.g4s);
|
|
132
|
+ KfbModel.getData().getGates().getmGate().get(3).setmActive(s1.isChecked());
|
|
133
|
+
|
|
134
|
+ urzdbe.active = s1.isChecked();
|
|
135
|
+ urzdbe.adres = t1.getText().toString();
|
|
136
|
+ urzdbe.ID = KfbModel.getData().getGates().getmGate().get(3).getId();
|
|
137
|
+ dbRep.updateUrzazenie(urzdbe);
|
|
138
|
+ t1 = (TextView) findViewById(R.id.t1t);
|
|
139
|
+ s1 = (Switch) findViewById(R.id.t1s);
|
|
140
|
+
|
|
141
|
+ Urzadzenia urzdb = dbRep.getUrzadzenie(4);
|
|
142
|
+ if(urzdb==null)
|
|
143
|
+ {
|
|
144
|
+ urzdb = new Urzadzenia();
|
|
145
|
+ urzdb.ID = 4;
|
|
146
|
+ urzdb.adres = t1.getText().toString();
|
|
147
|
+ urzdb.active = s1.isChecked();
|
|
148
|
+ dbRep.insertUrzazenie(urzdb);
|
|
149
|
+ }
|
|
150
|
+ else
|
|
151
|
+ {
|
|
152
|
+ urzdb.ID = 4;
|
|
153
|
+ urzdb.adres = t1.getText().toString();
|
|
154
|
+ urzdb.active = s1.isChecked();
|
|
155
|
+ dbRep.updateUrzazenie(urzdb);
|
|
156
|
+ }
|
|
157
|
+ t1 = (TextView) findViewById(R.id.t2t);
|
|
158
|
+ s1 = (Switch) findViewById(R.id.t2s);
|
|
159
|
+
|
|
160
|
+ urzdb = dbRep.getUrzadzenie(5);
|
|
161
|
+ if(urzdb==null)
|
|
162
|
+ {
|
|
163
|
+ urzdb = new Urzadzenia();
|
|
164
|
+ urzdb.ID = 5;
|
|
165
|
+ urzdb.adres = t1.getText().toString();
|
|
166
|
+ urzdb.active = s1.isChecked();
|
|
167
|
+ dbRep.insertUrzazenie(urzdb);
|
|
168
|
+ }
|
|
169
|
+ else
|
|
170
|
+ {
|
|
171
|
+ urzdb.ID = 5;
|
|
172
|
+ urzdb.adres = t1.getText().toString();
|
|
173
|
+ urzdb.active = s1.isChecked();
|
|
174
|
+ dbRep.updateUrzazenie(urzdb);
|
|
175
|
+ }
|
|
176
|
+ t1 = (TextView) findViewById(R.id.t3t);
|
|
177
|
+ s1 = (Switch) findViewById(R.id.t3s);
|
|
178
|
+
|
|
179
|
+ urzdb = dbRep.getUrzadzenie(6);
|
|
180
|
+ if(urzdb==null)
|
|
181
|
+ {
|
|
182
|
+ urzdb = new Urzadzenia();
|
|
183
|
+ urzdb.ID = 6;
|
|
184
|
+ urzdb.adres = t1.getText().toString();
|
|
185
|
+ urzdb.active = s1.isChecked();
|
|
186
|
+ dbRep.insertUrzazenie(urzdb);
|
|
187
|
+ }
|
|
188
|
+ else
|
|
189
|
+ {
|
|
190
|
+ urzdb.ID = 6;
|
|
191
|
+ urzdb.adres = t1.getText().toString();
|
|
192
|
+ urzdb.active = s1.isChecked();
|
|
193
|
+ dbRep.updateUrzazenie(urzdb);
|
|
194
|
+ }
|
|
195
|
+ t1 = (TextView) findViewById(R.id.t4t);
|
|
196
|
+ s1 = (Switch) findViewById(R.id.t4s);
|
|
197
|
+
|
|
198
|
+ urzdb = dbRep.getUrzadzenie(7);
|
|
199
|
+ if(urzdb==null)
|
|
200
|
+ {
|
|
201
|
+ urzdb = new Urzadzenia();
|
|
202
|
+ urzdb.ID = 7;
|
|
203
|
+ urzdb.adres = t1.getText().toString();
|
|
204
|
+ urzdb.active = s1.isChecked();
|
|
205
|
+ dbRep.insertUrzazenie(urzdb);
|
|
206
|
+ }
|
|
207
|
+ else
|
|
208
|
+ {
|
|
209
|
+ urzdb.ID = 7;
|
|
210
|
+ urzdb.adres = t1.getText().toString();
|
|
211
|
+ urzdb.active = s1.isChecked();
|
|
212
|
+ dbRep.updateUrzazenie(urzdb);
|
|
213
|
+ }
|
|
214
|
+ this.onBack(v);
|
|
215
|
+ }
|
|
216
|
+}
|