From 94c58edb7c0206b400a6773854cbde24a272670e Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Mar 2021 14:57:55 +0200 Subject: [PATCH 1/4] redesign trip recording dialog; add options dialog; --- .../layout/bottom_sheet_button_with_icon.xml | 8 +- .../layout/trip_recording_active_fragment.xml | 172 ------- OsmAnd/res/layout/trip_recording_fragment.xml | 91 ++++ OsmAnd/res/values/strings.xml | 2 + .../osmand/plus/activities/MapActivity.java | 6 +- .../plus/activities/MapActivityActions.java | 8 +- .../liveupdates/LiveUpdatesFragmentNew.java | 6 +- .../monitoring/OsmandMonitoringPlugin.java | 54 ++- ....java => TripRecordingBottomFragment.java} | 442 +++++++----------- ...TripRecordingClearDataBottomFragment.java} | 33 +- ...> TripRecordingDiscardBottomFragment.java} | 81 +--- .../TripRecordingOptionsBottomFragment.java | 350 ++++++++++++++ ... TripRecordingStartingBottomFragment.java} | 28 +- .../BooleanPreferenceBottomSheet.java | 4 +- .../fragments/BaseSettingsFragment.java | 8 +- .../plus/track/TrackAppearanceFragment.java | 14 +- 16 files changed, 728 insertions(+), 579 deletions(-) delete mode 100644 OsmAnd/res/layout/trip_recording_active_fragment.xml create mode 100644 OsmAnd/res/layout/trip_recording_fragment.xml rename OsmAnd/src/net/osmand/plus/monitoring/{TripRecordingActiveBottomSheet.java => TripRecordingBottomFragment.java} (65%) rename OsmAnd/src/net/osmand/plus/monitoring/{ClearRecordedDataBottomSheetFragment.java => TripRecordingClearDataBottomFragment.java} (71%) rename OsmAnd/src/net/osmand/plus/monitoring/{StopTrackRecordingBottomFragment.java => TripRecordingDiscardBottomFragment.java} (50%) create mode 100644 OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java rename OsmAnd/src/net/osmand/plus/monitoring/{TripRecordingStartingBottomSheet.java => TripRecordingStartingBottomFragment.java} (88%) diff --git a/OsmAnd/res/layout/bottom_sheet_button_with_icon.xml b/OsmAnd/res/layout/bottom_sheet_button_with_icon.xml index 7c56093fbc..8dd296f01b 100644 --- a/OsmAnd/res/layout/bottom_sheet_button_with_icon.xml +++ b/OsmAnd/res/layout/bottom_sheet_button_with_icon.xml @@ -3,14 +3,13 @@ xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + tools:background="@drawable/btn_background_inactive_dark"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OsmAnd/res/layout/trip_recording_fragment.xml b/OsmAnd/res/layout/trip_recording_fragment.xml new file mode 100644 index 0000000000..68e449cdf3 --- /dev/null +++ b/OsmAnd/res/layout/trip_recording_fragment.xml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 93cfd93231..21bb56470e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,8 @@ Thx - Hardy --> + All unsaved data will be lost. + Save and continue Logging interval set time period in which OsmAnd will ask for the current location position data. Please select another type of colorization. The track does not contain speed data. diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 487f4d902f..58e46db8ac 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -104,7 +104,7 @@ import net.osmand.plus.measurementtool.LoginBottomSheetFragment; import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.SnapTrackWarningFragment; -import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingStartingBottomFragment; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.resources.ResourceManager; import net.osmand.plus.routepreparationmenu.ChooseRouteFragment; @@ -2241,8 +2241,8 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(MeasurementToolFragment.TAG); } - public TripRecordingStartingBottomSheet getTripRecordingBottomSheet() { - return getFragment(TripRecordingStartingBottomSheet.TAG); + public TripRecordingStartingBottomFragment getTripRecordingBottomSheet() { + return getFragment(TripRecordingStartingBottomFragment.TAG); } public ChooseRouteFragment getChooseRouteFragment() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index ff78335e74..c51ed68f32 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -62,8 +62,8 @@ import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet; -import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingBottomFragment; +import net.osmand.plus.monitoring.TripRecordingStartingBottomFragment; import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.ProfileDataUtils; @@ -854,9 +854,9 @@ public class MapActivityActions implements DialogProvider { app.logEvent("trip_recording_open"); MapActivity.clearPrevActivityIntent(); if (monitoringPlugin.hasDataToSave() || monitoringPlugin.wasTrackMonitored()) { - TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), monitoringPlugin.getCurrentTrack()); + TripRecordingBottomFragment.showInstance(mapActivity.getSupportFragmentManager(), monitoringPlugin.getCurrentTrack()); } else { - TripRecordingStartingBottomSheet.showInstance(mapActivity.getSupportFragmentManager()); + TripRecordingStartingBottomFragment.showInstance(mapActivity.getSupportFragmentManager()); } return true; } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragmentNew.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragmentNew.java index 756f6a3551..4eb764da2d 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragmentNew.java @@ -85,9 +85,9 @@ import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceUpdateFreq import static net.osmand.plus.liveupdates.LiveUpdatesHelper.runLiveUpdate; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.setAlarmForPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesSettingsDialogFragmentNew.getTertiaryTextColorId; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.getActiveTextColorId; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.getOsmandIconColorId; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.getSecondaryIconColorId; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.getActiveTextColorId; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.getOsmandIconColorId; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.getSecondaryIconColorId; public class LiveUpdatesFragmentNew extends BaseOsmAndDialogFragment implements OnLiveUpdatesForLocalChange { diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index 4fa978a8d6..de95978f7d 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -41,13 +41,16 @@ import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType; +import net.osmand.plus.track.TrackMenuFragment; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; import net.osmand.util.Algorithms; +import java.io.File; import java.lang.ref.WeakReference; +import java.util.Collections; import java.util.List; import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT; @@ -329,9 +332,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { public void controlDialog(final Activity activity, final boolean showTrackSelection) { FragmentManager fragmentManager = ((FragmentActivity) activity).getSupportFragmentManager(); if (hasDataToSave() || wasTrackMonitored()) { - TripRecordingActiveBottomSheet.showInstance(fragmentManager, getCurrentTrack()); + TripRecordingBottomFragment.showInstance(fragmentManager, getCurrentTrack()); } else { - TripRecordingStartingBottomSheet.showInstance(fragmentManager); + TripRecordingStartingBottomFragment.showInstance(fragmentManager); } /*final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); @@ -436,16 +439,22 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { } public void saveCurrentTrack() { - saveCurrentTrack(null, null); + saveCurrentTrack(null, null, true, false); } public void saveCurrentTrack(@Nullable final Runnable onComplete) { - saveCurrentTrack(onComplete, null); + saveCurrentTrack(onComplete, null, true, false); } public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable Activity activity) { - stopRecording(); + saveCurrentTrack(onComplete, activity, true, false); + } + public void saveCurrentTrack(@Nullable final Runnable onComplete, @Nullable Activity activity, + final boolean stopRecording, final boolean openTrack) { + if (stopRecording) { + stopRecording(); + } final WeakReference activityRef = activity != null ? new WeakReference<>(activity) : null; app.getTaskManager().runInBackground(new OsmAndTaskRunnable() { @@ -461,7 +470,9 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { try { SavingTrackHelper helper = app.getSavingTrackHelper(); SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir()); - helper.close(); + if (stopRecording) { + helper.close(); + } return result; } catch (Exception e) { e.printStackTrace(); @@ -474,10 +485,31 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { isSaving = false; app.getNotificationHelper().refreshNotifications(); updateControl(); - if (activityRef != null && !Algorithms.isEmpty(result.getFilenames())) { - final Activity a = activityRef.get(); - if (a instanceof FragmentActivity && !a.isFinishing()) { - SaveGPXBottomSheetFragment.showInstance(((FragmentActivity) a).getSupportFragmentManager(), result.getFilenames()); + + File file = null; + File dir = app.getAppCustomization().getTracksDir(); + File[] children = dir.listFiles(); + if (children != null && !Algorithms.isEmpty(result.getFilenames())) { + SavingTrackHelper helper = app.getSavingTrackHelper(); + for (File child : children) { + if (child.getName().startsWith(result.getFilenames().get(0)) + && child.lastModified() == helper.getLastTimeFileSaved()) { + file = child; + } + } + } + if (file != null && file.exists()) { + if (!openTrack) { + if (activityRef != null) { + final Activity a = activityRef.get(); + if (a instanceof FragmentActivity && !a.isFinishing()) { + List singleName = Collections.singletonList(Algorithms.getFileNameWithoutExtension(file)); + SaveGPXBottomSheetFragment.showInstance(((FragmentActivity) a) + .getSupportFragmentManager(), singleName); + } + } + } else { + TrackMenuFragment.openTrack(mapActivity, file, null); } } @@ -523,7 +555,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { runnable.run(); } else if (map instanceof FragmentActivity) { FragmentActivity activity = (FragmentActivity) map; - TripRecordingStartingBottomSheet.showInstance(activity.getSupportFragmentManager()); + TripRecordingStartingBottomFragment.showInstance(activity.getSupportFragmentManager()); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java similarity index 65% rename from OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java rename to OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java index 7aaa832dd1..471ec813a6 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingActiveBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java @@ -5,11 +5,8 @@ import android.app.Dialog; import android.content.Context; import android.content.res.ColorStateList; import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; -import android.text.format.DateUtils; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.CompoundButton; @@ -25,59 +22,55 @@ import androidx.annotation.StringRes; import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatImageView; import androidx.cardview.widget.CardView; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.snackbar.Snackbar; - import net.osmand.AndroidUtils; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.SavingTrackHelper; -import net.osmand.plus.activities.SavingTrackHelper.SaveGpxResult; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.myplaces.SaveCurrentTrackTask; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.track.GpxBlockStatisticsBuilder; -import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.plus.track.TrackAppearanceFragment; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; -import java.lang.ref.WeakReference; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static net.osmand.AndroidUtils.getSecondaryTextColorId; +import static net.osmand.AndroidUtils.setPadding; import static net.osmand.plus.UiUtilities.CompoundButtonType.GLOBAL; -public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragment { +public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = TripRecordingActiveBottomSheet.class.getSimpleName(); - private static final Log log = PlatformUtil.getLog(TripRecordingActiveBottomSheet.class); - private static final String UPDATE_CURRENT_GPX_FILE = "update_current_gpx_file"; + public static final String TAG = TripRecordingBottomFragment.class.getSimpleName(); + private static final Log LOG = PlatformUtil.getLog(TripRecordingBottomFragment.class); + private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file"; public static final String UPDATE_TRACK_ICON = "update_track_icon"; - private static final int GENERAL_UPDATE_GPS_INTERVAL = 1000; - private static final int GENERAL_UPDATE_SAVE_INTERVAL = 1000; + private static final int GPS_UPDATE_INTERVAL = 1000; private OsmandApplication app; private OsmandSettings settings; - private SavingTrackHelper helper; + private OsmandMonitoringPlugin plugin; + + private View statusContainer; + private AppCompatImageView trackAppearanceIcon; + private GpxBlockStatisticsBuilder blockStatisticsBuilder; + private SelectedGpxFile selectedGpxFile; private View statusContainer; @@ -88,7 +81,6 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen private final Handler handler = new Handler(); private Runnable updatingGPS; - private Runnable updatingTimeTrackSaved; private GPXFile getGPXFile() { return selectedGpxFile.getGpxFile(); @@ -98,21 +90,21 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen this.selectedGpxFile = selectedGpxFile; } - public boolean hasDataToSave() { + private boolean hasDataToSave() { return app.getSavingTrackHelper().hasDataToSave(); } - public boolean searchingGPS() { + private boolean searchingGPS() { return app.getLocationProvider().getLastKnownLocation() == null; } - public boolean wasTrackMonitored() { + private boolean wasTrackMonitored() { return settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); } public static void showInstance(@NonNull FragmentManager fragmentManager, SelectedGpxFile selectedGpxFile) { if (!fragmentManager.isStateSaved()) { - TripRecordingActiveBottomSheet fragment = new TripRecordingActiveBottomSheet(); + TripRecordingBottomFragment fragment = new TripRecordingBottomFragment(); fragment.setSelectedGpxFile(selectedGpxFile); fragment.show(fragmentManager, TAG); } @@ -122,37 +114,22 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen public void createMenuItems(Bundle savedInstanceState) { app = requiredMyApplication(); settings = app.getSettings(); - helper = app.getSavingTrackHelper(); + plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode); final FragmentManager fragmentManager = getFragmentManager(); - View itemView = inflater.inflate(R.layout.trip_recording_active_fragment, null, false); + View itemView = inflater.inflate(R.layout.trip_recording_fragment, null, false); items.add(new BaseBottomSheetItem.Builder() .setCustomView(itemView) .create()); - View buttonClear = itemView.findViewById(R.id.button_clear); - final View buttonOnline = itemView.findViewById(R.id.button_online); - final View buttonSegment = itemView.findViewById(R.id.button_segment); - buttonSave = itemView.findViewById(R.id.button_save); - final View buttonPause = itemView.findViewById(R.id.button_pause); - View buttonStop = itemView.findViewById(R.id.button_stop); - - createItem(buttonClear, ItemType.CLEAR_DATA, hasDataToSave()); - createItem(buttonOnline, ItemType.STOP_ONLINE, hasDataToSave()); - createItem(buttonSegment, ItemType.START_NEW_SEGMENT, wasTrackMonitored()); - createItem(buttonPause, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME, true); - createItem(buttonStop, ItemType.STOP, true); - - AndroidUiHelper.updateVisibility(buttonOnline, app.getLiveMonitoringHelper().isLiveMonitoringEnabled()); - statusContainer = itemView.findViewById(R.id.status_container); updateStatus(); RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics); if (savedInstanceState != null) { - if (savedInstanceState.containsKey(UPDATE_CURRENT_GPX_FILE) - && savedInstanceState.getBoolean(UPDATE_CURRENT_GPX_FILE)) { + if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE) + && savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) { selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); } } @@ -161,63 +138,28 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen blockStatisticsBuilder.setBlocksClickable(false); blockStatisticsBuilder.initStatBlocks(null, ContextCompat.getColor(app, getActiveTextColorId(nightMode)), nightMode); - showTrackContainer = itemView.findViewById(R.id.show_track_on_map); + LinearLayout showTrackContainer = itemView.findViewById(R.id.show_track_on_map); trackAppearanceIcon = showTrackContainer.findViewById(R.id.additional_button_icon); createShowTrackItem(app, getMapActivity(), nightMode, showTrackContainer, trackAppearanceIcon, - ItemType.SHOW_TRACK.getTitleId(), TripRecordingActiveBottomSheet.this, new Runnable() { + ItemType.SHOW_TRACK.getTitleId(), TripRecordingBottomFragment.this, new Runnable() { @Override public void run() { hide(); } }); - buttonClear.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { + CardView cardLeft = itemView.findViewById(R.id.button_left); + createItem(cardLeft, ItemType.CANCEL); + cardLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (fragmentManager != null && hasDataToSave()) { - ClearRecordedDataBottomSheetFragment.showInstance(fragmentManager, TripRecordingActiveBottomSheet.this); - } + dismiss(); } }); - buttonOnline.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - settings.LIVE_MONITORING.set(false); - AndroidUiHelper.updateVisibility(buttonOnline, false); - } - }); - - buttonSegment.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (wasTrackMonitored()) { - blockStatisticsBuilder.stopUpdatingStatBlocks(); - helper.startNewSegment(); - blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); - } - } - }); - - buttonSave.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - if (hasDataToSave()) { - final GPXFile gpxFile = getGPXFile(); - new SaveCurrentTrackTask(app, gpxFile, createSaveListener(new Runnable() { - @Override - public void run() { - blockStatisticsBuilder.stopUpdatingStatBlocks(); - blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); - stopUpdatingTimeTrackSaved(); - runUpdatingTimeTrackSaved(); - } - })).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } - } - }); - - buttonPause.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { + final CardView cardCenterLeft = itemView.findViewById(R.id.button_center_left); + createItem(cardCenterLeft, wasTrackMonitored() ? ItemType.PAUSE : ItemType.RESUME); + cardCenterLeft.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean wasTrackMonitored = !wasTrackMonitored(); @@ -228,19 +170,94 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } settings.SAVE_GLOBAL_TRACK_TO_GPX.set(wasTrackMonitored); updateStatus(); - createItem(buttonPause, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME, true); - createItem(buttonSegment, ItemType.START_NEW_SEGMENT, wasTrackMonitored); + createItem(cardCenterLeft, wasTrackMonitored ? ItemType.PAUSE : ItemType.RESUME); } }); - buttonStop.findViewById(R.id.button_container).setOnClickListener(new View.OnClickListener() { + CardView cardCenterRight = itemView.findViewById(R.id.button_center_right); + createItem(cardCenterRight, ItemType.FINISH); + cardCenterRight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - if (fragmentManager != null) { - StopTrackRecordingBottomFragment.showInstance(getMapActivity(), fragmentManager, TripRecordingActiveBottomSheet.this); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null && plugin != null && app.getSavingTrackHelper().hasDataToSave()) { + plugin.saveCurrentTrack(null, mapActivity); + app.getNotificationHelper().refreshNotifications(); + dismiss(); } } }); + + CardView cardRight = itemView.findViewById(R.id.button_right); + createItem(cardRight, ItemType.OPTIONS); + cardRight.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (fragmentManager != null) { + TripRecordingOptionsBottomFragment.showInstance(fragmentManager, TripRecordingBottomFragment.this, selectedGpxFile); + } + } + }); + + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(SAVE_CURRENT_GPX_FILE, true); + } + + @Override + public void onResume() { + super.onResume(); + blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); + runUpdatingGPS(); + } + + @Override + public void onPause() { + super.onPause(); + blockStatisticsBuilder.stopUpdatingStatBlocks(); + stopUpdatingGPS(); + } + + public void show() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.show(); + } + } + + public void show(String... keys) { + show(); + for (String key : keys) { + if (key.equals(UPDATE_TRACK_ICON)) { + updateTrackIcon(app, trackAppearanceIcon); + } + } + } + + public void hide() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.hide(); + } + } + + public void stopUpdatingGPS() { + handler.removeCallbacks(updatingGPS); + } + + public void runUpdatingGPS() { + updatingGPS = new Runnable() { + @Override + public void run() { + int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); + updateStatus(); + handler.postDelayed(this, Math.max(GPS_UPDATE_INTERVAL, interval)); + } + }; + handler.post(updatingGPS); } private void updateStatus() { @@ -290,14 +307,14 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen showTrackCompound.setChecked(app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null); UiUtilities.setupCompoundButton(showTrackCompound, nightMode, GLOBAL); - setShowOnMapBackground(buttonShowTrack, showTrackCompound.isChecked(), nightMode); + setShowTrackItemBackground(buttonShowTrack, showTrackCompound.isChecked(), nightMode); buttonShowTrack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean checked = !showTrackCompound.isChecked(); showTrackCompound.setChecked(checked); app.getSelectedGpxHelper().selectGpxFile(app.getSavingTrackHelper().getCurrentGpx(), checked, false); - setShowOnMapBackground(buttonShowTrack, checked, nightMode); + setShowTrackItemBackground(buttonShowTrack, checked, nightMode); createItem(app, nightMode, buttonAppearance, ItemType.APPEARANCE, checked, null); } }); @@ -318,30 +335,31 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen }); } - private void createItem(View view, ItemType type, boolean enabled) { - createItem(app, nightMode, view, type, enabled, null); + protected static void setShowTrackItemBackground(View view, boolean checked, boolean nightMode) { + int background = checked ? getActiveTransparentBackgroundId(nightMode) : getInactiveStrokedBackgroundId(nightMode); + view.setBackgroundResource(background); } - private void createItem(View view, ItemType type, boolean enabled, @Nullable String description) { - createItem(app, nightMode, view, type, enabled, description); + private void createItem(View view, ItemType type) { + createItem(app, nightMode, view, type, true, null); } public static View createItem(Context context, boolean nightMode, LayoutInflater inflater, ItemType type) { + return createItem(context, nightMode, inflater, type, true, null); + } + + public static View createItem(Context context, boolean nightMode, LayoutInflater inflater, ItemType type, boolean enabled, String description) { View button = inflater.inflate(R.layout.bottom_sheet_button_with_icon, null); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); int horizontal = context.getResources().getDimensionPixelSize(R.dimen.content_padding); params.setMargins(horizontal, 0, horizontal, 0); button.setLayoutParams(params); - LinearLayout container = button.findViewById(R.id.button_container); - container.setClickable(false); - container.setFocusable(false); - createItem(context, nightMode, button, type, true, null); + createItem(context, nightMode, button, type, enabled, description); return button; } public static void createItem(Context context, boolean nightMode, View view, ItemType type, boolean enabled, @Nullable String description) { view.setTag(type); - LinearLayout button = view.findViewById(R.id.button_container); AppCompatImageView icon = view.findViewById(R.id.icon); if (icon != null) { @@ -367,151 +385,26 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen setTextColor(context, desc, false, nightMode, type); } - setItemBackground(context, nightMode, button != null ? button : view, enabled); + setItemBackground(context, nightMode, view, enabled); } - private String getTimeTrackSaved() { - long timeTrackSaved = helper.getLastTimeFileSaved(); - if (timeTrackSaved != 0) { - long now = System.currentTimeMillis(); - CharSequence time = DateUtils.getRelativeTimeSpanString(timeTrackSaved, now, DateUtils.MINUTE_IN_MILLIS); - return String.valueOf(time); + public static void setItemBackground(Context context, boolean nightMode, View view, boolean enabled) { + Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light); + if (background != null && enabled) { + int normalColorId = view instanceof CardView + ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode); + ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList( + context, normalColorId, getActiveTextColorId(nightMode) + ); + if (view instanceof CardView) { + ((CardView) view).setCardBackgroundColor(iconColorStateList); + return; + } + DrawableCompat.setTintList(background, iconColorStateList); } else { - return null; - } - } - - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(UPDATE_CURRENT_GPX_FILE, true); - } - - @Override - public void onResume() { - super.onResume(); - blockStatisticsBuilder.runUpdatingStatBlocksIfNeeded(); - runUpdatingGPS(); - runUpdatingTimeTrackSaved(); - } - - @Override - public void onPause() { - super.onPause(); - blockStatisticsBuilder.stopUpdatingStatBlocks(); - stopUpdatingGPS(); - stopUpdatingTimeTrackSaved(); - } - - public void stopUpdatingGPS() { - handler.removeCallbacks(updatingGPS); - } - - public void runUpdatingGPS() { - updatingGPS = new Runnable() { - @Override - public void run() { - int interval = app.getSettings().SAVE_GLOBAL_TRACK_INTERVAL.get(); - updateStatus(); - handler.postDelayed(this, Math.max(GENERAL_UPDATE_GPS_INTERVAL, interval)); - } - }; - handler.post(updatingGPS); - } - - public void stopUpdatingTimeTrackSaved() { - handler.removeCallbacks(updatingTimeTrackSaved); - } - - public void runUpdatingTimeTrackSaved() { - updatingTimeTrackSaved = new Runnable() { - @Override - public void run() { - String time = getTimeTrackSaved(); - createItem(buttonSave, ItemType.SAVE, hasDataToSave(), !Algorithms.isEmpty(time) ? time : null); - handler.postDelayed(this, GENERAL_UPDATE_SAVE_INTERVAL); - } - }; - handler.post(updatingTimeTrackSaved); - } - - private SaveGpxListener createSaveListener(@Nullable final Runnable callback) { - return new SaveGpxListener() { - - @Override - public void gpxSavingStarted() { - } - - @Override - public void gpxSavingFinished(Exception errorMessage) { - final MapActivity mapActivity = getMapActivity(); - final Context context = getContext(); - final SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir()); - ArrayList filenames = new ArrayList<>(result.getFilenames()); - String fileName = ""; - if (filenames.size() > 0) { - fileName = filenames.get(filenames.size() - 1) + IndexConstants.GPX_FILE_EXT; - } - String message = fileName + " " + app.getResources().getString(R.string.shared_string_is_saved) + ". " - + app.getResources().getString(R.string.track_recording_will_be_continued); - if (mapActivity != null && context != null) { - final WeakReference mapActivityRef = new WeakReference<>(mapActivity); - final FragmentManager fragmentManager = mapActivityRef.get().getSupportFragmentManager(); - Snackbar snackbar = Snackbar.make(getView(), - message, - Snackbar.LENGTH_LONG) - .setAction(R.string.shared_string_rename, new View.OnClickListener() { - @Override - public void onClick(View view) { - fragmentManager.beginTransaction().remove(TripRecordingActiveBottomSheet.this).commitAllowingStateLoss(); - SaveGPXBottomSheetFragment.showInstance(fragmentManager, result.getFilenames()); - } - }); - View view = snackbar.getView(); - CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams(); - params.gravity = Gravity.TOP; - AndroidUtils.setMargins(params, 0, AndroidUtils.getStatusBarHeight(context), 0, 0); - view.setLayoutParams(params); - UiUtilities.setupSnackbar(snackbar, nightMode); - snackbar.show(); - if (callback != null) { - callback.run(); - } - } - } - }; - } - - @Nullable - public MapActivity getMapActivity() { - Activity activity = getActivity(); - if (activity instanceof MapActivity) { - return (MapActivity) activity; - } - return null; - } - - public void show() { - Dialog dialog = getDialog(); - if (dialog != null) { - dialog.show(); - } - } - - public void show(String... keys) { - show(); - for (String key : keys) { - if (key.equals(UPDATE_TRACK_ICON)) { - updateTrackIcon(app, trackAppearanceIcon); - } - } - } - - public void hide() { - Dialog dialog = getDialog(); - if (dialog != null) { - dialog.hide(); + UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode))); } + view.setBackgroundDrawable(background); } public enum ItemType { @@ -522,7 +415,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen ON_PAUSE(R.string.on_pause, R.drawable.ic_pause), CLEAR_DATA(R.string.clear_recorded_data, R.drawable.ic_action_delete_dark), START_NEW_SEGMENT(R.string.gpx_start_new_segment, R.drawable.ic_action_new_segment), - SAVE(R.string.shared_string_save, R.drawable.ic_action_save_to_file), + SAVE(R.string.trip_recording_save_and_continue, R.drawable.ic_action_save_to_file), PAUSE(R.string.shared_string_pause, R.drawable.ic_pause), RESUME(R.string.shared_string_resume, R.drawable.ic_play_dark), STOP(R.string.shared_string_control_stop, R.drawable.ic_action_rec_stop), @@ -531,7 +424,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen STOP_ONLINE(R.string.live_monitoring_stop, R.drawable.ic_world_globe_dark), CANCEL(R.string.shared_string_cancel, R.drawable.ic_action_close), START_RECORDING(R.string.shared_string_control_start, R.drawable.ic_action_direction_movement), - SETTINGS(R.string.shared_string_settings, R.drawable.ic_action_settings); + SETTINGS(R.string.shared_string_settings, R.drawable.ic_action_settings), + FINISH(R.string.shared_string_finish, R.drawable.ic_action_point_destination), + OPTIONS(R.string.shared_string_options, R.drawable.ic_overflow_menu_with_background); @StringRes private final Integer titleId; @@ -559,31 +454,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } - public static void setItemBackground(Context context, boolean nightMode, View view, boolean enabled) { - Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light); - if (background != null && enabled) { - int normalColorId = view instanceof CardView - ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode); - ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList( - context, normalColorId, getActiveTextColorId(nightMode) - ); - if (view instanceof CardView) { - ((CardView) view).setCardBackgroundColor(iconColorStateList); - return; - } - DrawableCompat.setTintList(background, iconColorStateList); - } else { - UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode))); - } - view.setBackgroundDrawable(background); - } - - public static void setShowOnMapBackground(View view, boolean checked, boolean nightMode) { - int background = checked ? getActiveTransparentBackgroundId(nightMode) : getInactiveStrokedBackgroundId(nightMode); - view.setBackgroundResource(background); - } - - public static void setTextColor(Context context, TextView tv, boolean enabled, boolean nightMode, ItemType type) { + protected static void setTextColor(Context context, TextView tv, boolean enabled, boolean nightMode, ItemType type) { if (tv != null) { int activeColorId = type.isNegative() ? R.color.color_osm_edit_delete : getActiveTextColorId(nightMode); int normalColorId = enabled ? activeColorId : getSecondaryTextColorId(nightMode); @@ -592,7 +463,7 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } } - public static void setTintedIcon(Context context, AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) { + protected static void setTintedIcon(Context context, AppCompatImageView iv, boolean enabled, boolean nightMode, ItemType type) { Integer iconId = type.getIconId(); if (iv != null && iconId != null) { Drawable icon = AppCompatResources.getDrawable(context, iconId); @@ -607,6 +478,9 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen int stopSize = iv.getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin_large); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(stopSize, stopSize); iv.setLayoutParams(params); + View container = (View) iv.getParent(); + setPadding(container, container.getPaddingLeft(), container.getTop(), + context.getResources().getDimensionPixelSize(R.dimen.content_padding_half), container.getBottom()); } } } @@ -662,17 +536,17 @@ public class TripRecordingActiveBottomSheet extends MenuBottomSheetDialogFragmen } @Override - protected int getDismissButtonHeight() { - return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); - } - - @Override - protected int getDismissButtonTextId() { - return R.string.shared_string_close; - } - - @Override - protected boolean useVerticalButtons() { + protected boolean hideButtonsContainer() { return true; } + + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java similarity index 71% rename from OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java rename to OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java index 9a5e40ab95..e51911c867 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/ClearRecordedDataBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java @@ -11,21 +11,24 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; -import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType; +import net.osmand.plus.monitoring.TripRecordingBottomFragment.ItemType; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; -public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogFragment { +import static net.osmand.AndroidUtils.getPrimaryTextColorId; +import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.*; - public static final String TAG = ClearRecordedDataBottomSheetFragment.class.getSimpleName(); +public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = TripRecordingClearDataBottomFragment.class.getSimpleName(); private OsmandApplication app; public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) { if (!fragmentManager.isStateSaved()) { - ClearRecordedDataBottomSheetFragment fragment = new ClearRecordedDataBottomSheetFragment(); + TripRecordingClearDataBottomFragment fragment = new TripRecordingClearDataBottomFragment(); fragment.setTargetFragment(target, 0); fragment.show(fragmentManager, TAG); } @@ -37,14 +40,14 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding); - + String description = getString(R.string.clear_recorded_data_warning) + .concat(getString(R.string.lost_data_warning)); final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA); final View buttonCancel = createItem(inflater, ItemType.CANCEL); items.add(new BottomSheetItemWithDescription.Builder() - .setDescription(app.getString(R.string.clear_recorded_data_warning)) - .setDescriptionColorId(!nightMode ? R.color.text_color_primary_light : R.color.text_color_primary_dark) - .setDescriptionMaxLines(2) + .setDescription(description) + .setDescriptionColorId(getPrimaryTextColorId(nightMode)) .setTitle(app.getString(R.string.clear_recorded_data)) .setLayoutId(R.layout.bottom_sheet_item_title_with_description) .create()); @@ -58,6 +61,7 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF public void onClick(View v) { app.getSavingTrackHelper().clearRecordedData(true); dismiss(); + dismissTargetDialog(TripRecordingClearDataBottomFragment.this, TripRecordingOptionsBottomFragment.class); } }) .create()); @@ -78,15 +82,15 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF } private View createItem(LayoutInflater inflater, ItemType type) { - return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type); + return TripRecordingBottomFragment.createItem(app, nightMode, inflater, type); } @Override public void onResume() { super.onResume(); Fragment target = getTargetFragment(); - if (target instanceof TripRecordingActiveBottomSheet) { - ((TripRecordingActiveBottomSheet) target).hide(); + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).hide(); } } @@ -94,8 +98,8 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF public void onPause() { super.onPause(); Fragment target = getTargetFragment(); - if (target instanceof TripRecordingActiveBottomSheet) { - ((TripRecordingActiveBottomSheet) target).show(); + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).show(); } } @@ -103,4 +107,5 @@ public class ClearRecordedDataBottomSheetFragment extends MenuBottomSheetDialogF protected boolean hideButtonsContainer() { return true; } -} \ No newline at end of file + +} diff --git a/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java similarity index 50% rename from OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java rename to OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java index f648c5bbdf..971d7399e1 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/StopTrackRecordingBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java @@ -8,36 +8,29 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; -import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType; -import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.monitoring.TripRecordingBottomFragment.ItemType; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; -public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragment { +import static net.osmand.AndroidUtils.getPrimaryTextColorId; +import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.ACTION_STOP_AND_DISCARD; +import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.dismissTargetDialog; - public static final String TAG = StopTrackRecordingBottomFragment.class.getSimpleName(); +public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = TripRecordingDiscardBottomFragment.class.getSimpleName(); private OsmandApplication app; - private MapActivity mapActivity; - private OsmandSettings settings; - private OsmandMonitoringPlugin plugin; - private ItemType tag = ItemType.CANCEL; - public void setMapActivity(MapActivity mapActivity) { - this.mapActivity = mapActivity; - } - - public static void showInstance(MapActivity mapActivity, @NonNull FragmentManager fragmentManager, @NonNull Fragment target) { + public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) { if (!fragmentManager.isStateSaved()) { - StopTrackRecordingBottomFragment fragment = new StopTrackRecordingBottomFragment(); - fragment.setMapActivity(mapActivity); + TripRecordingDiscardBottomFragment fragment = new TripRecordingDiscardBottomFragment(); fragment.setTargetFragment(target, 0); fragment.show(fragmentManager, TAG); } @@ -46,67 +39,48 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm @Override public void createMenuItems(Bundle savedInstanceState) { app = requiredMyApplication(); - settings = app.getSettings(); - plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); + final OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding); - -// final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); - final View buttonSave = createItem(inflater, ItemType.STOP_AND_SAVE); + String description = getString(R.string.track_recording_description) + .concat(getString(R.string.lost_data_warning)); + final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); final View buttonCancel = createItem(inflater, ItemType.CANCEL); items.add(new BottomSheetItemWithDescription.Builder() - .setDescription(app.getString(R.string.track_recording_description)) - .setDescriptionColorId(!nightMode ? R.color.text_color_primary_light : R.color.text_color_primary_dark) - .setDescriptionMaxLines(4) + .setDescription(description) + .setDescriptionColorId(getPrimaryTextColorId(nightMode)) .setTitle(app.getString(R.string.track_recording_title)) .setLayoutId(R.layout.bottom_sheet_item_title_with_description) .create()); items.add(new DividerSpaceItem(app, verticalBig)); - /*items.add(new BaseBottomSheetItem.Builder() + items.add(new BaseBottomSheetItem.Builder() .setCustomView(buttonDiscard) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - tag = (ItemType) buttonDiscard.getTag(); - if (plugin != null && settings.SAVE_GLOBAL_TRACK_TO_GPX.get()) { + if (plugin != null && app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) { plugin.stopRecording(); app.getNotificationHelper().refreshNotifications(); } app.getSavingTrackHelper().clearRecordedData(true); dismiss(); + dismissTargetDialog(TripRecordingDiscardBottomFragment.this, + TripRecordingOptionsBottomFragment.class, ACTION_STOP_AND_DISCARD, true); } }) .create()); - items.add(new DividerSpaceItem(app, verticalBig));*/ - - items.add(new BaseBottomSheetItem.Builder() - .setCustomView(buttonSave) - .setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - tag = (ItemType) buttonSave.getTag(); - if (plugin != null && app.getSavingTrackHelper().hasDataToSave()) { - plugin.saveCurrentTrack(null, mapActivity); - app.getNotificationHelper().refreshNotifications(); - dismiss(); - } - } - }) - .create()); - - items.add(new DividerSpaceItem(app, verticalNormal)); + items.add(new DividerSpaceItem(app, verticalBig)); items.add(new BaseBottomSheetItem.Builder() .setCustomView(buttonCancel) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - tag = (ItemType) buttonCancel.getTag(); dismiss(); } }) @@ -116,15 +90,15 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm } private View createItem(LayoutInflater inflater, ItemType type) { - return TripRecordingActiveBottomSheet.createItem(app, nightMode, inflater, type); + return TripRecordingBottomFragment.createItem(app, nightMode, inflater, type); } @Override public void onResume() { super.onResume(); Fragment target = getTargetFragment(); - if (target instanceof TripRecordingActiveBottomSheet) { - ((TripRecordingActiveBottomSheet) target).hide(); + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).hide(); } } @@ -132,13 +106,8 @@ public class StopTrackRecordingBottomFragment extends MenuBottomSheetDialogFragm public void onPause() { super.onPause(); Fragment target = getTargetFragment(); - if (target instanceof TripRecordingActiveBottomSheet) { - TripRecordingActiveBottomSheet tripRec = (TripRecordingActiveBottomSheet) target; - if (tag == ItemType.CANCEL) { - tripRec.show(); - } else { - tripRec.dismiss(); - } + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).show(); } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java new file mode 100644 index 0000000000..aa755a4276 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java @@ -0,0 +1,350 @@ +package net.osmand.plus.monitoring; + +import android.app.Activity; +import android.app.Dialog; +import android.os.AsyncTask; +import android.os.Bundle; +import android.os.Handler; +import android.text.format.DateUtils; +import android.view.LayoutInflater; +import android.view.View; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.monitoring.TripRecordingBottomFragment.ItemType; +import net.osmand.plus.myplaces.SaveCurrentTrackTask; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; +import net.osmand.util.Algorithms; + +import static net.osmand.AndroidUtils.getPrimaryTextColorId; + +public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFragment { + + public static final String TAG = TripRecordingOptionsBottomFragment.class.getSimpleName(); + public static final String ACTION_STOP_AND_DISCARD = "action_stop_and_discard"; + private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file"; + private static final int SAVE_UPDATE_INTERVAL = 1000; + + private OsmandApplication app; + private OsmandSettings settings; + private SavingTrackHelper helper; + + private View buttonClear; + private View buttonSave; + + private SelectedGpxFile selectedGpxFile; + private final Handler handler = new Handler(); + private Runnable updatingTimeTrackSaved; + private int indexButtonOnline = -1; + private int indexButtonOnlineDivider = -1; + + private GPXFile getGPXFile() { + return selectedGpxFile.getGpxFile(); + } + + public void setSelectedGpxFile(SelectedGpxFile selectedGpxFile) { + this.selectedGpxFile = selectedGpxFile; + } + + public boolean hasDataToSave() { + return app.getSavingTrackHelper().hasDataToSave(); + } + + public boolean wasTrackMonitored() { + return settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target, SelectedGpxFile selectedGpxFile) { + if (!fragmentManager.isStateSaved()) { + TripRecordingOptionsBottomFragment fragment = new TripRecordingOptionsBottomFragment(); + fragment.setTargetFragment(target, 0); + fragment.setSelectedGpxFile(selectedGpxFile); + fragment.show(fragmentManager, TAG); + } + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + app = requiredMyApplication(); + settings = app.getSettings(); + helper = app.getSavingTrackHelper(); + LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); + final FragmentManager fragmentManager = getFragmentManager(); + int dp16 = getResources().getDimensionPixelSize(R.dimen.content_padding); + int dp36 = getResources().getDimensionPixelSize(R.dimen.context_menu_controller_height); + + if (savedInstanceState != null) { + if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE) + && savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) { + selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); + } + } + + buttonClear = createItem(inflater, ItemType.CLEAR_DATA, hasDataToSave()); + final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); + final View buttonOnline = createItem(inflater, ItemType.STOP_ONLINE, hasDataToSave()); + buttonSave = createItem(inflater, ItemType.SAVE, hasDataToSave()); + final View buttonSegment = createItem(inflater, ItemType.START_NEW_SEGMENT, wasTrackMonitored()); + + items.add(new SimpleBottomSheetItem.Builder() + .setTitle(getString(R.string.shared_string_options)) + .setTitleColorId(getPrimaryTextColorId(nightMode)) + .setLayoutId(R.layout.bottom_sheet_item_title) + .create()); + + items.add(new DividerSpaceItem(app, getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(buttonClear) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (fragmentManager != null && hasDataToSave()) { + TripRecordingClearDataBottomFragment.showInstance(fragmentManager, TripRecordingOptionsBottomFragment.this); + } + } + }) + .create()); + + items.add(new DividerSpaceItem(app, dp16)); + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(buttonDiscard) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (fragmentManager != null) { + TripRecordingDiscardBottomFragment.showInstance(fragmentManager, TripRecordingOptionsBottomFragment.this); + } + } + }) + .create()); + + items.add(new DividerSpaceItem(app, dp36)); + + if (app.getLiveMonitoringHelper().isLiveMonitoringEnabled()) { + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(buttonOnline) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + settings.LIVE_MONITORING.set(false); + if (indexButtonOnline != -1) { + AndroidUiHelper.updateVisibility(items.get(indexButtonOnline).getView(), false); + } + if (indexButtonOnlineDivider != -1) { + AndroidUiHelper.updateVisibility(items.get(indexButtonOnlineDivider).getView(), false); + } + } + }) + .create()); + indexButtonOnline = items.size() - 1; + + items.add(new DividerSpaceItem(app, dp36)); + indexButtonOnlineDivider = items.size() - 1; + } + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(buttonSave) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (hasDataToSave()) { + final GPXFile gpxFile = getGPXFile(); + new SaveCurrentTrackTask(app, gpxFile, createSaveListener()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + }) + .create()); + + items.add(new DividerSpaceItem(app, dp16)); + + items.add(new BaseBottomSheetItem.Builder() + .setCustomView(buttonSegment) + .setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (wasTrackMonitored()) { + helper.startNewSegment(); + } + } + }) + .create()); + + items.add(new DividerSpaceItem(app, getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(SAVE_CURRENT_GPX_FILE, true); + } + + @Override + public void onResume() { + super.onResume(); + runUpdatingTimeTrackSaved(); + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingBottomFragment) { + ((TripRecordingBottomFragment) target).hide(); + } + } + + @Override + public void onPause() { + super.onPause(); + stopUpdatingTimeTrackSaved(); + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingBottomFragment) { + if (isDiscard()) { + ((TripRecordingBottomFragment) target).dismiss(); + } else { + ((TripRecordingBottomFragment) target).show(); + } + } + } + + public void show() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.show(); + } + } + + public void hide() { + Dialog dialog = getDialog(); + if (dialog != null) { + dialog.hide(); + } + } + + private boolean isDiscard() { + Bundle args = getArguments(); + if (args != null) { + return args.getBoolean(ACTION_STOP_AND_DISCARD); + } + return false; + } + + protected static void dismissTargetDialog(Fragment current, Class targetClass) { + dismissTargetDialog(current, targetClass, null, null); + } + + protected static void dismissTargetDialog(Fragment current, Class targetClass, String booleanKey, Boolean value) { + if (targetClass.isInstance(current.getTargetFragment())) { + Fragment target = current.getTargetFragment(); + if (booleanKey != null && value != null) { + Bundle args = new Bundle(); + args.putBoolean(booleanKey, value); + target.setArguments(args); + } + if (target instanceof DialogFragment) { + ((DialogFragment) target).dismiss(); + } + } + } + + public void stopUpdatingTimeTrackSaved() { + handler.removeCallbacks(updatingTimeTrackSaved); + } + + public void runUpdatingTimeTrackSaved() { + updatingTimeTrackSaved = new Runnable() { + @Override + public void run() { + String time = getTimeTrackSaved(); + TripRecordingBottomFragment.createItem(app, nightMode, buttonSave, ItemType.SAVE, hasDataToSave(), !Algorithms.isEmpty(time) ? time : null); + TripRecordingBottomFragment.createItem(app, nightMode, buttonClear, ItemType.CLEAR_DATA, hasDataToSave(), null); + handler.postDelayed(this, SAVE_UPDATE_INTERVAL); + } + }; + handler.post(updatingTimeTrackSaved); + } + + private String getTimeTrackSaved() { + long timeTrackSaved = helper.getLastTimeFileSaved(); + if (timeTrackSaved != 0) { + long now = System.currentTimeMillis(); + CharSequence time = DateUtils.getRelativeTimeSpanString(timeTrackSaved, now, DateUtils.MINUTE_IN_MILLIS); + return String.valueOf(time); + } else { + return null; + } + } + + private View createItem(LayoutInflater inflater, ItemType type, boolean enabled) { + return TripRecordingBottomFragment.createItem(app, nightMode, inflater, type, enabled, null); + } + + private View createItem(LayoutInflater inflater, ItemType type) { + return TripRecordingBottomFragment.createItem(app, nightMode, inflater, type); + } + + private SaveGpxListener createSaveListener() { + return new SaveGpxListener() { + + @Override + public void gpxSavingStarted() { + } + + @Override + public void gpxSavingFinished(Exception errorMessage) { + MapActivity mapActivity = getMapActivity(); + OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); + if (mapActivity != null && plugin != null) { + stopUpdatingTimeTrackSaved(); + settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false); + plugin.saveCurrentTrack(null, mapActivity, false, true); + dismiss(); + dismissTargetDialog(TripRecordingOptionsBottomFragment.this, TripRecordingBottomFragment.class); + settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true); + runUpdatingTimeTrackSaved(); + } + } + }; + } + + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + } + + @Override + protected int getDismissButtonHeight() { + return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_back; + } + + @Override + protected boolean useVerticalButtons() { + return true; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java similarity index 88% rename from OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java rename to OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java index c8c96d1323..8d379237e2 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java @@ -29,21 +29,21 @@ import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; -import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.ItemType; +import net.osmand.plus.monitoring.TripRecordingBottomFragment.ItemType; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.UPDATE_TRACK_ICON; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.createItem; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.createShowTrackItem; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.updateTrackIcon; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.UPDATE_TRACK_ICON; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.createItem; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.createShowTrackItem; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.updateTrackIcon; -public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragment { +public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFragment { - public static final String TAG = TripRecordingStartingBottomSheet.class.getSimpleName(); + public static final String TAG = TripRecordingStartingBottomFragment.class.getSimpleName(); public static final String UPDATE_LOGGING_INTERVAL = "update_logging_interval"; private OsmandApplication app; @@ -52,7 +52,6 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm private AppCompatImageView upDownBtn; private AppCompatImageView trackAppearanceIcon; private TextView intervalValueView; - private LinearLayout showTrackContainer; private LinearLayout intervalContainer; private RangeSlider intervalSlider; @@ -60,7 +59,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm public static void showInstance(@NonNull FragmentManager fragmentManager) { if (!fragmentManager.isStateSaved()) { - TripRecordingStartingBottomSheet fragment = new TripRecordingStartingBottomSheet(); + TripRecordingStartingBottomFragment fragment = new TripRecordingStartingBottomFragment(); fragment.show(fragmentManager, TAG); } } @@ -91,10 +90,10 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm intervalSlider = itemView.findViewById(R.id.interval_slider); updateIntervalValue(); - showTrackContainer = itemView.findViewById(R.id.show_track_on_map); + LinearLayout showTrackContainer = itemView.findViewById(R.id.show_track_on_map); trackAppearanceIcon = showTrackContainer.findViewById(R.id.additional_button_icon); createShowTrackItem(app, getMapActivity(), nightMode, showTrackContainer, trackAppearanceIcon, - R.string.shared_string_show_on_map, TripRecordingStartingBottomSheet.this, new Runnable() { + R.string.shared_string_show_on_map, TripRecordingStartingBottomFragment.this, new Runnable() { @Override public void run() { hide(); @@ -104,6 +103,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm updateUpDownBtn(); CardView cardLeft = itemView.findViewById(R.id.button_left); + createItem(app, nightMode, cardLeft, ItemType.CANCEL, true, null); cardLeft.setOnClickListener(new View.OnClickListener() { @Override @@ -113,6 +113,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm }); CardView cardCenter = itemView.findViewById(R.id.button_center); + createItem(app, nightMode, cardCenter, ItemType.START_RECORDING, true, null); cardCenter.setOnClickListener(new View.OnClickListener() { @Override @@ -122,6 +123,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm }); CardView cardRight = itemView.findViewById(R.id.button_right); + createItem(app, nightMode, cardRight, ItemType.SETTINGS, true, null); cardRight.setOnClickListener(new View.OnClickListener() { @Override @@ -129,7 +131,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { hide(); - BaseSettingsFragment.showInstance(mapActivity, SettingsScreenType.MONITORING_SETTINGS, TripRecordingStartingBottomSheet.this); + BaseSettingsFragment.showInstance(mapActivity, SettingsScreenType.MONITORING_SETTINGS, TripRecordingStartingBottomFragment.this); } } }); @@ -214,7 +216,7 @@ public class TripRecordingStartingBottomSheet extends MenuBottomSheetDialogFragm app.startNavigationService(NavigationService.USED_BY_GPX); MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { - TripRecordingActiveBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack()); + TripRecordingBottomFragment.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack()); } dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java index 08a4e34b6b..e46e438f67 100644 --- a/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/bottomsheets/BooleanPreferenceBottomSheet.java @@ -6,7 +6,6 @@ import android.graphics.drawable.LayerDrawable; import android.os.Build; import android.os.Bundle; import android.view.View; -import android.widget.CompoundButton; import android.widget.LinearLayout; import androidx.annotation.NonNull; @@ -34,9 +33,8 @@ import net.osmand.plus.settings.preferences.SwitchPreferenceEx; import org.apache.commons.logging.Log; -import static net.osmand.plus.UiUtilities.CompoundButtonType.TOOLBAR; import static net.osmand.plus.liveupdates.LiveUpdatesSettingsDialogFragmentNew.getActivePrimaryColorId; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.getSecondaryIconColorId; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.getSecondaryIconColorId; public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index d71387c0ce..2faf24db46 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -61,7 +61,7 @@ import net.osmand.plus.activities.OsmandInAppPurchaseActivity; import net.osmand.plus.audionotes.MultimediaNotesFragment; import net.osmand.plus.development.DevelopmentSettingsFragment; import net.osmand.plus.monitoring.MonitoringSettingsFragment; -import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingStartingBottomFragment; import net.osmand.plus.openplacereviews.OprSettingsFragment; import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment; @@ -86,7 +86,7 @@ import java.io.Serializable; import java.util.Set; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; -import static net.osmand.plus.monitoring.TripRecordingStartingBottomSheet.UPDATE_LOGGING_INTERVAL; +import static net.osmand.plus.monitoring.TripRecordingStartingBottomFragment.UPDATE_LOGGING_INTERVAL; public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener, OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange { @@ -297,8 +297,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl public void onDestroyView() { super.onDestroyView(); Fragment target = getTargetFragment(); - if (target instanceof TripRecordingStartingBottomSheet) { - ((TripRecordingStartingBottomSheet) target).show(UPDATE_LOGGING_INTERVAL); + if (target instanceof TripRecordingStartingBottomFragment) { + ((TripRecordingStartingBottomFragment) target).show(UPDATE_LOGGING_INTERVAL); } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 807becbb1c..958f45193a 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -36,8 +36,8 @@ import net.osmand.plus.dialogs.GpxAppearanceAdapter; import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem; import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.monitoring.TripRecordingActiveBottomSheet; -import net.osmand.plus.monitoring.TripRecordingStartingBottomSheet; +import net.osmand.plus.monitoring.TripRecordingBottomFragment; +import net.osmand.plus.monitoring.TripRecordingStartingBottomFragment; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener; import net.osmand.plus.settings.backend.CommonPreference; @@ -64,7 +64,7 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_BOLD; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.TRACK_WIDTH_MEDIUM; import static net.osmand.plus.dialogs.GpxAppearanceAdapter.getAppearanceItems; -import static net.osmand.plus.monitoring.TripRecordingActiveBottomSheet.UPDATE_TRACK_ICON; +import static net.osmand.plus.monitoring.TripRecordingBottomFragment.UPDATE_TRACK_ICON; public class TrackAppearanceFragment extends ContextMenuScrollFragment implements CardListener, ColorPickerListener { @@ -398,10 +398,10 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement @Override public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) { Fragment target = getTargetFragment(); - if (target instanceof TripRecordingStartingBottomSheet) { - ((TripRecordingStartingBottomSheet) target).show(UPDATE_TRACK_ICON); - } else if (target instanceof TripRecordingActiveBottomSheet) { - ((TripRecordingActiveBottomSheet) target).show(UPDATE_TRACK_ICON); + if (target instanceof TripRecordingStartingBottomFragment) { + ((TripRecordingStartingBottomFragment) target).show(UPDATE_TRACK_ICON); + } else if (target instanceof TripRecordingBottomFragment) { + ((TripRecordingBottomFragment) target).show(UPDATE_TRACK_ICON); } } From 3bcf8d4e3ba4d68ab77fdf2577a0cf90fa98e32f Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Mar 2021 15:00:37 +0200 Subject: [PATCH 2/4] small fixes; --- .../plus/monitoring/TripRecordingBottomFragment.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java index 471ec813a6..36ecc4edfb 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java @@ -72,13 +72,6 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { private GpxBlockStatisticsBuilder blockStatisticsBuilder; private SelectedGpxFile selectedGpxFile; - - private View statusContainer; - private LinearLayout showTrackContainer; - private AppCompatImageView trackAppearanceIcon; - private View buttonSave; - private GpxBlockStatisticsBuilder blockStatisticsBuilder; - private final Handler handler = new Handler(); private Runnable updatingGPS; From 695a0016b918426cb6a719ecc133f0040d0307f5 Mon Sep 17 00:00:00 2001 From: Skalii Date: Mon, 22 Mar 2021 16:03:32 +0200 Subject: [PATCH 3/4] lost fixes after merge; --- .../plus/monitoring/MonitoringSettingsFragment.java | 6 +++--- .../routepreparationmenu/RouteOptionsBottomSheet.java | 8 ++++---- .../plus/settings/fragments/BaseSettingsFragment.java | 11 ----------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java index 8ade392007..8ee1de18a3 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java @@ -40,7 +40,7 @@ import java.util.LinkedHashMap; import static net.osmand.plus.activities.PluginInfoFragment.PLUGIN_INFO; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS; -import static net.osmand.plus.monitoring.TripRecordingStartingBottomSheet.UPDATE_LOGGING_INTERVAL; +import static net.osmand.plus.monitoring.TripRecordingStartingBottomFragment.UPDATE_LOGGING_INTERVAL; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.settings.backend.OsmandSettings.MONTHLY_DIRECTORY; import static net.osmand.plus.settings.backend.OsmandSettings.REC_DIRECTORY; @@ -300,8 +300,8 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment FragmentActivity activity = getActivity(); if (activity != null && !activity.isChangingConfigurations()) { Fragment target = getTargetFragment(); - if (target instanceof TripRecordingStartingBottomSheet) { - ((TripRecordingStartingBottomSheet) target).show(UPDATE_LOGGING_INTERVAL); + if (target instanceof TripRecordingStartingBottomFragment) { + ((TripRecordingStartingBottomFragment) target).show(UPDATE_LOGGING_INTERVAL); } } super.onDestroy(); diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 4067340431..52cf2ac54e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -105,7 +105,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { private final Class[] excludeParameters; @SafeVarargs - DialogMode(Class ... excludeParameters) { + DialogMode(Class... excludeParameters) { this.excludeParameters = excludeParameters; } @@ -693,9 +693,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { } public static void showInstance(MapActivity mapActivity, - Fragment targetFragment, - DialogMode dialogMode, - String appModeKey) { + Fragment targetFragment, + DialogMode dialogMode, + String appModeKey) { try { FragmentManager fm = mapActivity.getSupportFragmentManager(); if (!fm.isStateSaved()) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java index 6f6ced0203..4c0af32894 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/BaseSettingsFragment.java @@ -61,7 +61,6 @@ import net.osmand.plus.activities.OsmandInAppPurchaseActivity; import net.osmand.plus.audionotes.MultimediaNotesFragment; import net.osmand.plus.development.DevelopmentSettingsFragment; import net.osmand.plus.monitoring.MonitoringSettingsFragment; -import net.osmand.plus.monitoring.TripRecordingStartingBottomFragment; import net.osmand.plus.openplacereviews.OprSettingsFragment; import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.profiles.SelectAppModesBottomSheetDialogFragment; @@ -86,7 +85,6 @@ import java.io.Serializable; import java.util.Set; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID; -import static net.osmand.plus.monitoring.TripRecordingStartingBottomFragment.UPDATE_LOGGING_INTERVAL; public abstract class BaseSettingsFragment extends PreferenceFragmentCompat implements OnPreferenceChangeListener, OnPreferenceClickListener, AppModeChangedListener, OnConfirmPreferenceChange { @@ -293,15 +291,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } } - @Override - public void onDestroyView() { - super.onDestroyView(); - Fragment target = getTargetFragment(); - if (target instanceof TripRecordingStartingBottomFragment) { - ((TripRecordingStartingBottomFragment) target).show(UPDATE_LOGGING_INTERVAL); - } - } - @Override public void onDetach() { super.onDetach(); From e1da7bbadf3e53fc7093f7ce95616f374405f3e8 Mon Sep 17 00:00:00 2001 From: Skalii Date: Mon, 22 Mar 2021 19:05:51 +0200 Subject: [PATCH 4/4] some fixes; --- .../MonitoringSettingsFragment.java | 2 +- .../monitoring/OsmandMonitoringPlugin.java | 10 ++- .../TripRecordingBottomFragment.java | 57 ++++++------ .../TripRecordingClearDataBottomFragment.java | 14 ++- .../TripRecordingDiscardBottomFragment.java | 27 ++++-- .../TripRecordingOptionsBottomFragment.java | 87 +++++++------------ .../TripRecordingStartingBottomFragment.java | 14 +-- .../plus/track/TrackAppearanceFragment.java | 2 +- 8 files changed, 98 insertions(+), 115 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java index 8ee1de18a3..b8f5920d8d 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/MonitoringSettingsFragment.java @@ -301,7 +301,7 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment if (activity != null && !activity.isChangingConfigurations()) { Fragment target = getTargetFragment(); if (target instanceof TripRecordingStartingBottomFragment) { - ((TripRecordingStartingBottomFragment) target).show(UPDATE_LOGGING_INTERVAL); + ((TripRecordingStartingBottomFragment) target).show(); } } super.onDestroy(); diff --git a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java index de95978f7d..680fffd087 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/OsmandMonitoringPlugin.java @@ -25,6 +25,7 @@ import com.google.android.material.slider.Slider; import net.osmand.AndroidUtils; import net.osmand.Location; +import net.osmand.PlatformUtil; import net.osmand.ValueHolder; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.NavigationService; @@ -48,6 +49,8 @@ import net.osmand.plus.views.layers.MapInfoLayer; import net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget; import net.osmand.util.Algorithms; +import org.apache.commons.logging.Log; + import java.io.File; import java.lang.ref.WeakReference; import java.util.Collections; @@ -57,6 +60,7 @@ import static net.osmand.plus.UiUtilities.CompoundButtonType.PROFILE_DEPENDENT; public class OsmandMonitoringPlugin extends OsmandPlugin { + private static final Log LOG = PlatformUtil.getLog(OsmandMonitoringPlugin.class); public static final String ID = "osmand.monitoring"; public final static String OSMAND_SAVE_SERVICE_ACTION = "OSMAND_SAVE_SERVICE_ACTION"; public static final int REQUEST_LOCATION_PERMISSION_FOR_GPX_RECORDING = 208; @@ -470,12 +474,10 @@ public class OsmandMonitoringPlugin extends OsmandPlugin { try { SavingTrackHelper helper = app.getSavingTrackHelper(); SaveGpxResult result = helper.saveDataToGpx(app.getAppCustomization().getTracksDir()); - if (stopRecording) { - helper.close(); - } + helper.close(); return result; } catch (Exception e) { - e.printStackTrace(); + LOG.error(e.getMessage(), e); } return null; } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java index efed60b340..eb0d983f0e 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingBottomFragment.java @@ -38,6 +38,7 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.helpers.AndroidUiHelper; @@ -60,12 +61,12 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { public static final String TAG = TripRecordingBottomFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(TripRecordingBottomFragment.class); - private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file"; public static final String UPDATE_TRACK_ICON = "update_track_icon"; private static final int GPS_UPDATE_INTERVAL = 1000; private OsmandApplication app; private OsmandSettings settings; + private SavingTrackHelper helper; private OsmandMonitoringPlugin plugin; private View statusContainer; @@ -85,7 +86,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { } private boolean hasDataToSave() { - return app.getSavingTrackHelper().hasDataToSave(); + return helper.hasDataToSave(); } private boolean searchingGPS() { @@ -108,7 +109,9 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { public void createMenuItems(Bundle savedInstanceState) { app = requiredMyApplication(); settings = app.getSettings(); + helper = app.getSavingTrackHelper(); plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); + selectedGpxFile = helper.getCurrentTrack(); LayoutInflater inflater = UiUtilities.getInflater(getContext(), nightMode); final FragmentManager fragmentManager = getFragmentManager(); @@ -121,12 +124,6 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { updateStatus(); RecyclerView statBlocks = itemView.findViewById(R.id.block_statistics); - if (savedInstanceState != null) { - if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE) - && savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) { - selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); - } - } blockStatisticsBuilder = new GpxBlockStatisticsBuilder(app, selectedGpxFile); blockStatisticsBuilder.setBlocksView(statBlocks); blockStatisticsBuilder.setBlocksClickable(false); @@ -174,7 +171,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { @Override public void onClick(View v) { MapActivity mapActivity = getMapActivity(); - if (mapActivity != null && plugin != null && app.getSavingTrackHelper().hasDataToSave()) { + if (mapActivity != null && plugin != null && hasDataToSave()) { plugin.saveCurrentTrack(null, mapActivity); app.getNotificationHelper().refreshNotifications(); dismiss(); @@ -188,19 +185,13 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { @Override public void onClick(View v) { if (fragmentManager != null) { - TripRecordingOptionsBottomFragment.showInstance(fragmentManager, TripRecordingBottomFragment.this, selectedGpxFile); + TripRecordingOptionsBottomFragment.showInstance(fragmentManager, TripRecordingBottomFragment.this); } } }); } - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(SAVE_CURRENT_GPX_FILE, true); - } - @Override public void onResume() { super.onResume(); @@ -387,18 +378,18 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { } public static void setItemBackground(Context context, boolean nightMode, View view, boolean enabled) { - Drawable background = AppCompatResources.getDrawable(context, R.drawable.btn_background_inactive_light); + if (view instanceof CardView) { + int colorId = enabled ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode); + ((CardView) view).setCardBackgroundColor(AndroidUtils.createPressedColorStateList( + context, colorId, getActiveTextColorId(nightMode) + )); + return; + } + Drawable background = AppCompatResources.getDrawable(context, getInactiveButtonBackgroundId(nightMode)); if (background != null && enabled) { - int normalColorId = view instanceof CardView - ? getActiveTransparentColorId(nightMode) : getInactiveButtonColorId(nightMode); - ColorStateList iconColorStateList = AndroidUtils.createPressedColorStateList( - context, normalColorId, getActiveTextColorId(nightMode) - ); - if (view instanceof CardView) { - ((CardView) view).setCardBackgroundColor(iconColorStateList); - return; - } - DrawableCompat.setTintList(background, iconColorStateList); + DrawableCompat.setTintList(background, AndroidUtils.createPressedColorStateList( + context, getInactiveButtonColorId(nightMode), getActiveTextColorId(nightMode) + )); } else { UiUtilities.tintDrawable(background, ContextCompat.getColor(context, getInactiveButtonColorId(nightMode))); } @@ -483,6 +474,10 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { } } + public interface DismissTargetFragment { + void dismissTarget(); + } + @ColorRes public static int getActiveTextColorId(boolean nightMode) { return nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; @@ -513,7 +508,7 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { return nightMode ? R.color.icon_color_osmand_dark : R.color.icon_color_osmand_light; } - @DrawableRes + @ColorRes public static int getActiveTransparentColorId(boolean nightMode) { return nightMode ? R.color.switch_button_active_dark : R.color.switch_button_active_light; } @@ -533,6 +528,11 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { return nightMode ? R.drawable.btn_background_stroked_inactive_dark : R.drawable.btn_background_stroked_inactive_light; } + @DrawableRes + public static int getInactiveButtonBackgroundId(boolean nightMode) { + return nightMode ? R.drawable.btn_background_inactive_dark : R.drawable.btn_background_inactive_light; + } + @Override protected boolean hideButtonsContainer() { return true; @@ -546,5 +546,4 @@ public class TripRecordingBottomFragment extends MenuBottomSheetDialogFragment { } return null; } - } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java index e51911c867..c4bd642c1b 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingClearDataBottomFragment.java @@ -18,9 +18,8 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import static net.osmand.AndroidUtils.getPrimaryTextColorId; -import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.*; -public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogFragment { +public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment { public static final String TAG = TripRecordingClearDataBottomFragment.class.getSimpleName(); @@ -41,7 +40,7 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding); String description = getString(R.string.clear_recorded_data_warning) - .concat(getString(R.string.lost_data_warning)); + .concat("\n").concat(getString(R.string.lost_data_warning)); final View buttonClear = createItem(inflater, ItemType.CLEAR_DATA); final View buttonCancel = createItem(inflater, ItemType.CANCEL); @@ -61,7 +60,7 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF public void onClick(View v) { app.getSavingTrackHelper().clearRecordedData(true); dismiss(); - dismissTargetDialog(TripRecordingClearDataBottomFragment.this, TripRecordingOptionsBottomFragment.class); + dismissTarget(); } }) .create()); @@ -108,4 +107,11 @@ public class TripRecordingClearDataBottomFragment extends MenuBottomSheetDialogF return true; } + @Override + public void dismissTarget() { + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).dismiss(); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java index 971d7399e1..20a2889f3e 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingDiscardBottomFragment.java @@ -19,10 +19,9 @@ import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import static net.osmand.AndroidUtils.getPrimaryTextColorId; -import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.ACTION_STOP_AND_DISCARD; -import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.dismissTargetDialog; +import static net.osmand.plus.monitoring.TripRecordingOptionsBottomFragment.ACTION_STOP_AND_DISMISS; -public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFragment { +public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment { public static final String TAG = TripRecordingDiscardBottomFragment.class.getSimpleName(); @@ -43,13 +42,11 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); int verticalBig = getResources().getDimensionPixelSize(R.dimen.dialog_content_margin); int verticalNormal = getResources().getDimensionPixelSize(R.dimen.content_padding); - String description = getString(R.string.track_recording_description) - .concat(getString(R.string.lost_data_warning)); final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); final View buttonCancel = createItem(inflater, ItemType.CANCEL); items.add(new BottomSheetItemWithDescription.Builder() - .setDescription(description) + .setDescription(getString(R.string.track_recording_description)) .setDescriptionColorId(getPrimaryTextColorId(nightMode)) .setTitle(app.getString(R.string.track_recording_title)) .setLayoutId(R.layout.bottom_sheet_item_title_with_description) @@ -68,8 +65,14 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra } app.getSavingTrackHelper().clearRecordedData(true); dismiss(); - dismissTargetDialog(TripRecordingDiscardBottomFragment.this, - TripRecordingOptionsBottomFragment.class, ACTION_STOP_AND_DISCARD, true); + + Fragment target = getTargetFragment(); + if (target != null) { + Bundle args = new Bundle(); + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + target.setArguments(args); + } + dismissTarget(); } }) .create()); @@ -111,6 +114,14 @@ public class TripRecordingDiscardBottomFragment extends MenuBottomSheetDialogFra } } + @Override + public void dismissTarget() { + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingOptionsBottomFragment) { + ((TripRecordingOptionsBottomFragment) target).dismiss(); + } + } + @Override protected boolean hideButtonsContainer() { return true; diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java index aa755a4276..ee18485e78 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingOptionsBottomFragment.java @@ -11,7 +11,6 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -36,11 +35,10 @@ import net.osmand.util.Algorithms; import static net.osmand.AndroidUtils.getPrimaryTextColorId; -public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFragment { +public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFragment implements TripRecordingBottomFragment.DismissTargetFragment { public static final String TAG = TripRecordingOptionsBottomFragment.class.getSimpleName(); - public static final String ACTION_STOP_AND_DISCARD = "action_stop_and_discard"; - private static final String SAVE_CURRENT_GPX_FILE = "save_current_gpx_file"; + public static final String ACTION_STOP_AND_DISMISS = "action_stop_and_discard"; private static final int SAVE_UPDATE_INTERVAL = 1000; private OsmandApplication app; @@ -72,11 +70,10 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra return settings.SAVE_GLOBAL_TRACK_TO_GPX.get(); } - public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target, SelectedGpxFile selectedGpxFile) { + public static void showInstance(@NonNull FragmentManager fragmentManager, @NonNull Fragment target) { if (!fragmentManager.isStateSaved()) { TripRecordingOptionsBottomFragment fragment = new TripRecordingOptionsBottomFragment(); fragment.setTargetFragment(target, 0); - fragment.setSelectedGpxFile(selectedGpxFile); fragment.show(fragmentManager, TAG); } } @@ -86,18 +83,12 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra app = requiredMyApplication(); settings = app.getSettings(); helper = app.getSavingTrackHelper(); + selectedGpxFile = helper.getCurrentTrack(); LayoutInflater inflater = UiUtilities.getInflater(app, nightMode); final FragmentManager fragmentManager = getFragmentManager(); int dp16 = getResources().getDimensionPixelSize(R.dimen.content_padding); int dp36 = getResources().getDimensionPixelSize(R.dimen.context_menu_controller_height); - if (savedInstanceState != null) { - if (savedInstanceState.containsKey(SAVE_CURRENT_GPX_FILE) - && savedInstanceState.getBoolean(SAVE_CURRENT_GPX_FILE)) { - selectedGpxFile = app.getSavingTrackHelper().getCurrentTrack(); - } - } - buttonClear = createItem(inflater, ItemType.CLEAR_DATA, hasDataToSave()); final View buttonDiscard = createItem(inflater, ItemType.STOP_AND_DISCARD); final View buttonOnline = createItem(inflater, ItemType.STOP_ONLINE, hasDataToSave()); @@ -193,12 +184,6 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra } - @Override - public void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - outState.putBoolean(SAVE_CURRENT_GPX_FILE, true); - } - @Override public void onResume() { super.onResume(); @@ -213,14 +198,7 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra public void onPause() { super.onPause(); stopUpdatingTimeTrackSaved(); - Fragment target = getTargetFragment(); - if (target instanceof TripRecordingBottomFragment) { - if (isDiscard()) { - ((TripRecordingBottomFragment) target).dismiss(); - } else { - ((TripRecordingBottomFragment) target).show(); - } - } + dismissTarget(); } public void show() { @@ -237,32 +215,6 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra } } - private boolean isDiscard() { - Bundle args = getArguments(); - if (args != null) { - return args.getBoolean(ACTION_STOP_AND_DISCARD); - } - return false; - } - - protected static void dismissTargetDialog(Fragment current, Class targetClass) { - dismissTargetDialog(current, targetClass, null, null); - } - - protected static void dismissTargetDialog(Fragment current, Class targetClass, String booleanKey, Boolean value) { - if (targetClass.isInstance(current.getTargetFragment())) { - Fragment target = current.getTargetFragment(); - if (booleanKey != null && value != null) { - Bundle args = new Bundle(); - args.putBoolean(booleanKey, value); - target.setArguments(args); - } - if (target instanceof DialogFragment) { - ((DialogFragment) target).dismiss(); - } - } - } - public void stopUpdatingTimeTrackSaved() { handler.removeCallbacks(updatingTimeTrackSaved); } @@ -312,17 +264,37 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra OsmandMonitoringPlugin plugin = OsmandPlugin.getPlugin(OsmandMonitoringPlugin.class); if (mapActivity != null && plugin != null) { stopUpdatingTimeTrackSaved(); - settings.SAVE_GLOBAL_TRACK_TO_GPX.set(false); plugin.saveCurrentTrack(null, mapActivity, false, true); + Bundle args = new Bundle(); + args.putBoolean(ACTION_STOP_AND_DISMISS, true); + setArguments(args); dismiss(); - dismissTargetDialog(TripRecordingOptionsBottomFragment.this, TripRecordingBottomFragment.class); - settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true); - runUpdatingTimeTrackSaved(); + dismissTarget(); } } }; } + private boolean isDiscard() { + Bundle args = getArguments(); + if (args != null) { + return args.getBoolean(ACTION_STOP_AND_DISMISS); + } + return false; + } + + @Override + public void dismissTarget() { + Fragment target = getTargetFragment(); + if (target instanceof TripRecordingBottomFragment) { + if (isDiscard()) { + ((TripRecordingBottomFragment) target).dismiss(); + } else { + ((TripRecordingBottomFragment) target).show(); + } + } + } + @Nullable public MapActivity getMapActivity() { Activity activity = getActivity(); @@ -346,5 +318,4 @@ public class TripRecordingOptionsBottomFragment extends MenuBottomSheetDialogFra protected boolean useVerticalButtons() { return true; } - } diff --git a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java index ffbadd5557..0626b98c7d 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/TripRecordingStartingBottomFragment.java @@ -219,19 +219,13 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr dismiss(); } - public void show(String... keys) { + public void show() { Dialog dialog = getDialog(); if (dialog != null) { dialog.show(); - for (String key : keys) { - if (key.equals(UPDATE_TRACK_ICON)) { - updateTrackIcon(app, trackAppearanceIcon); - } - if (key.equals(UPDATE_LOGGING_INTERVAL)) { - updateIntervalValue(); - AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded); - } - } + updateTrackIcon(app, trackAppearanceIcon); + updateIntervalValue(); + AndroidUiHelper.updateVisibility(intervalContainer, infoExpanded); } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 958f45193a..e8bf36bc27 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -399,7 +399,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement public void onContextMenuDismiss(@NonNull ContextMenuFragment fragment) { Fragment target = getTargetFragment(); if (target instanceof TripRecordingStartingBottomFragment) { - ((TripRecordingStartingBottomFragment) target).show(UPDATE_TRACK_ICON); + ((TripRecordingStartingBottomFragment) target).show(); } else if (target instanceof TripRecordingBottomFragment) { ((TripRecordingBottomFragment) target).show(UPDATE_TRACK_ICON); }