mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-03-12 09:30:14 +01:00
Fix header glitch
This commit is contained in:
parent
2f0ff384d0
commit
775f56c6fa
@ -17,6 +17,7 @@ import androidx.recyclerview.widget.DiffUtil
|
|||||||
import com.drakeet.multitype.MultiTypeAdapter
|
import com.drakeet.multitype.MultiTypeAdapter
|
||||||
import org.moire.ultrasonic.domain.Identifiable
|
import org.moire.ultrasonic.domain.Identifiable
|
||||||
import org.moire.ultrasonic.util.BoundedTreeSet
|
import org.moire.ultrasonic.util.BoundedTreeSet
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The BaseAdapter which extends the MultiTypeAdapter from an external library.
|
* 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.
|
* @param list The new list to be displayed.
|
||||||
*/
|
*/
|
||||||
fun submitList(list: List<T>?) {
|
fun submitList(list: List<T>?) {
|
||||||
|
Timber.v("Received fresh list, size %s", list?.size)
|
||||||
mDiffer.submitList(list)
|
mDiffer.submitList(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.
|
* 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")
|
@Suppress("TooManyFunctions")
|
||||||
open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
|
open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
|
||||||
@ -93,7 +93,7 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
|
|||||||
refreshData(true)
|
refreshData(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
listModel.currentList.observe(viewLifecycleOwner, updateInterfaceWithEntries)
|
// TODO: remove special casing for songsForGenre
|
||||||
listModel.songsForGenre.observe(viewLifecycleOwner, songsForGenreObserver)
|
listModel.songsForGenre.observe(viewLifecycleOwner, songsForGenreObserver)
|
||||||
|
|
||||||
setupButtons(view)
|
setupButtons(view)
|
||||||
@ -137,9 +137,6 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
|
|||||||
enableButtons()
|
enableButtons()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Loads the data
|
|
||||||
refreshData(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal open fun setupButtons(view: View) {
|
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()
|
val entryList: MutableList<MusicDirectory.Entry> = it.toMutableList()
|
||||||
|
|
||||||
@ -513,9 +510,8 @@ open class TrackCollectionFragment : MultiListFragment<MusicDirectory.Entry>() {
|
|||||||
shareButton?.isVisible = shareButtonVisible
|
shareButton?.isVisible = shareButtonVisible
|
||||||
|
|
||||||
if (songCount > 0 && listModel.showHeader) {
|
if (songCount > 0 && listModel.showHeader) {
|
||||||
val name = listModel.currentDirectory.value?.name
|
|
||||||
val intentAlbumName = arguments?.getString(Constants.INTENT_EXTRA_NAME_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)
|
val mixedList: MutableList<Identifiable> = mutableListOf(albumHeader)
|
||||||
mixedList.addAll(entryList)
|
mixedList.addAll(entryList)
|
||||||
viewAdapter.submitList(mixedList)
|
viewAdapter.submitList(mixedList)
|
||||||
|
@ -18,16 +18,15 @@ import org.moire.ultrasonic.util.Util
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Model for retrieving different collections of tracks from the API
|
* 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) {
|
class TrackCollectionModel(application: Application) : GenericListModel(application) {
|
||||||
|
|
||||||
val currentDirectory: MutableLiveData<MusicDirectory> = MutableLiveData()
|
|
||||||
val currentList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData()
|
val currentList: MutableLiveData<List<MusicDirectory.Entry>> = MutableLiveData()
|
||||||
val songsForGenre: MutableLiveData<MusicDirectory> = 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(
|
suspend fun getMusicDirectory(
|
||||||
refresh: Boolean,
|
refresh: Boolean,
|
||||||
id: String,
|
id: String,
|
||||||
@ -39,7 +38,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getMusicDirectory(id, name, refresh)
|
val musicDirectory = service.getMusicDirectory(id, name, refresh)
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,7 +69,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory: MusicDirectory = service.getAlbum(id, name, refresh)
|
val musicDirectory: MusicDirectory = service.getAlbum(id, name, refresh)
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,8 +93,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
} else {
|
} else {
|
||||||
musicDirectory = Util.getSongsFromSearchResult(service.getStarred())
|
musicDirectory = Util.getSongsFromSearchResult(service.getStarred())
|
||||||
}
|
}
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +104,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val videos = service.getVideos(refresh)
|
val videos = service.getVideos(refresh)
|
||||||
currentDirectory.postValue(videos)
|
|
||||||
if (videos != null) {
|
if (videos != null) {
|
||||||
updateList(videos)
|
updateList(videos)
|
||||||
}
|
}
|
||||||
@ -122,7 +118,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
val musicDirectory = service.getRandomSongs(size)
|
val musicDirectory = service.getRandomSongs(size)
|
||||||
|
|
||||||
currentListIsSortable = false
|
currentListIsSortable = false
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +129,6 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getPlaylist(playlistId, playlistName)
|
val musicDirectory = service.getPlaylist(playlistId, playlistName)
|
||||||
|
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +138,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = service.getPodcastEpisodes(podcastChannelId)
|
val musicDirectory = service.getPodcastEpisodes(podcastChannelId)
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
if (musicDirectory != null) {
|
if (musicDirectory != null) {
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
@ -166,7 +161,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,7 +170,7 @@ class TrackCollectionModel(application: Application) : GenericListModel(applicat
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val service = MusicServiceFactory.getMusicService()
|
val service = MusicServiceFactory.getMusicService()
|
||||||
val musicDirectory = Util.getSongsFromBookmarks(service.getBookmarks())
|
val musicDirectory = Util.getSongsFromBookmarks(service.getBookmarks())
|
||||||
currentDirectory.postValue(musicDirectory)
|
|
||||||
updateList(musicDirectory)
|
updateList(musicDirectory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user