Parcourir la source

-Dynamic site
-Dynamic permit
-Fixing margin after scan

ilhamitubagoes il y a 4 ans
Parent
commit
6fc8b3badd

+ 105 - 29
app/src/main/java/com/fusi24/rfid/MainActivity.java

@@ -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
 }

+ 1 - 1
app/src/main/java/com/fusi24/rfid/adapter/ScanResultAdapter.java

@@ -10,7 +10,7 @@ import androidx.annotation.NonNull;
10 10
 import androidx.recyclerview.widget.RecyclerView;
11 11
 
12 12
 import com.fusi24.rfid.R;
13
-import com.fusi24.rfid.data.model.DataProblems;
13
+import com.fusi24.rfid.data.entity.DataProblems;
14 14
 import com.fusi24.rfid.util.DateHelper;
15 15
 
16 16
 import java.util.ArrayList;

+ 3 - 3
app/src/main/java/com/fusi24/rfid/data/DataManager.java

@@ -1,7 +1,7 @@
1 1
 package com.fusi24.rfid.data;
2 2
 
3 3
 import com.fusi24.rfid.data.api.RestService;
4
-import com.fusi24.rfid.data.model.DataResultRfid;
4
+import com.fusi24.rfid.data.entity.DataResultRfid;
5 5
 
6 6
 import io.reactivex.Observable;
7 7
 
@@ -13,8 +13,8 @@ public class DataManager {
13 13
         this.restService = restService;
14 14
     }
15 15
 
16
-    public Observable<DataResultRfid> checkRfidCard(String numberRfid, Integer permitId, String[] expand) {
17
-        return restService.checkRfidCard(numberRfid, permitId, expand);
16
+    public Observable<DataResultRfid> checkRfidCard(String numberRfid, Integer permitId, Integer siteId, String[] expand) {
17
+        return restService.checkRfidCard(numberRfid, permitId, siteId, expand);
18 18
     }
19 19
 
20 20
 }

+ 13 - 1
app/src/main/java/com/fusi24/rfid/data/api/RestService.java

@@ -1,17 +1,29 @@
1 1
 package com.fusi24.rfid.data.api;
2 2
 
3 3
 import com.fusi24.rfid.config.Constant;
4
-import com.fusi24.rfid.data.model.DataResultRfid;
4
+import com.fusi24.rfid.data.entity.DataEntryPermit;
5
+import com.fusi24.rfid.data.entity.DataResultRfid;
6
+import com.fusi24.rfid.data.entity.DataSite;
7
+
8
+import java.util.List;
5 9
 
6 10
 import io.reactivex.Observable;
11
+import retrofit2.Call;
7 12
 import retrofit2.http.GET;
8 13
 import retrofit2.http.Path;
9 14
 import retrofit2.http.Query;
10 15
 
11 16
 public interface RestService {
12 17
 
18
+    @GET(Constant.BEATS2_ENDPOINT + "/api/location")
19
+    Call<List<DataSite>> getDataSite(@Query("filter[type.id]") Integer typeId);
20
+
21
+    @GET(Constant.SID2_ENDPOINT + "/api/entryPermit")
22
+    Call<List<DataEntryPermit>> getEntryPermit();
23
+
13 24
     @GET(Constant.SID2_ENDPOINT + Constant.RFID_ENDPOINT + "/permit/check/{number_rfid}")
14 25
     Observable<DataResultRfid> checkRfidCard(@Path("number_rfid") String numberRfid,
26
+                                             @Query("siteId") Integer siteId,
15 27
                                              @Query("entryPermitId") Integer permitId,
16 28
                                              @Query("expand") String[] expand);
17 29
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataCommon.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 import org.jetbrains.annotations.NotNull;
4 4
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataCompany.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 public class DataCompany {
4 4
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataDocumentType.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 public class DataDocumentType {
4 4
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataEmployee.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 public class DataEmployee {
4 4
 

+ 49 - 0
app/src/main/java/com/fusi24/rfid/data/entity/DataEntryPermit.java

@@ -0,0 +1,49 @@
1
+package com.fusi24.rfid.data.entity;
2
+
3
+import org.jetbrains.annotations.NotNull;
4
+
5
+public class DataEntryPermit {
6
+
7
+    private Integer id;
8
+    private String name;
9
+    private String description;
10
+    private Boolean isActive;
11
+
12
+    public Integer getId() {
13
+        return id;
14
+    }
15
+
16
+    public void setId(Integer id) {
17
+        this.id = id;
18
+    }
19
+
20
+    public String getName() {
21
+        return name;
22
+    }
23
+
24
+    public void setName(String name) {
25
+        this.name = name;
26
+    }
27
+
28
+    public String getDescription() {
29
+        return description;
30
+    }
31
+
32
+    public void setDescription(String description) {
33
+        this.description = description;
34
+    }
35
+
36
+    public Boolean getActive() {
37
+        return isActive;
38
+    }
39
+
40
+    public void setActive(Boolean active) {
41
+        isActive = active;
42
+    }
43
+
44
+    @NotNull
45
+    @Override
46
+    public String toString() {
47
+        return getName();
48
+    }
49
+}

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataFunctionalPosition.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 public class DataFunctionalPosition {
4 4
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataProblems.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 import java.io.Serializable;
4 4
 

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataResultRfid.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 import java.util.List;
4 4
 

+ 49 - 0
app/src/main/java/com/fusi24/rfid/data/entity/DataSite.java

@@ -0,0 +1,49 @@
1
+package com.fusi24.rfid.data.entity;
2
+
3
+import org.jetbrains.annotations.NotNull;
4
+
5
+public class DataSite {
6
+
7
+    private Integer id;
8
+    private String name;
9
+    private String shortName;
10
+    private Boolean isActive;
11
+
12
+    public Integer getId() {
13
+        return id;
14
+    }
15
+
16
+    public void setId(Integer id) {
17
+        this.id = id;
18
+    }
19
+
20
+    public String getName() {
21
+        return name;
22
+    }
23
+
24
+    public void setName(String name) {
25
+        this.name = name;
26
+    }
27
+
28
+    public String getShortName() {
29
+        return shortName;
30
+    }
31
+
32
+    public void setShortName(String shortName) {
33
+        this.shortName = shortName;
34
+    }
35
+
36
+    public Boolean getActive() {
37
+        return isActive;
38
+    }
39
+
40
+    public void setActive(Boolean active) {
41
+        isActive = active;
42
+    }
43
+
44
+    @NotNull
45
+    @Override
46
+    public String toString() {
47
+        return getName();
48
+    }
49
+}

+ 1 - 1
app/src/main/java/com/fusi24/rfid/data/model/DataStructuralPosition.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid.data.model;
1
+package com.fusi24.rfid.data.entity;
2 2
 
3 3
 public class DataStructuralPosition {
4 4
 

+ 17 - 1
app/src/main/java/com/fusi24/rfid/ui/ScanActivity.java

@@ -15,17 +15,31 @@ import timber.log.Timber;
15 15
 
16 16
 public class ScanActivity extends LFScanProcessing {
17 17
 
18
+    public static final String ID_SITE = "id_site";
19
+    public static final String ID_PERMIT = "id_permit";
20
+
18 21
     @BindView(R.id.toggle_scan)
19 22
     ToggleButton toggleScan;
20 23
 
24
+    private String idSite;
25
+    private String idPermit;
26
+
21 27
     @Override
22 28
     protected void onCreate(Bundle savedInstanceState) {
23 29
         super.onCreate(savedInstanceState);
24 30
         setContentView(R.layout.activity_scan);
25 31
         ButterKnife.bind(this);
32
+        initView();
26 33
         initSound();
27 34
     }
28 35
 
36
+    private void initView() {
37
+        if (getIntent().getExtras() != null){
38
+            idSite = getIntent().getExtras().getString(ID_SITE);
39
+            idPermit = getIntent().getExtras().getString(ID_PERMIT);
40
+        }
41
+    }
42
+
29 43
     @OnCheckedChanged(R.id.toggle_scan)
30 44
     public void statusScanner(){
31 45
         if(toggleScan.isChecked()){
@@ -36,7 +50,9 @@ public class ScanActivity extends LFScanProcessing {
36 50
 
37 51
     void startInstance(String reception){
38 52
         Intent intent = new Intent(this, ScanResultActivity.class);
39
-        intent.putExtra("reception", reception); //Optional parameters
53
+        intent.putExtra(ScanResultActivity.ID_SITE, idSite);
54
+        intent.putExtra(ScanResultActivity.ID_PERMIT, idPermit);
55
+        intent.putExtra(ScanResultActivity.RFID_CARD_NUMBER, reception);
40 56
         startActivityForResult(intent, 1);
41 57
     }
42 58
 

+ 13 - 7
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultActivity.java

@@ -19,8 +19,8 @@ import com.fusi24.rfid.R;
19 19
 import com.fusi24.rfid.adapter.ScanResultAdapter;
20 20
 import com.fusi24.rfid.base.BaseActivity;
21 21
 import com.fusi24.rfid.config.Constant;
22
-import com.fusi24.rfid.data.model.DataProblems;
23
-import com.fusi24.rfid.data.model.DataResultRfid;
22
+import com.fusi24.rfid.data.entity.DataProblems;
23
+import com.fusi24.rfid.data.entity.DataResultRfid;
24 24
 
25 25
 import java.util.ArrayList;
26 26
 import java.util.List;
@@ -31,6 +31,10 @@ import de.hdodenhof.circleimageview.CircleImageView;
31 31
 
32 32
 public class ScanResultActivity extends BaseActivity implements ScanResultView {
33 33
 
34
+    public static final String ID_SITE = "id_site";
35
+    public static final String ID_PERMIT = "id_permit";
36
+    public static final String RFID_CARD_NUMBER = "rfid_card_number";
37
+
34 38
     @BindView(R.id.tv_rfid_number)
35 39
     TextView tvRfidNumber;
36 40
 
@@ -61,6 +65,8 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
61 65
     private ScanResultPresenter presenter;
62 66
     private ScanResultAdapter adapter;
63 67
     private List<DataProblems> problemsList;
68
+    private String idSite;
69
+    private String idPermit;
64 70
     private String numberRfid;
65 71
 
66 72
     @Override
@@ -74,7 +80,9 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
74 80
         presenter.attachView(this);
75 81
 
76 82
         if (getIntent() != null){
77
-            numberRfid = "000" + getIntent().getStringExtra("reception");
83
+            idSite = getIntent().getStringExtra(ID_SITE);
84
+            idPermit = getIntent().getStringExtra(ID_PERMIT);
85
+            numberRfid = "000" + getIntent().getStringExtra(RFID_CARD_NUMBER);
78 86
         }
79 87
 
80 88
         initView();
@@ -99,7 +107,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
99 107
     private void loadingdata(){
100 108
         problemsList.clear();
101 109
         String[] expand = {"employee.company, employee.structuralPosition, employee.functionalPosition"};
102
-        presenter.checkRfidCard(numberRfid, 1, expand);
110
+        presenter.checkRfidCard(numberRfid, Integer.valueOf(idPermit), Integer.valueOf(idSite), expand);
103 111
     }
104 112
 
105 113
     private void initEvent(){
@@ -109,9 +117,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
109 117
             startActivity(intent);
110 118
         });
111 119
 
112
-        btnScanAgain.setOnClickListener(v -> {
113
-            finish();
114
-        });
120
+        btnScanAgain.setOnClickListener(v -> finish());
115 121
     }
116 122
 
117 123
     @Override

+ 3 - 3
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultPresenter.java

@@ -5,7 +5,7 @@ import com.fusi24.rfid.data.DataManager;
5 5
 
6 6
 import io.reactivex.Scheduler;
7 7
 
8
-public class ScanResultPresenter extends BasePresenter<ScanResultView> {
8
+class ScanResultPresenter extends BasePresenter<ScanResultView> {
9 9
 
10 10
     private DataManager manager;
11 11
 
@@ -18,8 +18,8 @@ public class ScanResultPresenter extends BasePresenter<ScanResultView> {
18 18
         this.processScheduler = processScheduler;
19 19
     }
20 20
 
21
-    void checkRfidCard(String numberRfid, Integer permitId, String[] expand) {
22
-        disposable.add(manager.checkRfidCard(numberRfid, permitId, expand)
21
+    void checkRfidCard(String numberRfid, Integer permitId, Integer siteId, String[] expand) {
22
+        disposable.add(manager.checkRfidCard(numberRfid, siteId, permitId, expand)
23 23
                 .observeOn(androidScheduler)
24 24
                 .subscribeOn(processScheduler)
25 25
                 .subscribe(dataRfid -> {

+ 1 - 1
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultView.java

@@ -1,7 +1,7 @@
1 1
 package com.fusi24.rfid.ui.scanresult;
2 2
 
3 3
 import com.fusi24.rfid.base.BaseView;
4
-import com.fusi24.rfid.data.model.DataResultRfid;
4
+import com.fusi24.rfid.data.entity.DataResultRfid;
5 5
 
6 6
 public interface ScanResultView extends BaseView {
7 7
 

+ 4 - 4
app/src/main/res/layout/activity_scan_result.xml

@@ -44,7 +44,7 @@
44 44
             android:layout_width="match_parent"
45 45
             android:layout_height="wrap_content"
46 46
             android:gravity="center"
47
-            android:layout_margin="8dp"
47
+            android:layout_margin="2dp"
48 48
             tools:text="HADYAN EL AUFAR" />
49 49
 
50 50
         <TextView
@@ -53,7 +53,7 @@
53 53
             android:layout_width="match_parent"
54 54
             android:layout_height="wrap_content"
55 55
             android:gravity="center"
56
-            android:layout_margin="8dp"
56
+            android:layout_margin="2dp"
57 57
             tools:text="IT System Development Specialist" />
58 58
 
59 59
         <TextView
@@ -62,7 +62,7 @@
62 62
             android:layout_width="match_parent"
63 63
             android:layout_height="wrap_content"
64 64
             android:gravity="center"
65
-            android:layout_margin="8dp"
65
+            android:layout_margin="2dp"
66 66
             tools:text="Engineer/Specialist" />
67 67
 
68 68
         <TextView
@@ -71,7 +71,7 @@
71 71
             android:layout_width="match_parent"
72 72
             android:layout_height="wrap_content"
73 73
             android:gravity="center"
74
-            android:layout_margin="8dp"
74
+            android:layout_margin="2dp"
75 75
             tools:text="PT. Berau Coal Energy" />
76 76
 
77 77
     </LinearLayout>