Merge pull request #11487 from osmandapp/markers_refactor

Revert itinerary and refactor group markers
This commit is contained in:
vshcherb 2021-04-21 14:55:36 +02:00 committed by GitHub
commit 60b72f53be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 702 additions and 741 deletions

View file

@ -40,7 +40,6 @@ import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.helpers.LockHelper; import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.WaypointHelper; import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.inapp.InAppPurchaseHelperImpl; import net.osmand.plus.inapp.InAppPurchaseHelperImpl;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.liveupdates.LiveUpdatesHelper; import net.osmand.plus.liveupdates.LiveUpdatesHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
@ -473,7 +472,6 @@ public class AppInitializer implements IProgress {
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class); app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class); app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class); app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
app.itineraryHelper = startupInit(new ItineraryHelper(app), ItineraryHelper.class);
app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class); app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class);
initOpeningHoursParser(); initOpeningHoursParser();
@ -687,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.mapMarkersHelper.syncAllGroupsAsync();
app.searchUICore.initSearchUICore(); app.searchUICore.initSearchUICore();
checkLiveUpdatesAlerts(); checkLiveUpdatesAlerts();

View file

@ -17,7 +17,7 @@ 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.mapmarkers.MapMarkersHelper;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
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.util.Algorithms; import net.osmand.util.Algorithms;
@ -280,15 +280,16 @@ public class FavouritesDbHelper {
} }
private void runSyncWithMarkers(FavoriteGroup favGroup) { private void runSyncWithMarkers(FavoriteGroup favGroup) {
ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup); MapMarkersHelper helper = context.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
if (group != null) { if (group != null) {
context.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }
private boolean removeFromMarkers(FavoriteGroup favGroup) { private boolean removeFromMarkers(FavoriteGroup favGroup) {
MapMarkersHelper helper = context.getMapMarkersHelper(); MapMarkersHelper helper = context.getMapMarkersHelper();
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;
@ -297,7 +298,8 @@ public class FavouritesDbHelper {
} }
private void addToMarkers(FavoriteGroup favGroup) { private void addToMarkers(FavoriteGroup favGroup) {
context.getItineraryHelper().addOrEnableGroup(favGroup); MapMarkersHelper helper = context.getMapMarkersHelper();
helper.addOrEnableGroup(favGroup);
} }
private File getInternalFile() { private File getInternalFile() {

View file

@ -30,7 +30,8 @@ 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.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
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;
@ -797,7 +798,7 @@ public class GpxSelectionHelper {
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.getMapMarkersHelper().addOrEnableGroup(gpx);
} }
return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory); return selectGpxFile(gpx, dataItem, show, notShowNavigationDialog, syncGroup, selectedByUser, addToHistory);
} }
@ -824,9 +825,10 @@ public class GpxSelectionHelper {
} }
private void syncGpxWithMarkers(GPXFile gpxFile) { private void syncGpxWithMarkers(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
} }

View file

@ -67,7 +67,6 @@ import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.helpers.enums.DrivingRegion; import net.osmand.plus.helpers.enums.DrivingRegion;
import net.osmand.plus.helpers.enums.MetricsConstants; import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.itinerary.ItineraryHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementEditingContext;
@ -169,7 +168,6 @@ public class OsmandApplication extends MultiDexApplication {
OprAuthHelper oprAuthHelper; OprAuthHelper oprAuthHelper;
MeasurementEditingContext measurementEditingContext; MeasurementEditingContext measurementEditingContext;
OnlineRoutingHelper onlineRoutingHelper; OnlineRoutingHelper onlineRoutingHelper;
ItineraryHelper itineraryHelper;
BackupHelper backupHelper; BackupHelper backupHelper;
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>(); private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
@ -472,10 +470,6 @@ public class OsmandApplication extends MultiDexApplication {
return onlineRoutingHelper; return onlineRoutingHelper;
} }
public ItineraryHelper getItineraryHelper() {
return itineraryHelper;
}
public BackupHelper getBackupHelper() { public BackupHelper getBackupHelper() {
return backupHelper; return backupHelper;
} }

View file

@ -28,7 +28,7 @@ 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.mapmarkers.MapMarkersHelper;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
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;
@ -179,7 +179,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
final MapMarkersHelper markersHelper = app.getMapMarkersHelper(); final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final FavoriteGroup favGroup = this.group; final FavoriteGroup favGroup = this.group;
final ItineraryGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group); final MapMarkersGroup markersGr = markersHelper.getMarkersGroup(this.group);
final boolean synced = markersGr != null; final boolean synced = markersGr != null;
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder() BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
@ -192,7 +192,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
if (synced) { if (synced) {
markersHelper.removeMarkersGroup(markersGr); markersHelper.removeMarkersGroup(markersGr);
} else { } else {
app.getItineraryHelper().addOrEnableGroup(favGroup); markersHelper.addOrEnableGroup(favGroup);
} }
dismiss(); dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());

View file

