Add some code
This commit is contained in:
parent
f84b94d8da
commit
2a6e03f7d7
1 changed files with 13 additions and 10 deletions
|
@ -9,6 +9,7 @@ import net.osmand.plus.OsmandApplication;
|
||||||
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 java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR;
|
import static net.osmand.plus.MapMarkersHelper.MapMarker.DisplayPlace.TOPBAR;
|
||||||
|
@ -72,8 +73,8 @@ public class MapMarkersDbHelper {
|
||||||
GROUPS_COL_ADDED + " long);";
|
GROUPS_COL_ADDED + " long);";
|
||||||
|
|
||||||
private OsmandApplication context;
|
private OsmandApplication context;
|
||||||
private List<MapMarker> mapMarkers;
|
private List<MapMarker> mapMarkers = new LinkedList<>();
|
||||||
private List<MapMarker> mapMarkersHistory;
|
private List<MapMarker> mapMarkersHistory = new LinkedList<>();
|
||||||
|
|
||||||
public MapMarkersDbHelper(OsmandApplication context) {
|
public MapMarkersDbHelper(OsmandApplication context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
|
@ -112,7 +113,7 @@ public class MapMarkersDbHelper {
|
||||||
SQLiteConnection db = openConnection(false);
|
SQLiteConnection db = openConnection(false);
|
||||||
if (db != null) {
|
if (db != null) {
|
||||||
try {
|
try {
|
||||||
insert(db, marker);
|
insertLast(db, marker);
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
}
|
}
|
||||||
|
@ -121,21 +122,23 @@ public class MapMarkersDbHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int insert(SQLiteConnection db, MapMarker marker) {
|
private void insertLast(SQLiteConnection db, MapMarker marker) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
marker.id = currentTime;
|
||||||
double lat = marker.getLatitude();
|
double lat = marker.getLatitude();
|
||||||
double lon = marker.getLongitude();
|
double lon = marker.getLongitude();
|
||||||
String descr = marker.getName(context);
|
String descr = marker.getName(context); //fixme
|
||||||
int active = marker.history ? 0 : 1;
|
int active = marker.history ? 0 : 1;
|
||||||
long added = System.currentTimeMillis();
|
|
||||||
long visited = 0;
|
long visited = 0;
|
||||||
int groupKey = 0;
|
int groupKey = 0;
|
||||||
int colorIndex = marker.colorIndex;
|
int colorIndex = marker.colorIndex;
|
||||||
int displayPlace = marker.displayPlace == WIDGET ? 0 : 1;
|
int displayPlace = marker.displayPlace == WIDGET ? 0 : 1;
|
||||||
long next = marker.nextKey;
|
|
||||||
|
|
||||||
db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?",
|
db.execSQL("UPDATE " + MARKERS_TABLE_NAME + " SET " + MARKERS_COL_NEXT_KEY + " = ? " +
|
||||||
new Object[]{lat, lon, descr, active, added, visited, groupKey, colorIndex, displayPlace, next == -1 ? null : next});
|
"WHERE " + MARKERS_COL_NEXT_KEY + " = ?", new Object[]{marker.id, null});
|
||||||
return -1;
|
|
||||||
|
db.execSQL("INSERT INTO " + MARKERS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
new Object[]{marker.id, lat, lon, descr, active, currentTime, visited, groupKey, colorIndex, displayPlace, null});
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<MapMarker> getMapMarkers() {
|
public List<MapMarker> getMapMarkers() {
|
||||||
|
|
Loading…
Reference in a new issue