detail: band-aid crashes when library unavailable

Band-aid a crash that would occur when the library is somehow
unavailable in the detail view. Now, if it's unavailable, the
app simple navigates away.

Not sure how this is happening, but I'd imagine it's some caching
shenanigans I need to fix by using volatile on any shared field.
This commit is contained in:
Alexander Capehart 2023-01-03 13:53:17 -07:00
parent bd9c02a1e1
commit d4d3bd5ff4
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
2 changed files with 7 additions and 6 deletions

View file

@ -183,7 +183,7 @@ class DetailViewModel(application: Application) :
return
}
logD("Opening Song [uid: $uid]")
_currentSong.value = requireMusic<Song>(uid).also(::loadProperties)
_currentSong.value = requireMusic<Song>(uid)?.also(::loadProperties)
}
/**
@ -197,7 +197,7 @@ class DetailViewModel(application: Application) :
return
}
logD("Opening Album [uid: $uid]")
_currentAlbum.value = requireMusic<Album>(uid).also(::refreshAlbumList)
_currentAlbum.value = requireMusic<Album>(uid)?.also(::refreshAlbumList)
}
/**
@ -211,7 +211,7 @@ class DetailViewModel(application: Application) :
return
}
logD("Opening Artist [uid: $uid]")
_currentArtist.value = requireMusic<Artist>(uid).also(::refreshArtistList)
_currentArtist.value = requireMusic<Artist>(uid)?.also(::refreshArtistList)
}
/**
@ -225,11 +225,10 @@ class DetailViewModel(application: Application) :
return
}
logD("Opening Genre [uid: $uid]")
_currentGenre.value = requireMusic<Genre>(uid).also(::refreshGenreList)
_currentGenre.value = requireMusic<Genre>(uid)?.also(::refreshGenreList)
}
private fun <T : Music> requireMusic(uid: Music.UID): T =
requireNotNull(unlikelyToBeNull(musicStore.library).find(uid)) { "Invalid id provided" }
private fun <T : Music> requireMusic(uid: Music.UID) = musicStore.library?.find<T>(uid)
/**
* Start a new job to load a [DetailSong] based on the properties of the given [Song]'s file.

View file

@ -30,6 +30,8 @@ import org.oxycblt.auxio.music.filesystem.useQuery
* generally recommended to use this over Indexer to keep track of the library state, as the
* interface will be less volatile.
*
* TODO: Use volatile on individual fields
*
* @author Alexander Capehart (OxygenCobalt)
*/
class MusicStore private constructor() {