Fix changing lists and fix adapters
This commit is contained in:
parent
7ce58add2d
commit
4efaccc61c
7 changed files with 102 additions and 128 deletions
|
@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -24,7 +23,6 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -265,8 +263,8 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadMarkers() {
|
private void loadMarkers() {
|
||||||
mapMarkers.clear();
|
mapMarkers = new LinkedList<>();
|
||||||
mapMarkersHistory.clear();
|
mapMarkersHistory = new LinkedList<>();
|
||||||
|
|
||||||
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
|
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
|
||||||
addToMapMarkersList(activeMarkers);
|
addToMapMarkersList(activeMarkers);
|
||||||
|
@ -274,15 +272,21 @@ public class MapMarkersHelper {
|
||||||
|
|
||||||
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
|
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
|
||||||
sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
sortMarkers(markersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||||
mapMarkersHistory.addAll(markersHistory);
|
addToMapMarkersHistoryList(markersHistory);
|
||||||
|
|
||||||
if (!ctx.isApplicationInitializing()) {
|
if (!ctx.isApplicationInitializing()) {
|
||||||
lookupAddressAll();
|
lookupAddressAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeFromMapMarkersList(List<MapMarker> markers) {
|
||||||
|
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
|
||||||
|
copyList.removeAll(markers);
|
||||||
|
mapMarkers = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
private void removeFromMapMarkersList(MapMarker marker) {
|
private void removeFromMapMarkersList(MapMarker marker) {
|
||||||
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
|
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
|
||||||
copyList.remove(marker);
|
copyList.remove(marker);
|
||||||
mapMarkers = copyList;
|
mapMarkers = copyList;
|
||||||
}
|
}
|
||||||
|
@ -292,7 +296,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToMapMarkersList(int position, MapMarker marker) {
|
private void addToMapMarkersList(int position, MapMarker marker) {
|
||||||
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
|
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
|
||||||
copyList.add(position, marker);
|
copyList.add(position, marker);
|
||||||
mapMarkers = copyList;
|
mapMarkers = copyList;
|
||||||
}
|
}
|
||||||
|
@ -302,11 +306,53 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToMapMarkersList(int position, List<MapMarker> markers) {
|
private void addToMapMarkersList(int position, List<MapMarker> markers) {
|
||||||
List<MapMarker> copyList = new ArrayList<>(mapMarkers);
|
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
|
||||||
copyList.addAll(position, markers);
|
copyList.addAll(position, markers);
|
||||||
mapMarkers = copyList;
|
mapMarkers = copyList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void removeFromMapMarkersHistoryList(MapMarker marker) {
|
||||||
|
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
|
||||||
|
copyList.remove(marker);
|
||||||
|
mapMarkersHistory = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToMapMarkersHistoryList(MapMarker marker) {
|
||||||
|
addToMapMarkersHistoryList(mapMarkersHistory.size(), marker);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToMapMarkersHistoryList(int position, MapMarker marker) {
|
||||||
|
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
|
||||||
|
copyList.add(position, marker);
|
||||||
|
mapMarkersHistory = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToMapMarkersHistoryList(int position, List<MapMarker> markers) {
|
||||||
|
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory);
|
||||||
|
copyList.addAll(position, markers);
|
||||||
|
mapMarkersHistory = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToMapMarkersHistoryList(List<MapMarker> markers) {
|
||||||
|
addToMapMarkersHistoryList(mapMarkersHistory.size(), markers);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void removeFromGroupsList(MapMarkersGroup group) {
|
||||||
|
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
|
||||||
|
copyList.remove(group);
|
||||||
|
mapMarkersGroups = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToGroupsList(int position, MapMarkersGroup group) {
|
||||||
|
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
|
||||||
|
copyList.add(position, group);
|
||||||
|
mapMarkersGroups = copyList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToGroupsList(MapMarkersGroup group) {
|
||||||
|
addToGroupsList(mapMarkersGroups.size(), group);
|
||||||
|
}
|
||||||
|
|
||||||
public void reorderActiveMarkersIfNeeded() {
|
public void reorderActiveMarkersIfNeeded() {
|
||||||
if (!mapMarkers.isEmpty()) {
|
if (!mapMarkers.isEmpty()) {
|
||||||
if (mapMarkers.size() > 1) {
|
if (mapMarkers.size() > 1) {
|
||||||
|
@ -507,7 +553,7 @@ public class MapMarkersHelper {
|
||||||
removeFromMapMarkersList(marker);
|
removeFromMapMarkersList(marker);
|
||||||
marker.history = true;
|
marker.history = true;
|
||||||
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
|
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
|
||||||
mapMarkersHistory.add(marker);
|
addToMapMarkersHistoryList(marker);
|
||||||
reorderActiveMarkersIfNeeded();
|
reorderActiveMarkersIfNeeded();
|
||||||
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -528,7 +574,7 @@ public class MapMarkersHelper {
|
||||||
if (marker != null) {
|
if (marker != null) {
|
||||||
markersDbHelper.addMarker(marker);
|
markersDbHelper.addMarker(marker);
|
||||||
if (marker.history) {
|
if (marker.history) {
|
||||||
mapMarkersHistory.add(marker);
|
addToMapMarkersHistoryList(marker);
|
||||||
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||||
} else {
|
} else {
|
||||||
addToMapMarkersList(marker);
|
addToMapMarkersList(marker);
|
||||||
|
@ -542,7 +588,7 @@ public class MapMarkersHelper {
|
||||||
public void restoreMarkerFromHistory(MapMarker marker, int position) {
|
public void restoreMarkerFromHistory(MapMarker marker, int position) {
|
||||||
if (marker != null) {
|
if (marker != null) {
|
||||||
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
||||||
mapMarkersHistory.remove(marker);
|
removeFromMapMarkersHistoryList(marker);
|
||||||
marker.history = false;
|
marker.history = false;
|
||||||
addToMapMarkersList(position, marker);
|
addToMapMarkersList(position, marker);
|
||||||
reorderActiveMarkersIfNeeded();
|
reorderActiveMarkersIfNeeded();
|
||||||
|
@ -555,7 +601,7 @@ public class MapMarkersHelper {
|
||||||
if (markers != null) {
|
if (markers != null) {
|
||||||
for (MapMarker marker : markers) {
|
for (MapMarker marker : markers) {
|
||||||
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
||||||
mapMarkersHistory.remove(marker);
|
removeFromMapMarkersHistoryList(marker);
|
||||||
marker.history = false;
|
marker.history = false;
|
||||||
addToMapMarkersList(marker);
|
addToMapMarkersList(marker);
|
||||||
}
|
}
|
||||||
|
@ -571,7 +617,7 @@ public class MapMarkersHelper {
|
||||||
boolean history = marker.history;
|
boolean history = marker.history;
|
||||||
markersDbHelper.removeMarker(marker, history);
|
markersDbHelper.removeMarker(marker, history);
|
||||||
if (history) {
|
if (history) {
|
||||||
mapMarkersHistory.remove(marker);
|
removeFromMapMarkersHistoryList(marker);
|
||||||
} else {
|
} else {
|
||||||
removeFromMapMarkersList(marker);
|
removeFromMapMarkersList(marker);
|
||||||
}
|
}
|
||||||
|
@ -648,7 +694,7 @@ public class MapMarkersHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapMarkers.removeAll(markersToRemove);
|
removeFromMapMarkersList(markersToRemove);
|
||||||
addToMapMarkersList(0, markers);
|
addToMapMarkersList(0, markers);
|
||||||
reorderActiveMarkersIfNeeded();
|
reorderActiveMarkersIfNeeded();
|
||||||
ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
|
ctx.getSettings().MAP_MARKERS_ORDER_BY_MODE.set(OsmandSettings.MapMarkersOrderByMode.CUSTOM);
|
||||||
|
@ -696,8 +742,8 @@ public class MapMarkersHelper {
|
||||||
marker.history = true;
|
marker.history = true;
|
||||||
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
|
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
|
||||||
}
|
}
|
||||||
mapMarkersHistory.addAll(mapMarkers);
|
addToMapMarkersHistoryList(mapMarkers);
|
||||||
mapMarkers.clear();
|
mapMarkers = new LinkedList<>();
|
||||||
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
sortMarkers(mapMarkersHistory, true, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||||
updateGroups();
|
updateGroups();
|
||||||
refresh();
|
refresh();
|
||||||
|
@ -706,7 +752,7 @@ public class MapMarkersHelper {
|
||||||
public void removeMarkersHistory() {
|
public void removeMarkersHistory() {
|
||||||
cancelAddressRequests();
|
cancelAddressRequests();
|
||||||
markersDbHelper.clearAllMarkersHistory();
|
markersDbHelper.clearAllMarkersHistory();
|
||||||
mapMarkersHistory.clear();
|
mapMarkersHistory = new LinkedList<>();
|
||||||
refresh();
|
refresh();
|
||||||
removeHistoryMarkersFromGroups();
|
removeHistoryMarkersFromGroups();
|
||||||
}
|
}
|
||||||
|
@ -727,7 +773,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
MapMarkersGroup group = getMapMarkerGroupByKey(id);
|
MapMarkersGroup group = getMapMarkerGroupByKey(id);
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
mapMarkersGroups.remove(group);
|
removeFromGroupsList(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,9 +795,9 @@ public class MapMarkersHelper {
|
||||||
for (MapMarker marker : groupMarkers) {
|
for (MapMarker marker : groupMarkers) {
|
||||||
if (marker.history) {
|
if (marker.history) {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
mapMarkersHistory.remove(marker);
|
removeFromMapMarkersHistoryList(marker);
|
||||||
} else {
|
} else {
|
||||||
mapMarkersHistory.add(marker);
|
addToMapMarkersHistoryList(marker);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
|
@ -769,10 +815,12 @@ public class MapMarkersHelper {
|
||||||
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
|
public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
|
||||||
if (syncGroupId != null) {
|
if (syncGroupId != null) {
|
||||||
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
|
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
|
||||||
for (Iterator<MapMarker> iterator = mapMarkers.iterator(); iterator.hasNext(); ) {
|
List<MapMarker> copyList = new LinkedList<>(mapMarkers);
|
||||||
String groupKey = iterator.next().groupKey;
|
for (int i = 0; i < copyList.size(); i++) {
|
||||||
|
MapMarker marker = copyList.get(i);
|
||||||
|
String groupKey = marker.groupKey;
|
||||||
if (groupKey != null && groupKey.equals(syncGroupId)) {
|
if (groupKey != null && groupKey.equals(syncGroupId)) {
|
||||||
iterator.remove();
|
removeFromMapMarkersList(marker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reorderActiveMarkersIfNeeded();
|
reorderActiveMarkersIfNeeded();
|
||||||
|
@ -1020,7 +1068,7 @@ public class MapMarkersHelper {
|
||||||
|
|
||||||
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
|
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
|
||||||
if (mapMarkersGroup.getMarkers().size() == 0) {
|
if (mapMarkersGroup.getMarkers().size() == 0) {
|
||||||
mapMarkersGroups.remove(mapMarkersGroup);
|
removeFromGroupsList(mapMarkersGroup);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
|
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
|
||||||
|
@ -1086,7 +1134,7 @@ public class MapMarkersHelper {
|
||||||
group.setColor(MapMarker.getColorId(marker.colorIndex));
|
group.setColor(MapMarker.getColorId(marker.colorIndex));
|
||||||
}
|
}
|
||||||
group.setCreationDate(marker.creationDate);
|
group.setCreationDate(marker.creationDate);
|
||||||
mapMarkersGroups.add(group);
|
addToGroupsList(group);
|
||||||
sortGroups();
|
sortGroups();
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
@ -1159,7 +1207,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
mapMarkersGroups = new ArrayList<>(groupsMap.values());
|
mapMarkersGroups = new ArrayList<>(groupsMap.values());
|
||||||
if (noGroup != null) {
|
if (noGroup != null) {
|
||||||
mapMarkersGroups.add(noGroup);
|
addToGroupsList(noGroup);
|
||||||
}
|
}
|
||||||
sortGroups();
|
sortGroups();
|
||||||
|
|
||||||
|
@ -1175,7 +1223,8 @@ public class MapMarkersHelper {
|
||||||
MapMarkersGroup group = mapMarkersGroups.get(i);
|
MapMarkersGroup group = mapMarkersGroups.get(i);
|
||||||
if (group.getName() == null) {
|
if (group.getName() == null) {
|
||||||
sortMarkers(group.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
sortMarkers(group.getMarkers(), false, OsmandSettings.MapMarkersOrderByMode.DATE_ADDED_DESC);
|
||||||
noGroup = mapMarkersGroups.remove(i);
|
removeFromGroupsList(group);
|
||||||
|
noGroup = group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
|
Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
|
||||||
|
@ -1193,7 +1242,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (noGroup != null) {
|
if (noGroup != null) {
|
||||||
mapMarkersGroups.add(0, noGroup);
|
addToGroupsList(0, noGroup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,7 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
||||||
|
|
||||||
void updateAdapter() {
|
void updateAdapter() {
|
||||||
if (adapter != null) {
|
if (adapter != null) {
|
||||||
|
adapter.changeMarkers();
|
||||||
adapter.notifyDataSetChanged();
|
adapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,10 +185,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
||||||
int snackbarStringRes;
|
int snackbarStringRes;
|
||||||
if (direction == ItemTouchHelper.RIGHT) {
|
if (direction == ItemTouchHelper.RIGHT) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
|
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory((MapMarker) item);
|
||||||
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName);
|
|
||||||
if (group != null) {
|
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
|
||||||
}
|
|
||||||
snackbarStringRes = R.string.marker_moved_to_history;
|
snackbarStringRes = R.string.marker_moved_to_history;
|
||||||
} else {
|
} else {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
|
mapActivity.getMyApplication().getMapMarkersHelper().removeMarker((MapMarker) item);
|
||||||
|
|
|
@ -158,7 +158,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
app.getMapMarkersHelper().removeMarker((MapMarker) item);
|
app.getMapMarkersHelper().removeMarker((MapMarker) item);
|
||||||
snackbarStringRes = R.string.item_removed;
|
snackbarStringRes = R.string.item_removed;
|
||||||
}
|
}
|
||||||
adapter.notifyItemRemoved(pos);
|
|
||||||
snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,7 +230,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
Object item = adapter.getItem(pos);
|
Object item = adapter.getItem(pos);
|
||||||
if (item instanceof MapMarker) {
|
if (item instanceof MapMarker) {
|
||||||
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
|
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
|
||||||
adapter.notifyItemRemoved(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +238,6 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
||||||
Object item = adapter.getItem(pos);
|
Object item = adapter.getItem(pos);
|
||||||
if (item instanceof MapMarker) {
|
if (item instanceof MapMarker) {
|
||||||
app.getMapMarkersHelper().removeMarker((MapMarker) item);
|
app.getMapMarkersHelper().removeMarker((MapMarker) item);
|
||||||
adapter.notifyItemRemoved(pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
||||||
private boolean night;
|
private boolean night;
|
||||||
|
|
||||||
public MapMarkersActiveAdapter(MapActivity mapActivity) {
|
public MapMarkersActiveAdapter(MapActivity mapActivity) {
|
||||||
|
setHasStableIds(true);
|
||||||
this.mapActivity = mapActivity;
|
this.mapActivity = mapActivity;
|
||||||
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
|
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
|
||||||
night = !mapActivity.getMyApplication().getSettings().isLightContent();
|
night = !mapActivity.getMyApplication().getSettings().isLightContent();
|
||||||
|
@ -172,24 +173,16 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
||||||
final MapMarker marker = markers.get(position);
|
final MapMarker marker = markers.get(position);
|
||||||
|
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
||||||
notifyItemRemoved(position);
|
changeMarkers();
|
||||||
if (showDirectionEnabled && position < 2 && getItemCount() > 1) {
|
notifyDataSetChanged();
|
||||||
notifyItemChanged(1);
|
|
||||||
} else if (position == getItemCount()) {
|
|
||||||
notifyItemChanged(position - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
|
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
|
||||||
notifyItemInserted(position);
|
changeMarkers();
|
||||||
if (showDirectionEnabled && position < 2 && getItemCount() > 2) {
|
notifyDataSetChanged();
|
||||||
notifyItemChanged(2);
|
|
||||||
} else if (position == getItemCount() - 1) {
|
|
||||||
notifyItemChanged(position - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
View snackBarView = snackbar.getView();
|
View snackBarView = snackbar.getView();
|
||||||
|
@ -218,6 +211,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
||||||
return markers;
|
return markers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeMarkers() {
|
||||||
|
markers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
|
||||||
|
}
|
||||||
|
|
||||||
public void hideSnackbar() {
|
public void hideSnackbar() {
|
||||||
if (snackbar != null && snackbar.isShown()) {
|
if (snackbar != null && snackbar.isShown()) {
|
||||||
snackbar.dismiss();
|
snackbar.dismiss();
|
||||||
|
@ -245,23 +242,15 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
||||||
}
|
}
|
||||||
notifyItemRemoved(pos);
|
changeMarkers();
|
||||||
if (showDirectionEnabled && pos < 2 && getItemCount() > 1) {
|
notifyDataSetChanged();
|
||||||
notifyItemChanged(1);
|
|
||||||
} else if (pos == getItemCount()) {
|
|
||||||
notifyItemChanged(pos - 1);
|
|
||||||
}
|
|
||||||
snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
|
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
|
||||||
notifyItemInserted(pos);
|
changeMarkers();
|
||||||
if (showDirectionEnabled && pos < 2 && getItemCount() > 2) {
|
notifyDataSetChanged();
|
||||||
notifyItemChanged(2);
|
|
||||||
} else if (pos == getItemCount() - 1) {
|
|
||||||
notifyItemChanged(pos - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
View snackBarView = snackbar.getView();
|
View snackBarView = snackbar.getView();
|
||||||
|
@ -270,6 +259,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
||||||
snackbar.show();
|
snackbar.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(int position) {
|
||||||
|
return getItem(position).hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemDismiss(RecyclerView.ViewHolder holder) {
|
public void onItemDismiss(RecyclerView.ViewHolder holder) {
|
||||||
listener.onDragOrSwipeEnded(holder);
|
listener.onDragOrSwipeEnded(holder);
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createDisplayGroups() {
|
public void createDisplayGroups() {
|
||||||
items.clear();
|
items = new ArrayList<>();
|
||||||
app.getMapMarkersHelper().updateGroups();
|
app.getMapMarkersHelper().updateGroups();
|
||||||
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
|
List<MapMarkersGroup> groups = app.getMapMarkersHelper().getMapMarkersGroups();
|
||||||
for (int i = 0; i < groups.size(); i++) {
|
for (int i = 0; i < groups.size(); i++) {
|
||||||
|
@ -291,8 +291,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
itemViewHolder.description.setVisibility(View.GONE);
|
itemViewHolder.description.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String markerGroupName = marker.groupName;
|
|
||||||
final MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupByName(markerGroupName);
|
|
||||||
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
|
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
|
@ -302,42 +300,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
}
|
}
|
||||||
if (markerInHistory) {
|
if (markerInHistory) {
|
||||||
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
||||||
if (group != null) {
|
|
||||||
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
|
|
||||||
if (showHideHistoryButton != null) {
|
|
||||||
if (group.getHistoryMarkers().size() == 0) {
|
|
||||||
items.remove(showHideHistoryButton);
|
|
||||||
group.setShowHideHistoryButton(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
||||||
if (group != null) {
|
|
||||||
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
|
|
||||||
if (showHideHistoryButton == null) {
|
|
||||||
items.remove(marker);
|
|
||||||
if (markerGroupName != null) {
|
|
||||||
showHideHistoryButton = new ShowHideHistoryButton();
|
|
||||||
showHideHistoryButton.setShowHistory(false);
|
|
||||||
showHideHistoryButton.setMarkerGroup(group);
|
|
||||||
int index = getLastDisplayItemIndexOfGroup(group);
|
|
||||||
if (index != -1) {
|
|
||||||
items.add(index + 1, showHideHistoryButton);
|
|
||||||
group.setShowHideHistoryButton(showHideHistoryButton);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
boolean firstItemInDisplayGroup = position - 1 != -1 && getItem(position - 1) instanceof Integer;
|
|
||||||
boolean lastItemInDisplayGroup = position == getItemCount() || !(getItem(position) instanceof MapMarker);
|
|
||||||
if (firstItemInDisplayGroup && lastItemInDisplayGroup) {
|
|
||||||
items.remove(position - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (!showHideHistoryButton.isShowHistory()) {
|
|
||||||
items.remove(marker);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
createDisplayGroups();
|
||||||
updateShowDirectionMarkers();
|
updateShowDirectionMarkers();
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
if (!markerInHistory) {
|
if (!markerInHistory) {
|
||||||
|
@ -415,7 +381,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||||
group.setDisabled(!enabled);
|
group.setDisabled(!enabled);
|
||||||
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
|
app.getMapMarkersHelper().updateGroupDisabled(group, !enabled);
|
||||||
populateAdapterWithGroupMarkers(group, headerViewHolder.getAdapterPosition() + 1);
|
createDisplayGroups();
|
||||||
updateShowDirectionMarkers();
|
updateShowDirectionMarkers();
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
if (!enabled) {
|
if (!enabled) {
|
||||||
|
@ -454,15 +420,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
List<MapMarker> historyMarkers = showHideHistoryButton.getMapMarkerGroup().getHistoryMarkers();
|
showHideHistoryButton.setShowHistory(!showHistory);
|
||||||
int pos = holder.getAdapterPosition();
|
createDisplayGroups();
|
||||||
if (showHistory) {
|
|
||||||
showHideHistoryButton.setShowHistory(false);
|
|
||||||
items.removeAll(historyMarkers);
|
|
||||||
} else {
|
|
||||||
showHideHistoryButton.setShowHistory(true);
|
|
||||||
items.addAll(pos, historyMarkers);
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -509,24 +468,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
return monthStr;
|
return monthStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLastDisplayItemIndexOfGroup(MapMarkersGroup group) {
|
|
||||||
List<MapMarker> markers = group.getActiveMarkers();
|
|
||||||
int index = -1;
|
|
||||||
for (MapMarker marker : markers) {
|
|
||||||
int markerIndex = items.indexOf(marker);
|
|
||||||
if (markerIndex > index) {
|
|
||||||
index = markerIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (index == -1) {
|
|
||||||
GroupHeader header = group.getGroupHeader();
|
|
||||||
if (header != null) {
|
|
||||||
index = items.indexOf(group.getGroupHeader());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface MapMarkersGroupsAdapterListener {
|
public interface MapMarkersGroupsAdapterListener {
|
||||||
|
|
||||||
void onItemClick(View view);
|
void onItemClick(View view);
|
||||||
|
|
|
@ -43,10 +43,8 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createHeaders() {
|
public void createHeaders() {
|
||||||
items.clear();
|
items = new ArrayList<>();
|
||||||
|
|
||||||
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
|
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
|
||||||
|
|
||||||
int previousHeader = -1;
|
int previousHeader = -1;
|
||||||
int monthsDisplayed = 0;
|
int monthsDisplayed = 0;
|
||||||
|
|
||||||
|
@ -151,14 +149,12 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
|
||||||
notifyItemRemoved(position);
|
|
||||||
|
|
||||||
snackbar = Snackbar.make(itemViewHolder.itemView, app.getString(R.string.marker_moved_to_active), Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(itemViewHolder.itemView, app.getString(R.string.marker_moved_to_active), Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
View snackBarView = snackbar.getView();
|
View snackBarView = snackbar.getView();
|
||||||
|
|
Loading…
Reference in a new issue