|
@@ -24,29 +24,23 @@ import com.fusi24.rfid.SplashScreenActivity;
|
24
|
24
|
import com.fusi24.rfid.adapter.StatusScanAdapter;
|
25
|
25
|
import com.fusi24.rfid.base.BaseActivity;
|
26
|
26
|
import com.fusi24.rfid.config.Constant;
|
27
|
|
-import com.fusi24.rfid.data.api.RestService;
|
28
|
|
-import com.fusi24.rfid.data.api.RestServiceFactory;
|
29
|
27
|
import com.fusi24.rfid.data.entity.DataDetail;
|
30
|
28
|
import com.fusi24.rfid.data.entity.DataEntryPermit;
|
31
|
29
|
import com.fusi24.rfid.databinding.ActivityHomeBinding;
|
32
|
30
|
import com.fusi24.rfid.ui.ScanActivity;
|
33
|
31
|
|
34
|
|
-import org.jetbrains.annotations.NotNull;
|
35
|
|
-
|
36
|
32
|
import java.util.ArrayList;
|
37
|
33
|
import java.util.List;
|
38
|
34
|
|
39
|
|
-import retrofit2.Call;
|
40
|
|
-import retrofit2.Callback;
|
41
|
|
-import retrofit2.Response;
|
42
|
35
|
import timber.log.Timber;
|
43
|
36
|
|
44
|
|
-public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnItemSelected {
|
|
37
|
+public class HomeActivity extends BaseActivity implements HomeView, StatusScanAdapter.OnItemSelected {
|
45
|
38
|
|
46
|
39
|
private DataEntryPermit dataEntryPermit;
|
47
|
40
|
private List<DataEntryPermit> entryPermitList;
|
48
|
41
|
private List<DataDetail> statusScanList;
|
49
|
42
|
private ActivityHomeBinding binding;
|
|
43
|
+ private HomePresenter presenter;
|
50
|
44
|
private StatusScanAdapter adapter;
|
51
|
45
|
private Integer idCheckType = null;
|
52
|
46
|
private String idDevice, checkTypeName;
|
|
@@ -70,10 +64,11 @@ public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnIt
|
70
|
64
|
getSupportActionBar().setDisplayShowTitleEnabled(false);
|
71
|
65
|
}
|
72
|
66
|
|
|
67
|
+ presenter = new HomePresenter(getManager(), getAndroidScheduler(), getProcessScheduler());
|
|
68
|
+ presenter.attachView(this);
|
|
69
|
+
|
73
|
70
|
initView();
|
74
|
71
|
loadingData();
|
75
|
|
- getDataPermit();
|
76
|
|
- getDataStatusScan();
|
77
|
72
|
}
|
78
|
73
|
|
79
|
74
|
@Override
|
|
@@ -129,6 +124,9 @@ public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnIt
|
129
|
124
|
//TODO STILL HARDCODE
|
130
|
125
|
binding.tvGateName.setText("Suzuran");
|
131
|
126
|
binding.tvSiteName.setText("BMO 1");
|
|
127
|
+
|
|
128
|
+ presenter.getEntryPermit();
|
|
129
|
+ presenter.getStatusScan();
|
132
|
130
|
}
|
133
|
131
|
|
134
|
132
|
private void initEvent(){
|
|
@@ -167,45 +165,23 @@ public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnIt
|
167
|
165
|
|
168
|
166
|
}
|
169
|
167
|
|
170
|
|
- private void getDataPermit() {
|
171
|
|
- RestService restService = RestServiceFactory.create(Constant.JWT_TOKEN);
|
172
|
|
- Call<List<DataEntryPermit>> call = restService.getEntryPermit();
|
173
|
|
- call.enqueue(new Callback<List<DataEntryPermit>>() {
|
174
|
|
- @Override
|
175
|
|
- public void onResponse(@NotNull Call<List<DataEntryPermit>> call, @NotNull Response<List<DataEntryPermit>> response) {
|
176
|
|
- if (response.body() != null) {
|
177
|
|
- entryPermitList.addAll(response.body());
|
178
|
|
- setDataPermit();
|
179
|
|
- }
|
180
|
|
- }
|
181
|
|
-
|
182
|
|
- @Override
|
183
|
|
- public void onFailure(@NotNull Call<List<DataEntryPermit>> call, @NotNull Throwable t) {
|
184
|
|
- Toast.makeText(HomeActivity.this, "Failed to get data permit", Toast.LENGTH_SHORT).show();
|
185
|
|
- Timber.i("DEVELOPER : %s", t.getMessage());
|
186
|
|
- }
|
187
|
|
- });
|
|
168
|
+ @Override
|
|
169
|
+ public void onSelected(DataDetail detail) {
|
|
170
|
+ idCheckType = detail.getId();
|
|
171
|
+ checkTypeName = detail.getName();
|
188
|
172
|
}
|
189
|
173
|
|
190
|
|
- private void getDataStatusScan(){
|
191
|
|
- RestService restService = RestServiceFactory.create(Constant.JWT_TOKEN);
|
192
|
|
- Call<List<DataDetail>> call = restService.getLookUp("BeSCAN_CHECK_TYPE");
|
193
|
|
- call.enqueue(new Callback<List<DataDetail>>() {
|
194
|
|
- @Override
|
195
|
|
- public void onResponse(@NotNull Call<List<DataDetail>> call, @NotNull Response<List<DataDetail>> response) {
|
196
|
|
- if (response.body() != null){
|
197
|
|
- statusScanList.addAll(response.body());
|
198
|
|
- adapter.updateDetailList(statusScanList);
|
199
|
|
- adapter.notifyDataSetChanged();
|
200
|
|
- }
|
201
|
|
- }
|
|
174
|
+ @Override
|
|
175
|
+ public void showDataPermit(List<DataEntryPermit> dataEntryPermitList) {
|
|
176
|
+ entryPermitList.addAll(dataEntryPermitList);
|
|
177
|
+ setDataPermit();
|
|
178
|
+ }
|
202
|
179
|
|
203
|
|
- @Override
|
204
|
|
- public void onFailure(@NotNull Call<List<DataDetail>> call, @NotNull Throwable t) {
|
205
|
|
- Toast.makeText(HomeActivity.this, "Failed to get data status Scan", Toast.LENGTH_SHORT).show();
|
206
|
|
- Timber.i("DEVELOPER : %s", t.getMessage());
|
207
|
|
- }
|
208
|
|
- });
|
|
180
|
+ @Override
|
|
181
|
+ public void showDataStatusScan(List<DataDetail> dataStatusScanList) {
|
|
182
|
+ statusScanList.addAll(dataStatusScanList);
|
|
183
|
+ adapter.updateDetailList(statusScanList);
|
|
184
|
+ adapter.notifyDataSetChanged();
|
209
|
185
|
}
|
210
|
186
|
|
211
|
187
|
private void setDataPermit(){
|
|
@@ -214,14 +190,15 @@ public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnIt
|
214
|
190
|
}
|
215
|
191
|
|
216
|
192
|
@Override
|
217
|
|
- protected void onDestroy() {
|
218
|
|
- super.onDestroy();
|
219
|
|
- binding = null;
|
|
193
|
+ public void showError(Throwable e) {
|
|
194
|
+ Toast.makeText(HomeActivity.this, "Failed get data", Toast.LENGTH_SHORT).show();
|
|
195
|
+ Timber.i("DEVELOPER : %s", e.getMessage());
|
220
|
196
|
}
|
221
|
197
|
|
222
|
198
|
@Override
|
223
|
|
- public void onSelected(DataDetail detail) {
|
224
|
|
- idCheckType = detail.getId();
|
225
|
|
- checkTypeName = detail.getName();
|
|
199
|
+ protected void onDestroy() {
|
|
200
|
+ super.onDestroy();
|
|
201
|
+ presenter.detachView();
|
|
202
|
+ binding = null;
|
226
|
203
|
}
|
227
|
204
|
}
|