Browse Source

-Fixing document adapter nullPointer

ilhamitubagoes 4 years ago
parent
commit
43388ce82a

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

@@ -54,7 +54,7 @@ public class ProblemDocumentAdapter extends RecyclerView.Adapter<ProblemDocument
54
         holder.binding.tvDocumentName.setText(problems.getDataDocumentType().getName());
54
         holder.binding.tvDocumentName.setText(problems.getDataDocumentType().getName());
55
         holder.binding.tvDocumentStatus.setText(problems.getReason());
55
         holder.binding.tvDocumentStatus.setText(problems.getReason());
56
         if (problems.getExpiryDate() != null){
56
         if (problems.getExpiryDate() != null){
57
-            holder.binding.tvDocumentDate.setText(DateHelper.convertDateToReadableDate(problems.getExpiryDate()));
57
+            holder.binding.tvDocumentDate.setText(DateHelper.convertStringToMyPattern(problems.getExpiryDate(), "yyyy-MM-dd", "dd MMM yyyy"));
58
         } else {
58
         } else {
59
             holder.binding.tvDocumentDate.setText("");
59
             holder.binding.tvDocumentDate.setText("");
60
         }
60
         }

+ 13 - 0
app/src/main/java/com/fusi24/rfid/util/DateHelper.java

@@ -22,4 +22,17 @@ public class DateHelper {
22
         return output.format(d);
22
         return output.format(d);
23
     }
23
     }
24
 
24
 
25
+    @NonNull
26
+    public static String convertStringToMyPattern(String stringTime, String patternBefore, String patternAfter) {
27
+        SimpleDateFormat sdf = new SimpleDateFormat(patternBefore, Locale.getDefault());
28
+        SimpleDateFormat output = new SimpleDateFormat(patternAfter, Locale.getDefault());
29
+        Date d = null;
30
+        try {
31
+            d = sdf.parse(stringTime);
32
+        } catch (ParseException e) {
33
+            e.printStackTrace();
34
+        }
35
+        return output.format(d);
36
+    }
37
+
25
 }
38
 }

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

@@ -35,12 +35,12 @@
35
     <TextView
35
     <TextView
36
         android:id="@+id/tv_document_date"
36
         android:id="@+id/tv_document_date"
37
         style="@style/DocumentText"
37
         style="@style/DocumentText"
38
-        android:layout_width="wrap_content"
38
+        android:layout_width="55dp"
39
         android:layout_height="wrap_content"
39
         android:layout_height="wrap_content"
40
         android:layout_marginStart="4dp"
40
         android:layout_marginStart="4dp"
41
         android:layout_marginEnd="4dp"
41
         android:layout_marginEnd="4dp"
42
         android:layout_alignParentEnd="true"
42
         android:layout_alignParentEnd="true"
43
         android:layout_centerVertical="true"
43
         android:layout_centerVertical="true"
44
-        tools:text="1-Jul-2019" />
44
+        tools:text="19 Nov 2019" />
45
 
45
 
46
 </RelativeLayout>
46
 </RelativeLayout>