Explorar o código

Grouping problem document by id group

ilhamitubagoes %!s(int64=4) %!d(string=hai) anos
pai
achega
7e2e0733a3

+ 43 - 12
app/src/main/java/com/fusi24/rfid/adapter/ProblemDocumentAdapter.java

@@ -1,8 +1,11 @@
1 1
 package com.fusi24.rfid.adapter;
2 2
 
3 3
 import android.content.Context;
4
+import android.text.TextUtils;
4 5
 import android.view.LayoutInflater;
5 6
 import android.view.ViewGroup;
7
+import android.widget.Filter;
8
+import android.widget.Filterable;
6 9
 
7 10
 import androidx.annotation.NonNull;
8 11
 import androidx.recyclerview.widget.RecyclerView;
@@ -14,22 +17,16 @@ import com.fusi24.rfid.util.DateHelper;
14 17
 import java.util.ArrayList;
15 18
 import java.util.List;
16 19
 
17
-public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocumentAdapter.ViewHolder>{
20
+public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocumentAdapter.ViewHolder> implements Filterable {
18 21
 
19 22
     private Context context;
20 23
     private List<DataProblems> problemsList;
24
+    private List<DataProblems> problemsListFiltered;
21 25
 
22
-    public ProblemDocumentAdapter(Context context) {
26
+    public ProblemDocumentAdapter(Context context, List<DataProblems> problemsList) {
23 27
         this.context = context;
24
-        this.problemsList = new ArrayList<>();
25
-    }
26
-
27
-    private void setProblemsList(List<DataProblems> problemsList) {
28 28
         this.problemsList = problemsList;
29
-    }
30
-
31
-    public void updateProblemList(List<DataProblems> problemsList){
32
-        setProblemsList(problemsList);
29
+        this.problemsListFiltered = problemsList;
33 30
     }
34 31
 
35 32
     static class ViewHolder extends RecyclerView.ViewHolder {
@@ -52,7 +49,7 @@ public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocument
52 49
     @Override
53 50
     public void onBindViewHolder(@NonNull ProblemDocumentAdapter.ViewHolder holder, int position) {
54 51
 
55
-        DataProblems problems = problemsList.get(position);
52
+        DataProblems problems = problemsListFiltered.get(position);
56 53
 
57 54
         holder.binding.tvDocumentName.setText(problems.getDataDocumentType().getName());
58 55
         holder.binding.tvDocumentStatus.setText(problems.getReason());
@@ -62,6 +59,40 @@ public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocument
62 59
 
63 60
     @Override
64 61
     public int getItemCount() {
65
-        return problemsList.size();
62
+        return problemsListFiltered.size();
66 63
     }
64
+
65
+    @Override
66
+    public Filter getFilter() {
67
+        return new Filter() {
68
+            @Override
69
+            protected FilterResults performFiltering(CharSequence constraint) {
70
+
71
+                if (TextUtils.isEmpty(constraint.toString())){
72
+                    problemsListFiltered = problemsList;
73
+                } else {
74
+                    Integer idGroup = Integer.valueOf(constraint.toString());
75
+                    List<DataProblems> filterList = new ArrayList<>();
76
+
77
+                    for (DataProblems problems : problemsList){
78
+                        if (problems.getDataDocumentType().getGroup().getId().equals(idGroup)){
79
+                            filterList.add(problems);
80
+                        }
81
+                    }
82
+                    problemsListFiltered = filterList;
83
+                }
84
+
85
+                FilterResults results = new FilterResults();
86
+                results.values = problemsListFiltered;
87
+                return results;
88
+            }
89
+
90
+            @Override
91
+            protected void publishResults(CharSequence constraint, FilterResults results) {
92
+                problemsListFiltered = (List<DataProblems>) results.values;
93
+                notifyDataSetChanged();
94
+            }
95
+        };
96
+    }
97
+
67 98
 }

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

@@ -2,12 +2,16 @@ package com.fusi24.rfid.adapter;
2 2
 
3 3
 import android.content.Context;
4 4
 import android.view.LayoutInflater;
5
+import android.view.View;
5 6
 import android.view.ViewGroup;
6 7
 
7 8
 import androidx.annotation.NonNull;
9
+import androidx.recyclerview.widget.LinearLayoutManager;
8 10
 import androidx.recyclerview.widget.RecyclerView;
9 11
 
12
+import com.fusi24.rfid.R;
10 13
 import com.fusi24.rfid.data.entity.DataGroup;
14
+import com.fusi24.rfid.data.entity.DataProblems;
11 15
 import com.fusi24.rfid.databinding.RowGroupBinding;
12 16
 
13 17
 import java.util.ArrayList;
@@ -16,11 +20,14 @@ import java.util.List;
16 20
 public class ProblemGroupAdapter extends RecyclerView.Adapter<ProblemGroupAdapter.ViewHolder>{
17 21
 
18 22
     private Context context;
23
+    private RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
19 24
     private List<DataGroup> groupList;
25
+    private List<DataProblems> problemsList;
20 26
 
21 27
     public ProblemGroupAdapter(Context context) {
22 28
         this.context = context;
23 29
         this.groupList = new ArrayList<>();
30
+        this.problemsList = new ArrayList<>();
24 31
     }
25 32
 
26 33
     private void setGroupList(List<DataGroup> groupList) {
@@ -31,6 +38,14 @@ public class ProblemGroupAdapter extends RecyclerView.Adapter<ProblemGroupAdapte
31 38
         setGroupList(groupList);
32 39
     }
33 40
 
41
+    private void setProblemsList(List<DataProblems> problemsList) {
42
+        this.problemsList = problemsList;
43
+    }
44
+
45
+    public void updateProblemList(List<DataProblems> problemsList){
46
+        setProblemsList(problemsList);
47
+    }
48
+
34 49
     static class ViewHolder extends RecyclerView.ViewHolder {
35 50
         private RowGroupBinding binding;
36 51
 
@@ -54,6 +69,30 @@ public class ProblemGroupAdapter extends RecyclerView.Adapter<ProblemGroupAdapte
54 69
         DataGroup group = groupList.get(position);
55 70
         holder.binding.tvGroupName.setText(group.getName());
56 71
 
72
+        // Create layout manager with initial prefetch item count
73
+        LinearLayoutManager layoutManager = new LinearLayoutManager(
74
+                holder.binding.rvSubGroup.getContext(),
75
+                LinearLayoutManager.VERTICAL, false);
76
+
77
+        layoutManager.setInitialPrefetchItemCount(problemsList.size());
78
+
79
+        //Create Sub Item View Adapter
80
+        ProblemDocumentAdapter documentAdapter = new ProblemDocumentAdapter(context, problemsList);
81
+        holder.binding.rvSubGroup.setLayoutManager(layoutManager);
82
+        holder.binding.rvSubGroup.setAdapter(documentAdapter);
83
+        holder.binding.rvSubGroup.setRecycledViewPool(viewPool);
84
+
85
+        holder.binding.rlGroup.setOnClickListener(v -> {
86
+            documentAdapter.getFilter().filter(String.valueOf(group.getId()));
87
+            // Set Layout
88
+            if(holder.binding.rvSubGroup.getVisibility() == View.GONE){
89
+                holder.binding.rvSubGroup.setVisibility(View.VISIBLE);
90
+                holder.binding.ivChevron.setImageDrawable(context.getDrawable(R.drawable.chevron_up));
91
+            } else {
92
+                holder.binding.rvSubGroup.setVisibility(View.GONE);
93
+                holder.binding.ivChevron.setImageDrawable(context.getDrawable(R.drawable.chevron_down));
94
+            }
95
+        });
57 96
     }
58 97
 
59 98
     @Override

+ 1 - 0
app/src/main/java/com/fusi24/rfid/ui/scanresult/ScanResultActivity.java

@@ -198,6 +198,7 @@ public class ScanResultActivity extends BaseActivity implements ScanResultView {
198 198
                 .collect(Collectors.toList());
199 199
 
200 200
         adapter.updateGroupList(groupList);
201
+        adapter.updateProblemList(problemsList);
201 202
         adapter.notifyDataSetChanged();
202 203
     }
203 204
 

BIN=BIN
app/src/main/res/drawable-v24/chevron_up.png


+ 1 - 1
app/src/main/res/layout/row_document.xml

@@ -4,7 +4,7 @@
4 4
     android:orientation="horizontal"
5 5
     android:layout_width="match_parent"
6 6
     android:layout_height="wrap_content"
7
-    android:background="@color/backgroundLayoutGrey"
7
+    android:background="@color/backgroundLayoutGreyDark"
8 8
     android:padding="16dp"
9 9
     android:layout_margin="16dp">
10 10
 

+ 41 - 29
app/src/main/res/layout/row_group.xml

@@ -1,38 +1,50 @@
1 1
 <?xml version="1.0" encoding="utf-8"?>
2
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3 3
     xmlns:tools="http://schemas.android.com/tools"
4 4
     xmlns:app="http://schemas.android.com/apk/res-auto"
5
-    android:orientation="horizontal"
6 5
     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">
6
+    android:layout_height="wrap_content">
11 7
 
12
-    <TextView
13
-        android:id="@+id/tv_group_name"
14
-        style="@style/DocumentText"
15
-        android:layout_width="300dp"
8
+    <RelativeLayout
9
+        android:id="@+id/rl_group"
10
+        android:layout_width="match_parent"
16 11
         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" />
12
+        android:background="@color/backgroundLayoutGrey"
13
+        android:padding="8dp"
14
+        android:layout_margin="16dp">
24 15
 
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" />
16
+        <TextView
17
+            android:id="@+id/tv_group_name"
18
+            style="@style/DocumentText"
19
+            android:layout_width="300dp"
20
+            android:layout_height="wrap_content"
21
+            android:layout_marginStart="4dp"
22
+            android:layout_marginEnd="4dp"
23
+            android:layout_alignParentStart="true"
24
+            android:gravity="center_vertical"
25
+            tools:text="ID CARD KARYAWAN" />
36 26
 
27
+        <ImageView
28
+            android:id="@+id/iv_chevron"
29
+            android:layout_width="15dp"
30
+            android:layout_height="15dp"
31
+            android:paddingStart="0dp"
32
+            android:paddingEnd="0dp"
33
+            android:layout_alignParentEnd="true"
34
+            android:gravity="center_vertical"
35
+            app:srcCompat="@drawable/chevron_down"
36
+            android:contentDescription="@string/cd_image" />
37 37
 
38
-</RelativeLayout>
38
+        <androidx.recyclerview.widget.RecyclerView
39
+            android:id="@+id/rv_sub_group"
40
+            android:layout_width="match_parent"
41
+            android:layout_height="wrap_content"
42
+            android:layout_below="@+id/tv_group_name"
43
+            android:layout_marginTop="8dp"
44
+            android:visibility="gone"
45
+            tools:listitem="@layout/row_document"
46
+            tools:itemCount="2"/>
47
+
48
+    </RelativeLayout>
49
+
50
+</ScrollView>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -12,6 +12,7 @@
12 12
     <color name="backgroundOuter">#F5F5F5</color>
13 13
     <color name="backgroundCanvas">#f2f2f9</color>
14 14
     <color name="backgroundLayoutGrey">#E3E3E9</color>
15
+    <color name="backgroundLayoutGreyDark">#B4B4B8</color>
15 16
 
16 17
     <color name="colorWhite">#FFFFFF</color>
17 18
     <color name="colorBlack">#000000</color>