|
@@ -2,21 +2,33 @@ package com.fusi24.rfid;
|
2
|
2
|
|
3
|
3
|
import android.content.Intent;
|
4
|
4
|
import android.os.Bundle;
|
|
5
|
+import android.view.View;
|
|
6
|
+import android.widget.AdapterView;
|
5
|
7
|
import android.widget.ArrayAdapter;
|
6
|
8
|
import android.widget.Button;
|
7
|
9
|
import android.widget.Spinner;
|
8
|
|
-
|
9
|
|
-import androidx.appcompat.app.AppCompatActivity;
|
10
|
|
-
|
11
|
|
-import com.fusi24.rfid.data.model.DataCommon;
|
|
10
|
+import android.widget.Toast;
|
|
11
|
+
|
|
12
|
+import com.fusi24.rfid.base.BaseActivity;
|
|
13
|
+import com.fusi24.rfid.config.Constant;
|
|
14
|
+import com.fusi24.rfid.data.api.RestService;
|
|
15
|
+import com.fusi24.rfid.data.api.RestServiceFactory;
|
|
16
|
+import com.fusi24.rfid.data.entity.DataEntryPermit;
|
|
17
|
+import com.fusi24.rfid.data.entity.DataSite;
|
12
|
18
|
import com.fusi24.rfid.ui.ScanActivity;
|
13
|
19
|
|
|
20
|
+import org.jetbrains.annotations.NotNull;
|
|
21
|
+
|
14
|
22
|
import java.util.ArrayList;
|
|
23
|
+import java.util.List;
|
15
|
24
|
|
16
|
25
|
import butterknife.BindView;
|
17
|
26
|
import butterknife.ButterKnife;
|
|
27
|
+import retrofit2.Call;
|
|
28
|
+import retrofit2.Callback;
|
|
29
|
+import retrofit2.Response;
|
18
|
30
|
|
19
|
|
-public class MainActivity extends AppCompatActivity {
|
|
31
|
+public class MainActivity extends BaseActivity {
|
20
|
32
|
|
21
|
33
|
@BindView(R.id.btn_scan)
|
22
|
34
|
Button btnScan;
|
|
@@ -25,50 +37,114 @@ public class MainActivity extends AppCompatActivity {
|
25
|
37
|
@BindView(R.id.spinner_permit)
|
26
|
38
|
Spinner spinnerPermit;
|
27
|
39
|
|
|
40
|
+ private DataSite dataSite;
|
|
41
|
+ private DataEntryPermit dataEntryPermit;
|
|
42
|
+ private List<DataSite> siteList;
|
|
43
|
+ private List<DataEntryPermit> entryPermitList;
|
|
44
|
+
|
28
|
45
|
@Override
|
29
|
46
|
protected void onCreate(Bundle savedInstanceState) {
|
30
|
47
|
super.onCreate(savedInstanceState);
|
31
|
48
|
setContentView(R.layout.activity_main);
|
32
|
49
|
ButterKnife.bind(this);
|
33
|
50
|
|
34
|
|
- setDataSite();
|
35
|
|
- setDataPermit();
|
|
51
|
+ dataSite = new DataSite();
|
|
52
|
+ dataEntryPermit = new DataEntryPermit();
|
36
|
53
|
|
|
54
|
+ siteList = new ArrayList<>();
|
|
55
|
+ entryPermitList = new ArrayList<>();
|
|
56
|
+
|
|
57
|
+ getDataSite();
|
|
58
|
+ getDataPermit();
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ @Override
|
|
62
|
+ protected void onResume() {
|
|
63
|
+ super.onResume();
|
37
|
64
|
initEvent();
|
|
65
|
+
|
38
|
66
|
}
|
39
|
67
|
|
40
|
|
- private void initEvent(){
|
41
|
|
- btnScan.setOnClickListener(v -> {
|
42
|
|
- Intent intent = new Intent(this, ScanActivity.class);
|
43
|
|
- startActivity(intent);
|
|
68
|
+ private void getDataSite() {
|
|
69
|
+ RestService restService = RestServiceFactory.create(Constant.JWT_TOKEN);
|
|
70
|
+ Call<List<DataSite>> call = restService.getDataSite(100);
|
|
71
|
+ call.enqueue(new Callback<List<DataSite>>() {
|
|
72
|
+ @Override
|
|
73
|
+ public void onResponse(@NotNull Call<List<DataSite>> call, @NotNull Response<List<DataSite>> response) {
|
|
74
|
+ if (response.body() != null){
|
|
75
|
+ siteList.addAll(response.body());
|
|
76
|
+ setDataSite();
|
|
77
|
+ }
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Override
|
|
81
|
+ public void onFailure(@NotNull Call<List<DataSite>> call, @NotNull Throwable t) {
|
|
82
|
+ Toast.makeText(MainActivity.this, "Failed to get data site", Toast.LENGTH_SHORT).show();
|
|
83
|
+ }
|
|
84
|
+ });
|
|
85
|
+ }
|
|
86
|
+
|
|
87
|
+ private void getDataPermit() {
|
|
88
|
+ RestService restService = RestServiceFactory.create(Constant.JWT_TOKEN);
|
|
89
|
+ Call<List<DataEntryPermit>> call = restService.getEntryPermit();
|
|
90
|
+ call.enqueue(new Callback<List<DataEntryPermit>>() {
|
|
91
|
+ @Override
|
|
92
|
+ public void onResponse(@NotNull Call<List<DataEntryPermit>> call, @NotNull Response<List<DataEntryPermit>> response) {
|
|
93
|
+ if (response.body() != null) {
|
|
94
|
+ entryPermitList.addAll(response.body());
|
|
95
|
+ setDataPermit();
|
|
96
|
+ }
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ @Override
|
|
100
|
+ public void onFailure(@NotNull Call<List<DataEntryPermit>> call, @NotNull Throwable t) {
|
|
101
|
+ Toast.makeText(MainActivity.this, "Failed to get data permit", Toast.LENGTH_SHORT).show();
|
|
102
|
+ }
|
44
|
103
|
});
|
45
|
104
|
}
|
46
|
105
|
|
47
|
106
|
private void setDataSite(){
|
48
|
|
- ArrayList<DataCommon> siteList = new ArrayList<>();
|
49
|
|
-
|
50
|
|
- siteList.add(new DataCommon(111, "HO"));
|
51
|
|
- siteList.add(new DataCommon(112, "BMO 1"));
|
52
|
|
- siteList.add(new DataCommon(113, "BMO 2"));
|
53
|
|
- siteList.add(new DataCommon(114, "LMO"));
|
54
|
|
- siteList.add(new DataCommon(115, "SMO"));
|
55
|
|
- siteList.add(new DataCommon(116, "MARINE"));
|
56
|
|
- siteList.add(new DataCommon(117, "EKSPLORASI"));
|
57
|
|
- siteList.add(new DataCommon(118, "JAKARTA"));
|
58
|
|
-
|
59
|
|
- ArrayAdapter<DataCommon> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, siteList);
|
|
107
|
+ ArrayAdapter<DataSite> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, siteList);
|
60
|
108
|
spinnerSite.setAdapter(adapter);
|
61
|
109
|
}
|
62
|
110
|
|
63
|
111
|
private void setDataPermit(){
|
64
|
|
- ArrayList<DataCommon> permitList = new ArrayList<>();
|
|
112
|
+ ArrayAdapter<DataEntryPermit> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, entryPermitList);
|
|
113
|
+ spinnerPermit.setAdapter(adapter);
|
|
114
|
+ }
|
|
115
|
+
|
|
116
|
+ private void initEvent(){
|
65
|
117
|
|
66
|
|
- permitList.add(new DataCommon(1, "ID CARD"));
|
67
|
|
- permitList.add(new DataCommon(2, "VISITOR"));
|
68
|
|
- permitList.add(new DataCommon(3, "MAGANG"));
|
|
118
|
+ spinnerSite.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
119
|
+ @Override
|
|
120
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
121
|
+ dataSite = (DataSite) parent.getItemAtPosition(position);
|
|
122
|
+ }
|
69
|
123
|
|
70
|
|
- ArrayAdapter<DataCommon> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, permitList);
|
71
|
|
- spinnerPermit.setAdapter(adapter);
|
|
124
|
+ @Override
|
|
125
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
126
|
+ dataSite = (DataSite) parent.getSelectedItem();
|
|
127
|
+ }
|
|
128
|
+ });
|
|
129
|
+
|
|
130
|
+ spinnerPermit.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
|
131
|
+ @Override
|
|
132
|
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
|
133
|
+ dataEntryPermit = (DataEntryPermit) parent.getItemAtPosition(position);
|
|
134
|
+ }
|
|
135
|
+
|
|
136
|
+ @Override
|
|
137
|
+ public void onNothingSelected(AdapterView<?> parent) {
|
|
138
|
+ dataEntryPermit = (DataEntryPermit) parent.getSelectedItem();
|
|
139
|
+ }
|
|
140
|
+ });
|
|
141
|
+
|
|
142
|
+ btnScan.setOnClickListener(v -> {
|
|
143
|
+ Intent intent = new Intent(this, ScanActivity.class);
|
|
144
|
+ intent.putExtra(ScanActivity.ID_SITE, String.valueOf(dataSite.getId()));
|
|
145
|
+ intent.putExtra(ScanActivity.ID_PERMIT, String.valueOf(dataEntryPermit.getId()));
|
|
146
|
+ startActivity(intent);
|
|
147
|
+ });
|
72
|
148
|
}
|
73
|
149
|
|
74
|
150
|
}
|