Skip to content

Commit

Permalink
Fix slow rendering dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
hazuki0x0 committed Feb 21, 2021
1 parent 574374b commit 3108401
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ abstract class YuzuPreferenceFragment : YuzuBasePreferenceFragment() {
is SearchUrlPreference -> dialog = SearchUrlPreference.PreferenceDialog.newInstance(preference)
is NightModePreference -> dialog = NightModePreference.SettingDialog.newInstance(preference)
is WebTextSizePreference -> dialog = WebTextSizePreference.SizeDialog.newInstance(preference)
is SlowRenderingPreference -> dialog = SlowRenderingPreference.WarningDialog.newInstance(preference)
is SlowRenderingPreference -> {
SlowRenderingPreference.WarningDialog.newInstance(preference)
.show(childFragmentManager, "")
return
}
is CustomDialogPreference -> {
preference.show(childFragmentManager)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.util.AttributeSet
import androidx.preference.DialogPreference
import androidx.fragment.app.DialogFragment
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import jp.hazuki.yuzubrowser.legacy.R

Expand All @@ -36,7 +37,7 @@ class SlowRenderingPreference(context: Context, attrs: AttributeSet) : SwitchPre
}
}

class WarningDialog : androidx.fragment.app.DialogFragment() {
class WarningDialog : DialogFragment() {

companion object {
private const val ARG_KEY = "key"
Expand All @@ -52,18 +53,20 @@ class SlowRenderingPreference(context: Context, attrs: AttributeSet) : SwitchPre
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val fragment = parentFragmentManager as? DialogPreference.TargetFragment
?: throw IllegalStateException("Target fragment must implement TargetFragment" + " interface")

val key = requireArguments().getString(ARG_KEY)!!

val preference: SlowRenderingPreference = fragment.findPreference(key)!!

return AlertDialog.Builder(context).run {
setTitle(preference.title)
setTitle(R.string.pref_slow_rendering)
setMessage(R.string.pref_slow_rendering_alert)
setPositiveButton(android.R.string.ok)
{ _, _ -> if (preference.callChangeListener(true)) preference.isChecked = true }
{ _, _ ->
val fragment = parentFragment as? PreferenceFragmentCompat
?: throw IllegalStateException("This dialog is valid only for preference fragments.")

val key = requireArguments().getString(ARG_KEY)!!

val preference: SlowRenderingPreference = fragment.findPreference(key)!!

if (preference.callChangeListener(true)) preference.isChecked = true
}
setNegativeButton(android.R.string.cancel, null)
create()
}
Expand Down

0 comments on commit 3108401

Please sign in to comment.