Make small refactoring in MapMarkersHelper

This commit is contained in:
Alexander Sytnyk 2018-03-16 19:00:46 +02:00
parent 4262e9aec7
commit da2c482414
4 changed files with 23 additions and 36 deletions

View file

@ -135,7 +135,7 @@ public class FavouritesDbHelper {
flatGroups.remove(g.name);
favoriteGroups.remove(g);
cachedFavoritePoints.removeAll(g.points);
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true);
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name);
}
}
saveCurrentPointsIntoFile();
@ -352,7 +352,7 @@ public class FavouritesDbHelper {
if (remove) {
flatGroups.remove(group.name);
saveCurrentPointsIntoFile();
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true);
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name);
return true;
}
return false;
@ -622,7 +622,7 @@ public class FavouritesDbHelper {
}
if (!group.name.equals(newName)) {
FavoriteGroup gr = flatGroups.remove(group.name);
markersHelper.removeMarkersSyncGroup(group.name, true);
markersHelper.removeMarkersSyncGroup(group.name);
gr.name = newName;
FavoriteGroup renamedGroup = flatGroups.get(gr.name);
boolean existing = renamedGroup != null;

View file

@ -554,7 +554,7 @@ public class GpxSelectionHelper {
if (show && !enabled) {
mapMarkersHelper.addMarkersSyncGroup(syncGroup);
} else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) {
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true);
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath());
}
}
mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback);

View file

@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
@ -57,8 +56,8 @@ public class MapMarkersHelper {
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<MapMarker> mapMarkers = new LinkedList<>();
private List<MapMarker> mapMarkersHistory = new LinkedList<>();
private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private List<MapMarkerChangedListener> listeners = new ArrayList<>();
@ -195,16 +194,6 @@ public class MapMarkersHelper {
public static int getColorId(int colorIndex) {
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
}
public static int getColorIndex(Context context, int color) {
int[] colors = getColors(context);
for (int i = 0; i < colors.length; i++) {
if (colors[i] == color) {
return i;
}
}
return -1;
}
}
@Nullable
@ -293,8 +282,8 @@ public class MapMarkersHelper {
}
private void loadMarkers() {
mapMarkers = new LinkedList<>();
mapMarkersHistory = new LinkedList<>();
mapMarkers = new ArrayList<>();
mapMarkersHistory = new ArrayList<>();
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
addToMapMarkersList(activeMarkers);
@ -310,13 +299,13 @@ public class MapMarkersHelper {
}
private void removeFromMapMarkersList(List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.removeAll(markers);
mapMarkers = copyList;
}
private void removeFromMapMarkersList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.remove(marker);
mapMarkers = copyList;
}
@ -326,7 +315,7 @@ public class MapMarkersHelper {
}
private void addToMapMarkersList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.add(position, marker);
mapMarkers = copyList;
}
@ -336,13 +325,13 @@ public class MapMarkersHelper {
}
private void addToMapMarkersList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.addAll(position, markers);
mapMarkers = copyList;
}
private void removeFromMapMarkersHistoryList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.remove(marker);
mapMarkersHistory = copyList;
}
@ -352,13 +341,13 @@ public class MapMarkersHelper {
}
private void addToMapMarkersHistoryList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.add(position, marker);
mapMarkersHistory = copyList;
}
private void addToMapMarkersHistoryList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.addAll(position, markers);
mapMarkersHistory = copyList;
}
@ -562,7 +551,7 @@ public class MapMarkersHelper {
return;
}
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor));
@ -831,7 +820,7 @@ public class MapMarkersHelper {
}
public void addSelectedMarkersToTop(@NonNull List<MapMarker> markers) {
List<MapMarker> markersToRemove = new LinkedList<>();
List<MapMarker> markersToRemove = new ArrayList<>();
for (MapMarker m : mapMarkers) {
if (m.selected) {
if (!markers.contains(m)) {
@ -891,7 +880,7 @@ public class MapMarkersHelper {
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
}
addToMapMarkersHistoryList(mapMarkers);
mapMarkers = new LinkedList<>();
mapMarkers = new ArrayList<>();
sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC);
updateGroups();
refresh();
@ -900,7 +889,7 @@ public class MapMarkersHelper {
public void removeMarkersHistory() {
cancelAddressRequests();
markersDbHelper.clearAllMarkersHistory();
mapMarkersHistory = new LinkedList<>();
mapMarkersHistory = new ArrayList<>();
refresh();
removeHistoryMarkersFromGroups();
}
@ -913,12 +902,10 @@ public class MapMarkersHelper {
}
}
public void removeMarkersSyncGroup(String id, boolean removeActiveMarkers) {
public void removeMarkersSyncGroup(String id) {
if (id != null) {
markersDbHelper.removeMarkersSyncGroup(id);
if (removeActiveMarkers) {
removeActiveMarkersFromSyncGroup(id);
}
removeActiveMarkersFromSyncGroup(id);
MapMarkersGroup group = getMapMarkerGroupByKey(id);
if (group != null) {
removeFromGroupsList(group);
@ -963,7 +950,7 @@ public class MapMarkersHelper {
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
if (syncGroupId != null) {
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
for (int i = 0; i < copyList.size(); i++) {
MapMarker marker = copyList.get(i);
String groupKey = marker.groupKey;

View file

@ -189,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true);
markersHelper.removeMarkersSyncGroup(syncGroup.getId());
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}