@ -526,7 +526,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) { for (Map.Entry<String, Set<FavouritePoint>> entry : favoritesSelected.entrySet()) {
FavoriteGroup group = helper.getGroup(entry.getKey()); FavoriteGroup group = helper.getGroup(entry.getKey());
if (group != null && entry.getValue().size() == group.getPoints().size()) { if (group != null && entry.getValue().size() == group.getPoints().size()) {
getMyApplication().getItineraryHelper().addOrEnableGroup(group); markersHelper.addOrEnableGroup(group);
} else { } else {
for (FavouritePoint fp : entry.getValue()) { for (FavouritePoint fp : entry.getValue()) {
points.add(new LatLon(fp.getLatitude(), fp.getLongitude())); points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));

View file

@ -18,8 +18,8 @@ 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.MapMarkersDialogFragment; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants; import net.osmand.plus.openplacereviews.OPRConstants;
import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener; import net.osmand.plus.openplacereviews.OprAuthHelper.OprAuthorizationListener;
@ -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

@ -1,436 +0,0 @@
package net.osmand.plus.itinerary;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.plus.mapmarkers.MapMarkersHelper.BY_DATE_ADDED_DESC;
public class ItineraryHelper {
private static final Log LOG = PlatformUtil.getLog(ItineraryHelper.class);
private OsmandApplication app;
private MapMarkersHelper markersHelper;
private MapMarkersDbHelper markersDbHelper;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<ItineraryGroup> itineraryGroups = new ArrayList<>();
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
public ItineraryHelper(@NonNull OsmandApplication app) {
this.app = app;
markersHelper = app.getMapMarkersHelper();
markersDbHelper = app.getMapMarkersDbHelper();
loadGroups();
}
public List<ItineraryGroup> getItineraryGroups() {
return itineraryGroups;
}
public void syncAllGroupsAsync() {
for (ItineraryGroup group : itineraryGroups) {
if (group.getId() != null && group.getName() != null) {
runSynchronization(group);
}
}
}
public void updateGroupWptCategories(@NonNull ItineraryGroup 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 ItineraryGroup gr) {
// check if group doesn't exist internally
if (!itineraryGroups.contains(gr)) {
addGroupInternally(gr);
}
if (gr.isDisabled()) {
updateGroupDisabled(gr, false);
}
runSynchronization(gr);
}
public void updateGroups() {
for (ItineraryGroup group : itineraryGroups) {
markersHelper.updateGroup(group);
}
}
public void updateGroupDisabled(@NonNull ItineraryGroup 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 (ItineraryGroup group : itineraryGroups) {
if (group.getType() == ItineraryGroup.ANY_TYPE) {
for (MapMarker marker : group.getMarkers()) {
if (history && marker.history || !history && !marker.history) {
mapMarkers.add(marker);
}
}
}
}
return mapMarkers;
}
private void loadGroups() {
Map<String, ItineraryGroup> groupsMap = markersDbHelper.getAllGroupsMap();
List<MapMarker> allMarkers = new ArrayList<>(markersHelper.getMapMarkers());
allMarkers.addAll(markersHelper.getMapMarkersHistory());
Iterator<Entry<String, ItineraryGroup>> iterator = groupsMap.entrySet().iterator();
while (iterator.hasNext()) {
ItineraryGroup group = iterator.next().getValue();
if (group.getType() == ItineraryGroup.GPX_TYPE && !new File(group.getId()).exists()) {
markersDbHelper.removeMarkersGroup(group.getId());
iterator.remove();
}
}
ItineraryGroup noGroup = null;
for (MapMarker marker : allMarkers) {
ItineraryGroup group = groupsMap.get(marker.groupKey);
if (group == null) {
if (noGroup == null) {
noGroup = new ItineraryGroup();
noGroup.setCreationDate(Long.MAX_VALUE);
}
noGroup.getMarkers().add(marker);
} else {
if (marker.creationDate < group.getCreationDate()) {
group.setCreationDate(marker.creationDate);
}
group.getMarkers().add(marker);
}
}
itineraryGroups = new ArrayList<>(groupsMap.values());
if (noGroup != null) {
markersHelper.sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
addToGroupsList(noGroup);
}
sortGroups();
for (ItineraryGroup group : itineraryGroups) {
markersHelper.updateGroup(group);
}
}
public void addGroupInternally(ItineraryGroup gr) {
markersDbHelper.addGroup(gr);
markersHelper.addHistoryMarkersToGroup(gr);
addToGroupsList(gr);
}
public void updateGpxShowAsMarkers(File file) {
GPXDatabase.GpxDataItem dataItem = app.getGpxDbHelper().getItem(file);
if (dataItem != null) {
app.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
dataItem.setShowAsMarkers(true);
}
}
public void addToGroupsList(ItineraryGroup group) {
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups);
copyList.add(group);
itineraryGroups = copyList;
}
public void removeFromGroupsList(ItineraryGroup group) {
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups);
copyList.remove(group);
itineraryGroups = copyList;
}
public void addSyncListener(OnGroupSyncedListener listener) {
syncListeners.add(listener);
}
public void removeSyncListener(OnGroupSyncedListener listener) {
syncListeners.remove(listener);
}
public void runSynchronization(final @NonNull ItineraryGroup group) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
new SyncGroupTask(group).executeOnExecutor(executorService);
}
});
}
public ItineraryGroup getMarkersGroup(GPXFile gpx) {
if (gpx == null || gpx.path == null) {
return null;
}
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryGroup.GPX_TYPE);
}
public ItineraryGroup getMarkersGroup(FavoriteGroup favGroup) {
return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryGroup.FAVORITES_TYPE);
}
public ItineraryGroup addOrEnableGpxGroup(@NonNull File file) {
updateGpxShowAsMarkers(file);
ItineraryGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryGroup.GPX_TYPE);
if (gr == null) {
gr = createGPXMarkerGroup(file);
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
public ItineraryGroup addOrEnableGroup(@NonNull GPXFile file) {
updateGpxShowAsMarkers(new File(file.path));
ItineraryGroup gr = getMarkersGroup(file);
if (gr == null) {
gr = createGPXMarkerGroup(new File(file.path));
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
public ItineraryGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
ItineraryGroup gr = getMarkersGroup(group);
if (gr == null) {
gr = createFavMarkerGroup(group);
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
private ItineraryGroup createGPXMarkerGroup(File fl) {
return new ItineraryGroup(getMarkerGroupId(fl),
Algorithms.getFileNameWithoutExtension(fl.getName()),
ItineraryGroup.GPX_TYPE);
}
private ItineraryGroup createFavMarkerGroup(FavoriteGroup favGroup) {
return new ItineraryGroup(favGroup.getName(), favGroup.getName(), ItineraryGroup.FAVORITES_TYPE);
}
private String getMarkerGroupId(File gpx) {
return gpx.getAbsolutePath();
}
private String getMarkerGroupId(FavoriteGroup group) {
return group.getName();
}
public void removeMarkerFromGroup(MapMarker marker) {
if (marker != null) {
ItineraryGroup itineraryGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
if (itineraryGroup != null) {
itineraryGroup.getMarkers().remove(marker);
markersHelper.updateGroup(itineraryGroup);
}
}
}
public void sortGroups() {
if (itineraryGroups.size() > 0) {
Collections.sort(itineraryGroups, new Comparator<ItineraryGroup>() {
@Override
public int compare(ItineraryGroup group1, ItineraryGroup group2) {
long t1 = group1.getCreationDate();
long t2 = group2.getCreationDate();
return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1);
}
});
}
}
@Nullable
public ItineraryGroup getMapMarkerGroupById(String id, int type) {
for (ItineraryGroup group : itineraryGroups) {
if ((id == null && group.getId() == null)
|| (group.getId() != null && group.getId().equals(id))) {
if (type == ItineraryGroup.ANY_TYPE || type == group.getType()) {
return group;
}
}
}
return null;
}
@NonNull
public List<ItineraryGroup> getGroupsForDisplayedGpx() {
List<ItineraryGroup> res = new ArrayList<>();
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selected : selectedGpxFiles) {
ItineraryGroup search = getMarkersGroup(selected.getGpxFile());
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
ItineraryGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
group.setDisabled(true);
markersHelper.createHeadersInGroup(group);
res.add(group);
}
}
return res;
}
@NonNull
public List<ItineraryGroup> getGroupsForSavedArticlesTravelBook() {
List<ItineraryGroup> res = new ArrayList<>();
TravelHelper travelHelper = app.getTravelHelper();
if (travelHelper.isAnyTravelBookPresent()) {
List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
for (TravelArticle art : savedArticles) {
String gpxName = travelHelper.getGPXName(art);
File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
ItineraryGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryGroup.GPX_TYPE);
if (search == null) {
ItineraryGroup group = createGPXMarkerGroup(path);
group.setDisabled(true);
markersHelper.createHeadersInGroup(group);
res.add(group);
}
}
}
return res;
}
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
private ItineraryGroup group;
SyncGroupTask(ItineraryGroup group) {
this.group = group;
}
@Override
protected void onPreExecute() {
if (!syncListeners.isEmpty()) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {
listener.onSyncStarted();
}
}
});
}
}
@Override
protected Void doInBackground(Void... voids) {
runGroupSynchronization();
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
protected void onPostExecute(Void aVoid) {
if (!syncListeners.isEmpty()) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {
listener.onSyncDone();
}
}
});
}
}
}
}

View file

@ -17,6 +17,8 @@ import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.WptLocationPoint; import net.osmand.data.WptLocationPoint;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
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;
@ -24,7 +26,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,9 +220,10 @@ 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); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }
} }

View file

@ -20,6 +20,8 @@ import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.WptLocationPoint; import net.osmand.data.WptLocationPoint;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
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.R;
@ -27,7 +29,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,9 +238,10 @@ 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); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }
} }

View file

@ -56,7 +56,7 @@ public class AddFavouritesGroupBottomSheetDialogFragment extends AddGroupBottomS
if (!group.isVisible()) { if (!group.isVisible()) {
favouritesDbHelper.editFavouriteGroup(group, group.getName(), group.getColor(), true); favouritesDbHelper.editFavouriteGroup(group, group.getName(), group.getColor(), true);
} }
getMyApplication().getItineraryHelper().addOrEnableGroup(group); getMyApplication().getMapMarkersHelper().addOrEnableGroup(group);
dismiss(); dismiss();
} }
} }

View file

@ -108,7 +108,7 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
GPXFile res = GPXUtilities.loadGPXFile(gpx); GPXFile res = GPXUtilities.loadGPXFile(gpx);
selectionHelper.selectGpxFile(res, true, false, false, false, false); selectionHelper.selectGpxFile(res, true, false, false, false, false);
} }
app.getItineraryHelper().addOrEnableGpxGroup(gpx); app.getMapMarkersHelper().addOrEnableGpxGroup(gpx);
} }
} }
dismiss(); dismiss();

View file

@ -2,25 +2,3 @@ package net.osmand.plus.mapmarkers;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import net.osmand.plus.itinerary.ItineraryGroup;
public class CategoriesSubHeader {
@DrawableRes
private int iconRes;
private ItineraryGroup group;
public CategoriesSubHeader(int iconRes, ItineraryGroup group) {
this.iconRes = iconRes;
this.group = group;
}
@DrawableRes
public int getIconRes() {
return iconRes;
}
public ItineraryGroup getGroup() {
return group;
}
}

View file

