Small refactoring
This commit is contained in:
parent
db0eee7290
commit
a09a699ad1
15 changed files with 176 additions and 141 deletions
|
@ -4,12 +4,12 @@ import android.content.Context;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -111,17 +111,23 @@ public class FavouritesDbHelper {
|
|||
|
||||
private void runSyncWithMarkers(FavoriteGroup favGroup) {
|
||||
MapMarkersHelper helper = context.getMapMarkersHelper();
|
||||
helper.runSynchronization(helper.getOrCreateGroup(favGroup));
|
||||
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
|
||||
if(group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromMarkers(FavoriteGroup favGroup) {
|
||||
MapMarkersHelper helper = context.getMapMarkersHelper();
|
||||
helper.removeMarkersGroup(helper.getOrCreateGroup(favGroup));
|
||||
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
|
||||
if(group != null) {
|
||||
helper.removeMarkersGroup(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void addToMarkers(FavoriteGroup favGroup) {
|
||||
MapMarkersHelper helper = context.getMapMarkersHelper();
|
||||
helper.addOrEnableGroup(helper.getOrCreateGroup(favGroup));
|
||||
helper.addOrEnableGroup(favGroup);
|
||||
}
|
||||
|
||||
private File getInternalFile() {
|
||||
|
|
|
@ -5,7 +5,6 @@ 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;
|
||||
|
@ -15,6 +14,7 @@ import net.osmand.plus.GPXUtilities.Route;
|
|||
import net.osmand.plus.GPXUtilities.Track;
|
||||
import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandSettings.MetricsConstants;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
|
@ -499,7 +499,7 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
}
|
||||
if (syncGroup) {
|
||||
syncGpx(gpx);
|
||||
syncGpxWithMarkers(gpx);
|
||||
}
|
||||
return sf;
|
||||
}
|
||||
|
@ -516,30 +516,31 @@ public class GpxSelectionHelper {
|
|||
|
||||
public void clearPoints(GPXFile gpxFile) {
|
||||
gpxFile.clearPoints();
|
||||
syncGpx(gpxFile);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
}
|
||||
|
||||
public void addPoint(WptPt point, GPXFile gpxFile) {
|
||||
gpxFile.addPoint(point);
|
||||
syncGpx(gpxFile);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
}
|
||||
|
||||
public void addPoints(Collection<? extends WptPt> collection, GPXFile gpxFile) {
|
||||
gpxFile.addPoints(collection);
|
||||
syncGpx(gpxFile);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
}
|
||||
|
||||
public boolean removePoint(WptPt point, GPXFile gpxFile) {
|
||||
boolean res = gpxFile.deleteWptPt(point);
|
||||
syncGpx(gpxFile);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
return res;
|
||||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
private void syncGpxWithMarkers(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
||||
mapMarkersHelper.runSynchronization(mapMarkersHelper.getOrCreateGroup(gpx));
|
||||
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
mapMarkersHelper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -285,42 +285,77 @@ public class MapMarkersHelper {
|
|||
});
|
||||
}
|
||||
|
||||
public boolean isGroupSynced(String id) {
|
||||
return getMapMarkerGroupById(id) != null;
|
||||
}
|
||||
|
||||
public void runSynchronization(@NonNull MapMarkersGroup group) {
|
||||
runSynchronization(group, false);
|
||||
}
|
||||
|
||||
public void runSynchronization(@NonNull final MapMarkersGroup group, final boolean loadGpx) {
|
||||
public void runSynchronization(final @NonNull MapMarkersGroup group) {
|
||||
ctx.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new SyncGroupTask(group, loadGpx).executeOnExecutor(executorService);
|
||||
new SyncGroupTask(group).executeOnExecutor(executorService);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public MapMarkersGroup getMarkersGroup(SelectedGpxFile gpxFile) {
|
||||
if(gpxFile.getGpxFile() == null) {
|
||||
|
||||
public MapMarkersGroup getMarkersGroup(GPXFile gpx) {
|
||||
if(gpx == null || gpx.path == null) {
|
||||
return null;
|
||||
}
|
||||
return getMapMarkerGroupById(getMarkerGroupId(new File(gpxFile.getGpxFile().path)));
|
||||
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), MapMarkersGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) {
|
||||
return getMapMarkerGroupById(getMarkerGroupId(favGroup), MapMarkersGroup.FAVORITES_TYPE);
|
||||
}
|
||||
|
||||
|
||||
public void addOrEnableGroup(@NonNull MapMarkersGroup group) {
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
markersDbHelper.addGroup(group);
|
||||
addHistoryMarkersToGroup(group);
|
||||
addToGroupsList(group);
|
||||
} else if (group.isDisabled()) {
|
||||
updateGroupDisabled(group, false);
|
||||
public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
|
||||
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), MapMarkersGroup.GPX_TYPE);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(file);
|
||||
addGroupInternally(gr);
|
||||
}
|
||||
runSynchronization(group, true);
|
||||
enableGroup(gr);
|
||||
return gr;
|
||||
}
|
||||
|
||||
public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) {
|
||||
MapMarkersGroup gr = getMarkersGroup(file);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(new File(file.path));
|
||||
addGroupInternally(gr);
|
||||
}
|
||||
enableGroup(gr);
|
||||
return gr;
|
||||
}
|
||||
|
||||
|
||||
public MapMarkersGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
|
||||
MapMarkersGroup gr = getMarkersGroup(group);
|
||||
if (gr == null) {
|
||||
gr = createFavMarkerGroup(group);
|
||||
addGroupInternally(gr);
|
||||
}
|
||||
enableGroup(gr);
|
||||
return gr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void enableGroup(@NonNull MapMarkersGroup gr) {
|
||||
if (gr.isDisabled()) {
|
||||
updateGroupDisabled(gr, false);
|
||||
}
|
||||
runSynchronization(gr);
|
||||
}
|
||||
|
||||
private void addGroupInternally(MapMarkersGroup gr) {
|
||||
markersDbHelper.addGroup(gr);
|
||||
addHistoryMarkersToGroup(gr);
|
||||
addToGroupsList(gr);
|
||||
}
|
||||
|
||||
|
||||
private void addHistoryMarkersToGroup(@NonNull MapMarkersGroup group) {
|
||||
List<MapMarker> historyMarkers = new ArrayList<>(mapMarkersHistory);
|
||||
for (MapMarker m : historyMarkers) {
|
||||
|
@ -350,7 +385,7 @@ public class MapMarkersHelper {
|
|||
String id = group.getId();
|
||||
if (id != null) {
|
||||
group.wptCategories = wptCategories;
|
||||
if (wptCategories != null && isGroupSynced(id)) {
|
||||
if (wptCategories != null) {
|
||||
markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString());
|
||||
}
|
||||
}
|
||||
|
@ -401,7 +436,7 @@ public class MapMarkersHelper {
|
|||
|
||||
private void addMarkerToGroup(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey);
|
||||
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (mapMarkersGroup != null) {
|
||||
mapMarkersGroup.getMarkers().add(marker);
|
||||
updateGroup(mapMarkersGroup);
|
||||
|
@ -434,7 +469,7 @@ public class MapMarkersHelper {
|
|||
|
||||
private void removeMarkerFromGroup(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey);
|
||||
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (mapMarkersGroup != null) {
|
||||
mapMarkersGroup.getMarkers().remove(marker);
|
||||
updateGroup(mapMarkersGroup);
|
||||
|
@ -456,45 +491,44 @@ public class MapMarkersHelper {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public MapMarkersGroup getMapMarkerGroupById(String id) {
|
||||
public MapMarkersGroup getMapMarkerGroupById(String id, int type) {
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
if ((id == null && group.getId() == null)
|
||||
|| (group.getId() != null && group.getId().equals(id))) {
|
||||
if(type == MapMarkersGroup.ANY_TYPE || type == group.type) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public MapMarkersGroup getOrCreateGroup(@NonNull FavoriteGroup favGroup) {
|
||||
MapMarkersGroup group = getMapMarkerGroupById(favGroup.name);
|
||||
if (group == null) {
|
||||
group = new MapMarkersGroup(favGroup.name, favGroup.name, MapMarkersGroup.FAVORITES_TYPE);
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
public MapMarkersGroup getOrCreateGroup(@NonNull File gpx) {
|
||||
MapMarkersGroup group = getMapMarkerGroupById(getMarkerGroupId(gpx));
|
||||
if (group == null) {
|
||||
group = new MapMarkersGroup(getMarkerGroupId(gpx),
|
||||
AndroidUtils.trimExtension(gpx.getName()),
|
||||
private MapMarkersGroup createGPXMarkerGroup(File fl) {
|
||||
return new MapMarkersGroup(getMarkerGroupId(fl),
|
||||
AndroidUtils.trimExtension(fl.getName()),
|
||||
MapMarkersGroup.GPX_TYPE);
|
||||
}
|
||||
return group;
|
||||
|
||||
private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) {
|
||||
return new MapMarkersGroup(favGroup.name, favGroup.name, MapMarkersGroup.FAVORITES_TYPE);
|
||||
}
|
||||
|
||||
private String getMarkerGroupId(File gpx) {
|
||||
return gpx.getAbsolutePath();
|
||||
}
|
||||
|
||||
private String getMarkerGroupId(FavoriteGroup group) {
|
||||
return group.name;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
|
||||
List<MapMarkersGroup> res = new ArrayList<>();
|
||||
List<SelectedGpxFile> selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
for (SelectedGpxFile selected : selectedGpxFiles) {
|
||||
MapMarkersGroup group = getOrCreateGroup(new File(selected.getGpxFile().path));
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
MapMarkersGroup search = getMarkersGroup(selected.getGpxFile());
|
||||
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
|
||||
MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
|
||||
group.disabled = true;
|
||||
createHeaderInGroup(group);
|
||||
res.add(group);
|
||||
|
@ -512,9 +546,10 @@ public class MapMarkersHelper {
|
|||
for (TravelArticle art : savedArticles) {
|
||||
String gpxName = travelDbHelper.getGPXName(art);
|
||||
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
|
||||
LOG.debug("Article group " + getMarkerGroupId(path) + " " + path.exists()) ;
|
||||
MapMarkersGroup group = getOrCreateGroup(path);
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
LOG.debug("Article group " + path.getAbsolutePath() + " " + path.exists()) ;
|
||||
MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), MapMarkersGroup.GPX_TYPE);
|
||||
if (search == null) {
|
||||
MapMarkersGroup group = createGPXMarkerGroup(path);
|
||||
group.disabled = true;
|
||||
createHeaderInGroup(group);
|
||||
res.add(group);
|
||||
|
@ -971,7 +1006,7 @@ public class MapMarkersHelper {
|
|||
file.addPoint(wpt);
|
||||
}
|
||||
GPXUtilities.writeGpxFile(fout, file, ctx);
|
||||
return getMarkerGroupId(fout);
|
||||
return fout.getAbsolutePath();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
@ -1070,11 +1105,9 @@ public class MapMarkersHelper {
|
|||
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private MapMarkersGroup group;
|
||||
private boolean loadGpx;
|
||||
|
||||
SyncGroupTask(MapMarkersGroup group, boolean loadGpx) {
|
||||
SyncGroupTask(MapMarkersGroup group) {
|
||||
this.group = group;
|
||||
this.loadGpx = loadGpx;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1099,12 +1132,7 @@ public class MapMarkersHelper {
|
|||
|
||||
// TODO extract method from Asynctask to Helper directly
|
||||
private void runGroupSynchronization() {
|
||||
if (!isGroupSynced(group.getId())) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
|
||||
|
||||
if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) {
|
||||
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
|
||||
if (favGroup == null) {
|
||||
|
@ -1131,10 +1159,6 @@ public class MapMarkersHelper {
|
|||
String gpxPath = group.getId();
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
|
||||
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
||||
if (gpx == null && loadGpx) {
|
||||
gpx = GPXUtilities.loadGPXFile(ctx, new File(gpxPath));
|
||||
gpxHelper.selectGpxFile(gpx, true, false, false);
|
||||
}
|
||||
group.visible = gpx != null || group.visibleUntilRestart;
|
||||
if (gpx == null || group.isDisabled()) {
|
||||
removeGroupActiveMarkers(group, true);
|
||||
|
@ -1171,6 +1195,7 @@ public class MapMarkersHelper {
|
|||
|
||||
public static class MapMarkersGroup {
|
||||
|
||||
public static final int ANY_TYPE = -1;
|
||||
public static final int FAVORITES_TYPE = 0;
|
||||
public static final int GPX_TYPE = 1;
|
||||
|
||||
|
@ -1203,6 +1228,10 @@ public class MapMarkersHelper {
|
|||
return id;
|
||||
}
|
||||
|
||||
public String getGpxPath() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
@ -1318,6 +1347,12 @@ public class MapMarkersHelper {
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return favouritePoint == null ?
|
||||
(wptPt == null ? MapMarkersGroup.ANY_TYPE : MapMarkersGroup.GPX_TYPE) :
|
||||
MapMarkersGroup.FAVORITES_TYPE;
|
||||
}
|
||||
|
||||
public PointDescription getPointDescription(Context ctx) {
|
||||
return new PointDescription(POINT_TYPE_MAP_MARKER, ctx.getString(R.string.map_marker), getOnlyName());
|
||||
}
|
||||
|
@ -1405,4 +1440,7 @@ public class MapMarkersHelper {
|
|||
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -158,8 +158,9 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
items.add(new DividerHalfItem(getContext()));
|
||||
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(this.group);
|
||||
final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
|
||||
final FavoriteGroup favGroup = this.group;
|
||||
final MapMarkersGroup markersGr = markersHelper.getMarkersGroup(this.group);
|
||||
final boolean synced = markersGr != null;
|
||||
|
||||
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_flag_dark))
|
||||
|
@ -171,7 +172,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
if (synced) {
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
} else {
|
||||
markersHelper.addOrEnableGroup(markersGr);
|
||||
markersHelper.addOrEnableGroup(favGroup);
|
||||
}
|
||||
dismiss();
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
|
|
|
@ -421,15 +421,14 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
List<PointDescription> names = new ArrayList<>();
|
||||
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
|
||||
FavoriteGroup favGr = helper.getGroup(entry.getKey());
|
||||
MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(favGr);
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
markersHelper.addOrEnableGroup(markersGr);
|
||||
markersHelper.addOrEnableGroup(favGr);
|
||||
} else {
|
||||
for (FavouritePoint fp : entry.getValue()) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names, markersGr);
|
||||
markersHelper.addMapMarkers(points, names, null);
|
||||
points.clear();
|
||||
names.clear();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.os.Bundle;
|
|||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
|
@ -17,6 +16,7 @@ import net.osmand.plus.GPXUtilities.GPXFile;
|
|||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -177,10 +177,10 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
|
||||
helper.runSynchronization(helper.getOrCreateGroup(gpx));
|
||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
|
|||
if (!group.visible) {
|
||||
favouritesDbHelper.editFavouriteGroup(group, group.name, group.color, true);
|
||||
}
|
||||
addAndSyncGroup(getMyApplication().getMapMarkersHelper().getOrCreateGroup(group));
|
||||
getMyApplication().getMapMarkersHelper().addOrEnableGroup(group);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,10 +57,6 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
return false;
|
||||
}
|
||||
|
||||
protected void addAndSyncGroup(MapMarkersGroup group) {
|
||||
getMyApplication().getMapMarkersHelper().addOrEnableGroup(group);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
protected abstract GroupsAdapter createAdapter();
|
||||
|
||||
|
|
|
@ -69,21 +69,13 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
fragment.setUsedOnMap(false);
|
||||
fragment.show(getParentFragment().getChildFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
|
||||
dismiss();
|
||||
} else {
|
||||
addAndSyncGroup(createMapMarkersSyncGroup(getMyApplication(), dataItem));
|
||||
} else if(dataItem.getFile() != null) {
|
||||
getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(dataItem.getFile());
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private MapMarkersGroup createMapMarkersSyncGroup(OsmandApplication app, GpxDataItem gpxDataItem) {
|
||||
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
|
||||
File gpx = gpxDataItem.getFile();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
|
||||
if (selectedGpxFile == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(app, gpx);
|
||||
gpxSelectionHelper.selectGpxFile(res, true, false);
|
||||
}
|
||||
return getMyApplication().getMapMarkersHelper().getOrCreateGroup(gpx);
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
public class ProcessGpxTask extends AsyncTask<Void, GpxDataItem, Void> {
|
||||
|
|
|
@ -121,11 +121,11 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
|
|||
if (selectedGpxFile == null) {
|
||||
gpxSelectionHelper.selectGpxFile(gpxFile, true, false);
|
||||
}
|
||||
|
||||
MapMarkersGroup markersGr = mapMarkersHelper.getOrCreateGroup(new File(gpxFile.path));
|
||||
mapMarkersHelper.updateGroupWptCategories(markersGr, selectedCategories);
|
||||
|
||||
mapMarkersHelper.addOrEnableGroup(markersGr);
|
||||
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
|
||||
if(group == null) {
|
||||
group = mapMarkersHelper.addOrEnableGroup(gpxFile);
|
||||
}
|
||||
mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
|
||||
|
||||
dismiss();
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
|
@ -239,7 +239,8 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
|||
final int pos = holder.getAdapterPosition();
|
||||
final MapMarker marker = getItem(pos);
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
||||
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey);
|
||||
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey,
|
||||
MapMarkersGroup.ANY_TYPE);
|
||||
if (group != null) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.LatLon;
|
||||
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.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.GroupHeader;
|
||||
|
@ -26,6 +26,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
@ -174,7 +175,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
|
||||
public int getGroupHeaderPosition(String groupId) {
|
||||
int pos = -1;
|
||||
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId);
|
||||
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId, MapMarkersGroup.ANY_TYPE);
|
||||
if (group != null) {
|
||||
pos = items.indexOf(group.getGroupHeader());
|
||||
}
|
||||
|
@ -398,30 +399,27 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
final MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
||||
final GPXFile[] gpxFile = new GPXFile[1];
|
||||
boolean disabled = !enabled;
|
||||
boolean synced = false;
|
||||
|
||||
mapMarkersHelper.updateGroupDisabled(group, disabled);
|
||||
if (group.getType() == MapMarkersGroup.GPX_TYPE) {
|
||||
group.setVisibleUntilRestart(disabled);
|
||||
String gpxPath = group.getId();
|
||||
if (disabled) {
|
||||
String gpxPath = group.getGpxPath();
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
|
||||
if (selectedGpxFile != null) {
|
||||
gpxFile[0] = selectedGpxFile.getGpxFile();
|
||||
if (disabled) {
|
||||
if (selectedGpxFile != null) {
|
||||
switchGpxVisibility(gpxFile[0], false);
|
||||
}
|
||||
} else if (mapMarkersHelper.isGroupSynced(group.getId())) {
|
||||
mapMarkersHelper.runSynchronization(group, true);
|
||||
synced = true;
|
||||
}
|
||||
}
|
||||
if (!synced) {
|
||||
if (mapMarkersHelper.isGroupSynced(group.getId())) {
|
||||
mapMarkersHelper.runSynchronization(group);
|
||||
} else {
|
||||
mapMarkersHelper.addOrEnableGroup(group);
|
||||
if (selectedGpxFile == null) {
|
||||
// TODO IO load in another thread ?
|
||||
gpxFile[0] = GPXUtilities.loadGPXFile(app, new File(gpxPath));
|
||||
}
|
||||
switchGpxVisibility(gpxFile[0], true);
|
||||
}
|
||||
}
|
||||
mapMarkersHelper.runSynchronization(group);
|
||||
|
||||
|
||||
if (disabled) {
|
||||
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG)
|
||||
|
@ -431,7 +429,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
if (group.getType() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
|
||||
switchGpxVisibility(gpxFile[0], true);
|
||||
}
|
||||
mapMarkersHelper.addOrEnableGroup(group);
|
||||
mapMarkersHelper.enableGroup(group);
|
||||
}
|
||||
});
|
||||
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
|
||||
|
|
|
@ -455,8 +455,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
R.drawable.ic_action_gshare_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
|
||||
if (getGpx().path != null) {
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(new File(getGpx().path));
|
||||
final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
|
||||
final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null;
|
||||
createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers
|
||||
: R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag_dark,
|
||||
R.drawable.ic_action_flag_dark, MenuItemCompat.SHOW_AS_ACTION_NEVER);
|
||||
|
@ -594,22 +593,25 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
MapMarkersHelper helper = app.getMapMarkersHelper();
|
||||
helper.runSynchronization(helper.getOrCreateGroup(gpx));
|
||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void addOrRemoveMapMarkersSyncGroup() {
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final MapMarkersGroup markersGr = markersHelper.getOrCreateGroup(getGpxDataItem().getFile());
|
||||
final boolean synced = markersHelper.isGroupSynced(markersGr.getId());
|
||||
if (synced) {
|
||||
|
||||
MapMarkersGroup markersSearch = markersHelper.getMarkersGroup(getGpx());
|
||||
final MapMarkersGroup markersGr;
|
||||
if (markersSearch != null) {
|
||||
markersGr = markersSearch;
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
} else {
|
||||
markersHelper.addOrEnableGroup(markersGr);
|
||||
markersGr = markersHelper.addOrEnableGroup(getGpx());
|
||||
}
|
||||
final boolean synced = markersGr != null;
|
||||
getActionBarActivity().invalidateOptionsMenu();
|
||||
GPXFile gpxFile = getTrackActivity().getGpx();
|
||||
if (gpxFile != null) {
|
||||
|
@ -624,7 +626,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (synced) {
|
||||
markersHelper.addOrEnableGroup(markersGr);
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
getActionBarActivity().invalidateOptionsMenu();
|
||||
} else {
|
||||
Bundle args = new Bundle();
|
||||
|
|
|
@ -143,7 +143,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
|||
}
|
||||
for (FavouritePoint o : fullObjects) {
|
||||
if (o != contextMenuLayer.getMoveableObject()) {
|
||||
MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
|
||||
MapMarker mapMarker = mapMarkersHelper.getMapMarker(o);
|
||||
drawPoint(canvas, tileBox, latLonBounds, o, mapMarker);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ import android.support.annotation.ColorInt;
|
|||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.QuadRect;
|
||||
|
@ -35,6 +34,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings.CommonPreference;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -532,7 +532,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
}
|
||||
|
||||
private boolean isSyncedWithMarkers(SelectedGpxFile g) {
|
||||
return mapMarkersHelper.getMarkersGroup(g) != null;
|
||||
return mapMarkersHelper.getMarkersGroup(g.getGpxFile()) != null;
|
||||
}
|
||||
|
||||
private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) {
|
||||
|
@ -662,9 +662,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
mapMarkersHelper.runSynchronization(view.getApplication().getMapMarkersHelper().getOrCreateGroup(gpx));
|
||||
MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
mapMarkersHelper.runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue