Переглянути джерело

-Fixing radio button for status scan
-Fixing orientation

ilhamitubagoes 4 роки тому
батько
коміт
078d3a08fe

+ 9 - 8
app/src/main/AndroidManifest.xml

@@ -11,7 +11,8 @@
11 11
         android:label="@string/app_name"
12 12
         android:roundIcon="@drawable/logo_hse_autimation"
13 13
         android:supportsRtl="true"
14
-        android:theme="@style/AppTheme">
14
+        android:theme="@style/AppTheme"
15
+        android:fullBackupContent="">
15 16
         <activity
16 17
             android:name=".SplashScreenActivity"
17 18
             android:screenOrientation="fullSensor"
@@ -23,28 +24,28 @@
23 24
         </activity>
24 25
         <activity
25 26
             android:name=".ui.login.LoginActivity"
26
-            android:screenOrientation="fullSensor"
27
+            android:screenOrientation="portrait"
27 28
             android:theme="@style/Theme.AppCompat.Light.NoActionBar">
28 29
         </activity>
29 30
         <activity
30 31
             android:name=".MainActivity"
31
-            android:screenOrientation="fullSensor"
32
+            android:screenOrientation="portrait"
32 33
             android:theme="@style/Theme.AppCompat.Light.NoActionBar">
33 34
         </activity>
34 35
         <activity
35
-            android:name=".HomeActivity"
36
-            android:screenOrientation="fullSensor"
36
+            android:name=".ui.home.HomeActivity"
37
+            android:screenOrientation="portrait"
37 38
             android:theme="@style/Theme.AppCompat.Light.NoActionBar">
38 39
         </activity>
39 40
         <activity
40 41
             android:name=".ui.ScanActivity"
41
-            android:screenOrientation="fullSensor"/>
42
+            android:screenOrientation="portrait"/>
42 43
         <activity
43 44
             android:name=".ui.scanresult.ScanResultActivity"
44
-            android:screenOrientation="fullSensor"/>
45
+            android:screenOrientation="portrait"/>
45 46
         <activity
46 47
             android:name=".ui.login.ErrorLoginActivity"
47
-            android:screenOrientation="fullSensor"
48
+            android:screenOrientation="portrait"
48 49
             android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
49 50
     </application>
50 51
 

+ 1 - 0
app/src/main/java/com/fusi24/rfid/SplashScreenActivity.java

@@ -9,6 +9,7 @@ import androidx.annotation.Nullable;
9 9
 
10 10
 import com.fusi24.rfid.base.BaseActivity;
11 11
 import com.fusi24.rfid.data.SessionManager;
12
+import com.fusi24.rfid.ui.home.HomeActivity;
12 13
 import com.fusi24.rfid.ui.login.LoginActivity;
13 14
 
14 15
 public class SplashScreenActivity extends BaseActivity {

+ 80 - 0
app/src/main/java/com/fusi24/rfid/adapter/StatusScanAdapter.java

@@ -0,0 +1,80 @@
1
+package com.fusi24.rfid.adapter;
2
+
3
+import android.content.Context;
4
+import android.view.LayoutInflater;
5
+import android.view.View;
6
+import android.view.ViewGroup;
7
+
8
+import androidx.annotation.NonNull;
9
+import androidx.recyclerview.widget.RecyclerView;
10
+
11
+import com.fusi24.rfid.data.entity.DataDetail;
12
+import com.fusi24.rfid.databinding.RowStatusScanBinding;
13
+
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
17
+public class StatusScanAdapter extends RecyclerView.Adapter<StatusScanAdapter.ViewHolder>{
18
+
19
+    private Context context;
20
+    private List<DataDetail> detailList;
21
+    private OnItemSelected onItemSelected;
22
+    public int selectedItem = -1;
23
+
24
+    public StatusScanAdapter(Context context, OnItemSelected onItemSelected) {
25
+        this.context = context;
26
+        this.detailList = new ArrayList<>();
27
+        this.onItemSelected = onItemSelected;
28
+    }
29
+
30
+    private void setDetailList(List<DataDetail> detailList) {
31
+        this.detailList = detailList;
32
+    }
33
+
34
+    public void updateDetailList(List<DataDetail> detailList){
35
+        setDetailList(detailList);
36
+    }
37
+
38
+    class ViewHolder extends RecyclerView.ViewHolder {
39
+        private RowStatusScanBinding binding;
40
+
41
+        ViewHolder(RowStatusScanBinding itemBinding) {
42
+            super(itemBinding.getRoot());
43
+            this.binding = itemBinding;
44
+
45
+            View.OnClickListener listener = v -> {
46
+                selectedItem = getAdapterPosition();
47
+                onItemSelected.onSelected(detailList.get(getAdapterPosition()).getId());
48
+                notifyDataSetChanged();
49
+            };
50
+
51
+            itemView.setOnClickListener(listener);
52
+            binding.rbCommon.setOnClickListener(listener);
53
+        }
54
+    }
55
+
56
+
57
+    @NonNull
58
+    @Override
59
+    public StatusScanAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
60
+        RowStatusScanBinding itemBinding = RowStatusScanBinding.inflate(LayoutInflater.from(context), parent, false);
61
+        return new ViewHolder(itemBinding);
62
+    }
63
+
64
+    @Override
65
+    public void onBindViewHolder(@NonNull StatusScanAdapter.ViewHolder holder, int position) {
66
+        DataDetail detail = detailList.get(position);
67
+        holder.binding.rbCommon.setText(detail.getName());
68
+        holder.binding.rbCommon.setChecked(position == selectedItem);
69
+    }
70
+
71
+    @Override
72
+    public int getItemCount() {
73
+        return detailList.size();
74
+    }
75
+
76
+    public interface OnItemSelected {
77
+        void onSelected(Integer idStatus);
78
+    }
79
+
80
+}

