mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Simplify BasePreferenceFragment.kt
and remove duplicated calls
This commit is contained in:
parent
648949e360
commit
715e1b6f7c
@ -6,7 +6,6 @@ import androidx.preference.Preference
|
|||||||
import androidx.preference.PreferenceFragmentCompat
|
import androidx.preference.PreferenceFragmentCompat
|
||||||
import com.github.libretube.R
|
import com.github.libretube.R
|
||||||
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
import com.github.libretube.databinding.DialogTextPreferenceBinding
|
||||||
import com.github.libretube.helpers.PreferenceHelper
|
|
||||||
import com.github.libretube.ui.activities.SettingsActivity
|
import com.github.libretube.ui.activities.SettingsActivity
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
|
||||||
@ -32,14 +31,8 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(preference.title)
|
.setTitle(preference.title)
|
||||||
.setSingleChoiceItems(preference.entries, prefIndex) { dialog, index ->
|
.setSingleChoiceItems(preference.entries, prefIndex) { dialog, index ->
|
||||||
|
|
||||||
// get the new ListPreference value
|
// get the new ListPreference value
|
||||||
val newValue = preference.entryValues[index].toString()
|
val newValue = preference.entryValues[index].toString()
|
||||||
|
|
||||||
// save the new value and call the onPreferenceChange Method
|
|
||||||
preference.value = newValue
|
|
||||||
preference.callChangeListener(newValue)
|
|
||||||
|
|
||||||
// invoke the on change listeners
|
// invoke the on change listeners
|
||||||
if (preference.callChangeListener(newValue)) {
|
if (preference.callChangeListener(newValue)) {
|
||||||
preference.value = newValue
|
preference.value = newValue
|
||||||
@ -51,12 +44,7 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
}
|
}
|
||||||
is EditTextPreference -> {
|
is EditTextPreference -> {
|
||||||
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
|
val binding = DialogTextPreferenceBinding.inflate(layoutInflater)
|
||||||
binding.input.setText(
|
binding.input.setText(preference.text)
|
||||||
PreferenceHelper.getString(
|
|
||||||
preference.key,
|
|
||||||
""
|
|
||||||
)
|
|
||||||
)
|
|
||||||
MaterialAlertDialogBuilder(requireContext())
|
MaterialAlertDialogBuilder(requireContext())
|
||||||
.setTitle(preference.title)
|
.setTitle(preference.title)
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
@ -66,7 +54,7 @@ abstract class BasePreferenceFragment : PreferenceFragmentCompat() {
|
|||||||
preference.text = newValue
|
preference.text = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
.setNegativeButton(R.string.cancel, null)
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user