Browse Source

-Add condition for status scan if 2 data show toggle if more show recyclerview
-add toast when failure or cancel get last location

ilhamitubagoes 4 years ago
parent
commit
f484049be8

+ 3 - 0
app/build.gradle

@@ -78,6 +78,9 @@ dependencies {
78
     //Light Stream
78
     //Light Stream
79
     implementation 'com.annimon:stream:1.2.1'
79
     implementation 'com.annimon:stream:1.2.1'
80
 
80
 
81
+    // Toggle Button
82
+    implementation 'com.github.angads25:toggle:1.1.0'
83
+
81
     //Serial Port
84
     //Serial Port
82
     implementation files('libs/serialport.jar')
85
     implementation files('libs/serialport.jar')
83
     implementation files('libs/android-async-http-1.4.9.jar')
86
     implementation files('libs/android-async-http-1.4.9.jar')

+ 2 - 1
app/src/main/java/com/fusi24/rfid/config/Constant.java

@@ -7,8 +7,9 @@ public final class Constant {
7
     /*__________________________________ACCESS_PERMISSION_________________________________________________*/
7
     /*__________________________________ACCESS_PERMISSION_________________________________________________*/
8
 
8
 
9
     public static final String[] PERMISSIONS_RFID = new String[]{
9
     public static final String[] PERMISSIONS_RFID = new String[]{
10
+            Manifest.permission.ACCESS_COARSE_LOCATION,
10
             Manifest.permission.ACCESS_FINE_LOCATION,
11
             Manifest.permission.ACCESS_FINE_LOCATION,
11
-            Manifest.permission.ACCESS_COARSE_LOCATION
12
+            Manifest.permission.READ_PHONE_STATE
12
     };
13
     };
13
 
14
 
14
     /*===================================================================================================*/
15
     /*===================================================================================================*/

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

@@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
6
 import android.os.Bundle;
6
 import android.os.Bundle;
7
 import android.view.View;
7
 import android.view.View;
8
 import android.widget.TextView;
8
 import android.widget.TextView;
9
+import android.widget.Toast;
9
 
10
 
10
 import androidx.appcompat.widget.Toolbar;
11
 import androidx.appcompat.widget.Toolbar;
11
 import androidx.core.app.ActivityCompat;
12
 import androidx.core.app.ActivityCompat;
@@ -134,9 +135,11 @@ public class ScanActivity extends LFScanProcessing {
134
                 double latitude = location.getLatitude();
135
                 double latitude = location.getLatitude();
135
                 double longitude = location.getLongitude();
136
                 double longitude = location.getLongitude();
136
                 longLat = longitude + "," + latitude;
137
                 longLat = longitude + "," + latitude;
137
-                Timber.d("DEVELOPER Location : " + location.getLatitude() + " , " + location.getLongitude());
138
+                System.out.println("DEVELOPER Location 1 : " + location.getLatitude() + " , " + location.getLongitude());
138
             }
139
             }
139
         });
140
         });
141
+        locationClient.getLastLocation().addOnCanceledListener(() -> Toast.makeText(this, "Get last location cancelled", Toast.LENGTH_SHORT).show());
142
+        locationClient.getLastLocation().addOnFailureListener(e -> System.out.println(e.getMessage()));
140
     }
143
     }
141
 
144
 
142
     @Override
145
     @Override

+ 69 - 6
app/src/main/java/com/fusi24/rfid/ui/home/HomeActivity.java

@@ -1,9 +1,14 @@
1
 package com.fusi24.rfid.ui.home;
1
 package com.fusi24.rfid.ui.home;
2
 
2
 
3
+import android.Manifest;
3
 import android.annotation.SuppressLint;
4
 import android.annotation.SuppressLint;
5
+import android.content.Context;
4
 import android.content.Intent;
6
 import android.content.Intent;
7
+import android.content.pm.PackageManager;
5
 import android.os.Build;
8
 import android.os.Build;
6
 import android.os.Bundle;
9
 import android.os.Bundle;
10
+import android.provider.Settings;
11
+import android.telephony.TelephonyManager;
7
 import android.view.Menu;
12
 import android.view.Menu;
8
 import android.view.MenuItem;
13
 import android.view.MenuItem;
9
 import android.view.View;
14
 import android.view.View;
@@ -46,7 +51,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
46
     private StatusScanAdapter scanAdapter;
51
     private StatusScanAdapter scanAdapter;
47
     private SiteAdapter siteAdapter;
