Add Album list support in Offline

This commit is contained in:
tzugen 2022-07-07 19:20:40 +02:00
parent ecfce59e0f
commit 798d795e81
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
3 changed files with 21 additions and 11 deletions

View File

@ -19,6 +19,12 @@ interface AlbumDao : GenericDao<Album> {
@Query("SELECT * FROM albums")
fun get(): List<Album>
/**
* Get all albums in a specific range
*/
@Query("SELECT * FROM albums LIMIT :offset,:size")
fun get(size: Int, offset: Int = 0): List<Album>
/**
* Get album by id
*/

View File

@ -66,17 +66,17 @@ class MainFragment : Fragment(), KoinComponent {
override fun onResume() {
super.onResume()
var shouldRestart = false
var shouldRelayout = false
val currentId3Setting = Settings.shouldUseId3Tags
// If setting has changed...
if (currentId3Setting != cachedId3Setting) {
cachedId3Setting = currentId3Setting
shouldRestart = true
if (currentId3Setting != useId3) {
useId3 = currentId3Setting
shouldRelayout = true
}
// then setup the list anew.
if (shouldRestart) {
if (shouldRelayout) {
setupItemVisibility()
}
}
@ -109,17 +109,19 @@ class MainFragment : Fragment(), KoinComponent {
private fun setupItemVisibility() {
// Cache some values
cachedId3Setting = Settings.shouldUseId3Tags
useId3 = Settings.shouldUseId3Tags
useId3Offline = Settings.useId3TagsOffline
val isOnline = !isOffline()
// Music
musicTitle.isVisible = true
artistsButton.isVisible = true
albumsButton.isVisible = isOnline
albumsButton.isVisible = isOnline || useId3Offline
genresButton.isVisible = true
// Songs
songsTitle.isVisible = isOnline
songsTitle.isVisible = true
randomSongsButton.isVisible = true
songsStarredButton.isVisible = isOnline
@ -128,7 +130,7 @@ class MainFragment : Fragment(), KoinComponent {
albumsNewestButton.isVisible = isOnline
albumsRecentButton.isVisible = isOnline
albumsFrequentButton.isVisible = isOnline
albumsHighestButton.isVisible = isOnline && !cachedId3Setting
albumsHighestButton.isVisible = isOnline && !useId3
albumsRandomButton.isVisible = isOnline
albumsStarredButton.isVisible = isOnline
albumsAlphaByNameButton.isVisible = isOnline
@ -240,6 +242,7 @@ class MainFragment : Fragment(), KoinComponent {
}
companion object {
private var cachedId3Setting = false
private var useId3 = false
private var useId3Offline = false
}
}

View File

@ -328,7 +328,8 @@ class OfflineMusicService : MusicService, KoinComponent {
offset: Int,
musicFolderId: String?
): List<Album> {
throw OfflineException("getAlbumList2 isn't available in offline mode")
// TODO: Implement filtering by musicFolder?
return cachedAlbums.get(size, offset)
}
@Throws(Exception::class)