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:
OxygenCobalt 2021-09-12 16:13:53 -06:00
parent 744e4172f3
commit c9dd3b97a2
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
6 changed files with 37 additions and 35 deletions

View file

@ -39,6 +39,8 @@ import org.oxycblt.auxio.util.logD
/** /**
* A [Fragment] that displays more information about the song, along with more media controls. * 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.** * 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 * @author OxygenCobalt
*/ */
class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener { class PlaybackFragment : Fragment(), SeekBar.OnSeekBarChangeListener {

View file

@ -18,31 +18,35 @@
package org.oxycblt.auxio.settings package org.oxycblt.auxio.settings
import android.util.TypedValue import android.os.Bundle
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.view.ContextThemeWrapper
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
import androidx.preference.PreferenceFragmentCompat
import org.oxycblt.auxio.BuildConfig import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R import org.oxycblt.auxio.R
import org.oxycblt.auxio.ui.LifecycleDialog 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) { override fun onConfigDialog(builder: AlertDialog.Builder) {
// Don't set the title. Instead. Set a custom title view so that the padding actually // Since we have to store the preference key as an argument, we have to find the
// works between the title and this dialog's contents. I can't believe I have to do this. // preference we need to use manually.
val titleView = AppCompatTextView(requireContext()).apply { val pref = requireNotNull(
text = pref.title (parentFragment as PreferenceFragmentCompat).preferenceManager
typeface = ResourcesCompat.getFont(context, R.font.inter_bold) .findPreference<IntListPreference>(requireArguments().getString(ARG_KEY, null))
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, // Don't set the title. Instead, Set a custom title view so that the padding is actually a
// because Android's dialog code is a massive pile of broken spaghetti. // 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
val padding = resources.getDimension(R.dimen.spacing_medium).toInt() val padding = resources.getDimension(R.dimen.spacing_medium).toInt()
val paddingHack = resources.getDimension(R.dimen.spacing_small).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 -> builder.setSingleChoiceItems(pref.entries, pref.getValueIndex()) { _, index ->
pref.setValueIndex(index) pref.setValueIndex(index)
dismiss() dismiss()
} }
@ -62,5 +65,14 @@ class IntListPrefDialog(private val pref: IntListPreference) : LifecycleDialog()
companion object { companion object {
const val TAG = BuildConfig.APPLICATION_ID + ".tag.INT_PREF" 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)
}
}
}
} }
} }

View file

@ -74,7 +74,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
override fun onDisplayPreferenceDialog(preference: Preference?) { override fun onDisplayPreferenceDialog(preference: Preference?) {
if (preference is IntListPreference) { if (preference is IntListPreference) {
IntListPrefDialog(preference).show(childFragmentManager, IntListPrefDialog.TAG) IntListPrefDialog.from(preference).show(childFragmentManager, IntListPrefDialog.TAG)
} else { } else {
super.onDisplayPreferenceDialog(preference) super.onDisplayPreferenceDialog(preference)
} }

View file

@ -256,6 +256,8 @@ class ActionHeaderViewHolder private constructor(
override fun onBind(data: ActionHeader) { override fun onBind(data: ActionHeader) {
binding.header = data binding.header = data
binding.executePendingBindings()
binding.headerButton.apply { binding.headerButton.apply {
TooltipCompat.setTooltipText(this, contentDescription) TooltipCompat.setTooltipText(this, contentDescription)

View file

@ -1,20 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<!-- ANDROID COMPONENT-SPECIFIC STYLES. MOSTLY HACKS --> <!-- ANDROID COMPONENT-SPECIFIC STYLES.-->
<!-- Custom popup menu theme --> <!-- Dialog theme where all fixes are applied -->
<style name="Widget.CustomPopup" parent="Widget.MaterialComponents.PopupMenu.ContextMenu">
<item name="android:popupBackground">@drawable/ui_popup_bg</item>
<item name="cornerRadius">0dp</item>
</style>
<!-- Toolbar popup menu -->
<style name="ThemeOverlay.ToolbarPopup" parent="ThemeOverlay.AppCompat.DayNight">
<item name="android:colorBackground">?attr/colorSurface</item>
<item name="colorControlHighlight">@color/overlay_selection</item>
</style>
<!-- Normal DayNight dialog theme -->
<style name="Theme.CustomDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog"> <style name="Theme.CustomDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="android:checkedTextViewStyle">@style/Widget.CheckedTextView.Dialog</item> <item name="android:checkedTextViewStyle">@style/Widget.CheckedTextView.Dialog</item>
<item name="colorControlHighlight">@color/overlay_selection</item> <item name="colorControlHighlight">@color/overlay_selection</item>
@ -29,13 +17,12 @@
<item name="android:fontFamily">@font/inter_bold</item> <item name="android:fontFamily">@font/inter_bold</item>
<item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">@dimen/text_size_large</item> <item name="android:textSize">@dimen/text_size_large</item>
<item name="android:paddingBottom">@dimen/spacing_medium</item>
</style> </style>
<!-- The style for the checked text view in the custom dialog --> <!-- The style for the checked text view in the custom dialog -->
<style name="Widget.CheckedTextView.Dialog" parent="Widget.MaterialComponents.CheckedTextView"> <style name="Widget.CheckedTextView.Dialog" parent="Widget.MaterialComponents.CheckedTextView">
<item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:textSize">18sp</item> <item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:background">@null</item> <item name="android:background">@null</item>
</style> </style>

View file

@ -6,7 +6,6 @@
<style name="Widget.Toolbar" parent="ThemeOverlay.MaterialComponents.ActionBar"> <style name="Widget.Toolbar" parent="ThemeOverlay.MaterialComponents.ActionBar">
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>
<item name="android:layout_height">?android:attr/actionBarSize</item> <item name="android:layout_height">?android:attr/actionBarSize</item>
<item name="popupTheme">@style/ThemeOverlay.ToolbarPopup</item>
<item name="titleTextAppearance">@style/TextAppearance.Toolbar.Header</item> <item name="titleTextAppearance">@style/TextAppearance.Toolbar.Header</item>
<item name="titleTextColor">?attr/colorAccent</item> <item name="titleTextColor">?attr/colorAccent</item>