52
     private SiteAdapter siteAdapter;
48
     private Integer idCheckType = null;
53
     private Integer idCheckType = null;
49
-    private String idDevice, checkTypeName;
54
+    private String idDevice, checkTypeName, uniqueId;
50
 
55
 
51
     @Override
56
     @Override
52
     protected void onCreate(Bundle savedInstanceState) {
57
     protected void onCreate(Bundle savedInstanceState) {
@@ -58,12 +63,12 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
58
         Toolbar toolbar = findViewById(R.id.toolbar);
63
         Toolbar toolbar = findViewById(R.id.toolbar);
59
         TextView toolbarTitle = findViewById(R.id.toolbar_text);
64
         TextView toolbarTitle = findViewById(R.id.toolbar_text);
60
 
65
 
61
-        if(toolbarTitle !=null && toolbar !=null) {
66
+        if (toolbarTitle != null && toolbar != null) {
62
             toolbarTitle.setText(getString(R.string.app_name));
67
             toolbarTitle.setText(getString(R.string.app_name));
63
             setSupportActionBar(toolbar);
68
             setSupportActionBar(toolbar);
64
         }
69
         }
65
 
70
 
66
-        if (getSupportActionBar() != null){
71
+        if (getSupportActionBar() != null) {
67
             getSupportActionBar().setDisplayShowTitleEnabled(false);
72
             getSupportActionBar().setDisplayShowTitleEnabled(false);
68
         }
73
         }
69
 
74
 
@@ -71,6 +76,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
71
         presenter.attachView(this);
76
         presenter.attachView(this);
72
 
77
 
73
         initView();
78
         initView();
79
+        getDataDeviceId();
74
         loadingData();
80
         loadingData();
75
     }
81
     }
76
 
82
 
@@ -106,7 +112,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
106
         initEvent();
112
         initEvent();
107
     }
113
     }
108
 
114
 
109
-    private void initView(){
115
+    private void initView() {
110
         binding.refresh.setRefreshing(false);
116
         binding.refresh.setRefreshing(false);
111
         ActivityCompat.requestPermissions(this, Constant.PERMISSIONS_RFID, 1000);
117
         ActivityCompat.requestPermissions(this, Constant.PERMISSIONS_RFID, 1000);
112
 
118
 
@@ -125,8 +131,9 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
125
     }
131
     }
126
 
132
 
127
     @SuppressLint("SetTextI18n")
133
     @SuppressLint("SetTextI18n")
128
-    private void loadingData(){
129
-        idDevice = "RFID" + Build.ID  + Build.DEVICE;
134
+    private void loadingData() {
135
+        // Build.DISPLAY is different
136
+        idDevice = "RFID" + "-" + Build.ID + "-" + Build.DEVICE + "-" + uniqueId;
130
         binding.tvRfidGunId.setText(idDevice);
137
         binding.tvRfidGunId.setText(idDevice);
131
         binding.tvRfidCardNumber.setText(getSessionManager().getUserRfidNumber());
138
         binding.tvRfidCardNumber.setText(getSessionManager().getUserRfidNumber());
132
         binding.tvEmployeeName.setText(getSessionManager().getEmployeeName());
139
         binding.tvEmployeeName.setText(getSessionManager().getEmployeeName());
@@ -194,6 +201,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
194
         statusScanList.addAll(dataStatusScanList);
201
         statusScanList.addAll(dataStatusScanList);
195
         scanAdapter.updateDetailList(statusScanList);
202
         scanAdapter.updateDetailList(statusScanList);
196
         scanAdapter.notifyDataSetChanged();
203
         scanAdapter.notifyDataSetChanged();
204
+        setDataStatusScan(dataStatusScanList.size());
197
     }
205
     }
198
 
206
 
199
     @Override
207
     @Override
@@ -208,6 +216,61 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
208
         binding.spinnerPermit.setAdapter(adapter);
216
         binding.spinnerPermit.setAdapter(adapter);
209
     }
217
     }
210
 
218
 
219
+    private void setDataStatusScan(Integer size){
220
+        if (size <= 2){
221
+            binding.swStatusScan.setVisibility(View.VISIBLE);
222
+            binding.rvStatusScan.setVisibility(View.GONE);
223
+        } else {
224
+            binding.swStatusScan.setVisibility(View.GONE);
225
+            binding.rvStatusScan.setVisibility(View.VISIBLE);
226
+        }
227
+
228
+        binding.swStatusScan.setLabelOn(statusScanList.get(0).getName());
229
+        binding.swStatusScan.setLabelOff(statusScanList.get(1).getName());
230
+
231
+        binding.swStatusScan.setOnToggledListener((toggleableView, isOn) -> {
232
+            if (isOn){
233
+                idCheckType = statusScanList.get(0).getId();
234
+                checkTypeName = statusScanList.get(0).getName();
235
+            } else {
236
+                idCheckType = statusScanList.get(1).getId();
237
+                checkTypeName = statusScanList.get(1).getName();
238
+            }
239
+        });
240
+    }
241
+
242
+
243
+    @SuppressLint("HardwareIds")
244
+    private void getDataDeviceId(){
245
+        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
246
+            ActivityCompat.requestPermissions(this, Constant.PERMISSIONS_RFID, 1000);
247
+            return;
248
+        }
249
+        TelephonyManager mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
250
+        String imsi = "";
251
+        String imei = "";
252
+        if (mTelephonyMgr != null) {
253
+            imsi = mTelephonyMgr.getSubscriberId();
254
+            imei = mTelephonyMgr.getDeviceId();
255
+        }
256
+        String uniqueId = Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID);
257
+        System.out.println("DEVELOPER 1 : " + imsi);
258
+        System.out.println("DEVELOPER 2 : " + imei);
259
+        System.out.println("DEVELOPER 3 : " + uniqueId);
260
+
261
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
262
+            this.uniqueId = uniqueId;
263
+        } else {
264
+            if (mTelephonyMgr != null) {
265
+                if (mTelephonyMgr.getDeviceId() != null){
266
+                    this.uniqueId = imei;
267
+                } else {
268
+                    this.uniqueId = uniqueId;
269
+                }
270
+            }
271
+        }
272
+    }
273
+
211
     @Override
274
     @Override
212
     public void showError(Throwable e) {
275
     public void showError(Throwable e) {
213
         binding.refresh.setRefreshing(false);
276
         binding.refresh.setRefreshing(false);

+ 16 - 0
app/src/main/res/layout/activity_home.xml

@@ -3,6 +3,7 @@
3
     xmlns:tools="http://schemas.android.com/tools"
3
     xmlns:tools="http://schemas.android.com/tools"
4
     android:layout_width="match_parent"
4
     android:layout_width="match_parent"
5
     android:layout_height="wrap_content"
5
     android:layout_height="wrap_content"
6
+    xmlns:app="http://schemas.android.com/apk/res-auto"
6
     android:orientation="vertical"
7
     android:orientation="vertical"
7
     tools:context=".ui.home.HomeActivity">
8
     tools:context=".ui.home.HomeActivity">
8
 
9
 
@@ -231,12 +232,27 @@
231
                             android:textStyle="bold"
232
                             android:textStyle="bold"
232
                             android:text="@string/label_scan_status" />
233
                             android:text="@string/label_scan_status" />
233
 
234
 
235
+                        <com.github.angads25.toggle.widget.LabeledSwitch
236
+                            android:id="@+id/sw_status_scan"
237
+                            android:layout_width="175dp"
238
+                            android:layout_height="wrap_content"
239
+                            android:layout_margin="8dp"
240
+                            android:textSize="14sp"
241
+                            android:visibility="visible"
242
+                            android:layout_gravity="start"
243
+                            app:on="false"
244
+                            app:colorOn="@color/colorPrimary"
245
+                            app:colorOff="@color/colorWhite"
246
+                            app:colorDisabled="@color/backgroundLayoutGreyDark"
247
+                            app:colorBorder="@color/grey"/>
248
+
234
                         <androidx.recyclerview.widget.RecyclerView
249
                         <androidx.recyclerview.widget.RecyclerView
235
                             android:id="@+id/rv_status_scan"
250
                             android:id="@+id/rv_status_scan"
236
                             android:layout_width="175dp"
251
                             android:layout_width="175dp"
237
                             android:layout_height="wrap_content"
252
                             android:layout_height="wrap_content"
238
                             android:layout_marginStart="12dp"
253
                             android:layout_marginStart="12dp"
239
                             android:layout_marginEnd="12dp"
254
                             android:layout_marginEnd="12dp"
255
+                            android:visibility="gone"
240
                             tools:listitem="@layout/row_status_scan"
256
                             tools:listitem="@layout/row_status_scan"
241
                             tools:itemCount="2"/>
257
                             tools:itemCount="2"/>
242
 
258