Browse Source

-Change data error by group

ilhamitubagoes 4 years ago
parent
commit
4beb9e98aa

+ 3 - 0
app/build.gradle

@@ -75,6 +75,9 @@ dependencies {
75
     implementation 'com.github.bumptech.glide:glide:4.11.0'
75
     implementation 'com.github.bumptech.glide:glide:4.11.0'
76
     annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
76
     annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
77
 
77
 
78
+    //Light Stream
79
+    implementation 'com.annimon:stream:1.2.1'
80
+
78
     //Serial Port
81
     //Serial Port
79
     implementation files('libs/serialport.jar')
82
     implementation files('libs/serialport.jar')
80
     implementation files('libs/android-async-http-1.4.9.jar')
83
     implementation files('libs/android-async-http-1.4.9.jar')

+ 4 - 4
app/src/main/java/com/fusi24/rfid/adapter/ScanResultAdapter.java

@@ -14,12 +14,12 @@ import com.fusi24.rfid.util.DateHelper;
14
 import java.util.ArrayList;
14
 import java.util.ArrayList;
15
 import java.util.List;
15
 import java.util.List;
16
 
16
 
17
-public class ScanResultAdapter extends RecyclerView.Adapter<ScanResultAdapter.ViewHolder>{
17
+public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocumentAdapter.ViewHolder>{
18
 
18
 
19
     private Context context;
19
     private Context context;
20
     private List<DataProblems> problemsList;
20
     private List<DataProblems> problemsList;
21
 
21
 
22
-    public ScanResultAdapter(Context context) {
22
+    public ProblemDocumentAdapter(Context context) {
23
         this.context = context;
23
         this.context = context;
24
         this.problemsList = new ArrayList<>();
24
         this.problemsList = new ArrayList<>();
25
     }
25
     }
@@ -44,13 +44,13 @@ public class ScanResultAdapter extends RecyclerView.Adapter<ScanResultAdapter.Vi
44
 
44
 
45
     @NonNull
45
     @NonNull
46
     @Override
46
     @Override
47
-    public ScanResultAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
47
+    public ProblemDocumentAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
48
         RowDocumentBinding itemBinding = RowDocumentBinding.inflate(LayoutInflater.from(context), parent, false);
48
         RowDocumentBinding itemBinding = RowDocumentBinding.inflate(LayoutInflater.from(context), parent, false);
49
         return new ViewHolder(itemBinding);
49
         return new ViewHolder(itemBinding);
50
     }
50
     }
51
 
51
 
52
     @Override
52
     @Override
53
-    public void onBindViewHolder(@NonNull ScanResultAdapter.ViewHolder holder, int position) {
53
+    public void onBindViewHolder(@NonNull ProblemDocumentAdapter.ViewHolder holder, int position) {
54
 
54
 
55
         DataProblems problems = problemsList.get(position);
55
         DataProblems problems = problemsList.get(position);
56
 
56
 

+ 63 - 0
app/src/main/java/com/fusi24/rfid/adapter/ProblemGroupAdapter.java

@@ -0,0 +1,63 @@
1
+package com.fusi24.rfid.adapter;
2
+
3
+import android.content.Context;
4
+import android.view.LayoutInflater;
5
+import android.view.ViewGroup;
6
+
7
+import androidx.annotation.NonNull;
8
+import androidx.recyclerview.widget.RecyclerView;
9
+
10
+import com.fusi24.rfid.data.entity.DataGroup;
11
+import com.fusi24.rfid.databinding.RowGroupBinding;
12
+
13
+import java.util.ArrayList;
14
+import java.util.List;
15
+
16
+public class ProblemGroupAdapter extends RecyclerView.Adapter<ProblemGroupAdapter.ViewHolder>{
17
+
18
+    private Context context;
19
+    private List<DataGroup> groupList;
20
+
21
+    public ProblemGroupAdapter(Context context) {
22
+        this.context = context;
23
+        this.groupList = new ArrayList<>();
24
+    }
25
+
26
+    private void setGroupList(List<DataGroup> groupList) {
27
+        this.groupList = groupList;
28
+    }
29
+
30
+    public void updateGroupList(List<DataGroup> groupList){
31
+        setGroupList(groupList);
32
+    }
33
+
34
+    static class ViewHolder extends RecyclerView.ViewHolder {
35
+        private RowGroupBinding binding;
36
+
37
+        ViewHolder(RowGroupBinding itemBinding) {
38
+            super(itemBinding.getRoot());
39
+            this.binding = itemBinding;
40
+        }
41
+    }
42
+
43
+
44
+    @NonNull
45
+    @Override
46
+    public ProblemGroupAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
47
+        RowGroupBinding itemBinding = RowGroupBinding.inflate(LayoutInflater.from(context), parent, false);
48
+        return new ViewHolder(itemBinding);
49
+    }
50
+
51
+    @Override
52
+    public void onBindViewHolder(@NonNull ProblemGroupAdapter.ViewHolder holder, int position) {
53
+
54
+        DataGroup group = groupList.get(position);
55
+        holder.binding.tvGroupName.setText(group.getName());
56
+
57
+    }
58
+
59
+    @Override
60
+    public int getItemCount() {
61
+        return groupList.size();
62
+    }
63
+}

+ 14 - 4
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultActivity.java

@@ -12,11 +12,14 @@ import androidx.recyclerview.widget.DefaultItemAnimator;
12
 import androidx.recyclerview.widget.DividerItemDecoration;
12
 import androidx.recyclerview.widget.DividerItemDecoration;
13
 import androidx.recyclerview.widget.LinearLayoutManager;
13
 import androidx.recyclerview.widget.LinearLayoutManager;
14
 
14
 
15
+import com.annimon.stream.Collectors;
16
+import com.annimon.stream.Stream;
15
 import com.bumptech.glide.Glide;
17
 import com.bumptech.glide.Glide;
16
 import com.fusi24.rfid.R;
18
 import com.fusi24.rfid.R;
17
-import com.fusi24.rfid.adapter.ScanResultAdapter;
19
+import com.fusi24.rfid.adapter.ProblemGroupAdapter;
18
 import com.fusi24.rfid.base.BaseActivity;
20
 import com.fusi24.rfid.base.BaseActivity;
19
 import com.fusi24.rfid.config.Constant;
21
 import com.fusi24.rfid.config.Constant;
22
+import com.fusi24.rfid.data.entity.DataGroup;
20
 import com.fusi24.rfid.data.entity.DataProblems;
23
 import com.fusi24.rfid.data.entity.DataProblems;
21
 import com.fusi24.rfid.data.entity.DataResultRfid;
24
 import com.fusi24.rfid.data.entity.DataResultRfid;
22
 import com.fusi24.rfid.databinding.ActivityScanResultNewBinding;
25
 import com.fusi24.rfid.databinding.ActivityScanResultNewBinding;
@@ -36,7 +39,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
36
     public static final String LOCATION = "location";
39
     public static final String LOCATION = "location";
37
 
40
 
38
     private ScanResultPresenter presenter;
41
     private ScanResultPresenter presenter;
39
-    private ScanResultAdapter adapter;
42
+    private ProblemGroupAdapter adapter;
40
     private List<DataProblems> problemsList;
43
     private List<DataProblems> problemsList;
41
     private String dataUrl, numberRfid, numberRfidTemp, idPermit, idDevice, idCheckType, checkTypeName, longLat;
44
     private String dataUrl, numberRfid, numberRfidTemp, idPermit, idDevice, idCheckType, checkTypeName, longLat;
42
     private ActivityScanResultNewBinding binding;
45
     private ActivityScanResultNewBinding binding;
@@ -97,7 +100,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
97
         binding.tvRfidNumber.setText(numberRfid);
100
         binding.tvRfidNumber.setText(numberRfid);
98
 
101
 
99
         problemsList = new ArrayList<>();
102
         problemsList = new ArrayList<>();
100
-        adapter = new ScanResultAdapter(this);
103
+        adapter = new ProblemGroupAdapter(this);
101
 
104
 
102
         LinearLayoutManager layoutManager = new LinearLayoutManager(this);
105
         LinearLayoutManager layoutManager = new LinearLayoutManager(this);
103
         binding.rvDocumentProblem.setLayoutManager(layoutManager);
106
         binding.rvDocumentProblem.setLayoutManager(layoutManager);
@@ -187,7 +190,14 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
187
         }
190
         }
