Sync itinerary groups initial commit

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,7 +18,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginsFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.itinerary.ItineraryGroup;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants;
@ -219,7 +219,7 @@ public class IntentHelper {
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
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);
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -40,7 +40,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper;
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.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -376,8 +376,8 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
item.setTitle(globalSettingsItem.getPublicName(app));
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
} else if (object instanceof ItineraryGroup) {
ItineraryGroup markersGroup = (ItineraryGroup) object;
} else if (object instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
item.setTitle(getString(R.string.map_markers));
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.helpers.AndroidUiHelper;
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.ExportSettingsType;
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
@ -311,8 +311,8 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter {
itemsSize += ((FileSettingsItem) object).getSize();
} else if (object instanceof File) {
itemsSize += ((File) object).length();
} else if (object instanceof ItineraryGroup) {
int selectedMarkers = ((ItineraryGroup) object).getMarkers().size();
} else if (object instanceof MapMarkersGroup) {
int selectedMarkers = ((MapMarkersGroup) object).getMarkers().size();
String itemsDescr = app.getString(R.string.shared_string_items);
return app.getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers);
}

View file

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