Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
17c0c62b2a
6 changed files with 108 additions and 115 deletions
|
@ -1,6 +1,7 @@
|
|||
package net.osmand.plus;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
|
@ -50,7 +51,7 @@ public class MapMarkersHelper {
|
|||
public long creationDate;
|
||||
public long visitedDate;
|
||||
public String nextKey;
|
||||
public long groupKey = -1;
|
||||
public String groupKey;
|
||||
public String groupName;
|
||||
|
||||
public MapMarker(LatLon point, PointDescription name, int colorIndex,
|
||||
|
@ -154,6 +155,34 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static class MarkersSyncGroup {
|
||||
|
||||
public static final int FAVORITES_TYPE = 0;
|
||||
public static final int GPX_TYPE = 1;
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private int type;
|
||||
|
||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public MapMarkersHelper(OsmandApplication ctx) {
|
||||
this.ctx = ctx;
|
||||
settings = ctx.getSettings();
|
||||
|
@ -186,6 +215,7 @@ public class MapMarkersHelper {
|
|||
|
||||
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
|
||||
mapMarkers.addAll(activeMarkers);
|
||||
checkAndFixActiveMarkersOrderIfNeeded();
|
||||
|
||||
List<MapMarker> markersHistory = markersDbHelper.getMarkersHistory();
|
||||
sortMarkers(markersHistory, true);
|
||||
|
@ -253,19 +283,8 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public long getGroupId(String name) {
|
||||
return markersDbHelper.getGroupId(name);
|
||||
}
|
||||
public void syncGroup(MarkersSyncGroup group) {
|
||||
|
||||
// public void removeMarker(double lat, double lon, long groupId) {
|
||||
// markersDbHelper.removeMarker(lat, lon, groupId);
|
||||
// loadMarkers();
|
||||
// refresh();
|
||||
// }
|
||||
|
||||
@Nullable
|
||||
public String getGroupName(long id) {
|
||||
return markersDbHelper.getGroupName(id);
|
||||
}
|
||||
|
||||
public void moveMapMarkerToHistory(MapMarker marker) {
|
||||
|
@ -384,15 +403,15 @@ public class MapMarkersHelper {
|
|||
addMarkers(Collections.singletonList(point), Collections.singletonList(historyName), null);
|
||||
}
|
||||
|
||||
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames, List<String> groups) {
|
||||
addMarkers(points, historyNames, groups);
|
||||
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
|
||||
addMarkers(points, historyNames, group);
|
||||
}
|
||||
|
||||
public void addMapMarkers(List<LatLon> points, List<PointDescription> historyNames) {
|
||||
addMarkers(points, historyNames, null);
|
||||
}
|
||||
|
||||
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable List<String> groups) {
|
||||
private void addMarkers(List<LatLon> points, List<PointDescription> historyNames, @Nullable MarkersSyncGroup group) {
|
||||
if (points.size() > 0) {
|
||||
int colorIndex = -1;
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
|
@ -418,8 +437,12 @@ public class MapMarkersHelper {
|
|||
}
|
||||
|
||||
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
|
||||
if (groups != null) {
|
||||
marker.groupKey = markersDbHelper.createGroupIfNeeded(groups.get(i));
|
||||
if (group != null) {
|
||||
if (markersDbHelper.getGroup(group.getId()) == null) {
|
||||
markersDbHelper.addGroup(group.getId(), group.getName(), group.getType());
|
||||
}
|
||||
marker.id = group.getId() + marker.getName(ctx);
|
||||
marker.groupName = group.getName();
|
||||
}
|
||||
marker.history = false;
|
||||
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
|
||||
|
|
|
@ -30,6 +30,7 @@ import net.osmand.plus.FavouritesDbHelper;
|
|||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
|
@ -188,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names);
|
||||
markersHelper.addMapMarkers(points, names, new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
dismiss();
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -57,6 +58,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -401,18 +403,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
if (getSelectedFavoritesCount() > 0) {
|
||||
if (getSettings().USE_MAP_MARKERS.get()) {
|
||||
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
int size = getSelectedFavoritesCount();
|
||||
List<LatLon> points = new ArrayList<>(size);
|
||||
List<PointDescription> names = new ArrayList<>(size);
|
||||
List<String> groups = new ArrayList<>(size);
|
||||
List<LatLon> points = new LinkedList<>();
|
||||
List<PointDescription> names = new LinkedList<>();
|
||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||
MarkersSyncGroup syncGr = null;
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
syncGr = new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||
}
|
||||
for (FavouritePoint fp : entry.getValue()) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
groups.add(entry.getKey());
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names, syncGr);
|
||||
points.clear();
|
||||
names.clear();
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names, groups);
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
} else {
|
||||
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
|
@ -20,7 +21,7 @@ import java.util.Random;
|
|||
|
||||
public class MapMarkersDbHelper {
|
||||
|
||||
private static final int DB_VERSION = 4;
|
||||
private static final int DB_VERSION = 6;
|
||||
public static final String DB_NAME = "map_markers_db";
|
||||
|
||||
private static final String MARKERS_TABLE_NAME = "map_markers";
|
||||
|
@ -46,7 +47,7 @@ public class MapMarkersDbHelper {
|
|||
MARKERS_COL_ADDED + " long, " +
|
||||
MARKERS_COL_VISITED + " long, " +
|
||||
MARKERS_COL_GROUP_NAME + " TEXT, " +
|
||||
MARKERS_COL_GROUP_KEY + " long, " +
|
||||
MARKERS_COL_GROUP_KEY + " TEXT, " +
|
||||
MARKERS_COL_COLOR + " int, " +
|
||||
MARKERS_COL_NEXT_KEY + " TEXT);";
|
||||
|
||||
|
@ -67,15 +68,18 @@ public class MapMarkersDbHelper {
|
|||
private static final String GROUPS_TABLE_NAME = "map_markers_groups";
|
||||
private static final String GROUPS_COL_ID = "group_id";
|
||||
private static final String GROUPS_COL_NAME = "group_name";
|
||||
private static final String GROUPS_COL_TYPE = "group_type";
|
||||
|
||||
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
|
||||
GROUPS_TABLE_NAME + " (" +
|
||||
GROUPS_COL_ID + " long PRIMARY KEY, " +
|
||||
GROUPS_COL_NAME + " TEXT);";
|
||||
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
|
||||
GROUPS_COL_NAME + " TEXT, " +
|
||||
GROUPS_COL_TYPE + " int);";
|
||||
|
||||
private static final String GROUPS_TABLE_SELECT = "SELECT " +
|
||||
GROUPS_COL_ID + ", " +
|
||||
GROUPS_COL_NAME +
|
||||
GROUPS_COL_NAME + ", " +
|
||||
GROUPS_COL_TYPE +
|
||||
" FROM " + GROUPS_TABLE_NAME;
|
||||
|
||||
public static final String TAIL_NEXT_VALUE = "tail_next";
|
||||
|
@ -149,18 +153,26 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public long createGroupIfNeeded(String name) {
|
||||
long res = -1;
|
||||
public void addGroup(String id, String name, int type) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?",
|
||||
new String[]{name});
|
||||
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?)", new Object[]{id, name, type});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MarkersSyncGroup getGroup(String id) {
|
||||
MarkersSyncGroup res = null;
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id});
|
||||
if (query.moveToFirst()) {
|
||||
res = query.getLong(0);
|
||||
} else {
|
||||
res = Long.parseLong(String.valueOf(System.currentTimeMillis()) + String.valueOf(new Random().nextInt(900) + 100));
|
||||
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?)", new Object[]{res, name});
|
||||
res = readSyncGroup(query);
|
||||
}
|
||||
query.close();
|
||||
} finally {
|
||||
|
@ -170,6 +182,14 @@ public class MapMarkersDbHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
private MarkersSyncGroup readSyncGroup(SQLiteCursor query) {
|
||||
String id = query.getString(0);
|
||||
String name = query.getString(1);
|
||||
int type = query.getInt(2);
|
||||
|
||||
return new MarkersSyncGroup(id, name, type);
|
||||
}
|
||||
|
||||
public void addMarker(MapMarker marker) {
|
||||
addMarker(marker, false);
|
||||
}
|
||||
|
@ -194,7 +214,9 @@ public class MapMarkersDbHelper {
|
|||
} else {
|
||||
currentTime = System.currentTimeMillis();
|
||||
}
|
||||
marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100);
|
||||
if (marker.id == null) {
|
||||
marker.id = String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100);
|
||||
}
|
||||
marker.creationDate = currentTime;
|
||||
String descr = PointDescription.serializeToString(marker.getOriginalPointDescription());
|
||||
int active = marker.history ? 0 : 1;
|
||||
|
@ -217,45 +239,6 @@ public class MapMarkersDbHelper {
|
|||
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE});
|
||||
}
|
||||
|
||||
public long getGroupId(String name) {
|
||||
long res = -1;
|
||||
if (name != null) {
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_NAME + " = ?",
|
||||
new String[]{name});
|
||||
if (query.moveToFirst()) {
|
||||
res = query.getLong(0);
|
||||
}
|
||||
query.close();
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getGroupName(long id) {
|
||||
String res = null;
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?",
|
||||
new String[]{String.valueOf(id)});
|
||||
if (query.moveToFirst()) {
|
||||
res = query.getString(1);
|
||||
}
|
||||
query.close();
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<MapMarker> getActiveMarkers() {
|
||||
List<MapMarker> res = new LinkedList<>();
|
||||
HashMap<String, MapMarker> markers = new LinkedHashMap<>();
|
||||
|
@ -288,7 +271,7 @@ public class MapMarkersDbHelper {
|
|||
long added = query.getLong(5);
|
||||
long visited = query.getLong(6);
|
||||
String groupName = query.getString(7);
|
||||
long groupKey = query.getLong(8);
|
||||
String groupKey = query.getString(8);
|
||||
int colorIndex = query.getInt(9);
|
||||
String nextKey = query.getString(10);
|
||||
|
||||
|
@ -308,12 +291,14 @@ public class MapMarkersDbHelper {
|
|||
|
||||
private void buildLinkedList(HashMap<String, MapMarker> markers, List<MapMarker> res) {
|
||||
if (!markers.isEmpty()) {
|
||||
int count = 1;
|
||||
for (MapMarker marker : markers.values()) {
|
||||
if (!markers.keySet().contains(marker.nextKey)) {
|
||||
if (!markers.keySet().contains(marker.nextKey) || count == markers.size()) {
|
||||
res.add(0, marker);
|
||||
markers.remove(marker.id);
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
buildLinkedList(markers, res);
|
||||
}
|
||||
|
@ -349,38 +334,6 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeMarker(double lat, double lon, long groupId) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
MapMarker marker = null;
|
||||
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " +
|
||||
MARKERS_COL_LAT + " = ? AND " +
|
||||
MARKERS_COL_LON + " = ? AND " +
|
||||
MARKERS_COL_GROUP_KEY + " = ?",
|
||||
new String[]{String.valueOf(lat), String.valueOf(lon), String.valueOf(groupId)});
|
||||
if (query.moveToFirst()) {
|
||||
marker = readItem(query);
|
||||
}
|
||||
query.close();
|
||||
|
||||
if (marker != null) {
|
||||
if (marker.history) {
|
||||
removeMarkerFromHistory(marker);
|
||||
} else {
|
||||
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " +
|
||||
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id});
|
||||
|
||||
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME + " WHERE " + MARKERS_COL_ID + " = ?",
|
||||
new Object[]{marker.id});
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void moveMarkerToHistory(MapMarker marker) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
|
|
|
@ -110,8 +110,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
|||
holder.title.setText(marker.getName(mapActivity));
|
||||
|
||||
String descr;
|
||||
if (marker.groupKey != -1
|
||||
&& (descr = mapActivity.getMyApplication().getMapMarkersHelper().getGroupName(marker.groupKey)) != null) {
|
||||
if ((descr = marker.groupName) != null) {
|
||||
if (descr.equals("")) {
|
||||
descr = mapActivity.getString(R.string.shared_string_favorites);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -607,7 +608,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, i.name));
|
||||
}
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names);
|
||||
File gpx = getGpxDataItem().getFile();
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
markersHelper.addMapMarkers(points, names, syncGroup);
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
} else {
|
||||
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
|
@ -626,6 +629,14 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private String trimExtension(String src) {
|
||||
int index = src.lastIndexOf('.');
|
||||
if (index != -1) {
|
||||
return src.substring(0, index);
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
private void enterFavoritesMode() {
|
||||
actionMode = getActionBarActivity().startSupportActionMode(new ActionMode.Callback() {
|
||||
|
||||
|
|
Loading…
Reference in a new issue