settings: split up ui

Split up the settings ui into four categories.

This should reduce the visual load on the user as Auxio continues to
accrue possible configuration options.

Resolves #323.
This commit is contained in:
Alexander Capehart
2023-01-16 16:14:51 -07:00
parent e7ff7293c0
commit 4a7bc4e511
58 changed files with 904 additions and 616 deletions
@@ -64,7 +64,7 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
binding.playbackInfo.isSelected = true
// Set up actions
binding.playbackPlayPause.setOnClickListener { playbackModel.toggleIsPlaying() }
binding.playbackPlayPause.setOnClickListener { playbackModel.togglePlaying() }
setupSecondaryActions(binding, playbackModel.currentBarAction)
// Load the track color in manually as it's unclear whether the track actually supports
@@ -108,7 +108,7 @@ class PlaybackBarFragment : ViewBindingFragment<FragmentPlaybackBarBinding>() {
setIconResource(R.drawable.sel_shuffle_state_24)
contentDescription = getString(R.string.desc_shuffle)
iconTint = context.getColorCompat(R.color.sel_activatable_icon)
setOnClickListener { playbackModel.invertShuffled() }
setOnClickListener { playbackModel.toggleShuffled() }
collectImmediately(playbackModel.isShuffled, ::updateShuffled)
}
}
@@ -105,9 +105,9 @@ class PlaybackPanelFragment :
// TODO: Add better playback button accessibility
binding.playbackRepeat.setOnClickListener { playbackModel.toggleRepeatMode() }
binding.playbackSkipPrev.setOnClickListener { playbackModel.prev() }
binding.playbackPlayPause.setOnClickListener { playbackModel.toggleIsPlaying() }
binding.playbackPlayPause.setOnClickListener { playbackModel.togglePlaying() }
binding.playbackSkipNext.setOnClickListener { playbackModel.next() }
binding.playbackShuffle.setOnClickListener { playbackModel.invertShuffled() }
binding.playbackShuffle.setOnClickListener { playbackModel.toggleShuffled() }
// --- VIEWMODEL SETUP --
collectImmediately(playbackModel.song, ::updateSong)
@@ -325,8 +325,6 @@ class PlaybackViewModel(application: Application) :
* @param song The [Song] to add.
*/
fun playNext(song: Song) {
// TODO: Queue additions without a playing song should map to playing items
// (impossible until queue rework)
playbackManager.playNext(song)
}
@@ -405,12 +403,12 @@ class PlaybackViewModel(application: Application) :
// --- STATUS FUNCTIONS ---
/** Toggle [isPlaying] (i.e from playing to paused) */
fun toggleIsPlaying() {
fun togglePlaying() {
playbackManager.setPlaying(!playbackManager.playerState.isPlaying)
}
/** Toggle [isShuffled] (ex. from on to off) */
fun invertShuffled() {
fun toggleShuffled() {
playbackManager.reorder(!playbackManager.queue.isShuffled)
}
@@ -59,7 +59,7 @@ class PlaybackStateManager private constructor() {
val queue = Queue()
/** The [MusicParent] currently being played. Null if playback is occurring from all songs. */
@Volatile
var parent: MusicParent? = null // TODO: Parent is interpreted wrong when nothing is playing.
var parent: MusicParent? = null // FIXME: Parent is interpreted wrong when nothing is playing.
private set
/** The current [InternalPlayer] state. */
@@ -20,13 +20,12 @@ package org.oxycblt.auxio.settings
import android.os.Bundle
import android.view.LayoutInflater
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.google.android.material.transition.MaterialFadeThrough
import org.oxycblt.auxio.databinding.FragmentSettingsBinding
import org.oxycblt.auxio.ui.ViewBindingFragment
/**
* A [Fragment] wrapper containing the preference fragment and a companion Toolbar.
* A [Fragment] wrapper wrapping the preference navigation flow.
* @author Alexander Capehart (OxygenCobalt)
*/
class SettingsFragment : ViewBindingFragment<FragmentSettingsBinding>() {
@@ -39,9 +38,5 @@ class SettingsFragment : ViewBindingFragment<FragmentSettingsBinding>() {
override fun onCreateBinding(inflater: LayoutInflater) =
FragmentSettingsBinding.inflate(inflater)
override fun onBindingCreated(binding: FragmentSettingsBinding, savedInstanceState: Bundle?) {
// Point AppBarLayout to the preference fragment's RecyclerView.
binding.settingsAppbar.liftOnScrollTargetViewId = androidx.preference.R.id.recycler_view
binding.settingsToolbar.setNavigationOnClickListener { findNavController().navigateUp() }
}
override fun onBindingCreated(binding: FragmentSettingsBinding, savedInstanceState: Bundle?) {}
}
@@ -1,193 +0,0 @@
/*
* Copyright (c) 2021 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.prefs
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.view.updatePadding
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.children
import androidx.recyclerview.widget.RecyclerView
import coil.Coil
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.settings.SettingsFragmentDirections
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.androidActivityViewModels
import org.oxycblt.auxio.util.isNight
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.showToast
import org.oxycblt.auxio.util.systemBarInsetsCompat
/**
* The [PreferenceFragmentCompat] that displays the list of settings.
* @author Alexander Capehart (OxygenCobalt)
*/
class PreferenceFragment : PreferenceFragmentCompat() {
private val playbackModel: PlaybackViewModel by androidActivityViewModels()
private val musicModel: MusicViewModel by activityViewModels()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
preferenceManager.onDisplayPreferenceDialogListener = this
preferenceScreen.children.forEach(::setupPreference)
// Configure the RecyclerView to support edge-to-edge.
view.findViewById<RecyclerView>(androidx.preference.R.id.recycler_view).apply {
clipToPadding = false
setOnApplyWindowInsetsListener { _, insets ->
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
insets
}
}
logD("Fragment created")
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.prefs_main, 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)
dialog.show(parentFragmentManager, IntListPreferenceDialog.TAG)
}
is WrappedDialogPreference -> {
// WrappedDialogPreference cannot launch a dialog on it's own, it has to
// be handled manually.
val directions =
when (preference.key) {
getString(R.string.set_key_accent) ->
SettingsFragmentDirections.goToAccentDialog()
getString(R.string.set_key_home_tabs) ->
SettingsFragmentDirections.goToTabDialog()
getString(R.string.set_key_pre_amp) ->
SettingsFragmentDirections.goToPreAmpDialog()
getString(R.string.set_key_music_dirs) ->
SettingsFragmentDirections.goToMusicDirsDialog()
getString(R.string.set_key_separators) ->
SettingsFragmentDirections.goToSeparatorsDialog()
else -> error("Unexpected dialog key ${preference.key}")
}
findNavController().navigate(directions)
}
else -> super.onDisplayPreferenceDialog(preference)
}
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
// Hook generic preferences to their specified preferences
// TODO: These seem like good things to put into a side navigation view, if I choose to
// do one.
when (preference.key) {
getString(R.string.set_key_save_state) -> {
playbackModel.savePlaybackState { saved ->
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
if (saved) {
context?.showToast(R.string.lbl_state_saved)
} else {
context?.showToast(R.string.err_did_not_save)
}
}
}
getString(R.string.set_key_wipe_state) -> {
playbackModel.wipePlaybackState { wiped ->
if (wiped) {
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
context?.showToast(R.string.lbl_state_wiped)
} else {
context?.showToast(R.string.err_did_not_wipe)
}
}
}
getString(R.string.set_key_restore_state) ->
playbackModel.tryRestorePlaybackState { restored ->
if (restored) {
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
context?.showToast(R.string.lbl_state_restored)
} else {
context?.showToast(R.string.err_did_not_restore)
}
}
getString(R.string.set_key_reindex) -> musicModel.refresh()
getString(R.string.set_key_rescan) -> musicModel.rescan()
else -> return super.onPreferenceTreeClick(preference)
}
return true
}
private fun setupPreference(preference: Preference) {
if (!preference.isVisible) {
// Nothing to do.
return
}
if (preference is PreferenceCategory) {
preference.children.forEach(::setupPreference)
return
}
when (preference.key) {
getString(R.string.set_key_theme) -> {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, value ->
AppCompatDelegate.setDefaultNightMode(value as Int)
true
}
}
getString(R.string.set_key_accent) -> {
preference.summary = getString(UISettings.from(requireContext()).accent.name)
}
getString(R.string.set_key_black_theme) -> {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
val activity = requireActivity()
if (activity.isNight) {
activity.recreate()
}
true
}
}
getString(R.string.set_key_cover_mode) -> {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
Coil.imageLoader(requireContext()).memoryCache?.clear()
true
}
}
}
}
}
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2023 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import androidx.navigation.fragment.findNavController
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
class AudioPreferenceFragment : BasePreferenceFragment(R.xml.preferences_audio) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_pre_amp)) {
findNavController().navigate(SettingsFragmentDirections.goToPreAmpDialog())
}
}
}
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2023 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.XmlRes
import androidx.appcompat.widget.Toolbar
import androidx.core.view.updatePadding
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.children
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.transition.MaterialSharedAxis
import org.oxycblt.auxio.R
import org.oxycblt.auxio.util.logD
import org.oxycblt.auxio.util.systemBarInsetsCompat
abstract class BasePreferenceFragment(@XmlRes private val screen: Int) :
PreferenceFragmentCompat() {
/**
* Called when the UI entry of a given [Preference] needs to be configured.
* @param preference The [Preference] to configure.
*/
open fun onSetupPreference(preference: Preference) {}
/**
* Called when an arbitrary [WrappedDialogPreference] needs to be opened.
* @param preference The [WrappedDialogPreference] to open.
*/
open fun onOpenDialogPreference(preference: WrappedDialogPreference) {}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enterTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
returnTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
exitTransition = MaterialSharedAxis(MaterialSharedAxis.X, true)
reenterTransition = MaterialSharedAxis(MaterialSharedAxis.X, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
view.findViewById<AppBarLayout>(R.id.preferences_appbar).liftOnScrollTargetViewId =
androidx.preference.R.id.recycler_view
view.findViewById<Toolbar>(R.id.preferences_toolbar).apply {
title = preferenceScreen.title
setNavigationOnClickListener {
val fragmentManager = fragmentManager
if (fragmentManager == null || fragmentManager.backStackEntryCount == 0) {
findNavController().navigateUp()
} else {
fragmentManager.popBackStack()
}
}
}
preferenceManager.onDisplayPreferenceDialogListener = this
preferenceScreen.children.forEach(::setupPreference)
logD("Fragment created")
}
override fun onCreateRecyclerView(
inflater: LayoutInflater,
parent: ViewGroup,
savedInstanceState: Bundle?
) =
super.onCreateRecyclerView(inflater, parent, savedInstanceState).apply {
clipToPadding = false
setOnApplyWindowInsetsListener { _, insets ->
updatePadding(bottom = insets.systemBarInsetsCompat.bottom)
insets
}
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
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)
dialog.show(parentFragmentManager, IntListPreferenceDialog.TAG)
}
is WrappedDialogPreference -> {
// These dialog preferences cannot launch on their own, delegate to
// implementations.
onOpenDialogPreference(preference)
}
else -> super.onDisplayPreferenceDialog(preference)
}
}
private fun setupPreference(preference: Preference) {
if (!preference.isVisible) {
// Nothing to do.
return
}
if (preference is PreferenceCategory) {
preference.children.forEach(::setupPreference)
return
}
onSetupPreference(preference)
}
}
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.prefs
package org.oxycblt.auxio.settings.ui
import android.content.Context
import android.content.res.TypedArray
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.prefs
package org.oxycblt.auxio.settings.ui
import android.os.Bundle
import androidx.preference.PreferenceDialogFragmentCompat
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2023 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import coil.Coil
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
class MusicPreferenceFragment : BasePreferenceFragment(R.xml.preferences_music) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_separators)) {
findNavController().navigate(SettingsFragmentDirections.goToSeparatorsDialog())
}
}
override fun onSetupPreference(preference: Preference) {
if (preference.key == getString(R.string.set_key_cover_mode)) {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
Coil.imageLoader(requireContext()).memoryCache?.clear()
true
}
}
}
}
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2023 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import androidx.navigation.fragment.findNavController
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
class PersonalizePreferenceFragment : BasePreferenceFragment(R.xml.preferences_personalize) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_home_tabs)) {
findNavController().navigate(SettingsFragmentDirections.goToTabDialog())
}
}
}
@@ -0,0 +1,89 @@
/*
* Copyright (c) 2021 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import org.oxycblt.auxio.R
import org.oxycblt.auxio.music.MusicViewModel
import org.oxycblt.auxio.playback.PlaybackViewModel
import org.oxycblt.auxio.settings.SettingsFragmentDirections
import org.oxycblt.auxio.util.androidActivityViewModels
import org.oxycblt.auxio.util.showToast
/**
* The [PreferenceFragmentCompat] that displays the root settings list.
* @author Alexander Capehart (OxygenCobalt)
*/
class RootPreferenceFragment : BasePreferenceFragment(R.xml.preferences_root) {
private val playbackModel: PlaybackViewModel by androidActivityViewModels()
private val musicModel: MusicViewModel by activityViewModels()
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_music_dirs)) {
findNavController().navigate(SettingsFragmentDirections.goToMusicDirsDialog())
}
}
override fun onPreferenceTreeClick(preference: Preference): Boolean {
// Hook generic preferences to their specified preferences
// TODO: These seem like good things to put into a side navigation view, if I choose to
// do one.
when (preference.key) {
getString(R.string.set_key_reindex) -> musicModel.refresh()
getString(R.string.set_key_rescan) -> musicModel.rescan()
getString(R.string.set_key_save_state) -> {
playbackModel.savePlaybackState { saved ->
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
if (saved) {
context?.showToast(R.string.lbl_state_saved)
} else {
context?.showToast(R.string.err_did_not_save)
}
}
}
getString(R.string.set_key_wipe_state) -> {
playbackModel.wipePlaybackState { wiped ->
if (wiped) {
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
context?.showToast(R.string.lbl_state_wiped)
} else {
context?.showToast(R.string.err_did_not_wipe)
}
}
}
getString(R.string.set_key_restore_state) ->
playbackModel.tryRestorePlaybackState { restored ->
if (restored) {
// Use the nullable context, as we could try to show a toast when this
// fragment is no longer attached.
context?.showToast(R.string.lbl_state_restored)
} else {
context?.showToast(R.string.err_did_not_restore)
}
}
else -> return super.onPreferenceTreeClick(preference)
}
return true
}
}
@@ -0,0 +1,60 @@
/*
* Copyright (c) 2023 Auxio Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.ui
import androidx.appcompat.app.AppCompatDelegate
import androidx.navigation.fragment.findNavController
import androidx.preference.Preference
import org.oxycblt.auxio.R
import org.oxycblt.auxio.settings.SettingsFragmentDirections
import org.oxycblt.auxio.ui.UISettings
import org.oxycblt.auxio.util.isNight
class UIPreferenceFragment : BasePreferenceFragment(R.xml.preferences_ui) {
override fun onOpenDialogPreference(preference: WrappedDialogPreference) {
if (preference.key == getString(R.string.set_key_accent)) {
findNavController().navigate(SettingsFragmentDirections.goToAccentDialog())
}
}
override fun onSetupPreference(preference: Preference) {
when (preference.key) {
getString(R.string.set_key_theme) -> {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, value ->
AppCompatDelegate.setDefaultNightMode(value as Int)
true
}
}
getString(R.string.set_key_accent) -> {
preference.summary = getString(UISettings.from(requireContext()).accent.name)
}
getString(R.string.set_key_black_theme) -> {
preference.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, _ ->
val activity = requireActivity()
if (activity.isNight) {
activity.recreate()
}
true
}
}
}
}
}
@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.oxycblt.auxio.settings.prefs
package org.oxycblt.auxio.settings.ui
import android.content.Context
import android.util.AttributeSet
@@ -40,8 +40,7 @@ fun <T> unlikelyToBeNull(value: T?) =
* @throws IllegalStateException If the data cannot be casted to [T].
*/
inline fun <reified T> requireIs(data: Any?): T {
requireNotNull(data) { "Unexpected datatype: null" }
check(data is T) { "Unexpected datatype: ${data::class.simpleName}" }
check(data is T) { "Unexpected datatype: ${data?.let { it::class.simpleName }}" }
return data
}