parent
60dbe70ca5
commit
241e51015f
|
@ -59,7 +59,7 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
|
|||
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),
|
||||
AsyncDifferConfig.Builder(diffCallback).build()
|
||||
)
|
||||
|
@ -182,12 +182,11 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
|
|||
|
||||
// Select them all
|
||||
getCurrentList().mapNotNullTo(
|
||||
selectedSet,
|
||||
{ entry ->
|
||||
// Exclude any -1 ids, eg. headers and other UI elements
|
||||
entry.longId.takeIf { it != -1L }
|
||||
}
|
||||
)
|
||||
selectedSet
|
||||
) { entry ->
|
||||
// Exclude any -1 ids, eg. headers and other UI elements
|
||||
entry.longId.takeIf { it != -1L }
|
||||
}
|
||||
|
||||
return selectedSet.count()
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ class ActiveServerProvider(
|
|||
private val repository: ServerSettingDao
|
||||
) : CoroutineScope by CoroutineScope(Dispatchers.IO) {
|
||||
private var cachedServer: ServerSetting? = null
|
||||
// FIXME cach never set
|
||||
private var cachedDatabase: MetaDatabase? = null
|
||||
private var cachedServerId: Int? = null
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ import org.moire.ultrasonic.util.Constants
|
|||
import org.moire.ultrasonic.util.EntryByDiscAndTrackComparator
|
||||
import org.moire.ultrasonic.util.Settings
|
||||
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.
|
||||
|
@ -61,11 +62,11 @@ import org.moire.ultrasonic.util.Util
|
|||
open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
||||
|
||||
private var albumButtons: View? = null
|
||||
internal var selectButton: ImageView? = null
|
||||
private var selectButton: ImageView? = null
|
||||
internal var playNowButton: ImageView? = null
|
||||
private var playNextButton: ImageView? = null
|
||||
private var playLastButton: ImageView? = null
|
||||
internal var pinButton: ImageView? = null
|
||||
private var pinButton: ImageView? = null
|
||||
private var unpinButton: ImageView? = null
|
||||
private var downloadButton: 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
|
||||
viewAdapter.selectionRevision.observe(
|
||||
viewLifecycleOwner,
|
||||
{
|
||||
enableButtons()
|
||||
}
|
||||
)
|
||||
viewLifecycleOwner
|
||||
) {
|
||||
enableButtons()
|
||||
}
|
||||
}
|
||||
|
||||
internal open fun setupButtons(view: View) {
|
||||
|
@ -267,10 +267,10 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
private val childCount: Int
|
||||
get() {
|
||||
val count = viewAdapter.getCurrentList().count()
|
||||
if (listModel.showHeader) {
|
||||
return count - 1
|
||||
return if (listModel.showHeader) {
|
||||
count - 1
|
||||
} else {
|
||||
return count
|
||||
count
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,13 +320,13 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
} as List<Track>
|
||||
}
|
||||
|
||||
internal fun selectAllOrNone() {
|
||||
private fun selectAllOrNone() {
|
||||
val someUnselected = viewAdapter.selectedSet.size < childCount
|
||||
|
||||
selectAll(someUnselected, true)
|
||||
}
|
||||
|
||||
internal fun selectAll(selected: Boolean, toast: Boolean) {
|
||||
private fun selectAll(selected: Boolean, toast: Boolean) {
|
||||
var selectedCount = viewAdapter.selectedSet.size * -1
|
||||
|
||||
selectedCount += viewAdapter.setSelectionStatusOfAll(selected)
|
||||
|
@ -366,7 +366,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
deleteButton?.isVisible = (enabled && deleteEnabled)
|
||||
}
|
||||
|
||||
internal fun downloadBackground(save: Boolean) {
|
||||
private fun downloadBackground(save: Boolean) {
|
||||
var songs = getSelectedSongs()
|
||||
|
||||
if (songs.isEmpty()) {
|
||||
|
@ -426,6 +426,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
|
||||
override val defaultObserver: (List<MusicDirectory.Child>) -> Unit = {
|
||||
|
||||
Timber.i("Received list")
|
||||
val entryList: MutableList<MusicDirectory.Child> = it.toMutableList()
|
||||
|
||||
if (listModel.currentListIsSortable && Settings.shouldSortByDisc) {
|
||||
|
@ -454,9 +455,9 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
moreButton!!.visibility = View.GONE
|
||||
} else {
|
||||
moreButton!!.visibility = View.VISIBLE
|
||||
if (arguments?.getInt(Constants.INTENT_RANDOM, 0) ?: 0 > 0) {
|
||||
if ((arguments?.getInt(Constants.INTENT_RANDOM, 0) ?: 0) > 0) {
|
||||
moreRandomTracks()
|
||||
} else if (arguments?.getString(Constants.INTENT_GENRE_NAME, "") ?: "" != "") {
|
||||
} else if ((arguments?.getString(Constants.INTENT_GENRE_NAME, "") ?: "") != "") {
|
||||
moreSongsForGenre()
|
||||
}
|
||||
}
|
||||
|
@ -497,6 +498,8 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
}
|
||||
|
||||
listModel.currentListIsSortable = true
|
||||
|
||||
Timber.i("Processed list")
|
||||
}
|
||||
|
||||
private fun moreSongsForGenre(args: Bundle = requireArguments()) {
|
||||
|
@ -556,6 +559,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
args: Bundle?,
|
||||
refresh: Boolean
|
||||
): LiveData<List<MusicDirectory.Child>> {
|
||||
Timber.i("Starting gathering track collection data...")
|
||||
if (args == null) return listModel.currentList
|
||||
val id = args.getString(Constants.INTENT_ID)
|
||||
val isAlbum = args.getBoolean(Constants.INTENT_IS_ALBUM, false)
|
||||
|
@ -669,7 +673,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Child>() {
|
|||
return true
|
||||
}
|
||||
|
||||
internal fun getClickedSong(item: MusicDirectory.Child): List<Track> {
|
||||
private fun getClickedSong(item: MusicDirectory.Child): List<Track> {
|
||||
// This can probably be done better
|
||||
return viewAdapter.getCurrentList().mapNotNull {
|
||||
if (it is Track && (it.id == item.id))
|
||||
|
|
|
@ -54,7 +54,6 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
|
|||
// New Room Database
|
||||
private var cachedArtists = metaDatabase.artistDao()
|
||||
private var cachedAlbums = metaDatabase.albumDao()
|
||||
private var cachedTracks = metaDatabase.trackDao()
|
||||
private var cachedIndexes = metaDatabase.indexDao()
|
||||
private val cachedMusicFolders = metaDatabase.musicFoldersDao()
|
||||
|
||||
|
@ -118,40 +117,18 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
|
|||
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)
|
||||
override fun getArtists(refresh: Boolean): List<Artist> {
|
||||
checkSettingsChanged()
|
||||
|
||||
if (refresh) {
|
||||
cachedArtists.clear()
|
||||
}
|
||||
// FIXME unnecessary check
|
||||
|
||||
var result = cachedArtists.get()
|
||||
|
||||
if (result.isEmpty()) {
|
||||
result = musicService.getArtists(refresh)
|
||||
// FIXME
|
||||
// cachedAlbums.clear()
|
||||
cachedArtists.set(result)
|
||||
}
|
||||
return result
|
||||
|
@ -173,6 +150,10 @@ class CachedMusicService(private val musicService: MusicService) : MusicService,
|
|||
return dir
|
||||
}
|
||||
|
||||
/*
|
||||
* Retrieves all albums of the provided artist.
|
||||
* Cached in the RoomDB
|
||||
*/
|
||||
@Throws(Exception::class)
|
||||
override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean):
|
||||
List<Album> {
|
||||
|
|
|
@ -536,6 +536,7 @@ class Downloader(
|
|||
|
||||
// Now cache the album
|
||||
if (albumId?.isNotEmpty() == true) {
|
||||
// This is a cached call
|
||||
val albums = musicService.getAlbumsOfArtist(artistId!!, null, false)
|
||||
val album = albums.find { it.id == albumId }
|
||||
|
||||
|
|
|
@ -60,8 +60,6 @@ class OfflineMusicService : MusicService, KoinComponent {
|
|||
private var cachedArtists = metaDatabase.artistDao()
|
||||
private var cachedAlbums = metaDatabase.albumDao()
|
||||
private var cachedTracks = metaDatabase.trackDao()
|
||||
private var cachedIndexes = metaDatabase.indexDao()
|
||||
private val cachedMusicFolders = metaDatabase.musicFoldersDao()
|
||||
|
||||
override fun getIndexes(musicFolderId: String?, refresh: Boolean): List<Index> {
|
||||
val indexes: MutableList<Index> = ArrayList()
|
||||
|
@ -474,20 +472,22 @@ class OfflineMusicService : MusicService, KoinComponent {
|
|||
@Throws(Exception::class)
|
||||
override fun getAlbumsOfArtist(id: String, name: String?, refresh: Boolean):
|
||||
List<Album> {
|
||||
// FIXME: Add fallback?
|
||||
return cachedAlbums.byArtist(id)
|
||||
}
|
||||
|
||||
@Throws(OfflineException::class)
|
||||
override fun getAlbum(id: String, name: String?, refresh: Boolean): MusicDirectory {
|
||||
|
||||
Timber.i("Starting album query...")
|
||||
|
||||
val list = cachedTracks
|
||||
.byAlbum(id)
|
||||
.sortedWith(EntryByDiscAndTrackComparator())
|
||||
|
||||
var dir = MusicDirectory()
|
||||
val dir = MusicDirectory()
|
||||
dir.addAll(list)
|
||||
|
||||
Timber.i("Returning query.")
|
||||
return dir
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue