Procházet zdrojové kódy

Penambahan data serial port menjadi 3 untuk 3 device yang berbeda di BC
Menghilangkan URL Development (bcui.fusi24.com)

ilhamitubagoes před 3 roky
rodič
revize
554c4309c4

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

@@ -19,18 +19,21 @@ public final class Constant {
19 19
 
20 20
     /*===================================================================================================*/
21 21
 
22
-    // SERIAL PORT ttyS2 BUAT TEST DEVICE di FUSI
23
-    public final static String PATH_SP2 = "/dev/ttyS2";
24
-    public final static String PATHNAME_SP2 = "/proc/gpiocontrol/set_id";
22
+    // SERIAL PORT Device V1
23
+    public final static String PATH_SP1 = "/dev/ttyS2";
24
+    public final static String PATHNAME_SP1 = "/proc/gpiocontrol/set_id";
25 25
 
26
-    // SERIAL PORT ttyS3 BUAT TEST DEVICE di BERAU COAL
27
-    public final static String PATH_SP3 = "/dev/ttyS3"; // Untuk versi 3.0
28
-    public final static String PATHNAME_SP3 = "/proc/gpiocontrol/set_sam"; // untuk versi 3.0
26
+    // SERIAL PORT Device V2 (Lecom U8000)
27
+    public final static String PATH_SP2 = "/dev/ttyS3";
28
+    public final static String PATHNAME_SP2 = "/proc/gpiocontrol/set_sam";
29
+
30
+    // SERIAL PORT Device V2 (Lecom U9000)
31
+    public final static String PATH_SP3 = "/dev/ttyS3";
32
+    public final static String PATHNAME_SP3 = "/proc/gpiocontrol/set_id";
29 33
 
30 34
     /*===================================================================================================*/
31 35
 
32 36
     //Direct API Service
33
-    public final static String BASE_URL_DEV = "https://bcui2.fusi24.com"; // Development
34 37
     public final static String BASE_URL_STAGING = "http://beats-dev.beraucoal.co.id"; // Development
35 38
     public final static String BASE_URL_PROD = "http://hseautomation.beraucoal.co.id"; // Production
36 39
 

+ 5 - 16
app/src/main/java/com/fusi24/entryPermitScanner/data/SessionManager.java

@@ -23,8 +23,7 @@ public class SessionManager {
23 23
     private static final String GATE                    = "gate";
24 24
     private static final String SITE_LIST               = "site_list";
25 25
     private static final String PERMIT_LIST             = "permit_list";
26
-    private static final String IS_SERIALPORT_2         = "serial_port_2";
27
-    private static final String IS_DEVELOPMENT          = "development";
26
+    private static final String DATA_SERIAL_PORT        = "serial_port_2";
28 27
     private static final String DATA_DIRECT_ID          = "data_direct_id";
29 28
 
30 29
     private final SharedPreferences preferences;
@@ -159,23 +158,13 @@ public class SessionManager {
159 158
         editor.apply();
160 159
     }
161 160
 
162
-    public Boolean isSerialPort2() {
163
-        return preferences.getBoolean(IS_SERIALPORT_2, false);
161
+    public Integer getDataSerialPort() {
162
+        return preferences.getInt(DATA_SERIAL_PORT, 1);
164 163
     }
165 164
 
166
-    public void setIsSerialport2(Boolean isSerialport2) {
165
+    public void setDataSerialPort(Integer serialPort) {
167 166
         SharedPreferences.Editor editor = preferences.edit();
168
-        editor.putBoolean(IS_SERIALPORT_2, isSerialport2);
169
-        editor.apply();
170
-    }
171
-
172
-    public Boolean isDevelopment() {
173
-        return preferences.getBoolean(IS_DEVELOPMENT, false);
174
-    }
175
-
176
-    public void setIsDevelopment(Boolean isDevelopment) {
177
-        SharedPreferences.Editor editor = preferences.edit();
178
-        editor.putBoolean(IS_DEVELOPMENT, isDevelopment);
167
+        editor.putInt(DATA_SERIAL_PORT, serialPort);
179 168
         editor.apply();
180 169
     }
181 170
 

+ 1 - 8
app/src/main/java/com/fusi24/entryPermitScanner/data/api/RestServiceFactory.java

@@ -29,14 +29,7 @@ public class RestServiceFactory {
29 29
 
30 30
         Retrofit retrofit;
31 31
         SessionManager session = new SessionManager(Helper.getDefaultPreferences(context));
32
-        if (session.getDataDirectId() == 1){ // DEVELOPMENT
33
-            retrofit = new Retrofit.Builder()
34
-                    .baseUrl(Constant.BASE_URL_DEV)
35
-                    .client(okHttp)
36
-                    .addConverterFactory(GsonConverterFactory.create(gson))
37
-                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
38
-                    .build();
39
-        } else if (session.getDataDirectId() == 2) { // STAGING
32
+       if (session.getDataDirectId() == 1) { // STAGING
40 33
             retrofit = new Retrofit.Builder()
41 34
                     .baseUrl(Constant.BASE_URL_STAGING)
42 35
                     .client(okHttp)

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

@@ -228,8 +228,6 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
228 228
     public void showDataPermit(DataWorkingPermit dataWorkingPermit) {
229 229
         if (dataWorkingPermit.getEmployee() != null) {
230 230
             if (getSessionManager().getDataDirectId() == 1){
231
-                dataUrl = Constant.BASE_URL_DEV + Constant.URL_PHOTO + dataWorkingPermit.getEmployee().getUrlPhoto().substring(14);
232
-            } else if (getSessionManager().getDataDirectId() == 1){
233 231
                 dataUrl = Constant.BASE_URL_STAGING + Constant.URL_PHOTO + dataWorkingPermit.getEmployee().getUrlPhoto().substring(14);
234 232
             } else {
235 233
                 dataUrl = Constant.BASE_URL_PROD + Constant.URL_PHOTO + dataWorkingPermit.getEmployee().getUrlPhoto().substring(14);

+ 19 - 16
app/src/main/java/com/fusi24/entryPermitScanner/ui/setting/SettingActivity.java

@@ -70,15 +70,15 @@ public class SettingActivity extends BaseActivity {
70 70
     }
71 71
 
72 72
     private void getDataSerialPort() {
73
-        serialPortList.add(new DataSerialPort(1, "Serial Port 2"));
74
-        serialPortList.add(new DataSerialPort(2, "Serial Port 3"));
73
+        serialPortList.add(new DataSerialPort(1, "Serial Port 1"));
74
+        serialPortList.add(new DataSerialPort(2, "Serial Port 2"));
75
+        serialPortList.add(new DataSerialPort(3, "Serial Port 3"));
75 76
         setDataSerialPort();
76 77
     }
77 78
 
78 79
     private void getDataDirectURL() {
79 80
         directURLList.add(new DataDirectURL(1, "Development"));
80
-        directURLList.add(new DataDirectURL(2, "Staging"));
81
-        directURLList.add(new DataDirectURL(3, "Production"));
81
+        directURLList.add(new DataDirectURL(2, "Production"));
82 82
         setDataDirectURL();
83 83
     }
84 84
 
@@ -86,10 +86,16 @@ public class SettingActivity extends BaseActivity {
86 86
     private void setDataSerialPort(){
87 87
         ArrayAdapter<DataSerialPort> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, serialPortList);
88 88
         binding.spinnerSerialPort.setAdapter(adapter);
89
-        if (getSessionManager().isSerialPort2()){
90
-            binding.spinnerSerialPort.setSelection(0);
91
-        } else {
92
-            binding.spinnerSerialPort.setSelection(1);
89
+        switch (getSessionManager().getDataSerialPort()){
90
+            case 1:
91
+                binding.spinnerSerialPort.setSelection(0);
92
+                break;
93
+            case 2:
94
+                binding.spinnerSerialPort.setSelection(1);
95
+                break;
96
+            case 3:
97
+                binding.spinnerSerialPort.setSelection(2);
98
+                break;
93 99
         }
94 100
     }
95 101
 
@@ -103,9 +109,6 @@ public class SettingActivity extends BaseActivity {
103 109
             case 2:
104 110
                 binding.spinnerDirectUrl.setSelection(1);
105 111
                 break;
106
-            case 3:
107
-                binding.spinnerDirectUrl.setSelection(2);
108
-                break;
109 112
         }
110 113
     }
111 114
 
@@ -140,16 +143,16 @@ public class SettingActivity extends BaseActivity {
140 143
             Toast.makeText(this, dataSerialPort.getName() + " " + dataDirectURL.getName(), Toast.LENGTH_LONG).show();
141 144
 
142 145
             // ID 1 ==> Serial Port 2
143
-            if (dataSerialPort.getId() == 1){
144
-                getSessionManager().setIsSerialport2(true);
146
+            if (dataSerialPort.getId() != null){
147
+                Timber.i("Data Serial Port : %s", dataSerialPort.getId());
148
+                getSessionManager().setDataSerialPort(dataSerialPort.getId());
145 149
             } else {
146
-                getSessionManager().setIsSerialport2(false);
150
+                Timber.i("Data Serial Port Null");
147 151
             }
148 152
 
149 153
             // DATA DIRECT URL
150 154
             // ID 1 ==> DEV
151
-            // ID 2 ==> STAGING
152
-            // ID 3 ==> PRODUCTION
155
+            // ID 2 ==> PRODUCTION
153 156
             if (dataDirectURL.getId() != null){
154 157
                 Timber.i("Data Direct ID : %s", dataDirectURL.getId());
155 158
                 getSessionManager().setDataDirectId(dataDirectURL.getId());

+ 4 - 14
app/src/main/java/com/fusi24/entryPermitScanner/util/LFScanProcessing.java

@@ -36,28 +36,18 @@ public abstract class LFScanProcessing extends LFSerialPortActivity {
36 36
     @Override
37 37
     protected void onStart() {
38 38
         super.onStart();
39
-
40 39
         // Start Reception
41
-        if (getSessionManager().isSerialPort2()){
42
-            PowerUtil.power("1", true);
43
-        } else {
44
-            // Serial Port 3
45
-            PowerUtil.power("1", false);
46
-        }
40
+        Integer serialPort = getSessionManager().getDataSerialPort();
41
+        PowerUtil.power("1", serialPort);
47 42
         this.open();
48 43
     }
49 44
 
50 45
     @Override
51 46
     protected void onStop() {
52 47
         super.onStop();
53
-
54 48
         // Stop Reception
55 49
         this.close();
56
-        if (getSessionManager().isSerialPort2()){
57
-            PowerUtil.power("0", true);
58
-        } else {
59
-            // Serial Port 3
60
-            PowerUtil.power("0", false);
61
-        }
50
+        Integer serialPort = getSessionManager().getDataSerialPort();
51
+        PowerUtil.power("0", serialPort);
62 52
     }
63 53
 }

+ 4 - 1
app/src/main/java/com/fusi24/entryPermitScanner/util/LFSerialPortActivity.java

@@ -33,6 +33,7 @@ import android_serialport_api.SerialPortTool;
33 33
 
34 34
 public abstract class LFSerialPortActivity extends BaseActivity {
35 35
 
36
+  public static final String PATH_SP1 = Constant.PATH_SP1;
36 37
   public static final String PATH_SP2 = Constant.PATH_SP2;
37 38
   public static final String PATH_SP3 = Constant.PATH_SP3;
38 39
   public static final int BAUTRATE = Constant.BAUTRATE;
@@ -96,7 +97,9 @@ public abstract class LFSerialPortActivity extends BaseActivity {
96 97
 
97 98
     try {
98 99
 
99
-      if (getSessionManager().isSerialPort2()){
100
+      if (getSessionManager().getDataSerialPort() == 1){
101
+        mSerialPort = serialPortTool.getSerialPort(PATH_SP1, BAUTRATE);
102
+      } else if (getSessionManager().getDataSerialPort() == 2) {
100 103
         mSerialPort = serialPortTool.getSerialPort(PATH_SP2, BAUTRATE);
101 104
       } else {
102 105
         mSerialPort = serialPortTool.getSerialPort(PATH_SP3, BAUTRATE);

+ 5 - 3
app/src/main/java/com/fusi24/entryPermitScanner/util/PowerUtil.java

@@ -6,13 +6,15 @@ import java.io.File;
6 6
 import java.io.FileWriter;
7 7
 
8 8
 public class PowerUtil {
9
-  public static void power(String id, Boolean isSerialPort2) {
9
+  public static void power(String id, Integer serialPort) {
10 10
     try {
11 11
       FileWriter localFileWriterOn;
12
-      if (isSerialPort2){
12
+      if (serialPort == 1){
13
+        localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP1));
14
+      } else if (serialPort == 2) {
13 15
         localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP2));
14 16
       } else {
15
-        localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP2));
17
+        localFileWriterOn = new FileWriter(new File(Constant.PATHNAME_SP3));
16 18
       }
17 19
       localFileWriterOn.write(id);
18 20
       localFileWriterOn.close();