Browse Source

-Add session every list in home
-Add filter by is active in list

ilhamitubagoes 4 years ago
parent
commit
25d7bc02e5

+ 4 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -1,6 +1,10 @@
1
 <component name="InspectionProjectProfileManager">
1
 <component name="InspectionProjectProfileManager">
2
   <profile version="1.0">
2
   <profile version="1.0">
3
     <option name="myName" value="Project Default" />
3
     <option name="myName" value="Project Default" />
4
+    <inspection_tool class="ConstantConditions" enabled="false" level="WARNING" enabled_by_default="false">
5
+      <option name="SUGGEST_NULLABLE_ANNOTATIONS" value="false" />
6
+      <option name="DONT_REPORT_TRUE_ASSERT_STATEMENTS" value="false" />
7
+    </inspection_tool>
4
     <inspection_tool class="UNCHECKED_WARNING" enabled="false" level="WARNING" enabled_by_default="false" />
8
     <inspection_tool class="UNCHECKED_WARNING" enabled="false" level="WARNING" enabled_by_default="false" />
5
   </profile>
9
   </profile>
6
 </component>
10
 </component>

+ 22 - 0
app/src/main/java/com/fusi24/entryPermitScanner/data/SessionManager.java

@@ -2,6 +2,7 @@ package com.fusi24.entryPermitScanner.data;
2
 
2
 
3
 import android.content.SharedPreferences;
3
 import android.content.SharedPreferences;
4
 
4
 
5
+import com.fusi24.entryPermitScanner.data.entity.DataEntryPermit;
5
 import com.fusi24.entryPermitScanner.data.entity.DataSite;
6
 import com.fusi24.entryPermitScanner.data.entity.DataSite;
6
 import com.google.gson.Gson;
7
 import com.google.gson.Gson;
7
 import com.google.gson.reflect.TypeToken;
8
 import com.google.gson.reflect.TypeToken;
@@ -21,6 +22,7 @@ public class SessionManager {
21
     private static final String USER_RFID_NUMBER        = "user_rfid_number";
22
     private static final String USER_RFID_NUMBER        = "user_rfid_number";
22
     private static final String GATE                    = "gate";
23
     private static final String GATE                    = "gate";
23
     private static final String SITE_LIST               = "site_list";
24
     private static final String SITE_LIST               = "site_list";
25
+    private static final String PERMIT_LIST             = "permit_list";
24
     private static final String IS_SERIALPORT_2         = "serial_port_2";
26
     private static final String IS_SERIALPORT_2         = "serial_port_2";
25
     private static final String IS_DEVELOPMENT          = "development";
27
     private static final String IS_DEVELOPMENT          = "development";
26
 
28
 
@@ -138,6 +140,24 @@ public class SessionManager {
138
         editor.apply();
140
         editor.apply();
139
     }
141
     }
140
 
142
 
143
+    public List<DataEntryPermit> getPermitList(){
144
+        List<DataEntryPermit> permitList;
145
+        String jsonPreferences = preferences.getString(PERMIT_LIST, "");
146
+
147
+        Type type = new TypeToken<List<DataEntryPermit>>() {}.getType();
148
+        permitList = new Gson().fromJson(jsonPreferences, type);
149
+
150
+        return permitList;
151
+    }
152
+
153
+    public void setPermitList(List<DataEntryPermit> list){
154
+        String jsonCurProduct = new Gson().toJson(list);
155
+
156
+        SharedPreferences.Editor editor = preferences.edit();
157
+        editor.putString(PERMIT_LIST , jsonCurProduct);
158
+        editor.apply();
159
+    }
160
+
141
     public Boolean isSerialPort2() {
161
     public Boolean isSerialPort2() {
142
         return preferences.getBoolean(IS_SERIALPORT_2, false);
162
         return preferences.getBoolean(IS_SERIALPORT_2, false);
143
     }
163
     }
@@ -169,6 +189,8 @@ public class SessionManager {
169
         editor.remove(USER_TELEPHONE);
189
         editor.remove(USER_TELEPHONE);
170
         editor.remove(USER_RFID_NUMBER);
190
         editor.remove(USER_RFID_NUMBER);
171
         editor.remove(GATE);
191
         editor.remove(GATE);
192
+        editor.remove(SITE_LIST);
193
+        editor.remove(PERMIT_LIST);
172
         editor.apply();
194
         editor.apply();
173
     }
195
     }
174
 }
196
 }

+ 0 - 4
app/src/main/java/com/fusi24/entryPermitScanner/ui/ScanActivity.java

@@ -228,17 +228,13 @@ public class ScanActivity extends LFScanProcessing implements GoogleApiClient.Co
228
             return;
228
             return;
229
         }
229
         }
230
         Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
230
         Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
231
-
232
         if (location == null) {
231
         if (location == null) {
233
             LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
232
             LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
234
-
235
         } else {
233
         } else {
236
             //If everything went fine lets get latitude and longitude
234
             //If everything went fine lets get latitude and longitude
237
             currentLatitude = location.getLatitude();
235
             currentLatitude = location.getLatitude();
238
             currentLongitude = location.getLongitude();
236
             currentLongitude = location.getLongitude();
239
-
240
             longLat = currentLongitude + "," + currentLatitude;
237
             longLat = currentLongitude + "," + currentLatitude;
241
-
242
             Timber.i("Latitude : " + currentLatitude + ", Longitude : " + currentLongitude);
238
             Timber.i("Latitude : " + currentLatitude + ", Longitude : " + currentLongitude);
243
         }
239
         }
244
     }
240
     }

+ 6 - 3
app/src/main/java/com/fusi24/entryPermitScanner/ui/home/HomeActivity.java

@@ -23,6 +23,7 @@ import androidx.core.app.ActivityCompat;
23
 import androidx.recyclerview.widget.DefaultItemAnimator;
23
 import androidx.recyclerview.widget.DefaultItemAnimator;
24
 import androidx.recyclerview.widget.LinearLayoutManager;
24
 import androidx.recyclerview.widget.LinearLayoutManager;
25
 
25
 
26
+import com.annimon.stream.Collectors;
26
 import com.annimon.stream.Stream;
27
 import com.annimon.stream.Stream;
27
 import com.fusi24.entryPermitScanner.BuildConfig;
28
 import com.fusi24.entryPermitScanner.BuildConfig;
28
 import com.fusi24.entryPermitScanner.R;
29
 import com.fusi24.entryPermitScanner.R;
@@ -197,8 +198,9 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
197
 
198
 
198
     @Override
199
     @Override
199
     public void showDataPermit(List<DataEntryPermit> dataEntryPermitList) {
200
     public void showDataPermit(List<DataEntryPermit> dataEntryPermitList) {
201
+        getSessionManager().setPermitList(dataEntryPermitList);
200
         entryPermitList.clear();
202
         entryPermitList.clear();
201
-        entryPermitList.addAll(dataEntryPermitList);
203
+        entryPermitList.addAll(getSessionManager().getPermitList());
202
         setDataPermit();
204
         setDataPermit();
203
     }
205
     }
204
 
206
 
@@ -215,14 +217,15 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
215
     @Override
217
     @Override
216
     public void showDataDevice(List<DataDevice> dataDevices) {
218
     public void showDataDevice(List<DataDevice> dataDevices) {
217
         getSessionManager().setGate(dataDevices.get(0).getGate().getName());
219
         getSessionManager().setGate(dataDevices.get(0).getGate().getName());
218
-        getSessionManager().setSiteList(Stream.of(dataDevices.get(0).getGate().getSites()).sortBy(DataSite::getId).toList());
220
+        getSessionManager().setSiteList(Stream.of(dataDevices.get(0).getGate().getSites()).filter(DataSite::getActive).sortBy(DataSite::getId).toList());
219
         binding.tvGateName.setText(getSessionManager().getGate());
221
         binding.tvGateName.setText(getSessionManager().getGate());
220
         siteAdapter.updateSiteList(getSessionManager().getSiteList());
222
         siteAdapter.updateSiteList(getSessionManager().getSiteList());
221
         siteAdapter.notifyDataSetChanged();
223
         siteAdapter.notifyDataSetChanged();
222
     }
224
     }
223
 
225
 
224
     private void setDataPermit(){
226
     private void setDataPermit(){
225
-        ArrayAdapter<DataEntryPermit> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, entryPermitList);
227
+        ArrayAdapter<DataEntryPermit> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item,
228
+                Stream.of(entryPermitList).filter(DataEntryPermit::getActive).collect(Collectors.toList()));
226
         binding.spinnerPermit.setAdapter(adapter);
229
         binding.spinnerPermit.setAdapter(adapter);
227
     }
230
     }
228
 
231