Save markers on exit

This commit is contained in:
PavelRatushnyi 2017-10-25 19:39:03 +03:00
parent 7670f6667a
commit 107a10476c
4 changed files with 46 additions and 2 deletions

View file

@ -477,6 +477,18 @@ public class MapMarkersHelper {
}
}
public void addMarkers(List<MapMarker> markers) {
if (markers != null) {
markersDbHelper.addMarkers(markers);
mapMarkers.addAll(markers);
reorderActiveMarkersIfNeeded();
for (MapMarker marker : markers) {
addMarkerToGroup(marker);
}
refresh();
}
}
public void addMarker(MapMarker marker) {
if (marker != null) {
markersDbHelper.addMarker(marker);

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers;
import android.app.Dialog;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
@ -93,6 +94,18 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private boolean compassUpdateAllowed = true;
private MapMarkersHelper mapMarkersHelper;
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getContext(), getTheme()) {
@Override
public void onBackPressed() {
saveMarkers();
super.onBackPressed();
}
};
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -125,6 +138,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
saveMarkers();
dismiss();
}
});
@ -285,6 +299,10 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
super.onDestroyView();
}
private void saveMarkers() {
mapMarkersHelper.addMarkers(mapMarkers);
}
private void registerTextFieldBoxes() {
View.OnTouchListener textFieldBoxOnTouchListener = new View.OnTouchListener() {
@Override

View file

@ -287,6 +287,19 @@ public class MapMarkersDbHelper {
}
}
public void addMarkers(List<MapMarker> markers) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
for (MapMarker marker : markers) {
insertLast(db, marker, false);
}
} finally {
db.close();
}
}
}
public void addMarker(MapMarker marker) {
addMarker(marker, false);
}

View file

@ -9,13 +9,12 @@ import android.view.ViewGroup;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import java.util.ArrayList;
import java.util.List;
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
@ -119,6 +118,8 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
}
MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
mapMarker.history = false;
mapMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
mapMarkers.add(mapMarker);
notifyDataSetChanged();
}