Add new field "categories" to markers sync group; remove unused field "color"
This commit is contained in:
parent
a58359b442
commit
437077b3c3
6 changed files with 43 additions and 35 deletions
|
@ -180,7 +180,7 @@ public class FavouritesDbHelper {
|
||||||
sortAll();
|
sortAll();
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
}
|
}
|
||||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ public class FavouritesDbHelper {
|
||||||
}
|
}
|
||||||
sortAll();
|
sortAll();
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,7 +283,7 @@ public class FavouritesDbHelper {
|
||||||
p.setLatitude(lat);
|
p.setLatitude(lat);
|
||||||
p.setLongitude(lon);
|
p.setLongitude(lon);
|
||||||
saveCurrentPointsIntoFile();
|
saveCurrentPointsIntoFile();
|
||||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ public class FavouritesDbHelper {
|
||||||
for (FavouritePoint p : gr.points) {
|
for (FavouritePoint p : gr.points) {
|
||||||
p.setColor(color);
|
p.setColor(color);
|
||||||
}
|
}
|
||||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
|
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
}
|
}
|
||||||
if (group.visible != visible) {
|
if (group.visible != visible) {
|
||||||
FavoriteGroup gr = flatGroups.get(group.name);
|
FavoriteGroup gr = flatGroups.get(group.name);
|
||||||
|
@ -618,7 +618,7 @@ public class FavouritesDbHelper {
|
||||||
for (FavouritePoint p : gr.points) {
|
for (FavouritePoint p : gr.points) {
|
||||||
p.setVisible(visible);
|
p.setVisible(visible);
|
||||||
}
|
}
|
||||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
}
|
}
|
||||||
if (!group.name.equals(newName)) {
|
if (!group.name.equals(newName)) {
|
||||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||||
|
@ -638,7 +638,7 @@ public class FavouritesDbHelper {
|
||||||
renamedGroup.points.add(p);
|
renamedGroup.points.add(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||||
markersHelper.syncGroupAsync(syncGroup);
|
markersHelper.syncGroupAsync(syncGroup);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@ -222,20 +223,21 @@ public class MapMarkersHelper {
|
||||||
private String id;
|
private String id;
|
||||||
private String name;
|
private String name;
|
||||||
private int type;
|
private int type;
|
||||||
private int color;
|
private Set<String> wptCategories;
|
||||||
|
|
||||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type, int color) {
|
|
||||||
this.id = id;
|
|
||||||
this.name = name;
|
|
||||||
this.type = type;
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type) {
|
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type) {
|
||||||
|
init(id, name, type, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type, @Nullable Set<String> wptCategories) {
|
||||||
|
init(id, name, type, wptCategories);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(String id, String name, int type, Set<String> wptCategories) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.color = -1;
|
this.wptCategories = wptCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -250,12 +252,15 @@ public class MapMarkersHelper {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColor() {
|
public Set<String> getWptCategories() {
|
||||||
return color;
|
return wptCategories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setColor(int color) {
|
public String getWptCategoriesString() {
|
||||||
this.color = color;
|
if (wptCategories != null) {
|
||||||
|
return Algorithms.encodeStringSet(wptCategories);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -538,9 +543,6 @@ public class MapMarkersHelper {
|
||||||
removeActiveMarkersFromGroup(group.getId());
|
removeActiveMarkersFromGroup(group.getId());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (group.getColor() == -1) {
|
|
||||||
group.setColor(favGroup.color);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (FavouritePoint fp : favGroup.points) {
|
for (FavouritePoint fp : favGroup.points) {
|
||||||
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled, fp, null);
|
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), enabled, fp, null);
|
||||||
|
@ -563,9 +565,7 @@ public class MapMarkersHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
|
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints());
|
||||||
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
|
|
||||||
for (WptPt pt : gpxPoints) {
|
for (WptPt pt : gpxPoints) {
|
||||||
group.setColor(pt.getColor(defColor));
|
|
||||||
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled, null, pt);
|
addNewMarkerIfNeeded(group, dbMarkers, new LatLon(pt.lat, pt.lon), pt.name, enabled, null, pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -908,7 +908,7 @@ public class MapMarkersHelper {
|
||||||
public void addMarkersSyncGroup(MarkersSyncGroup group) {
|
public void addMarkersSyncGroup(MarkersSyncGroup group) {
|
||||||
if (group != null) {
|
if (group != null) {
|
||||||
if (markersDbHelper.getGroup(group.getId()) == null) {
|
if (markersDbHelper.getGroup(group.getId()) == null) {
|
||||||
markersDbHelper.addGroup(group.getId(), group.getName(), group.getType());
|
markersDbHelper.addGroup(group.getId(), group.getName(), group.getType(), group.getWptCategoriesString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
||||||
|
|
||||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||||
final MarkersSyncGroup syncGroup =
|
final MarkersSyncGroup syncGroup =
|
||||||
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||||
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup.getId());
|
||||||
|
|
||||||
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
|
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
|
||||||
|
|
|
@ -431,7 +431,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||||
MarkersSyncGroup syncGr =
|
MarkersSyncGroup syncGr =
|
||||||
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
|
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE);
|
||||||
if (entry.getValue().size() == favGr.points.size()) {
|
if (entry.getValue().size() == favGr.points.size()) {
|
||||||
markersHelper.addMarkersSyncGroup(syncGr);
|
markersHelper.addMarkersSyncGroup(syncGr);
|
||||||
markersHelper.syncGroupAsync(syncGr);
|
markersHelper.syncGroupAsync(syncGr);
|
||||||
|
|
|
@ -30,6 +30,6 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
||||||
if (!group.visible) {
|
if (!group.visible) {
|
||||||
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
|
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
|
||||||
}
|
}
|
||||||
addAndSyncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
addAndSyncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -25,7 +26,7 @@ import java.util.Set;
|
||||||
|
|
||||||
public class MapMarkersDbHelper {
|
public class MapMarkersDbHelper {
|
||||||
|
|
||||||
private static final int DB_VERSION = 12;
|
private static final int DB_VERSION = 13;
|
||||||
public static final String DB_NAME = "map_markers_db";
|
public static final String DB_NAME = "map_markers_db";
|
||||||
|
|
||||||
private static final String MARKERS_TABLE_NAME = "map_markers";
|
private static final String MARKERS_TABLE_NAME = "map_markers";
|
||||||
|
@ -83,19 +84,22 @@ public class MapMarkersDbHelper {
|
||||||
private static final String GROUPS_COL_NAME = "group_name";
|
private static final String GROUPS_COL_NAME = "group_name";
|
||||||
private static final String GROUPS_COL_TYPE = "group_type";
|
private static final String GROUPS_COL_TYPE = "group_type";
|
||||||
private static final String GROUPS_COL_DISABLED = "group_disabled";
|
private static final String GROUPS_COL_DISABLED = "group_disabled";
|
||||||
|
private static final String GROUPS_COL_CATEGORIES = "group_categories";
|
||||||
|
|
||||||
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
|
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
|
||||||
GROUPS_TABLE_NAME + " (" +
|
GROUPS_TABLE_NAME + " (" +
|
||||||
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
|
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
|
||||||
GROUPS_COL_NAME + " TEXT, " +
|
GROUPS_COL_NAME + " TEXT, " +
|
||||||
GROUPS_COL_TYPE + " int, " +
|
GROUPS_COL_TYPE + " int, " +
|
||||||
GROUPS_COL_DISABLED + " int);"; // 1 = true, 0 = false
|
GROUPS_COL_DISABLED + " int, " + // 1 = true, 0 = false
|
||||||
|
GROUPS_COL_CATEGORIES + " TEXT);";
|
||||||
|
|
||||||
private static final String GROUPS_TABLE_SELECT = "SELECT " +
|
private static final String GROUPS_TABLE_SELECT = "SELECT " +
|
||||||
GROUPS_COL_ID + ", " +
|
GROUPS_COL_ID + ", " +
|
||||||
GROUPS_COL_NAME + ", " +
|
GROUPS_COL_NAME + ", " +
|
||||||
GROUPS_COL_TYPE + ", " +
|
GROUPS_COL_TYPE + ", " +
|
||||||
GROUPS_COL_DISABLED +
|
GROUPS_COL_DISABLED + ", " +
|
||||||
|
GROUPS_COL_CATEGORIES +
|
||||||
" FROM " + GROUPS_TABLE_NAME;
|
" FROM " + GROUPS_TABLE_NAME;
|
||||||
|
|
||||||
public static final String TAIL_NEXT_VALUE = "tail_next";
|
public static final String TAIL_NEXT_VALUE = "tail_next";
|
||||||
|
@ -156,6 +160,9 @@ public class MapMarkersDbHelper {
|
||||||
if (oldVersion < 12) {
|
if (oldVersion < 12) {
|
||||||
db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT");
|
db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT");
|
||||||
}
|
}
|
||||||
|
if (oldVersion < 13) {
|
||||||
|
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_CATEGORIES + " TEXT");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveExistingMarkersToDb() {
|
private void saveExistingMarkersToDb() {
|
||||||
|
@ -189,11 +196,11 @@ public class MapMarkersDbHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addGroup(String id, String name, int type) {
|
public void addGroup(String id, String name, int type, String categories) {
|
||||||
SQLiteConnection db = openConnection(false);
|
SQLiteConnection db = openConnection(false);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?)", new Object[]{id, name, type, 0});
|
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)", new Object[]{id, name, type, 0, categories});
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
@ -241,8 +248,9 @@ public class MapMarkersDbHelper {
|
||||||
String id = query.getString(0);
|
String id = query.getString(0);
|
||||||
String name = query.getString(1);
|
String name = query.getString(1);
|
||||||
int type = query.getInt(2);
|
int type = query.getInt(2);
|
||||||
|
String categories = query.getString(4);
|
||||||
|
|
||||||
return new MarkersSyncGroup(id, name, type);
|
return new MarkersSyncGroup(id, name, type, categories == null ? null : Algorithms.decodeStringSet(categories));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeMarkersSyncGroup(String id) {
|
public void removeMarkersSyncGroup(String id) {
|
||||||
|
|
Loading…
Reference in a new issue