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)
|
||||
protected void runLayoutListener() {
|
||||
runLayoutListener(null);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
protected void runLayoutListener(final Runnable runnable) {
|
||||
if (view != null) {
|
||||
ViewTreeObserver vto = view.getViewTreeObserver();
|
||||
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
|
@ -974,6 +979,9 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment
|
|||
int menuState = getCurrentMenuState();
|
||||
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.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<String> 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<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() {
|
||||
return new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_copy))
|
||||
|
|
|
@ -270,7 +270,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
setupToolbar();
|
||||
updateHeader();
|
||||
setupButtons(view);
|
||||
runLayoutListener();
|
||||
calculateLayoutAndUpdateMenuState();
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
@ -797,7 +797,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
|
||||
@Override
|
||||
protected void onHeaderClick() {
|
||||
adjustMapPosition(getViewY());
|
||||
updateMenuState();
|
||||
}
|
||||
|
||||
private void adjustMapPosition(int y) {
|
||||
|
@ -837,6 +837,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
menuType = type;
|
||||
setupCards();
|
||||
updateHeader();
|
||||
calculateLayoutAndUpdateMenuState();
|
||||
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
|
||||
public void updateContent() {
|
||||
if (segmentsCard != null) {
|
||||
|
|
Loading…
Reference in a new issue