ソースを参照

-Optimize session for data gate, site and permit
-Add sound util for dynamic sound (must import in project)

ilhamitubagoes 4 年 前
コミット
9d4b0859db

+ 1 - 1
app/src/main/AndroidManifest.xml

@@ -16,7 +16,7 @@
16 16
         android:theme="@style/AppTheme">
17 17
         <activity
18 18
             android:name=".SplashScreenActivity"
19
-            android:screenOrientation="fullSensor"
19
+            android:screenOrientation="portrait"
20 20
             android:theme="@style/Theme.AppCompat.Light.NoActionBar">
21 21
         <intent-filter>
22 22
             <action android:name="android.intent.action.MAIN" />

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

@@ -30,7 +30,7 @@ public final class Constant {
30 30
     /*===================================================================================================*/
31 31
 
32 32
     //Direct API Service
33
-    public final static String BASE_URL_DEV = "http://bcui2.fusi24.com"; // Development
33
+    public final static String BASE_URL_DEV = "https://bcui2.fusi24.com"; // Development
34 34
     public final static String BASE_URL_PROD = "http://hseautomation.beraucoal.co.id"; // Production
35 35
 
36 36
     public final static String BEATS_ENDPOINT = "/beats";

+ 37 - 10
app/src/main/java/com/fusi24/entryPermitScanner/ui/home/HomeActivity.java

@@ -39,6 +39,7 @@ import com.fusi24.entryPermitScanner.data.entity.DataSite;
39 39
 import com.fusi24.entryPermitScanner.databinding.ActivityHomeBinding;
40 40
 import com.fusi24.entryPermitScanner.ui.ScanActivity;
41 41
 import com.fusi24.entryPermitScanner.ui.setting.SettingActivity;
42
+import com.google.gson.Gson;
42 43
 
43 44
 import java.util.ArrayList;
44 45
 import java.util.List;
@@ -82,6 +83,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
82 83
         initView();
83 84
         getDataDeviceId();
84 85
         loadingData();
86
+        getDataFromService();
85 87
     }
86 88
 
87 89
     @Override
@@ -118,6 +120,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
118 120
     @Override
119 121
     protected void onResume() {
120 122
         super.onResume();
123
+        loadingData();
121 124
         initEvent();
122 125
     }
123 126
 
@@ -146,7 +149,26 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
146 149
         binding.tvRfidGunId.setText(idDevice);
147 150
         binding.tvRfidCardNumber.setText(getSessionManager().getUserRfidNumber());
148 151
         binding.tvEmployeeName.setText(getSessionManager().getEmployeeName());
152
+        binding.tvGateName.setText(getSessionManager().getGate());
153
+
154
+        if (getSessionManager().getSiteList() != null) {
155
+            siteAdapter.updateSiteList(getSessionManager().getSiteList());
156
+            siteAdapter.notifyDataSetChanged();
157
+        }
158
+
159
+        if (getSessionManager().getPermitList() != null) {
160
+            entryPermitList.clear();
161
+            entryPermitList.addAll(getSessionManager().getPermitList());
162
+        }
163
+        setDataPermit();
164
+
165
+        Gson gson = new Gson();
166
+        System.out.println("Developer Gate : " + gson.toJson(getSessionManager().getGate()));
167
+        System.out.println("Developer Site : " + gson.toJson(getSessionManager().getSiteList()));
168
+        System.out.println("Developer Permit : " + gson.toJson(getSessionManager().getPermitList()));
169
+    }
149 170
 
171
+    private void getDataFromService(){
150 172
         presenter.getEntryPermit();
151 173
         presenter.getStatusScan();
152 174
         presenter.getDataDevice(idDevice);
@@ -186,7 +208,7 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
186 208
             startActivity(intent);
187 209
         });
188 210
 
189
-        binding.refresh.setOnRefreshListener(this::loadingData);
211
+        binding.refresh.setOnRefreshListener(this::getDataFromService);
190 212
 
