Invert disableComplexRouting in UI

This commit is contained in:
Vitaliy 2020-10-09 00:01:15 +03:00
parent 0b7ebe6c7a
commit 213a3171f1
3 changed files with 25 additions and 15 deletions

View file

@ -11,7 +11,6 @@ import net.osmand.plus.Version;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.util.SunriseSunset;
import java.text.SimpleDateFormat;
@ -60,11 +59,9 @@ public class DevelopmentSettingsFragment extends BaseSettingsFragment {
private void setupOpenglRenderPref() {
SwitchPreferenceEx useOpenglRender = findPreference(settings.USE_OPENGL_RENDER.getId());
if (Version.isOpenGlAvailable(app)) {
assert useOpenglRender != null;
useOpenglRender.setDescription(getString(R.string.use_opengl_render_descr));
useOpenglRender.setIconSpaceReserved(false);
} else {
assert useOpenglRender != null;
useOpenglRender.setVisible(false);
}
}

View file

@ -43,8 +43,12 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore {
@Override
public void putBoolean(String key, boolean value) {
if (osmandSettings.DISABLE_COMPLEX_ROUTING.getId().equals(key)) {
osmandSettings.setPreference(key, !value, appMode);
} else {
osmandSettings.setPreference(key, value, appMode);
}
}
public void putValue(String key, Object value) {
osmandSettings.setPreference(key, value, appMode);
@ -102,7 +106,11 @@ public class OsmAndPreferencesDataStore extends PreferenceDataStore {
public boolean getBoolean(String key, boolean defValue) {
OsmandPreference<?> preference = osmandSettings.getPreference(key);
if (preference instanceof BooleanPreference) {
return ((BooleanPreference) preference).getModeValue(appMode);
BooleanPreference booleanPreference = (BooleanPreference) preference;
if (osmandSettings.DISABLE_COMPLEX_ROUTING.getId().equals(booleanPreference.getId())) {
return !booleanPreference.getModeValue(appMode);
}
return booleanPreference.getModeValue(appMode);
}
return defValue;
}

View file

@ -6,7 +6,6 @@ import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -26,19 +25,19 @@ import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.slider.Slider;
import net.osmand.StateChangedListener;
import net.osmand.plus.Version;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.backend.BooleanPreference;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.BooleanPreference;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.settings.bottomsheets.RecalculateRouteInDeviationBottomSheet;
import net.osmand.plus.settings.preferences.ListPreferenceEx;
import net.osmand.plus.settings.preferences.MultiSelectBooleanPreference;
@ -190,14 +189,12 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
}
private void setupDisableComplexRoutingPref() {
boolean enabled = !settings.DISABLE_COMPLEX_ROUTING.get(); // pref ui was inverted
SwitchPreferenceEx disableComplexRouting = createSwitchPreferenceEx(settings.DISABLE_COMPLEX_ROUTING.getId(),
R.string.use_complex_routing, R.layout.preference_with_descr_dialog_and_switch);
disableComplexRouting.setDescription(getString(R.string.complex_routing_descr));
disableComplexRouting.setSummaryOn(R.string.shared_string_enabled);
disableComplexRouting.setSummaryOff(R.string.shared_string_disabled);
disableComplexRouting.setIconSpaceReserved(true);
disableComplexRouting.setChecked(enabled);
getPreferenceScreen().addPreference(disableComplexRouting);
}
@ -520,6 +517,14 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (settings.DISABLE_COMPLEX_ROUTING.getId().equals(preference.getKey()) && newValue instanceof Boolean) {
return onConfirmPreferenceChange(preference.getKey(), !(Boolean) newValue, getApplyQueryType()); // pref ui was inverted
}
return onConfirmPreferenceChange(preference.getKey(), newValue, getApplyQueryType());
}
@Override
public void onApplyPreferenceChange(String prefId, boolean applyToAllProfiles, Object newValue) {
if ((RELIEF_SMOOTHNESS_FACTOR.equals(prefId) || DRIVING_STYLE.equals(prefId)) && newValue instanceof String) {