Add group to markers in gpx menu

This commit is contained in:
Vitaliy 2021-01-28 09:38:00 +02:00
parent a97b7c84e7
commit cc7ec8e0d9
2 changed files with 68 additions and 30 deletions

View file

@ -30,6 +30,7 @@ import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
@ -70,19 +71,32 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
public static final String TAG = EditTrackGroupDialogFragment.class.getSimpleName(); public static final String TAG = EditTrackGroupDialogFragment.class.getSimpleName();
private OsmandApplication app; private OsmandApplication app;
private GpxSelectionHelper selectedGpxHelper;
private MapMarkersHelper mapMarkersHelper;
private GpxDisplayGroup group; private GpxDisplayGroup group;
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
if (group == null) { if (group == null) {
return; return;
} }
app = requiredMyApplication();
selectedGpxHelper = app.getSelectedGpxHelper();
mapMarkersHelper = app.getMapMarkersHelper();
items.add(new TitleItem(getCategoryName(app, group.getName()))); 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; boolean trackPoints = group.getType() == GpxDisplayItemType.TRACK_POINTS;
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getGpx().path);
if (trackPoints && selectedGpxFile != null) { if (trackPoints && selectedGpxFile != null) {
items.add(createShowOnMapItem(selectedGpxFile)); items.add(createShowOnMapItem(selectedGpxFile));
} }
@ -92,7 +106,9 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
} }
items.add(new OptionsDividerItem(app)); items.add(new OptionsDividerItem(app));
// items.add(createCopyToMarkersItem()); if (!currentTrack) {
items.add(createCopyToMarkersItem(gpxFile));
}
items.add(createCopyToFavoritesItem()); items.add(createCopyToFavoritesItem());
items.add(new OptionsDividerItem(app)); items.add(new OptionsDividerItem(app));
@ -175,27 +191,51 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
.create(); .create();
} }
private BaseBottomSheetItem createCopyToMarkersItem() { private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) {
final MapMarkersGroup markersGroup = getOrCreateMarkersGroup(gpxFile);
final Set<String> categories = markersGroup.getWptCategories();
final boolean synced = categories != null && categories.contains(group.getName());
return new SimpleBottomSheetItem.Builder() return new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_copy)) .setIcon(getContentIcon(synced ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_copy))
.setTitle(getString(R.string.copy_to_map_markers)) .setTitle(getString(synced ? R.string.remove_from_map_markers : R.string.copy_to_map_markers))
.setLayoutId(R.layout.bottom_sheet_item_simple)
.setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp) .setLayoutId(R.layout.bottom_sheet_item_simple_pad_32dp)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// MapMarkersHelper markersHelper = app.getMapMarkersHelper(); updateGroupWptCategory(gpxFile, markersGroup, categories, synced);
// MapMarkersGroup markersGroup = markersHelper.getMarkersGroup(group); dismiss();
// if (markersGroup != null) {
// markersHelper.removeMarkersGroup(markersGroup);
// } else {
// markersHelper.addOrEnableGroup(group);
// }
} }
}) })
.create(); .create();
} }
private void updateGroupWptCategory(GPXFile gpxFile, MapMarkersGroup markersGroup, Set<String> categories, boolean synced) {
SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath(gpxFile.path);
if (selectedGpxFile == null) {
selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false);
}
Set<String> 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() { private BaseBottomSheetItem createCopyToFavoritesItem() {
return new SimpleBottomSheetItem.Builder() return new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_copy)) .setIcon(getContentIcon(R.drawable.ic_action_copy))

View file

@ -808,7 +808,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
@Override @Override
protected void onHeaderClick() { protected void onHeaderClick() {
adjustMapPosition(getViewY()); updateMenuState();
} }
private void adjustMapPosition(int y) { private void adjustMapPosition(int y) {
@ -848,7 +848,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
menuType = type; menuType = type;
setupCards(); setupCards();
updateHeader(); updateHeader();
updateMenuState(); runLayoutListener(new Runnable() {
@Override
public void run() {
updateMenuState();
}
});
break; break;
} }
} }
@ -857,21 +862,14 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
}); });
} }
private void updateMenuState() { private void updateMenuState() {
runLayoutListener(new Runnable() { if (menuType == TrackMenuType.OPTIONS) {
openMenuFullScreen();
@Override } else if (menuType == TrackMenuType.OVERVIEW) {
public void run() { openMenuHeaderOnly();
if (menuType == TrackMenuType.OPTIONS) { } else {
openMenuFullScreen(); openMenuHalfScreen();
} else if (menuType == TrackMenuType.OVERVIEW) { }
openMenuHeaderOnly();
} else {
openMenuHalfScreen();
}
}
});
} }
@Override @Override