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();
|
||||
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;
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
sortAll();
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ public class FavouritesDbHelper {
|
|||
p.setLatitude(lat);
|
||||
p.setLongitude(lon);
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -610,7 +610,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
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) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
|
@ -618,7 +618,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
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)) {
|
||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||
|
@ -638,7 +638,7 @@ public class FavouritesDbHelper {
|
|||
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.syncGroupAsync(syncGroup);
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
@ -222,20 +223,21 @@ public class MapMarkersHelper {
|
|||
private String id;
|
||||
private String name;
|
||||
private int type;
|
||||
private int color;
|
||||
|
||||
public MarkersSyncGroup(@NonNull String id, @NonNull String name, int type, int color) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.color = color;
|
||||
}
|
||||
private Set<String> wptCategories;
|
||||
|
||||
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.name = name;
|
||||
this.type = type;
|
||||
this.color = -1;
|
||||
this.wptCategories = wptCategories;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
|
@ -250,12 +252,15 @@ public class MapMarkersHelper {
|
|||
return type;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
public Set<String> getWptCategories() {
|
||||
return wptCategories;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
public String getWptCategoriesString() {
|
||||
if (wptCategories != null) {
|
||||
return Algorithms.encodeStringSet(wptCategories);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -538,9 +543,6 @@ public class MapMarkersHelper {
|
|||
removeActiveMarkersFromGroup(group.getId());
|
||||
return;
|
||||
}
|
||||
if (group.getColor() == -1) {
|
||||
group.setColor(favGroup.color);
|
||||
}
|
||||
|
||||
for (FavouritePoint fp : favGroup.points) {
|
||||
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());
|
||||
int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
|
||||
for (WptPt pt : gpxPoints) {
|
||||
group.setColor(pt.getColor(defColor));
|
||||
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) {
|
||||
if (group != 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 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());
|
||||
|
||||
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()) {
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
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()) {
|
||||
markersHelper.addMarkersSyncGroup(syncGr);
|
||||
markersHelper.syncGroupAsync(syncGr);
|
||||
|
|
|
@ -30,6 +30,6 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
|||
if (!group.visible) {
|
||||
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.SQLiteCursor;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -25,7 +26,7 @@ import java.util.Set;
|
|||
|
||||
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";
|
||||
|
||||
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_TYPE = "group_type";
|
||||
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 " +
|
||||
GROUPS_TABLE_NAME + " (" +
|
||||
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
|
||||
GROUPS_COL_NAME + " TEXT, " +
|
||||
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 " +
|
||||
GROUPS_COL_ID + ", " +
|
||||
GROUPS_COL_NAME + ", " +
|
||||
GROUPS_COL_TYPE + ", " +
|
||||
GROUPS_COL_DISABLED +
|
||||
GROUPS_COL_DISABLED + ", " +
|
||||
GROUPS_COL_CATEGORIES +
|
||||
" FROM " + GROUPS_TABLE_NAME;
|
||||
|
||||
public static final String TAIL_NEXT_VALUE = "tail_next";
|
||||
|
@ -156,6 +160,9 @@ public class MapMarkersDbHelper {
|
|||
if (oldVersion < 12) {
|
||||
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() {
|
||||
|
@ -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);
|
||||
if (db != null) {
|
||||
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 {
|
||||
db.close();
|
||||
}
|
||||
|
@ -241,8 +248,9 @@ public class MapMarkersDbHelper {
|
|||
String id = query.getString(0);
|
||||
String name = query.getString(1);
|
||||
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) {
|
||||
|
@ -385,7 +393,7 @@ public class MapMarkersDbHelper {
|
|||
MARKERS_COL_NEXT_KEY + ", " +
|
||||
MARKERS_COL_DISABLED + ", " +
|
||||
MARKERS_COL_SELECTED + ", " +
|
||||
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
||||
MARKERS_COL_MAP_OBJECT_NAME + ") " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{marker.id, marker.getLatitude(), marker.getLongitude(), descr, active,
|
||||
currentTime, visited, marker.groupName, marker.groupKey, marker.colorIndex,
|
||||
|
|
Loading…
Reference in a new issue