191 213
     }
192 214
 
@@ -198,10 +220,8 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
198 220
 
199 221
     @Override
200 222
     public void showDataPermit(List<DataEntryPermit> dataEntryPermitList) {
223
+        binding.refresh.setRefreshing(false);
201 224
         getSessionManager().setPermitList(dataEntryPermitList);
202
-        entryPermitList.clear();
203
-        entryPermitList.addAll(getSessionManager().getPermitList());
204
-        setDataPermit();
205 225
     }
206 226
 
207 227
     @Override
@@ -216,11 +236,19 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
216 236
 
217 237
     @Override
218 238
     public void showDataDevice(List<DataDevice> dataDevices) {
219
-        getSessionManager().setGate(dataDevices.get(0).getGate().getName());
220
-        getSessionManager().setSiteList(Stream.of(dataDevices.get(0).getGate().getSites()).filter(DataSite::getActive).sortBy(DataSite::getId).toList());
221
-        binding.tvGateName.setText(getSessionManager().getGate());
222
-        siteAdapter.updateSiteList(getSessionManager().getSiteList());
223
-        siteAdapter.notifyDataSetChanged();
239
+        // If data empty clear session
240
+        if (dataDevices.isEmpty()){
241
+            List<DataSite> siteList = new ArrayList<>();
242
+            getSessionManager().setSiteList(siteList);
243
+            getSessionManager().setGate("");
244
+        } else {
245
+            getSessionManager().setGate(dataDevices.get(0).getGate().getName()); // Data Gate
246
+            getSessionManager().setSiteList(Stream.of(dataDevices.get(0).getGate().getSites()) // Data Site
247
+                    .filter(DataSite::getActive)
248
+                    .sortBy(DataSite::getId).toList());
249
+        }
250
+        binding.refresh.setRefreshing(false);
251
+        loadingData();
224 252
     }
225 253
 
226 254
     private void setDataPermit(){
@@ -239,7 +267,6 @@ public class HomeActivity extends BaseActivity implements HomeView, StatusScanAd
239 267
         }
240 268
 
241 269
         // Inisiasi pertama saat muncul halaman default true
242
-        binding.swStatusScan.setOn(true);
243 270
         idCheckType = statusScanList.get(0).getId(); // <-- Check In Code (649)
244 271
         checkTypeName = statusScanList.get(0).getName(); // <-- Check In Name
245 272
 

+ 2 - 5
app/src/main/java/com/fusi24/entryPermitScanner/ui/login/LoginActivity.java

@@ -6,6 +6,7 @@ import android.os.Bundle;
6 6
 import android.view.View;
7 7
 import android.widget.Toast;
8 8
 
9
+import com.fusi24.entryPermitScanner.R;
9 10
 import com.fusi24.entryPermitScanner.data.SessionManager;
10 11
 import com.fusi24.entryPermitScanner.data.entity.DataAuth;
11 12
 import com.fusi24.entryPermitScanner.data.entity.DataUser;
@@ -98,11 +99,7 @@ public class LoginActivity extends LFScanProcessing implements LoginView {
98 99
             setResult(Activity.RESULT_OK, result);
99 100
             finish();
100 101
         } else {
101
-            Intent intent = new Intent(this, ErrorLoginActivity.class);
102
-            if (dataUser.getMessage() != null){
103
-                intent.putExtra(ErrorLoginActivity.MESSAGE, dataUser.getMessage());
104
-            }
105
-            startActivity(intent);
102
+            Toast.makeText(this, getString(R.string.error_only_security), Toast.LENGTH_SHORT).show();
106 103
         }
107 104
     }
108 105
 

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

@@ -23,6 +23,7 @@ import com.fusi24.entryPermitScanner.data.entity.DataProblems;
23 23
 import com.fusi24.entryPermitScanner.data.entity.DataResultRfid;
