From a094d4f0d983012d8d17928eddb11ed01fa72038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Sun, 11 Mar 2018 19:31:56 +0100 Subject: [PATCH] Fix crash in grades on some devices (#66) --- .../ui/main/grades/GradeHeaderItem.java | 7 ++++--- .../wulkanowy/ui/main/grades/GradesSubItem.java | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradeHeaderItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradeHeaderItem.java index 5edabb7b8..a66be29b9 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradeHeaderItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradeHeaderItem.java @@ -91,15 +91,16 @@ public class GradeHeaderItem numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals, subItems.size(), subItems.size())); averageText.setText(getGradesAverageString(item)); - alertImage.setVisibility(isSubItemsRead(subItems) ? View.INVISIBLE : View.VISIBLE); - alertImage.setTag(item.getName()); + alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems) + ? View.INVISIBLE : View.VISIBLE); } - private boolean isSubItemsRead(List subItems) { + private boolean isSubItemsReadAndSaveAlertView(List subItems) { boolean isRead = true; for (GradesSubItem item : subItems) { isRead = item.getGrade().getRead(); + item.setSubjectAlertImage(alertImage); } return isRead; } diff --git a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesSubItem.java b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesSubItem.java index c252bb2ad..102a232f4 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesSubItem.java +++ b/app/src/main/java/io/github/wulkanowy/ui/main/grades/GradesSubItem.java @@ -1,6 +1,5 @@ package io.github.wulkanowy.ui.main.grades; -import android.app.Activity; import android.content.Context; import android.support.v4.app.DialogFragment; import android.support.v4.app.FragmentActivity; @@ -27,6 +26,8 @@ public class GradesSubItem private static int numberOfNotReadGrade; + private View subjectAlertImage; + GradesSubItem(GradeHeaderItem header, Grade grade) { super(header); this.grade = grade; @@ -36,6 +37,10 @@ public class GradesSubItem return grade; } + public void setSubjectAlertImage(View subjectAlertImage) { + this.subjectAlertImage = subjectAlertImage; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -68,7 +73,7 @@ public class GradesSubItem @Override public void bindViewHolder(FlexibleAdapter adapter, SubItemViewHolder holder, int position, List payloads) { - holder.onBind(grade); + holder.onBind(grade, subjectAlertImage); } static class SubItemViewHolder extends FlexibleViewHolder { @@ -85,6 +90,8 @@ public class GradesSubItem @BindView(R.id.grade_subitem_alert_image) View alert; + private View subjectAlertImage; + private Context context; private Grade item; @@ -96,8 +103,9 @@ public class GradesSubItem view.setOnClickListener(this); } - void onBind(Grade item) { + void onBind(Grade item, View subjectAlertImage) { this.item = item; + this.subjectAlertImage = subjectAlertImage; value.setText(item.getValue()); value.setBackgroundResource(item.getValueColor()); @@ -119,8 +127,7 @@ public class GradesSubItem numberOfNotReadGrade--; if (numberOfNotReadGrade == 0) { - ((Activity) context).findViewById(R.id.grade_fragment_container) - .findViewWithTag(item.getSubject()).setVisibility(View.INVISIBLE); + subjectAlertImage.setVisibility(View.INVISIBLE); } item.setIsNew(false); item.setRead(true);