Fix crash in grades on some devices (#66)

This commit is contained in:
Rafał Borcz 2018-03-11 19:31:56 +01:00 committed by Mikołaj Pich
parent 3aca34340d
commit a094d4f0d9
2 changed files with 16 additions and 8 deletions

View File

@ -91,15 +91,16 @@ public class GradeHeaderItem
numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals, numberText.setText(resources.getQuantityString(R.plurals.numberOfGradesPlurals,
subItems.size(), subItems.size())); subItems.size(), subItems.size()));
averageText.setText(getGradesAverageString(item)); averageText.setText(getGradesAverageString(item));
alertImage.setVisibility(isSubItemsRead(subItems) ? View.INVISIBLE : View.VISIBLE); alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
alertImage.setTag(item.getName()); ? View.INVISIBLE : View.VISIBLE);
} }
private boolean isSubItemsRead(List<GradesSubItem> subItems) { private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
boolean isRead = true; boolean isRead = true;
for (GradesSubItem item : subItems) { for (GradesSubItem item : subItems) {
isRead = item.getGrade().getRead(); isRead = item.getGrade().getRead();
item.setSubjectAlertImage(alertImage);
} }
return isRead; return isRead;
} }

View File

@ -1,6 +1,5 @@
package io.github.wulkanowy.ui.main.grades; package io.github.wulkanowy.ui.main.grades;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
@ -27,6 +26,8 @@ public class GradesSubItem
private static int numberOfNotReadGrade; private static int numberOfNotReadGrade;
private View subjectAlertImage;
GradesSubItem(GradeHeaderItem header, Grade grade) { GradesSubItem(GradeHeaderItem header, Grade grade) {
super(header); super(header);
this.grade = grade; this.grade = grade;
@ -36,6 +37,10 @@ public class GradesSubItem
return grade; return grade;
} }
public void setSubjectAlertImage(View subjectAlertImage) {
this.subjectAlertImage = subjectAlertImage;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -68,7 +73,7 @@ public class GradesSubItem
@Override @Override
public void bindViewHolder(FlexibleAdapter adapter, SubItemViewHolder holder, int position, List payloads) { public void bindViewHolder(FlexibleAdapter adapter, SubItemViewHolder holder, int position, List payloads) {
holder.onBind(grade); holder.onBind(grade, subjectAlertImage);
} }
static class SubItemViewHolder extends FlexibleViewHolder { static class SubItemViewHolder extends FlexibleViewHolder {
@ -85,6 +90,8 @@ public class GradesSubItem
@BindView(R.id.grade_subitem_alert_image) @BindView(R.id.grade_subitem_alert_image)
View alert; View alert;
private View subjectAlertImage;
private Context context; private Context context;
private Grade item; private Grade item;
@ -96,8 +103,9 @@ public class GradesSubItem
view.setOnClickListener(this); view.setOnClickListener(this);
} }
void onBind(Grade item) { void onBind(Grade item, View subjectAlertImage) {
this.item = item; this.item = item;
this.subjectAlertImage = subjectAlertImage;
value.setText(item.getValue()); value.setText(item.getValue());
value.setBackgroundResource(item.getValueColor()); value.setBackgroundResource(item.getValueColor());
@ -119,8 +127,7 @@ public class GradesSubItem
numberOfNotReadGrade--; numberOfNotReadGrade--;
if (numberOfNotReadGrade == 0) { if (numberOfNotReadGrade == 0) {
((Activity) context).findViewById(R.id.grade_fragment_container) subjectAlertImage.setVisibility(View.INVISIBLE);
.findViewWithTag(item.getSubject()).setVisibility(View.INVISIBLE);
} }
item.setIsNew(false); item.setIsNew(false);
item.setRead(true); item.setRead(true);