diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/ThemeSettingsFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/ThemeSettingsFragment.java index 1caaba44ab..386f000e39 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/ThemeSettingsFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/ThemeSettingsFragment.java @@ -14,6 +14,7 @@ import com.kunfei.bookshelf.MApplication; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.help.RxBusTag; +import com.kunfei.bookshelf.utils.ColorUtil; import com.kunfei.bookshelf.utils.Theme.ATH; import com.kunfei.bookshelf.view.activity.ThemeSettingActivity; @@ -72,6 +73,7 @@ public void onPause() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + AlertDialog alertDialog; switch (key) { case "immersionStatusBar": case "navigationBarColorChange": @@ -81,24 +83,55 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin case "colorPrimary": case "colorAccent": case "colorBackground": - MApplication.getInstance().upThemeStore(); - RxBus.get().post(RxBusTag.RECREATE, true); - if (!settingActivity.isNightTheme()) { - new Handler().postDelayed(() -> getActivity().recreate(), 200); + if (!ColorUtil.isColorLight(sharedPreferences.getInt("colorBackground", settingActivity.getResources().getColor(R.color.md_grey_100)))) { + alertDialog = new AlertDialog.Builder(getActivity()) + .setTitle("白天背景太暗") + .setMessage("将会恢复默认背景?") + .setPositiveButton(R.string.ok, (dialog, which) -> { + settingActivity.preferences.edit().putInt("colorBackground", settingActivity.getResources().getColor(R.color.md_grey_100)).apply(); + upTheme(false); + }) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + upTheme(false); + }) + .show(); + ATH.setAlertDialogTint(alertDialog); + } else { + upTheme(false); } break; case "colorPrimaryNight": case "colorAccentNight": case "colorBackgroundNight": - MApplication.getInstance().upThemeStore(); - RxBus.get().post(RxBusTag.RECREATE, true); - if (settingActivity.isNightTheme()) { - new Handler().postDelayed(() -> getActivity().recreate(), 200); + if (ColorUtil.isColorLight(sharedPreferences.getInt("colorBackgroundNight", settingActivity.getResources().getColor(R.color.md_grey_800)))) { + alertDialog = new AlertDialog.Builder(getActivity()) + .setTitle("夜间背景太亮") + .setMessage("将会恢复默认背景?") + .setPositiveButton(R.string.ok, (dialog, which) -> { + settingActivity.preferences.edit().putInt("colorBackgroundNight", settingActivity.getResources().getColor(R.color.md_grey_800)).apply(); + upTheme(true); + }) + .setNegativeButton(R.string.cancel, (dialogInterface, i) -> { + upTheme(true); + }) + .show(); + ATH.setAlertDialogTint(alertDialog); + + } else { + upTheme(true); } break; } } + private void upTheme(boolean isNightTheme) { + if (settingActivity.isNightTheme() == isNightTheme) { + MApplication.getInstance().upThemeStore(); + RxBus.get().post(RxBusTag.RECREATE, true); + new Handler().postDelayed(() -> getActivity().recreate(), 200); + } + } + @Override public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { if (Objects.equals(preference.getKey(), "defaultTheme")) {