24 24
 import com.fusi24.entryPermitScanner.databinding.ActivityScanResultNewBinding;
25 25
 import com.fusi24.entryPermitScanner.ui.home.HomeActivity;
26
+import com.fusi24.entryPermitScanner.util.SoundUtil;
26 27
 
27 28
 import java.util.ArrayList;
28 29
 import java.util.List;
@@ -64,6 +65,8 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
64 65
             getSupportActionBar().setDisplayShowTitleEnabled(false);
65 66
         }
66 67
 
68
+        SoundUtil.initSound(this, R.raw.rfid_error);
69
+
67 70
         presenter = new ScanResultPresenter(getManager(), getAndroidScheduler(), getProcessScheduler());
68 71
         presenter.attachView(this);
69 72
 
@@ -172,6 +175,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
172 175
             binding.tvProfileStatus.setText(R.string.label_status_passed);
173 176
             binding.llProfileStatus.setBackgroundColor(getResources().getColor(R.color.greenPassed));
174 177
         } else {
178
+            SoundUtil.playSound();
175 179
             if (dataResultRfid.getAlertType() != null) {
176 180
                 if (dataResultRfid.getAlertType().equalsIgnoreCase("ERROR")) {
177 181
                     binding.tvProfileStatus.setText(R.string.label_status_not_passed);

+ 1 - 2
app/src/main/java/com/fusi24/entryPermitScanner/ui/setting/SettingActivity.java

@@ -30,7 +30,7 @@ public class SettingActivity extends BaseActivity {
30 30
     private List<DataSerialPort> serialPortList;
31 31
     private List<DataDirectURL> directURLList;
32 32
     private ActivitySettingBinding binding;
33
-    private boolean isFromLogin = false;
33
+    boolean isFromLogin = false;
34 34
 
35 35
     @Override
36 36
     protected void onCreate(Bundle savedInstanceState) {
@@ -174,7 +174,6 @@ public class SettingActivity extends BaseActivity {
174 174
     @Override
175 175
     protected void onDestroy() {
176 176
         super.onDestroy();
177
-        System.out.println("DEVELOPER Setting onDestroy");
178 177
         binding = null;
179 178
     }
180 179
 }

+ 29 - 0
app/src/main/java/com/fusi24/entryPermitScanner/util/SoundUtil.java

@@ -0,0 +1,29 @@
1
+package com.fusi24.entryPermitScanner.util;
2
+
3
+import android.content.Context;
4
+import android.media.AudioAttributes;
5
+import android.media.SoundPool;
6
+
7
+public class SoundUtil {
8
+
9
+  protected static int soundid;
10
+  protected static SoundPool soundpool = null;
11
+  protected static AudioAttributes attributes = null;
12
+
13
+  public static void initSound(Context context, Integer soundId){
14
+    attributes = new AudioAttributes.Builder()
15
+            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
16
+            .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT)
17
+            .build();
18
+
19
+    soundpool = new SoundPool.Builder()
20
+            .setMaxStreams(1)
21
+            .setAudioAttributes(attributes)
22
+            .build();
23
+    soundid = soundpool.load(context, soundId, 1);
24
+  }
25
+
26
+  public static void playSound(){
27
+    soundpool.play(soundid, 1, 1, 0, 0, 1);
28
+  }
29
+}

+ 1 - 1
app/src/main/res/layout/activity_home.xml

@@ -245,7 +245,7 @@
245 245
                             android:textSize="14sp"
246 246
                             android:visibility="visible"
247 247
                             android:layout_gravity="start"
248
-                            app:on="false"
248
+                            app:on="true"
249 249
                             app:colorOn="@color/colorPrimary"
250 250
                             app:colorOff="@color/colorWhite"
251 251
                             app:colorDisabled="@color/backgroundLayoutGreyDark"

BIN
app/src/main/res/raw/error_yamete.ogg


BIN
app/src/main/res/raw/rfid_error.ogg