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") @Query("SELECT * FROM albums")
fun get(): List<Album> 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 * Get album by id
*/ */

View File

@ -66,17 +66,17 @@ class MainFragment : Fragment(), KoinComponent {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
var shouldRestart = false var shouldRelayout = false
val currentId3Setting = Settings.shouldUseId3Tags val currentId3Setting = Settings.shouldUseId3Tags
// If setting has changed... // If setting has changed...
if (currentId3Setting != cachedId3Setting) { if (currentId3Setting != useId3) {
cachedId3Setting = currentId3Setting useId3 = currentId3Setting
shouldRestart = true shouldRelayout = true
} }
// then setup the list anew. // then setup the list anew.
if (shouldRestart) { if (shouldRelayout) {
setupItemVisibility() setupItemVisibility()
} }
} }
@ -109,17 +109,19 @@ class MainFragment : Fragment(), KoinComponent {
private fun setupItemVisibility() { private fun setupItemVisibility() {
// Cache some values // Cache some values
cachedId3Setting = Settings.shouldUseId3Tags useId3 = Settings.shouldUseId3Tags
useId3Offline = Settings.useId3TagsOffline
val isOnline = !isOffline() val isOnline = !isOffline()
// Music // Music
musicTitle.isVisible = true musicTitle.isVisible = true
artistsButton.isVisible = true artistsButton.isVisible = true
albumsButton.isVisible = isOnline albumsButton.isVisible = isOnline || useId3Offline
genresButton.isVisible = true genresButton.isVisible = true
// Songs // Songs
songsTitle.isVisible = isOnline songsTitle.isVisible = true
randomSongsButton.isVisible = true randomSongsButton.isVisible = true
songsStarredButton.isVisible = isOnline songsStarredButton.isVisible = isOnline
@ -128,7 +130,7 @@ class MainFragment : Fragment(), KoinComponent {
albumsNewestButton.isVisible = isOnline albumsNewestButton.isVisible = isOnline
albumsRecentButton.isVisible = isOnline albumsRecentButton.isVisible = isOnline
albumsFrequentButton.isVisible = isOnline albumsFrequentButton.isVisible = isOnline
albumsHighestButton.isVisible = isOnline && !cachedId3Setting albumsHighestButton.isVisible = isOnline && !useId3
albumsRandomButton.isVisible = isOnline albumsRandomButton.isVisible = isOnline
albumsStarredButton.isVisible = isOnline albumsStarredButton.isVisible = isOnline
albumsAlphaByNameButton.isVisible = isOnline albumsAlphaByNameButton.isVisible = isOnline
@ -240,6 +242,7 @@ class MainFragment : Fragment(), KoinComponent {
} }
companion object { 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, offset: Int,
musicFolderId: String? musicFolderId: String?
): List<Album> { ): List<Album> {
throw OfflineException("getAlbumList2 isn't available in offline mode") // TODO: Implement filtering by musicFolder?
return cachedAlbums.get(size, offset)
} }
@Throws(Exception::class) @Throws(Exception::class)