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,47 +57,30 @@ 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(marker);
} else if (markerDay == currentDay - 1) {
if (previousHeader != YESTERDAY_HEADER) {
items.add(YESTERDAY_HEADER); items.add(YESTERDAY_HEADER);
previousHeader = YESTERDAY_HEADER; previousHeader = YESTERDAY_HEADER;
} } else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousHeader != LAST_SEVEN_DAYS_HEADER) {
items.add(marker);
} else if (currentDay - markerDay <= 8) {
if (previousHeader != LAST_SEVEN_DAYS_HEADER) {
items.add(LAST_SEVEN_DAYS_HEADER); items.add(LAST_SEVEN_DAYS_HEADER);
previousHeader = LAST_SEVEN_DAYS_HEADER; previousHeader = LAST_SEVEN_DAYS_HEADER;
} } else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousHeader != markerMonth) {
items.add(marker);
} else if (monthsDisplayed < 3 || currentMonth - 3 == markerMonth) {
if (previousHeader != markerMonth) {
items.add(markerMonth); items.add(markerMonth);
previousHeader = markerMonth; previousHeader = markerMonth;
monthsDisplayed += 1; monthsDisplayed += 1;
} } else if (currentMonth - markerMonth >= 4 && previousHeader != THIS_YEAR_HEADER) {
items.add(marker);
} else {
if (previousHeader != THIS_YEAR_HEADER) {
items.add(THIS_YEAR_HEADER); items.add(THIS_YEAR_HEADER);
previousHeader = THIS_YEAR_HEADER; previousHeader = THIS_YEAR_HEADER;
} }
items.add(marker); } else if (previousHeader != markerYear) {
}
} else {
if (previousHeader != markerYear) {
items.add(markerYear); items.add(markerYear);
previousHeader = markerYear; previousHeader = markerYear;
} }
items.add(marker); items.add(marker);
} }
} }
}
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) { public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
this.listener = listener; this.listener = listener;