pull/1211/head
parent
1f3e13b169
commit
dd15cab020
@ -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) |
|
||||||
|
|
||||||
} |
|
@ -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…
Reference in new issue