forked from github/wulkanowy-mirror
Fix animations on expand and collapse (#97)
This commit is contained in:
parent
ffd20c94dd
commit
bfaa3d196b
@ -79,7 +79,7 @@ public class GradeHeaderItem
|
|||||||
TextView numberText;
|
TextView numberText;
|
||||||
|
|
||||||
@BindView(R.id.grade_header_predicted_rating_text)
|
@BindView(R.id.grade_header_predicted_rating_text)
|
||||||
TextView predictedTest;
|
TextView predictedText;
|
||||||
|
|
||||||
@BindView(R.id.grade_header_final_rating_text)
|
@BindView(R.id.grade_header_final_rating_text)
|
||||||
TextView finalText;
|
TextView finalText;
|
||||||
@ -87,9 +87,11 @@ public class GradeHeaderItem
|
|||||||
@BindView(R.id.grade_header_alert_image)
|
@BindView(R.id.grade_header_alert_image)
|
||||||
View alertImage;
|
View alertImage;
|
||||||
|
|
||||||
Resources resources;
|
private Resources resources;
|
||||||
|
|
||||||
private boolean isSummaryTogglable = true;
|
private Subject item;
|
||||||
|
|
||||||
|
private FlexibleAdapter adapter;
|
||||||
|
|
||||||
private boolean isShowSummary;
|
private boolean isShowSummary;
|
||||||
|
|
||||||
@ -99,35 +101,25 @@ public class GradeHeaderItem
|
|||||||
resources = view.getResources();
|
resources = view.getResources();
|
||||||
view.setOnClickListener(this);
|
view.setOnClickListener(this);
|
||||||
this.isShowSummary = isShowSummary;
|
this.isShowSummary = isShowSummary;
|
||||||
|
this.adapter = adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onBind(Subject item, List<GradesSubItem> subItems) {
|
void onBind(Subject item, List<GradesSubItem> subItems) {
|
||||||
|
this.item = item;
|
||||||
|
|
||||||
subjectName.setText(item.getName());
|
subjectName.setText(item.getName());
|
||||||
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());
|
||||||
|
|
||||||
predictedTest.setText(resources.getString(R.string.info_grades_predicted_rating,
|
predictedText.setText(resources.getString(R.string.info_grades_predicted_rating,
|
||||||
item.getPredictedRating()));
|
item.getPredictedRating()));
|
||||||
finalText.setText(resources.getString(R.string.info_grades_final_rating,
|
finalText.setText(resources.getString(R.string.info_grades_final_rating,
|
||||||
item.getFinalRating()));
|
item.getFinalRating()));
|
||||||
predictedTest.setVisibility(View.GONE);
|
|
||||||
finalText.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
boolean isSummaryEmpty = true;
|
resetViews();
|
||||||
|
toggleSummaryText();
|
||||||
if (!"-".equals(item.getPredictedRating()) || !"-".equals(item.getFinalRating())) {
|
toggleSubjectText();
|
||||||
isSummaryEmpty = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isSummaryEmpty) {
|
|
||||||
isSummaryTogglable = false;
|
|
||||||
} else if (isShowSummary) {
|
|
||||||
predictedTest.setVisibility(View.VISIBLE);
|
|
||||||
finalText.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
isSummaryTogglable = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
|
alertImage.setVisibility(isSubItemsReadAndSaveAlertView(subItems)
|
||||||
? View.INVISIBLE : View.VISIBLE);
|
? View.INVISIBLE : View.VISIBLE);
|
||||||
@ -136,38 +128,48 @@ public class GradeHeaderItem
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
super.onClick(view);
|
super.onClick(view);
|
||||||
if (subjectName.getLineCount() == 1) {
|
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);
|
subjectName.setMaxLines(3);
|
||||||
} else {
|
} else {
|
||||||
subjectName.setMaxLines(1);
|
subjectName.setMaxLines(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSummaryTogglable) {
|
|
||||||
toggleText(predictedTest);
|
|
||||||
toggleText(finalText);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toggleText(final View view) {
|
private void resetViews() {
|
||||||
if (view.getVisibility() == View.GONE) {
|
subjectName.setMaxLines(1);
|
||||||
AnimationUtils.slideDown(view);
|
predictedText.setVisibility(View.GONE);
|
||||||
} else {
|
finalText.setVisibility(View.GONE);
|
||||||
AnimationUtils.slideUp(view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
|
private boolean isSubItemsReadAndSaveAlertView(List<GradesSubItem> subItems) {
|
||||||
boolean isRead = true;
|
boolean isRead = true;
|
||||||
|
|
||||||
for (GradesSubItem item : subItems) {
|
for (GradesSubItem gradesSubItem : subItems) {
|
||||||
isRead = item.getGrade().getRead();
|
isRead = gradesSubItem.getGrade().getRead();
|
||||||
item.setSubjectAlertImage(alertImage);
|
gradesSubItem.setSubjectAlertImage(alertImage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return isRead;
|
return isRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getGradesAverageString(Subject item) {
|
private String getGradesAverageString() {
|
||||||
float average = GradeUtils.calculate(item.getGradeList());
|
float average = GradeUtils.calculate(item.getGradeList());
|
||||||
|
|
||||||
if (average < 0) {
|
if (average < 0) {
|
||||||
@ -176,5 +178,27 @@ public class GradeHeaderItem
|
|||||||
|
|
||||||
return resources.getString(R.string.info_average_grades, average);
|
return resources.getString(R.string.info_average_grades, average);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isExpand() {
|
||||||
|
return adapter.isExpanded(getFlexibleAdapterPosition());
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSummaryToggleable() {
|
||||||
|
boolean isSummaryEmpty = true;
|
||||||
|
|
||||||
|
if (!"-".equals(item.getPredictedRating()) || !"-".equals(item.getFinalRating())) {
|
||||||
|
isSummaryEmpty = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSummaryEmpty) {
|
||||||
|
return false;
|
||||||
|
} else if (isShowSummary) {
|
||||||
|
predictedText.setVisibility(View.VISIBLE);
|
||||||
|
finalText.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user