Merge remote-tracking branch 'origin/r3.9'

This commit is contained in:
Victor Shcherb 2021-02-19 16:44:00 +02:00
commit 837452a568
2 changed files with 92 additions and 38 deletions

View file

@ -52,7 +52,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin);
int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding); int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding);
final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); // final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD);
final View buttonSave = createItem(inflater, ItemType.STOP_AND_SAVE); final View buttonSave = createItem(inflater, ItemType.STOP_AND_SAVE);
final View buttonCancel = createItem(inflater, ItemType.CANCEL); final View buttonCancel = createItem(inflater, ItemType.CANCEL);
@ -66,7 +66,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
items.add(new DividerSpaceItem(app, verticalBig)); items.add(new DividerSpaceItem(app, verticalBig));
items.add(new BaseBottomSheetItem.Builder() /*items.add(new BaseBottomSheetItem.Builder()
.setCustomView(buttonDiscard) .setCustomView(buttonDiscard)
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -82,7 +82,7 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm
}) })
.create()); .create());
items.add(new DividerSpaceItem(app, verticalBig)); items.add(new DividerSpaceItem(app, verticalBig));*/
items.add(new BaseBottomSheetItem.Builder() items.add(new BaseBottomSheetItem.Builder()
.setCustomView(buttonSave) .setCustomView(buttonSave)

View file

@ -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,7 +329,14 @@ 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) {
initContent(view);
}
}
return view;
}
private void initContent(@NonNull View view) {
setupCards(); setupCards();
setupToolbar(); setupToolbar();
updateHeader(); updateHeader();
@ -312,8 +348,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
calculateLayoutAndUpdateMenuState(); calculateLayoutAndUpdateMenuState();
} }
} }
return view;
}
private void setHeaderTitle(String text, boolean iconVisibility) { private void setHeaderTitle(String text, boolean iconVisibility) {
headerTitle.setText(text); headerTitle.setText(text);
@ -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,8 +601,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
} }
updateControlsVisibility(false); updateControlsVisibility(false);
stopLocationUpdate(); stopLocationUpdate();
if (overviewCard != null) {
overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks(); overviewCard.getBlockStatisticsBuilder().stopUpdatingStatBlocks();
} }
}
@Override @Override
public void updateLocation(Location location) { public void updateLocation(Location location) {
@ -603,8 +638,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
private void updateDistanceDirection() { private void updateDistanceDirection() {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null && overviewCard != null && overviewCard.getView() != null) {
View view = overviewCard.getView(); View view = overviewCard.getView();
if (mapActivity != null && view != null) {
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) {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && mapActivity.getMapView() != null) {
GPXFile gpxFile = getGpx(); GPXFile gpxFile = getGpx();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && mapActivity.getMapView() != null && gpxFile != null) {
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 {