ui: fix dialog issues
Remove some more redundant dialog styles and fix an issue where preference dialogs would crash when the screen is rotated.
This commit is contained in:
@@ -39,6 +39,8 @@ import org.oxycblt.auxio.util.logD
|
||||
/**
|
||||
* A [Fragment] that displays more information about the song, along with more media controls.
|
||||
* Instantiation is done by the navigation component, **do not instantiate this fragment manually.**
|
||||
* TODO: Turn the seekbar + durations combo into a single view that shares touch events. This could
|
||||
* also make material sliders usable maybe.
|
||||
* @author OxygenCobalt
|
||||
*/
|
||||
class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {
|
||||
|
||||
@@ -18,31 +18,35 @@
|
||||
|
||||
package org.oxycblt.auxio.settings
|
||||
|
||||
import android.util.TypedValue
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.view.ContextThemeWrapper
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import org.oxycblt.auxio.BuildConfig
|
||||
import org.oxycblt.auxio.R
|
||||
import org.oxycblt.auxio.ui.LifecycleDialog
|
||||
import org.oxycblt.auxio.util.resolveAttr
|
||||
|
||||
class IntListPrefDialog(private val pref: IntListPreference) : LifecycleDialog() {
|
||||
class IntListPrefDialog : LifecycleDialog() {
|
||||
override fun onConfigDialog(builder: AlertDialog.Builder) {
|
||||
// Don't set the title. Instead. Set a custom title view so that the padding actually
|
||||
// works between the title and this dialog's contents. I can't believe I have to do this.
|
||||
val titleView = AppCompatTextView(requireContext()).apply {
|
||||
// Since we have to store the preference key as an argument, we have to find the
|
||||
// preference we need to use manually.
|
||||
val pref = requireNotNull(
|
||||
(parentFragment as PreferenceFragmentCompat).preferenceManager
|
||||
.findPreference<IntListPreference>(requireArguments().getString(ARG_KEY, null))
|
||||
)
|
||||
|
||||
// Don't set the title. Instead, Set a custom title view so that the padding is actually a
|
||||
// uniform 16dp between the title and the list of options. I can't believe I have to do this.
|
||||
val titleView = AppCompatTextView(
|
||||
ContextThemeWrapper(
|
||||
requireContext(),
|
||||
R.style.Widget_TextView_Dialog_Title
|
||||
)
|
||||
).apply {
|
||||
text = pref.title
|
||||
typeface = ResourcesCompat.getFont(context, R.font.inter_bold)
|
||||
setTextSize(
|
||||
TypedValue.COMPLEX_UNIT_PX,
|
||||
resources.getDimensionPixelSize(R.dimen.text_size_large).toFloat()
|
||||
)
|
||||
setTextColor(android.R.attr.textColorPrimary.resolveAttr(context))
|
||||
|
||||
// We have to make the bottom padding account for the ListView's immutable top padding,
|
||||
// because Android's dialog code is a massive pile of broken spaghetti.
|
||||
val padding = resources.getDimension(R.dimen.spacing_medium).toInt()
|
||||
val paddingHack = resources.getDimension(R.dimen.spacing_small).toInt()
|
||||
|
||||
@@ -53,7 +57,6 @@ class IntListPrefDialog(private val pref: IntListPreference) : LifecycleDialog()
|
||||
|
||||
builder.setSingleChoiceItems(pref.entries, pref.getValueIndex()) { _, index ->
|
||||
pref.setValueIndex(index)
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
@@ -62,5 +65,14 @@ class IntListPrefDialog(private val pref: IntListPreference) : LifecycleDialog()
|
||||
|
||||
companion object {
|
||||
const val TAG = BuildConfig.APPLICATION_ID + ".tag.INT_PREF"
|
||||
const val ARG_KEY = BuildConfig.APPLICATION_ID + ".arg.PREF_KEY"
|
||||
|
||||
fun from(pref: IntListPreference): IntListPrefDialog {
|
||||
return IntListPrefDialog().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(ARG_KEY, pref.key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
|
||||
|
||||
override fun onDisplayPreferenceDialog(preference: Preference?) {
|
||||
if (preference is IntListPreference) {
|
||||
IntListPrefDialog(preference).show(childFragmentManager, IntListPrefDialog.TAG)
|
||||
IntListPrefDialog.from(preference).show(childFragmentManager, IntListPrefDialog.TAG)
|
||||
} else {
|
||||
super.onDisplayPreferenceDialog(preference)
|
||||
}
|
||||
|
||||
@@ -256,6 +256,8 @@ class ActionHeaderViewHolder private constructor(
|
||||
override fun onBind(data: ActionHeader) {
|
||||
binding.header = data
|
||||
|
||||
binding.executePendingBindings()
|
||||
|
||||
binding.headerButton.apply {
|
||||
TooltipCompat.setTooltipText(this, contentDescription)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user