Add possibility to restore marker from history

This commit is contained in:
Alex 2017-09-01 18:23:56 +03:00
parent 7abae45ba8
commit 9aa9fb9c5e
3 changed files with 25 additions and 7 deletions

View file

@ -321,6 +321,12 @@ public class MapMarkersHelper {
refresh(); refresh();
} }
public void addMapMarker(MapMarker marker) {
settings.insertMapMarker(marker.getLatitude(), marker.getLongitude(), marker.pointDescription,
marker.colorIndex, marker.selected, marker.creationDate, 0);
readFromSettings();
}
public void addMapMarker(LatLon point, PointDescription historyName) { public void addMapMarker(LatLon point, PointDescription historyName) {
List<LatLon> points = new ArrayList<>(1); List<LatLon> points = new ArrayList<>(1);
List<PointDescription> historyNames = new ArrayList<>(1); List<PointDescription> historyNames = new ArrayList<>(1);

View file

@ -2179,8 +2179,8 @@ public class OsmandSettings {
} }
public boolean insertPoint(double latitude, double longitude, public boolean insertPoint(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int pos, PointDescription historyDescription, int colorIndex,
boolean selected, int index) { boolean selected, long creationDate, int index) {
List<LatLon> ps = getPoints(); List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size()); List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size()); List<Integer> cs = getColors(ps.size());
@ -2190,7 +2190,7 @@ public class OsmandSettings {
ds.add(index, PointDescription.serializeToString(historyDescription)); ds.add(index, PointDescription.serializeToString(historyDescription));
cs.add(index, colorIndex); cs.add(index, colorIndex);
bs.add(index, selected); bs.add(index, selected);
cds.add(index, System.currentTimeMillis()); cds.add(index, creationDate == 0 ? System.currentTimeMillis() : creationDate);
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) { if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription); SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
} }
@ -2562,10 +2562,10 @@ public class OsmandSettings {
} }
public boolean insertMapMarker(double latitude, double longitude, public boolean insertMapMarker(double latitude, double longitude,
PointDescription historyDescription, int colorIndex, int pos, PointDescription historyDescription, int colorIndex,
boolean selected, int index) { boolean selected, long creationDate, int index) {
return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex, return mapMarkersStorage.insertPoint(latitude, longitude, historyDescription, colorIndex,
index, selected, pos); selected, creationDate, index);
} }
public boolean insertMapMarkers(double[] latitudes, double[] longitudes, public boolean insertMapMarkers(double[] latitudes, double[] longitudes,

View file

@ -40,7 +40,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
} }
@Override @Override
public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) { public void onBindViewHolder(final MapMarkerItemViewHolder holder, int pos) {
IconsCache iconsCache = app.getIconsCache(); IconsCache iconsCache = app.getIconsCache();
MapMarker marker = markers.get(pos); MapMarker marker = markers.get(pos);
@ -50,6 +50,18 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color));
holder.title.setText(marker.getName(app)); holder.title.setText(marker.getName(app));
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_refresh_dark));
holder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = holder.getAdapterPosition();
MapMarker marker = markers.get(position);
app.getMapMarkersHelper().removeMapMarkerHistory(marker);
app.getMapMarkersHelper().addMapMarker(marker);
notifyItemRemoved(position);
}
});
} }
@Override @Override