settings: redocument

This commit is contained in:
Alexander Capehart
2023-01-17 15:06:16 -07:00
parent 0f265cc2a4
commit 2c2b560195
7 changed files with 37 additions and 6 deletions
@@ -25,6 +25,11 @@ import com.google.android.material.divider.BackportMaterialDividerItemDecoration
import org.oxycblt.auxio.R
import org.oxycblt.auxio.list.Header
/**
* A [BackportMaterialDividerItemDecoration] that sets up the divider configuration to correctly
* separate content with headers.
* @author Alexander Capehart (OxygenCobalt)
*/
class HeaderItemDecoration
@JvmOverloads
constructor(
@@ -35,6 +40,9 @@ constructor(
) : BackportMaterialDividerItemDecoration(context, attributeSet, defStyleAttr, orientation) {
override fun shouldDrawDivider(position: Int, adapter: RecyclerView.Adapter<*>?) =
try {
// Add a divider if the next item is a header. This organizes the divider to separate
// the ends of content rather than the beginning of content, alongside an added benefit
// of preventing top headers from having a divider applied.
(adapter as DiffAdapter<*, *, *>).getItem(position + 1) is Header
} catch (e: ClassCastException) {
false
@@ -21,6 +21,10 @@ import androidx.navigation.fragment.findNavController
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
/**
* Audio settings interface.
* @author Alexander Capehart (OxygenCobalt)
*/
class AudioPreferenceFragment : BasePreferenceFragment(R.xml.preferences_audio) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
@@ -35,6 +35,10 @@ import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
* Shared [PreferenceFragmentCompat] used across all preference screens.
* @author Alexander Capehart (OxygenCobalt)
*/
abstract class BasePreferenceFragment(@XmlRes private val screen: Int) :
PreferenceFragmentCompat() {
/**
@@ -65,7 +69,7 @@ abstract class BasePreferenceFragment(@XmlRes private val screen: Int) :
view.findViewById<Toolbar>(R.id.preferences_toolbar).apply {
title = preferenceScreen.title
setNavigationOnClickListener {
val fragmentManager = fragmentManager
val fragmentManager = @Suppress("Deprecation") fragmentManager
if (fragmentManager == null || fragmentManager.backStackEntryCount == 0) {
findNavController().navigateUp()
} else {
@@ -98,14 +102,13 @@ abstract class BasePreferenceFragment(@XmlRes private val screen: Int) :
setPreferencesFromResource(screen, rootKey)
}
@Suppress("Deprecation")
override fun onDisplayPreferenceDialog(preference: Preference) {
when (preference) {
is IntListPreference -> {
// Copy the built-in preference dialog launching code into our project so
// we can automatically use the provided preference class.
val dialog = IntListPreferenceDialog.from(preference)
dialog.setTargetFragment(this, 0)
@Suppress("Deprecation") dialog.setTargetFragment(this, 0)
dialog.show(parentFragmentManager, IntListPreferenceDialog.TAG)
}
is WrappedDialogPreference -> {
@@ -23,6 +23,10 @@ import coil.Coil
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
/**
* "Content" settings.
* @author Alexander Capehart (OxygenCobalt)
*/
class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_separators)) {
@@ -21,6 +21,10 @@ import androidx.navigation.fragment.findNavController
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
/**
* Personalization settings interface.
* @author Alexander Capehart (OxygenCobalt)
*/
class PersonalizePreferenceFragment : BasePreferenceFragment(R.xml.preferences_personalize) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_home_tabs)) {
@@ -25,8 +25,12 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.divider.BackportMaterialDividerItemDecoration
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.logD
/**
* A [BackportMaterialDividerItemDecoration] that sets up the divider configuration to correctly
* separate preference categories.
* @author Alexander Capehart (OxygenCobalt)
*/
class PreferenceHeaderItemDecoration
@JvmOverloads
constructor(
@@ -37,7 +41,10 @@ constructor(
) : BackportMaterialDividerItemDecoration(context, attributeSet, defStyleAttr, orientation) {
override fun shouldDrawDivider(position: Int, adapter: RecyclerView.Adapter<*>?) =
try {
logD(position)
// Add a divider if the next item is a header (in this case a preference category
// that corresponds to a header viewholder). This organizes the divider to separate
// the ends of content rather than the beginning of content, alongside an added benefit
// of preventing top headers from having a divider applied.
(adapter as PreferenceGroupAdapter).getItem(position + 1) is PreferenceCategory
} catch (e: ClassCastException) {
false