+ 36 - 35
app/src/main/java/com/fusi24/rfid/HomeActivity.java

@@ -1,4 +1,4 @@
1
-package com.fusi24.rfid;
1
+package com.fusi24.rfid.ui.home;
2 2
 
3 3
 import android.annotation.SuppressLint;
4 4
 import android.content.Intent;
@@ -9,14 +9,18 @@ import android.view.MenuItem;
9 9
 import android.view.View;
10 10
 import android.widget.AdapterView;
11 11
 import android.widget.ArrayAdapter;
12
-import android.widget.LinearLayout;
13
-import android.widget.RadioButton;
14 12
 import android.widget.TextView;
15 13
 import android.widget.Toast;
16 14
 
17 15
 import androidx.annotation.NonNull;
18 16
 import androidx.appcompat.widget.Toolbar;
17
+import androidx.recyclerview.widget.DefaultItemAnimator;
18
+import androidx.recyclerview.widget.LinearLayoutManager;
19 19
 
20
+import com.fusi24.rfid.BuildConfig;
21
+import com.fusi24.rfid.R;
22
+import com.fusi24.rfid.SplashScreenActivity;
23
+import com.fusi24.rfid.adapter.StatusScanAdapter;
20 24
 import com.fusi24.rfid.base.BaseActivity;
21 25
 import com.fusi24.rfid.config.Constant;
22 26
 import com.fusi24.rfid.data.api.RestService;
@@ -36,15 +40,14 @@ import retrofit2.Callback;
36 40
 import retrofit2.Response;
37 41
 import timber.log.Timber;
38 42
 
39
-public class HomeActivity extends BaseActivity implements View.OnClickListener {
43
+public class HomeActivity extends BaseActivity implements StatusScanAdapter.OnItemSelected {
40 44
 
41 45
     private DataEntryPermit dataEntryPermit;
42 46
     private List<DataEntryPermit> entryPermitList;
43 47
     private List<DataDetail> statusScanList;
44 48
     private ActivityHomeBinding binding;
45
-    Toolbar toolbar;
46
-    TextView toolbarTitle;
47
-    RadioButton rb;
49
+    private StatusScanAdapter adapter;
50
+    private Integer idStatus = null;
48 51
 
49 52
     @Override
50 53
     protected void onCreate(Bundle savedInstanceState) {
@@ -53,10 +56,10 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
53 56
         View view = binding.getRoot();
54 57
         setContentView(view);
55 58
 
56
-        toolbar = findViewById(R.id.toolbar);
57
-        toolbarTitle = findViewById(R.id.toolbar_text);
59
+        Toolbar toolbar = findViewById(R.id.toolbar);
60
+        TextView toolbarTitle = findViewById(R.id.toolbar_text);
58 61
 
59
-        if(toolbarTitle!=null && toolbar!=null) {
62
+        if(toolbarTitle !=null && toolbar !=null) {
60 63
             toolbarTitle.setText(getString(R.string.app_name));
61 64
             setSupportActionBar(toolbar);
62 65
         }
@@ -65,10 +68,8 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
65 68
             getSupportActionBar().setDisplayShowTitleEnabled(false);
66 69
         }
67 70
 
68
-        entryPermitList = new ArrayList<>();
69
-        statusScanList = new ArrayList<>();
70
-
71 71
         initView();
72
+        loadingData();
72 73
         getDataPermit();
73 74
         getDataStatusScan();
74 75
     }
@@ -105,8 +106,18 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
105 106
         initEvent();
106 107
     }
107 108
 
108
-    @SuppressLint("SetTextI18n")
109 109
     private void initView(){
110
+        entryPermitList = new ArrayList<>();
111
+        statusScanList = new ArrayList<>();
112
+
113
+        adapter = new StatusScanAdapter(this, this);
114
+        binding.rvStatusScan.setLayoutManager(new LinearLayoutManager(this));
115
+        binding.rvStatusScan.setItemAnimator(new DefaultItemAnimator());
116
+        binding.rvStatusScan.setAdapter(adapter);
117
+    }
118
+
119
+    @SuppressLint("SetTextI18n")
120
+    private void loadingData(){
110 121
         binding.tvRfidGunId.setText("RFID-" + Build.ID + "-" + Build.DEVICE);
111 122
         binding.tvRfidCardNumber.setText(getSessionManager().getUserRfidNumber());
112 123
         binding.tvEmployeeName.setText(getSessionManager().getEmployeeName());
@@ -136,13 +147,16 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
136 147
                 return;
137 148
             }
138 149
 
150
+            if (idStatus == null){
151
+                Toast.makeText(this, "Status Scan Belum Terpilih", Toast.LENGTH_SHORT).show();
152
+                return;
153
+            }
154
+
139 155
             Intent intent = new Intent(this, ScanActivity.class);
140 156
             intent.putExtra(ScanActivity.ID_PERMIT, String.valueOf(dataEntryPermit.getId()));
141 157
             startActivity(intent);
142 158
         });
