1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2025-01-31 15:18:20 +01:00

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,
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<GradesSubItem> subItems) {
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
boolean isRead = true;
for (GradesSubItem item : subItems) {
isRead = item.getGrade().getRead();
item.setSubjectAlertImage(alertImage);
}
return isRead;
}

View File

@ -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);