Merge branch 'r3.5'
This commit is contained in:
commit
1f73b0708c
17 changed files with 207 additions and 67 deletions
|
@ -13,6 +13,7 @@ import android.net.NetworkInfo;
|
|||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.util.Pair;
|
||||
|
@ -149,7 +150,6 @@ public class OsmandSettings {
|
|||
|
||||
/// Settings variables
|
||||
private final OsmandApplication ctx;
|
||||
private PreferencesDataStore dataStore;
|
||||
private SettingsAPI settingsAPI;
|
||||
private Object defaultProfilePreferences;
|
||||
private Object globalPreferences;
|
||||
|
@ -166,7 +166,6 @@ public class OsmandSettings {
|
|||
protected OsmandSettings(OsmandApplication clientContext, SettingsAPI settinsAPI) {
|
||||
ctx = clientContext;
|
||||
this.settingsAPI = settinsAPI;
|
||||
dataStore = new PreferencesDataStore();
|
||||
initPrefs();
|
||||
}
|
||||
|
||||
|
@ -174,7 +173,6 @@ public class OsmandSettings {
|
|||
ctx = clientContext;
|
||||
this.settingsAPI = settinsAPI;
|
||||
CUSTOM_SHARED_PREFERENCES_NAME = CUSTOM_SHARED_PREFERENCES_PREFIX + sharedPreferencesName;
|
||||
dataStore = new PreferencesDataStore();
|
||||
initPrefs();
|
||||
setCustomized();
|
||||
}
|
||||
|
@ -210,8 +208,8 @@ public class OsmandSettings {
|
|||
return settingsAPI;
|
||||
}
|
||||
|
||||
public PreferencesDataStore getDataStore() {
|
||||
return dataStore;
|
||||
public PreferencesDataStore getDataStore(@Nullable ApplicationMode appMode) {
|
||||
return new PreferencesDataStore(appMode != null ? appMode : APPLICATION_MODE.get());
|
||||
}
|
||||
|
||||
public static String getSharedPreferencesName(ApplicationMode mode) {
|
||||
|
@ -3484,38 +3482,44 @@ public class OsmandSettings {
|
|||
|
||||
public class PreferencesDataStore extends PreferenceDataStore {
|
||||
|
||||
private ApplicationMode appMode;
|
||||
|
||||
public PreferencesDataStore(@NonNull ApplicationMode appMode) {
|
||||
this.appMode = appMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putString(String key, @Nullable String value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStringSet(String key, @Nullable Set<String> values) {
|
||||
setPreference(key, values);
|
||||
setPreference(key, values, appMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putInt(String key, int value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putLong(String key, long value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putFloat(String key, float value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBoolean(String key, boolean value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
public void putValue(String key, Object value) {
|
||||
setPreference(key, value);
|
||||
setPreference(key, value, appMode);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -3523,9 +3527,9 @@ public class OsmandSettings {
|
|||
public String getString(String key, @Nullable String defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference instanceof StringPreference) {
|
||||
return ((StringPreference) preference).get();
|
||||
return ((StringPreference) preference).getModeValue(appMode);
|
||||
} else {
|
||||
Object value = preference.get();
|
||||
Object value = preference.getModeValue(appMode);
|
||||
if (value != null) {
|
||||
return value.toString();
|
||||
}
|
||||
|
@ -3543,7 +3547,7 @@ public class OsmandSettings {
|
|||
public int getInt(String key, int defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference instanceof IntPreference) {
|
||||
return ((IntPreference) preference).get();
|
||||
return ((IntPreference) preference).getModeValue(appMode);
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
@ -3552,7 +3556,7 @@ public class OsmandSettings {
|
|||
public long getLong(String key, long defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference instanceof LongPreference) {
|
||||
return ((LongPreference) preference).get();
|
||||
return ((LongPreference) preference).getModeValue(appMode);
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
@ -3561,7 +3565,7 @@ public class OsmandSettings {
|
|||
public float getFloat(String key, float defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference instanceof FloatPreference) {
|
||||
return ((FloatPreference) preference).get();
|
||||
return ((FloatPreference) preference).getModeValue(appMode);
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
@ -3570,7 +3574,7 @@ public class OsmandSettings {
|
|||
public boolean getBoolean(String key, boolean defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference instanceof BooleanPreference) {
|
||||
return ((BooleanPreference) preference).get();
|
||||
return ((BooleanPreference) preference).getModeValue(appMode);
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
@ -3579,7 +3583,7 @@ public class OsmandSettings {
|
|||
public Object getValue(String key, Object defValue) {
|
||||
OsmandPreference preference = getPreference(key);
|
||||
if (preference != null) {
|
||||
return preference.get();
|
||||
return preference.getModeValue(appMode);
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
|
|
@ -2084,7 +2084,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
try {
|
||||
String fragmentName = pref.getFragment();
|
||||
Fragment fragment = Fragment.instantiate(this, fragmentName);
|
||||
|
||||
if (caller instanceof BaseSettingsFragment) {
|
||||
fragment.setArguments(((BaseSettingsFragment) caller).buildArguments());
|
||||
}
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
|
||||
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package net.osmand.plus.profiles;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -17,9 +20,26 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
|
||||
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 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
|
||||
public void onResume() {
|
||||
|
@ -29,6 +49,22 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
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
|
||||
protected void getData() {
|
||||
activeModes.addAll(ApplicationMode.values(getMyApplication()));
|
||||
|
@ -36,7 +72,7 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
|
||||
@Override
|
||||
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
|
||||
|
@ -45,25 +81,39 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onProfilePressed(ApplicationMode item) {
|
||||
if (!(item == getMyApplication().getSettings().APPLICATION_MODE.get())) {
|
||||
getMyApplication().getSettings().APPLICATION_MODE.set(item);
|
||||
|
||||
public void onProfilePressed(ApplicationMode appMode) {
|
||||
OsmandSettings settings = getMyApplication().getSettings();
|
||||
if (appMode != this.appMode) {
|
||||
if (appModeChangeable) {
|
||||
settings.APPLICATION_MODE.set(appMode);
|
||||
}
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment instanceof AppModeChangedListener) {
|
||||
AppModeChangedListener listener = (AppModeChangedListener) targetFragment;
|
||||
listener.onAppModeChanged();
|
||||
listener.onAppModeChanged(appMode);
|
||||
}
|
||||
}
|
||||
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 {
|
||||
if (fm.findFragmentByTag(SelectAppModesBottomSheetDialogFragment.TAG) == null) {
|
||||
SelectAppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment();
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setAppModeChangeable(appModeChangeable);
|
||||
fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
|
@ -72,6 +122,6 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
}
|
||||
|
||||
public interface AppModeChangedListener {
|
||||
void onAppModeChanged();
|
||||
void onAppModeChanged(ApplicationMode appMode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,8 +31,8 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
|
|||
private static final Log LOG = PlatformUtil.getLog(SelectProfileMenuAdapter.class);
|
||||
|
||||
private List<Object> items = new ArrayList<>();
|
||||
@Nullable
|
||||
private final OsmandApplication app;
|
||||
private ApplicationMode appMode;
|
||||
@ColorRes
|
||||
private int selectedIconColorRes;
|
||||
private boolean bottomButton;
|
||||
|
@ -41,13 +41,15 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
|
|||
|
||||
private boolean nightMode;
|
||||
|
||||
public SelectProfileMenuAdapter(List<ApplicationMode> items, OsmandApplication app,
|
||||
String bottomButtonText, boolean nightMode) {
|
||||
public SelectProfileMenuAdapter(List<ApplicationMode> items, @NonNull OsmandApplication app,
|
||||
String bottomButtonText, boolean nightMode,
|
||||
@Nullable ApplicationMode appMode) {
|
||||
this.items.addAll(items);
|
||||
if (bottomButton) {
|
||||
this.items.add(BUTTON_ITEM);
|
||||
}
|
||||
this.app = app;
|
||||
this.appMode = appMode != null ? appMode : app.getSettings().getApplicationMode();
|
||||
this.bottomButton = !Algorithms.isEmpty(bottomButtonText);
|
||||
this.bottomButtonText = bottomButtonText;
|
||||
this.nightMode = nightMode;
|
||||
|
@ -103,7 +105,7 @@ public class SelectProfileMenuAdapter extends AbstractProfileMenuAdapter<SelectP
|
|||
|
||||
//set up cell color
|
||||
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);
|
||||
|
||||
if (selectedMode) {
|
||||
|
|
|
@ -21,8 +21,6 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
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.bottomsheetmenu.BaseBottomSheetItem;
|
||||
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.routing.RouteProvider;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -302,10 +301,9 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final Intent settings = new Intent(mapActivity, SettingsNavigationActivity.class);
|
||||
settings.putExtra(SettingsNavigationActivity.INTENT_SKIP_DIALOG, true);
|
||||
settings.putExtra(SettingsBaseActivity.INTENT_APP_MODE, routingHelper.getAppMode().getStringKey());
|
||||
mapActivity.startActivity(settings);
|
||||
dismiss();
|
||||
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.NAVIGATION,
|
||||
mapActivity.getRoutingHelper().getAppMode());
|
||||
}
|
||||
})
|
||||
.create();
|
||||
|
|
|
@ -66,6 +66,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
OnPreferenceClickListener, AppModeChangedListener {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(BaseSettingsFragment.class);
|
||||
private static final String APP_MODE_KEY = "app_mode_key";
|
||||
|
||||
protected OsmandApplication app;
|
||||
protected OsmandSettings settings;
|
||||
|
@ -73,6 +74,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
|
||||
protected int themeRes;
|
||||
|
||||
private ApplicationMode appMode;
|
||||
private SettingsScreenType currentScreenType;
|
||||
|
||||
private int statusBarColor = -1;
|
||||
|
@ -113,13 +115,23 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
public void onCreate(Bundle savedInstanceState) {
|
||||
app = requireMyApplication();
|
||||
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);
|
||||
currentScreenType = getCurrentScreenType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
getPreferenceManager().setPreferenceDataStore(settings.getDataStore());
|
||||
getPreferenceManager().setPreferenceDataStore(settings.getDataStore(getSelectedAppMode()));
|
||||
}
|
||||
|
||||
@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
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
@ -273,21 +291,23 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
return;
|
||||
}
|
||||
|
||||
ApplicationMode appMode = getSelectedAppMode();
|
||||
if (preference instanceof ListPreferenceEx) {
|
||||
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false);
|
||||
SingleSelectPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
|
||||
} 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) {
|
||||
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false);
|
||||
EditTextPreferenceBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
|
||||
} else if (preference instanceof MultiSelectBooleanPreference) {
|
||||
MultiSelectPreferencesBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false);
|
||||
MultiSelectPreferencesBottomSheet.showInstance(fragmentManager, preference.getKey(), this, false, appMode);
|
||||
} else {
|
||||
super.onDisplayPreferenceDialog(preference);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAppModeChanged() {
|
||||
public void onAppModeChanged(ApplicationMode appMode) {
|
||||
this.appMode = appMode;
|
||||
if (updateTheme()) {
|
||||
recreate();
|
||||
} 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() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
Fragment fragment = Fragment.instantiate(activity, currentScreenType.fragmentName);
|
||||
fragment.setArguments(buildArguments());
|
||||
FragmentManager fm = activity.getSupportFragmentManager();
|
||||
fm.popBackStack();
|
||||
fm.beginTransaction()
|
||||
|
@ -354,7 +381,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
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() {
|
||||
return settings.APPLICATION_MODE.get();
|
||||
return appMode;
|
||||
}
|
||||
|
||||
public boolean isNightMode() {
|
||||
|
@ -681,9 +709,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
}
|
||||
|
||||
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 {
|
||||
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()
|
||||
.replace(R.id.fragmentContainer, fragment, screenType.fragmentName)
|
||||
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
|
||||
|
|
|
@ -121,7 +121,8 @@ public class CoordinatesFormatFragment extends BaseSettingsFragment {
|
|||
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
if (fragmentManager != null) {
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager, settings.COORDINATES_FORMAT.getId(), newFormat, this, false);
|
||||
ChangeGeneralProfilesPrefBottomSheet.showInstance(fragmentManager,
|
||||
settings.COORDINATES_FORMAT.getId(), newFormat, this, false, getSelectedAppMode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -379,7 +379,8 @@ public class GeneralProfileSettingsFragment extends BaseSettingsFragment impleme
|
|||
if (pref instanceof CommonPreference && !((CommonPreference) pref).hasDefaultValueForMode(getSelectedAppMode())) {
|
||||
FragmentManager fragmentManager = getFragmentManager();
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
|
|||
if (app == null) {
|
||||
return;
|
||||
}
|
||||
ApplicationMode selectedMode = settings.DEFAULT_APPLICATION_MODE.get();
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
|
||||
ApplicationMode[] appModes = ApplicationMode.values(app).toArray(new ApplicationMode[0]);
|
||||
String[] entries = new String[appModes.length];
|
||||
|
|
|
@ -136,10 +136,10 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
fastRoute.setSummaryOn(R.string.shared_string_enable);
|
||||
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);
|
||||
} else {
|
||||
ApplicationMode am = app.getSettings().getApplicationMode();
|
||||
GeneralRouter router = getRouter(getMyApplication().getRoutingConfig(), am);
|
||||
clearParameters();
|
||||
if (router != null) {
|
||||
|
@ -236,9 +236,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAppModeChanged() {
|
||||
public void onAppModeChanged(ApplicationMode appMode) {
|
||||
removeRoutingPrefListeners();
|
||||
super.onAppModeChanged();
|
||||
super.onAppModeChanged(appMode);
|
||||
addRoutingPrefListeners();
|
||||
}
|
||||
|
||||
|
@ -303,7 +303,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
|||
private ListPreferenceEx createRoutingBooleanListPreference(String groupKey, List<RoutingParameter> routingParameters) {
|
||||
String defaultTitle = Algorithms.capitalizeFirstLetterAndLowercase(groupKey.replace('_', ' '));
|
||||
String title = SettingsBaseActivity.getRoutingStringPropertyName(app, groupKey, defaultTitle);
|
||||
ApplicationMode am = settings.getApplicationMode();
|
||||
ApplicationMode am = getSelectedAppMode();
|
||||
|
||||
Object[] entryValues = new Object[routingParameters.size()];
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
|
|
@ -33,7 +33,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
|
|||
vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||
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) {
|
||||
GeneralRouter router = getRouter(app.getRoutingConfig(), getSelectedAppMode());
|
||||
if (router != null) {
|
||||
|
@ -101,7 +101,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
|
|||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference.getKey().equals(GeneralRouter.DEFAULT_SPEED)) {
|
||||
RouteService routeService = app.getSettings().getApplicationMode().getRouteService();
|
||||
RouteService routeService = getSelectedAppMode().getRouteService();
|
||||
showSeekbarSettingsDialog(getActivity(), routeService == RouteService.STRAIGHT);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.support.v4.app.FragmentManager;
|
|||
import android.support.v7.preference.DialogPreference.TargetFragment;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -14,9 +15,35 @@ import java.util.List;
|
|||
public abstract class BasePreferenceBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
|
||||
public static final String PREFERENCE_ID = "preference_id";
|
||||
private static final String APP_MODE_KEY = "app_mode_key";
|
||||
|
||||
private String prefId;
|
||||
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() {
|
||||
if (prefId == null) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.drawable.LayerDrawable;
|
|||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.ContextThemeWrapper;
|
||||
|
@ -12,6 +13,7 @@ import android.view.View;
|
|||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandSettings.BooleanPreference;
|
||||
|
@ -54,7 +56,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
final OsmandSettings.BooleanPreference pref = (BooleanPreference) preference;
|
||||
final String on = getString(R.string.shared_string_on);
|
||||
final String off = getString(R.string.shared_string_off);
|
||||
boolean checked = pref.get();
|
||||
boolean checked = pref.getModeValue(getAppMode());
|
||||
|
||||
final BottomSheetItemWithCompoundButton[] preferenceBtn = new BottomSheetItemWithCompoundButton[1];
|
||||
preferenceBtn[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
|
||||
|
@ -64,7 +66,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean newValue = !pref.get();
|
||||
boolean newValue = !pref.getModeValue(getAppMode());
|
||||
if (switchPreference.callChangeListener(newValue)) {
|
||||
switchPreference.setChecked(newValue);
|
||||
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 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 bgColor = UiUtilities.getColorWithAlpha(color, 0.1f);
|
||||
int selectedColor = UiUtilities.getColorWithAlpha(color, 0.3f);
|
||||
|
@ -126,7 +128,8 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
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 {
|
||||
if (fm.findFragmentByTag(BooleanPreferenceBottomSheet.TAG) == null) {
|
||||
Bundle args = new Bundle();
|
||||
|
@ -135,6 +138,7 @@ public class BooleanPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
BooleanPreferenceBottomSheet fragment = new BooleanPreferenceBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fm, BooleanPreferenceBottomSheet.TAG);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.settings.bottomsheets;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
|
@ -61,7 +62,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.create();
|
||||
items.add(applyToAllProfiles);
|
||||
|
||||
ApplicationMode selectedAppMode = getMyApplication().getSettings().APPLICATION_MODE.get();
|
||||
ApplicationMode selectedAppMode = getAppMode();
|
||||
|
||||
BaseBottomSheetItem applyToCurrentProfile = new SimpleBottomSheetItem.Builder()
|
||||
.setTitle(getString(R.string.apply_to_current_profile, selectedAppMode.toHumanString(app)))
|
||||
|
@ -70,7 +71,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
app.getSettings().setPreference(prefId, newValue);
|
||||
app.getSettings().setPreference(prefId, newValue, getAppMode());
|
||||
updateTargetSettings(false);
|
||||
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 {
|
||||
if (fm.findFragmentByTag(ChangeGeneralProfilesPrefBottomSheet.TAG) == null) {
|
||||
Bundle args = new Bundle();
|
||||
|
@ -134,6 +136,7 @@ public class ChangeGeneralProfilesPrefBottomSheet extends BasePreferenceBottomSh
|
|||
ChangeGeneralProfilesPrefBottomSheet fragment = new ChangeGeneralProfilesPrefBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fm, ChangeGeneralProfilesPrefBottomSheet.TAG);
|
||||
}
|
||||
|
|
|
@ -3,10 +3,12 @@ package net.osmand.plus.settings.bottomsheets;
|
|||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
|
@ -87,7 +89,8 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
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 {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PREFERENCE_ID, key);
|
||||
|
@ -95,6 +98,7 @@ public class EditTextPreferenceBottomSheet extends BasePreferenceBottomSheet {
|
|||
EditTextPreferenceBottomSheet fragment = new EditTextPreferenceBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
return true;
|
||||
|
|
|
@ -2,11 +2,13 @@ package net.osmand.plus.settings.bottomsheets;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
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 {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PREFERENCE_ID, prefId);
|
||||
|
@ -163,6 +166,7 @@ public class MultiSelectPreferencesBottomSheet extends BasePreferenceBottomSheet
|
|||
MultiSelectPreferencesBottomSheet fragment = new MultiSelectPreferencesBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
return true;
|
||||
|
|
|
@ -3,11 +3,13 @@ package net.osmand.plus.settings.bottomsheets;
|
|||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
||||
|
@ -122,7 +124,8 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
|
|||
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 {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(PREFERENCE_ID, key);
|
||||
|
@ -130,6 +133,7 @@ public class SingleSelectPreferenceBottomSheet extends BasePreferenceBottomSheet
|
|||
SingleSelectPreferenceBottomSheet fragment = new SingleSelectPreferenceBottomSheet();
|
||||
fragment.setArguments(args);
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.setAppMode(appMode);
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fragmentManager, TAG);
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue