瀏覽代碼

-Get data gate and site

ilhamitubagoes 4 年之前
父節點
當前提交
0d471ed484

+ 63 - 0
app/src/main/java/com/fusi24/rfid/adapter/SiteAdapter.java

@@ -0,0 +1,63 @@
1
+package com.fusi24.rfid.adapter;
2
+
3
+import android.content.Context;
4
+import android.view.LayoutInflater;
5
+import android.view.ViewGroup;
6
+
7
+import androidx.annotation.NonNull;
8
+import androidx.recyclerview.widget.RecyclerView;
9
+
10
+import com.fusi24.rfid.data.entity.DataSite;
11
+import com.fusi24.rfid.databinding.RowSiteBinding;
12
+
13
+import java.util.ArrayList;
14
+import java.util.List;
15
+
16
+public class SiteAdapter extends RecyclerView.Adapter<SiteAdapter.ViewHolder>{
17
+
18
+    private Context context;
19
+    private List<DataSite> siteList;
20
+
21
+    public SiteAdapter(Context context) {
22
+        this.context = context;
23
+        this.siteList = new ArrayList<>();
24
+    }
25
+
26
+    private void setSiteList(List<DataSite> siteList) {
27
+        this.siteList = siteList;
28
+    }
29
+
30
+    public void updateSiteList(List<DataSite> siteList){
31
+        setSiteList(siteList);
32
+    }
33
+
34
+    static class ViewHolder extends RecyclerView.ViewHolder {
35
+        private RowSiteBinding binding;
36
+
37
+        ViewHolder(RowSiteBinding itemBinding) {
38
+            super(itemBinding.getRoot());
39
+            this.binding = itemBinding;
40
+        }
41
+    }
42
+
43
+
44
+    @NonNull
45
+    @Override
46
+    public SiteAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
47
+        RowSiteBinding itemBinding = RowSiteBinding.inflate(LayoutInflater.from(context), parent, false);
48
+        return new ViewHolder(itemBinding);
49
+    }
50
+
51
+    @Override
52
+    public void onBindViewHolder(@NonNull SiteAdapter.ViewHolder holder, int position) {
53
+
54
+        DataSite site = siteList.get(position);
55
+        holder.binding.tvCommon.setText(site.getName());
56
+
57
+    }
58
+
59
+    @Override
60
+    public int getItemCount() {
61
+        return siteList.size();
62
+    }
63
+}

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

@@ -3,6 +3,7 @@ package com.fusi24.rfid.data;
3 3
 import com.fusi24.rfid.data.api.RestService;
4 4
 import com.fusi24.rfid.data.entity.DataAuth;
5 5
 import com.fusi24.rfid.data.entity.DataDetail;
6
+import com.fusi24.rfid.data.entity.DataDevice;
6 7
 import com.fusi24.rfid.data.entity.DataEntryPermit;
7 8
 import com.fusi24.rfid.data.entity.DataResultRfid;
8 9
 import com.fusi24.rfid.data.entity.DataUser;
@@ -31,6 +32,10 @@ public class DataManager {
31 32
         return restService.getLookUp(code);
32 33
     }
33 34
 
35
+    public Observable<List<DataDevice>> getDataDevice(String deviceId, String[] expand) {
36
+        return restService.getDataDevice(deviceId, expand);
37
+    }
38
+
34 39
     public Observable<DataResultRfid> checkRfidCard(String numberRfid, Integer permitId, String rfidDeviceId, Integer checkTypeId, String longLat, String[] expand) {
35 40
         return restService.checkRfidCard(numberRfid, permitId, rfidDeviceId, checkTypeId, longLat, expand);
36 41
     }

+ 8 - 3
app/src/main/java/com/fusi24/rfid/data/api/RestService.java

@@ -3,6 +3,7 @@ package com.fusi24.rfid.data.api;
3 3
 import com.fusi24.rfid.config.Constant;
