From dd15cab020c7e9f56d55bb6eab0cbc031c08adb5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 5 Aug 2021 09:34:32 +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 --- .../ui/config/ImageBlurringDialogFragment.kt | 53 ------------------- .../app/ui/config/ThemeConfigFragment.kt | 46 ++++++++++++++-- ...g_dialog.xml => dialog_image_blurring.xml} | 26 ++++----- 3 files changed, 55 insertions(+), 70 deletions(-) delete mode 100644 app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt rename app/src/main/res/layout/{fragment_image_blurring_dialog.xml => dialog_image_blurring.xml} (67%) diff --git a/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt b/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt deleted file mode 100644 index 06065dd69..000000000 --- a/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt +++ /dev/null @@ -1,53 +0,0 @@ -package io.legado.app.ui.config - -import android.app.Dialog -import android.content.SharedPreferences -import android.os.Bundle -import android.widget.SeekBar -import androidx.appcompat.app.AlertDialog -import androidx.fragment.app.DialogFragment -import androidx.fragment.app.FragmentManager -import androidx.preference.PreferenceManager -import io.legado.app.R -import io.legado.app.databinding.FragmentImageBlurringDialogBinding - -class ImageBlurringDialogFragment(private val prefName: String, private val block: () -> Unit): DialogFragment() { - - companion object { - private const val DEFAULT_VALUE = 0 - private const val TAG = "ImageBlurringDialogFragment" - } - - private val requireContext get() = requireContext() - private var _fragmentImageBlurringDialogBinding: FragmentImageBlurringDialogBinding? = null - private val fragmentImageBlurringDialog get() = _fragmentImageBlurringDialogBinding!! - private lateinit var sharedPreference: SharedPreferences - - override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { - _fragmentImageBlurringDialogBinding = FragmentImageBlurringDialogBinding.inflate(layoutInflater) - sharedPreference = PreferenceManager.getDefaultSharedPreferences(requireContext) - sharedPreference.getInt(prefName, DEFAULT_VALUE).apply { - fragmentImageBlurringDialog.seekBar.progress = this - fragmentImageBlurringDialog.textViewValue.text = this.toString() - } - fragmentImageBlurringDialog.seekBar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - fragmentImageBlurringDialog.textViewValue.text = progress.toString() - } - override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit - override fun onStopTrackingTouch(seekBar: SeekBar?) = Unit - }) - return AlertDialog.Builder(requireContext) - .setTitle(R.string.background_image_blurring_radius) - .setView(fragmentImageBlurringDialog.root) - .setPositiveButton(R.string.dialog_confirm) { _, _ -> - sharedPreference.edit().putInt(prefName, fragmentImageBlurringDialog.seekBar.progress).commit() - block() - } - .setNegativeButton(R.string.dialog_cancel) { _, _ -> } - .create() - } - - fun show(fragmentManager: FragmentManager) = show(fragmentManager, TAG) - -} \ No newline at end of file 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 44c7f0b28..510819f23 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 @@ -9,6 +9,7 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View +import android.widget.SeekBar import androidx.documentfile.provider.DocumentFile import androidx.preference.Preference import io.legado.app.R @@ -17,6 +18,7 @@ import io.legado.app.constant.AppConst import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogEditTextBinding +import io.legado.app.databinding.DialogImageBlurringBinding import io.legado.app.help.AppConfig import io.legado.app.help.LauncherIconHelp import io.legado.app.help.ThemeConfig @@ -28,6 +30,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.image.CoverImageView import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.ColorPreference +import io.legado.app.ui.widget.seekbar.SeekBarChangeListener import io.legado.app.utils.* import java.io.File @@ -134,7 +137,10 @@ class ThemeConfigFragment : BasePreferenceFragment(), PreferKey.cNBBackground -> { upTheme(true) } - PreferKey.defaultCover, PreferKey.defaultCoverDark -> { + PreferKey.bgImage, + PreferKey.bgImageN, + PreferKey.defaultCover, + PreferKey.defaultCoverDark -> { upPreferenceSummary(key, getPrefString(key)) } } @@ -183,8 +189,12 @@ class ThemeConfigFragment : BasePreferenceFragment(), } } } - PreferKey.bgImageBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager) - PreferKey.bgImageNBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageNBlurring) { upTheme(true) }.show(parentFragmentManager) + PreferKey.bgImageBlurring -> alertImageBlurring(PreferKey.bgImageBlurring) { + upTheme(false) + } + PreferKey.bgImageNBlurring -> alertImageBlurring(PreferKey.bgImageNBlurring) { + upTheme(true) + } PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { selectImage.launch(requestCodeCover) } else { @@ -235,6 +245,34 @@ class ThemeConfigFragment : BasePreferenceFragment(), }.show() } + private fun alertImageBlurring(preferKey: String, success: () -> Unit) { + alert(R.string.background_image_blurring) { + val alertBinding = DialogImageBlurringBinding.inflate(layoutInflater).apply { + getPrefInt(preferKey, 0).let { + seekBar.progress = it + textViewValue.text = it.toString() + } + seekBar.setOnSeekBarChangeListener(object : SeekBarChangeListener { + override fun onProgressChanged( + seekBar: SeekBar, + progress: Int, + fromUser: Boolean + ) { + textViewValue.text = progress.toString() + } + }) + } + customView { alertBinding.root } + okButton { + alertBinding.seekBar.progress.let { + putPrefInt(preferKey, it) + success.invoke() + } + } + noButton() + }.show() + } + private fun upTheme(isNightTheme: Boolean) { if (AppConfig.isNightTheme == isNightTheme) { listView.post { @@ -276,7 +314,6 @@ class ThemeConfigFragment : BasePreferenceFragment(), }.getOrNull()?.let { byteArray -> file.writeBytes(byteArray) putPrefString(preferenceKey, file.absolutePath) - upPreferenceSummary(preferenceKey, file.absolutePath) success() } ?: toastOnUi("获取文件出错") } @@ -295,7 +332,6 @@ class ThemeConfigFragment : BasePreferenceFragment(), file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) file.writeBytes(imgFile.readBytes()) putPrefString(preferenceKey, file.absolutePath) - upPreferenceSummary(preferenceKey, file.absolutePath) success() } } diff --git a/app/src/main/res/layout/fragment_image_blurring_dialog.xml b/app/src/main/res/layout/dialog_image_blurring.xml similarity index 67% rename from app/src/main/res/layout/fragment_image_blurring_dialog.xml rename to app/src/main/res/layout/dialog_image_blurring.xml index 907aff57c..b9d20e55e 100644 --- a/app/src/main/res/layout/fragment_image_blurring_dialog.xml +++ b/app/src/main/res/layout/dialog_image_blurring.xml @@ -1,28 +1,30 @@ - - - + android:textColor="@color/primaryText" + android:textSize="17sp" /> + + \ No newline at end of file