Sync itinerary groups initial commit

This commit is contained in:
Vitaliy 2021-04-15 05:43:43 +03:00
parent 9d9dd32503
commit 7ce5ac4aae
31 changed files with 571 additions and 428 deletions

View file

@ -685,7 +685,7 @@ public class AppInitializer implements IProgress {
// restore backuped favorites to normal file // restore backuped favorites to normal file
restoreBackupForFavoritesFiles(); restoreBackupForFavoritesFiles();
notifyEvent(InitEvents.RESTORE_BACKUPS); notifyEvent(InitEvents.RESTORE_BACKUPS);
app.itineraryHelper.syncAllGroupsAsync(); app.itineraryHelper.syncAllGroups();
app.searchUICore.initSearchUICore(); app.searchUICore.initSearchUICore();
checkLiveUpdatesAlerts(); checkLiveUpdatesAlerts();

View file

@ -16,10 +16,10 @@ import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
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 net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@ -271,16 +271,13 @@ public class FavouritesDbHelper {
return changed; return changed;
} }
private void runSyncWithMarkers(FavoriteGroup favGroup) { private void syncGroupWithItinerary(FavoriteGroup favGroup) {
ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup); context.getItineraryHelper().runSynchronizationAsync(favGroup);
if (group != null) {
context.getItineraryHelper().runSynchronization(group);
}
} }
private boolean removeFromMarkers(FavoriteGroup favGroup) { private boolean removeFromMarkers(FavoriteGroup favGroup) {
MapMarkersHelper helper = context.getMapMarkersHelper(); ItineraryHelper helper = context.getItineraryHelper();
ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup); MapMarkersGroup group = helper.getMarkersGroup(favGroup);
if (group != null) { if (group != null) {
helper.removeMarkersGroup(group); helper.removeMarkersGroup(group);
return true; return true;
@ -308,7 +305,7 @@ public class FavouritesDbHelper {
cachedFavoritePoints.remove(p); cachedFavoritePoints.remove(p);
} }
for (FavoriteGroup gr : groupsToSync) { for (FavoriteGroup gr : groupsToSync) {
runSyncWithMarkers(gr); syncGroupWithItinerary(gr);
} }
} }
if (groupsToDelete != null) { if (groupsToDelete != null) {
@ -331,7 +328,7 @@ public class FavouritesDbHelper {
FavoriteGroup group = flatGroups.get(p.getCategory()); FavoriteGroup group = flatGroups.get(p.getCategory());
if (group != null) { if (group != null) {
group.points.remove(p); group.points.remove(p);
runSyncWithMarkers(group); syncGroupWithItinerary(group);
} }
cachedFavoritePoints.remove(p); cachedFavoritePoints.remove(p);
} }
@ -387,7 +384,7 @@ public class FavouritesDbHelper {
sortAll(); sortAll();
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
} }
runSyncWithMarkers(group); syncGroupWithItinerary(group);
return true; return true;
} }
@ -528,14 +525,14 @@ public class FavouritesDbHelper {
} }
sortAll(); sortAll();
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0)); syncGroupWithItinerary(getOrCreateGroup(p, 0));
return true; return true;
} }
private void editAddressDescription(@NonNull FavouritePoint p, @Nullable String address) { private void editAddressDescription(@NonNull FavouritePoint p, @Nullable String address) {
p.setAddress(address); p.setAddress(address);
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0)); syncGroupWithItinerary(getOrCreateGroup(p, 0));
} }
public boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon) { public boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon) {
@ -551,7 +548,7 @@ public class FavouritesDbHelper {
p.setDescription(description); p.setDescription(description);
} }
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
runSyncWithMarkers(getOrCreateGroup(p, 0)); syncGroupWithItinerary(getOrCreateGroup(p, 0));
return true; return true;
} }
@ -570,7 +567,7 @@ public class FavouritesDbHelper {
} }
} }
private void backup(File backupFile, File externalFile) { public static void backup(File backupFile, File externalFile) {
try { try {
File f = new File(backupFile.getParentFile(), backupFile.getName()); File f = new File(backupFile.getParentFile(), backupFile.getName());
BZip2CompressorOutputStream out = new BZip2CompressorOutputStream(new FileOutputStream(f)); BZip2CompressorOutputStream out = new BZip2CompressorOutputStream(new FileOutputStream(f));
@ -625,7 +622,11 @@ public class FavouritesDbHelper {
} }
public File getBackupFile() { public File getBackupFile() {
File fld = new File(context.getAppPath(null), BACKUP_FOLDER); return getBackupFile(context, "favourites_bak_");
}
public static File getBackupFile(OsmandApplication app, String fileName) {
File fld = new File(app.getAppPath(null), BACKUP_FOLDER);
if (!fld.exists()) { if (!fld.exists()) {
fld.mkdirs(); fld.mkdirs();
} }
@ -638,7 +639,7 @@ public class FavouritesDbHelper {
if (back < 10) { if (back < 10) {
backPrefix = "0" + backPrefix; backPrefix = "0" + backPrefix;
} }
File bak = new File(fld, "favourites_bak_" + backPrefix + ".gpx.bz2"); File bak = new File(fld, fileName + backPrefix + ".gpx.bz2");
if (!bak.exists()) { if (!bak.exists()) {
return bak; return bak;
} else if (bak.lastModified() < firstModifiedMin) { } else if (bak.lastModified() < firstModifiedMin) {
@ -851,7 +852,7 @@ public class FavouritesDbHelper {
} }
} }
group.color = color; group.color = color;
runSyncWithMarkers(gr); syncGroupWithItinerary(gr);
} }
if (group.visible != visible) { if (group.visible != visible) {
FavoriteGroup gr = flatGroups.get(group.name); FavoriteGroup gr = flatGroups.get(group.name);
@ -859,7 +860,7 @@ public class FavouritesDbHelper {
for (FavouritePoint p : gr.points) { for (FavouritePoint p : gr.points) {
p.setVisible(visible); p.setVisible(visible);
} }
runSyncWithMarkers(gr); syncGroupWithItinerary(gr);
} }
if (!group.name.equals(newName)) { if (!group.name.equals(newName)) {
FavoriteGroup gr = flatGroups.remove(group.name); FavoriteGroup gr = flatGroups.remove(group.name);
@ -886,13 +887,6 @@ public class FavouritesDbHelper {
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
} }
protected void createDefaultCategories() {
addEmptyCategory(context.getString(R.string.favorite_home_category));
addEmptyCategory(context.getString(R.string.favorite_friends_category));
addEmptyCategory(context.getString(R.string.favorite_places_category));
addEmptyCategory(context.getString(R.string.shared_string_others));
}
private FavoriteGroup getOrCreateGroup(FavouritePoint p, int defColor) { private FavoriteGroup getOrCreateGroup(FavouritePoint p, int defColor) {
if (flatGroups.containsKey(p.getCategory())) { if (flatGroups.containsKey(p.getCategory())) {
return flatGroups.get(p.getCategory()); return flatGroups.get(p.getCategory());

View file

@ -30,7 +30,6 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder; import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.track.GpxSplitType; import net.osmand.plus.track.GpxSplitType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -582,7 +581,7 @@ public class GpxSelectionHelper {
} else if (obj.has(BACKUP)) { } else if (obj.has(BACKUP)) {
selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime); selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime);
} else { } else {
SelectedGpxFile file = selectGpxFile(gpx, true, false, true, selectedByUser, false, false); SelectedGpxFile file = selectGpxFile(gpx, true, false, false, selectedByUser, false, false);
if (obj.has(HIDDEN_GROUPS)) { if (obj.has(HIDDEN_GROUPS)) {
readHiddenGroups(file, obj.getString(HIDDEN_GROUPS)); readHiddenGroups(file, obj.getString(HIDDEN_GROUPS));
} }
@ -686,12 +685,12 @@ public class GpxSelectionHelper {
} }
private SelectedGpxFile selectGpxFileImpl(GPXFile gpx, private SelectedGpxFile selectGpxFileImpl(GPXFile gpx,
GpxDataItem dataItem, GpxDataItem dataItem,
boolean show, boolean show,
boolean notShowNavigationDialog, boolean notShowNavigationDialog,
boolean syncGroup, boolean syncGroup,
boolean selectedByUser, boolean selectedByUser,
boolean addToHistory) { boolean addToHistory) {
boolean displayed; boolean displayed;
SelectedGpxFile sf; SelectedGpxFile sf;
if (gpx != null && gpx.showCurrentTrack) { if (gpx != null && gpx.showCurrentTrack) {
@ -726,7 +725,7 @@ public class GpxSelectionHelper {
} }
} }
if (syncGroup) { if (syncGroup) {
syncGpxWithMarkers(gpx); syncGpxWithItinerary(gpx);
} }
if (sf != null) { if (sf != null) {
sf.splitProcessed = false; sf.splitProcessed = false;
@ -766,33 +765,33 @@ public class GpxSelectionHelper {
} }
public SelectedGpxFile selectGpxFile(GPXFile gpx, public SelectedGpxFile selectGpxFile(GPXFile gpx,
GpxDataItem dataItem, GpxDataItem dataItem,
boolean show, boolean show,
boolean notShowNavigationDialog, boolean notShowNavigationDialog,
boolean syncGroup, boolean syncGroup,
boolean selectedByUser, boolean selectedByUser,
boolean addToHistory) { boolean addToHistory) {
SelectedGpxFile sf = selectGpxFileImpl(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory); SelectedGpxFile sf = selectGpxFileImpl(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory);
saveCurrentSelections(); saveCurrentSelections();
return sf; return sf;
} }
public SelectedGpxFile selectGpxFile(GPXFile gpx, public SelectedGpxFile selectGpxFile(GPXFile gpx,
boolean show, boolean show,
boolean notShowNavigationDialog, boolean notShowNavigationDialog,
boolean syncGroup, boolean syncGroup,
boolean selectedByUser, boolean selectedByUser,
boolean canAddToMarkers) { boolean canAddToMarkers) {
return selectGpxFile(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser, canAddToMarkers, true); return selectGpxFile(gpx, show, notShowNavigationDialog, syncGroup, selectedByUser, canAddToMarkers, true);
} }
public SelectedGpxFile selectGpxFile(GPXFile gpx, public SelectedGpxFile selectGpxFile(GPXFile gpx,
boolean show, boolean show,
boolean notShowNavigationDialog, boolean notShowNavigationDialog,
boolean syncGroup, boolean syncGroup,
boolean selectedByUser, boolean selectedByUser,
boolean canAddToMarkers, boolean canAddToMarkers,
boolean addToHistory) { boolean addToHistory) {
GpxDataItem dataItem = app.getGpxDbHelper().getItem(new File(gpx.path)); GpxDataItem dataItem = app.getGpxDbHelper().getItem(new File(gpx.path));
if (canAddToMarkers && show && dataItem != null && dataItem.isShowAsMarkers()) { if (canAddToMarkers && show && dataItem != null && dataItem.isShowAsMarkers()) {
app.getItineraryHelper().addOrEnableGroup(gpx); app.getItineraryHelper().addOrEnableGroup(gpx);
@ -802,30 +801,27 @@ public class GpxSelectionHelper {
public void clearPoints(GPXFile gpxFile) { public void clearPoints(GPXFile gpxFile) {
gpxFile.clearPoints(); gpxFile.clearPoints();
syncGpxWithMarkers(gpxFile); syncGpxWithItinerary(gpxFile);
} }
public void addPoint(WptPt point, GPXFile gpxFile) { public void addPoint(WptPt point, GPXFile gpxFile) {
gpxFile.addPoint(point); gpxFile.addPoint(point);
syncGpxWithMarkers(gpxFile); syncGpxWithItinerary(gpxFile);
} }
public void addPoints(Collection<? extends WptPt> collection, GPXFile gpxFile) { public void addPoints(Collection<? extends WptPt> collection, GPXFile gpxFile) {
gpxFile.addPoints(collection); gpxFile.addPoints(collection);
syncGpxWithMarkers(gpxFile); syncGpxWithItinerary(gpxFile);
} }
public boolean removePoint(WptPt point, GPXFile gpxFile) { public boolean removePoint(WptPt point, GPXFile gpxFile) {
boolean res = gpxFile.deleteWptPt(point); boolean res = gpxFile.deleteWptPt(point);
syncGpxWithMarkers(gpxFile); syncGpxWithItinerary(gpxFile);
return res; return res;
} }
private void syncGpxWithMarkers(GPXFile gpxFile) { private void syncGpxWithItinerary(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); app.getItineraryHelper().runSynchronizationAsync(gpxFile);
if (group != null) {
app.getItineraryHelper().runSynchronization(group);
}
} }
public static class SelectedGpxFile { public static class SelectedGpxFile {

View file

@ -27,8 +27,6 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
@ -40,6 +38,8 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragment { public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragment {
@ -177,9 +177,9 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
if (group.getPoints().size() > 0) { if (group.getPoints().size() > 0) {
items.add(new DividerHalfItem(getContext())); items.add(new DividerHalfItem(getContext()));
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final ItineraryHelper itineraryHelper = app.getItineraryHelper();
final FavoriteGroup favGroup = this.group; final FavoriteGroup favGroup = this.group;
final ItineraryGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group); final MapMarkersGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group);
final boolean synced = markersGr != null; final boolean synced = markersGr != null;
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder() BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
@ -190,7 +190,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (synced) { if (synced) {
markersHelper.removeMarkersGroup(markersGr); itineraryHelper.removeMarkersGroup(markersGr);
} else { } else {
app.getItineraryHelper().addOrEnableGroup(favGroup); app.getItineraryHelper().addOrEnableGroup(favGroup);
} }

View file

@ -18,7 +18,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsFragment; import net.osmand.plus.activities.PluginsFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants; import net.osmand.plus.openplacereviews.OPRConstants;
@ -219,7 +219,7 @@ public class IntentHelper {
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) { if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS); Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
if (openMapMarkersGroupsExtra != null) { if (openMapMarkersGroupsExtra != null) {
MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(ItineraryGroup.MARKERS_SYNC_GROUP_ID)); MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
} }
mapActivity.setIntent(null); mapActivity.setIntent(null);
} }

View file

@ -5,6 +5,7 @@ import android.os.AsyncTask;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -12,14 +13,19 @@ import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener; import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -43,7 +49,11 @@ import static net.osmand.plus.mapmarkers.MapMarkersHelper.BY_DATE_ADDED_DESC;
public class ItineraryHelper { public class ItineraryHelper {
private static final Log LOG = PlatformUtil.getLog(ItineraryHelper.class); private static final Log log = PlatformUtil.getLog(ItineraryHelper.class);
private static final String CATEGORIES_SPLIT = ",";
private static final String FILE_TO_SAVE = "itinerary.gpx";
private static final String FILE_TO_BACKUP = "itinerary_bak.gpx";
private OsmandApplication app; private OsmandApplication app;
@ -53,6 +63,7 @@ public class ItineraryHelper {
private ExecutorService executorService = Executors.newSingleThreadExecutor(); private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<ItineraryGroup> itineraryGroups = new ArrayList<>(); private List<ItineraryGroup> itineraryGroups = new ArrayList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>(); private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
public ItineraryHelper(@NonNull OsmandApplication app) { public ItineraryHelper(@NonNull OsmandApplication app) {
@ -62,88 +73,132 @@ public class ItineraryHelper {
loadGroups(); loadGroups();
} }
public List<ItineraryGroup> getItineraryGroups() { public static class ItineraryItem {
return itineraryGroups;
public Object object;
public ItineraryType type;
public ItineraryItem(Object object, ItineraryType type) {
this.object = object;
this.type = type;
}
} }
public void syncAllGroupsAsync() { public static class ItineraryGroup {
for (ItineraryGroup group : itineraryGroups) {
if (group.getId() != null && group.getName() != null) { public String id;
runSynchronization(group); public String name;
public ItineraryType type = ItineraryType.MARKERS;
public Set<String> wptCategories;
public boolean disabled;
private List<ItineraryItem> itineraryItems = new ArrayList<>();
}
public void syncItineraryGroups() {
for (MapMarkersGroup markersGroup : mapMarkersGroups) {
ItineraryGroup itineraryGroup = new ItineraryGroup();
itineraryGroup.id = markersGroup.getId();
itineraryGroup.name = markersGroup.getName();
itineraryGroup.type = markersGroup.getType();
itineraryGroup.wptCategories = markersGroup.getWptCategories();
itineraryGroup.disabled = markersGroup.isDisabled();
if (markersGroup.getType() == ItineraryType.FAVOURITES) {
syncFavoriteGroup(itineraryGroup, markersGroup);
} else if (markersGroup.getType() == ItineraryType.TRACK) {
syncTrackGroup(itineraryGroup, markersGroup);
} else {
syncMarkersGroup(itineraryGroup, markersGroup);
} }
} }
if (trimEmptyGroups()) {
}
} }
public void updateGroupWptCategories(@NonNull ItineraryGroup group, Set<String> wptCategories) { public boolean trimEmptyGroups() {
String id = group.getId(); boolean changed = false;
if (id != null) { Iterator<ItineraryGroup> iterator = itineraryGroups.iterator();
group.setWptCategories(wptCategories); while (iterator.hasNext()) {
if (wptCategories != null) { ItineraryGroup group = iterator.next();
markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString()); if (Algorithms.isEmpty(group.itineraryItems)) {
changed = true;
iterator.remove();
} }
} }
return changed;
} }
public void enableGroup(@NonNull ItineraryGroup gr) { private void syncFavoriteGroup(ItineraryGroup itineraryGroup, MapMarkersGroup markersGroup) {
// check if group doesn't exist internally FavoriteGroup favoriteGroup = app.getFavorites().getGroup(markersGroup.getId());
if (!itineraryGroups.contains(gr)) { if (favoriteGroup != null) {
addGroupInternally(gr); for (FavouritePoint favouritePoint : favoriteGroup.getPoints()) {
} ItineraryItem itineraryItem = new ItineraryItem(favouritePoint, ItineraryType.FAVOURITES);
if (gr.isDisabled()) { itineraryGroup.itineraryItems.add(itineraryItem);
updateGroupDisabled(gr, false); }
} itineraryGroups.add(itineraryGroup);
runSynchronization(gr);
}
public void updateGroups() {
for (ItineraryGroup group : itineraryGroups) {
markersHelper.updateGroup(group);
} }
} }
public void updateGroupDisabled(@NonNull ItineraryGroup group, boolean disabled) { private void syncTrackGroup(ItineraryGroup itineraryGroup, MapMarkersGroup markersGroup) {
String id = group.getId(); File file = new File(markersGroup.getId());
if (id != null) { if (file.exists()) {
markersDbHelper.updateGroupDisabled(id, disabled); GPXFile gpxFile;
group.setDisabled(disabled); SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(markersGroup.getId());
} if (selectedGpxFile != null) {
} gpxFile = selectedGpxFile.getGpxFile();
} else {
public List<MapMarker> getMapMarkersFromDefaultGroups(boolean history) { gpxFile = GPXUtilities.loadGPXFile(file);
List<MapMarker> mapMarkers = new ArrayList<>(); }
for (ItineraryGroup group : itineraryGroups) { if (gpxFile != null && gpxFile.error == null) {
if (group.getType() == ItineraryGroup.ANY_TYPE) { for (WptPt wptPt : gpxFile.getPoints()) {
for (MapMarker marker : group.getMarkers()) { if (shouldAddWpt(wptPt, itineraryGroup.wptCategories)) {
if (history && marker.history || !history && !marker.history) { ItineraryItem itineraryItem = new ItineraryItem(wptPt, ItineraryType.TRACK);
mapMarkers.add(marker); itineraryGroup.itineraryItems.add(itineraryItem);
} }
} }
itineraryGroups.add(itineraryGroup);
} }
} }
return mapMarkers; }
private void syncMarkersGroup(ItineraryGroup itineraryGroup, MapMarkersGroup markersGroup) {
for (MapMarker marker : markersGroup.getMarkers()) {
ItineraryItem itineraryItem = new ItineraryItem(marker, ItineraryType.MARKERS);
itineraryGroup.itineraryItems.add(itineraryItem);
}
itineraryGroups.add(itineraryGroup);
}
private boolean shouldAddWpt(WptPt wptPt, Set<String> wptCategories) {
boolean addAll = wptCategories == null || wptCategories.isEmpty();
return addAll || wptCategories.contains(wptPt.category)
|| wptPt.category == null && wptCategories.contains("");
} }
private void loadGroups() { private void loadGroups() {
Map<String, ItineraryGroup> groupsMap = markersDbHelper.getAllGroupsMap(); Map<String, MapMarkersGroup> groupsMap = markersDbHelper.getAllGroupsMap();
List<MapMarker> allMarkers = new ArrayList<>(markersHelper.getMapMarkers()); List<MapMarker> allMarkers = new ArrayList<>(markersHelper.getMapMarkers());
allMarkers.addAll(markersHelper.getMapMarkersHistory()); allMarkers.addAll(markersHelper.getMapMarkersHistory());
Iterator<Entry<String, ItineraryGroup>> iterator = groupsMap.entrySet().iterator(); Iterator<Entry<String, MapMarkersGroup>> iterator = groupsMap.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
ItineraryGroup group = iterator.next().getValue(); MapMarkersGroup group = iterator.next().getValue();
if (group.getType() == ItineraryGroup.GPX_TYPE && !new File(group.getId()).exists()) { if (group.getType() == ItineraryType.TRACK && !new File(group.getId()).exists()) {
markersDbHelper.removeMarkersGroup(group.getId()); markersDbHelper.removeMarkersGroup(group.getId());
iterator.remove(); iterator.remove();
} }
} }
ItineraryGroup noGroup = null; MapMarkersGroup noGroup = null;
for (MapMarker marker : allMarkers) { for (MapMarker marker : allMarkers) {
ItineraryGroup group = groupsMap.get(marker.groupKey); MapMarkersGroup group = groupsMap.get(marker.groupKey);
if (group == null) { if (group == null) {
if (noGroup == null) { if (noGroup == null) {
noGroup = new ItineraryGroup(); noGroup = new MapMarkersGroup();
noGroup.setCreationDate(Long.MAX_VALUE); noGroup.setCreationDate(Long.MAX_VALUE);
} }
noGroup.getMarkers().add(marker); noGroup.getMarkers().add(marker);
@ -155,7 +210,7 @@ public class ItineraryHelper {
} }
} }
itineraryGroups = new ArrayList<>(groupsMap.values()); mapMarkersGroups = new ArrayList<>(groupsMap.values());
if (noGroup != null) { if (noGroup != null) {
markersHelper.sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC); markersHelper.sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
addToGroupsList(noGroup); addToGroupsList(noGroup);
@ -163,35 +218,97 @@ public class ItineraryHelper {
sortGroups(); sortGroups();
for (ItineraryGroup group : itineraryGroups) { for (MapMarkersGroup group : mapMarkersGroups) {
markersHelper.updateGroup(group); updateGroup(group);
} }
} }
public void addGroupInternally(ItineraryGroup gr) { public List<MapMarkersGroup> getMapMarkersGroups() {
return mapMarkersGroups;
}
public void syncAllGroups() {
for (MapMarkersGroup group : mapMarkersGroups) {
if (group.getId() != null && group.getName() != null) {
runGroupSynchronization(group);
}
}
syncItineraryGroups();
}
public void updateGroupWptCategories(@NonNull MapMarkersGroup group, Set<String> wptCategories) {
String id = group.getId();
if (id != null) {
group.setWptCategories(wptCategories);
if (wptCategories != null) {
markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString());
}
}
}
public void enableGroup(@NonNull MapMarkersGroup gr) {
// check if group doesn't exist internally
if (!mapMarkersGroups.contains(gr)) {
addGroupInternally(gr);
}
if (gr.isDisabled()) {
updateGroupDisabled(gr, false);
}
runSynchronizationAsync(gr);
}
public void updateGroups() {
for (MapMarkersGroup group : mapMarkersGroups) {
updateGroup(group);
}
}
public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
String id = group.getId();
if (id != null) {
markersDbHelper.updateGroupDisabled(id, disabled);
group.setDisabled(disabled);
}
}
public List<MapMarker> getMapMarkersFromDefaultGroups(boolean history) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : mapMarkersGroups) {
if (group.getType() == ItineraryType.MARKERS) {
for (MapMarker marker : group.getMarkers()) {
if (history && marker.history || !history && !marker.history) {
mapMarkers.add(marker);
}
}
}
}
return mapMarkers;
}
public void addGroupInternally(MapMarkersGroup gr) {
markersDbHelper.addGroup(gr); markersDbHelper.addGroup(gr);
markersHelper.addHistoryMarkersToGroup(gr); markersHelper.addHistoryMarkersToGroup(gr);
addToGroupsList(gr); addToGroupsList(gr);
} }
public void updateGpxShowAsMarkers(File file) { public void updateGpxShowAsMarkers(File file) {
GPXDatabase.GpxDataItem dataItem = app.getGpxDbHelper().getItem(file); GpxDataItem dataItem = app.getGpxDbHelper().getItem(file);
if (dataItem != null) { if (dataItem != null) {
app.getGpxDbHelper().updateShowAsMarkers(dataItem, true); app.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
dataItem.setShowAsMarkers(true); dataItem.setShowAsMarkers(true);
} }
} }
public void addToGroupsList(ItineraryGroup group) { public void addToGroupsList(MapMarkersGroup group) {
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups); List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.add(group); copyList.add(group);
itineraryGroups = copyList; mapMarkersGroups = copyList;
} }
public void removeFromGroupsList(ItineraryGroup group) { public void removeFromGroupsList(MapMarkersGroup group) {
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups); List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.remove(group); copyList.remove(group);
itineraryGroups = copyList; mapMarkersGroups = copyList;
} }
public void addSyncListener(OnGroupSyncedListener listener) { public void addSyncListener(OnGroupSyncedListener listener) {
@ -202,7 +319,7 @@ public class ItineraryHelper {
syncListeners.remove(listener); syncListeners.remove(listener);
} }
public void runSynchronization(final @NonNull ItineraryGroup group) { public void runSynchronizationAsync(final @NonNull MapMarkersGroup group) {
app.runInUIThread(new Runnable() { app.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -211,20 +328,88 @@ public class ItineraryHelper {
}); });
} }
public ItineraryGroup getMarkersGroup(GPXFile gpx) { public void runSynchronizationAsync(@NonNull FavoriteGroup favoriteGroup) {
MapMarkersGroup group = getMarkersGroup(favoriteGroup);
if (group != null) {
runSynchronizationAsync(group);
}
}
public void runSynchronizationAsync(@NonNull GPXFile gpxFile) {
MapMarkersGroup group = getMarkersGroup(gpxFile);
if (group != null) {
runSynchronizationAsync(group);
}
}
public void addMarkerToGroup(MapMarker marker) {
if (marker != null) {
MapMarkersGroup mapMarkersGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType());
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().add(marker);
updateGroup(mapMarkersGroup);
if (mapMarkersGroup.getName() == null) {
markersHelper.sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
}
} else {
mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, ItineraryType.MARKERS);
mapMarkersGroup.setCreationDate(Long.MAX_VALUE);
mapMarkersGroup.getMarkers().add(marker);
addToGroupsList(mapMarkersGroup);
sortGroups();
updateGroup(mapMarkersGroup);
}
}
}
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
return;
}
createHeadersInGroup(mapMarkersGroup);
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null) {
if (historyMarkersCount == 0) {
mapMarkersGroup.setShowHideHistoryButton(null);
}
} else if (historyMarkersCount > 0) {
showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.showHistory = false;
mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton);
}
}
public void createHeadersInGroup(@NonNull MapMarkersGroup group) {
ItineraryType type = group.getType();
int headerIconId = 0;
int subHeaderIconId = 0;
if (type != ItineraryType.MARKERS) {
headerIconId = type == ItineraryType.FAVOURITES
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
subHeaderIconId = R.drawable.ic_action_filter;
}
GroupHeader header = new GroupHeader(headerIconId, group);
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(subHeaderIconId, group);
group.setHeader(header);
group.setCategoriesSubHeader(categoriesSubHeader);
}
public MapMarkersGroup getMarkersGroup(GPXFile gpx) {
if (gpx == null || gpx.path == null) { if (gpx == null || gpx.path == null) {
return null; return null;
} }
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryGroup.GPX_TYPE); return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryType.TRACK);
} }
public ItineraryGroup getMarkersGroup(FavoriteGroup favGroup) { public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) {
return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryGroup.FAVORITES_TYPE); return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryType.FAVOURITES);
} }
public ItineraryGroup addOrEnableGpxGroup(@NonNull File file) { public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
updateGpxShowAsMarkers(file); updateGpxShowAsMarkers(file);
ItineraryGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryGroup.GPX_TYPE); MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryType.TRACK);
if (gr == null) { if (gr == null) {
gr = createGPXMarkerGroup(file); gr = createGPXMarkerGroup(file);
addGroupInternally(gr); addGroupInternally(gr);
@ -233,9 +418,9 @@ public class ItineraryHelper {
return gr; return gr;
} }
public ItineraryGroup addOrEnableGroup(@NonNull GPXFile file) { public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) {
updateGpxShowAsMarkers(new File(file.path)); updateGpxShowAsMarkers(new File(file.path));
ItineraryGroup gr = getMarkersGroup(file); MapMarkersGroup gr = getMarkersGroup(file);
if (gr == null) { if (gr == null) {
gr = createGPXMarkerGroup(new File(file.path)); gr = createGPXMarkerGroup(new File(file.path));
addGroupInternally(gr); addGroupInternally(gr);
@ -244,8 +429,8 @@ public class ItineraryHelper {
return gr; return gr;
} }
public ItineraryGroup addOrEnableGroup(@NonNull FavoriteGroup group) { public MapMarkersGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
ItineraryGroup gr = getMarkersGroup(group); MapMarkersGroup gr = getMarkersGroup(group);
if (gr == null) { if (gr == null) {
gr = createFavMarkerGroup(group); gr = createFavMarkerGroup(group);
addGroupInternally(gr); addGroupInternally(gr);
@ -254,14 +439,14 @@ public class ItineraryHelper {
return gr; return gr;
} }
private ItineraryGroup createGPXMarkerGroup(File fl) { private MapMarkersGroup createGPXMarkerGroup(File fl) {
return new ItineraryGroup(getMarkerGroupId(fl), return new MapMarkersGroup(getMarkerGroupId(fl),
Algorithms.getFileNameWithoutExtension(fl.getName()), Algorithms.getFileNameWithoutExtension(fl.getName()),
ItineraryGroup.GPX_TYPE); ItineraryType.TRACK);
} }
private ItineraryGroup createFavMarkerGroup(FavoriteGroup favGroup) { private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) {
return new ItineraryGroup(favGroup.getName(), favGroup.getName(), ItineraryGroup.FAVORITES_TYPE); return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), ItineraryType.FAVOURITES);
} }
private String getMarkerGroupId(File gpx) { private String getMarkerGroupId(File gpx) {
@ -272,22 +457,21 @@ public class ItineraryHelper {
return group.getName(); return group.getName();
} }
public void removeMarkerFromGroup(MapMarker marker) { public void removeMarkerFromGroup(MapMarker marker) {
if (marker != null) { if (marker != null) {
ItineraryGroup itineraryGroup = getMapMarkerGroupById(marker.groupKey, marker.getType()); MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
if (itineraryGroup != null) { if (mapMarkersGroup != null) {
itineraryGroup.getMarkers().remove(marker); mapMarkersGroup.getMarkers().remove(marker);
markersHelper.updateGroup(itineraryGroup); updateGroup(mapMarkersGroup);
} }
} }
} }
public void sortGroups() { public void sortGroups() {
if (itineraryGroups.size() > 0) { if (mapMarkersGroups.size() > 0) {
Collections.sort(itineraryGroups, new Comparator<ItineraryGroup>() { Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
@Override @Override
public int compare(ItineraryGroup group1, ItineraryGroup group2) { public int compare(MapMarkersGroup group1, MapMarkersGroup group2) {
long t1 = group1.getCreationDate(); long t1 = group1.getCreationDate();
long t2 = group2.getCreationDate(); long t2 = group2.getCreationDate();
return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1); return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1);
@ -297,11 +481,11 @@ public class ItineraryHelper {
} }
@Nullable @Nullable
public ItineraryGroup getMapMarkerGroupById(String id, int type) { public MapMarkersGroup getMapMarkerGroupById(String id, ItineraryType type) {
for (ItineraryGroup group : itineraryGroups) { for (MapMarkersGroup group : mapMarkersGroups) {
if ((id == null && group.getId() == null) if ((id == null && group.getId() == null)
|| (group.getId() != null && group.getId().equals(id))) { || (group.getId() != null && group.getId().equals(id))) {
if (type == ItineraryGroup.ANY_TYPE || type == group.getType()) { if (type == ItineraryType.MARKERS || type == group.getType()) {
return group; return group;
} }
} }
@ -310,15 +494,15 @@ public class ItineraryHelper {
} }
@NonNull @NonNull
public List<ItineraryGroup> getGroupsForDisplayedGpx() { public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
List<ItineraryGroup> res = new ArrayList<>(); List<MapMarkersGroup> res = new ArrayList<>();
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles(); List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selected : selectedGpxFiles) { for (SelectedGpxFile selected : selectedGpxFiles) {
ItineraryGroup search = getMarkersGroup(selected.getGpxFile()); MapMarkersGroup search = getMarkersGroup(selected.getGpxFile());
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) { if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
ItineraryGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path)); MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
group.setDisabled(true); group.setDisabled(true);
markersHelper.createHeadersInGroup(group); createHeadersInGroup(group);
res.add(group); res.add(group);
} }
} }
@ -326,19 +510,19 @@ public class ItineraryHelper {
} }
@NonNull @NonNull
public List<ItineraryGroup> getGroupsForSavedArticlesTravelBook() { public List<MapMarkersGroup> getGroupsForSavedArticlesTravelBook() {
List<ItineraryGroup> res = new ArrayList<>(); List<MapMarkersGroup> res = new ArrayList<>();
TravelHelper travelHelper = app.getTravelHelper(); TravelHelper travelHelper = app.getTravelHelper();
if (travelHelper.isAnyTravelBookPresent()) { if (travelHelper.isAnyTravelBookPresent()) {
List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles(); List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
for (TravelArticle art : savedArticles) { for (TravelArticle art : savedArticles) {
String gpxName = travelHelper.getGPXName(art); String gpxName = travelHelper.getGPXName(art);
File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
ItineraryGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryGroup.GPX_TYPE); MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryType.TRACK);
if (search == null) { if (search == null) {
ItineraryGroup group = createGPXMarkerGroup(path); MapMarkersGroup group = createGPXMarkerGroup(path);
group.setDisabled(true); group.setDisabled(true);
markersHelper.createHeadersInGroup(group); createHeadersInGroup(group);
res.add(group); res.add(group);
} }
} }
@ -346,11 +530,61 @@ public class ItineraryHelper {
return res; return res;
} }
public void removeMarkersGroup(MapMarkersGroup group) {
if (group != null) {
markersDbHelper.removeMarkersGroup(group.getId());
markersHelper.removeGroupActiveMarkers(group, false);
removeFromGroupsList(group);
}
}
private void runGroupSynchronization(MapMarkersGroup group) {
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
if (group.getType() == ItineraryType.FAVOURITES) {
FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
group.setVisible(favGroup.isVisible());
if (!group.isVisible() || group.isDisabled()) {
markersHelper.removeGroupActiveMarkers(group, true);
return;
}
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
for (FavouritePoint fp : points) {
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
}
} else if (group.getType() == ItineraryType.TRACK) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
File file = new File(group.getId());
if (!file.exists()) {
return;
}
String gpxPath = group.getId();
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
group.setVisible(gpx != null || group.isVisibleUntilRestart());
if (gpx == null || group.isDisabled()) {
markersHelper.removeGroupActiveMarkers(group, true);
return;
}
List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
for (WptPt pt : gpxPoints) {
if (shouldAddWpt(pt, group.getWptCategories())) {
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt);
}
}
}
markersHelper.removeOldMarkersIfPresent(groupMarkers);
}
private class SyncGroupTask extends AsyncTask<Void, Void, Void> { private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
private ItineraryGroup group; private MapMarkersGroup group;
SyncGroupTask(ItineraryGroup group) { SyncGroupTask(MapMarkersGroup group) {
this.group = group; this.group = group;
} }
@ -370,55 +604,10 @@ public class ItineraryHelper {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
runGroupSynchronization(); runGroupSynchronization(group);
return null; return null;
} }
// TODO extract method from Asynctask to Helper directly
private void runGroupSynchronization() {
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
if (group.getType() == ItineraryGroup.FAVORITES_TYPE) {
FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
group.setVisible(favGroup.isVisible());
if (!group.isVisible() || group.isDisabled()) {
markersHelper.removeGroupActiveMarkers(group, true);
return;
}
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
for (FavouritePoint fp : points) {
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
}
} else if (group.getType() == ItineraryGroup.GPX_TYPE) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
File file = new File(group.getId());
if (!file.exists()) {
return;
}
String gpxPath = group.getId();
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
group.setVisible(gpx != null || group.isVisibleUntilRestart());
if (gpx == null || group.isDisabled()) {
markersHelper.removeGroupActiveMarkers(group, true);
return;
}
boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty();
List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
for (WptPt pt : gpxPoints) {
if (addAll || group.getWptCategories().contains(pt.category)
|| (pt.category == null && group.getWptCategories().contains(""))) {
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt);
}
}
}
markersHelper.removeOldMarkersIfPresent(groupMarkers);
}
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
if (!syncListeners.isEmpty()) { if (!syncListeners.isEmpty()) {

View file

@ -0,0 +1,43 @@
package net.osmand.plus.itinerary;
import androidx.annotation.NonNull;
public enum ItineraryType {
MARKERS("markers", -1),
FAVOURITES("favourites", 0),
TRACK("track", 1);
private int typeId;
private String typeName;
ItineraryType(@NonNull String typeName, int typeId) {
this.typeName = typeName;
this.typeId = typeId;
}
public int getTypeId() {
return typeId;
}
public String getTypeName() {
return typeName;
}
public static ItineraryType findTypeForId(int typeId) {
for (ItineraryType type : values()) {
if (type.getTypeId() == typeId) {
return type;
}
}
return ItineraryType.MARKERS;
}
public static ItineraryType findTypeForName(String typeName) {
for (ItineraryType type : values()) {
if (type.getTypeName().equalsIgnoreCase(typeName)) {
return type;
}
}
return ItineraryType.MARKERS;
}
}

View file

@ -14,8 +14,6 @@ import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -25,6 +23,8 @@ import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.builders.FavouritePointMenuBuilder; import net.osmand.plus.mapcontextmenu.builders.FavouritePointMenuBuilder;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragmentNew; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragmentNew;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.transport.TransportStopRoute; import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.widgets.style.CustomTypefaceSpan; import net.osmand.plus.widgets.style.CustomTypefaceSpan;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -79,6 +79,11 @@ public class FavouritePointMenuController extends MenuController {
return fav; return fav;
} }
@Override
protected Object getCorrespondingMapObject() {
return mapMarker;
}
@Override @Override
public List<TransportStopRoute> getTransportStopRoutes() { public List<TransportStopRoute> getTransportStopRoutes() {
if (transportStopController != null) { if (transportStopController != null) {

View file

@ -27,7 +27,6 @@ public class MapMarkerMenuController extends MenuController {
public MapMarkerMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull MapMarker mapMarker) { public MapMarkerMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull MapMarker mapMarker) {
super(new MenuBuilder(mapActivity), pointDescription, mapActivity); super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
final boolean useStateList = Build.VERSION.SDK_INT >= 21;
this.mapMarker = mapMarker; this.mapMarker = mapMarker;
builder.setShowNearestWiki(true); builder.setShowNearestWiki(true);

View file

@ -84,6 +84,11 @@ public class WptPtMenuController extends MenuController {
return wpt; return wpt;
} }
@Override
protected Object getCorrespondingMapObject() {
return mapMarker;
}
/* /*
@Override @Override
public boolean handleSingleTapOnMap() { public boolean handleSingleTapOnMap() {

View file

@ -24,7 +24,6 @@ import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -219,10 +218,7 @@ public class WptPtEditorFragment extends PointEditorFragment {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app != null) { if (app != null) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); app.getItineraryHelper().runSynchronizationAsync(gpxFile);
if (group != null) {
app.getItineraryHelper().runSynchronization(group);
}
} }
} }

View file

@ -27,7 +27,6 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener;
import net.osmand.plus.track.SaveGpxAsyncTask; import net.osmand.plus.track.SaveGpxAsyncTask;
@ -237,10 +236,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app != null) { if (app != null) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); app.getItineraryHelper().runSynchronizationAsync(gpxFile);
if (group != null) {
app.getItineraryHelper().runSynchronization(group);
}
} }
} }
@ -278,7 +274,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
} }
protected void addWpt(GPXFile gpx, String description, String name, String category, int color, String iconName, protected void addWpt(GPXFile gpx, String description, String name, String category, int color, String iconName,
String backgroundType) { String backgroundType) {
WptPt wpt = getWpt(); WptPt wpt = getWpt();
if (wpt != null) { if (wpt != null) {
this.wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(), this.wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(),

View file

@ -2,15 +2,13 @@ package net.osmand.plus.mapmarkers;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import net.osmand.plus.itinerary.ItineraryGroup;
public class CategoriesSubHeader { public class CategoriesSubHeader {
@DrawableRes @DrawableRes
private int iconRes; private int iconRes;
private ItineraryGroup group; private MapMarkersGroup group;
public CategoriesSubHeader(int iconRes, ItineraryGroup group) { public CategoriesSubHeader(int iconRes, MapMarkersGroup group) {
this.iconRes = iconRes; this.iconRes = iconRes;
this.group = group; this.group = group;
} }
@ -20,7 +18,7 @@ public class CategoriesSubHeader {
return iconRes; return iconRes;
} }
public ItineraryGroup getGroup() { public MapMarkersGroup getGroup() {
return group; return group;
} }
} }

View file

@ -71,7 +71,6 @@ import net.osmand.plus.Version;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.itinerary.ItineraryHelper; import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM;
@ -171,10 +170,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
ItineraryHelper helper = getMyApplication().getItineraryHelper(); ItineraryHelper helper = getMyApplication().getItineraryHelper();
ItineraryGroup group = helper.getMarkersGroup(gpxFile); helper.runSynchronizationAsync(gpxFile);
if (group != null) {
helper.runSynchronization(group);
}
} }
protected void addWpt(GPXFile gpx, String description, String name, String category, int color, double lat, double lon) { protected void addWpt(GPXFile gpx, String description, String name, String category, int color, double lat, double lon) {

View file

@ -2,15 +2,13 @@ package net.osmand.plus.mapmarkers;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import net.osmand.plus.itinerary.ItineraryGroup;
public class GroupHeader { public class GroupHeader {
@DrawableRes @DrawableRes
private int iconRes; private int iconRes;
private ItineraryGroup group; private MapMarkersGroup group;
public GroupHeader(int iconRes, ItineraryGroup group) { public GroupHeader(int iconRes, MapMarkersGroup group) {
this.iconRes = iconRes; this.iconRes = iconRes;
this.group = group; this.group = group;
} }
@ -20,7 +18,7 @@ public class GroupHeader {
return iconRes; return iconRes;
} }
public ItineraryGroup getGroup() { public MapMarkersGroup getGroup() {
return group; return group;
} }
} }

View file

@ -11,7 +11,7 @@ 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.R; import net.osmand.plus.R;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -45,10 +45,10 @@ public class MapMarker implements LocationPoint {
this.index = index; this.index = index;
} }
public int getType() { public ItineraryType getType() {
return favouritePoint == null ? return favouritePoint == null ?
(wptPt == null ? ItineraryGroup.ANY_TYPE : ItineraryGroup.GPX_TYPE) : (wptPt == null ? ItineraryType.MARKERS : ItineraryType.TRACK) :
ItineraryGroup.FAVORITES_TYPE; ItineraryType.FAVOURITES;
} }
public PointDescription getPointDescription(Context ctx) { public PointDescription getPointDescription(Context ctx) {

View file

@ -8,7 +8,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 net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -162,27 +162,27 @@ public class MapMarkersDbHelper {
} }
} }
public void addGroup(ItineraryGroup group) { public void addGroup(MapMarkersGroup group) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)", db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)",
new Object[]{group.getId(), group.getName(), group.getType(), group.isDisabled(), group.getWptCategoriesString()}); new Object[]{group.getId(), group.getName(), group.getType().getTypeId(), group.isDisabled(), group.getWptCategoriesString()});
} finally { } finally {
db.close(); db.close();
} }
} }
} }
public Map<String, ItineraryGroup> getAllGroupsMap() { public Map<String, MapMarkersGroup> getAllGroupsMap() {
Map<String, ItineraryGroup> res = new LinkedHashMap<>(); Map<String, MapMarkersGroup> res = new LinkedHashMap<>();
SQLiteConnection db = openConnection(true); SQLiteConnection db = openConnection(true);
if (db != null) { if (db != null) {
try { try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null); SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
if (query != null && query.moveToFirst()) { if (query != null && query.moveToFirst()) {
do { do {
ItineraryGroup group = readGroup(query); MapMarkersGroup group = readGroup(query);
res.put(group.getId(), group); res.put(group.getId(), group);
} while (query.moveToNext()); } while (query.moveToNext());
} }
@ -196,14 +196,14 @@ public class MapMarkersDbHelper {
return res; return res;
} }
private ItineraryGroup readGroup(SQLiteCursor query) { private MapMarkersGroup readGroup(SQLiteCursor query) {
String id = query.getString(0); String id = query.getString(0);
String name = query.getString(1); String name = query.getString(1);
int type = query.getInt(2); int type = query.getInt(2);
boolean disabled = query.getInt(3) == 1; boolean disabled = query.getInt(3) == 1;
String categories = query.getString(4); String categories = query.getString(4);
ItineraryGroup res = new ItineraryGroup(id, name, type); MapMarkersGroup res = new MapMarkersGroup(id, name, ItineraryType.findTypeForId(type));
res.setDisabled(disabled); res.setDisabled(disabled);
res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories)); res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));

View file

@ -1,12 +1,9 @@
package net.osmand.plus.itinerary; package net.osmand.plus.mapmarkers;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import net.osmand.plus.mapmarkers.CategoriesSubHeader; import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -14,20 +11,17 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
public class ItineraryGroup { public class MapMarkersGroup {
public static final int ANY_TYPE = -1;
public static final int FAVORITES_TYPE = 0;
public static final int GPX_TYPE = 1;
public static final String MARKERS_SYNC_GROUP_ID = "markers_sync_group_id"; public static final String MARKERS_SYNC_GROUP_ID = "markers_sync_group_id";
private String id; private String id;
private String name; private String name;
private int type = ANY_TYPE; private ItineraryType type = ItineraryType.MARKERS;
private Set<String> wptCategories; private Set<String> wptCategories;
private long creationDate;
private boolean disabled; private boolean disabled;
private long creationDate;
private boolean visible = true; private boolean visible = true;
private boolean wasShown = false; private boolean wasShown = false;
private boolean visibleUntilRestart; private boolean visibleUntilRestart;
@ -38,11 +32,11 @@ public class ItineraryGroup {
private CategoriesSubHeader categoriesSubHeader; private CategoriesSubHeader categoriesSubHeader;
private ShowHideHistoryButton showHideHistoryButton; private ShowHideHistoryButton showHideHistoryButton;
public ItineraryGroup() { public MapMarkersGroup() {
} }
public ItineraryGroup(@NonNull String id, @NonNull String name, int type) { public MapMarkersGroup(@NonNull String id, @NonNull String name, @NonNull ItineraryType type) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.type = type; this.type = type;
@ -104,7 +98,7 @@ public class ItineraryGroup {
return name; return name;
} }
public int getType() { public ItineraryType getType() {
return type; return type;
} }

View file

@ -17,9 +17,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -117,7 +115,6 @@ public class MapMarkersHelper {
} }
} }
public void lookupAddressAll() { public void lookupAddressAll() {
for (MapMarker mapMarker : mapMarkers) { for (MapMarker mapMarker : mapMarkers) {
lookupAddress(mapMarker); lookupAddress(mapMarker);
@ -230,7 +227,7 @@ public class MapMarkersHelper {
}); });
} }
public void addHistoryMarkersToGroup(@NonNull ItineraryGroup group) { public void addHistoryMarkersToGroup(@NonNull MapMarkersGroup group) {
List<MapMarker> historyMarkers = new ArrayList<>(mapMarkersHistory); List<MapMarker> historyMarkers = new ArrayList<>(mapMarkersHistory);
for (MapMarker m : historyMarkers) { for (MapMarker m : historyMarkers) {
if (m.groupKey != null && group.getId() != null && m.groupKey.equals(group.getId())) { if (m.groupKey != null && group.getId() != null && m.groupKey.equals(group.getId())) {
@ -239,87 +236,29 @@ public class MapMarkersHelper {
} }
} }
public void removeMarkersGroup(ItineraryGroup group) { private void syncMarkerWithItinerary(@NonNull MapMarker marker) {
if (group != null) { app.getItineraryHelper().addMarkerToGroup(marker);
markersDbHelper.removeMarkersGroup(group.getId());
removeGroupActiveMarkers(group, false);
app.getItineraryHelper().removeFromGroupsList(group);
}
} }
public void removeGroupActiveMarkers(ItineraryGroup group, boolean updateGroup) { public void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) {
if (group != null) { if (group != null) {
markersDbHelper.removeActiveMarkersFromGroup(group.getId()); markersDbHelper.removeActiveMarkersFromGroup(group.getId());
removeFromMapMarkersList(group.getActiveMarkers()); removeFromMapMarkersList(group.getActiveMarkers());
if (updateGroup) { if (updateGroup) {
group.setMarkers(group.getHistoryMarkers()); group.setMarkers(group.getHistoryMarkers());
updateGroup(group); app.getItineraryHelper().updateGroup(group);
} }
reorderActiveMarkersIfNeeded(); reorderActiveMarkersIfNeeded();
refresh(); refresh();
} }
} }
public void updateGroup(ItineraryGroup itineraryGroup) {
if (itineraryGroup.getId() == null || itineraryGroup.getName() == null) {
return;
}
createHeadersInGroup(itineraryGroup);
int historyMarkersCount = itineraryGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = itineraryGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null) {
if (historyMarkersCount == 0) {
itineraryGroup.setShowHideHistoryButton(null);
}
} else if (historyMarkersCount > 0) {
showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.showHistory = false;
itineraryGroup.setShowHideHistoryButton(showHideHistoryButton);
}
}
private void addMarkersToGroups(@NonNull List<MapMarker> markers) { private void addMarkersToGroups(@NonNull List<MapMarker> markers) {
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
addMarkerToGroup(marker); syncMarkerWithItinerary(marker);
} }
} }
private void addMarkerToGroup(MapMarker marker) {
if (marker != null) {
ItineraryGroup itineraryGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType());
if (itineraryGroup != null) {
itineraryGroup.getMarkers().add(marker);
updateGroup(itineraryGroup);
if (itineraryGroup.getName() == null) {
sortMarkers(itineraryGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
}
} else {
itineraryGroup = new ItineraryGroup(marker.groupKey, marker.groupName, ItineraryGroup.ANY_TYPE);
itineraryGroup.setCreationDate(Long.MAX_VALUE);
itineraryGroup.getMarkers().add(marker);
app.getItineraryHelper().addToGroupsList(itineraryGroup);
app.getItineraryHelper().sortGroups();
updateGroup(itineraryGroup);
}
}
}
public void createHeadersInGroup(@NonNull ItineraryGroup group) {
int type = group.getType();
int headerIconId = 0;
int subHeaderIconId = 0;
if (type != -1) {
headerIconId = type == ItineraryGroup.FAVORITES_TYPE
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
subHeaderIconId = R.drawable.ic_action_filter;
}
GroupHeader header = new GroupHeader(headerIconId, group);
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(subHeaderIconId, group);
group.setHeader(header);
group.setCategoriesSubHeader(categoriesSubHeader);
}
@Nullable @Nullable
public MapMarker getMapMarker(WptPt wptPt) { public MapMarker getMapMarker(WptPt wptPt) {
for (MapMarker marker : getMarkers()) { for (MapMarker marker : getMarkers()) {
@ -350,6 +289,16 @@ public class MapMarkersHelper {
return null; return null;
} }
@Nullable
public MapMarker getMapMarker(@NonNull String id) {
for (MapMarker marker : getMarkers()) {
if (Algorithms.stringsEqual(marker.id, id)) {
return marker;
}
}
return null;
}
private List<MapMarker> getMarkers() { private List<MapMarker> getMarkers() {
List<MapMarker> res = new ArrayList<>(mapMarkers); List<MapMarker> res = new ArrayList<>(mapMarkers);
if (app.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) { if (app.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
@ -371,7 +320,7 @@ public class MapMarkersHelper {
return null; return null;
} }
public void addNewMarkerIfNeeded(@NonNull ItineraryGroup group, public void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group,
@NonNull List<MapMarker> groupMarkers, @NonNull List<MapMarker> groupMarkers,
@NonNull LatLon latLon, @NonNull LatLon latLon,
@NonNull String name, @NonNull String name,
@ -446,7 +395,7 @@ public class MapMarkersHelper {
addToMapMarkersList(marker); addToMapMarkersList(marker);
reorderActiveMarkersIfNeeded(); reorderActiveMarkersIfNeeded();
} }
addMarkerToGroup(marker); syncMarkerWithItinerary(marker);
refresh(); refresh();
} }
} }
@ -608,13 +557,13 @@ public class MapMarkersHelper {
public void addMapMarkers(@NonNull List<LatLon> points, public void addMapMarkers(@NonNull List<LatLon> points,
@NonNull List<PointDescription> historyNames, @NonNull List<PointDescription> historyNames,
@Nullable ItineraryGroup group) { @Nullable MapMarkersGroup group) {
addMarkers(points, historyNames, group, null, null, null); addMarkers(points, historyNames, group, null, null, null);
} }
private void addMarkers(@NonNull List<LatLon> points, private void addMarkers(@NonNull List<LatLon> points,
@NonNull List<PointDescription> historyNames, @NonNull List<PointDescription> historyNames,
@Nullable ItineraryGroup group, @Nullable MapMarkersGroup group,
@Nullable List<FavouritePoint> favouritePoints, @Nullable List<FavouritePoint> favouritePoints,
@Nullable List<WptPt> wptPts, @Nullable List<WptPt> wptPts,
@Nullable List<String> mapObjNames) { @Nullable List<String> mapObjNames) {

View file

@ -20,7 +20,6 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.itinerary.ItineraryHelper; import net.osmand.plus.itinerary.ItineraryHelper;
import java.io.File; import java.io.File;
@ -144,12 +143,12 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
if (selectedGpxFile == null) { if (selectedGpxFile == null) {
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false); gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false);
} }
ItineraryGroup group = helper.getMarkersGroup(gpxFile); MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group == null) { if (group == null) {
group = helper.addOrEnableGroup(gpxFile); group = helper.addOrEnableGroup(gpxFile);
} }
helper.updateGroupWptCategories(group, selectedCategories); helper.updateGroupWptCategories(group, selectedCategories);
helper.runSynchronization(group); helper.runSynchronizationAsync(group);
} }
private boolean isAllChecked() { private boolean isAllChecked() {

View file

@ -13,13 +13,14 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.Collections; import java.util.Collections;
@ -214,10 +215,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
final int pos = holder.getAdapterPosition(); final int pos = holder.getAdapterPosition();
final MapMarker marker = getItem(pos); final MapMarker marker = getItem(pos);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker); mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
ItineraryGroup group = mapActivity.getMyApplication().getItineraryHelper().getMapMarkerGroupById(marker.groupKey, MapMarkersGroup group = mapActivity.getMyApplication().getItineraryHelper().getMapMarkerGroupById(marker.groupKey,
ItineraryGroup.ANY_TYPE); ItineraryType.MARKERS);
if (group != null) { if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group); mapActivity.getMyApplication().getItineraryHelper().updateGroup(group);
} }
changeMarkers(); changeMarkers();
notifyDataSetChanged(); notifyDataSetChanged();

View file

@ -21,20 +21,21 @@ import net.osmand.IndexConstants;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment; import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.data.TravelHelper;
@ -106,11 +107,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
items = new ArrayList<>(); items = new ArrayList<>();
ItineraryHelper helper = app.getItineraryHelper(); ItineraryHelper helper = app.getItineraryHelper();
helper.updateGroups(); helper.updateGroups();
List<ItineraryGroup> groups = new ArrayList<>(helper.getItineraryGroups()); List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
groups.addAll(helper.getGroupsForDisplayedGpx()); groups.addAll(helper.getGroupsForDisplayedGpx());
groups.addAll(helper.getGroupsForSavedArticlesTravelBook()); groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
for (int i = 0; i < groups.size(); i++) { for (int i = 0; i < groups.size(); i++) {
ItineraryGroup group = groups.get(i); MapMarkersGroup group = groups.get(i);
if (!group.isVisible()) { if (!group.isVisible()) {
continue; continue;
} }
@ -196,7 +197,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
return null; return null;
} }
private void populateAdapterWithGroupMarkers(ItineraryGroup group, int position) { private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) {
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
if (!group.isDisabled()) { if (!group.isDisabled()) {
@ -221,7 +222,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
public int getGroupHeaderPosition(String groupId) { public int getGroupHeaderPosition(String groupId) {
int pos = -1; int pos = -1;
ItineraryGroup group = app.getItineraryHelper().getMapMarkerGroupById(groupId, ItineraryGroup.ANY_TYPE); MapMarkersGroup group = app.getItineraryHelper().getMapMarkerGroupById(groupId, ItineraryType.MARKERS);
if (group != null) { if (group != null) {
pos = items.indexOf(group.getGroupHeader()); pos = items.indexOf(group.getGroupHeader());
} }
@ -402,11 +403,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
headerViewHolder.articleDescription.setVisibility(View.GONE); headerViewHolder.articleDescription.setVisibility(View.GONE);
} else if (header instanceof GroupHeader) { } else if (header instanceof GroupHeader) {
final GroupHeader groupHeader = (GroupHeader) header; final GroupHeader groupHeader = (GroupHeader) header;
final ItineraryGroup group = groupHeader.getGroup(); final MapMarkersGroup group = groupHeader.getGroup();
String groupName = group.getName(); String groupName = group.getName();
if (groupName.isEmpty()) { if (groupName.isEmpty()) {
groupName = app.getString(R.string.shared_string_favorites); groupName = app.getString(R.string.shared_string_favorites);
} else if (group.getType() == ItineraryGroup.GPX_TYPE) { } else if (group.getType() == ItineraryType.TRACK) {
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " "); groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
} }
if (group.isDisabled()) { if (group.isDisabled()) {
@ -464,7 +465,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
} }
app.getItineraryHelper().updateGroupDisabled(group, disabled); app.getItineraryHelper().updateGroupDisabled(group, disabled);
if (group.getType() == ItineraryGroup.GPX_TYPE) { if (group.getType() == ItineraryType.TRACK) {
group.setVisibleUntilRestart(disabled); group.setVisibleUntilRestart(disabled);
String gpxPath = group.getGpxPath(); String gpxPath = group.getGpxPath();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath); SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
@ -479,7 +480,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
if(!disabled) { if(!disabled) {
app.getItineraryHelper().enableGroup(group); app.getItineraryHelper().enableGroup(group);
} else { } else {
app.getItineraryHelper().runSynchronization(group); app.getItineraryHelper().runSynchronizationAsync(group);
} }
if (disabled) { if (disabled) {
@ -487,7 +488,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
.setAction(R.string.shared_string_undo, new View.OnClickListener() { .setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
if (group.getType() == ItineraryGroup.GPX_TYPE && gpxFile[0] != null) { if (group.getType() == ItineraryType.TRACK && gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], null, true); switchGpxVisibility(gpxFile[0], null, true);
} }
app.getItineraryHelper().enableGroup(group); app.getItineraryHelper().enableGroup(group);
@ -530,7 +531,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
final Object header = getItem(position); final Object header = getItem(position);
if (header instanceof CategoriesSubHeader) { if (header instanceof CategoriesSubHeader) {
final CategoriesSubHeader categoriesSubHeader = (CategoriesSubHeader) header; final CategoriesSubHeader categoriesSubHeader = (CategoriesSubHeader) header;
final ItineraryGroup group = categoriesSubHeader.getGroup(); final MapMarkersGroup group = categoriesSubHeader.getGroup();
View.OnClickListener openChooseCategoriesDialog = new View.OnClickListener() { View.OnClickListener openChooseCategoriesDialog = new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
@ -573,7 +574,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} }
} }
private String getGroupWptCategoriesString(ItineraryGroup group) { private String getGroupWptCategoriesString(MapMarkersGroup group) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Set<String> categories = group.getWptCategories(); Set<String> categories = group.getWptCategories();
if (categories != null && !categories.isEmpty()) { if (categories != null && !categories.isEmpty()) {

View file

@ -8,7 +8,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -58,18 +57,11 @@ public class DeletePointsTask extends AsyncTask<Void, Void, Void> {
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
} }
} }
syncGpx(gpx); app.getItineraryHelper().runSynchronizationAsync(gpx);
} }
return null; return null;
} }
private void syncGpx(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
if (group != null) {
app.getItineraryHelper().runSynchronization(group);
}
}
@Override @Override
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
OnPointsDeleteListener listener = listenerRef.get(); OnPointsDeleteListener listener = listenerRef.get();

View file

@ -49,7 +49,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.measurementtool.OptionsDividerItem; import net.osmand.plus.measurementtool.OptionsDividerItem;
import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener; import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener;
@ -192,7 +192,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) { private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) {
ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories()) final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories())
|| markersGroup.getWptCategories().contains(group.getName())); || markersGroup.getWptCategories().contains(group.getName()));
@ -216,7 +216,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false); selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false);
} }
boolean groupCreated = false; boolean groupCreated = false;
ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
if (markersGroup == null) { if (markersGroup == null) {
groupCreated = true; groupCreated = true;
markersGroup = app.getItineraryHelper().addOrEnableGroup(gpxFile); markersGroup = app.getItineraryHelper().addOrEnableGroup(gpxFile);
@ -232,11 +232,11 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
selectedCategories.add(group.getName()); selectedCategories.add(group.getName());
} }
if (Algorithms.isEmpty(selectedCategories)) { if (Algorithms.isEmpty(selectedCategories)) {
mapMarkersHelper.removeMarkersGroup(markersGroup); app.getItineraryHelper().removeMarkersGroup(markersGroup);
} else { } else {
app.getItineraryHelper().updateGroupWptCategories(markersGroup, selectedCategories); app.getItineraryHelper().updateGroupWptCategories(markersGroup, selectedCategories);
if (!groupCreated) { if (!groupCreated) {
app.getItineraryHelper().runSynchronization(markersGroup); app.getItineraryHelper().runSynchronizationAsync(markersGroup);
} }
} }
} }
@ -504,7 +504,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
protected void onPostExecute(Void aVoid) { protected void onPostExecute(Void aVoid) {
GPXFile gpxFile = group.getGpx(); GPXFile gpxFile = group.getGpx();
if (gpxFile != null && wasUpdated) { if (gpxFile != null && wasUpdated) {
syncGpx(gpxFile); app.getItineraryHelper().runSynchronizationAsync(gpxFile);
} }
if (progressDialog != null && progressDialog.isShowing()) { if (progressDialog != null && progressDialog.isShowing()) {
@ -522,12 +522,5 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
} }
} }
private void syncGpx(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
if (group != null) {
app.getItineraryHelper().runSynchronization(group);
}
}
} }
} }

View file

@ -63,7 +63,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener; import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
@ -500,12 +500,12 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
return; return;
} }
final GPXFile gpxFile = getGpx(); final GPXFile gpxFile = getGpx();
ItineraryGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile);
final ItineraryGroup markersGr; final MapMarkersGroup markersGr;
final boolean markersRemoved; final boolean markersRemoved;
if (markersSearch != null) { if (markersSearch != null) {
markersGr = markersSearch; markersGr = markersSearch;
markersHelper.removeMarkersGroup(markersGr); app.getItineraryHelper().removeMarkersGroup(markersGr);
markersRemoved = true; markersRemoved = true;
} else if (gpxFile != null) { } else if (gpxFile != null) {
markersGr = app.getItineraryHelper().addOrEnableGroup(gpxFile); markersGr = app.getItineraryHelper().addOrEnableGroup(gpxFile);
@ -537,9 +537,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
app.getItineraryHelper().addOrEnableGroup(gpxFile); app.getItineraryHelper().addOrEnableGroup(gpxFile);
} }
} else { } else {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
markersHelper.removeMarkersGroup(group); app.getItineraryHelper().removeMarkersGroup(group);
} }
} }
trackActivity.invalidateOptionsMenu(); trackActivity.invalidateOptionsMenu();

View file

@ -10,9 +10,10 @@ import net.osmand.GPXUtilities.GPXFile;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -122,10 +123,10 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
} }
} }
public ItineraryGroup getMarkersGroup() { public MapMarkersGroup getMarkersGroup() {
String name = app.getString(R.string.markers_history); String name = app.getString(R.string.markers_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name(); String groupId = ExportSettingsType.HISTORY_MARKERS.name();
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(items); markersGroup.setMarkers(items);
return markersGroup; return markersGroup;
} }

View file

@ -10,9 +10,10 @@ import net.osmand.GPXUtilities.GPXFile;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -122,10 +123,10 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
} }
} }
public ItineraryGroup getMarkersGroup() { public MapMarkersGroup getMarkersGroup() {
String name = app.getString(R.string.map_markers); String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name(); String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(items); markersGroup.setMarkers(items);
return markersGroup; return markersGroup;
} }

View file

@ -32,8 +32,9 @@ import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.itinerary.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -609,7 +610,7 @@ public class SettingsHelper {
if (!mapMarkers.isEmpty()) { if (!mapMarkers.isEmpty()) {
String name = app.getString(R.string.map_markers); String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name(); String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(mapMarkers); markersGroup.setMarkers(mapMarkers);
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup)); myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
} }
@ -617,7 +618,7 @@ public class SettingsHelper {
if (!markersHistory.isEmpty()) { if (!markersHistory.isEmpty()) {
String name = app.getString(R.string.shared_string_history); String name = app.getString(R.string.shared_string_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name(); String groupId = ExportSettingsType.HISTORY_MARKERS.name();
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE); MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(markersHistory); markersGroup.setMarkers(markersHistory);
myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup)); myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
} }
@ -720,8 +721,8 @@ public class SettingsHelper {
List<FavoriteGroup> favoriteGroups = new ArrayList<>(); List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>(); List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>(); List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<ItineraryGroup> markersGroups = new ArrayList<>(); List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<ItineraryGroup> markersHistoryGroups = new ArrayList<>(); List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
List<HistoryEntry> historyEntries = new ArrayList<>(); List<HistoryEntry> historyEntries = new ArrayList<>();
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>(); List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
@ -755,12 +756,12 @@ public class SettingsHelper {
osmEditsPointList.add((OpenstreetmapPoint) object); osmEditsPointList.add((OpenstreetmapPoint) object);
} else if (object instanceof FavoriteGroup) { } else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object); favoriteGroups.add((FavoriteGroup) object);
} else if (object instanceof ItineraryGroup) { } else if (object instanceof MapMarkersGroup) {
ItineraryGroup markersGroup = (ItineraryGroup) object; MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
markersGroups.add((ItineraryGroup) object); markersGroups.add((MapMarkersGroup) object);
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) { } else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
markersHistoryGroups.add((ItineraryGroup) object); markersHistoryGroups.add((MapMarkersGroup) object);
} }
} else if (object instanceof HistoryEntry) { } else if (object instanceof HistoryEntry) {
historyEntries.add((HistoryEntry) object); historyEntries.add((HistoryEntry) object);
@ -812,7 +813,7 @@ public class SettingsHelper {
} }
if (!markersGroups.isEmpty()) { if (!markersGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>(); List<MapMarker> mapMarkers = new ArrayList<>();
for (ItineraryGroup group : markersGroups) { for (MapMarkersGroup group : markersGroups) {
mapMarkers.addAll(group.getMarkers()); mapMarkers.addAll(group.getMarkers());
} }
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems); MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
@ -820,7 +821,7 @@ public class SettingsHelper {
} }
if (!markersHistoryGroups.isEmpty()) { if (!markersHistoryGroups.isEmpty()) {
List<MapMarker> mapMarkers = new ArrayList<>(); List<MapMarker> mapMarkers = new ArrayList<>();
for (ItineraryGroup group : markersHistoryGroups) { for (MapMarkersGroup group : markersHistoryGroups) {
mapMarkers.addAll(group.getMarkers()); mapMarkers.addAll(group.getMarkers());
} }
HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems); HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
@ -910,8 +911,8 @@ public class SettingsHelper {
List<OsmNotesPoint> notesPointList = new ArrayList<>(); List<OsmNotesPoint> notesPointList = new ArrayList<>();
List<OpenstreetmapPoint> editsPointList = new ArrayList<>(); List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>(); List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<ItineraryGroup> markersGroups = new ArrayList<>(); List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<ItineraryGroup> markersHistoryGroups = new ArrayList<>(); List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
List<HistoryEntry> historyEntries = new ArrayList<>(); List<HistoryEntry> historyEntries = new ArrayList<>();
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>(); List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();

View file

@ -40,7 +40,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -376,8 +376,8 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object; GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
item.setTitle(globalSettingsItem.getPublicName(app)); item.setTitle(globalSettingsItem.getPublicName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object))); item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
} else if (object instanceof ItineraryGroup) { } else if (object instanceof MapMarkersGroup) {
ItineraryGroup markersGroup = (ItineraryGroup) object; MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) { if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.map_markers)); item.setTitle(getString(R.string.map_markers));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object))); item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));

View file

@ -18,7 +18,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.settings.backend.ExportSettingsCategory; import net.osmand.plus.settings.backend.ExportSettingsCategory;
import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.ExportSettingsType;
import net.osmand.plus.settings.backend.backup.FileSettingsItem; import net.osmand.plus.settings.backend.backup.FileSettingsItem;
@ -311,8 +311,8 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter {
itemsSize += ((FileSettingsItem) object).getSize(); itemsSize += ((FileSettingsItem) object).getSize();
} else if (object instanceof File) { } else if (object instanceof File) {
itemsSize += ((File) object).length(); itemsSize += ((File) object).length();
} else if (object instanceof ItineraryGroup) { } else if (object instanceof MapMarkersGroup) {
int selectedMarkers = ((ItineraryGroup) object).getMarkers().size(); int selectedMarkers = ((MapMarkersGroup) object).getMarkers().size();
String itemsDescr = app.getString(R.string.shared_string_items); String itemsDescr = app.getString(R.string.shared_string_items);
return app.getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers); return app.getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers);
} }

View file

@ -44,7 +44,6 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint; import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints; import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
@ -1210,10 +1209,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
ItineraryGroup group = view.getApplication().getItineraryHelper().getMarkersGroup(gpxFile); view.getApplication().getItineraryHelper().runSynchronizationAsync(gpxFile);
if (group != null) {
view.getApplication().getItineraryHelper().runSynchronization(group);
}
} }
private static class CachedTrack { private static class CachedTrack {