4 4
 import com.fusi24.rfid.data.entity.DataAuth;
5 5
 import com.fusi24.rfid.data.entity.DataDetail;
6
+import com.fusi24.rfid.data.entity.DataDevice;
6 7
 import com.fusi24.rfid.data.entity.DataEntryPermit;
7 8
 import com.fusi24.rfid.data.entity.DataResultRfid;
8 9
 import com.fusi24.rfid.data.entity.DataSite;
@@ -23,15 +24,19 @@ public interface RestService {
23 24
     @POST(Constant.BEATS_ENDPOINT + "/api/mobile/login/rfid")
24 25
     Observable<DataUser> userLogin(@Body DataAuth dataAuth);
25 26
 
26
-    @GET(Constant.SID2_ENDPOINT + "/api/entryPermit")
27
-    Observable<List<DataEntryPermit>> getEntryPermit();
28
-
29 27
     @GET(Constant.BEATS2_ENDPOINT + "/api/lookup")
30 28
     Observable<List<DataDetail>> getLookUp(@Query("filter[parent.code]") String code);
31 29
 
32 30
     @GET(Constant.BEATS2_ENDPOINT + "/api/location")
33 31
     Call<List<DataSite>> getDataSite(@Query("filter[type.id]") Integer typeId);
34 32
 
33
+    @GET(Constant.SID2_ENDPOINT + "/api/entryPermit")
34
+    Observable<List<DataEntryPermit>> getEntryPermit();
35
+
36
+    @GET(Constant.SID2_ENDPOINT + "/api/entryRfid")
37
+    Observable<List<DataDevice>> getDataDevice(@Query("filter[deviceId]") String deviceId,
38
+                                               @Query("expand") String[] expand);
39
+
35 40
     @GET(Constant.SID2_ENDPOINT + Constant.RFID_ENDPOINT + "/permit/check/{number_rfid}")
36 41
     Observable<DataResultRfid> checkRfidCard(@Path("number_rfid") String numberRfid,
37 42
                                              @Query("entryPermitId") Integer permitId,

+ 41 - 0
app/src/main/java/com/fusi24/rfid/data/entity/DataDevice.java

@@ -0,0 +1,41 @@
1
+package com.fusi24.rfid.data.entity;
2
+
3
+public class DataDevice {
4
+
5
+    private Integer id;
6
+    private String deviceId;
7
+    private DataGate gate;
8
+    private boolean isActive;
9
+
10
+    public Integer getId() {
11
+        return id;
12
+    }
13
+
14
+    public void setId(Integer id) {
15
+        this.id = id;
16
+    }
17
+
18
+    public String getDeviceId() {
19
+        return deviceId;
20
+    }
21
+
22
+    public void setDeviceId(String deviceId) {
23
+        this.deviceId = deviceId;
24
+    }
25
+
26
+    public DataGate getGate() {
27
+        return gate;
28
+    }
29
+
30
+    public void setGate(DataGate gate) {
31
+        this.gate = gate;
32
+    }
33
+
34
+    public boolean isActive() {
35
+        return isActive;
36
+    }
37
+
38
+    public void setActive(boolean active) {
39
+        isActive = active;
40
+    }
41
+}

+ 52 - 0
app/src/main/java/com/fusi24/rfid/data/entity/DataGate.java

@@ -0,0 +1,52 @@
1
+package com.fusi24.rfid.data.entity;
2
+
3
+import java.util.List;
4
+
5
+public class DataGate {
6
+
7
+    private Integer id;
8
+    private String name;
9
+    private String description;
10
+    private boolean isActive;
11
+    private List<DataSite> sites;
12
+
13
+    public Integer getId() {
14
+        return id;
15
+    }
16
+
17
+    public void setId(Integer id) {
18
+        this.id = id;
19
+    }
20
+
21
+    public String getName() {
22
+        return name;
23
+    }
24
+
25
+    public void setName(String name) {
26
+        this.name = name;
27
+    }
28
+
29
+    public String getDescription() {
30
+        return description;
31
+    }
32
+
33
+    public void setDescription(String description) {
34
+        this.description = description;
35
+    }
36
+
37
+    public boolean isActive() {
38
+        return isActive;
39
+    }
40
+
41
+    public void setActive(boolean active) {
42
+        isActive = active;
43
+    }
44
+
45
+    public List<DataSite> getSites() {
46
+        return sites;
47
+    }
48
+
49
+    public void setSites(List<DataSite> sites) {
50
+        this.sites = sites;
51
+    }
52
+}

+ 21 - 8
app/src/main/java/com/fusi24/rfid/ui/home/HomeActivity.java

@@ -21,10 +21,12 @@ import androidx.recyclerview.widget.LinearLayoutManager;
21 21
 import com.fusi24.rfid.BuildConfig;
22 22
 import com.fusi24.rfid.R;
23 23
 import com.fusi24.rfid.SplashScreenActivity;
24
+import com.fusi24.rfid.adapter.SiteAdapter;
24 25
 import com.fusi24.rfid.adapter.StatusScanAdapter;
25 26
 import com.fusi24.rfid.base.BaseActivity;
26 27
 import com.fusi24.rfid.config.Constant;
27 28
 import com.fusi24.rfid.data.entity.DataDetail;
29
+import com.fusi24.rfid.data.entity.DataDevice;
28 30
 import com.fusi24.rfid.data.entity.DataEntryPermit;
29 31
 import com.fusi24.rfid.databinding.ActivityHomeBinding;
30 32
 import com.fusi24.rfid.ui.ScanActivity;
@@ -41,7 +43,8 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
41 43
     private List<DataDetail> statusScanList;
42 44
     private ActivityHomeBinding binding;
43 45
     private HomePresenter presenter;
44
-    private StatusScanAdapter adapter;
46
+    private StatusScanAdapter scanAdapter;
47
+    private SiteAdapter siteAdapter;
45 48
     private Integer idCheckType = null;
46 49
     private String idDevice, checkTypeName;
47 50
 
@@ -109,10 +112,15 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
109 112
         entryPermitList = new ArrayList<>();
110 113
         statusScanList = new ArrayList<>();
111 114
 
112
-        adapter = new StatusScanAdapter(this, this);
115
+        scanAdapter = new StatusScanAdapter(this, this);
113 116
         binding.rvStatusScan.setLayoutManager(new LinearLayoutManager(this));
114 117
         binding.rvStatusScan.setItemAnimator(new DefaultItemAnimator());
115
-        binding.rvStatusScan.setAdapter(adapter);
118
+        binding.rvStatusScan.setAdapter(scanAdapter);
119
+
120
+        siteAdapter = new SiteAdapter(this);
121
+        binding.rvSite.setLayoutManager(new LinearLayoutManager(this));
122
+        binding.rvSite.setItemAnimator(new DefaultItemAnimator());
123
+        binding.rvSite.setAdapter(siteAdapter);
116 124
     }
117 125
 
118 126
     @SuppressLint("SetTextI18n")
@@ -121,12 +129,10 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
121 129
         binding.tvRfidGunId.setText(idDevice);
122 130
         binding.tvRfidCardNumber.setText(getSessionManager().getUserRfidNumber());
123 131
         binding.tvEmployeeName.setText(getSessionManager().getEmployeeName());
124
-        //TODO STILL HARDCODE
125
-        binding.tvGateName.setText("Suzuran");
126
-        binding.tvSiteName.setText("BMO 1");
127 132
 
128 133
         presenter.getEntryPermit();
129 134
         presenter.getStatusScan();
135
+        presenter.getDataDevice(idDevice);
130 136
     }
131 137
 
132 138
     private void initEvent(){
@@ -180,8 +186,15 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
180 186
     @Override
181 187
     public void showDataStatusScan(List<DataDetail> dataStatusScanList) {
182 188
         statusScanList.addAll(dataStatusScanList);
183
-        adapter.updateDetailList(statusScanList);
184
-        adapter.notifyDataSetChanged();
189
+        scanAdapter.updateDetailList(statusScanList);
190
+        scanAdapter.notifyDataSetChanged();
191
+    }
192
+
193
+    @Override
194
+    public void showDataDevice(List<DataDevice> dataDevices) {
195
+        binding.tvGateName.setText(dataDevices.get(0).getGate().getName());
196
+        siteAdapter.updateSiteList(dataDevices.get(0).getGate().getSites());
197
+        siteAdapter.notifyDataSetChanged();
185 198
     }
186 199
 
187 200
     private void setDataPermit(){

+ 16 - 0
app/src/main/java/com/fusi24/rfid/ui/home/HomePresenter.java

@@ -47,4 +47,20 @@ class HomePresenter extends BasePresenter<HomeView> {
47 47
                 }));
48 48
     }
49 49
 
50
+    void getDataDevice(String deviceId) {
51
+        String[] expand = {"gate.sites"};
52
+        disposable.add(manager.getDataDevice(deviceId, expand)
53
+                .observeOn(androidScheduler)
54
+                .subscribeOn(processScheduler)
55
+                .subscribe(result -> {
56
+                    if (isViewAttached()) {
57
+                        getView().showDataDevice(result);
58
+                    }
59
+                }, throwable -> {
60
+                    if (isViewAttached()) {
61
+                        getView().showError(throwable);
62
+                    }
63
+                }));
64
+    }
65
+
50 66
 }

