add new setting - show start dialog

This commit is contained in:
Skalii 2021-03-22 13:13:04 +02:00
parent 913e125968
commit 5f67fbcac6
7 changed files with 45 additions and 7 deletions

View file

@ -11,7 +11,9 @@
Thx - Hardy
-->
<string name="lost_data_warning">All unsaved data will be lost.</string>
<string name="trip_recording_show_start_dialog_setting">If disabled, recording will start right after tap on the widget or menu item, skipping the confirmation dialog.</string>
<string name="show_start_dialog">Show start dialog</string>
<string name="lost_data_warning">All unsaved data will be lost.</string>
<string name="trip_recording_save_and_continue">Save and continue</string>
<string name="trip_recording_logging_interval_info">Logging interval set time period in which OsmAnd will ask for the current location position data.</string>
<string name="select_another_colorization">Please select another type of colorization.</string>

View file

@ -4,6 +4,13 @@
xmlns:tools="http://schemas.android.com/tools"
android:title="@string/monitoring_settings">
<net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="show_trip_recording_start_dialog"
android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_disabled"
android:summaryOn="@string/shared_string_enabled"
android:title="@string/show_start_dialog" />
<PreferenceCategory
android:key="navigation"
android:layout="@layout/preference_category_with_descr"
@ -36,8 +43,8 @@
<net.osmand.plus.settings.preferences.ListPreferenceEx
android:key="save_global_track_interval"
android:layout="@layout/preference_with_descr"
android:title="@string/save_global_track_interval"
android:persistent="false"
android:title="@string/save_global_track_interval"
tools:icon="@drawable/ic_action_time_span"
tools:summary="3 seconds" />

View file

@ -856,7 +856,7 @@ public class MapActivityActions implements DialogProvider {
if (monitoringPlugin.hasDataToSave() || monitoringPlugin.wasTrackMonitored()) {
TripRecordingBottomFragment.showInstance(mapActivity.getSupportFragmentManager(), monitoringPlugin.getCurrentTrack());
} else {
TripRecordingStartingBottomFragment.showInstance(mapActivity.getSupportFragmentManager());
TripRecordingStartingBottomFragment.showInstance(mapActivity.getSupportFragmentManager(), app, monitoringPlugin.getCurrentTrack());
}
return true;
}

View file

@ -81,6 +81,8 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
@Override
protected void setupPreferences() {
setupShowStartDialog();
setupSaveTrackToGpxPref();
setupSaveTrackIntervalPref();
@ -103,6 +105,11 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment
setupResetToDefaultPref();
}
private void setupShowStartDialog() {
SwitchPreferenceEx showStartDialog = (SwitchPreferenceEx) findPreference(settings.SHOW_TRIP_REC_START_DIALOG.getId());
showStartDialog.setDescription(getString(R.string.trip_recording_show_start_dialog_setting));
}
private void setupSaveTrackToGpxPref() {
SwitchPreferenceEx saveTrackToGpx = (SwitchPreferenceEx) findPreference(settings.SAVE_TRACK_TO_GPX.getId());
saveTrackToGpx.setDescription(getString(R.string.save_track_to_gpx_descrp));

View file

@ -82,6 +82,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
pluginPreferences.add(settings.DISABLE_RECORDING_ONCE_APP_KILLED);
pluginPreferences.add(settings.SAVE_HEADING_TO_GPX);
pluginPreferences.add(settings.SHOW_TRIP_REC_NOTIFICATION);
pluginPreferences.add(settings.SHOW_TRIP_REC_START_DIALOG);
pluginPreferences.add(settings.TRACK_STORAGE_DIRECTORY);
pluginPreferences.add(settings.LIVE_MONITORING);
pluginPreferences.add(settings.LIVE_MONITORING_URL);
@ -334,7 +335,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
if (hasDataToSave() || wasTrackMonitored()) {
TripRecordingBottomFragment.showInstance(fragmentManager, getCurrentTrack());
} else {
TripRecordingStartingBottomFragment.showInstance(fragmentManager);
TripRecordingStartingBottomFragment.showInstance(fragmentManager, app, getCurrentTrack());
}
/*final boolean wasTrackMonitored = settings.SAVE_GLOBAL_TRACK_TO_GPX.get();
@ -555,7 +556,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
runnable.run();
} else if (map instanceof FragmentActivity) {
FragmentActivity activity = (FragmentActivity) map;
TripRecordingStartingBottomFragment.showInstance(activity.getSupportFragmentManager());
TripRecordingStartingBottomFragment.showInstance(activity.getSupportFragmentManager(), app, getCurrentTrack());
}
}

View file

@ -19,6 +19,7 @@ import androidx.fragment.app.FragmentManager;
import com.google.android.material.slider.RangeSlider;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -64,6 +65,19 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
}
}
public static void showInstance(@NonNull FragmentManager fragmentManager, OsmandApplication app, SelectedGpxFile selectedGpxFile) {
if (!fragmentManager.isStateSaved()) {
OsmandSettings settings = app.getSettings();
boolean showStartDialog = settings.SHOW_TRIP_REC_START_DIALOG.get();
if (showStartDialog) {
showInstance(fragmentManager);
} else {
startRecording(app);
TripRecordingBottomFragment.showInstance(fragmentManager, selectedGpxFile);
}
}
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
@ -209,13 +223,19 @@ public class TripRecordingStartingBottomFragment extends MenuBottomSheetDialogFr
upDownBtn.setImageDrawable(getContentIcon(iconId));
}
private void startRecording() {
private static void startRecording(OsmandApplication app) {
OsmandSettings settings = app.getSettings();
SavingTrackHelper helper = app.getSavingTrackHelper();
helper.startNewSegment();
settings.SAVE_GLOBAL_TRACK_TO_GPX.set(true);
app.startNavigationService(NavigationService.USED_BY_GPX);
}
private void startRecording() {
startRecording(app);
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
SavingTrackHelper helper = app.getSavingTrackHelper();
TripRecordingBottomFragment.showInstance(mapActivity.getSupportFragmentManager(), helper.getCurrentTrack());
}
dismiss();

View file

@ -1276,6 +1276,7 @@ public class OsmandSettings {
public final CommonPreference<Integer> SAVE_GLOBAL_TRACK_INTERVAL = new IntPreference(this, "save_global_track_interval", 5000).makeProfile().cache();
public final CommonPreference<Boolean> SAVE_GLOBAL_TRACK_REMEMBER = new BooleanPreference(this, "save_global_track_remember", false).makeProfile().cache();
public final CommonPreference<Boolean> SHOW_SAVED_TRACK_REMEMBER = new BooleanPreference(this, "show_saved_track_remember", true).makeGlobal().makeShared();
public final CommonPreference<Boolean> SHOW_TRIP_REC_START_DIALOG = new BooleanPreference(this, "show_trip_recording_start_dialog", true).makeGlobal().makeShared();
// this value string is synchronized with settings_pref.xml preference name
public final CommonPreference<Boolean> SAVE_TRACK_TO_GPX = new BooleanPreference(this, "save_track_to_gpx", false).makeProfile().cache();