Completely remove old map markers from OsmandSettings

This commit is contained in:
Alex Sytnyk 2018-07-16 16:39:01 +03:00
parent 31021eb2c6
commit 51e0d34707
2 changed files with 0 additions and 366 deletions

View file

@ -1793,19 +1793,6 @@ public class OsmandSettings {
public final static String INTERMEDIATE_POINTS_BACKUP = "intermediate_points_backup"; //$NON-NLS-1$
public final static String INTERMEDIATE_POINTS_DESCRIPTION_BACKUP = "intermediate_points_description_backup"; //$NON-NLS-1$
public final static String MAP_MARKERS_POINT = "map_markers_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_COLOR = "map_markers_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_DESCRIPTION = "map_markers_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_SELECTION = "map_markers_selection"; //$NON-NLS-1$
public final static String MAP_MARKERS_CREATION_DATE = "map_markers_creation_date"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_POINT = "map_markers_history_point"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_COLOR = "map_markers_history_color"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_DESCRIPTION = "map_markers_history_description"; //$NON-NLS-1$
public final static String MAP_MARKERS_HISTORY_CREATION_DATE = "map_markers_history_creation_date"; //$NON-NLS-1$
public final static int MAP_MARKERS_HISTORY_LIMIT = 30;
private MapMarkersStorage mapMarkersStorage = new MapMarkersStorage();
private MapMarkersHistoryStorage mapMarkersHistoryStorage = new MapMarkersHistoryStorage();
private static final String IMPASSABLE_ROAD_POINTS = "impassable_road_points";
private static final String IMPASSABLE_ROADS_DESCRIPTIONS = "impassable_roads_descriptions";
private ImpassableRoadsStorage mImpassableRoadsStorage = new ImpassableRoadsStorage();
@ -1926,300 +1913,6 @@ public class OsmandSettings {
}
}
private class MapMarkersHistoryStorage extends MapPointsStorage {
protected String colorsKey;
protected String creationDatesKey;
public MapMarkersHistoryStorage() {
pointsKey = MAP_MARKERS_HISTORY_POINT;
descriptionsKey = MAP_MARKERS_HISTORY_DESCRIPTION;
colorsKey = MAP_MARKERS_HISTORY_COLOR;
creationDatesKey = MAP_MARKERS_HISTORY_CREATION_DATE;
}
public List<Integer> getColors(int sz) {
List<Integer> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, colorsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String colorStr = tok.nextToken();
list.add(Integer.parseInt(colorStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
int i = 0;
while (list.size() < sz) {
list.add(i % MapMarkersHelper.MAP_MARKERS_COLORS_COUNT);
i++;
}
return list;
}
public List<Long> getCreationDates(int sz) {
List<Long> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String creationDateStr = tok.nextToken();
list.add(Long.parseLong(creationDateStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(0L);
}
return list;
}
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs, List<Long> cds) {
while (ps.size() > MAP_MARKERS_HISTORY_LIMIT) {
ps.remove(ps.size() - 1);
ds.remove(ds.size() - 1);
cs.remove(cs.size() - 1);
cds.remove(cds.size() - 1);
}
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
StringBuilder cb = new StringBuilder();
for (int i = 0; i < cs.size(); i++) {
if (i > 0) {
cb.append(",");
}
cb.append(Integer.toString(cs.get(i)));
}
StringBuilder cdb = new StringBuilder();
if (cds != null) {
for (int i = 0; i < cds.size(); i++) {
if (i > 0) {
cdb.append(",");
}
cdb.append(Long.toString(cds.get(i)));
}
}
return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString())
.putString(creationDatesKey, cdb.toString())
.commit();
}
@Override
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.remove(index);
ds.remove(index);
cds.remove(index);
if (cs.size() > index) {
cs.remove(index);
}
return savePoints(ps, ds, cs, cds);
}
@Override
public boolean savePoints(List<LatLon> ps, List<String> ds) {
return false;
}
@Override
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
return false;
}
@Override
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
return false;
}
}
private class MapMarkersStorage extends MapPointsStorage {
protected String colorsKey;
protected String selectionKey;
protected String creationDatesKey;
public MapMarkersStorage() {
pointsKey = MAP_MARKERS_POINT;
descriptionsKey = MAP_MARKERS_DESCRIPTION;
colorsKey = MAP_MARKERS_COLOR;
selectionKey = MAP_MARKERS_SELECTION;
creationDatesKey = MAP_MARKERS_CREATION_DATE;
}
public List<Integer> getColors(int sz) {
List<Integer> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, colorsKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String colorStr = tok.nextToken();
list.add(Integer.parseInt(colorStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
int i = 0;
while (list.size() < sz) {
list.add(i % MapMarkersHelper.MAP_MARKERS_COLORS_COUNT);
i++;
}
return list;
}
public List<Boolean> getSelections(int sz) {
List<Boolean> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, selectionKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String indexStr = tok.nextToken();
list.add(Boolean.parseBoolean(indexStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(false);
}
return list;
}
public List<Long> getCreationDates(int sz) {
List<Long> list = new ArrayList<>();
String ip = settingsAPI.getString(globalPreferences, creationDatesKey, "");
if (ip.trim().length() > 0) {
StringTokenizer tok = new StringTokenizer(ip, ",");
while (tok.hasMoreTokens()) {
String creationDateStr = tok.nextToken();
list.add(Long.parseLong(creationDateStr));
}
}
while (list.size() > sz) {
list.remove(list.size() - 1);
}
while (list.size() < sz) {
list.add(0L);
}
return list;
}
@Override
public boolean deletePoint(int index) {
List<LatLon> ps = getPoints();
List<String> ds = getPointDescriptions(ps.size());
List<Integer> cs = getColors(ps.size());
List<Boolean> bs = getSelections(ps.size());
List<Long> cds = getCreationDates(ps.size());
ps.remove(index);
ds.remove(index);
cds.remove(index);
if (cs.size() > index) {
cs.remove(index);
}
if (bs.size() > index) {
bs.remove(index);
}
return savePoints(ps, ds, cs, bs, cds);
}
public boolean savePoints(List<LatLon> ps, List<String> ds, List<Integer> cs,
List<Boolean> bs, List<Long> cds) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < ps.size(); i++) {
if (i > 0) {
sb.append(",");
}
sb.append(((float) ps.get(i).getLatitude() + "")).append(",").append(((float) ps.get(i).getLongitude() + ""));
}
StringBuilder tb = new StringBuilder();
for (int i = 0; i < ds.size(); i++) {
if (i > 0) {
tb.append("--");
}
if (ds.get(i) == null) {
tb.append("");
} else {
tb.append(ds.get(i));
}
}
StringBuilder cb = new StringBuilder();
for (int i = 0; i < cs.size(); i++) {
if (i > 0) {
cb.append(",");
}
cb.append(Integer.toString(cs.get(i)));
}
StringBuilder bb = new StringBuilder();
if (bs != null) {
for (int i = 0; i < bs.size(); i++) {
if (i > 0) {
bb.append(",");
}
bb.append(Boolean.toString(bs.get(i)));
}
}
StringBuilder cdb = new StringBuilder();
if (cds != null) {
for (int i = 0; i < cds.size(); i++) {
if (i > 0) {
cdb.append(",");
}
cdb.append(Long.toString(cds.get(i)));
}
}
return settingsAPI.edit(globalPreferences)
.putString(pointsKey, sb.toString())
.putString(descriptionsKey, tb.toString())
.putString(colorsKey, cb.toString())
.putString(selectionKey, bb.toString())
.putString(creationDatesKey, cdb.toString())
.commit();
}
@Override
public boolean insertPoint(double latitude, double longitude, PointDescription historyDescription, int index) {
return false;
}
@Override
public boolean updatePoint(double latitude, double longitude, PointDescription historyDescription) {
return false;
}
@Override
public boolean savePoints(List<LatLon> ps, List<String> ds) {
return false;
}
}
private class ImpassableRoadsStorage extends MapPointsStorage {
public ImpassableRoadsStorage() {
pointsKey = IMPASSABLE_ROAD_POINTS;
@ -2381,32 +2074,6 @@ public class OsmandSettings {
return intermediatePointsStorage.savePoints(ps, ds);
}
public List<String> getMapMarkersPointDescriptions(int sz) {
return mapMarkersStorage.getPointDescriptions(sz);
}
public List<Integer> getMapMarkersColors(int sz) {
return mapMarkersStorage.getColors(sz);
}
public List<LatLon> getMapMarkersPoints() {
return mapMarkersStorage.getPoints();
}
public List<String> getMapMarkersHistoryPointDescriptions(int sz) {
return mapMarkersHistoryStorage.getPointDescriptions(sz);
}
public List<LatLon> getMapMarkersHistoryPoints() {
return mapMarkersHistoryStorage.getPoints();
}
public List<Integer> getMapMarkersHistoryColors(int sz) {
return mapMarkersHistoryStorage.getColors(sz);
}
public boolean clearPointToNavigate() {
return settingsAPI.edit(globalPreferences).remove(POINT_NAVIGATE_LAT).remove(POINT_NAVIGATE_LON).
remove(POINT_NAVIGATE_DESCRIPTION).commit();

View file

@ -7,7 +7,6 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
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;
@ -135,7 +134,6 @@ public class MapMarkersDbHelper {
private void onCreate(SQLiteConnection db) {
db.execSQL(MARKERS_TABLE_CREATE);
db.execSQL(GROUPS_TABLE_CREATE);
saveExistingMarkersToDb();
}
private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
@ -167,37 +165,6 @@ public class MapMarkersDbHelper {
}
}
private void saveExistingMarkersToDb() {
OsmandSettings settings = context.getSettings();
List<LatLon> ips = settings.getMapMarkersPoints();
List<String> desc = settings.getMapMarkersPointDescriptions(ips.size());
List<Integer> colors = settings.getMapMarkersColors(ips.size());
int colorIndex = 0;
for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)),
colorIndex, false, i);
marker.history = false;
addMarker(marker, true);
}
ips = settings.getMapMarkersHistoryPoints();
desc = settings.getMapMarkersHistoryPointDescriptions(ips.size());
colors = settings.getMapMarkersHistoryColors(ips.size());
for (int i = 0; i < ips.size(); i++) {
if (colors.size() > i) {
colorIndex = colors.get(i);
}
MapMarker marker = new MapMarker(ips.get(i), PointDescription.deserializeFromString(desc.get(i), ips.get(i)),
colorIndex, false, i);
marker.history = true;
addMarker(marker, true);
}
}
public void addGroup(MapMarkersGroup group) {
SQLiteConnection db = openConnection(false);
if (db != null) {