@ -71,8 +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.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener; import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS; import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS;
@ -170,8 +168,8 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
ItineraryHelper helper = getMyApplication().getItineraryHelper(); MapMarkersHelper helper = getMyApplication().getMapMarkersHelper();
ItineraryGroup group = helper.getMarkersGroup(gpxFile); MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
helper.runSynchronization(group); helper.runSynchronization(group);
} }
@ -1091,7 +1089,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
public void saveGpx(final String fileName) { public void saveGpx(final String fileName) {
new SaveGpxAsyncTask(app, getGpx(),fileName, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); new SaveGpxAsyncTask(app, getGpx(),fileName, false).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
hasUnsavedChanges = false; hasUnsavedChanges = false;
app.getItineraryHelper().addOrEnableGroup(getGpx()); app.getMapMarkersHelper().addOrEnableGroup(getGpx());
if (listener != null) { if (listener != null) {
listener.onPointsSaved(); listener.onPointsSaved();
} }

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,6 @@ 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.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;
@ -47,8 +46,8 @@ public class MapMarker implements LocationPoint {
public int getType() { public int getType() {
return favouritePoint == null ? return favouritePoint == null ?
(wptPt == null ? ItineraryGroup.ANY_TYPE : ItineraryGroup.GPX_TYPE) : (wptPt == null ? MapMarkersGroup.ANY_TYPE : MapMarkersGroup.GPX_TYPE) :
ItineraryGroup.FAVORITES_TYPE; MapMarkersGroup.FAVORITES_TYPE;
} }
public PointDescription getPointDescription(Context ctx) { public PointDescription getPointDescription(Context ctx) {

View file

@ -8,7 +8,6 @@ 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.util.Algorithms; import net.osmand.util.Algorithms;
import java.util.ArrayList; import java.util.ArrayList;
@ -162,7 +161,7 @@ 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 {
@ -174,15 +173,15 @@ public class MapMarkersDbHelper {
} }
} }
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 +195,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, 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

@ -218,13 +218,13 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
getMyApplication().getItineraryHelper().addSyncListener(this); getMyApplication().getMapMarkersHelper().addSyncListener(this);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
getMyApplication().getItineraryHelper().removeSyncListener(this); getMyApplication().getMapMarkersHelper().removeSyncListener(this);
} }
@Override @Override

View file

@ -1,12 +1,8 @@
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.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,7 +10,7 @@ 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 ANY_TYPE = -1;
public static final int FAVORITES_TYPE = 0; public static final int FAVORITES_TYPE = 0;
@ -35,14 +31,13 @@ public class ItineraryGroup {
private TravelArticle wikivoyageArticle; private TravelArticle wikivoyageArticle;
// TODO should be removed from this class: // TODO should be removed from this class:
private GroupHeader header; private GroupHeader header;
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, int type) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.type = type; this.type = type;
@ -80,10 +75,6 @@ public class ItineraryGroup {
this.header = header; this.header = header;
} }
public void setCategoriesSubHeader(CategoriesSubHeader categoriesSubHeader) {
this.categoriesSubHeader = categoriesSubHeader;
}
public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) { public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) {
this.showHideHistoryButton = showHideHistoryButton; this.showHideHistoryButton = showHideHistoryButton;
} }
@ -148,10 +139,6 @@ public class ItineraryGroup {
return header; return header;
} }
public CategoriesSubHeader getCategoriesSubHeader() {
return categoriesSubHeader;
}
public ShowHideHistoryButton getShowHideHistoryButton() { public ShowHideHistoryButton getShowHideHistoryButton() {
return showHideHistoryButton; return showHideHistoryButton;
} }

View file

