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 5d0fd073..33e96189 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 @@ -118,57 +118,13 @@ public class GradeHeaderItem item.getFinalRating())); resetViews(); - toggleSummaryText(); toggleSubjectText(); + toggleSummary(); alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems) ? 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 subItems) { - boolean isRead = true; - - for (GradesSubItem gradesSubItem : subItems) { - isRead = gradesSubItem.getGrade().getRead(); - gradesSubItem.setSubjectAlertImage(alertImage); - } - - return isRead; - } - private String getGradesAverageString() { float average = GradeUtils.calculate(item.getGradeList()); @@ -179,26 +135,65 @@ public class GradeHeaderItem 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() { return adapter.isExpanded(getFlexibleAdapterPosition()); } - private boolean isSummaryToggleable() { - boolean isSummaryEmpty = true; - - if (!"-".equals(item.getPredictedRating()) || !"-".equals(item.getFinalRating())) { - isSummaryEmpty = false; + private void toggleSummaryView(View view, String value, boolean expand) { + if ("-".equals(value) || isShowSummary) { + return; } - if (isSummaryEmpty) { - return false; - } else if (isShowSummary) { - predictedText.setVisibility(View.VISIBLE); - finalText.setVisibility(View.VISIBLE); - - return false; + if (expand) { + AnimationUtils.slideDown(view); + } else { + AnimationUtils.slideUp(view); } - return true; + } + + private boolean isSubItemsReadAndSaveAlertView(List subItems) { + boolean isRead = true; + + for (GradesSubItem gradesSubItem : subItems) { + isRead = gradesSubItem.getGrade().getRead(); + gradesSubItem.setSubjectAlertImage(alertImage); + } + + return isRead; } } }