diff --git a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java index 19c398685c..fa7bff99ed 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/EditTrackGroupDialogFragment.java @@ -30,6 +30,7 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.FavouritePoint; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; @@ -70,19 +71,32 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment public static final String TAG = EditTrackGroupDialogFragment.class.getSimpleName(); private OsmandApplication app; + private GpxSelectionHelper selectedGpxHelper; + private MapMarkersHelper mapMarkersHelper; private GpxDisplayGroup group; @Override public void createMenuItems(Bundle savedInstanceState) { - app = requiredMyApplication(); if (group == null) { return; } + app = requiredMyApplication(); + selectedGpxHelper = app.getSelectedGpxHelper(); + mapMarkersHelper = app.getMapMarkersHelper(); items.add(new TitleItem(getCategoryName(app, group.getName()))); + GPXFile gpxFile = group.getGpx(); + + boolean currentTrack = group.getGpx().showCurrentTrack; + + SelectedGpxFile selectedGpxFile; + if (currentTrack) { + selectedGpxFile = selectedGpxHelper.getSelectedCurrentRecordingTrack(); + } else { + selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); + } boolean trackPoints = group.getType() == GpxDisplayItemType.TRACK_POINTS; - SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getGpx().path); if (trackPoints && selectedGpxFile != null) { items.add(createShowOnMapItem(selectedGpxFile)); } @@ -92,7 +106,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment } items.add(new OptionsDividerItem(app)); -// items.add(createCopyToMarkersItem()); + if (!currentTrack) { + items.add(createCopyToMarkersItem(gpxFile)); + } items.add(createCopyToFavoritesItem()); items.add(new OptionsDividerItem(app)); @@ -175,27 +191,51 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment .create(); } - private BaseBottomSheetItem createCopyToMarkersItem() { + private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) { + final MapMarkersGroup markersGroup = getOrCreateMarkersGroup(gpxFile); + final Set categories = markersGroup.getWptCategories(); + final boolean synced = categories != null && categories.contains(group.getName()); + return new SimpleBottomSheetItem.Builder() - .setIcon(getContentIcon(R.drawable.ic_action_copy)) - .setTitle(getString(R.string.copy_to_map_markers)) - .setLayoutId(R.layout.bottom_sheet_item_simple) + .setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy)) + .setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.copy_to_map_markers)) .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { -// MapMarkersHelper markersHelper = app.getMapMarkersHelper(); -// MapMarkersGroup markersGroup = markersHelper.getMarkersGroup(group); -// if (markersGroup != null) { -// markersHelper.removeMarkersGroup(markersGroup); -// } else { -// markersHelper.addOrEnableGroup(group); -// } + updateGroupWptCategory(gpxFile, markersGroup, categories, synced); + dismiss(); } }) .create(); } + private void updateGroupWptCategory(GPXFile gpxFile, MapMarkersGroup markersGroup, Set categories, boolean synced) { + SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path); + if (selectedGpxFile == null) { + selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false); + } + Set selectedCategories = new HashSet<>(); + if (categories != null) { + selectedCategories.addAll(categories); + } + if (synced) { + selectedCategories.remove(group.getName()); + } else { + selectedCategories.add(group.getName()); + } + mapMarkersHelper.updateGroupWptCategories(markersGroup, selectedCategories); + mapMarkersHelper.runSynchronization(markersGroup); + } + + private MapMarkersGroup getOrCreateMarkersGroup(GPXFile gpxFile) { + MapMarkersGroup markersGroup = mapMarkersHelper.getMarkersGroup(gpxFile); + if (markersGroup == null) { + markersGroup = mapMarkersHelper.addOrEnableGroup(gpxFile); + } + return markersGroup; + } + private BaseBottomSheetItem createCopyToFavoritesItem() { return new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_copy)) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6c9857e11e..dd2ca7f465 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -808,7 +808,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override protected void onHeaderClick() { - adjustMapPosition(getViewY()); + updateMenuState(); } private void adjustMapPosition(int y) { @@ -848,7 +848,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card menuType = type; setupCards(); updateHeader(); - updateMenuState(); + runLayoutListener(new Runnable() { + @Override + public void run() { + updateMenuState(); + } + }); break; } } @@ -857,21 +862,14 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card }); } - private void updateMenuState() { - runLayoutListener(new Runnable() { - - @Override - public void run() { - if (menuType == TrackMenuType.OPTIONS) { - openMenuFullScreen(); - } else if (menuType == TrackMenuType.OVERVIEW) { - openMenuHeaderOnly(); - } else { - openMenuHalfScreen(); - } - } - }); + if (menuType == TrackMenuType.OPTIONS) { + openMenuFullScreen(); + } else if (menuType == TrackMenuType.OVERVIEW) { + openMenuHeaderOnly(); + } else { + openMenuHalfScreen(); + } } @Override