@ -1,5 +1,7 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.os.AsyncTask;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
@ -14,12 +16,17 @@ 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.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXDatabase;
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.GpxSelectionHelper;
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.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -34,10 +41,15 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.GPXUtilities.GPX_TIME_FORMAT; import static net.osmand.GPXUtilities.GPX_TIME_FORMAT;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER; import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
@ -63,13 +75,17 @@ public class MapMarkersHelper {
public @interface MapMarkersSortByDef { public @interface MapMarkersSortByDef {
} }
private OsmandApplication app; private OsmandApplication ctx;
private MapMarkersDbHelper markersDbHelper; private MapMarkersDbHelper markersDbHelper;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<MapMarker> mapMarkers = new ArrayList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new ArrayList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
private MarkersPlanRouteContext planRouteContext; private MarkersPlanRouteContext planRouteContext;
@ -81,24 +97,29 @@ public class MapMarkersHelper {
return mapMarkersHistory; return mapMarkersHistory;
} }
public List<MapMarkersGroup> getMapMarkersGroups() {
return mapMarkersGroups;
}
public boolean isStartFromMyLocation() { public boolean isStartFromMyLocation() {
return app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get(); return ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get();
} }
public void setStartFromMyLocation(boolean startFromMyLocation) { public void setStartFromMyLocation(boolean startFromMyLocation) {
app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation); ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
} }
public MarkersPlanRouteContext getPlanRouteContext() { public MarkersPlanRouteContext getPlanRouteContext() {
return planRouteContext; return planRouteContext;
} }
public MapMarkersHelper(OsmandApplication app) { public MapMarkersHelper(OsmandApplication ctx) {
this.app = app; this.ctx = ctx;
markersDbHelper = app.getMapMarkersDbHelper(); markersDbHelper = ctx.getMapMarkersDbHelper();
planRouteContext = new MarkersPlanRouteContext(app); planRouteContext = new MarkersPlanRouteContext(ctx);
markersDbHelper.removeDisabledGroups(); markersDbHelper.removeDisabledGroups();
loadMarkers(); loadMarkers();
loadGroups();
} }
private void loadMarkers() { private void loadMarkers() {
@ -112,11 +133,63 @@ public class MapMarkersHelper {
sortMarkers(markersHistory, true, BY_DATE_ADDED_DESC); sortMarkers(markersHistory, true, BY_DATE_ADDED_DESC);
addToMapMarkersHistoryList(markersHistory); addToMapMarkersHistoryList(markersHistory);
if (!app.isApplicationInitializing()) { if (!ctx.isApplicationInitializing()) {
lookupAddressAll(); lookupAddressAll();
} }
} }
private void loadGroups() {
Map<String, MapMarkersGroup> groupsMap = markersDbHelper.getAllGroupsMap();
List<MapMarker> allMarkers = new ArrayList<>(mapMarkers);
allMarkers.addAll(mapMarkersHistory);
Iterator<Map.Entry<String, MapMarkersGroup>> iterator = groupsMap.entrySet().iterator();
while (iterator.hasNext()) {
MapMarkersGroup group = iterator.next().getValue();
if (group.getType() == MapMarkersGroup.GPX_TYPE && !new File(group.getId()).exists()) {
markersDbHelper.removeMarkersGroup(group.getId());
iterator.remove();
}
}
MapMarkersGroup noGroup = null;
for (MapMarker marker : allMarkers) {
MapMarkersGroup group = groupsMap.get(marker.groupKey);
if (group == null) {
if (noGroup == null) {
noGroup = new MapMarkersGroup();
noGroup.setCreationDate(Long.MAX_VALUE);
}
noGroup.getMarkers().add(marker);
} else {
if (marker.creationDate < group.getCreationDate()) {
group.setCreationDate(marker.creationDate);
}
group.getMarkers().add(marker);
}
}
mapMarkersGroups = new ArrayList<>(groupsMap.values());
if (noGroup != null) {
sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
addToGroupsList(noGroup);
}
sortGroups();
for (MapMarkersGroup group : mapMarkersGroups) {
updateGroup(group);
}
}
public void syncAllGroupsAsync() {
for (MapMarkersGroup gr : mapMarkersGroups) {
if (gr.getId() != null && gr.getName() != null) {
runSynchronization(gr);
}
}
}
public void lookupAddressAll() { public void lookupAddressAll() {
for (MapMarker mapMarker : mapMarkers) { for (MapMarker mapMarker : mapMarkers) {
@ -128,7 +201,7 @@ public class MapMarkersHelper {
} }
private void lookupAddress(final MapMarker mapMarker) { private void lookupAddress(final MapMarker mapMarker) {
if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(app)) { if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(ctx)) {
cancelPointAddressRequests(mapMarker.point); cancelPointAddressRequests(mapMarker.point);
AddressLookupRequest lookupRequest = new AddressLookupRequest(mapMarker.point, AddressLookupRequest lookupRequest = new AddressLookupRequest(mapMarker.point,
new GeocodingLookupService.OnAddressLookupResult() { new GeocodingLookupService.OnAddressLookupResult() {
@ -136,7 +209,7 @@ public class MapMarkersHelper {
public void geocodingDone(String address) { public void geocodingDone(String address) {
PointDescription pointDescription = mapMarker.getOriginalPointDescription(); PointDescription pointDescription = mapMarker.getOriginalPointDescription();
if (Algorithms.isEmpty(address)) { if (Algorithms.isEmpty(address)) {
pointDescription.setName(PointDescription.getAddressNotFoundStr(app)); pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx));
} else { } else {
pointDescription.setName(address); pointDescription.setName(address);
} }
@ -144,7 +217,7 @@ public class MapMarkersHelper {
refreshMarker(mapMarker); refreshMarker(mapMarker);
} }
}, null); }, null);
app.getGeocodingLookupService().lookupAddress(lookupRequest); ctx.getGeocodingLookupService().lookupAddress(lookupRequest);
} }
} }
@ -161,7 +234,7 @@ public class MapMarkersHelper {
private void cancelPointAddressRequests(LatLon latLon) { private void cancelPointAddressRequests(LatLon latLon) {
if (latLon != null) { if (latLon != null) {
app.getGeocodingLookupService().cancel(latLon); ctx.getGeocodingLookupService().cancel(latLon);
} }
} }
@ -190,7 +263,7 @@ public class MapMarkersHelper {
reorderActiveMarkersIfNeeded(); reorderActiveMarkersIfNeeded();
} }
public void sortMarkers(List<MapMarker> markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) { private void sortMarkers(List<MapMarker> markers, final boolean visited, final @MapMarkersSortByDef int sortByMode) {
sortMarkers(markers, visited, sortByMode, null); sortMarkers(markers, visited, sortByMode, null);
} }
@ -222,15 +295,92 @@ public class MapMarkersHelper {
return sortByMode == BY_DISTANCE_DESC ? 1 : -1; return sortByMode == BY_DISTANCE_DESC ? 1 : -1;
} }
} else { } else {
String n1 = mapMarker1.getName(app); String n1 = mapMarker1.getName(ctx);
String n2 = mapMarker2.getName(app); String n2 = mapMarker2.getName(ctx);
return n1.compareToIgnoreCase(n2); return n1.compareToIgnoreCase(n2);
} }
} }
}); });
} }
public void addHistoryMarkersToGroup(@NonNull ItineraryGroup group) { public void runSynchronization(final @NonNull MapMarkersGroup group) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
new SyncGroupTask(group).executeOnExecutor(executorService);
}
});
}
public MapMarkersGroup getMarkersGroup(GPXFile gpx) {
if (gpx == null || gpx.path == null) {
return null;
}
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), MapMarkersGroup.GPX_TYPE);
}
public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) {
return getMapMarkerGroupById(getMarkerGroupId(favGroup), MapMarkersGroup.FAVORITES_TYPE);
}
public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
updateGpxShowAsMarkers(file);
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), MapMarkersGroup.GPX_TYPE);
if (gr == null) {
gr = createGPXMarkerGroup(file);
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) {
updateGpxShowAsMarkers(new File(file.path));
MapMarkersGroup gr = getMarkersGroup(file);
if (gr == null) {
gr = createGPXMarkerGroup(new File(file.path));
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
public MapMarkersGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
MapMarkersGroup gr = getMarkersGroup(group);
if (gr == null) {
gr = createFavMarkerGroup(group);
addGroupInternally(gr);
}
enableGroup(gr);
return gr;
}
public void enableGroup(@NonNull MapMarkersGroup gr) {
// check if group doesn't exist internally
if (!mapMarkersGroups.contains(gr)) {
addGroupInternally(gr);
}
if (gr.isDisabled()) {
updateGroupDisabled(gr, false);
}
runSynchronization(gr);
}
private void addGroupInternally(MapMarkersGroup gr) {
markersDbHelper.addGroup(gr);
addHistoryMarkersToGroup(gr);
addToGroupsList(gr);
}
private void updateGpxShowAsMarkers(File file) {
GPXDatabase.GpxDataItem dataItem = ctx.getGpxDbHelper().getItem(file);
if (dataItem != null) {
ctx.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
dataItem.setShowAsMarkers(true);
}
}
private 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,15 +389,33 @@ public class MapMarkersHelper {
} }
} }
public void removeMarkersGroup(ItineraryGroup group) { public void removeMarkersGroup(MapMarkersGroup group) {
if (group != null) { if (group != null) {
markersDbHelper.removeMarkersGroup(group.getId()); markersDbHelper.removeMarkersGroup(group.getId());
removeGroupActiveMarkers(group, false); removeGroupActiveMarkers(group, false);
app.getItineraryHelper().removeFromGroupsList(group); removeFromGroupsList(group);
} }
} }
public void removeGroupActiveMarkers(ItineraryGroup group, boolean updateGroup) { public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
String id = group.getId();
if (id != null) {
markersDbHelper.updateGroupDisabled(id, disabled);
group.setDisabled(disabled);
}
}
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());
}
}
}
private 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());
@ -260,21 +428,27 @@ public class MapMarkersHelper {
} }
} }
public void updateGroup(ItineraryGroup itineraryGroup) { public void updateGroups() {
if (itineraryGroup.getId() == null || itineraryGroup.getName() == null) { for (MapMarkersGroup group : mapMarkersGroups) {
updateGroup(group);
}
}
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
return; return;
} }
createHeadersInGroup(itineraryGroup); createHeadersInGroup(mapMarkersGroup);
int historyMarkersCount = itineraryGroup.getHistoryMarkers().size(); int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = itineraryGroup.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null) { if (showHideHistoryButton != null) {
if (historyMarkersCount == 0) { if (historyMarkersCount == 0) {
itineraryGroup.setShowHideHistoryButton(null); mapMarkersGroup.setShowHideHistoryButton(null);
} }
} else if (historyMarkersCount > 0) { } else if (historyMarkersCount > 0) {
showHideHistoryButton = new ShowHideHistoryButton(); showHideHistoryButton = new ShowHideHistoryButton();
showHideHistoryButton.showHistory = false; showHideHistoryButton.showHistory = false;
itineraryGroup.setShowHideHistoryButton(showHideHistoryButton); mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton);
} }
} }
@ -286,38 +460,124 @@ public class MapMarkersHelper {
private void addMarkerToGroup(MapMarker marker) { private void addMarkerToGroup(MapMarker marker) {
if (marker != null) { if (marker != null) {
ItineraryGroup itineraryGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType()); MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
if (itineraryGroup != null) { if (mapMarkersGroup != null) {
itineraryGroup.getMarkers().add(marker); mapMarkersGroup.getMarkers().add(marker);
updateGroup(itineraryGroup); updateGroup(mapMarkersGroup);
if (itineraryGroup.getName() == null) { if (mapMarkersGroup.getName() == null) {
sortMarkers(itineraryGroup.getMarkers(), false, BY_DATE_ADDED_DESC); sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
} }
} else { } else {
itineraryGroup = new ItineraryGroup(marker.groupKey, marker.groupName, ItineraryGroup.ANY_TYPE); mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, MapMarkersGroup.ANY_TYPE);
itineraryGroup.setCreationDate(Long.MAX_VALUE); mapMarkersGroup.setCreationDate(Long.MAX_VALUE);
itineraryGroup.getMarkers().add(marker); mapMarkersGroup.getMarkers().add(marker);
app.getItineraryHelper().addToGroupsList(itineraryGroup); addToGroupsList(mapMarkersGroup);
app.getItineraryHelper().sortGroups(); sortGroups();
updateGroup(itineraryGroup); updateGroup(mapMarkersGroup);
} }
} }
} }
public void createHeadersInGroup(@NonNull ItineraryGroup group) { private void createHeadersInGroup(@NonNull MapMarkersGroup group) {
int type = group.getType(); int type = group.getType();
int headerIconId = 0; int headerIconId = 0;
int subHeaderIconId = 0;
if (type != -1) { if (type != -1) {
headerIconId = type == ItineraryGroup.FAVORITES_TYPE headerIconId = type == MapMarkersGroup.FAVORITES_TYPE
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark; ? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
subHeaderIconId = R.drawable.ic_action_filter;
} }
GroupHeader header = new GroupHeader(headerIconId, group); GroupHeader header = new GroupHeader(headerIconId, group);
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(subHeaderIconId, group);
group.setHeader(header); group.setHeader(header);
group.setCategoriesSubHeader(categoriesSubHeader); }
private void removeMarkerFromGroup(MapMarker marker) {
if (marker != null) {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().remove(marker);
updateGroup(mapMarkersGroup);
}
}
}
private void sortGroups() {
if (mapMarkersGroups.size() > 0) {
Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
@Override
public int compare(MapMarkersGroup group1, MapMarkersGroup group2) {
long t1 = group1.getCreationDate();
long t2 = group2.getCreationDate();
return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1);
}
});
}
}
@Nullable
public MapMarkersGroup getMapMarkerGroupById(String id, int type) {
for (MapMarkersGroup group : mapMarkersGroups) {
if ((id == null && group.getId() == null)
|| (group.getId() != null && group.getId().equals(id))) {
if (type == MapMarkersGroup.ANY_TYPE || type == group.getType()) {
return group;
}
}
}
return null;
}
private MapMarkersGroup createGPXMarkerGroup(File fl) {
return new MapMarkersGroup(getMarkerGroupId(fl),
Algorithms.getFileNameWithoutExtension(fl.getName()),
MapMarkersGroup.GPX_TYPE);
}
private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) {
return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), MapMarkersGroup.FAVORITES_TYPE);
}
private String getMarkerGroupId(File gpx) {
return gpx.getAbsolutePath();
}
private String getMarkerGroupId(FavoriteGroup group) {
return group.getName();
}
@NonNull
public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
List<MapMarkersGroup> res = new ArrayList<>();
List<SelectedGpxFile> selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selected : selectedGpxFiles) {
MapMarkersGroup search = getMarkersGroup(selected.getGpxFile());
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
group.setDisabled(true);
createHeadersInGroup(group);
res.add(group);
}
}
return res;
}
@NonNull
public List<MapMarkersGroup> getGroupsForSavedArticlesTravelBook() {
List<MapMarkersGroup> res = new ArrayList<>();
TravelHelper travelHelper = ctx.getTravelHelper();
if (travelHelper.isAnyTravelBookPresent()) {
List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
for (TravelArticle art : savedArticles) {
String gpxName = travelHelper.getGPXName(art);
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), MapMarkersGroup.GPX_TYPE);
if (search == null) {
MapMarkersGroup group = createGPXMarkerGroup(path);
group.setDisabled(true);
createHeadersInGroup(group);
res.add(group);
}
}
}
return res;
} }
@Nullable @Nullable
@ -352,7 +612,7 @@ public class MapMarkersHelper {
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 (ctx.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
res.addAll(mapMarkersHistory); res.addAll(mapMarkersHistory);
} }
return res; return res;
@ -371,12 +631,12 @@ public class MapMarkersHelper {
return null; return null;
} }
public void addNewMarkerIfNeeded(@NonNull ItineraryGroup group, private 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,
@Nullable FavouritePoint favouritePoint, @Nullable FavouritePoint favouritePoint,
@Nullable WptPt wptPt) { @Nullable WptPt wptPt) {
boolean exists = false; boolean exists = false;
Iterator<MapMarker> iterator = groupMarkers.iterator(); Iterator<MapMarker> iterator = groupMarkers.iterator();
@ -406,7 +666,7 @@ public class MapMarkersHelper {
} }
} }
public void removeOldMarkersIfPresent(List<MapMarker> markers) { private void removeOldMarkersIfPresent(List<MapMarker> markers) {
if (!markers.isEmpty()) { if (!markers.isEmpty()) {
boolean needRefresh = false; boolean needRefresh = false;
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
@ -473,7 +733,7 @@ public class MapMarkersHelper {
addToMapMarkersList(markers); addToMapMarkersList(markers);
reorderActiveMarkersIfNeeded(); reorderActiveMarkersIfNeeded();
sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC);
app.getItineraryHelper().updateGroups(); updateGroups();
refresh(); refresh();
} }
} }
@ -490,7 +750,7 @@ public class MapMarkersHelper {
} else { } else {
removeFromMapMarkersList(marker); removeFromMapMarkersList(marker);
} }
app.getItineraryHelper().removeMarkerFromGroup(marker); removeMarkerFromGroup(marker);
if (refresh) { if (refresh) {
refresh(); refresh();
} }
@ -587,7 +847,7 @@ public class MapMarkersHelper {
addToMapMarkersHistoryList(mapMarkers); addToMapMarkersHistoryList(mapMarkers);
mapMarkers = new ArrayList<>(); mapMarkers = new ArrayList<>();
sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC);
app.getItineraryHelper().updateGroups(); updateGroups();
refresh(); refresh();
} }
@ -608,18 +868,18 @@ 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) {
if (points.size() > 0) { if (points.size() > 0) {
app.getSettings().SHOW_MAP_MARKERS.set(true); ctx.getSettings().SHOW_MAP_MARKERS.set(true);
int colorIndex = -1; int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>(); List<MapMarker> addedMarkers = new ArrayList<>();
for (int i = 0; i < points.size(); i++) { for (int i = 0; i < points.size(); i++) {
@ -635,7 +895,7 @@ public class MapMarkersHelper {
pointDescription = historyName; pointDescription = historyName;
} }
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) { if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(app)); pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
} }
if (colorIndex == -1) { if (colorIndex == -1) {
if (mapMarkers.size() > 0) { if (mapMarkers.size() > 0) {
@ -649,7 +909,7 @@ public class MapMarkersHelper {
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0); MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
if (group != null) { if (group != null) {
marker.id = group.getId() + marker.getName(app) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15); marker.id = group.getId() + marker.getName(ctx) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15);
if (markersDbHelper.getMarker(marker.id) != null) { if (markersDbHelper.getMarker(marker.id) != null) {
continue; continue;
} }
@ -705,6 +965,14 @@ public class MapMarkersHelper {
} }
} }
public void addSyncListener(OnGroupSyncedListener listener) {
syncListeners.add(listener);
}
public void removeSyncListener(OnGroupSyncedListener listener) {
syncListeners.remove(listener);
}
public void addListener(MapMarkerChangedListener l) { public void addListener(MapMarkerChangedListener l) {
if (!listeners.contains(l)) { if (!listeners.contains(l)) {
listeners.add(l); listeners.add(l);
@ -716,7 +984,7 @@ public class MapMarkersHelper {
} }
private void refreshMarker(final MapMarker marker) { private void refreshMarker(final MapMarker marker) {
app.runInUIThread(new Runnable() { ctx.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
for (MapMarkerChangedListener l : listeners) { for (MapMarkerChangedListener l : listeners) {
@ -727,7 +995,7 @@ public class MapMarkersHelper {
} }
private void refresh() { private void refresh() {
app.runInUIThread(new Runnable() { ctx.runInUIThread(new Runnable() {
@Override @Override
public void run() { public void run() {
for (MapMarkerChangedListener l : listeners) { for (MapMarkerChangedListener l : listeners) {
@ -737,14 +1005,28 @@ public class MapMarkersHelper {
}); });
} }
public List<MapMarker> getMapMarkersFromDefaultGroups(boolean history) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : mapMarkersGroups) {
if (group.getType() == MapMarkersGroup.ANY_TYPE) {
for (MapMarker marker : group.getMarkers()) {
if (history && marker.history || !history && !marker.history) {
mapMarkers.add(marker);
}
}
}
}
return mapMarkers;
}
public String saveMarkersToFile(String fileName) { public String saveMarkersToFile(String fileName) {
GPXFile gpxFile = generateGpx(); GPXFile gpxFile = generateGpx();
String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR; String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR;
File dir = app.getAppPath(dirName); File dir = ctx.getAppPath(dirName);
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdirs(); dir.mkdirs();
} }
String uniqueFileName = FileUtils.createUniqueFileName(app, fileName, dirName, IndexConstants.GPX_FILE_EXT); String uniqueFileName = FileUtils.createUniqueFileName(ctx, fileName, dirName, IndexConstants.GPX_FILE_EXT);
File fout = new File(dir, uniqueFileName + IndexConstants.GPX_FILE_EXT); File fout = new File(dir, uniqueFileName + IndexConstants.GPX_FILE_EXT);
GPXUtilities.writeGpxFile(fout, gpxFile); GPXUtilities.writeGpxFile(fout, gpxFile);
@ -759,13 +1041,13 @@ public class MapMarkersHelper {
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US); SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC")); format.setTimeZone(TimeZone.getTimeZone("UTC"));
GPXFile gpxFile = new GPXFile(Version.getFullVersion(app)); GPXFile gpxFile = new GPXFile(Version.getFullVersion(ctx));
for (MapMarker marker : markers) { for (MapMarker marker : markers) {
WptPt wpt = new WptPt(); WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude(); wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude(); wpt.lon = marker.getLongitude();
wpt.name = marker.getOnlyName(); wpt.name = marker.getOnlyName();
wpt.setColor(ContextCompat.getColor(app, MapMarker.getColorId(marker.colorIndex))); wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex)));
if (completeBackup) { if (completeBackup) {
if (marker.creationDate != 0) { if (marker.creationDate != 0) {
wpt.getExtensionsToWrite().put(CREATION_DATE, format.format(new Date(marker.creationDate))); wpt.getExtensionsToWrite().put(CREATION_DATE, format.format(new Date(marker.creationDate)));
@ -786,7 +1068,7 @@ public class MapMarkersHelper {
List<MapMarker> mapMarkers = new ArrayList<>(); List<MapMarker> mapMarkers = new ArrayList<>();
for (WptPt point : gpxFile.getPoints()) { for (WptPt point : gpxFile.getPoints()) {
LatLon latLon = new LatLon(point.lat, point.lon); LatLon latLon = new LatLon(point.lat, point.lon);
int colorIndex = MapMarker.getColorIndex(app, point.getColor()); int colorIndex = MapMarker.getColorIndex(ctx, point.getColor());
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name); PointDescription name = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name);
MapMarker marker = new MapMarker(latLon, name, colorIndex, false, 0); MapMarker marker = new MapMarker(latLon, name, colorIndex, false, 0);
@ -877,6 +1159,22 @@ public class MapMarkersHelper {
mapMarkersHistory = copyList; mapMarkersHistory = copyList;
} }
// accessors to markers groups:
private void addToGroupsList(MapMarkersGroup group) {
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.add(group);
mapMarkersGroups = copyList;
}
private void removeFromGroupsList(MapMarkersGroup group) {
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
copyList.remove(group);
mapMarkersGroups = copyList;
}
// ---------------------------------------------------------------------------------------------
// classes and interfaces: // classes and interfaces:
public interface MapMarkerChangedListener { public interface MapMarkerChangedListener {
@ -891,4 +1189,93 @@ public class MapMarkersHelper {
void onSyncDone(); void onSyncDone();
} }
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
private MapMarkersGroup group;
SyncGroupTask(MapMarkersGroup group) {
this.group = group;
}
@Override
protected void onPreExecute() {
if (!syncListeners.isEmpty()) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {
listener.onSyncStarted();
}
}
});
}
}
@Override
protected Void doInBackground(Void... voids) {
runGroupSynchronization();
return null;
}
// TODO extract method from Asynctask to Helper directly
private void runGroupSynchronization() {
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) {
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
group.setVisible(favGroup.isVisible());
if (!group.isVisible() || group.isDisabled()) {
removeGroupActiveMarkers(group, true);
return;
}
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
for (FavouritePoint fp : points) {
addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
}
} else if (group.getType() == MapMarkersGroup.GPX_TYPE) {
GpxSelectionHelper gpxHelper = ctx.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()) {
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(""))) {
addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt);
}
}
}
removeOldMarkersIfPresent(groupMarkers);
}
@Override
protected void onPostExecute(Void aVoid) {
if (!syncListeners.isEmpty()) {
ctx.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {
listener.onSyncDone();
}
}
});
}
}
}
} }

View file

@ -20,8 +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 java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
@ -138,18 +136,18 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
private void updateAddOrEnableGroupWptCategories() { private void updateAddOrEnableGroupWptCategories() {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper(); GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
ItineraryHelper helper = app.getItineraryHelper(); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path); SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpxFile.path);
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 = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group == null) { if (group == null) {
group = helper.addOrEnableGroup(gpxFile); group = mapMarkersHelper.addOrEnableGroup(gpxFile);
} }
helper.updateGroupWptCategories(group, selectedCategories); mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
helper.runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
private boolean isAllChecked() { private boolean isAllChecked() {

View file

@ -14,7 +14,7 @@ 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.mapmarkers.MapMarker;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
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;
@ -214,8 +214,8 @@ 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().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey,
ItineraryGroup.ANY_TYPE); MapMarkersGroup.ANY_TYPE);
if (group != null) { if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group); mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
} }

View file

@ -7,8 +7,10 @@ import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -21,12 +23,10 @@ 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.MapMarkersHelper;
import net.osmand.plus.mapmarkers.GroupHeader; import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.itinerary.ItineraryGroup; import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton; 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;
@ -38,6 +38,7 @@ import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment;
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;
import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -56,10 +57,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private static final int SHOW_HIDE_HISTORY_TYPE = 3; private static final int SHOW_HIDE_HISTORY_TYPE = 3;
private static final int CATEGORIES_TYPE = 4; private static final int CATEGORIES_TYPE = 4;
private static final int TODAY_HEADER = 56;
private static final int YESTERDAY_HEADER = 57;
private static final int LAST_SEVEN_DAYS_HEADER = 58;
private static final int THIS_YEAR_HEADER = 59;
private MapActivity mapActivity; private MapActivity mapActivity;
private OsmandApplication app; private OsmandApplication app;
@ -104,55 +101,90 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private void createDisplayGroups() { private void createDisplayGroups() {
items = new ArrayList<>(); items = new ArrayList<>();
ItineraryHelper helper = app.getItineraryHelper(); MapMarkersHelper helper = app.getMapMarkersHelper();
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());
// evaluate time constants
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
long currentTimeMillis = System.currentTimeMillis();
Calendar currentDateCalendar = Calendar.getInstance();
currentDateCalendar.setTimeInMillis(currentTimeMillis);
// evaluate today, yesterday, last 7 days
String today = dateFormat.format(currentDateCalendar.getTime());
currentDateCalendar.add(Calendar.DAY_OF_YEAR, -1);
String yesterday = dateFormat.format(currentDateCalendar.getTime());
currentDateCalendar.set(Calendar.HOUR_OF_DAY, 0);
currentDateCalendar.set(Calendar.MINUTE, 0);
currentDateCalendar.add(Calendar.DAY_OF_YEAR, -6);
long last7Days = currentDateCalendar.getTimeInMillis();
// evaluate this year & last 3 months
currentDateCalendar.setTimeInMillis(currentTimeMillis);
String thisYear = dateFormat.format(currentDateCalendar.getTime()).substring(0, 5);
currentDateCalendar.add(Calendar.MONTH, -1);
String monthMinus1 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
currentDateCalendar.add(Calendar.MONTH, -1);
String monthMinus2 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
currentDateCalendar.add(Calendar.MONTH, -1);
String monthMinus3 = dateFormat.format(currentDateCalendar.getTime()).substring(0, 8);
Calendar markerCalendar = Calendar.getInstance();
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;
} }
String markerGroupName = group.getName(); String markerGroupName = group.getName();
if (markerGroupName == null) {
int previousDateHeader = -1;
int monthsDisplayed = 0;
Calendar currentDateCalendar = Calendar.getInstance(); if (markerGroupName == null) {
currentDateCalendar.setTimeInMillis(System.currentTimeMillis()); int previousGroupDateId = 0;
int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR); int monthsDisplayed = 0;
int currentMonth = currentDateCalendar.get(Calendar.MONTH);
int currentYear = currentDateCalendar.get(Calendar.YEAR);
Calendar markerCalendar = Calendar.getInstance();
List<MapMarker> groupMarkers = group.getActiveMarkers(); List<MapMarker> groupMarkers = group.getActiveMarkers();
for (int j = 0; j < groupMarkers.size(); j++) { for (int j = 0; j < groupMarkers.size(); j++) {
MapMarker marker = groupMarkers.get(j); MapMarker marker = groupMarkers.get(j);
markerCalendar.setTimeInMillis(marker.creationDate); String markerDate = dateFormat.format(new Date(marker.creationDate));
int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR); int currentGroupDateId;
int markerMonth = markerCalendar.get(Calendar.MONTH); MarkerGroupItem currentGroupItem = null ;
int markerYear = markerCalendar.get(Calendar.YEAR); if (marker.creationDate >= currentTimeMillis || (today.equals(markerDate))) {
if (markerYear == currentYear) { currentGroupDateId = -1;
if (markerDay == currentDay && previousDateHeader != TODAY_HEADER) { currentGroupItem = MarkerGroupItem.TODAY_HEADER;
items.add(TODAY_HEADER); } else if (yesterday.equals(markerDate)) {
previousDateHeader = TODAY_HEADER; currentGroupDateId = -2;
} else if (markerDay == currentDay - 1 && previousDateHeader != YESTERDAY_HEADER) { currentGroupItem = MarkerGroupItem.YESTERDAY_HEADER;
items.add(YESTERDAY_HEADER); } else if (marker.creationDate >= last7Days) {
previousDateHeader = YESTERDAY_HEADER; currentGroupDateId = -3;
} else if (currentDay - markerDay >= 2 && currentDay - markerDay <= 8 && previousDateHeader != LAST_SEVEN_DAYS_HEADER) { currentGroupItem = MarkerGroupItem.LAST_SEVEN_DAYS_HEADER;
items.add(LAST_SEVEN_DAYS_HEADER); } else if (markerDate.startsWith(monthMinus1)) {
previousDateHeader = LAST_SEVEN_DAYS_HEADER; currentGroupDateId = -5;
} else if (currentDay - markerDay > 8 && monthsDisplayed < 3 && previousDateHeader != markerMonth) { } else if (markerDate.startsWith(monthMinus2)) {
items.add(markerMonth); currentGroupDateId = -6;
previousDateHeader = markerMonth; } else if (markerDate.startsWith(monthMinus3)) {
monthsDisplayed += 1; currentGroupDateId = -7;
} else if (currentMonth - markerMonth >= 4 && previousDateHeader != markerMonth && previousDateHeader != THIS_YEAR_HEADER) { } else if (markerDate.startsWith(thisYear)) {
items.add(THIS_YEAR_HEADER); currentGroupItem = MarkerGroupItem.THIS_YEAR_HEADER;
previousDateHeader = THIS_YEAR_HEADER; currentGroupDateId = -4;
} else {
markerCalendar.setTimeInMillis(marker.creationDate);
currentGroupDateId = markerCalendar.get(Calendar.YEAR);
}
if (previousGroupDateId != currentGroupDateId) {
if (currentGroupItem != null) {
items.add(currentGroupItem);
} else if(currentGroupDateId < 0) {
SimpleDateFormat monthdateFormat = new SimpleDateFormat("LLLL", Locale.getDefault());
String monthStr = monthdateFormat.format(new Date(marker.creationDate));
if (monthStr.length() > 1) {
monthStr = Algorithms.capitalizeFirstLetter(monthStr);
}
items.add(new MarkerGroupItem(monthStr));
} else {
items.add(new MarkerGroupItem(currentGroupDateId + ""));
} }
} else if (previousDateHeader != markerYear) { previousGroupDateId = currentGroupDateId;
items.add(markerYear);
previousDateHeader = markerYear;
} }
items.add(marker); items.add(marker);
} }
@ -161,7 +193,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
items.add(header); items.add(header);
if (!group.isDisabled()) { if (!group.isDisabled()) {
if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) { if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
CategoriesSubHeader categoriesSubHeader = group.getCategoriesSubHeader(); CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(group);
items.add(categoriesSubHeader); items.add(categoriesSubHeader);
} }
TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper(); TravelHelper travelHelper = mapActivity.getMyApplication().getTravelHelper();
@ -177,7 +209,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} }
} }
if (group.getWptCategories() == null || group.getWptCategories().isEmpty()) { if (group.getWptCategories() == null || group.getWptCategories().isEmpty()) {
app.getItineraryHelper().updateGroupWptCategories(group, getGpxFile(group.getGpxPath()).getPointsByCategories().keySet()); helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath()).getPointsByCategories().keySet());
} }
populateAdapterWithGroupMarkers(group, getItemCount()); populateAdapterWithGroupMarkers(group, getItemCount());
} }
@ -196,7 +228,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 +253,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.getMapMarkersHelper().getMapMarkerGroupById(groupId, MapMarkersGroup.ANY_TYPE);
if (group != null) { if (group != null) {
pos = items.indexOf(group.getGroupHeader()); pos = items.indexOf(group.getGroupHeader());
} }
@ -381,32 +413,19 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder; final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder;
final Object header = getItem(position); final Object header = getItem(position);
String headerString; String headerString;
if (header instanceof Integer) { if (header instanceof MarkerGroupItem) {
headerViewHolder.icon.setVisibility(View.GONE); headerViewHolder.icon.setVisibility(View.GONE);
headerViewHolder.iconSpace.setVisibility(View.VISIBLE); headerViewHolder.iconSpace.setVisibility(View.VISIBLE);
Integer dateHeader = (Integer) header; headerString = ((MarkerGroupItem) header).getName(app);
if (dateHeader == TODAY_HEADER) {
headerString = app.getString(R.string.today);
} else if (dateHeader == YESTERDAY_HEADER) {
headerString = app.getString(R.string.yesterday);
} else if (dateHeader == LAST_SEVEN_DAYS_HEADER) {
headerString = app.getString(R.string.last_seven_days);
} else if (dateHeader == THIS_YEAR_HEADER) {
headerString = app.getString(R.string.this_year);
} else if (dateHeader / 100 == 0) {
headerString = getMonth(dateHeader);
} else {
headerString = String.valueOf(dateHeader);
}
headerViewHolder.disableGroupSwitch.setVisibility(View.GONE); headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
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() == MapMarkersGroup.GPX_TYPE) {
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " "); groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
} }
if (group.isDisabled()) { if (group.isDisabled()) {
@ -463,8 +482,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
fragment.setUsedOnMap(false); fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
} }
app.getItineraryHelper().updateGroupDisabled(group, disabled); mapMarkersHelper.updateGroupDisabled(group, disabled);
if (group.getType() == ItineraryGroup.GPX_TYPE) { if (group.getType() == MapMarkersGroup.GPX_TYPE) {
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);
@ -477,9 +496,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
switchGpxVisibility(gpxFile[0], selectedGpxFile, !disabled); switchGpxVisibility(gpxFile[0], selectedGpxFile, !disabled);
} }
if(!disabled) { if(!disabled) {
app.getItineraryHelper().enableGroup(group); mapMarkersHelper.enableGroup(group);
} else { } else {
app.getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
if (disabled) { if (disabled) {
@ -487,10 +506,10 @@ 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() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], null, true); switchGpxVisibility(gpxFile[0], null, true);
} }
app.getItineraryHelper().enableGroup(group); mapMarkersHelper.enableGroup(group);
} }
}); });
UiUtilities.setupSnackbar(snackbar, night); UiUtilities.setupSnackbar(snackbar, night);
@ -530,7 +549,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) {
@ -544,7 +563,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
fragment.setUsedOnMap(false); fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG); fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
} else { } else {
mapActivity.getMyApplication().getItineraryHelper().addOrEnableGpxGroup(new File(group.getGpxPath())); mapActivity.getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(new File(group.getGpxPath()));
} }
} }
}; };
@ -573,7 +592,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()) {
@ -617,17 +636,46 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
return items.get(position); return items.get(position);
} }
private String getMonth(int month) {
SimpleDateFormat dateFormat = new SimpleDateFormat("LLLL", Locale.getDefault()); public static class MarkerGroupItem {
Date date = new Date();
date.setMonth(month); static final MarkerGroupItem TODAY_HEADER = new MarkerGroupItem(R.string.today);
String monthStr = dateFormat.format(date); static final MarkerGroupItem YESTERDAY_HEADER = new MarkerGroupItem(R.string.yesterday);
if (monthStr.length() > 1) { static final MarkerGroupItem LAST_SEVEN_DAYS_HEADER = new MarkerGroupItem(R.string.last_seven_days);
monthStr = Character.toUpperCase(monthStr.charAt(0)) + monthStr.substring(1); static final MarkerGroupItem THIS_YEAR_HEADER = new MarkerGroupItem(R.string.this_year);
private @StringRes int iname;
protected String name;
public MarkerGroupItem(@StringRes int name) {
this.iname = name;
}
public MarkerGroupItem(String name) {
this.name = name;
}
public String getName(OsmandApplication app) {
if (name == null && iname != 0) {
name = app.getString(iname);
}
return name;
} }
return monthStr;
} }
public class CategoriesSubHeader {
private MapMarkersGroup group;
public CategoriesSubHeader(MapMarkersGroup group) {
this.group = group;
}
public MapMarkersGroup getGroup() {
return group;
}
}
public interface MapMarkersGroupsAdapterListener { public interface MapMarkersGroupsAdapterListener {
void onItemClick(View view); void onItemClick(View view);

View file

@ -8,7 +8,8 @@ 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 net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import java.io.File; import java.io.File;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
@ -64,9 +65,10 @@ public class DeletePointsTask extends AsyncTask<Void, Void, Void> {
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersHelper helper = app.getMapMarkersHelper();
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); helper.runSynchronization(group);
} }
} }

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 = mapMarkersHelper.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,10 +216,10 @@ 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 = mapMarkersHelper.getMarkersGroup(gpxFile);
if (markersGroup == null) { if (markersGroup == null) {
groupCreated = true; groupCreated = true;
markersGroup = app.getItineraryHelper().addOrEnableGroup(gpxFile); markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile);
} }
Set<String> categories = markersGroup.getWptCategories(); Set<String> categories = markersGroup.getWptCategories();
Set<String> selectedCategories = new HashSet<>(); Set<String> selectedCategories = new HashSet<>();
@ -234,9 +234,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
if (Algorithms.isEmpty(selectedCategories)) { if (Algorithms.isEmpty(selectedCategories)) {
mapMarkersHelper.removeMarkersGroup(markersGroup); mapMarkersHelper.removeMarkersGroup(markersGroup);
} else { } else {
app.getItineraryHelper().updateGroupWptCategories(markersGroup, selectedCategories); mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories);
if (!groupCreated) { if (!groupCreated) {
app.getItineraryHelper().runSynchronization(markersGroup); mapMarkersHelper.runSynchronization(markersGroup);
} }
} }
} }
@ -524,9 +524,10 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
private void syncGpx(GPXFile gpxFile) { private void syncGpx(GPXFile gpxFile) {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersHelper markersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
app.getItineraryHelper().runSynchronization(group); markersHelper.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;
@ -399,7 +399,8 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER, true); createMenuItem(menu, SHARE_ID, R.string.shared_string_share, R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_NEVER, true);
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
if (gpxFile != null && gpxFile.path != null) { if (gpxFile != null && gpxFile.path != null) {
final boolean synced = app.getItineraryHelper().getMarkersGroup(getGpx()) != null; final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
final boolean synced = markersHelper.getMarkersGroup(getGpx()) != null;
createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers createMenuItem(menu, SELECT_MAP_MARKERS_ID, synced ? R.string.remove_from_map_markers
: R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag, MenuItem.SHOW_AS_ACTION_NEVER); : R.string.shared_string_add_to_map_markers, R.drawable.ic_action_flag, MenuItem.SHOW_AS_ACTION_NEVER);
} }
@ -500,15 +501,15 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
return; return;
} }
final GPXFile gpxFile = getGpx(); final GPXFile gpxFile = getGpx();
ItineraryGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup markersSearch = markersHelper.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); markersHelper.removeMarkersGroup(markersGr);
markersRemoved = true; markersRemoved = true;
} else if (gpxFile != null) { } else if (gpxFile != null) {
markersGr = app.getItineraryHelper().addOrEnableGroup(gpxFile); markersGr = markersHelper.addOrEnableGroup(gpxFile);
markersRemoved = false; markersRemoved = false;
} else { } else {
markersRemoved = false; markersRemoved = false;
@ -534,10 +535,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
if (trackActivity != null) { if (trackActivity != null) {
if (markersRemoved) { if (markersRemoved) {
if (gpxFile != null) { if (gpxFile != null) {
app.getItineraryHelper().addOrEnableGroup(gpxFile); markersHelper.addOrEnableGroup(gpxFile);
} }
} else { } else {
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile); MapMarkersGroup group = markersHelper.getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
markersHelper.removeMarkersGroup(group); markersHelper.removeMarkersGroup(group);
} }

View file

@ -12,7 +12,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
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.MapMarkersGroup;
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;
@ -46,7 +46,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
protected void init() { protected void init() {
super.init(); super.init();
markersHelper = app.getMapMarkersHelper(); markersHelper = app.getMapMarkersHelper();
existingItems = new ArrayList<>(app.getItineraryHelper().getMapMarkersFromDefaultGroups(true)); existingItems = new ArrayList<>(markersHelper.getMapMarkersFromDefaultGroups(true));
} }
@NonNull @NonNull
@ -122,10 +122,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, MapMarkersGroup.ANY_TYPE);
markersGroup.setMarkers(items); markersGroup.setMarkers(items);
return markersGroup; return markersGroup;
} }

View file

@ -12,7 +12,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
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.MapMarkersGroup;
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;
@ -46,7 +46,7 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
protected void init() { protected void init() {
super.init(); super.init();
markersHelper = app.getMapMarkersHelper(); markersHelper = app.getMapMarkersHelper();
existingItems = new ArrayList<>(app.getItineraryHelper().getMapMarkersFromDefaultGroups(false)); existingItems = new ArrayList<>(markersHelper.getMapMarkersFromDefaultGroups(false));
} }
@NonNull @NonNull
@ -122,10 +122,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, MapMarkersGroup.ANY_TYPE);
markersGroup.setMarkers(items); markersGroup.setMarkers(items);
return markersGroup; return markersGroup;
} }

View file

@ -30,10 +30,11 @@ 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.GpxUiHelper.GPXInfo; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.LocaleHelper;
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.MapMarker; import net.osmand.plus.mapmarkers.MapMarker;
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;
@ -605,19 +606,19 @@ public class SettingsHelper {
myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files); myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
} }
} }
List<MapMarker> mapMarkers = app.getItineraryHelper().getMapMarkersFromDefaultGroups(false); List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(false);
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, MapMarkersGroup.ANY_TYPE);
markersGroup.setMarkers(mapMarkers); markersGroup.setMarkers(mapMarkers);
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup)); myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
} }
List<MapMarker> markersHistory = app.getItineraryHelper().getMapMarkersFromDefaultGroups(true); List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersFromDefaultGroups(true);
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, MapMarkersGroup.ANY_TYPE);
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