188
 
191
 
189
         problemsList = dataResultRfid.getProblems();
192
         problemsList = dataResultRfid.getProblems();
190
-        adapter.updateProblemList(problemsList);
193
+
194
+        // Function mapping data problem by Group
195
+        List<DataGroup> groupList = Stream.of(problemsList)
196
+                .map(v -> v.getDataDocumentType().getGroup())
197
+                .distinctBy(DataGroup::getId)
198
+                .collect(Collectors.toList());
199
+
200
+        adapter.updateGroupList(groupList);
191
         adapter.notifyDataSetChanged();
201
         adapter.notifyDataSetChanged();
192
     }
202
     }
193
 
203
 

+ 38 - 0
app/src/main/res/layout/row_group.xml

@@ -0,0 +1,38 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+    xmlns:tools="http://schemas.android.com/tools"
4
+    xmlns:app="http://schemas.android.com/apk/res-auto"
5
+    android:orientation="horizontal"
6
+    android:layout_width="match_parent"
7
+    android:layout_height="wrap_content"
8
+    android:background="@color/backgroundLayoutGrey"
9
+    android:padding="8dp"
10
+    android:layout_margin="16dp">
11
+
12
+    <TextView
13
+        android:id="@+id/tv_group_name"
14
+        style="@style/DocumentText"
15
+        android:layout_width="300dp"
16
+        android:layout_height="wrap_content"
17
+        android:layout_marginStart="4dp"
18
+        android:layout_marginEnd="4dp"
19
+        android:layout_alignParentStart="true"
20
+        android:layout_alignParentTop="true"
21
+        android:layout_alignParentBottom="true"
22
+        android:gravity="center_vertical"
23
+        tools:text="ID CARD KARYAWAN" />
24
+
25
+    <ImageView
26
+        android:id="@+id/chevron1"
27
+        android:layout_width="15dp"
28
+        android:layout_height="15dp"
29
+        android:paddingStart="0dp"
30
+        android:paddingEnd="0dp"
31
+        android:layout_alignParentEnd="true"
32
+        android:layout_alignParentTop="true"
33
+        android:layout_alignParentBottom="true"
34
+        app:srcCompat="@drawable/chevron_down"
35
+        android:contentDescription="@string/cd_image" />
36
+
37
+
38
+</RelativeLayout>