Merge branch 'r3.5'

This commit is contained in:
max-klaus 2019-11-13 21:02:26 +03:00
commit 1f73b0708c
17 changed files with 207 additions and 67 deletions

View file

@ -13,6 +13,7 @@ import android.net.NetworkInfo;
import android.os.Build; import android.os.Build;
import android.os.Environment; import android.os.Environment;
import android.support.annotation.DrawableRes; import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.annotation.StringRes; import android.support.annotation.StringRes;
import android.support.v4.util.Pair; import android.support.v4.util.Pair;
@ -149,7 +150,6 @@ public class OsmandSettings {
/// Settings variables /// Settings variables
private final OsmandApplication ctx; private final OsmandApplication ctx;
private PreferencesDataStore dataStore;
private SettingsAPI settingsAPI; private SettingsAPI settingsAPI;
private Object defaultProfilePreferences; private Object defaultProfilePreferences;
private Object globalPreferences; private Object globalPreferences;
@ -166,7 +166,6 @@ public class OsmandSettings {
protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) { protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) {
ctx = clientContext; ctx = clientContext;
this.settingsAPI = settinsAPI; this.settingsAPI = settinsAPI;
dataStore = new PreferencesDataStore();
initPrefs(); initPrefs();
} }
@ -174,7 +173,6 @@ public class OsmandSettings {
ctx = clientContext; ctx = clientContext;
this.settingsAPI = settinsAPI; this.settingsAPI = settinsAPI;
CUSTOM_SHARED_PREFERENCES_NAME = CUSTOM_SHARED_PREFERENCES_PREFIX + sharedPreferencesName; CUSTOM_SHARED_PREFERENCES_NAME = CUSTOM_SHARED_PREFERENCES_PREFIX + sharedPreferencesName;
dataStore = new PreferencesDataStore();
initPrefs(); initPrefs();
setCustomized(); setCustomized();
} }
@ -210,8 +208,8 @@ public class OsmandSettings {
return settingsAPI; return settingsAPI;
} }
public PreferencesDataStore getDataStore() { public PreferencesDataStore getDataStore(@Nullable ApplicationMode appMode) {
return dataStore; return new PreferencesDataStore(appMode != null ? appMode : APPLICATION_MODE.get());
} }
public static String getSharedPreferencesName(ApplicationMode mode) { public static String getSharedPreferencesName(ApplicationMode mode) {
@ -3484,38 +3482,44 @@ public class OsmandSettings {
public class PreferencesDataStore extends PreferenceDataStore { public class PreferencesDataStore extends PreferenceDataStore {
private ApplicationMode appMode;
public PreferencesDataStore(@NonNull ApplicationMode appMode) {
this.appMode = appMode;
}
@Override @Override
public void putString(String key, @Nullable String value) { public void putString(String key, @Nullable String value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
@Override @Override
public void putStringSet(String key, @Nullable Set<String> values) { public void putStringSet(String key, @Nullable Set<String> values) {
setPreference(key, values); setPreference(key, values, appMode);
} }
@Override @Override
public void putInt(String key, int value) { public void putInt(String key, int value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
@Override @Override
public void putLong(String key, long value) { public void putLong(String key, long value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
@Override @Override
public void putFloat(String key, float value) { public void putFloat(String key, float value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
@Override @Override
public void putBoolean(String key, boolean value) { public void putBoolean(String key, boolean value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
public void putValue(String key, Object value) { public void putValue(String key, Object value) {
setPreference(key, value); setPreference(key, value, appMode);
} }
@Nullable @Nullable
@ -3523,9 +3527,9 @@ public class OsmandSettings {
public String getString(String key, @Nullable String defValue) { public String getString(String key, @Nullable String defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference instanceof StringPreference) { if (preference instanceof StringPreference) {
return ((StringPreference) preference).get(); return ((StringPreference) preference).getModeValue(appMode);
} else { } else {
Object value = preference.get(); Object value = preference.getModeValue(appMode);
if (value != null) { if (value != null) {
return value.toString(); return value.toString();
} }
@ -3543,7 +3547,7 @@ public class OsmandSettings {
public int getInt(String key, int defValue) { public int getInt(String key, int defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference instanceof IntPreference) { if (preference instanceof IntPreference) {
return ((IntPreference) preference).get(); return ((IntPreference) preference).getModeValue(appMode);
} }
return defValue; return defValue;
} }
@ -3552,7 +3556,7 @@ public class OsmandSettings {
public long getLong(String key, long defValue) { public long getLong(String key, long defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference instanceof LongPreference) { if (preference instanceof LongPreference) {
return ((LongPreference) preference).get(); return ((LongPreference) preference).getModeValue(appMode);
} }
return defValue; return defValue;
} }
@ -3561,7 +3565,7 @@ public class OsmandSettings {
public float getFloat(String key, float defValue) { public float getFloat(String key, float defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference instanceof FloatPreference) { if (preference instanceof FloatPreference) {
return ((FloatPreference) preference).get(); return ((FloatPreference) preference).getModeValue(appMode);
} }
return defValue; return defValue;
} }
@ -3570,7 +3574,7 @@ public class OsmandSettings {
public boolean getBoolean(String key, boolean defValue) { public boolean getBoolean(String key, boolean defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference instanceof BooleanPreference) { if (preference instanceof BooleanPreference) {
return ((BooleanPreference) preference).get(); return ((BooleanPreference) preference).getModeValue(appMode);
} }
return defValue; return defValue;
} }
@ -3579,7 +3583,7 @@ public class OsmandSettings {
public Object getValue(String key, Object defValue) { public Object getValue(String key, Object defValue) {
OsmandPreference preference = getPreference(key); OsmandPreference preference = getPreference(key);
if (preference != null) { if (preference != null) {
return preference.get(); return preference.getModeValue(appMode);
} }
return defValue; return defValue;
} }

View file

@ -2084,7 +2084,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
try { try {
String fragmentName = pref.getFragment(); String fragmentName = pref.getFragment();
Fragment fragment = Fragment.instantiate(this, fragmentName); Fragment fragment = Fragment.instantiate(this, fragmentName);
if (caller instanceof BaseSettingsFragment) {
fragment.setArguments(((BaseSettingsFragment) caller).buildArguments());
}
getSupportFragmentManager().beginTransaction() getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName()) .replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
.addToBackStack(DRAWER_SETTINGS_ID + ".new") .addToBackStack(DRAWER_SETTINGS_ID + ".new")

View file

@ -1,11 +1,14 @@
package net.osmand.plus.profiles; package net.osmand.plus.profiles;
import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode; import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -17,9 +20,26 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
public static final String TAG = "SelectAppModesBottomSheetDialogFragment"; public static final String TAG = "SelectAppModesBottomSheetDialogFragment";
private static final String APP_MODE_KEY = "app_mode_key";
private static final String APP_MODE_CHANGEABLE_KEY = "app_mode_changeable_key";
private static final Log LOG = PlatformUtil.getLog(SelectAppModesBottomSheetDialogFragment.class); private static final Log LOG = PlatformUtil.getLog(SelectAppModesBottomSheetDialogFragment.class);
private List<ApplicationMode> activeModes = new ArrayList<>(); private List<ApplicationMode> activeModes = new ArrayList<>();
private ApplicationMode appMode;
private boolean appModeChangeable;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
appModeChangeable = savedInstanceState.getBoolean(APP_MODE_CHANGEABLE_KEY);
}
if (appMode == null) {
appMode = requiredMyApplication().getSettings().getApplicationMode();
}
}
@Override @Override
public void onResume() { public void onResume() {
@ -29,6 +49,22 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
setupHeightAndBackground(getView()); setupHeightAndBackground(getView());
} }
public ApplicationMode getAppMode() {
return appMode;
}
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}
public boolean isAppModeChangeable() {
return appModeChangeable;
}
public void setAppModeChangeable(boolean appModeChangeable) {
this.appModeChangeable = appModeChangeable;
}
@Override @Override
protected void getData() { protected void getData() {
activeModes.addAll(ApplicationMode.values(getMyApplication())); activeModes.addAll(ApplicationMode.values(getMyApplication()));
@ -36,7 +72,7 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
@Override @Override
protected SelectProfileMenuAdapter getMenuAdapter() { protected SelectProfileMenuAdapter getMenuAdapter() {
return new SelectProfileMenuAdapter(activeModes, getMyApplication(), getString(R.string.shared_string_manage), nightMode); return new SelectProfileMenuAdapter(activeModes, requiredMyApplication(), getString(R.string.shared_string_manage), nightMode, appMode);
} }
@Override @Override
@ -45,25 +81,39 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
} }
@Override @Override
public void onProfilePressed(ApplicationMode item) { public void onProfilePressed(ApplicationMode appMode) {
if (!(item == getMyApplication().getSettings().APPLICATION_MODE.get())) { OsmandSettings settings = getMyApplication().getSettings();
getMyApplication().getSettings().APPLICATION_MODE.set(item); if (appMode != this.appMode) {
if (appModeChangeable) {
settings.APPLICATION_MODE.set(appMode);
}
Fragment targetFragment = getTargetFragment(); Fragment targetFragment = getTargetFragment();
if (targetFragment instanceof AppModeChangedListener) { if (targetFragment instanceof AppModeChangedListener) {
AppModeChangedListener listener = (AppModeChangedListener) targetFragment; AppModeChangedListener listener = (AppModeChangedListener) targetFragment;
listener.onAppModeChanged(); listener.onAppModeChanged(appMode);
} }
} }
dismiss(); dismiss();
} }
public static void showInstance(@NonNull FragmentManager fm, Fragment target, boolean usedOnMap) { @Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (appMode != null) {
outState.putString(APP_MODE_KEY, appMode.getStringKey());
}
outState.putBoolean(APP_MODE_CHANGEABLE_KEY, appModeChangeable);
}
public static void showInstance(@NonNull FragmentManager fm, Fragment target, boolean usedOnMap,
@Nullable ApplicationMode appMode, boolean appModeChangeable) {
try { try {
if (fm.findFragmentByTag(SelectAppModesBottomSheetDialogFragment.TAG) == null) { if (fm.findFragmentByTag(SelectAppModesBottomSheetDialogFragment.TAG) == null) {
SelectAppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment(); SelectAppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment();
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setAppModeChangeable(appModeChangeable);
fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG); fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG);
} }
} catch (RuntimeException e) { } catch (RuntimeException e) {
@ -72,6 +122,6 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
} }
public interface AppModeChangedListener { public interface AppModeChangedListener {
void onAppModeChanged(); void onAppModeChanged(ApplicationMode appMode);
} }
} }

View file

@ -31,8 +31,8 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
private static final Log LOG = PlatformUtil.getLog(SelectProfileMenuAdapter.class); private static final Log LOG = PlatformUtil.getLog(SelectProfileMenuAdapter.class);
private List<Object> items = new ArrayList<>(); private List<Object> items = new ArrayList<>();
@Nullable
private final OsmandApplication app; private final OsmandApplication app;
private ApplicationMode appMode;
@ColorRes @ColorRes
private int selectedIconColorRes; private int selectedIconColorRes;
private boolean bottomButton; private boolean bottomButton;
@ -41,13 +41,15 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
private boolean nightMode; private boolean nightMode;
public SelectProfileMenuAdapter(List<ApplicationMode> items, OsmandApplication app, public SelectProfileMenuAdapter(List<ApplicationMode> items, @NonNull OsmandApplication app,
String bottomButtonText, boolean nightMode) { String bottomButtonText, boolean nightMode,
@Nullable ApplicationMode appMode) {
this.items.addAll(items); this.items.addAll(items);
if (bottomButton) { if (bottomButton) {
this.items.add(BUTTON_ITEM); this.items.add(BUTTON_ITEM);
} }
this.app = app; this.app = app;
this.appMode = appMode != null ? appMode : app.getSettings().getApplicationMode();
this.bottomButton = !Algorithms.isEmpty(bottomButtonText); this.bottomButton = !Algorithms.isEmpty(bottomButtonText);
this.bottomButtonText = bottomButtonText; this.bottomButtonText = bottomButtonText;
this.nightMode = nightMode; this.nightMode = nightMode;
@ -103,7 +105,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
//set up cell color //set up cell color
int colorNoAlpha = ContextCompat.getColor(app, profileColorResId); int colorNoAlpha = ContextCompat.getColor(app, profileColorResId);
boolean selectedMode = app.getSettings().APPLICATION_MODE.get() == item; boolean selectedMode = appMode == item;
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f); Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, colorNoAlpha, 0.3f);
if (selectedMode) { if (selectedMode) {

View file

@ -21,8 +21,6 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
@ -43,6 +41,7 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRou
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditionalRoutingItem; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditionalRoutingItem;
import net.osmand.plus.routing.RouteProvider; import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.router.GeneralRouter; import net.osmand.router.GeneralRouter;
import java.io.File; import java.io.File;
@ -302,10 +301,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class); dismiss();
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true); BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
settings.putExtra(SettingsBaseActivity.INTENT_APP_MODE, routingHelper.getAppMode().getStringKey()); mapActivity.getRoutingHelper().getAppMode());
mapActivity.startActivity(settings);
} }
}) })
.create(); .create();

View file

@ -66,6 +66,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
OnPreferenceClickListener, AppModeChangedListener { OnPreferenceClickListener, AppModeChangedListener {
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class); private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
private static final String APP_MODE_KEY = "app_mode_key";
protected OsmandApplication app; protected OsmandApplication app;
protected OsmandSettings settings; protected OsmandSettings settings;
@ -73,6 +74,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
protected int themeRes; protected int themeRes;
private ApplicationMode appMode;
private SettingsScreenType currentScreenType; private SettingsScreenType currentScreenType;
private int statusBarColor = -1; private int statusBarColor = -1;
@ -113,13 +115,23 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
app = requireMyApplication(); app = requireMyApplication();
settings = app.getSettings(); settings = app.getSettings();
Bundle args = getArguments();
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
}
if (appMode == null && args != null) {
appMode = ApplicationMode.valueOfStringKey(args.getString(APP_MODE_KEY), null);
}
if (appMode == null) {
appMode = settings.getApplicationMode();
}
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
currentScreenType = getCurrentScreenType(); currentScreenType = getCurrentScreenType();
} }
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setPreferenceDataStore(settings.getDataStore()); getPreferenceManager().setPreferenceDataStore(settings.getDataStore(getSelectedAppMode()));
} }
@Override @Override
@ -185,6 +197,12 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
}; };
} }
@Override
public void onSaveInstanceState(Bundle outState) {
outState.putString(APP_MODE_KEY, appMode.getStringKey());
super.onSaveInstanceState(outState);
}
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
@ -273,21 +291,23 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
return; return;
} }
ApplicationMode appMode = getSelectedAppMode();
if (preference instanceof ListPreferenceEx) { if (preference instanceof ListPreferenceEx) {
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false); SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else if (preference instanceof SwitchPreferenceEx) { } else if (preference instanceof SwitchPreferenceEx) {
BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false); BooleanPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else if (preference instanceof EditTextPreference) { } else if (preference instanceof EditTextPreference) {
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false); EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else if (preference instanceof MultiSelectBooleanPreference) { } else if (preference instanceof MultiSelectBooleanPreference) {
MultiSelectPreferencesBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false); MultiSelectPreferencesBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
} else { } else {
super.onDisplayPreferenceDialog(preference); super.onDisplayPreferenceDialog(preference);
} }
} }
@Override @Override
public void onAppModeChanged() { public void onAppModeChanged(ApplicationMode appMode) {
this.appMode = appMode;
if (updateTheme()) { if (updateTheme()) {
recreate(); recreate();
} else { } else {
@ -296,10 +316,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
} }
} }
public Bundle buildArguments() {
Bundle args = new Bundle();
args.putString(APP_MODE_KEY, appMode.getStringKey());
return args;
}
public void recreate() { public void recreate() {
FragmentActivity activity = getActivity(); FragmentActivity activity = getActivity();
if (activity != null) { if (activity != null) {
Fragment fragment = Fragment.instantiate(activity, currentScreenType.fragmentName); Fragment fragment = Fragment.instantiate(activity, currentScreenType.fragmentName);
fragment.setArguments(buildArguments());
FragmentManager fm = activity.getSupportFragmentManager(); FragmentManager fm = activity.getSupportFragmentManager();
fm.popBackStack(); fm.popBackStack();
fm.beginTransaction() fm.beginTransaction()
@ -354,7 +381,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
public void onClick(View v) { public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager, BaseSettingsFragment.this, false); SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager,
BaseSettingsFragment.this, false, getSelectedAppMode(), false);
} }
} }
}); });
@ -520,7 +548,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
} }
public ApplicationMode getSelectedAppMode() { public ApplicationMode getSelectedAppMode() {
return settings.APPLICATION_MODE.get(); return appMode;
} }
public boolean isNightMode() { public boolean isNightMode() {
@ -681,9 +709,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
} }
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) { public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType) {
return showInstance(activity, screenType, null);
}
public static boolean showInstance(FragmentActivity activity, SettingsScreenType screenType, @Nullable ApplicationMode appMode) {
try { try {
Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName); Fragment fragment = Fragment.instantiate(activity, screenType.fragmentName);
Bundle args = new Bundle();
if (appMode != null) {
args.putString(APP_MODE_KEY, appMode.getStringKey());
}
fragment.setArguments(args);
activity.getSupportFragmentManager().beginTransaction() activity.getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, fragment, screenType.fragmentName) .replace(R.id.fragmentContainer, fragment, screenType.fragmentName)
.addToBackStack(DRAWER_SETTINGS_ID + ".new") .addToBackStack(DRAWER_SETTINGS_ID + ".new")

View file

@ -121,7 +121,8 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) { if (fragmentManager != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, settings.COORDINATES_FORMAT.getId(), newFormat, this, false); ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager,
settings.COORDINATES_FORMAT.getId(), newFormat, this, false, getSelectedAppMode());
} }
} }
} }

