Change theme of pref screen on profile switch
This commit is contained in:
parent
299c14f2a2
commit
3dea308641
3 changed files with 35 additions and 14 deletions
|
@ -2086,7 +2086,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
Fragment fragment = Fragment.instantiate(this, fragmentName);
|
Fragment fragment = Fragment.instantiate(this, fragmentName);
|
||||||
|
|
||||||
getSupportFragmentManager().beginTransaction()
|
getSupportFragmentManager().beginTransaction()
|
||||||
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getSimpleName())
|
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
|
||||||
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
|
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
|
||||||
.commit();
|
.commit();
|
||||||
|
|
||||||
|
|
|
@ -58,11 +58,12 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm, Fragment target) {
|
public static void showInstance(@NonNull FragmentManager fm, Fragment target, boolean usedOnMap) {
|
||||||
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.show(fm, SelectAppModesBottomSheetDialogFragment.TAG);
|
fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
|
@ -125,9 +125,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
@Override
|
@Override
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
nightMode = !settings.isLightContent();
|
updateTheme();
|
||||||
themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
|
||||||
|
|
||||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||||
if (view != null) {
|
if (view != null) {
|
||||||
AndroidUtils.addStatusBarPadding21v(getContext(), view);
|
AndroidUtils.addStatusBarPadding21v(getContext(), view);
|
||||||
|
@ -145,10 +143,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
setDivider(null);
|
setDivider(null);
|
||||||
view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColorRes()));
|
view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColorRes()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean updateTheme() {
|
||||||
|
boolean nightMode = !settings.isLightContent();
|
||||||
|
boolean changed = this.nightMode != nightMode;
|
||||||
|
this.nightMode = nightMode;
|
||||||
|
this.themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||||
super.onViewCreated(view, savedInstanceState);
|
super.onViewCreated(view, savedInstanceState);
|
||||||
|
@ -157,11 +162,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
public RecyclerView onCreateRecyclerView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||||
LayoutInflater themedInflater = UiUtilities.getInflater(getActivity(), nightMode);
|
LayoutInflater themedInflater = UiUtilities.getInflater(getActivity(), isNightMode());
|
||||||
|
|
||||||
RecyclerView recyclerView = super.onCreateRecyclerView(themedInflater, parent, savedInstanceState);
|
RecyclerView recyclerView = super.onCreateRecyclerView(themedInflater, parent, savedInstanceState);
|
||||||
recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 80));
|
recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 80));
|
||||||
|
|
||||||
return recyclerView;
|
return recyclerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -285,8 +288,25 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAppModeChanged() {
|
public void onAppModeChanged() {
|
||||||
updateToolbar();
|
if (updateTheme()) {
|
||||||
updateAllSettings();
|
recreate();
|
||||||
|
} else {
|
||||||
|
updateToolbar();
|
||||||
|
updateAllSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recreate() {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
Fragment fragment = Fragment.instantiate(activity, currentScreenType.fragmentName);
|
||||||
|
FragmentManager fm = activity.getSupportFragmentManager();
|
||||||
|
fm.popBackStack();
|
||||||
|
fm.beginTransaction()
|
||||||
|
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
|
||||||
|
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract void setupPreferences();
|
protected abstract void setupPreferences();
|
||||||
|
@ -311,7 +331,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.appbar);
|
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.appbar);
|
||||||
ViewCompat.setElevation(appBarLayout, 5.0f);
|
ViewCompat.setElevation(appBarLayout, 5.0f);
|
||||||
|
|
||||||
View toolbarContainer = UiUtilities.getInflater(getActivity(), nightMode).inflate(currentScreenType.toolbarResId, appBarLayout);
|
View toolbarContainer = UiUtilities.getInflater(getActivity(), isNightMode()).inflate(currentScreenType.toolbarResId, appBarLayout);
|
||||||
|
|
||||||
TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
|
TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
|
||||||
toolbarTitle.setText(getPreferenceScreen().getTitle());
|
toolbarTitle.setText(getPreferenceScreen().getTitle());
|
||||||
|
@ -334,7 +354,7 @@ 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);
|
SelectAppModesBottomSheetDialogFragment.showInstance(fragmentManager, BaseSettingsFragment.this, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -433,7 +453,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
||||||
public void updateAllSettings() {
|
public void updateAllSettings() {
|
||||||
PreferenceScreen screen = getPreferenceScreen();
|
PreferenceScreen screen = getPreferenceScreen();
|
||||||
if (screen != null) {
|
if (screen != null) {
|
||||||
getPreferenceScreen().removeAll();
|
screen.removeAll();
|
||||||
}
|
}
|
||||||
updatePreferencesScreen();
|
updatePreferencesScreen();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue