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:
parent
744e4172f3
commit
c9dd3b97a2
6 changed files with 37 additions and 35 deletions
|
@ -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 {
|
||||
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))
|
||||
// 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
|
||||
|
||||
// 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)
|
||||
|
||||
|
|
|
@ -1,20 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- ANDROID COMPONENT-SPECIFIC STYLES. MOSTLY HACKS -->
|
||||
<!-- ANDROID COMPONENT-SPECIFIC STYLES.-->
|
||||
|
||||
<!-- Custom popup menu theme -->
|
||||
<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 -->
|
||||
<!-- Dialog theme where all fixes are applied -->
|
||||
<style name="Theme.CustomDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
|
||||
<item name="android:checkedTextViewStyle">@style/Widget.CheckedTextView.Dialog</item>
|
||||
<item name="colorControlHighlight">@color/overlay_selection</item>
|
||||
|
@ -29,13 +17,12 @@
|
|||
<item name="android:fontFamily">@font/inter_bold</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
<item name="android:textSize">@dimen/text_size_large</item>
|
||||
<item name="android:paddingBottom">@dimen/spacing_medium</item>
|
||||
</style>
|
||||
|
||||
<!-- The style for the checked text view in the custom dialog -->
|
||||
<style name="Widget.CheckedTextView.Dialog" parent="Widget.MaterialComponents.CheckedTextView">
|
||||
<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>
|
||||
</style>
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
<style name="Widget.Toolbar" parent="ThemeOverlay.MaterialComponents.ActionBar">
|
||||
<item name="android:layout_width">match_parent</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="titleTextColor">?attr/colorAccent</item>
|
||||
|
|
Loading…
Reference in a new issue