View file

@ -379,7 +379,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) { if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null && newValue instanceof Serializable) { if (fragmentManager != null && newValue instanceof Serializable) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId, (Serializable) newValue, this, false); ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, prefId,
(Serializable) newValue, this, false, getSelectedAppMode());
} }
return false; return false;
} }

View file

@ -102,7 +102,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
if (app == null) { if (app == null) {
return; return;
} }
ApplicationMode selectedMode = settings.DEFAULT_APPLICATION_MODE.get(); ApplicationMode selectedMode = getSelectedAppMode();
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]); ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
String[] entries = new String[appModes.length]; String[] entries = new String[appModes.length];

View file

@ -136,10 +136,10 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
fastRoute.setSummaryOn(R.string.shared_string_enable); fastRoute.setSummaryOn(R.string.shared_string_enable);
fastRoute.setSummaryOff(R.string.shared_string_disable); fastRoute.setSummaryOff(R.string.shared_string_disable);
if (app.getSettings().getApplicationMode().getRouteService() != RouteProvider.RouteService.OSMAND) { ApplicationMode am = getSelectedAppMode();
if (am.getRouteService() != RouteProvider.RouteService.OSMAND) {
screen.addPreference(fastRoute); screen.addPreference(fastRoute);
} else { } else {
ApplicationMode am = app.getSettings().getApplicationMode();
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am); GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
clearParameters(); clearParameters();
if (router != null) { if (router != null) {
@ -236,9 +236,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
} }
@Override @Override
public void onAppModeChanged() { public void onAppModeChanged(ApplicationMode appMode) {
removeRoutingPrefListeners(); removeRoutingPrefListeners();
super.onAppModeChanged(); super.onAppModeChanged(appMode);
addRoutingPrefListeners(); addRoutingPrefListeners();
} }
@ -303,7 +303,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<RoutingParameter> routingParameters) { private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<RoutingParameter> routingParameters) {
String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' ')); String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' '));
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle); String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle);
ApplicationMode am = settings.getApplicationMode(); ApplicationMode am = getSelectedAppMode();
Object[] entryValues = new Object[routingParameters.size()]; Object[] entryValues = new Object[routingParameters.size()];
String[] entries = new String[entryValues.length]; String[] entries = new String[entryValues.length];

