Make save playback state setting public

Make the ability to force-save the playback state public in the settings menu instead of in the debug menu.
This commit is contained in:
OxygenCobalt 2021-02-19 11:19:45 -07:00
parent 0a7fbeca6d
commit e631ddd730
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
8 changed files with 54 additions and 55 deletions

View file

@ -73,6 +73,16 @@ class LoadingFragment : Fragment() {
return binding.root
}
override fun onResume() {
super.onResume()
if (MusicStore.getInstance().loaded) {
findNavController().navigate(
LoadingFragmentDirections.actionToMain()
)
}
}
// --- PERMISSIONS ---
private fun noPermissions(): Boolean {

View file

@ -62,8 +62,6 @@ class MusicLoader(private val app: Application) {
Genres.DEFAULT_SORT_ORDER
)
val genrePlaceholder = app.getString(R.string.placeholder_genre)
// And then process those into Genre objects
genreCursor?.use { cursor ->
val idIndex = cursor.getColumnIndexOrThrow(Genres._ID)
@ -71,7 +69,7 @@ class MusicLoader(private val app: Application) {
while (cursor.moveToNext()) {
val id = cursor.getLong(idIndex)
val name = cursor.getStringOrNull(nameIndex) ?: genrePlaceholder
val name = cursor.getStringOrNull(nameIndex) ?: continue // No non-broken genre would be missing a name
genres.add(Genre(id, name))
}
@ -119,12 +117,7 @@ class MusicLoader(private val app: Application) {
artistName = artistPlaceholder
}
albums.add(
Album(
id = id, name = name, artistName = artistName,
coverUri = coverUri, year = year
)
)
albums.add(Album(id, name, artistName, coverUri, year))
}
cursor.close()
@ -170,12 +163,7 @@ class MusicLoader(private val app: Application) {
val track = cursor.getInt(trackIndex)
val duration = cursor.getLong(durationIndex)
songs.add(
Song(
id, title, albumId,
track, duration
)
)
songs.add(Song(id, title, albumId, track, duration))
}
cursor.close()
@ -187,6 +175,7 @@ class MusicLoader(private val app: Application) {
// Then try to associate any genres with their respective songs
// This is stupidly inefficient, but I don't have another choice really.
// Blame the android devs for deciding to design MediaStore this way.
for (genre in genres) {
val songGenreCursor = resolver.query(
Genres.Members.getContentUri("external", genre.id),
@ -207,6 +196,23 @@ class MusicLoader(private val app: Application) {
}
}
/*
// Fix that will group songs w/o genres into an unknown genre
// Currently disabled until it would actually benefit someone, otherwise its just
// a performance deadweight.
val songsWithoutGenres = songs.filter { it.genre == null }
if (songsWithoutGenres.isNotEmpty()) {
val unknownGenre = Genre(name = app.getString(R.string.placeholder_genre))
songsWithoutGenres.forEach {
unknownGenre.addSong(it)
}
genres.add(unknownGenre)
}
*/
logD("Song search finished with ${songs.size} found")
}
}

View file

@ -298,6 +298,18 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
// --- SAVE/RESTORE FUNCTIONS ---
/**
* Force save the current [PlaybackStateManager] state to the database. Called by SettingsListFragment.
* @param context [Context] required.
*/
fun savePlaybackState(context: Context) {
viewModelScope.launch {
playbackManager.saveStateToDatabase(context)
context.getString(R.string.debug_state_saved).createToast(context)
}
}
/**
* Get [PlaybackStateManager] to restore its state from the database, if needed. Called by MainFragment.
* @param context [Context] required.
@ -310,18 +322,6 @@ class PlaybackViewModel : ViewModel(), PlaybackStateManager.Callback {
}
}
/**
* Force save the current [PlaybackStateManager] state to the database. Called by SettingsListFragment.
* @param context [Context] required.
*/
fun save(context: Context) {
viewModelScope.launch {
playbackManager.saveStateToDatabase(context)
context.getString(R.string.debug_state_saved).createToast(context)
}
}
/** Attempt to restore the current playback state from an existing [PlaybackStateManager] instance */
private fun restorePlaybackState() {
logD("Attempting to restore playback state.")

View file

@ -14,7 +14,6 @@ import coil.Coil
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.utils.invalidateDividers
import org.oxycblt.auxio.BuildConfig
import org.oxycblt.auxio.R
import org.oxycblt.auxio.logD
import org.oxycblt.auxio.playback.PlaybackViewModel
@ -48,13 +47,6 @@ class SettingsListFragment : PreferenceFragmentCompat() {
private fun recursivelyHandleChildren(pref: Preference) {
if (pref is PreferenceCategory) {
// Show the debug category if this build is a debug build
if (pref.title == getString(R.string.debug_title) && BuildConfig.DEBUG) {
logD("Showing debug category.")
pref.isVisible = true
}
// If this preference is a category of its own, handle its own children
pref.children.forEach { recursivelyHandleChildren(it) }
} else {
@ -133,7 +125,7 @@ class SettingsListFragment : PreferenceFragmentCompat() {
SettingsManager.Keys.KEY_DEBUG_SAVE -> {
onPreferenceClickListener = Preference.OnPreferenceClickListener {
playbackModel.save(requireContext())
playbackModel.savePlaybackState(requireContext())
true
}

View file

@ -51,7 +51,7 @@
<string name="setting_title">Einstellungen</string>
<string name="setting_ui">Aussehen</string>
<string name="setting_theme">Theme</string>
<string name="setting_theme">Thema</string>
<string name="setting_theme_auto">Automatisch</string>
<string name="setting_theme_day">Hell</string>
<string name="setting_theme_night">Dunkel</string>
@ -59,7 +59,7 @@
<string name="setting_accent_unknown">Unbekannte Akzentfarbe</string>
<string name="setting_display">Anzeige</string>
<string name="setting_lib_display">Musikbibliothek-Items</string>
<string name="setting_lib_display">Musikbibliothekitems</string>
<string name="setting_color_notif">Benachrichtigung farblich anpassen</string>
<string name="setting_color_desc">Albumcover am Benachrichtigung zeigen</string>
<string name="setting_show_covers">Albumcover anzeigen</string>
@ -86,6 +86,8 @@
<string name="setting_behavior_keep_shuffle_desc">Lassen zufällig an, wenn ein neues Lied anspielen</string>
<string name="setting_behavior_rewind_prev">Zurückspulen, bevor zurück springen</string>
<string name="setting_behavior_rewind_prev_desc">Zurückspulen, bevor zum vorheriger Lied springen</string>
<string name="setting_behavior_save" >Wiedergabezustand abspeichern</string>
<string name="setting_behavior_save_desc">der aktuell Wiedergabezustand jetzt abspeichern</string>
<!-- Error Namespace | Error Labels -->
<string name="error_no_music">Keine Musik gefunden</string>

View file

@ -8,11 +8,4 @@
<string name="format_double_info" translatable="false">%1$s / %2$s / %3$s</string>
<string name="format_double_counts" translatable="false">%1$s, %2$s</string>
<string name="format_accent_summary" translatable="false">&lt;b>%1$s&lt;/b>:&#160;%2$s</string>
<!-- Debug Namespace | Debug labels -->
<!-- These are never shown to the user in normal use and therefore shouldnt be translated -->
<string name="debug_title" translatable="false">Debug</string>
<string name="debug_state_save" translatable="false">Save playback state</string>
<string name="debug_state_save_desc" translatable="false">Force save the current playback state</string>
<string name="debug_state_saved" translatable="false">State saved</string>
</resources>

View file

@ -42,6 +42,8 @@
<string name="label_go_artist">Go to artist</string>
<string name="label_go_album">Go to album</string>
<string name="debug_state_saved">State saved</string>
<string name="label_about">About</string>
<string name="label_version">Version</string>
<string name="label_code">View on Github</string>
@ -88,6 +90,8 @@
<string name="setting_behavior_keep_shuffle_desc">Keep shuffle on when playing a new song</string>
<string name="setting_behavior_rewind_prev">Rewind before skipping back</string>
<string name="setting_behavior_rewind_prev_desc">Rewind before skipping to the previous song</string>
<string name="setting_behavior_save" >Save playback state</string>
<string name="setting_behavior_save_desc">Save the current playback state now</string>
<!-- Error Namespace | Error Labels -->
<string name="error_no_music">No music found</string>

View file

@ -126,18 +126,10 @@
app:key="KEY_PREV_REWIND"
app:summary="@string/setting_behavior_rewind_prev_desc" />
</PreferenceCategory>
<PreferenceCategory
android:title="@string/debug_title"
app:isPreferenceVisible="false"
app:layout="@layout/item_header">
<Preference
android:title="@string/debug_state_save"
android:title="@string/setting_behavior_save"
app:iconSpaceReserved="false"
app:key="KEY_SAVE_STATE"
app:summary="@string/debug_state_save_desc" />
app:summary="@string/setting_behavior_save_desc" />
</PreferenceCategory>
</PreferenceScreen>