commit
c51d31bf40
3 changed files with 84 additions and 16 deletions
|
@ -946,6 +946,11 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
protected void runLayoutListener() {
|
protected void runLayoutListener() {
|
||||||
|
runLayoutListener(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
|
protected void runLayoutListener(final Runnable runnable) {
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||||
|
@ -974,6 +979,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
|
||||||
int menuState = getCurrentMenuState();
|
int menuState = getCurrentMenuState();
|
||||||
listener.onContextMenuStateChanged(ContextMenuFragment.this, menuState, menuState);
|
listener.onContextMenuStateChanged(ContextMenuFragment.this, menuState, menuState);
|
||||||
}
|
}
|
||||||
|
if (runnable != null) {
|
||||||
|
runnable.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -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))
|
||||||
|
|
|
@ -270,7 +270,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
setupToolbar();
|
setupToolbar();
|
||||||
updateHeader();
|
updateHeader();
|
||||||
setupButtons(view);
|
setupButtons(view);
|
||||||
runLayoutListener();
|
calculateLayoutAndUpdateMenuState();
|
||||||
}
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -797,7 +797,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) {
|
||||||
|
@ -837,6 +837,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
menuType = type;
|
menuType = type;
|
||||||
setupCards();
|
setupCards();
|
||||||
updateHeader();
|
updateHeader();
|
||||||
|
calculateLayoutAndUpdateMenuState();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -845,6 +846,25 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void calculateLayoutAndUpdateMenuState() {
|
||||||
|
runLayoutListener(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
updateMenuState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMenuState() {
|
||||||
|
if (menuType == TrackMenuType.OPTIONS) {
|
||||||
|
openMenuFullScreen();
|
||||||
|
} else if (menuType == TrackMenuType.OVERVIEW) {
|
||||||
|
openMenuHeaderOnly();
|
||||||
|
} else {
|
||||||
|
openMenuHalfScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateContent() {
|
public void updateContent() {
|
||||||
if (segmentsCard != null) {
|
if (segmentsCard != null) {
|
||||||
|
|
Loading…
Reference in a new issue