View file

@ -33,7 +33,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext()))); vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext())));
RouteService routeService = app.getSettings().getApplicationMode().getRouteService(); RouteService routeService = getSelectedAppMode().getRouteService();
if (routeService == RouteService.OSMAND) { if (routeService == RouteService.OSMAND) {
GeneralRouter router = getRouter(app.getRoutingConfig(), getSelectedAppMode()); GeneralRouter router = getRouter(app.getRoutingConfig(), getSelectedAppMode());
if (router != null) { if (router != null) {
@ -101,7 +101,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
@Override @Override
public boolean onPreferenceClick(Preference preference) { public boolean onPreferenceClick(Preference preference) {
if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) { if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) {
RouteService routeService = app.getSettings().getApplicationMode().getRouteService(); RouteService routeService = getSelectedAppMode().getRouteService();
showSeekbarSettingsDialog(getActivity(), routeService == RouteService.STRAIGHT); showSeekbarSettingsDialog(getActivity(), routeService == RouteService.STRAIGHT);
return true; return true;
} }

View file

@ -7,6 +7,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v7.preference.DialogPreference.TargetFragment; import android.support.v7.preference.DialogPreference.TargetFragment;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import java.util.List; import java.util.List;
@ -14,9 +15,35 @@ import java.util.List;
public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFragment { public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFragment {
public static final String PREFERENCE_ID = "preference_id"; public static final String PREFERENCE_ID = "preference_id";
private static final String APP_MODE_KEY = "app_mode_key";
private String prefId; private String prefId;
private Preference preference; private Preference preference;
private ApplicationMode appMode;
protected void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}
public ApplicationMode getAppMode() {
return appMode != null ? appMode : requiredMyApplication().getSettings().getApplicationMode();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
if (appMode != null) {
outState.putString(APP_MODE_KEY, appMode.getStringKey());
}
}
public String getPrefId() { public String getPrefId() {
if (prefId == null) { if (prefId == null) {

View file

@ -5,6 +5,7 @@ import android.graphics.drawable.LayerDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
@ -12,6 +13,7 @@ import android.view.View;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.BooleanPreference; import net.osmand.plus.OsmandSettings.BooleanPreference;
@ -54,7 +56,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference; final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
final String on = getString(R.string.shared_string_on); final String on = getString(R.string.shared_string_on);
final String off = getString(R.string.shared_string_off); final String off = getString(R.string.shared_string_off);
boolean checked = pref.get(); boolean checked = pref.getModeValue(getAppMode());
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1]; final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder() preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
@ -64,7 +66,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean newValue = !pref.get(); boolean newValue = !pref.getModeValue(getAppMode());
if (switchPreference.callChangeListener(newValue)) { if (switchPreference.callChangeListener(newValue)) {
switchPreference.setChecked(newValue); switchPreference.setChecked(newValue);
preferenceBtn[0].setTitle(newValue ? on : off); preferenceBtn[0].setTitle(newValue ? on : off);
@ -100,7 +102,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
View customView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_item_preference_switch, null); View customView = View.inflate(new ContextThemeWrapper(app, themeRes), R.layout.bottom_sheet_item_preference_switch, null);
View buttonView = customView.findViewById(R.id.button_container); View buttonView = customView.findViewById(R.id.button_container);
int colorRes = app.getSettings().APPLICATION_MODE.get().getIconColorInfo().getColor(nightMode); int colorRes = getAppMode().getIconColorInfo().getColor(nightMode);
int color = getResolvedColor(colorRes); int color = getResolvedColor(colorRes);
int bgColor = UiUtilities.getColorWithAlpha(color, 0.1f); int bgColor = UiUtilities.getColorWithAlpha(color, 0.1f);
int selectedColor = UiUtilities.getColorWithAlpha(color, 0.3f); int selectedColor = UiUtilities.getColorWithAlpha(color, 0.3f);
@ -126,7 +128,8 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
return (SwitchPreferenceEx) getPreference(); return (SwitchPreferenceEx) getPreference();
} }
public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap) { public static void showInstance(@NonNull FragmentManager fm, String prefId, Fragment target, boolean usedOnMap,
@Nullable ApplicationMode appMode) {
try { try {
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) { if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -135,6 +138,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
BooleanPreferenceBottomSheet fragment = new BooleanPreferenceBottomSheet(); BooleanPreferenceBottomSheet fragment = new BooleanPreferenceBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fm, BooleanPreferenceBottomSheet.TAG); fragment.show(fm, BooleanPreferenceBottomSheet.TAG);
} }

View file

@ -2,6 +2,7 @@ package net.osmand.plus.settings.bottomsheets;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.View; import android.view.View;
@ -61,7 +62,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
.create(); .create();
items.add(applyToAllProfiles); items.add(applyToAllProfiles);
ApplicationMode selectedAppMode = getMyApplication().getSettings().APPLICATION_MODE.get(); ApplicationMode selectedAppMode = getAppMode();
BaseBottomSheetItem applyToCurrentProfile = new SimpleBottomSheetItem.Builder() BaseBottomSheetItem applyToCurrentProfile = new SimpleBottomSheetItem.Builder()
.setTitle(getString(R.string.apply_to_current_profile, selectedAppMode.toHumanString(app))) .setTitle(getString(R.string.apply_to_current_profile, selectedAppMode.toHumanString(app)))
@ -70,7 +71,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) {
app.getSettings().setPreference(prefId, newValue); app.getSettings().setPreference(prefId, newValue, getAppMode());
updateTargetSettings(false); updateTargetSettings(false);
dismiss(); dismiss();
} }
@ -124,7 +125,8 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
} }
} }
public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target, boolean usedOnMap) { public static void showInstance(@NonNull FragmentManager fm, String prefId, Serializable newValue, Fragment target,
boolean usedOnMap, @Nullable ApplicationMode appMode) {
try { try {
if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) { if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) {
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -134,6 +136,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet(); ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG); fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG);
} }

