commit
4ba7191fc1
1 changed files with 89 additions and 35 deletions
|
@ -83,6 +83,7 @@ import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
||||||
import net.osmand.plus.routing.RouteProvider;
|
import net.osmand.plus.routing.RouteProvider;
|
||||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||||
|
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
|
||||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||||
import net.osmand.plus.widgets.IconPopupMenu;
|
import net.osmand.plus.widgets.IconPopupMenu;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -94,6 +95,8 @@ import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.plus.activities.MapActivityActions.KEY_LATITUDE;
|
||||||
|
import static net.osmand.plus.activities.MapActivityActions.KEY_LONGITUDE;
|
||||||
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
|
import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING;
|
||||||
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
|
import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME;
|
||||||
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected;
|
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected;
|
||||||
|
@ -115,7 +118,7 @@ import static net.osmand.plus.track.TrackPointsCard.OPEN_WAYPOINT_INDEX;
|
||||||
|
|
||||||
public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener,
|
public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener,
|
||||||
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
|
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
|
||||||
OsmAndLocationListener, OsmAndCompassListener, TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
|
OsmAndLocationListener, OsmAndCompassListener, OnSegmentSelectedListener {
|
||||||
|
|
||||||
public static final String OPEN_TRACK_MENU = "open_track_menu";
|
public static final String OPEN_TRACK_MENU = "open_track_menu";
|
||||||
public static final String RETURN_SCREEN_NAME = "return_screen_name";
|
public static final String RETURN_SCREEN_NAME = "return_screen_name";
|
||||||
|
@ -226,18 +229,32 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
app = requireMyApplication();
|
app = requireMyApplication();
|
||||||
displayHelper = new TrackDisplayHelper(app);
|
displayHelper = new TrackDisplayHelper(app);
|
||||||
updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
|
updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache();
|
||||||
|
|
||||||
if (!selectedGpxFile.isShowCurrentTrack()) {
|
|
||||||
File file = new File(selectedGpxFile.getGpxFile().path);
|
|
||||||
displayHelper.setFile(file);
|
|
||||||
displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
|
|
||||||
}
|
|
||||||
displayHelper.setGpx(selectedGpxFile.getGpxFile());
|
|
||||||
String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
|
|
||||||
gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName)
|
|
||||||
: app.getResources().getString(R.string.shared_string_currently_recording_track);
|
|
||||||
toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
|
toolbarHeightPx = getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
|
||||||
|
|
||||||
|
if (selectedGpxFile == null && savedInstanceState != null) {
|
||||||
|
String path = savedInstanceState.getString(TRACK_FILE_NAME);
|
||||||
|
boolean showCurrentTrack = savedInstanceState.getBoolean(CURRENT_RECORDING);
|
||||||
|
MapActivity mapActivity = requireMapActivity();
|
||||||
|
loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject<SelectedGpxFile>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(SelectedGpxFile result) {
|
||||||
|
selectedGpxFile = result;
|
||||||
|
setupDisplayHelper();
|
||||||
|
if (getView() != null) {
|
||||||
|
initContent(getView());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (savedInstanceState.containsKey(KEY_LATITUDE) && savedInstanceState.containsKey(KEY_LONGITUDE)) {
|
||||||
|
double latitude = savedInstanceState.getDouble(KEY_LATITUDE);
|
||||||
|
double longitude = savedInstanceState.getDouble(KEY_LONGITUDE);
|
||||||
|
latLon = new LatLon(latitude, longitude);
|
||||||
|
}
|
||||||
|
} else if (selectedGpxFile != null) {
|
||||||
|
setupDisplayHelper();
|
||||||
|
}
|
||||||
|
|
||||||
FragmentActivity activity = requireMyActivity();
|
FragmentActivity activity = requireMyActivity();
|
||||||
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
|
||||||
public void handleOnBackPressed() {
|
public void handleOnBackPressed() {
|
||||||
|
@ -261,6 +278,18 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setupDisplayHelper() {
|
||||||
|
if (!selectedGpxFile.isShowCurrentTrack()) {
|
||||||
|
File file = new File(selectedGpxFile.getGpxFile().path);
|
||||||
|
displayHelper.setFile(file);
|
||||||
|
displayHelper.setGpxDataItem(app.getGpxDbHelper().getItem(file));
|
||||||
|
}
|
||||||
|
displayHelper.setGpx(selectedGpxFile.getGpxFile());
|
||||||
|
String fileName = Algorithms.getFileWithoutDirs(getGpx().path);
|
||||||
|
gpxTitle = !isCurrentRecordingTrack() ? GpxUiHelper.getGpxTitle(fileName)
|
||||||
|
: app.getResources().getString(R.string.shared_string_currently_recording_track);
|
||||||
|
}
|
||||||
|
|
||||||
public GPXFile getGpx() {
|
public GPXFile getGpx() {
|
||||||
return displayHelper.getGpx();
|
return displayHelper.getGpx();
|
||||||
}
|
}
|
||||||
|
@ -300,21 +329,26 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
params.gravity = Gravity.BOTTOM | Gravity.START;
|
params.gravity = Gravity.BOTTOM | Gravity.START;
|
||||||
bottomNav.setLayoutParams(params);
|
bottomNav.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
|
if (selectedGpxFile != null) {
|
||||||
setupCards();
|
initContent(view);
|
||||||
setupToolbar();
|
|
||||||
updateHeader();
|
|
||||||
setupButtons(view);
|
|
||||||
updateCardsLayout();
|
|
||||||
if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
|
|
||||||
calculateLayoutAndShowHeader();
|
|
||||||
} else {
|
|
||||||
calculateLayoutAndUpdateMenuState();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initContent(@NonNull View view) {
|
||||||
|
setupCards();
|
||||||
|
setupToolbar();
|
||||||
|
updateHeader();
|
||||||
|
setupButtons(view);
|
||||||
|
updateCardsLayout();
|
||||||
|
if (menuType == TrackMenuType.OVERVIEW && isPortrait()) {
|
||||||
|
calculateLayoutAndShowHeader();
|
||||||
|
} else {
|
||||||
|
calculateLayoutAndUpdateMenuState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setHeaderTitle(String text, boolean iconVisibility) {
|
private void setHeaderTitle(String text, boolean iconVisibility) {
|
||||||
headerTitle.setText(text);
|
headerTitle.setText(text);
|
||||||
AndroidUiHelper.updateVisibility(headerIcon, iconVisibility);
|
AndroidUiHelper.updateVisibility(headerIcon, iconVisibility);
|
||||||
|
@ -553,9 +587,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
}
|
}
|
||||||
updateControlsVisibility(true);
|
updateControlsVisibility(true);
|
||||||
startLocationUpdate();
|
startLocationUpdate();
|
||||||
GpxBlockStatisticsBuilder blockStats = overviewCard.getBlockStatisticsBuilder();
|
if (overviewCard != null && menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack()) {
|
||||||
if (menuType == TrackMenuType.OVERVIEW && isCurrentRecordingTrack()) {
|
overviewCard.getBlockStatisticsBuilder().runUpdatingStatBlocksIfNeeded();
|
||||||
blockStats.runUpdatingStatBlocksIfNeeded();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,7 +601,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
}
|
}
|
||||||
updateControlsVisibility(false);
|
updateControlsVisibility(false);
|
||||||
stopLocationUpdate();
|
stopLocationUpdate();
|
||||||
overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
|
if (overviewCard != null) {
|
||||||
|
overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -603,8 +638,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
|
|
||||||
private void updateDistanceDirection() {
|
private void updateDistanceDirection() {
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
View view = overviewCard.getView();
|
if (mapActivity != null && overviewCard != null && overviewCard.getView() != null) {
|
||||||
if (mapActivity != null && view != null) {
|
View view = overviewCard.getView();
|
||||||
TextView distanceText = view.findViewById(R.id.distance);
|
TextView distanceText = view.findViewById(R.id.distance);
|
||||||
ImageView direction = view.findViewById(R.id.direction);
|
ImageView direction = view.findViewById(R.id.direction);
|
||||||
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
|
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
|
||||||
|
@ -677,6 +712,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
outState.putString(TRACK_FILE_NAME, getGpx().path);
|
outState.putString(TRACK_FILE_NAME, getGpx().path);
|
||||||
outState.putBoolean(CURRENT_RECORDING, selectedGpxFile.isShowCurrentTrack());
|
outState.putBoolean(CURRENT_RECORDING, selectedGpxFile.isShowCurrentTrack());
|
||||||
|
if (latLon != null) {
|
||||||
|
outState.putDouble(KEY_LATITUDE, latLon.getLatitude());
|
||||||
|
outState.putDouble(KEY_LONGITUDE, latLon.getLongitude());
|
||||||
|
}
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,7 +802,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
segment = segments.get(0);
|
segment = segments.get(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT};
|
GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT};
|
||||||
List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
|
List<GpxDisplayItem> items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes));
|
||||||
if (segment != null && !Algorithms.isEmpty(items)) {
|
if (segment != null && !Algorithms.isEmpty(items)) {
|
||||||
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
|
SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment);
|
||||||
|
@ -888,9 +927,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
}
|
}
|
||||||
|
|
||||||
private void adjustMapPosition(int y) {
|
private void adjustMapPosition(int y) {
|
||||||
|
GPXFile gpxFile = getGpx();
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null && mapActivity.getMapView() != null) {
|
if (mapActivity != null && mapActivity.getMapView() != null && gpxFile != null) {
|
||||||
GPXFile gpxFile = getGpx();
|
|
||||||
QuadRect r = gpxFile.getRect();
|
QuadRect r = gpxFile.getRect();
|
||||||
|
|
||||||
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
||||||
|
@ -1148,7 +1187,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
@Override
|
@Override
|
||||||
public void gpxSavingFinished(Exception errorMessage) {
|
public void gpxSavingFinished(Exception errorMessage) {
|
||||||
if (selectedGpxFile != null) {
|
if (selectedGpxFile != null) {
|
||||||
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT});
|
List<GpxDisplayGroup> groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT});
|
||||||
selectedGpxFile.setDisplayGroups(groups, app);
|
selectedGpxFile.setDisplayGroups(groups, app);
|
||||||
selectedGpxFile.processPoints(app);
|
selectedGpxFile.processPoints(app);
|
||||||
}
|
}
|
||||||
|
@ -1204,8 +1243,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull MapActivity mapActivity, @Nullable String path,
|
private static void loadSelectedGpxFile(@NonNull MapActivity mapActivity, @Nullable String path,
|
||||||
boolean showCurrentTrack, @Nullable final LatLon latLon, @Nullable final String returnScreenName) {
|
boolean showCurrentTrack, final CallbackWithObject<SelectedGpxFile> callback) {
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
SelectedGpxFile selectedGpxFile;
|
SelectedGpxFile selectedGpxFile;
|
||||||
if (showCurrentTrack) {
|
if (showCurrentTrack) {
|
||||||
|
@ -1214,7 +1253,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
|
selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(path);
|
||||||
}
|
}
|
||||||
if (selectedGpxFile != null) {
|
if (selectedGpxFile != null) {
|
||||||
showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
|
callback.processResult(selectedGpxFile);
|
||||||
} else if (!Algorithms.isEmpty(path)) {
|
} else if (!Algorithms.isEmpty(path)) {
|
||||||
String title = app.getString(R.string.loading_smth, "");
|
String title = app.getString(R.string.loading_smth, "");
|
||||||
final ProgressDialog progress = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data));
|
final ProgressDialog progress = ProgressDialog.show(mapActivity, title, app.getString(R.string.loading_data));
|
||||||
|
@ -1228,7 +1267,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
OsmandApplication app = mapActivity.getMyApplication();
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
|
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().selectGpxFile(result, true, false);
|
||||||
if (selectedGpxFile != null) {
|
if (selectedGpxFile != null) {
|
||||||
showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
|
callback.processResult(selectedGpxFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
|
if (progress != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
|
||||||
|
@ -1241,6 +1280,21 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull MapActivity mapActivity, @Nullable String path,
|
||||||
|
boolean showCurrentTrack, @Nullable final LatLon latLon, @Nullable final String returnScreenName) {
|
||||||
|
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||||
|
loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject<SelectedGpxFile>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(SelectedGpxFile selectedGpxFile) {
|
||||||
|
MapActivity mapActivity = mapActivityRef.get();
|
||||||
|
if (mapActivity != null && selectedGpxFile != null) {
|
||||||
|
showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile,
|
public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile,
|
||||||
@Nullable LatLon latLon, @Nullable String returnScreenName) {
|
@Nullable LatLon latLon, @Nullable String returnScreenName) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue