Add some code

This commit is contained in:
Alexander Sytnyk 2017-09-05 15:10:53 +03:00
parent 0a7e6d0db5
commit 2501657467
3 changed files with 65 additions and 20 deletions

View file

@ -818,8 +818,10 @@ public class OsmandAidlApi {
if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) { if (m.getOnlyName().equals(markerPrev.getName()) && latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
PointDescription pd = new PointDescription( PointDescription pd = new PointDescription(
PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : ""); PointDescription.POINT_TYPE_MAP_MARKER, markerNew.getName() != null ? markerNew.getName() : "");
MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, MapMarker marker = new MapMarker(m.point, pd, m.colorIndex, m.selected, m.index);
m.creationDate, m.visitedDate, m.displayPlace, m.index); marker.creationDate = m.creationDate;
marker.visitedDate = m.visitedDate;
marker.displayPlace = m.displayPlace;
markersHelper.moveMapMarker(marker, latLonNew); markersHelper.moveMapMarker(marker, latLonNew);
refreshMap(); refreshMap();
return true; return true;

View file

@ -6,7 +6,6 @@ import android.support.annotation.Nullable;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,13 +47,11 @@ public class MapMarkersHelper {
} }
public MapMarker(LatLon point, PointDescription name, int colorIndex, public MapMarker(LatLon point, PointDescription name, int colorIndex,
boolean selected, long creationDate, long visitedDate, boolean selected, int index) {
DisplayPlace displayPlace, int index) {
this.point = point; this.point = point;
this.pointDescription = name; this.pointDescription = name;
this.colorIndex = colorIndex; this.colorIndex = colorIndex;
this.selected = selected; this.selected = selected;
this.creationDate = creationDate;
this.index = index; this.index = index;
} }
@ -190,7 +187,8 @@ public class MapMarkersHelper {
} }
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex, PointDescription.deserializeFromString(desc.get(i), ips.get(i)), colorIndex,
selections.get(i), creationDates.get(i), 0, DisplayPlace.WIDGET, i); selections.get(i), i);
mapMarker.creationDate = creationDates.get(i);
mapMarkers.add(mapMarker); mapMarkers.add(mapMarker);
} }
@ -204,8 +202,9 @@ public class MapMarkersHelper {
} }
MapMarker mapMarker = new MapMarker(ips.get(i), MapMarker mapMarker = new MapMarker(ips.get(i),
PointDescription.deserializeFromString(desc.get(i), ips.get(i)), PointDescription.deserializeFromString(desc.get(i), ips.get(i)),
colorIndex, false, creationDates.get(i), 0, DisplayPlace.WIDGET, i); colorIndex, false, i);
mapMarker.history = true; mapMarker.history = true;
mapMarker.creationDate = creationDates.get(i);
mapMarkersHistory.add(mapMarker); mapMarkersHistory.add(mapMarker);
} }

View file

@ -7,6 +7,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
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;
@ -74,9 +75,10 @@ public class MapMarkersDbHelper {
GROUPS_COL_TYPE + " TEXT, " + GROUPS_COL_TYPE + " TEXT, " +
GROUPS_COL_ADDED + " long);"; GROUPS_COL_ADDED + " long);";
private static final long TAIL_NEXT_VALUE = -1; private static final int TAIL_NEXT_VALUE = 0;
private static final int HISTORY_NEXT_VALUE = -1;
private OsmandApplication context; private final OsmandApplication context;
public MapMarkersDbHelper(OsmandApplication context) { public MapMarkersDbHelper(OsmandApplication context) {
this.context = context; this.context = context;
@ -104,14 +106,47 @@ public class MapMarkersDbHelper {
private void onCreate(SQLiteConnection db) { private void onCreate(SQLiteConnection db) {
db.execSQL(MARKERS_TABLE_CREATE); db.execSQL(MARKERS_TABLE_CREATE);
db.execSQL(GROUPS_TABLE_CREATE); db.execSQL(GROUPS_TABLE_CREATE);
//todo: load all existing markers saveExistingMarkersToDb();
} }
private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
} }
public boolean addMapMarker(MapMarker marker) { 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;
marker.displayPlace = WIDGET; //fixme
addMapMarker(marker);
}
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;
marker.displayPlace = WIDGET; //fixme
addMapMarker(marker);
}
}
public void addMapMarker(MapMarker marker) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
@ -119,14 +154,13 @@ public class MapMarkersDbHelper {
} finally { } finally {
db.close(); db.close();
} }
return true;
} }
return false;
} }
private void insertLast(SQLiteConnection db, MapMarker marker) { private void insertLast(SQLiteConnection db, MapMarker marker) {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100)); marker.id = Long.parseLong(String.valueOf(currentTime) + String.valueOf(new Random().nextInt(900) + 100));
marker.creationDate = currentTime;
double lat = marker.getLatitude(); double lat = marker.getLatitude();
double lon = marker.getLongitude(); double lon = marker.getLongitude();
String descr = marker.getName(context); //fixme String descr = marker.getName(context); //fixme
@ -136,11 +170,14 @@ public class MapMarkersDbHelper {
int colorIndex = marker.colorIndex; int colorIndex = marker.colorIndex;
int displayPlace = marker.displayPlace == WIDGET ? 0 : 1; int displayPlace = marker.displayPlace == WIDGET ? 0 : 1;
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + if (!marker.history) {
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE}); db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " +
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, TAIL_NEXT_VALUE});
}
db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, TAIL_NEXT_VALUE}); new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace,
marker.history ? HISTORY_NEXT_VALUE : TAIL_NEXT_VALUE});
} }
public List<MapMarker> getMapMarkers() { public List<MapMarker> getMapMarkers() {
@ -181,7 +218,10 @@ public class MapMarkersDbHelper {
LatLon latLon = new LatLon(lat, lon); LatLon latLon = new LatLon(lat, lon);
MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon), MapMarker marker = new MapMarker(latLon, PointDescription.deserializeFromString(desc, latLon),
colorIndex, false, added, visited, displayPlace == 0 ? WIDGET : TOPBAR, 0); colorIndex, false, 0);
marker.creationDate = added;
marker.visitedDate = visited;
marker.displayPlace = displayPlace == 0 ? WIDGET : TOPBAR;
marker.history = !active; marker.history = !active;
marker.nextKey = nextKey; marker.nextKey = nextKey;
marker.id = id; marker.id = id;
@ -239,11 +279,15 @@ public class MapMarkersDbHelper {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
marker.visitedDate = System.currentTimeMillis();
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " +
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id}); "WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.nextKey, marker.id});
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_ACTIVE + " = ? " + db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " +
"WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.id}); MARKERS_COL_ACTIVE + " = ? " +
MARKERS_COL_VISITED + " = ? " +
"WHERE " + MARKERS_COL_ID + " = ?", new Object[]{0, marker.visitedDate, marker.id});
} finally { } finally {
db.close(); db.close();
} }