143 159
 
144
-        binding.rgStatusScan.setOnCheckedChangeListener((group, checkedId) -> Timber.i("DEVELOPER : %s", checkedId));
145
-
146 160
     }
147 161
 
148 162
     private void getDataPermit() {
@@ -173,7 +187,8 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
173 187
             public void onResponse(@NotNull Call<List<DataDetail>> call, @NotNull Response<List<DataDetail>> response) {
174 188
                 if (response.body() != null){
175 189
                     statusScanList.addAll(response.body());
176
-                    setDataStatusScan();
190
+                    adapter.updateDetailList(statusScanList);
191
+                    adapter.notifyDataSetChanged();
177 192
                 }
178 193
             }
179 194
 
@@ -190,17 +205,6 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
190 205
         binding.spinnerPermit.setAdapter(adapter);
191 206
     }
192 207
 
193
-    private void setDataStatusScan(){
194
-        binding.rgStatusScan.setOrientation(LinearLayout.VERTICAL);
195
-        for (int i=0; i<statusScanList.size(); i++){
196
-            rb = new RadioButton(this);
197
-            rb.setId(View.generateViewId());
198
-            rb.setText(statusScanList.get(i).getName());
199
-            rb.setOnClickListener(this);
200
-            binding.rgStatusScan.addView(rb);
201
-        }
202
-    }
203
-
204 208
     @Override