+ 2 - 1
app/src/main/java/com/fusi24/rfid/ui/home/HomeView.java

@@ -2,8 +2,8 @@ package com.fusi24.rfid.ui.home;
2 2
 
3 3
 import com.fusi24.rfid.base.BaseView;
4 4
 import com.fusi24.rfid.data.entity.DataDetail;
5
+import com.fusi24.rfid.data.entity.DataDevice;
5 6
 import com.fusi24.rfid.data.entity.DataEntryPermit;
6
-import com.fusi24.rfid.data.entity.DataResultRfid;
7 7
 
8 8
 import java.util.List;
9 9
 
@@ -11,5 +11,6 @@ public interface HomeView extends BaseView {
11 11
 
12 12
     void showDataPermit(List<DataEntryPermit> dataEntryPermitList);
13 13
     void showDataStatusScan(List<DataDetail> dataStatusScanList);
14
+    void showDataDevice(List<DataDevice> dataDevices);
14 15
 
15 16
 }

+ 4 - 3
app/src/main/res/layout/activity_home.xml

@@ -156,15 +156,16 @@
156 156
                 android:textStyle="bold"
157 157
                 android:text="@string/label_site" />
158 158
 
159
-            <TextView
160
-                android:id="@+id/tv_site_name"
159
+            <androidx.recyclerview.widget.RecyclerView
160
+                android:id="@+id/rv_site"
161 161
                 android:layout_width="match_parent"
162 162
                 android:layout_height="wrap_content"
163 163
                 android:layout_weight="1"
164 164
                 android:layout_marginStart="12dp"
165 165
                 android:textSize="14sp"
166 166
                 android:textColor="@color/colorBlack"
167
-                tools:text="BMO 1" />
167
+                tools:listitem="@layout/row_site"
168
+                tools:itemCount="3"/>
168 169
         </LinearLayout>
169 170
 
170 171
         <LinearLayout

+ 8 - 0
app/src/main/res/layout/row_site.xml

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    android:id="@+id/tv_common"
5
+    android:layout_width="match_parent"
6
+    android:layout_height="wrap_content"
7
+    android:orientation="vertical"
8
+    tools:text="BMO 1" />