1
0
mirror of https://github.com/wulkanowy/wulkanowy.git synced 2024-09-20 04:29:09 -05:00

Hide empty fields in summary (#128)

This commit is contained in:
Mikołaj Pich 2018-05-31 23:01:52 +02:00 committed by Rafał Borcz
parent 306092ce45
commit 228f680e5d

View File

@ -118,57 +118,13 @@ public class GradeHeaderItem
item.getFinalRating())); item.getFinalRating()));
resetViews(); resetViews();
toggleSummaryText();
toggleSubjectText(); toggleSubjectText();
toggleSummary();
alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems) alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
? View.INVISIBLE : View.VISIBLE); ? View.INVISIBLE : View.VISIBLE);
} }
@Override
public void onClick(View view) {
super.onClick(view);
toggleSubjectText();
toggleSummaryText();
}
private void toggleSummaryText() {
if (isSummaryToggleable()) {
if (isExpand()) {
AnimationUtils.slideDown(predictedText);
AnimationUtils.slideDown(finalText);
} else {
AnimationUtils.slideUp(predictedText);
AnimationUtils.slideUp(finalText);
}
}
}
private void toggleSubjectText() {
if (isExpand()) {
subjectName.setMaxLines(3);
} else {
subjectName.setMaxLines(1);
}
}
private void resetViews() {
subjectName.setMaxLines(1);
predictedText.setVisibility(View.GONE);
finalText.setVisibility(View.GONE);
}
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
boolean isRead = true;
for (GradesSubItem gradesSubItem : subItems) {
isRead = gradesSubItem.getGrade().getRead();
gradesSubItem.setSubjectAlertImage(alertImage);
}
return isRead;
}
private String getGradesAverageString() { private String getGradesAverageString() {
float average = GradeUtils.calculate(item.getGradeList()); float average = GradeUtils.calculate(item.getGradeList());
@ -179,26 +135,65 @@ public class GradeHeaderItem
return resources.getString(R.string.info_average_grades, average); return resources.getString(R.string.info_average_grades, average);
} }
@Override
public void onClick(View view) {
super.onClick(view);
toggleSubjectText();
toggleSummary();
}
private void resetViews() {
subjectName.setMaxLines(1);
setDefaultSummaryVisibility(predictedText, item.getPredictedRating());
setDefaultSummaryVisibility(finalText, item.getFinalRating());
}
private void setDefaultSummaryVisibility(View view, String value) {
if (!"-".equals(value) && isShowSummary) {
view.setVisibility(View.VISIBLE);
} else {
view.setVisibility(View.GONE);
}
}
private void toggleSubjectText() {
if (isExpand()) {
subjectName.setMaxLines(3);
} else {
subjectName.setMaxLines(1);
}
}
private void toggleSummary() {
toggleSummaryView(predictedText, item.getPredictedRating(), isExpand());
toggleSummaryView(finalText, item.getFinalRating(), isExpand());
}
private boolean isExpand() { private boolean isExpand() {
return adapter.isExpanded(getFlexibleAdapterPosition()); return adapter.isExpanded(getFlexibleAdapterPosition());
} }
private boolean isSummaryToggleable() { private void toggleSummaryView(View view, String value, boolean expand) {
boolean isSummaryEmpty = true; if ("-".equals(value) || isShowSummary) {
return;
if (!"-".equals(item.getPredictedRating()) || !"-".equals(item.getFinalRating())) {
isSummaryEmpty = false;
} }
if (isSummaryEmpty) { if (expand) {
return false; AnimationUtils.slideDown(view);
} else if (isShowSummary) { } else {
predictedText.setVisibility(View.VISIBLE); AnimationUtils.slideUp(view);
finalText.setVisibility(View.VISIBLE); }
}
return false; private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
boolean isRead = true;
for (GradesSubItem gradesSubItem : subItems) {
isRead = gradesSubItem.getGrade().getRead();
gradesSubItem.setSubjectAlertImage(alertImage);
} }
return true;
return isRead;
} }
} }
} }