Do not allow settings screens to change main profile - 1
This commit is contained in:
parent
8368326438
commit
a7e8b0b11b
6 changed files with 58 additions and 22 deletions
|
@ -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")
|
||||
|
|
|
@ -6,6 +6,7 @@ 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;
|
||||
|
@ -45,14 +46,15 @@ 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 != settings.APPLICATION_MODE.get()) {
|
||||
settings.APPLICATION_MODE.set(appMode);
|
||||
|
||||
Fragment targetFragment = getTargetFragment();
|
||||
if (targetFragment instanceof AppModeChangedListener) {
|
||||
AppModeChangedListener listener = (AppModeChangedListener) targetFragment;
|
||||
listener.onAppModeChanged();
|
||||
listener.onAppModeChanged(appMode);
|
||||
}
|
||||
}
|
||||
dismiss();
|
||||
|
@ -72,6 +74,6 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
|||
}
|
||||
|
||||
public interface AppModeChangedListener {
|
||||
void onAppModeChanged();
|
||||
void onAppModeChanged(ApplicationMode appMode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,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;
|
||||
|
@ -42,6 +40,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;
|
||||
|
@ -301,10 +300,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,6 +115,16 @@ 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();
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -287,7 +305,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAppModeChanged() {
|
||||
public void onAppModeChanged(ApplicationMode appMode) {
|
||||
this.appMode = appMode;
|
||||
if (updateTheme()) {
|
||||
recreate();
|
||||
} else {
|
||||
|
@ -296,10 +315,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()
|
||||
|
@ -520,7 +546,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
}
|
||||
|
||||
public ApplicationMode getSelectedAppMode() {
|
||||
return settings.APPLICATION_MODE.get();
|
||||
return appMode;
|
||||
}
|
||||
|
||||
public boolean isNightMode() {
|
||||
|
@ -681,9 +707,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")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue