Clean & formatting

Update room 2.4.0 -> 2.4.2
This commit is contained in:
tzugen 2022-06-19 12:59:26 +02:00
parent 60dbe70ca5
commit 241e51015f
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
6 changed files with 37 additions and 53 deletions

View File

@ -59,7 +59,7 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
throw IllegalAccessException("You must use submitList() to add data to the Adapter") throw IllegalAccessException("You must use submitList() to add data to the Adapter")
} }
var mDiffer: AsyncListDiffer<T> = AsyncListDiffer( private var mDiffer: AsyncListDiffer<T> = AsyncListDiffer(
AdapterListUpdateCallback(this), AdapterListUpdateCallback(this),
AsyncDifferConfig.Builder(diffCallback).build() AsyncDifferConfig.Builder(diffCallback).build()
) )
@ -182,12 +182,11 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
// Select them all // Select them all
getCurrentList().mapNotNullTo( getCurrentList().mapNotNullTo(
selectedSet, selectedSet
{ entry -> ) { entry ->
// Exclude any -1 ids, eg. headers and other UI elements // Exclude any -1 ids, eg. headers and other UI elements
entry.longId.takeIf { it != -1L } entry.longId.takeIf { it != -1L }
} }
)
return selectedSet.count() return selectedSet.count()
} }

View File

