Merge branch 'sasha_pasha_branch' of ssh://github.com/osmandapp/Osmand into sasha_pasha_branch
This commit is contained in:
commit
3b20016b3a
3 changed files with 107 additions and 42 deletions
|
@ -112,11 +112,16 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Set<FavoriteGroup> groupsToDelete, Set<FavouritePoint> favoritesSelected) {
|
public void delete(Set<FavoriteGroup> groupsToDelete, Set<FavouritePoint> favoritesSelected) {
|
||||||
|
MapMarkersHelper markersHelper = context.getMapMarkersHelper();
|
||||||
if (favoritesSelected != null) {
|
if (favoritesSelected != null) {
|
||||||
for (FavouritePoint p : favoritesSelected) {
|
for (FavouritePoint p : favoritesSelected) {
|
||||||
FavoriteGroup group = flatGroups.get(p.getCategory());
|
FavoriteGroup group = flatGroups.get(p.getCategory());
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
group.points.remove(p);
|
group.points.remove(p);
|
||||||
|
long groupId = markersHelper.getGroupId(group.name);
|
||||||
|
if (groupId != -1) {
|
||||||
|
markersHelper.removeMarker(p.getLatitude(), p.getLongitude(), groupId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
cachedFavoritePoints.remove(p);
|
cachedFavoritePoints.remove(p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -224,8 +224,14 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public long createGroupIfNeeded(String name) {
|
public long getGroupId(String name) {
|
||||||
return markersDbHelper.createGroupIfNeeded(name);
|
return markersDbHelper.getGroupId(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeMarker(double lat, double lon, long groupId) {
|
||||||
|
markersDbHelper.removeMarker(lat, lon, groupId);
|
||||||
|
loadMarkers();
|
||||||
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
|
@ -166,6 +166,7 @@ public class MapMarkersDbHelper {
|
||||||
res = Long.parseLong(String.valueOf(System.currentTimeMillis()) + String.valueOf(new Random().nextInt(900) + 100));
|
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});
|
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?)", new Object[]{res, name});
|
||||||
}
|
}
|
||||||
|
query.close();
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
@ -223,6 +224,26 @@ public class MapMarkersDbHelper {
|
||||||
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE});
|
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
|
@Nullable
|
||||||
public String getGroupName(long id) {
|
public String getGroupName(long id) {
|
||||||
String res = null;
|
String res = null;
|
||||||
|
@ -234,6 +255,7 @@ public class MapMarkersDbHelper {
|
||||||
if (query.moveToFirst()) {
|
if (query.moveToFirst()) {
|
||||||
res = query.getString(1);
|
res = query.getString(1);
|
||||||
}
|
}
|
||||||
|
query.close();
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
@ -347,6 +369,38 @@ 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) {
|
public void moveMarkerToHistory(MapMarker marker) {
|
||||||
SQLiteConnection db = openConnection(false);
|
SQLiteConnection db = openConnection(false);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
|
|
Loading…
Reference in a new issue