open from settings fix

This commit is contained in:
veliymolfar 2020-04-10 19:45:02 +03:00
parent c80c93e57f
commit b1c3d03291
3 changed files with 61 additions and 6 deletions

View file

@ -67,6 +67,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
public static final String TAG = ConfigureMenuItemsFragment.class.getName();
private static final Log LOG = PlatformUtil.getLog(ConfigureMenuItemsFragment.class.getName());
private static final String APP_MODE_KEY = "app_mode_key";
private static final String ITEM_TYPE_KEY = "item_type_key";
private static final String ITEMS_ORDER_KEY = "items_order_key";
private static final String HIDDEN_ITEMS_KEY = "hidden_items_key";
@ -89,11 +90,16 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
outState.putStringArrayList(HIDDEN_ITEMS_KEY, new ArrayList<>(hiddenMenuItems));
outState.putSerializable(ITEMS_ORDER_KEY, menuItemsOrder);
outState.putSerializable(ITEM_TYPE_KEY, screenType);
outState.putString(APP_MODE_KEY, appMode.getStringKey());
}
public static ConfigureMenuItemsFragment showInstance(@NonNull FragmentManager fm, @NonNull ScreenType type) {
public static ConfigureMenuItemsFragment showInstance(
@NonNull FragmentManager fm,
@NonNull ApplicationMode appMode,
@NonNull ScreenType type) {
ConfigureMenuItemsFragment fragment = new ConfigureMenuItemsFragment();
fragment.setScreenType(type);
fragment.setAppMode(appMode);
fm.beginTransaction()
.replace(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(CONFIGURE_MENU_ITEMS_TAG)
@ -101,6 +107,13 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
return fragment;
}
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}
public ApplicationMode getAppMode() {
return appMode != null ? appMode : app.getSettings().getApplicationMode();
}
@Override
public int getStatusBarColorId() {
@ -115,7 +128,6 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requireMyApplication();
appMode = app.getSettings().getApplicationMode();
nightMode = !app.getSettings().isLightContent();
mInflater = UiUtilities.getInflater(app, nightMode);
instantiateContextMenuAdapter();
@ -123,6 +135,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
&& savedInstanceState.containsKey(ITEM_TYPE_KEY)
&& savedInstanceState.containsKey(HIDDEN_ITEMS_KEY)
&& savedInstanceState.containsKey(ITEMS_ORDER_KEY)) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
screenType = (ScreenType) savedInstanceState.getSerializable(ITEM_TYPE_KEY);
hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY);
menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);

View file

@ -20,6 +20,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@ -50,15 +51,37 @@ import java.util.List;
public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
public static final String TAG = ConfigureMenuRootFragment.class.getName();
private static final String APP_MODE_KEY = "app_mode_key";
private static final Log LOG = PlatformUtil.getLog(TAG);
private OsmandApplication app;
private LayoutInflater mInflater;
private boolean nightMode;
private ApplicationMode appMode;
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
Fragment target,
@NonNull ApplicationMode appMode) {
try {
ConfigureMenuRootFragment fragment = new ConfigureMenuRootFragment();
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0);
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, fragment, TAG)
.addToBackStack(null)
.commitAllowingStateLoss();
return true;
} catch (RuntimeException e) {
return false;
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
}
app = requireMyApplication();
nightMode = !app.getSettings().isLightContent();
mInflater = UiUtilities.getInflater(app, nightMode);
@ -67,7 +90,6 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ApplicationMode profile = app.getSettings().getApplicationMode();
View root = mInflater.inflate(R.layout.fragment_ui_customization, container, false);
Toolbar toolbar = root.findViewById(R.id.toolbar);
TextView toolbarTitle = root.findViewById(R.id.toolbar_title);
@ -92,7 +114,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
}
});
toolbarTitle.setText(R.string.ui_customization);
toolbarSubTitle.setText(profile.toHumanString());
toolbarSubTitle.setText(appMode.toHumanString());
toolbarSubTitle.setVisibility(View.VISIBLE);
List<Object> items = new ArrayList<>();
items.add(getString(R.string.ui_customization_description));
@ -102,7 +124,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
public void onItemClick(ScreenType type) {
FragmentManager fm = getFragmentManager();
if (fm != null) {
ConfigureMenuItemsFragment.showInstance(fm, type);
ConfigureMenuItemsFragment.showInstance(fm, appMode, type);
}
}
});
@ -123,6 +145,19 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
return nightMode ? R.color.activity_background_dark : R.color.activity_background_light;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(APP_MODE_KEY, getAppMode().getStringKey());
}
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}
public ApplicationMode getAppMode() {
return appMode != null ? appMode : app.getSettings().getApplicationMode();
}
private class CustomizationItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

View file

@ -392,7 +392,6 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
Preference uiCustomization = findPreference(UI_CUSTOMIZATION);
if (uiCustomization != null) {
uiCustomization.setIcon(getContentIcon(R.drawable.ic_action_ui_customization));
uiCustomization.setFragment(ConfigureMenuRootFragment.TAG);
}
}
@ -440,6 +439,14 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
}
} else if (DELETE_PROFILE.equals(prefId)) {
onDeleteProfileClick();
} else if (UI_CUSTOMIZATION.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ConfigureMenuRootFragment.showInstance(
fragmentManager,
this,
getSelectedAppMode());
}
}
return super.onPreferenceClick(preference);
}