Pārlūkot izejas kodu

Penambahan URL Staging

ilhamitubagoes 4 gadi atpakaļ
vecāks
revīzija
76ef11dee1

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

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

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

@@ -25,6 +25,7 @@ public class SessionManager {
25 25
     private static final String PERMIT_LIST             = "permit_list";
26 26
     private static final String IS_SERIALPORT_2         = "serial_port_2";
27 27
     private static final String IS_DEVELOPMENT          = "development";
28
+    private static final String DATA_DIRECT_ID          = "data_direct_id";
28 29
 
29 30
     private final SharedPreferences preferences;
30 31
 
@@ -178,6 +179,16 @@ public class SessionManager {
178 179
         editor.apply();
179 180
     }
180 181
 
182
+    public Integer getDataDirectId() {
183
+        return preferences.getInt(DATA_DIRECT_ID, 1); // 1 For Development ==> BCUI
184
+    }
185
+
186
+    public void setDataDirectId(Integer dataDirectId) {
187
+        SharedPreferences.Editor editor = preferences.edit();
188
+        editor.putInt(DATA_DIRECT_ID, dataDirectId);
189
+        editor.apply();
190
+    }
191
+
181 192
     public void clearData() {
182 193
         SharedPreferences.Editor editor = preferences.edit();
183 194
         editor.remove(IS_LOGIN);

+ 9 - 2
app/src/main/java/com/fusi24/entryPermitScanner/data/api/RestServiceFactory.java

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

+ 3 - 1
app/src/main/java/com/fusi24/entryPermitScanner/ui/scanresult/ScanResultActivity.java

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

+ 22 - 9
app/src/main/java/com/fusi24/entryPermitScanner/ui/setting/SettingActivity.java

@@ -22,6 +22,8 @@ import com.fusi24.entryPermitScanner.ui.login.LoginActivity;
22 22
 import java.util.ArrayList;
23 23
 import java.util.List;
24 24
 
25
+import timber.log.Timber;
26
+
25 27
 public class SettingActivity extends BaseActivity {
26 28
 
27 29
     public static final String IS_FROM_LOGIN = "is_from_login"; // <== To define from Login Page or Home Page
@@ -75,7 +77,8 @@ public class SettingActivity extends BaseActivity {
75 77
 
76 78
     private void getDataDirectURL() {
77 79
         directURLList.add(new DataDirectURL(1, "Development"));
78
-        directURLList.add(new DataDirectURL(2, "Production"));
80
+        directURLList.add(new DataDirectURL(2, "Staging"));
81
+        directURLList.add(new DataDirectURL(3, "Production"));
79 82
         setDataDirectURL();
80 83
     }
81 84
 
@@ -93,10 +96,16 @@ public class SettingActivity extends BaseActivity {
93 96
     private void setDataDirectURL(){
94 97
         ArrayAdapter<DataDirectURL> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, directURLList);
95 98
         binding.spinnerDirectUrl.setAdapter(adapter);
96
-        if (getSessionManager().isDevelopment()){
97
-            binding.spinnerDirectUrl.setSelection(0);
98
-        } else {
99
-            binding.spinnerDirectUrl.setSelection(1);
99
+        switch (getSessionManager().getDataDirectId()){
100
+            case 1:
101
+                binding.spinnerDirectUrl.setSelection(0);
102
+                break;
103
+            case 2:
104
+                binding.spinnerDirectUrl.setSelection(1);
105
+                break;
106
+            case 3:
107
+                binding.spinnerDirectUrl.setSelection(2);
108
+                break;
100 109
         }
101 110
     }
102 111
 
@@ -137,11 +146,15 @@ public class SettingActivity extends BaseActivity {
137 146
                 getSessionManager().setIsSerialport2(false);
138 147
             }
139 148
 
140
-            // ID 1 ==> Development
141
-            if (dataDirectURL.getId() == 1){
142
-                getSessionManager().setIsDevelopment(true);
149
+            // DATA DIRECT URL
150
+            // ID 1 ==> DEV
151
+            // ID 2 ==> STAGING
152
+            // ID 3 ==> PRODUCTION
153
+            if (dataDirectURL.getId() != null){
154
+                Timber.i("Data Direct ID : %s", dataDirectURL.getId());
155
+                getSessionManager().setDataDirectId(dataDirectURL.getId());
143 156
             } else {
144
-                getSessionManager().setIsDevelopment(false);
157
+                Timber.i("Data URL NULL");
145 158
             }
146 159
 
147 160
             Intent intent;