Fix header glitch

This commit is contained in:
tzugen 2021-11-29 19:00:28 +01:00
parent 2f0ff384d0
commit 775f56c6fa
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
3 changed files with 15 additions and 22 deletions

View File

@ -17,6 +17,7 @@ import androidx.recyclerview.widget.DiffUtil
import com.drakeet.multitype.MultiTypeAdapter
import org.moire.ultrasonic.domain.Identifiable
import org.moire.ultrasonic.util.BoundedTreeSet
import timber.log.Timber
/**
* The BaseAdapter which extends the MultiTypeAdapter from an external library.
@ -86,6 +87,7 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter() {
* @param list The new list to be displayed.
*/
fun submitList(list: List<T>?) {
Timber.v("Received fresh list, size %s", list?.size)
mDiffer.submitList(list)
}

View File

@ -49,7 +49,7 @@ import org.moire.ultrasonic.util.Util
/**
* Displays a group of tracks, eg. the songs of an album, of a playlist etc.
* FIXME: Offset when navigating to?
* FIXME: Mixed lists are not handled correctly
*/
@Suppress("TooManyFunctions")
open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
@ -93,7 +93,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
refreshData(true)
}
listModel.currentList.observe(viewLifecycleOwner, updateInterfaceWithEntries)
// TODO: remove special casing for songsForGenre
listModel.songsForGenre.observe(viewLifecycleOwner, songsForGenreObserver)
setupButtons(view)
@ -137,9 +137,6 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
enableButtons()
}
)
// Loads the data
refreshData(false)
}
internal open fun setupButtons(view: View) {
@ -450,7 +447,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
}
}
private val updateInterfaceWithEntries = Observer<List<MusicDirectory.Entry>> {
override val defaultObserver: (List<MusicDirectory.Entry>) -> Unit = {
val entryList: MutableList<MusicDirectory.Entry> = it.toMutableList()
@ -513,9 +510,8 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
shareButton?.isVisible = shareButtonVisible
if (songCount > 0 && listModel.showHeader) {
val name = listModel.currentDirectory.value?.name
val intentAlbumName = arguments?.getString(Constants.INTENT_EXTRA_NAME_NAME, "")
val albumHeader = AlbumHeader(it, name ?: intentAlbumName)
val albumHeader = AlbumHeader(it, intentAlbumName)
val mixedList: MutableList<Identifiable> = mutableListOf(albumHeader)
mixedList.addAll(entryList)
viewAdapter.submitList(mixedList)

View File

@ -18,16 +18,15 @@ import org.moire.ultrasonic.util.Util
/*
* Model for retrieving different collections of tracks from the API
*
* TODO: Remove double data keeping in currentList/currentDirectory and use the base model liveData
* For this refactor MusicService to replace MusicDirectories with List<Album> or List<Track>
*/
class TrackCollectionModel(application: Application) : GenericListModel(application) {
val currentDirectory: MutableLiveData<MusicDirectory> = MutableLiveData()
val currentList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData()
val songsForGenre: MutableLiveData<MusicDirectory> = MutableLiveData()
/*
* Especially when dealing with indexes, this method can return Albums, Entries or a mix of both!
*/
suspend fun getMusicDirectory(
refresh: Boolean,
id: String,
@ -39,7 +38,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
val service = MusicServiceFactory.getMusicService()
val musicDirectory = service.getMusicDirectory(id, name, refresh)
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -71,7 +69,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
val service = MusicServiceFactory.getMusicService()
val musicDirectory: MusicDirectory = service.getAlbum(id, name, refresh)
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -96,8 +93,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
} else {
musicDirectory = Util.getSongsFromSearchResult(service.getStarred())
}
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -108,7 +104,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
withContext(Dispatchers.IO) {
val service = MusicServiceFactory.getMusicService()
val videos = service.getVideos(refresh)
currentDirectory.postValue(videos)
if (videos != null) {
updateList(videos)
}
@ -122,7 +118,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
val musicDirectory = service.getRandomSongs(size)
currentListIsSortable = false
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -133,7 +129,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
val service = MusicServiceFactory.getMusicService()
val musicDirectory = service.getPlaylist(playlistId, playlistName)
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -143,7 +138,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
withContext(Dispatchers.IO) {
val service = MusicServiceFactory.getMusicService()
val musicDirectory = service.getPodcastEpisodes(podcastChannelId)
currentDirectory.postValue(musicDirectory)
if (musicDirectory != null) {
updateList(musicDirectory)
}
@ -166,7 +161,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
break
}
}
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}
@ -175,7 +170,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
withContext(Dispatchers.IO) {
val service = MusicServiceFactory.getMusicService()
val musicDirectory = Util.getSongsFromBookmarks(service.getBookmarks())
currentDirectory.postValue(musicDirectory)
updateList(musicDirectory)
}
}