Преглед на файлове

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

ilhamitubagoes преди 4 години
родител
ревизия
25d7bc02e5

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

@@ -1,6 +1,10 @@
1 1
 <component name="InspectionProjectProfileManager">
2 2
   <profile version="1.0">
3 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 8
     <inspection_tool class="UNCHECKED_WARNING" enabled="false" level="WARNING" enabled_by_default="false" />
5 9
   </profile>
6 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 3
 import android.content.SharedPreferences;
4 4
 
5
+import com.fusi24.entryPermitScanner.data.entity.DataEntryPermit;
5 6
 import com.fusi24.entryPermitScanner.data.entity.DataSite;
6 7
 import com.google.gson.Gson;
7 8
 import com.google.gson.reflect.TypeToken;
@@ -21,6 +22,7 @@ public class SessionManager {
21 22
     private static final String USER_RFID_NUMBER        = "user_rfid_number";
22 23
     private static final String GATE                    = "gate";
23 24
     private static final String SITE_LIST               = "site_list";
25
+    private static final String PERMIT_LIST             = "permit_list";
24 26
     private static final String IS_SERIALPORT_2         = "serial_port_2";
25 27
     private static final String IS_DEVELOPMENT          = "development";
26 28
 
@@ -138,6 +140,24 @@ public class SessionManager {
138 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 161
     public Boolean isSerialPort2() {
142 162
         return preferences.getBoolean(IS_SERIALPORT_2, false);
143 163
     }
@@ -169,6 +189,8 @@ public class SessionManager {
169 189
         editor.remove(USER_TELEPHONE);
170 190
         editor.remove(USER_RFID_NUMBER);
171 191
         editor.remove(GATE);
192
+        editor.remove(SITE_LIST);
193
+        editor.remove(PERMIT_LIST);
172 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 228
             return;
229 229
         }
230 230
         Location location = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
231
-
232 231
         if (location == null) {
233 232
             LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
234
-
235 233
         } else {
236 234
             //If everything went fine lets get latitude and longitude
237 235
             currentLatitude = location.getLatitude();
238 236
             currentLongitude = location.getLongitude();
239
-
240 237
             longLat = currentLongitude + "," + currentLatitude;
241
-
242 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 23
 import androidx.recyclerview.widget.DefaultItemAnimator;
24 24
 import androidx.recyclerview.widget.LinearLayoutManager;
25 25
 
26
+import com.annimon.stream.Collectors;
26 27
 import com.annimon.stream.Stream;
27 28
 import com.fusi24.entryPermitScanner.BuildConfig;
28 29
 import com.fusi24.entryPermitScanner.R;
@@ -197,8 +198,9 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
197 198
 
198 199
     @Override
199 200
     public void showDataPermit(List<DataEntryPermit> dataEntryPermitList) {
201
+        getSessionManager().setPermitList(dataEntryPermitList);
200 202
         entryPermitList.clear();
201
-        entryPermitList.addAll(dataEntryPermitList);
203
+        entryPermitList.addAll(getSessionManager().getPermitList());
202 204
         setDataPermit();
203 205
     }
204 206
 
@@ -215,14 +217,15 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
215 217
     @Override
216 218
     public void showDataDevice(List<DataDevice> dataDevices) {
217 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 221
         binding.tvGateName.setText(getSessionManager().getGate());
220 222
         siteAdapter.updateSiteList(getSessionManager().getSiteList());
221 223
         siteAdapter.notifyDataSetChanged();
222 224
     }
223 225
 
224 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 229
         binding.spinnerPermit.setAdapter(adapter);
227 230
     }
228 231