From 8d260f7f921f2b86439aba787dd303c02a6245b2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 27 Jan 2022 12:43:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/about/AboutFragment.kt | 4 +- .../io/legado/app/ui/about/DonateFragment.kt | 4 +- .../ui/book/read/config/MoreConfigDialog.kt | 8 ++-- .../book/read/config/ReadAloudConfigDialog.kt | 8 ++-- .../app/ui/config/BackupConfigFragment.kt | 8 ++-- .../legado/app/ui/config/CheckSourceConfig.kt | 42 +++++++++++-------- .../app/ui/config/CoverConfigFragment.kt | 8 ++-- .../app/ui/config/OtherConfigFragment.kt | 8 ++-- .../app/ui/config/ThemeConfigFragment.kt | 8 ++-- .../io/legado/app/ui/main/my/MyFragment.kt | 8 ++-- .../app/ui/widget/prefs/ColorPreference.kt | 4 +- .../app/ui/widget/prefs/PreferenceCategory.kt | 2 +- 12 files changed, 59 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt index bcd91439f..3f56844c1 100644 --- a/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/AboutFragment.kt @@ -46,8 +46,8 @@ class AboutFragment : PreferenceFragmentCompat() { listView.overScrollMode = View.OVER_SCROLL_NEVER } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { "contributors" -> openUrl(R.string.contributors_url) "update_log" -> show("updateLog.md") "check_update" -> checkUpdate() diff --git a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt index 94c7a7baf..4d9f934b6 100644 --- a/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt +++ b/app/src/main/java/io/legado/app/ui/about/DonateFragment.kt @@ -29,8 +29,8 @@ class DonateFragment : PreferenceFragmentCompat() { listView.overScrollMode = View.OVER_SCROLL_NEVER } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { "wxZsm" -> requireContext().openUrl(wxZsRwmUrl) "zfbHbRwm" -> requireContext().openUrl(zfbHbRwmUrl) "zfbSkRwm" -> requireContext().openUrl(zfbSkRwmUrl) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt index 769bf9c1e..362fe5524 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt @@ -84,13 +84,13 @@ class MoreConfigDialog : DialogFragment() { super.onResume() preferenceManager .sharedPreferences - .registerOnSharedPreferenceChangeListener(this) + ?.registerOnSharedPreferenceChangeListener(this) } override fun onPause() { preferenceManager .sharedPreferences - .unregisterOnSharedPreferenceChangeListener(this) + ?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } @@ -131,8 +131,8 @@ class MoreConfigDialog : DialogFragment() { } } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { "customPageKey" -> PageKeyDialog(requireContext()).show() "clickRegionalConfig" -> { (activity as? ReadBookActivity)?.showClickRegionalConfig() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt index 8f9191f31..2bcd7490a 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudConfigDialog.kt @@ -85,16 +85,16 @@ class ReadAloudConfigDialog : DialogFragment() { override fun onResume() { super.onResume() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { PreferKey.ttsEngine -> showDialogFragment(SpeakEngineDialog()) } return super.onPreferenceTreeClick(preference) diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index ec8739dd6..6314e693b 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -129,7 +129,7 @@ class BackupConfigFragment : BasePreferenceFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) activity?.setTitle(R.string.backup_restore) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) listView.setEdgeEffectColor(primaryColor) setHasOptionsMenu(true) if (!LocalConfig.backupHelpVersionIsLast) { @@ -157,7 +157,7 @@ class BackupConfigFragment : BasePreferenceFragment(), override fun onDestroy() { super.onDestroy() - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { @@ -204,8 +204,8 @@ class BackupConfigFragment : BasePreferenceFragment(), } } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { PreferKey.backupPath -> selectBackupPath.launch() PreferKey.restoreIgnore -> backupIgnore() "web_dav_backup" -> backup() diff --git a/app/src/main/java/io/legado/app/ui/config/CheckSourceConfig.kt b/app/src/main/java/io/legado/app/ui/config/CheckSourceConfig.kt index 0be6dee25..afb1e2647 100644 --- a/app/src/main/java/io/legado/app/ui/config/CheckSourceConfig.kt +++ b/app/src/main/java/io/legado/app/ui/config/CheckSourceConfig.kt @@ -6,11 +6,11 @@ import android.view.ViewGroup import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.databinding.DialogCheckSourceConfigBinding -import io.legado.app.model.CheckSource import io.legado.app.lib.theme.primaryColor +import io.legado.app.model.CheckSource import io.legado.app.utils.setLayout -import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.toastOnUi +import io.legado.app.utils.viewbindingdelegate.viewBinding import splitties.views.onClick class CheckSourceConfig : BaseDialogFragment(R.layout.dialog_check_source_config) { @@ -31,11 +31,11 @@ class CheckSourceConfig : BaseDialogFragment(R.layout.dialog_check_source_config binding.toolBar.setBackgroundColor(primaryColor) CheckSource.run { binding.checkSourceTimeout.setText((timeout / 1000).toString()) - binding.checkSearch?.isChecked = checkSearch - binding.checkDiscovery?.isChecked = checkDiscovery - binding.checkInfo?.isChecked = checkInfo - binding.checkCategory?.isChecked = checkCategory - binding.checkContent?.isChecked = checkContent + binding.checkSearch.isChecked = checkSearch + binding.checkDiscovery.isChecked = checkDiscovery + binding.checkInfo.isChecked = checkInfo + binding.checkCategory.isChecked = checkCategory + binding.checkContent.isChecked = checkContent binding.tvCancel.onClick { dismiss() } @@ -47,22 +47,28 @@ class CheckSourceConfig : BaseDialogFragment(R.layout.dialog_check_source_config return@onClick } text.toLong() < minTimeout -> { - toastOnUi("${getString(R.string.timeout)}${getString(R.string.less_than)}${minTimeout}${getString(R.string.seconds)}") + toastOnUi( + "${getString(R.string.timeout)}${getString(R.string.less_than)}${minTimeout}${ + getString( + R.string.seconds + ) + }" + ) return@onClick } else -> timeout = text.toLong() * 1000 } - val _checkSearch = binding.checkSearch?.isChecked - val _checkDiscovery = binding.checkDiscovery?.isChecked - if (!_checkSearch && !_checkDiscovery) { - toastOnUi(getString(R.string.error_check_source_config)) - return@onClick + val mCheckSearch = binding.checkSearch.isChecked + val mCheckDiscovery = binding.checkDiscovery.isChecked + if (!mCheckSearch && !mCheckDiscovery) { + toastOnUi(getString(R.string.error_check_source_config)) + return@onClick } - checkSearch = _checkSearch - checkDiscovery = _checkDiscovery - checkInfo = binding.checkInfo?.isChecked - checkCategory = binding.checkCategory?.isChecked - checkContent = binding.checkContent?.isChecked + checkSearch = mCheckSearch + checkDiscovery = mCheckDiscovery + checkInfo = binding.checkInfo.isChecked + checkCategory = binding.checkCategory.isChecked + checkContent = binding.checkContent.isChecked putConfig() dismiss() } diff --git a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt index 3e6664953..1ce842670 100644 --- a/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt @@ -48,12 +48,12 @@ class CoverConfigFragment : BasePreferenceFragment(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onDestroy() { super.onDestroy() - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { @@ -81,8 +81,8 @@ class CoverConfigFragment : BasePreferenceFragment(), } @SuppressLint("PrivateResource") - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { selectImage.launch(requestCodeCover) diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index 31ea56012..775507b40 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -57,17 +57,17 @@ class OtherConfigFragment : BasePreferenceFragment(), override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) activity?.setTitle(R.string.other_setting) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) listView.setEdgeEffectColor(primaryColor) } override fun onDestroy() { super.onDestroy() - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { PreferKey.userAgent -> showUserAgentDialog() PreferKey.defaultBookTreeUri -> localBookTreeSelect.launch { title = getString(R.string.select_book_folder) diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 06828f99d..37a878567 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -90,12 +90,12 @@ class ThemeConfigFragment : BasePreferenceFragment(), override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onDestroy() { super.onDestroy() - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { @@ -140,8 +140,8 @@ class ThemeConfigFragment : BasePreferenceFragment(), } @SuppressLint("PrivateResource") - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (val key = preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (val key = preference.key) { PreferKey.barElevation -> NumberPickerDialog(requireContext()) .setTitle(getString(R.string.bar_elevation)) .setMaxValue(32) diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 2116abe8b..138d862fe 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -107,11 +107,11 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { override fun onResume() { super.onResume() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.registerOnSharedPreferenceChangeListener(this) } override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + preferenceManager.sharedPreferences?.unregisterOnSharedPreferenceChangeListener(this) super.onPause() } @@ -131,8 +131,8 @@ class MyFragment : BaseFragment(R.layout.fragment_my_config) { } } - override fun onPreferenceTreeClick(preference: Preference?): Boolean { - when (preference?.key) { + override fun onPreferenceTreeClick(preference: Preference): Boolean { + when (preference.key) { "bookSourceManage" -> startActivity() "replaceManage" -> startActivity() "setting" -> startActivity { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt index b9efd2398..806cb9ac9 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/ColorPreference.kt @@ -138,8 +138,8 @@ class ColorPreference(context: Context, attrs: AttributeSet) : Preference(contex } } - override fun onGetDefaultValue(a: TypedArray?, index: Int): Any { - return a!!.getInteger(index, Color.BLACK) + override fun onGetDefaultValue(a: TypedArray, index: Int): Any { + return a.getInteger(index, Color.BLACK) } override fun onColorSelected(dialogId: Int, @ColorInt color: Int) { diff --git a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt index c0c8fae2d..45cca0f19 100644 --- a/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt +++ b/app/src/main/java/io/legado/app/ui/widget/prefs/PreferenceCategory.kt @@ -29,7 +29,7 @@ class PreferenceCategory(context: Context, attrs: AttributeSet) : view.text = title if (view.isInEditMode) return view.setTextColor(context.accentColor) - view.isVisible = title != null && title.isNotEmpty() + view.isVisible = !title.isNullOrEmpty() val da = holder.findViewById(R.id.preference_divider_above) val dividerColor = if (AppConfig.isNightTheme) {