From c02331e9be37b72d6045ed16530cd57cf155ddb5 Mon Sep 17 00:00:00 2001 From: 1552980358 <1552980358@qq.com> Date: Wed, 4 Aug 2021 17:08:28 +0800 Subject: [PATCH] Update ImageBlurringDialogFragment Signed-off-by: 1552980358 <1552980358@qq.com> --- .../ui/config/ImageBlurringDialogFragment.kt | 53 +++++++++++++++++++ .../layout/fragment_image_blurring_dialog.xml | 28 ++++++++++ 2 files changed, 81 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt create mode 100644 app/src/main/res/layout/fragment_image_blurring_dialog.xml 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 new file mode 100644 index 000000000..06065dd69 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt @@ -0,0 +1,53 @@ +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/res/layout/fragment_image_blurring_dialog.xml b/app/src/main/res/layout/fragment_image_blurring_dialog.xml new file mode 100644 index 000000000..907aff57c --- /dev/null +++ b/app/src/main/res/layout/fragment_image_blurring_dialog.xml @@ -0,0 +1,28 @@ + + + + + + + + + + \ No newline at end of file