205 209
     protected void onDestroy() {
206 210
         super.onDestroy();
@@ -208,12 +212,9 @@ public class HomeActivity extends BaseActivity implements View.OnClickListener {
208 212
     }
209 213
 
210 214
     @Override
211
-    public void onClick(View v) {
212
-
213
-        rb.setOnClickListener(v1 -> {
214
-            Timber.i("DEVELOPER RB : %s", v1.getId());
215
-        });
216
-
217
-        Timber.tag(HomeActivity.class.getName()).d("DEVELOPER : Name " + ((RadioButton) v).getText() + " Id is " + v.getId());
215
+    public void onSelected(Integer idStatus) {
216
+        this.idStatus = idStatus;
217
+        Timber.tag(HomeActivity.class.getName()).d("DEVELOPER idStatus : %s", idStatus);
218
+        Toast.makeText(this, idStatus.toString(), Toast.LENGTH_SHORT).show();
218 219
     }
219 220
 }

+ 15 - 14
app/src/main/res/layout/activity_home.xml

@@ -4,7 +4,7 @@
4 4
     android:layout_width="match_parent"
5 5
     android:layout_height="wrap_content"
6 6
     android:orientation="vertical"
7
-    tools:context=".HomeActivity">
7
+    tools:context=".ui.home.HomeActivity">
8 8
 
9 9
     <include layout="@layout/default_toolbar"/>
10 10
 
@@ -18,7 +18,6 @@
18 18
             android:layout_marginTop="24dp"
19 19
             android:layout_width="match_parent"
20 20
             android:layout_height="wrap_content"
21
-            android:layout_below="@+id/tv_title_label"
22 21
             android:orientation="horizontal">
23 22
 
24 23
             <TextView
@@ -31,7 +30,7 @@
31 30
                 android:layout_marginRight="2dp"
32 31
                 android:layout_weight="1"
33 32
                 android:textStyle="bold"
34
-                android:text="Nomor RFID Gun" />
33
+                android:text="@string/label_number_rfid" />
35 34
 
36 35
             <TextView
37 36
                 android:id="@+id/tv_rfid_gun_id"
@@ -62,7 +61,7 @@
62 61
                 android:layout_marginRight="2dp"
63 62
                 android:layout_weight="1"
64 63
                 android:textStyle="bold"
65
-                android:text="Nomor RFID Card" />
64
+                android:text="@string/label_number_rfid_card" />
66 65
 
67 66
             <TextView
68 67
                 android:id="@+id/tv_rfid_card_number"
@@ -93,7 +92,7 @@
93 92
                 android:layout_marginRight="2dp"
94 93
                 android:layout_weight="1"
95 94
                 android:textStyle="bold"
96
-                android:text="Nama Karyawan" />
95
+                android:text="@string/label_employee_name" />
97 96
 
98 97
             <TextView
99 98
                 android:id="@+id/tv_employee_name"
@@ -124,7 +123,7 @@
124 123
                 android:layout_marginRight="2dp"
125 124
                 android:layout_weight="1"
126 125
                 android:textStyle="bold"
127
-                android:text="Gate" />
126
+                android:text="@string/label_gate" />
128 127
 
129 128
             <TextView
130 129
                 android:id="@+id/tv_gate_name"
@@ -155,7 +154,7 @@
155 154
                 android:layout_marginRight="2dp"
156 155
                 android:layout_weight="1"
157 156
                 android:textStyle="bold"
158
-                android:text="Site" />
157
+                android:text="@string/label_site" />
159 158
 
160 159
             <TextView
161 160
                 android:id="@+id/tv_site_name"
@@ -179,14 +178,14 @@
179 178
             <TextView
180 179
                 android:textSize="14sp"
181 180
                 android:textColor="@color/colorBlack"
182
-                android:layout_width="230dp"
181
+                android:layout_width="0dp"
183 182
                 android:layout_height="wrap_content"
184 183
                 android:layout_marginEnd="2dp"
185 184
                 android:layout_marginLeft="2dp"
186 185
                 android:layout_marginRight="2dp"
187 186
                 android:layout_weight="1"
188 187
                 android:textStyle="bold"
189
-                android:text="Izin Masuk" />
188
+                android:text="@string/label_entry_ermit" />
190 189
 
191 190
             <androidx.appcompat.widget.AppCompatSpinner
192 191
                 android:id="@+id/spinner_permit"
@@ -208,21 +207,23 @@
208 207
             <TextView
209 208
                 android:textSize="14sp"
210 209
                 android:textColor="@color/colorBlack"
211
-                android:layout_width="230dp"
210
+                android:layout_width="0dp"
212 211
                 android:layout_height="wrap_content"
213 212
                 android:layout_marginEnd="2dp"
214 213
                 android:layout_marginLeft="2dp"
215 214
                 android:layout_marginRight="2dp"
216 215
                 android:layout_weight="1"
217 216
                 android:textStyle="bold"
218
-                android:text="Status Scan" />
217
+                android:text="@string/label_scan_status" />
219 218
 
220
-            <RadioGroup
221
-                android:id="@+id/rg_status_scan"
219
+            <androidx.recyclerview.widget.RecyclerView
220
+                android:id="@+id/rv_status_scan"
222 221
                 android:layout_width="175dp"
223 222
                 android:layout_height="wrap_content"
224 223
                 android:layout_marginStart="12dp"
225
-                android:layout_marginEnd="12dp" />
224
+                android:layout_marginEnd="12dp"
225
+                tools:listitem="@layout/row_status_scan"
226
+                tools:itemCount="2"/>
226 227
 
227 228
         </LinearLayout>
228 229
 

+ 6 - 0
app/src/main/res/layout/row_status_scan.xml

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
3
+    android:id="@+id/rb_common"
4
+    android:layout_width="match_parent"
5
+    android:layout_height="wrap_content"
6
+    android:orientation="vertical"/>

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

@@ -26,5 +26,12 @@
26 26
     <string name="error_unknown">The serial port can not be opened for an unknown reason.</string>
27 27
     <string name="error_scan_id">Mohon maaf sistem sedang sibuk</string>
28 28
     <string name="error_only_security">Oops……… \n sepertinya anda bukan Security</string>
29
+    <string name="label_number_rfid">Nomor RFID Gun</string>
30
+    <string name="label_number_rfid_card">Nomor RFID Card</string>
31
+    <string name="label_employee_name">Nama Karyawan</string>
32
+    <string name="label_gate">Gate</string>
33
+    <string name="label_site">Site</string>
34
+    <string name="label_entry_ermit">Izin Masuk</string>
35
+    <string name="label_scan_status">Status Scan</string>
29 36
 
30 37
 </resources>