@ -41,7 +41,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;
@ -377,8 +377,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

@ -106,7 +106,7 @@ public class FavouritesLayer extends OsmandMapLayer implements IContextMenuProvi
List<LatLon> smallObjectsLatLon = new ArrayList<>(); List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (FavoriteGroup group : favouritesDbHelper.getFavoriteGroups()) { for (FavoriteGroup group : favouritesDbHelper.getFavoriteGroups()) {
List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>(); List<Pair<FavouritePoint, MapMarker>> fullObjects = new ArrayList<>();
boolean synced = view.getApplication().getItineraryHelper().getMarkersGroup(group) != null; boolean synced = mapMarkersHelper.getMarkersGroup(group) != null;
for (FavouritePoint favoritePoint : group.getPoints()) { for (FavouritePoint favoritePoint : group.getPoints()) {
double lat = favoritePoint.getLatitude(); double lat = favoritePoint.getLatitude();
double lon = favoritePoint.getLongitude(); double lon = favoritePoint.getLongitude();

View file

@ -44,10 +44,10 @@ 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;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.render.OsmandRenderer.RenderingContext;
@ -543,7 +543,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
for (SelectedGpxFile g : selectedGPXFiles) { for (SelectedGpxFile g : selectedGPXFiles) {
List<Pair<WptPt, MapMarker>> fullObjects = new ArrayList<>(); List<Pair<WptPt, MapMarker>> fullObjects = new ArrayList<>();
int fileColor = getFileColor(g); int fileColor = getFileColor(g);
boolean synced = view.getApplication().getItineraryHelper().getMarkersGroup(g.getGpxFile()) != null; boolean synced = mapMarkersHelper.getMarkersGroup(g.getGpxFile()) != null;
for (WptPt wpt : getListStarPoints(g)) { for (WptPt wpt : getListStarPoints(g)) {
if (wpt.lat >= latLonBounds.bottom && wpt.lat <= latLonBounds.top if (wpt.lat >= latLonBounds.bottom && wpt.lat <= latLonBounds.top
&& wpt.lon >= latLonBounds.left && wpt.lon <= latLonBounds.right && wpt.lon >= latLonBounds.left && wpt.lon <= latLonBounds.right
@ -1226,9 +1226,9 @@ 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); MapMarkersGroup group = view.getApplication().getMapMarkersHelper().getMarkersGroup(gpxFile);
if (group != null) { if (group != null) {
view.getApplication().getItineraryHelper().runSynchronization(group); mapMarkersHelper.runSynchronization(group);
} }
} }