pull/1211/head
gedoor 3 years ago
parent 1f3e13b169
commit dd15cab020
  1. 53
      app/src/main/java/io/legado/app/ui/config/ImageBlurringDialogFragment.kt
  2. 46
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  3. 26
      app/src/main/res/layout/dialog_image_blurring.xml

@ -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)
}

@ -9,6 +9,7 @@ import android.view.Menu
import android.view.MenuInflater import android.view.MenuInflater
import android.view.MenuItem import android.view.MenuItem
import android.view.View import android.view.View
import android.widget.SeekBar
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.preference.Preference import androidx.preference.Preference
import io.legado.app.R 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.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogImageBlurringBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ThemeConfig 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.image.CoverImageView
import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.prefs.ColorPreference import io.legado.app.ui.widget.prefs.ColorPreference
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File
@ -134,7 +137,10 @@ class ThemeConfigFragment : BasePreferenceFragment(),
PreferKey.cNBBackground -> { PreferKey.cNBBackground -> {
upTheme(true) upTheme(true)
} }
PreferKey.defaultCover, PreferKey.defaultCoverDark -> { PreferKey.bgImage,
PreferKey.bgImageN,
PreferKey.defaultCover,
PreferKey.defaultCoverDark -> {
upPreferenceSummary(key, getPrefString(key)) upPreferenceSummary(key, getPrefString(key))
} }
} }
@ -183,8 +189,12 @@ class ThemeConfigFragment : BasePreferenceFragment(),
} }
} }
} }
PreferKey.bgImageBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageBlurring) { upTheme(false) }.show(parentFragmentManager) PreferKey.bgImageBlurring -> alertImageBlurring(PreferKey.bgImageBlurring) {
PreferKey.bgImageNBlurring -> ImageBlurringDialogFragment(PreferKey.bgImageNBlurring) { upTheme(true) }.show(parentFragmentManager) upTheme(false)
}
PreferKey.bgImageNBlurring -> alertImageBlurring(PreferKey.bgImageNBlurring) {
upTheme(true)
}
PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) { PreferKey.defaultCover -> if (getPrefString(PreferKey.defaultCover).isNullOrEmpty()) {
selectImage.launch(requestCodeCover) selectImage.launch(requestCodeCover)
} else { } else {
@ -235,6 +245,34 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}.show() }.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) { private fun upTheme(isNightTheme: Boolean) {
if (AppConfig.isNightTheme == isNightTheme) { if (AppConfig.isNightTheme == isNightTheme) {
listView.post { listView.post {
@ -276,7 +314,6 @@ class ThemeConfigFragment : BasePreferenceFragment(),
}.getOrNull()?.let { byteArray -> }.getOrNull()?.let { byteArray ->
file.writeBytes(byteArray) file.writeBytes(byteArray)
putPrefString(preferenceKey, file.absolutePath) putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success() success()
} ?: toastOnUi("获取文件出错") } ?: toastOnUi("获取文件出错")
} }
@ -295,7 +332,6 @@ class ThemeConfigFragment : BasePreferenceFragment(),
file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name) file = FileUtils.createFileIfNotExist(file, preferenceKey, imgFile.name)
file.writeBytes(imgFile.readBytes()) file.writeBytes(imgFile.readBytes())
putPrefString(preferenceKey, file.absolutePath) putPrefString(preferenceKey, file.absolutePath)
upPreferenceSummary(preferenceKey, file.absolutePath)
success() success()
} }
} }

@ -1,28 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"> android:padding="10dp">
<androidx.appcompat.widget.AppCompatSeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="25"
android:id="@+id/seek_bar" />
<TextView <TextView
android:id="@+id/text_view_value"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/text_view_value" android:padding="6dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:textSize="17sp" android:textColor="@color/primaryText"
android:textColor="@color/black"/> android:textSize="17sp" />
<androidx.appcompat.widget.AppCompatSeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="6dp"
android:max="25" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/background_image_hint" /> android:text="@string/background_image_hint" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save