Fix empty genre bug
Bandaid MusicSorter to remove any genres that dont have anything in them, because that happens now. Also prevent a crash just in case an empty music model does get played.
This commit is contained in:
parent
c4c115274b
commit
3337747cb7
5 changed files with 35 additions and 9 deletions
|
@ -21,7 +21,7 @@ class LibraryViewModel : ViewModel() {
|
||||||
val searchHasFocus: Boolean get() = mSearchHasFocus
|
val searchHasFocus: Boolean get() = mSearchHasFocus
|
||||||
|
|
||||||
// TODO: Move these to prefs when they're added
|
// TODO: Move these to prefs when they're added
|
||||||
private val mShowMode = MutableLiveData(ShowMode.SHOW_GENRES)
|
private val mShowMode = MutableLiveData(ShowMode.SHOW_ARTISTS)
|
||||||
val showMode: LiveData<ShowMode> get() = mShowMode
|
val showMode: LiveData<ShowMode> get() = mShowMode
|
||||||
|
|
||||||
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)
|
private val mSortMode = MutableLiveData(SortMode.ALPHA_DOWN)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.oxycblt.auxio.music
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
|
|
||||||
// --- MUSIC MODELS ---
|
// --- MUSIC MODELS ---
|
||||||
// TODO: Remove parent/child references so that they can be parcelable [Would require genre rework]
|
// FIXME: Remove parent/child references so that they can be parcelable?
|
||||||
|
|
||||||
// The base model for all music
|
// The base model for all music
|
||||||
// This is used in a lot of general functions in order to have generic utilities
|
// This is used in a lot of general functions in order to have generic utilities
|
||||||
|
@ -94,6 +94,13 @@ data class Genre(
|
||||||
}
|
}
|
||||||
num
|
num
|
||||||
}
|
}
|
||||||
|
val songs: MutableList<Song> by lazy {
|
||||||
|
val songs = mutableListOf<Song>()
|
||||||
|
artists.forEach {
|
||||||
|
songs.addAll(it.songs)
|
||||||
|
}
|
||||||
|
songs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header [Used for search, nothing else]
|
// Header [Used for search, nothing else]
|
||||||
|
|
|
@ -129,8 +129,6 @@ class MusicLoader(
|
||||||
name = artistPlaceholder
|
name = artistPlaceholder
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(this::class.simpleName, id.toString())
|
|
||||||
|
|
||||||
artists.add(
|
artists.add(
|
||||||
Artist(
|
Artist(
|
||||||
id, name
|
id, name
|
||||||
|
@ -141,6 +139,10 @@ class MusicLoader(
|
||||||
cursor.close()
|
cursor.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
artists = artists.distinctBy {
|
||||||
|
it.name to it.genres
|
||||||
|
}.toMutableList()
|
||||||
|
|
||||||
// Then try to associate any genres with their respective artists.
|
// Then try to associate any genres with their respective artists.
|
||||||
for (genre in genres) {
|
for (genre in genres) {
|
||||||
val artistGenreCursor = resolver.query(
|
val artistGenreCursor = resolver.query(
|
||||||
|
@ -166,10 +168,6 @@ class MusicLoader(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
artists = artists.distinctBy {
|
|
||||||
it.name to it.genres
|
|
||||||
}.toMutableList()
|
|
||||||
|
|
||||||
Log.d(
|
Log.d(
|
||||||
this::class.simpleName,
|
this::class.simpleName,
|
||||||
"Artist search finished with ${artists.size} artists found."
|
"Artist search finished with ${artists.size} artists found."
|
||||||
|
|
|
@ -26,6 +26,9 @@ class MusicSorter(
|
||||||
genres = genres.distinctBy {
|
genres = genres.distinctBy {
|
||||||
it.name
|
it.name
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|
||||||
|
// Also elimate any genres that dont have artists, which also happens sometimes.
|
||||||
|
genres.removeAll { it.artists.isEmpty() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortSongsIntoAlbums() {
|
private fun sortSongsIntoAlbums() {
|
||||||
|
|
|
@ -18,7 +18,7 @@ import kotlin.random.Random.Default.nextLong
|
||||||
// TODO: Queue
|
// TODO: Queue
|
||||||
// TODO: Add the playback service itself
|
// TODO: Add the playback service itself
|
||||||
// TODO: Add loop control [From playback]
|
// TODO: Add loop control [From playback]
|
||||||
// TODO: Implement persistence through Bundles and sanity checks [I want to keep my shuffles, okay?]
|
// TODO: Implement persistence through Bundles [I want to keep my shuffles, okay?]
|
||||||
// A ViewModel that acts as an intermediary between PlaybackService and the Playback Fragments.
|
// A ViewModel that acts as an intermediary between PlaybackService and the Playback Fragments.
|
||||||
class PlaybackViewModel : ViewModel() {
|
class PlaybackViewModel : ViewModel() {
|
||||||
private val mCurrentSong = MutableLiveData<Song>()
|
private val mCurrentSong = MutableLiveData<Song>()
|
||||||
|
@ -108,6 +108,12 @@ class PlaybackViewModel : ViewModel() {
|
||||||
fun play(album: Album, isShuffled: Boolean) {
|
fun play(album: Album, isShuffled: Boolean) {
|
||||||
Log.d(this::class.simpleName, "Playing album ${album.name}")
|
Log.d(this::class.simpleName, "Playing album ${album.name}")
|
||||||
|
|
||||||
|
if (album.songs.isEmpty()) {
|
||||||
|
Log.e(this::class.simpleName, "Album is empty, not playing.")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val songs = orderSongsInAlbum(album)
|
val songs = orderSongsInAlbum(album)
|
||||||
|
|
||||||
updatePlayback(songs[0])
|
updatePlayback(songs[0])
|
||||||
|
@ -128,6 +134,12 @@ class PlaybackViewModel : ViewModel() {
|
||||||
fun play(artist: Artist, isShuffled: Boolean) {
|
fun play(artist: Artist, isShuffled: Boolean) {
|
||||||
Log.d(this::class.simpleName, "Playing artist ${artist.name}")
|
Log.d(this::class.simpleName, "Playing artist ${artist.name}")
|
||||||
|
|
||||||
|
if (artist.songs.isEmpty()) {
|
||||||
|
Log.e(this::class.simpleName, "Artist is empty, not playing.")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val songs = orderSongsInArtist(artist)
|
val songs = orderSongsInArtist(artist)
|
||||||
|
|
||||||
updatePlayback(songs[0])
|
updatePlayback(songs[0])
|
||||||
|
@ -148,6 +160,12 @@ class PlaybackViewModel : ViewModel() {
|
||||||
fun play(genre: Genre, isShuffled: Boolean) {
|
fun play(genre: Genre, isShuffled: Boolean) {
|
||||||
Log.d(this::class.simpleName, "Playing genre ${genre.name}")
|
Log.d(this::class.simpleName, "Playing genre ${genre.name}")
|
||||||
|
|
||||||
|
if (genre.songs.isEmpty()) {
|
||||||
|
Log.e(this::class.simpleName, "Genre is empty, not playing.")
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
val songs = orderSongsInGenre(genre)
|
val songs = orderSongsInGenre(genre)
|
||||||
|
|
||||||
updatePlayback(songs[0])
|
updatePlayback(songs[0])
|
||||||
|
|
Loading…
Reference in a new issue