Fix sorting
This commit is contained in:
parent
61fb2ab0ba
commit
a86ea5118b
1 changed files with 11 additions and 18 deletions
|
@ -176,11 +176,10 @@ public class MapMarkersHelper {
|
||||||
mapMarkersHistory.clear();
|
mapMarkersHistory.clear();
|
||||||
|
|
||||||
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
|
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
|
||||||
sortActiveMarkers(activeMarkers);
|
|
||||||
mapMarkers.addAll(activeMarkers);
|
mapMarkers.addAll(activeMarkers);
|
||||||
|
|
||||||
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
|
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
|
||||||
sortHistoryMarkers(markersHistory);
|
sortMarkers(markersHistory, true);
|
||||||
mapMarkersHistory.addAll(markersHistory);
|
mapMarkersHistory.addAll(markersHistory);
|
||||||
|
|
||||||
if (!ctx.isApplicationInitializing()) {
|
if (!ctx.isApplicationInitializing()) {
|
||||||
|
@ -188,28 +187,22 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sortActiveMarkers(List<MapMarker> markers) {
|
private void sortMarkers(List<MapMarker> markers, final boolean history) {
|
||||||
Collections.sort(markers, new Comparator<MapMarker>() {
|
Collections.sort(markers, new Comparator<MapMarker>() {
|
||||||
@Override
|
@Override
|
||||||
public int compare(MapMarker mapMarker1, MapMarker mapMarker2) {
|
public int compare(MapMarker mapMarker1, MapMarker mapMarker2) {
|
||||||
if (mapMarker1.creationDate > mapMarker2.creationDate) {
|
long firstMarkerDate;
|
||||||
return -1;
|
long secondMarkerDate;
|
||||||
} else if (mapMarker1.creationDate == mapMarker2.creationDate) {
|
if (history) {
|
||||||
return 0;
|
firstMarkerDate = mapMarker1.visitedDate;
|
||||||
|
secondMarkerDate = mapMarker2.visitedDate;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
firstMarkerDate = mapMarker1.creationDate;
|
||||||
|
secondMarkerDate = mapMarker2.creationDate;
|
||||||
}
|
}
|
||||||
}
|
if (firstMarkerDate > secondMarkerDate) {
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sortHistoryMarkers(List<MapMarker> markers) {
|
|
||||||
Collections.sort(markers, new Comparator<MapMarker>() {
|
|
||||||
@Override
|
|
||||||
public int compare(MapMarker mapMarker1, MapMarker mapMarker2) {
|
|
||||||
if (mapMarker1.visitedDate > mapMarker2.visitedDate) {
|
|
||||||
return -1;
|
return -1;
|
||||||
} else if (mapMarker1.visitedDate == mapMarker2.visitedDate) {
|
} else if (firstMarkerDate == secondMarkerDate) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Reference in a new issue