Improve create headers algorithm

This commit is contained in:
PavelRatushnyi 2017-09-11 00:44:49 +03:00
parent f166ecf436
commit b88bed8e01

View file

@ -57,45 +57,28 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
int markerMonth = markerCalendar.get(Calendar.MONTH); int markerMonth = markerCalendar.get(Calendar.MONTH);
int markerYear = markerCalendar.get(Calendar.YEAR); int markerYear = markerCalendar.get(Calendar.YEAR);
if (markerYear == currentYear) { if (markerYear == currentYear) {
if (markerDay == currentDay) { if (markerDay == currentDay && previousHeader != TODAY_HEADER) {
if (previousHeader != TODAY_HEADER) { items.add(TODAY_HEADER);
items.add(TODAY_HEADER); previousHeader = TODAY_HEADER;
previousHeader = TODAY_HEADER; } else if (markerDay == currentDay - 1 && previousHeader != YESTERDAY_HEADER) {
} items.add(YESTERDAY_HEADER);
items.add(marker); previousHeader = YESTERDAY_HEADER;
} else if (markerDay == currentDay - 1) { } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousHeader != LAST_SEVEN_DAYS_HEADER) {
if (previousHeader != YESTERDAY_HEADER) { items.add(LAST_SEVEN_DAYS_HEADER);
items.add(YESTERDAY_HEADER); previousHeader = LAST_SEVEN_DAYS_HEADER;
previousHeader = YESTERDAY_HEADER; } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousHeader != markerMonth) {
} items.add(markerMonth);
items.add(marker); previousHeader = markerMonth;
} else if (currentDay - markerDay <= 8) { monthsDisplayed += 1;
if (previousHeader != LAST_SEVEN_DAYS_HEADER) { } else if (currentMonth - markerMonth >= 4 && previousHeader != THIS_YEAR_HEADER) {
items.add(LAST_SEVEN_DAYS_HEADER); items.add(THIS_YEAR_HEADER);
previousHeader = LAST_SEVEN_DAYS_HEADER; previousHeader = THIS_YEAR_HEADER;
}
items.add(marker);
} else if (monthsDisplayed < 3 || currentMonth - 3 == markerMonth) {
if (previousHeader != markerMonth) {
items.add(markerMonth);
previousHeader = markerMonth;
monthsDisplayed += 1;
}
items.add(marker);
} else {
if (previousHeader != THIS_YEAR_HEADER) {
items.add(THIS_YEAR_HEADER);
previousHeader = THIS_YEAR_HEADER;
}
items.add(marker);
} }
} else { } else if (previousHeader != markerYear) {
if (previousHeader != markerYear) { items.add(markerYear);
items.add(markerYear); previousHeader = markerYear;
previousHeader = markerYear;
}
items.add(marker);
} }
items.add(marker);
} }
} }