@ -24,7 +24,6 @@ class ActiveServerProvider(
private val repository: ServerSettingDao private val repository: ServerSettingDao
) : CoroutineScope by CoroutineScope(Dispatchers.IO) { ) : CoroutineScope by CoroutineScope(Dispatchers.IO) {
private var cachedServer: ServerSetting? = null private var cachedServer: ServerSetting? = null
// FIXME cach never set
private var cachedDatabase: MetaDatabase? = null private var cachedDatabase: MetaDatabase? = null
private var cachedServerId: Int? = null private var cachedServerId: Int? = null

View File

@ -47,6 +47,7 @@ import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.EntryByDiscAndTrackComparator import org.moire.ultrasonic.util.EntryByDiscAndTrackComparator
import org.moire.ultrasonic.util.Settings import org.moire.ultrasonic.util.Settings
import org.moire.ultrasonic.util.Util import org.moire.ultrasonic.util.Util
import timber.log.Timber
/** /**
* Displays a group of tracks, eg. the songs of an album, of a playlist etc. * Displays a group of tracks, eg. the songs of an album, of a playlist etc.
@ -61,11 +62,11 @@ import org.moire.ultrasonic.util.Util
open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() { open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
private var albumButtons: View? = null private var albumButtons: View? = null
internal var selectButton: ImageView? = null private var selectButton: ImageView? = null
internal var playNowButton: ImageView? = null internal var playNowButton: ImageView? = null
private var playNextButton: ImageView? = null private var playNextButton: ImageView? = null
private var playLastButton: ImageView? = null private var playLastButton: ImageView? = null
internal var pinButton: ImageView? = null private var pinButton: ImageView? = null
private var unpinButton: ImageView? = null private var unpinButton: ImageView? = null
private var downloadButton: ImageView? = null private var downloadButton: ImageView? = null
private var deleteButton: ImageView? = null private var deleteButton: ImageView? = null
@ -144,11 +145,10 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
// Update the buttons when the selection has changed // Update the buttons when the selection has changed
viewAdapter.selectionRevision.observe( viewAdapter.selectionRevision.observe(
viewLifecycleOwner, viewLifecycleOwner
{ ) {
enableButtons() enableButtons()
} }
)
} }
internal open fun setupButtons(view: View) { internal open fun setupButtons(view: View) {
@ -267,10 +267,10 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
private val childCount: Int private val childCount: Int
get() { get() {
val count = viewAdapter.getCurrentList().count() val count = viewAdapter.getCurrentList().count()
if (listModel.showHeader) { return if (listModel.showHeader) {
return count - 1 count - 1
} else { } else {
return count count
} }
} }
@ -320,13 +320,13 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
} as List<Track> } as List<Track>
} }
internal fun selectAllOrNone() { private fun selectAllOrNone() {
val someUnselected = viewAdapter.selectedSet.size < childCount val someUnselected = viewAdapter.selectedSet.size < childCount
selectAll(someUnselected, true) selectAll(someUnselected, true)
} }
internal fun selectAll(selected: Boolean, toast: Boolean) { private fun selectAll(selected: Boolean, toast: Boolean) {
var selectedCount = viewAdapter.selectedSet.size * -1 var selectedCount = viewAdapter.selectedSet.size * -1
selectedCount += viewAdapter.setSelectionStatusOfAll(selected) selectedCount += viewAdapter.setSelectionStatusOfAll(selected)
@ -366,7 +366,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
deleteButton?.isVisible = (enabled && deleteEnabled) deleteButton?.isVisible = (enabled && deleteEnabled)
} }
internal fun downloadBackground(save: Boolean) { private fun downloadBackground(save: Boolean) {
var songs = getSelectedSongs() var songs = getSelectedSongs()
if (songs.isEmpty()) { if (songs.isEmpty()) {
@ -426,6 +426,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
override val defaultObserver: (List<MusicDirectory.Child>) -> Unit = { override val defaultObserver: (List<MusicDirectory.Child>) -> Unit = {
Timber.i("Received list")
val entryList: MutableList<MusicDirectory.Child> = it.toMutableList() val entryList: MutableList<MusicDirectory.Child> = it.toMutableList()
if (listModel.currentListIsSortable && Settings.shouldSortByDisc) { if (listModel.currentListIsSortable && Settings.shouldSortByDisc) {
@ -454,9 +455,9 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
moreButton!!.visibility = View.GONE moreButton!!.visibility = View.GONE
} else { } else {
moreButton!!.visibility = View.VISIBLE moreButton!!.visibility = View.VISIBLE
if (arguments?.getInt(Constants.INTENT_RANDOM, 0) ?: 0 > 0) { if ((arguments?.getInt(Constants.INTENT_RANDOM, 0) ?: 0) > 0) {
moreRandomTracks() moreRandomTracks()
} else if (arguments?.getString(Constants.INTENT_GENRE_NAME, "") ?: "" != "") { } else if ((arguments?.getString(Constants.INTENT_GENRE_NAME, "") ?: "") != "") {
moreSongsForGenre() moreSongsForGenre()
} }
} }
@ -497,6 +498,8 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
} }
listModel.currentListIsSortable = true listModel.currentListIsSortable = true
Timber.i("Processed list")
} }
private fun moreSongsForGenre(args: Bundle = requireArguments()) { private fun moreSongsForGenre(args: Bundle = requireArguments()) {
@ -556,6 +559,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
args: Bundle?, args: Bundle?,
refresh: Boolean refresh: Boolean
): LiveData<List<MusicDirectory.Child>> { ): LiveData<List<MusicDirectory.Child>> {
Timber.i("Starting gathering track collection data...")
if (args == null) return listModel.currentList if (args == null) return listModel.currentList
val id = args.getString(Constants.INTENT_ID) val id = args.getString(Constants.INTENT_ID)
val isAlbum = args.getBoolean(Constants.INTENT_IS_ALBUM, false) val isAlbum = args.getBoolean(Constants.INTENT_IS_ALBUM, false)
@ -669,7 +673,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
return true return true
} }
internal fun getClickedSong(item: MusicDirectory.Child): List<Track> { private fun getClickedSong(item: MusicDirectory.Child): List<Track> {
// This can probably be done better // This can probably be done better
return viewAdapter.getCurrentList().mapNotNull { return viewAdapter.getCurrentList().mapNotNull {
if (it is Track && (it.id == item.id)) if (it is Track && (it.id == item.id))

View File

@ -54,7 +54,6 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
// New Room Database // New Room Database
private var cachedArtists = metaDatabase.artistDao() private var cachedArtists = metaDatabase.artistDao()
private var cachedAlbums = metaDatabase.albumDao() private var cachedAlbums = metaDatabase.albumDao()
private var cachedTracks = metaDatabase.trackDao()
private var cachedIndexes = metaDatabase.indexDao() private var cachedIndexes = metaDatabase.indexDao()
private val cachedMusicFolders = metaDatabase.musicFoldersDao() private val cachedMusicFolders = metaDatabase.musicFoldersDao()
@ -118,40 +117,18 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
return indexes return indexes
} }
// FIXME why commented?
// @Throws(Exception::class)
// override fun getArtist(id: String, refresh: Boolean): Artist? {
//
// // Check if we have a cache hit
// var result = cachedArtists.get(id)
//
// if (result == null || refresh) {
// musicService.getArtists(refresh = true)
// }
// //var result = cachedArtists.get()
//
// if (result.isEmpty()) {
// result = getArtists(refresh)
// // FIXME
// // cachedAlbums.clear()
// cachedArtists.set(result)
// }
// return result
// }
//
@Throws(Exception::class) @Throws(Exception::class)
override fun getArtists(refresh: Boolean): List<Artist> { override fun getArtists(refresh: Boolean): List<Artist> {
checkSettingsChanged() checkSettingsChanged()
if (refresh) { if (refresh) {
cachedArtists.clear() cachedArtists.clear()
} }
// FIXME unnecessary check
var result = cachedArtists.get() var result = cachedArtists.get()
if (result.isEmpty()) { if (result.isEmpty()) {
result = musicService.getArtists(refresh) result = musicService.getArtists(refresh)
// FIXME
// cachedAlbums.clear()
cachedArtists.set(result) cachedArtists.set(result)
} }
return result return result
@ -173,6 +150,10 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
return dir return dir
} }
/*
* Retrieves all albums of the provided artist.
* Cached in the RoomDB
*/
@Throws(Exception::class) @Throws(Exception::class)
override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean): override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean):
List<Album> { List<Album> {

View File

@ -536,6 +536,7 @@ class Downloader(
// Now cache the album // Now cache the album
if (albumId?.isNotEmpty() == true) { if (albumId?.isNotEmpty() == true) {
// This is a cached call
val albums = musicService.getAlbumsOfArtist(artistId!!, null, false) val albums = musicService.getAlbumsOfArtist(artistId!!, null, false)
val album = albums.find { it.id == albumId } val album = albums.find { it.id == albumId }

View File

@ -60,8 +60,6 @@ class OfflineMusicService : MusicService, KoinComponent {
private var cachedArtists = metaDatabase.artistDao() private var cachedArtists = metaDatabase.artistDao()
private var cachedAlbums = metaDatabase.albumDao() private var cachedAlbums = metaDatabase.albumDao()
private var cachedTracks = metaDatabase.trackDao() private var cachedTracks = metaDatabase.trackDao()
private var cachedIndexes = metaDatabase.indexDao()
private val cachedMusicFolders = metaDatabase.musicFoldersDao()
override fun getIndexes(musicFolderId: String?, refresh: Boolean): List<Index> { override fun getIndexes(musicFolderId: String?, refresh: Boolean): List<Index> {
val indexes: MutableList<Index> = ArrayList() val indexes: MutableList<Index> = ArrayList()
@ -474,20 +472,22 @@ class OfflineMusicService : MusicService, KoinComponent {
@Throws(Exception::class) @Throws(Exception::class)
override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean): override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean):
List<Album> { List<Album> {
// FIXME: Add fallback?
return cachedAlbums.byArtist(id) return cachedAlbums.byArtist(id)
} }
@Throws(OfflineException::class) @Throws(OfflineException::class)
override fun getAlbum(id: String, name: String?, refresh: Boolean): MusicDirectory { override fun getAlbum(id: String, name: String?, refresh: Boolean): MusicDirectory {
Timber.i("Starting album query...")
val list = cachedTracks val list = cachedTracks
.byAlbum(id) .byAlbum(id)
.sortedWith(EntryByDiscAndTrackComparator()) .sortedWith(EntryByDiscAndTrackComparator())
var dir = MusicDirectory() val dir = MusicDirectory()
dir.addAll(list) dir.addAll(list)
Timber.i("Returning query.")
return dir return dir
} }