Merge branch 'r3.5' of ssh://github.com/osmandapp/Osmand into plugins_fixes

This commit is contained in:
Chumva 2019-11-12 17:01:34 +02:00
commit 05ba618930
4 changed files with 36 additions and 15 deletions

View file

@ -3390,6 +3390,6 @@ Abgedeckte Fläche: %1$s x %2$s</string>
<string name="file_import_error">%1$s Importfehler: %2$s</string>
<string name="file_imported_successfully">%1$s erfolgreich importiert.</string>
<string name="rendering_value_white_name">Weiß</string>
<string name="swap_two_places">%1 und %2 s tauschen</string>
<string name="swap_two_places">%1$s und %2$s tauschen</string>
<string name="route_start_point">Startpunkt</string>
</resources>

View file

@ -2086,7 +2086,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
Fragment fragment = Fragment.instantiate(this, fragmentName);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getSimpleName())
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getName())
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
.commit();

View file

@ -58,11 +58,12 @@ public class SelectAppModesBottomSheetDialogFragment extends AppModesBottomSheet
dismiss();
}
public static void showInstance(@NonNull FragmentManager fm, Fragment target) {
public static void showInstance(@NonNull FragmentManager fm, Fragment target, boolean usedOnMap) {
try {
if (fm.findFragmentByTag(SelectAppModesBottomSheetDialogFragment.TAG) == null) {
SelectAppModesBottomSheetDialogFragment fragment = new SelectAppModesBottomSheetDialogFragment();
fragment.setTargetFragment(target, 0);
fragment.setUsedOnMap(usedOnMap);
fragment.show(fm, SelectAppModesBottomSheetDialogFragment.TAG);
}
} catch (RuntimeException e) {

View file

@ -125,9 +125,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
@SuppressLint("RestrictedApi")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
nightMode = !settings.isLightContent();
themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
updateTheme();
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
@ -145,10 +143,17 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
setDivider(null);
view.setBackgroundColor(ContextCompat.getColor(app, getBackgroundColorRes()));
}
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
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
@ -157,11 +162,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
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.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 80));
return recyclerView;
}
@ -285,8 +288,25 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
@Override
public void onAppModeChanged() {
updateToolbar();
updateAllSettings();
if (updateTheme()) {
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();
@ -311,7 +331,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
AppBarLayout appBarLayout = (AppBarLayout) view.findViewById(R.id.appbar);
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);
toolbarTitle.setText(getPreferenceScreen().getTitle());
@ -334,7 +354,7 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
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() {
PreferenceScreen screen = getPreferenceScreen();
if (screen != null) {
getPreferenceScreen().removeAll();
screen.removeAll();
}
updatePreferencesScreen();
}