Merge pull request #8400 from osmandapp/Fix_8303_general_logging_interval

Fix 8303 general logging interval ui logic changes
This commit is contained in:
max-klaus 2020-02-06 21:05:50 +03:00 committed by GitHub
commit d25ce7d4ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 5 deletions

View file

@ -37,6 +37,7 @@
android:key="save_global_track_interval" android:key="save_global_track_interval"
android:layout="@layout/preference_with_descr" android:layout="@layout/preference_with_descr"
android:title="@string/save_global_track_interval" android:title="@string/save_global_track_interval"
android:persistent="false"
tools:icon="@drawable/ic_action_time_span" tools:icon="@drawable/ic_action_time_span"
tools:summary="3 seconds" /> tools:summary="3 seconds" />

View file

@ -39,7 +39,8 @@ import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.MINUTES;
import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS; import static net.osmand.plus.monitoring.OsmandMonitoringPlugin.SECONDS;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
public class MonitoringSettingsFragment extends BaseSettingsFragment implements CopyAppModePrefsListener, ResetAppModePrefsListener { public class MonitoringSettingsFragment extends BaseSettingsFragment
implements CopyAppModePrefsListener, ResetAppModePrefsListener {
private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings"; private static final String COPY_PLUGIN_SETTINGS = "copy_plugin_settings";
private static final String RESET_TO_DEFAULT = "reset_to_default"; private static final String RESET_TO_DEFAULT = "reset_to_default";
@ -90,6 +91,12 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment implements
ListPreferenceEx saveTrackInterval = (ListPreferenceEx) findPreference(settings.SAVE_GLOBAL_TRACK_INTERVAL.getId()); ListPreferenceEx saveTrackInterval = (ListPreferenceEx) findPreference(settings.SAVE_GLOBAL_TRACK_INTERVAL.getId());
saveTrackInterval.setEntries(entry.values().toArray(new String[0])); saveTrackInterval.setEntries(entry.values().toArray(new String[0]));
saveTrackInterval.setEntryValues(entry.keySet().toArray()); saveTrackInterval.setEntryValues(entry.keySet().toArray());
ApplicationMode selectedAppMode = getSelectedAppMode();
if (!settings.SAVE_GLOBAL_TRACK_REMEMBER.getModeValue(selectedAppMode)) {
saveTrackInterval.setValue(settings.SAVE_GLOBAL_TRACK_REMEMBER.getModeValue(selectedAppMode));
} else {
saveTrackInterval.setValue(settings.SAVE_GLOBAL_TRACK_INTERVAL.getModeValue(selectedAppMode));
}
saveTrackInterval.setIcon(getActiveIcon(R.drawable.ic_action_time_span)); saveTrackInterval.setIcon(getActiveIcon(R.drawable.ic_action_time_span));
saveTrackInterval.setDescription(R.string.save_global_track_interval_descr); saveTrackInterval.setDescription(R.string.save_global_track_interval_descr);
} }
@ -333,4 +340,16 @@ public class MonitoringSettingsFragment extends BaseSettingsFragment implements
updateAllSettings(); updateAllSettings();
} }
} }
@Override
public void applySetting(String prefId, boolean applyToAllProfiles) {
if (settings.SAVE_GLOBAL_TRACK_INTERVAL.getId().equals(prefId)) {
if (applyToAllProfiles) {
app.getSettings().setPreferenceForAllModes(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), true);
} else {
app.getSettings().setPreference(settings.SAVE_GLOBAL_TRACK_REMEMBER.getId(), true, getSelectedAppMode());
}
}
}
} }

View file

@ -545,6 +545,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
updateAllSettings(); updateAllSettings();
} }
public void applySetting(String prefId, boolean applyToAllProfiles){
}
public void updateAllSettings() { public void updateAllSettings() {
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
if (screen != null) { if (screen != null) {

View file

@ -55,7 +55,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreferenceForAllModes(prefId, newValue); app.getSettings().setPreferenceForAllModes(prefId, newValue);
updateTargetSettings(false); updateTargetSettings(false, true);
dismiss(); dismiss();
} }
}) })
@ -72,7 +72,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
@Override @Override
public void onClick(View v) { public void onClick(View v) {
app.getSettings().setPreference(prefId, newValue, getAppMode()); app.getSettings().setPreference(prefId, newValue, getAppMode());
updateTargetSettings(false); updateTargetSettings(false, false);
dismiss(); dismiss();
} }
}) })
@ -86,7 +86,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
updateTargetSettings(true); updateTargetSettings(true, false);
dismiss(); dismiss();
} }
}) })
@ -105,9 +105,12 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
outState.putSerializable(NEW_VALUE_KEY, newValue); outState.putSerializable(NEW_VALUE_KEY, newValue);
} }
private void updateTargetSettings(boolean discard) { private void updateTargetSettings(boolean discard, boolean applyToAllProfiles) {
BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment(); BaseSettingsFragment target = (BaseSettingsFragment) getTargetFragment();
if (target != null) { if (target != null) {
if (!discard) {
target.applySetting(getPrefId(), applyToAllProfiles);
}
target.updateSetting(getPrefId()); target.updateSetting(getPrefId());
if (!discard) { if (!discard) {
if (target.shouldDismissOnChange()) { if (target.shouldDismissOnChange()) {