View file

@ -3,10 +3,12 @@ package net.osmand.plus.settings.bottomsheets;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.widget.EditText; import android.widget.EditText;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
@ -87,7 +89,8 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
return (EditTextPreferenceEx) getPreference(); return (EditTextPreferenceEx) getPreference();
} }
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target, boolean usedOnMap) { public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target,
boolean usedOnMap, @Nullable ApplicationMode appMode) {
try { try {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key); args.putString(PREFERENCE_ID, key);
@ -95,6 +98,7 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
EditTextPreferenceBottomSheet fragment = new EditTextPreferenceBottomSheet(); EditTextPreferenceBottomSheet fragment = new EditTextPreferenceBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
return true; return true;

View file

@ -2,11 +2,13 @@ package net.osmand.plus.settings.bottomsheets;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.View; import android.view.View;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -155,7 +157,8 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
} }
} }
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target, boolean usedOnMap) { public static boolean showInstance(@NonNull FragmentManager fragmentManager, String prefId, Fragment target,
boolean usedOnMap, @Nullable ApplicationMode appMode) {
try { try {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PREFERENCE_ID, prefId); args.putString(PREFERENCE_ID, prefId);
@ -163,6 +166,7 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
MultiSelectPreferencesBottomSheet fragment = new MultiSelectPreferencesBottomSheet(); MultiSelectPreferencesBottomSheet fragment = new MultiSelectPreferencesBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
return true; return true;

View file

@ -3,11 +3,13 @@ package net.osmand.plus.settings.bottomsheets;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.view.View; import android.view.View;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton; import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
@ -122,7 +124,8 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
return (ListPreferenceEx) getPreference(); return (ListPreferenceEx) getPreference();
} }
public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target, boolean usedOnMap) { public static boolean showInstance(@NonNull FragmentManager fragmentManager, String key, Fragment target,
boolean usedOnMap, @Nullable ApplicationMode appMode) {
try { try {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(PREFERENCE_ID, key); args.putString(PREFERENCE_ID, key);
@ -130,6 +133,7 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
SingleSelectPreferenceBottomSheet fragment = new SingleSelectPreferenceBottomSheet(); SingleSelectPreferenceBottomSheet fragment = new SingleSelectPreferenceBottomSheet();
fragment.setArguments(args); fragment.setArguments(args);
fragment.setUsedOnMap(usedOnMap); fragment.setUsedOnMap(usedOnMap);
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0); fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG); fragment.show(fragmentManager, TAG);
return true; return true;