Add check if pref was set for app mode
This commit is contained in:
parent
73af3931e8
commit
eb1b61d8bf
3 changed files with 26 additions and 18 deletions
|
@ -81,6 +81,8 @@ public class OsmandSettings {
|
|||
void removeListener(StateChangedListener<T> listener);
|
||||
|
||||
boolean isSet();
|
||||
|
||||
boolean isSetForMode(ApplicationMode m);
|
||||
}
|
||||
|
||||
private abstract class PreferenceWithListener<T> implements OsmandPreference<T> {
|
||||
|
@ -326,13 +328,12 @@ public class OsmandSettings {
|
|||
|
||||
// this value string is synchronized with settings_pref.xml preference name
|
||||
public final OsmandPreference<ApplicationMode> APPLICATION_MODE = new PreferenceWithListener<ApplicationMode>() {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return "application_mode";
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public ApplicationMode get() {
|
||||
return currentMode;
|
||||
|
@ -348,14 +349,15 @@ public class OsmandSettings {
|
|||
set(ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public boolean isSet() {
|
||||
return true;
|
||||
}
|
||||
|
||||
;
|
||||
@Override
|
||||
public boolean isSetForMode(ApplicationMode m) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean set(ApplicationMode val) {
|
||||
|
@ -582,6 +584,9 @@ public class OsmandSettings {
|
|||
return settingsAPI.contains(getPreferences(), getId());
|
||||
}
|
||||
|
||||
public boolean isSetForMode(ApplicationMode mode) {
|
||||
return settingsAPI.contains(getProfilePreferences(mode), getId());
|
||||
}
|
||||
}
|
||||
|
||||
public class BooleanPreference extends CommonPreference<Boolean> {
|
||||
|
|
|
@ -279,10 +279,15 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment {
|
|||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
OsmandSettings.OsmandPreference pref = settings.getPreference(preference.getKey());
|
||||
if (pref != null && !pref.isSetForMode(getSelectedAppMode())) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, preference.getKey(), newValue, this, false);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -41,9 +41,11 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
if (app == null || args == null || newValue == null || !args.containsKey(PREFERENCE_ID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String prefId = args.getString(PREFERENCE_ID);
|
||||
CommonPreference pref = getPreference(prefId);
|
||||
if (pref == null) {
|
||||
OsmandPreference osmandPref = app.getSettings().getPreference(prefId);
|
||||
if (pref == null || osmandPref == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,20 +53,16 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
final List<ApplicationMode> values = ApplicationMode.values(app);
|
||||
List<ApplicationMode> appModesSameValue = new ArrayList<>();
|
||||
List<ApplicationMode> appModesDefaultValue = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < values.size(); i++) {
|
||||
ApplicationMode mode = values.get(i);
|
||||
Object modeValue = pref.getModeValue(mode);
|
||||
if (modeValue instanceof Enum) {
|
||||
modeValue = ((Enum) modeValue).ordinal();
|
||||
}
|
||||
if (modeValue.equals(newValue)) {
|
||||
appModesSameValue.add(mode);
|
||||
if (!osmandPref.isSetForMode(mode)) {
|
||||
appModesDefaultValue.add(mode);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<ApplicationMode> iterator = appModesSameValue.iterator();
|
||||
Iterator<ApplicationMode> iterator = appModesDefaultValue.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
builder.append(iterator.next().toHumanString(app));
|
||||
builder.append(iterator.hasNext() ? ", " : '.');
|
||||
|
|
Loading…
Reference in a new issue