Sfoglia il codice sorgente

-Add config dynamic for service URL
-Make default to Serial Port 3 and Production URL

ilhamitubagoes 4 anni fa
parent
commit
ce034b9252

+ 1 - 1
app/src/main/java/com/fusi24/entryPermitScanner/base/BaseActivity.java

@@ -21,7 +21,7 @@ public abstract class BaseActivity extends AppCompatActivity {
21 21
 
22 22
     public RestService getRestService() {
23 23
         if (restService == null) {
24
-            restService = RestServiceFactory.create(getJwtToken());
24
+            restService = RestServiceFactory.create(getJwtToken(), this);
25 25
         }
26 26
         return restService;
27 27
     }

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

@@ -29,29 +29,16 @@ public final class Constant {
29 29
 
30 30
     /*===================================================================================================*/
31 31
 
32
-    //Direct ke BCUI
33
-    public final static String BASE_URL = "http://bcui2.fusi24.com";
32
+    //Direct API Service
33
+    public final static String BASE_URL_DEV = "http://bcui2.fusi24.com"; // Development
34
+    public final static String BASE_URL_PROD = "http://hseautomation.beraucoal.co.id"; // Production
34 35
 
35 36
     public final static String BEATS_ENDPOINT = "/beats";
36 37
     public final static String BEATS2_ENDPOINT = "/beats2";
37
-    public final static String SID_ENDPOINT = "/sid";
38 38
     public final static String SID2_ENDPOINT = "/sid2";
39
-    public final static String RFID_ENDPOINT = "/rfid";
40 39
     public final static String RFID_NEW_ENDPOINT = "/new/rfid";
41 40
 
42
-    public static final String URL_PHOTO = BASE_URL + BEATS2_ENDPOINT + "/file?path=";
43
-
44
-    //Direct ke Production
45
-    /*public final static String BASE_URL = "http://hseautomation.beraucoal.co.id";
46
-
47
-    public final static String BEATS_ENDPOINT = "/beats";
48
-    public final static String BEATS2_ENDPOINT = "/beats2";
49
-    public final static String SID_ENDPOINT = "/sid";
50
-    public final static String SID2_ENDPOINT = "/sid2";
51
-    public final static String RFID_ENDPOINT = "/rfid";
52
-    public final static String RFID_NEW_ENDPOINT = "/new/rfid";
53
-
54
-    public static final String URL_PHOTO = BASE_URL + BEATS2_ENDPOINT + "/file?path=";*/
41
+    public static final String URL_PHOTO = BEATS2_ENDPOINT + "/file?path=";
55 42
 
56 43
     /*===================================================================================================*/
57 44
 

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

@@ -14,6 +14,7 @@ public class SessionManager {
14 14
     private static final String USER_RFID_NUMBER        = "user_rfid_number";
15 15
     private static final String GATE                    = "gate";
16 16
     private static final String IS_SERIALPORT_2         = "serial_port_2";
17
+    private static final String IS_DEVELOPMENT          = "development";
17 18
 
18 19
     private final SharedPreferences preferences;
19 20
 
@@ -121,6 +122,16 @@ public class SessionManager {
121 122
         editor.apply();
122 123
     }
123 124
 
125
+    public Boolean isDevelopment() {
126
+        return preferences.getBoolean(IS_DEVELOPMENT, false);
127
+    }
128
+
129
+    public void setIsDevelopment(Boolean isDevelopment) {
130
+        SharedPreferences.Editor editor = preferences.edit();
131
+        editor.putBoolean(IS_DEVELOPMENT, isDevelopment);
132
+        editor.apply();
133
+    }
134
+
124 135
     public void clearData() {
125 136
         SharedPreferences.Editor editor = preferences.edit();
126 137
         editor.remove(IS_LOGIN);

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

@@ -1,9 +1,13 @@
1 1
 package com.fusi24.entryPermitScanner.data.api;
2 2
 
3
+import android.content.Context;
4
+
3 5
 import androidx.annotation.NonNull;
4 6
 
5 7
 import com.fusi24.entryPermitScanner.BuildConfig;
6 8
 import com.fusi24.entryPermitScanner.config.Constant;
9
+import com.fusi24.entryPermitScanner.data.SessionManager;
10
+import com.fusi24.entryPermitScanner.util.Helper;
7 11
 import com.google.gson.Gson;
8 12
 import com.google.gson.GsonBuilder;
9 13
 
@@ -16,19 +20,30 @@ import retrofit2.converter.gson.GsonConverterFactory;
16 20
 
17 21
 public class RestServiceFactory {
18 22
 
19
-    public static RestService create(String token) {
23
+    public static RestService create(String token, Context context) {
20 24
         OkHttpClient client = makeClientService(makeLoggingInterceptor(), token);
21
-        return makeRestService(client, makeGson());
25
+        return makeRestService(client, makeGson(), context);
22 26
     }
23 27
 
24
-    private static RestService makeRestService(OkHttpClient okHttp, Gson gson) {
28
+    private static RestService makeRestService(OkHttpClient okHttp, Gson gson, Context context) {
25 29
 
26
-        Retrofit retrofit = new Retrofit.Builder()
27
-                .baseUrl(Constant.BASE_URL)
28
-                .client(okHttp)
29
-                .addConverterFactory(GsonConverterFactory.create(gson))
30
-                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
31
-                .build();
30
+        Retrofit retrofit;
31
+        SessionManager session = new SessionManager(Helper.getDefaultPreferences(context));
32
+        if (session.isDevelopment()){
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 {
40
+            retrofit = new Retrofit.Builder()
41
+                    .baseUrl(Constant.BASE_URL_PROD)
42
+                    .client(okHttp)
43
+                    .addConverterFactory(GsonConverterFactory.create(gson))
44
+                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
45
+                    .build();
46
+        }
32 47
         return retrofit.create(RestService.class);
33 48
     }
34 49
 

+ 38 - 0
app/src/main/java/com/fusi24/entryPermitScanner/data/entity/DataDirectURL.java

@@ -0,0 +1,38 @@
1
+package com.fusi24.entryPermitScanner.data.entity;
2
+
3
+import org.jetbrains.annotations.NotNull;
4
+
5
+public class DataDirectURL {
6
+
7
+    private Integer id;
8
+    private String name;
9
+
10
+    public DataDirectURL() {}
11
+
12
+    public DataDirectURL(Integer id, String name) {
13
+        this.id = id;
14
+        this.name = name;
15
+    }
16
+
17
+    public Integer getId() {
18
+        return id;
19
+    }
20
+
21
+    public void setId(Integer id) {
22
+        this.id = id;
23
+    }
24
+
25
+    public String getName() {
26
+        return name;
27
+    }
28
+
29
+    public void setName(String name) {
30
+        this.name = name;
31
+    }
32
+
33
+    @NotNull
34
+    @Override
35
+    public String toString() {
36
+        return name;
37
+    }
38
+}

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

@@ -46,6 +46,7 @@ public class LoginActivity extends LFScanProcessing implements LoginView {
46 46
     private void initEvent() {
47 47
         binding.ivIconScan.setOnClickListener(v -> {
48 48
             Intent intent = new Intent(this, SettingActivity.class);
49
+            intent.putExtra(SettingActivity.IS_FROM_LOGIN, true);
49 50
             startActivity(intent);
50 51
         });
51 52
     }
@@ -123,5 +124,6 @@ public class LoginActivity extends LFScanProcessing implements LoginView {
123 124
     protected void onDestroy() {
124 125
         super.onDestroy();
125 126
         presenter.detachView();
127
+        binding = null;
126 128
     }
127 129
 }

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

@@ -62,8 +62,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
62 62
             getSupportActionBar().setDisplayShowTitleEnabled(false);
63 63
         }
64 64
 
65
-        presenter = new ScanResultPresenter(
66
-                getManager(), getAndroidScheduler(), getProcessScheduler());
65
+        presenter = new ScanResultPresenter(getManager(), getAndroidScheduler(), getProcessScheduler());
67 66
         presenter.attachView(this);
68 67
 
69 68
         if (getIntent() != null) {
@@ -144,7 +143,11 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
144 143
     public void showDataRfid(DataResultRfid dataResultRfid) {
145 144
 
146 145
         if (dataResultRfid.getEmployee() != null) {
147
-            dataUrl = Constant.URL_PHOTO + dataResultRfid.getEmployee().getUrlPhoto().substring(14);
146
+            if (getSessionManager().isDevelopment()){
147
+                dataUrl = Constant.BASE_URL_DEV + Constant.URL_PHOTO + dataResultRfid.getEmployee().getUrlPhoto().substring(14);
148
+            } else {
149
+                dataUrl = Constant.BASE_URL_PROD + Constant.URL_PHOTO + dataResultRfid.getEmployee().getUrlPhoto().substring(14);
150
+            }
148 151
 
149 152
             binding.tvProfileName.setText(dataResultRfid.getEmployee().getName());
150 153
             binding.tvStructuralPosition.setText(dataResultRfid.getEmployee().getStructuralPosition().getName());

+ 67 - 0
app/src/main/java/com/fusi24/entryPermitScanner/ui/setting/SettingActivity.java

@@ -1,27 +1,36 @@
1 1
 package com.fusi24.entryPermitScanner.ui.setting;
2 2
 
3
+import android.content.Intent;
3 4
 import android.os.Bundle;
4 5
 import android.view.MenuItem;
5 6
 import android.view.View;
6 7
 import android.widget.AdapterView;
7 8
 import android.widget.ArrayAdapter;
8 9
 import android.widget.TextView;
10
+import android.widget.Toast;
9 11
 
10 12
 import androidx.appcompat.widget.Toolbar;
11 13
 
12 14
 import com.fusi24.entryPermitScanner.R;
13 15
 import com.fusi24.entryPermitScanner.base.BaseActivity;
16
+import com.fusi24.entryPermitScanner.data.entity.DataDirectURL;
14 17
 import com.fusi24.entryPermitScanner.data.entity.DataSerialPort;
15 18
 import com.fusi24.entryPermitScanner.databinding.ActivitySettingBinding;
19
+import com.fusi24.entryPermitScanner.ui.home.HomeActivity;
20
+import com.fusi24.entryPermitScanner.ui.login.LoginActivity;
16 21
 
17 22
 import java.util.ArrayList;
18 23
 import java.util.List;
19 24
 
20 25
 public class SettingActivity extends BaseActivity {
21 26
 
27
+    public static final String IS_FROM_LOGIN = "is_from_login"; // <== To define from Login Page or Home Page
22 28
     private DataSerialPort dataSerialPort;
29
+    private DataDirectURL dataDirectURL;
23 30
     private List<DataSerialPort> serialPortList;
31
+    private List<DataDirectURL> directURLList;
24 32
     private ActivitySettingBinding binding;
33
+    private boolean isFromLogin = false;
25 34
 
26 35
     @Override
27 36
     protected void onCreate(Bundle savedInstanceState) {
@@ -29,6 +38,7 @@ public class SettingActivity extends BaseActivity {
29 38
         binding = ActivitySettingBinding.inflate(getLayoutInflater());
30 39
         View view = binding.getRoot();
31 40
         setContentView(view);
41
+        System.out.println("DEVELOPER Setting onCreate");
32 42
 
33 43
         Toolbar toolbar = findViewById(R.id.toolbar);
34 44
         TextView toolbarTitle = findViewById(R.id.toolbar_text);
@@ -43,10 +53,17 @@ public class SettingActivity extends BaseActivity {
43 53
             getSupportActionBar().setDisplayHomeAsUpEnabled(true);
44 54
         }
45 55
 
56
+        if (getIntent().getExtras() != null){
57
+            isFromLogin = getIntent().getExtras().getBoolean(IS_FROM_LOGIN);
58
+        }
59
+
46 60
         dataSerialPort = new DataSerialPort();
61
+        dataDirectURL = new DataDirectURL();
47 62
         serialPortList = new ArrayList<>();
63
+        directURLList = new ArrayList<>();
48 64
 
49 65
         getDataSerialPort();
66
+        getDataDirectURL();
50 67
         initEvent();
51 68
     }
52 69
 
@@ -56,6 +73,12 @@ public class SettingActivity extends BaseActivity {
56 73
         setDataSerialPort();
57 74
     }
58 75
 
76
+    private void getDataDirectURL() {
77
+        directURLList.add(new DataDirectURL(1, "Development"));
78
+        directURLList.add(new DataDirectURL(2, "Production"));
79
+        setDataDirectURL();
80
+    }
81
+
59 82
 
60 83
     private void setDataSerialPort(){
61 84
         ArrayAdapter<DataSerialPort> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, serialPortList);
@@ -67,6 +90,16 @@ public class SettingActivity extends BaseActivity {
67 90
         }
68 91
     }
69 92
 
93
+    private void setDataDirectURL(){
94
+        ArrayAdapter<DataDirectURL> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, directURLList);
95
+        binding.spinnerDirectUrl.setAdapter(adapter);
96
+        if (getSessionManager().isDevelopment()){
97
+            binding.spinnerDirectUrl.setSelection(0);
98
+        } else {
99
+            binding.spinnerDirectUrl.setSelection(1);
100
+        }
101
+    }
102
+
70 103
     private void initEvent(){
71 104
 
72 105
         binding.spinnerSerialPort.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@@ -81,12 +114,45 @@ public class SettingActivity extends BaseActivity {
81 114
             }
82 115
         });
83 116
 
117
+        binding.spinnerDirectUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
118
+            @Override
119
+            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
120
+                dataDirectURL = (DataDirectURL) parent.getItemAtPosition(position);
121
+            }
122
+
123
+            @Override
124
+            public void onNothingSelected(AdapterView<?> parent) {
125
+                dataDirectURL = (DataDirectURL) parent.getSelectedItem();
126
+            }
127
+        });
128
+
84 129
         binding.btnScan.setOnClickListener(v -> {
130
+
131
+            Toast.makeText(this, dataSerialPort.getName() + " " + dataDirectURL.getName(), Toast.LENGTH_LONG).show();
132
+
133
+            // ID 1 ==> Serial Port 2
85 134
             if (dataSerialPort.getId() == 1){
86 135
                 getSessionManager().setIsSerialport2(true);
87 136
             } else {
88 137
                 getSessionManager().setIsSerialport2(false);
89 138
             }
139
+
140
+            // ID 1 ==> Development
141
+            if (dataDirectURL.getId() == 1){
142
+                getSessionManager().setIsDevelopment(true);
143
+            } else {
144
+                getSessionManager().setIsDevelopment(false);
145
+            }
146
+
147
+            Intent intent;
148
+            if (isFromLogin){
149
+                intent = new Intent(this, LoginActivity.class);
150
+            } else {
151
+                intent = new Intent(this, HomeActivity.class);
152
+            }
153
+            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
154
+            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
155
+            startActivity(intent);
90 156
             finish();
91 157
         });
92 158
     }
@@ -108,6 +174,7 @@ public class SettingActivity extends BaseActivity {
108 174
     @Override
109 175
     protected void onDestroy() {
110 176
         super.onDestroy();
177
+        System.out.println("DEVELOPER Setting onDestroy");
111 178
         binding = null;
112 179
     }
113 180
 }

File diff suppressed because it is too large
+ 40 - 78
app/src/main/res/drawable/ic_scan_card.xml


+ 12 - 2
app/src/main/res/layout/activity_login.xml

@@ -17,19 +17,29 @@
17 17
     <ImageView
18 18
         android:id="@+id/iv_icon_scan"
19 19
         android:layout_width="match_parent"
20
-        android:layout_height="400dp"
20
+        android:layout_height="250dp"
21 21
         android:src="@drawable/ic_scan_card"
22 22
         android:layout_below="@+id/tv_login_note"
23 23
         android:layout_alignParentStart="true"
24 24
         android:layout_alignParentEnd="true"
25 25
         android:layout_marginStart="0dp"
26
-        android:layout_marginTop="0dp"
26
+        android:layout_marginTop="32dp"
27 27
         android:layout_marginEnd="0dp"
28 28
         android:layout_marginBottom="0dp"
29 29
         android:gravity="center"
30 30
         android:contentDescription="@string/cd_image" />
31 31
 
32 32
     <TextView
33
+        android:id="@+id/tv_note"
34
+        style="@style/MyTextData"
35
+        android:layout_below="@id/iv_icon_scan"
36
+        android:layout_marginTop="24dp"
37
+        android:layout_width="match_parent"
38
+        android:layout_height="wrap_content"
39
+        android:gravity="center"
40
+        android:text="@string/label_tap_to_setting" />
41
+
42
+    <TextView
33 43
         android:id="@+id/tv_company_label"
34 44
         style="@style/BottomText"
35 45
         android:layout_width="match_parent"

+ 30 - 3
app/src/main/res/layout/activity_setting.xml

@@ -14,7 +14,7 @@
14 14
         android:layout_height="match_parent">
15 15
 
16 16
         <TextView
17
-            android:id="@+id/tv_title_label"
17
+            android:id="@+id/tv_serial_label"
18 18
             android:layout_width="match_parent"
19 19
             android:layout_height="wrap_content"
20 20
             android:layout_alignParentStart="true"
@@ -30,7 +30,34 @@
30 30
             android:id="@+id/spinner_serial_port"
31 31
             android:layout_width="match_parent"
32 32
             android:layout_height="wrap_content"
33
-            android:layout_below="@+id/tv_title_label"
33
+            android:layout_below="@+id/tv_serial_label"
34
+            android:layout_alignParentStart="true"
35
+            android:layout_alignParentEnd="true"
36
+            android:layout_marginStart="16dp"
37
+            android:layout_marginTop="8dp"
38
+            android:layout_marginEnd="16dp"
39
+            android:layout_marginBottom="0dp"
40
+            style="@style/spinner_style" />
41
+
42
+        <TextView
43
+            android:id="@+id/tv_service_label"
44
+            android:layout_width="match_parent"
45
+            android:layout_height="wrap_content"
46
+            android:layout_below="@+id/spinner_serial_port"
47
+            android:layout_alignParentStart="true"
48
+            android:layout_alignParentEnd="true"
49
+            android:layout_marginTop="16dp"
50
+            android:layout_marginStart="16dp"
51
+            android:layout_marginEnd="16dp"
52
+            android:gravity="start"
53
+            style="@style/MyTextLabel"
54
+            android:text="@string/label_direct_url"/>
55
+
56
+        <androidx.appcompat.widget.AppCompatSpinner
57
+            android:id="@+id/spinner_direct_url"
58
+            android:layout_width="match_parent"
59
+            android:layout_height="wrap_content"
60
+            android:layout_below="@+id/tv_service_label"
34 61
             android:layout_alignParentStart="true"
35 62
             android:layout_alignParentEnd="true"
36 63
             android:layout_marginStart="16dp"
@@ -44,7 +71,7 @@
44 71
             style="@style/ButtonCommon"
45 72
             android:layout_width="match_parent"
46 73
             android:layout_height="wrap_content"
47
-            android:layout_below="@+id/spinner_serial_port"
74
+            android:layout_below="@+id/spinner_direct_url"
48 75
             android:layout_alignParentStart="true"
49 76
             android:layout_alignParentEnd="true"
50 77
             android:layout_marginStart="16dp"

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -8,11 +8,13 @@
8 8
     <string name="label_btn_scan">Start Scanning</string>
9 9
     <string name="label_info_scan">Tempelkan RFID Gun \n pada RFID Card</string>
10 10
     <string name="label_login_scan">Tempelkan \n RFID Card untuk login</string>
11
+    <string name="label_tap_to_setting">Klik gambar untuk pengaturan device</string>
11 12
     <string name="label_more_options">More Options</string>
12 13
     <string name="label_app_version">App version</string>
13 14
     <string name="label_logout">Keluar</string>
14 15
     <string name="label_setting">Pengaturan Device</string>
15 16
     <string name="label_serial_port">Serial Port</string>
17
+    <string name="label_direct_url">Direct URL</string>
16 18
     <string name="label_save">Simpan</string>
17 19
     <string name="label_home">Home</string>
18 20
     <string name="label_scan_other">Scan Other</string>