Merge pull request #6263 from osmandapp/MarkersImprovements
Markers improvements
This commit is contained in:
commit
3d7df19a7b
9 changed files with 92 additions and 33 deletions
|
@ -16,7 +16,7 @@ import java.util.List;
|
|||
public class GPXDatabase {
|
||||
|
||||
private static final String DB_NAME = "gpx_database";
|
||||
private static final int DB_VERSION = 7;
|
||||
private static final int DB_VERSION = 8;
|
||||
private static final String GPX_TABLE_NAME = "gpxTable";
|
||||
private static final String GPX_COL_NAME = "fileName";
|
||||
private static final String GPX_COL_DIR = "fileDir";
|
||||
|
@ -50,6 +50,8 @@ public class GPXDatabase {
|
|||
|
||||
private static final String GPX_COL_WPT_CATEGORY_NAMES = "wptCategoryNames";
|
||||
|
||||
private static final String GPX_COL_SHOW_AS_MARKERS = "showAsMarkers";
|
||||
|
||||
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
|
||||
public static final int GPX_SPLIT_TYPE_DISTANCE = 1;
|
||||
public static final int GPX_SPLIT_TYPE_TIME = 2;
|
||||
|
@ -81,7 +83,8 @@ public class GPXDatabase {
|
|||
GPX_COL_SPLIT_TYPE + " int, " +
|
||||
GPX_COL_SPLIT_INTERVAL + " double, " +
|
||||
GPX_COL_API_IMPORTED + " int, " + // 1 = true, 0 = false
|
||||
GPX_COL_WPT_CATEGORY_NAMES + " TEXT);";
|
||||
GPX_COL_WPT_CATEGORY_NAMES + " TEXT, " +
|
||||
GPX_COL_SHOW_AS_MARKERS + " int);"; // 1 = true, 0 = false
|
||||
|
||||
private static final String GPX_TABLE_SELECT = "SELECT " +
|
||||
GPX_COL_NAME + ", " +
|
||||
|
@ -107,7 +110,8 @@ public class GPXDatabase {
|
|||
GPX_COL_SPLIT_TYPE + ", " +
|
||||
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||
GPX_COL_API_IMPORTED + ", " +
|
||||
GPX_COL_WPT_CATEGORY_NAMES +
|
||||
GPX_COL_WPT_CATEGORY_NAMES + ", " +
|
||||
GPX_COL_SHOW_AS_MARKERS +
|
||||
" FROM " + GPX_TABLE_NAME;
|
||||
|
||||
private OsmandApplication context;
|
||||
|
@ -120,6 +124,7 @@ public class GPXDatabase {
|
|||
private int splitType;
|
||||
private double splitInterval;
|
||||
private boolean apiImported;
|
||||
private boolean showAsMarkers;
|
||||
|
||||
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
|
||||
this.file = file;
|
||||
|
@ -162,6 +167,14 @@ public class GPXDatabase {
|
|||
public void setApiImported(boolean apiImported) {
|
||||
this.apiImported = apiImported;
|
||||
}
|
||||
|
||||
public boolean isShowAsMarkers() {
|
||||
return showAsMarkers;
|
||||
}
|
||||
|
||||
public void setShowAsMarkers(boolean showAsMarkers) {
|
||||
this.showAsMarkers = showAsMarkers;
|
||||
}
|
||||
}
|
||||
|
||||
public GPXDatabase(OsmandApplication app) {
|
||||
|
@ -252,6 +265,13 @@ public class GPXDatabase {
|
|||
if (oldVersion < 7) {
|
||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WPT_CATEGORY_NAMES + " TEXT");
|
||||
}
|
||||
|
||||
if (oldVersion < 8) {
|
||||
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_AS_MARKERS + " int");
|
||||
db.execSQL("UPDATE " + GPX_TABLE_NAME +
|
||||
" SET " + GPX_COL_SHOW_AS_MARKERS + " = ? " +
|
||||
"WHERE " + GPX_COL_SHOW_AS_MARKERS + " IS NULL", new Object[]{0});
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateLastModifiedTime(GpxDataItem item) {
|
||||
|
@ -314,6 +334,25 @@ public class GPXDatabase {
|
|||
return false;
|
||||
}
|
||||
|
||||
public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
String fileName = getFileName(item.file);
|
||||
String fileDir = getFileDir(item.file);
|
||||
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
|
||||
GPX_COL_SHOW_AS_MARKERS + " = ? " +
|
||||
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
|
||||
new Object[]{showAsMarkers ? 1 : 0, fileName, fileDir});
|
||||
item.setShowAsMarkers(showAsMarkers);
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null){
|
||||
|
@ -390,11 +429,11 @@ public class GPXDatabase {
|
|||
}
|
||||
if (a != null) {
|
||||
db.execSQL(
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{ fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
|
||||
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
|
||||
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
|
||||
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
|
||||
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0,
|
||||
Algorithms.encodeStringSet(item.analysis.wptCategoryNames)});
|
||||
} else {
|
||||
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
|
||||
|
@ -404,9 +443,10 @@ public class GPXDatabase {
|
|||
GPX_COL_FILE_LAST_MODIFIED_TIME + ", " +
|
||||
GPX_COL_SPLIT_TYPE + ", " +
|
||||
GPX_COL_SPLIT_INTERVAL + ", " +
|
||||
GPX_COL_API_IMPORTED +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0});
|
||||
GPX_COL_API_IMPORTED + ", " +
|
||||
GPX_COL_SHOW_AS_MARKERS +
|
||||
") VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
new Object[]{fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -474,6 +514,7 @@ public class GPXDatabase {
|
|||
double splitInterval = query.getDouble(21);
|
||||
boolean apiImported = query.getInt(22) == 1;
|
||||
String wptCategoryNames = query.getString(23);
|
||||
boolean showAsMarkers = query.getInt(24) == 1;
|
||||
|
||||
GPXTrackAnalysis a = new GPXTrackAnalysis();
|
||||
a.totalDistance = totalDistance;
|
||||
|
@ -513,6 +554,7 @@ public class GPXDatabase {
|
|||
item.splitType = splitType;
|
||||
item.splitInterval = splitInterval;
|
||||
item.apiImported = apiImported;
|
||||
item.showAsMarkers = showAsMarkers;
|
||||
return item;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.Matrix;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
|
@ -411,7 +412,7 @@ public class GpxSelectionHelper {
|
|||
public void setGpxFileToDisplay(GPXFile... gpxs) {
|
||||
// special case for gpx current route
|
||||
for (GPXFile gpx : gpxs) {
|
||||
selectGpxFileImpl(gpx, true, false, true, true);
|
||||
selectGpxFile(gpx, true, false);
|
||||
}
|
||||
saveCurrentSelections();
|
||||
}
|
||||
|
@ -438,7 +439,7 @@ public class GpxSelectionHelper {
|
|||
if (gpx.warning != null) {
|
||||
save = true;
|
||||
} else {
|
||||
selectGpxFile(gpx, true, false, true, selectedByUser);
|
||||
selectGpxFile(gpx, true, false, true, selectedByUser, false);
|
||||
}
|
||||
} else if (obj.has(CURRENT_TRACK)) {
|
||||
SelectedGpxFile file = savingTrackHelper.getCurrentTrack();
|
||||
|
@ -516,7 +517,7 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
|
||||
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog) {
|
||||
return selectGpxFile(gpx, show, notShowNavigationDialog, true, true);
|
||||
return selectGpxFile(gpx, show, notShowNavigationDialog, true, true, true);
|
||||
}
|
||||
|
||||
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser) {
|
||||
|
@ -525,6 +526,16 @@ public class GpxSelectionHelper {
|
|||
return sf;
|
||||
}
|
||||
|
||||
public SelectedGpxFile selectGpxFile(GPXFile gpx, boolean show, boolean notShowNavigationDialog, boolean syncGroup, boolean selectedByUser, boolean canAddToMarkers) {
|
||||
if (canAddToMarkers && show) {
|
||||
GPXDatabase.GpxDataItem dataItem = app.getGpxDatabase().getItem(new File(gpx.path));
|
||||
if (dataItem != null && dataItem.isShowAsMarkers()) {
|
||||
app.getMapMarkersHelper().addOrEnableGroup(gpx);
|
||||
}
|
||||
}
|
||||
return selectGpxFile(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser);
|
||||
}
|
||||
|
||||
public void clearPoints(GPXFile gpxFile) {
|
||||
gpxFile.clearPoints();
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
|
|
|
@ -10,7 +10,6 @@ import android.support.v4.content.ContextCompat;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.core.jni.MapMarker;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
|
@ -320,6 +319,7 @@ public class MapMarkersHelper {
|
|||
|
||||
|
||||
public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
|
||||
updateGpxShowAsMarkers(file);
|
||||
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), MapMarkersGroup.GPX_TYPE);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(file);
|
||||
|
@ -330,6 +330,7 @@ public class MapMarkersHelper {
|
|||
}
|
||||
|
||||
public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) {
|
||||
updateGpxShowAsMarkers(new File(file.path));
|
||||
MapMarkersGroup gr = getMarkersGroup(file);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(new File(file.path));
|
||||
|
@ -350,9 +351,6 @@ public class MapMarkersHelper {
|
|||
return gr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void enableGroup(@NonNull MapMarkersGroup gr) {
|
||||
// check if group doesn't exist internally
|
||||
if(!mapMarkersGroups.contains(gr)) {
|
||||
|
@ -363,13 +361,20 @@ public class MapMarkersHelper {
|
|||
}
|
||||
runSynchronization(gr);
|
||||
}
|
||||
|
||||
|
||||
private void addGroupInternally(MapMarkersGroup gr) {
|
||||
markersDbHelper.addGroup(gr);
|
||||
addHistoryMarkersToGroup(gr);
|
||||
addToGroupsList(gr);
|
||||
}
|
||||
|
||||
|
||||
private void updateGpxShowAsMarkers(File file) {
|
||||
GPXDatabase.GpxDataItem dataItem = ctx.getGpxDatabase().getItem(file);
|
||||
if (dataItem != null) {
|
||||
ctx.getGpxDatabase().updateShowAsMarkers(dataItem, true);
|
||||
dataItem.setShowAsMarkers(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void addHistoryMarkersToGroup(@NonNull MapMarkersGroup group) {
|
||||
List<MapMarker> historyMarkers = new ArrayList<>(mapMarkersHistory);
|
||||
|
@ -640,7 +645,7 @@ public class MapMarkersHelper {
|
|||
Iterator<MapMarker> iterator = groupMarkers.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
MapMarker marker = iterator.next();
|
||||
if (marker.id.equals(group.getId() + name)) {
|
||||
if (marker.id.equals(group.getId() + name + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15))) {
|
||||
exists = true;
|
||||
marker.favouritePoint = favouritePoint;
|
||||
marker.wptPt = wptPt;
|
||||
|
@ -907,7 +912,7 @@ public class MapMarkersHelper {
|
|||
|
||||
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
|
||||
if (group != null) {
|
||||
marker.id = group.getId() + marker.getName(ctx);
|
||||
marker.id = group.getId() + marker.getName(ctx) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15);
|
||||
// TODO ???????
|
||||
if (markersDbHelper.getMarker(marker.id) != null) {
|
||||
continue;
|
||||
|
|
|
@ -73,7 +73,7 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
File gpx = dataItem.getFile();
|
||||
if (selectionHelper.getSelectedFileByPath(gpx.getAbsolutePath()) == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
|
||||
selectionHelper.selectGpxFile(res, true, false, false, false);
|
||||
selectionHelper.selectGpxFile(res, true, false, false, false, false);
|
||||
}
|
||||
app.getMapMarkersHelper().addOrEnableGpxGroup(gpx);
|
||||
}
|
||||
|
|
|
@ -1510,7 +1510,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if (!gpxSelected) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpx, true, false, true, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -136,7 +136,7 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
|
|||
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path);
|
||||
if (selectedGpxFile == null) {
|
||||
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false);
|
||||
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false);
|
||||
}
|
||||
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
|
||||
if (group == null) {
|
||||
|
|
|
@ -11,22 +11,23 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.GroupHeader;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment;
|
||||
|
@ -563,7 +564,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
if (!visible && selectedGpxFile != null && selectedGpxFile.selectedByUser) {
|
||||
return;
|
||||
}
|
||||
gpxHelper.selectGpxFile(gpxFile, visible, false, false, false);
|
||||
gpxHelper.selectGpxFile(gpxFile, visible, false, false, false, false);
|
||||
}
|
||||
|
||||
public void hideSnackbar() {
|
||||
|
|
|
@ -22,7 +22,6 @@ import android.view.View;
|
|||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
|
@ -321,10 +320,10 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
|
|||
}
|
||||
|
||||
vis.setChecked(gpxFileSelected);
|
||||
vis.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
vis.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (!isChecked) {
|
||||
public void onClick(View v) {
|
||||
if (!vis.isChecked()) {
|
||||
selectedSplitInterval = 0;
|
||||
}
|
||||
setTrackVisibilityOnMap(vis.isChecked());
|
||||
|
@ -335,6 +334,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
|
|||
TrackActivity trackActivity = getTrackActivity();
|
||||
if (trackActivity != null) {
|
||||
trackActivity.updateHeader(fragment);
|
||||
trackActivity.invalidateOptionsMenu();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -53,12 +53,12 @@ import net.osmand.plus.GPXUtilities.WptPt;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
|
@ -514,7 +514,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
if (markersGr != null) {
|
||||
activity.invalidateOptionsMenu();
|
||||
if (gpxFile != null) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false, true, true, false);
|
||||
}
|
||||
if (fragmentAdapter != null) {
|
||||
fragmentAdapter.hideTransparentOverlay();
|
||||
|
|
Loading…
Reference in a new issue