list: disable complex diffing for now
Disable the new instructions-based system for now. The way I was doing reflection was likely far too unsafe and prone to bugs. I'll want to do it some other way.
This commit is contained in:
parent
8e9a22ccf3
commit
900bcd142e
14 changed files with 39 additions and 257 deletions
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
#### What's New
|
#### What's New
|
||||||
- Added ability to play/shuffle selections
|
- Added ability to play/shuffle selections
|
||||||
- Resigned header components
|
- Redesigned header components
|
||||||
- Resigned settings view
|
- Redesigned settings view
|
||||||
|
|
||||||
#### What's Improved
|
#### What's Improved
|
||||||
- Added ability to edit previously played or currently playing items in the queue
|
- Added ability to edit previously played or currently playing items in the queue
|
||||||
|
@ -13,7 +13,6 @@
|
||||||
- Pressing the button will now clear the current selection before navigating back
|
- Pressing the button will now clear the current selection before navigating back
|
||||||
- Added support for non-standard `ARTISTS` tags
|
- Added support for non-standard `ARTISTS` tags
|
||||||
- Play Next and Add To Queue now start playback if there is no queue to add
|
- Play Next and Add To Queue now start playback if there is no queue to add
|
||||||
- Made resorting list animations consistent across app
|
|
||||||
|
|
||||||
#### What's Fixed
|
#### What's Fixed
|
||||||
- Fixed unreliable ReplayGain adjustment application in certain situations
|
- Fixed unreliable ReplayGain adjustment application in certain situations
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.oxycblt.auxio.databinding.FragmentDetailBinding
|
||||||
import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter
|
import org.oxycblt.auxio.detail.recycler.AlbumDetailAdapter
|
||||||
import org.oxycblt.auxio.list.Item
|
import org.oxycblt.auxio.list.Item
|
||||||
import org.oxycblt.auxio.list.ListFragment
|
import org.oxycblt.auxio.list.ListFragment
|
||||||
|
import org.oxycblt.auxio.list.adapter.BasicListInstructions
|
||||||
import org.oxycblt.auxio.music.Album
|
import org.oxycblt.auxio.music.Album
|
||||||
import org.oxycblt.auxio.music.Artist
|
import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Music
|
import org.oxycblt.auxio.music.Music
|
||||||
|
@ -259,9 +260,7 @@ class AlbumDetailFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(items: List<Item>) {
|
private fun updateList(items: List<Item>) {
|
||||||
detailAdapter.submitList(
|
detailAdapter.submitList(items, BasicListInstructions.DIFF)
|
||||||
items, detailModel.albumListInstructions ?: DetailListInstructions.Diff)
|
|
||||||
detailModel.finishAlbumListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selected: List<Music>) {
|
private fun updateSelection(selected: List<Music>) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.oxycblt.auxio.detail.recycler.ArtistDetailAdapter
|
||||||
import org.oxycblt.auxio.detail.recycler.DetailAdapter
|
import org.oxycblt.auxio.detail.recycler.DetailAdapter
|
||||||
import org.oxycblt.auxio.list.Item
|
import org.oxycblt.auxio.list.Item
|
||||||
import org.oxycblt.auxio.list.ListFragment
|
import org.oxycblt.auxio.list.ListFragment
|
||||||
|
import org.oxycblt.auxio.list.adapter.BasicListInstructions
|
||||||
import org.oxycblt.auxio.music.Album
|
import org.oxycblt.auxio.music.Album
|
||||||
import org.oxycblt.auxio.music.Artist
|
import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Music
|
import org.oxycblt.auxio.music.Music
|
||||||
|
@ -235,9 +236,7 @@ class ArtistDetailFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(items: List<Item>) {
|
private fun updateList(items: List<Item>) {
|
||||||
detailAdapter.submitList(
|
detailAdapter.submitList(items, BasicListInstructions.DIFF)
|
||||||
items, detailModel.artistListInstructions ?: DetailListInstructions.Diff)
|
|
||||||
detailModel.finishArtistListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selected: List<Music>) {
|
private fun updateSelection(selected: List<Music>) {
|
||||||
|
|
|
@ -48,18 +48,3 @@ data class SongProperties(
|
||||||
val sampleRateHz: Int?,
|
val sampleRateHz: Int?,
|
||||||
val resolvedMimeType: MimeType
|
val resolvedMimeType: MimeType
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the specific way to update a list of items in the detail lists.
|
|
||||||
* @author Alexander Capehart (OxygenCobalt)
|
|
||||||
*/
|
|
||||||
sealed class DetailListInstructions {
|
|
||||||
/** Do a plain asynchronous diff. */
|
|
||||||
object Diff : DetailListInstructions()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replace all the items starting at the given index.
|
|
||||||
* @param at The index to start replacing at.
|
|
||||||
*/
|
|
||||||
data class ReplaceRest(val at: Int) : DetailListInstructions()
|
|
||||||
}
|
|
||||||
|
|
|
@ -78,18 +78,14 @@ class DetailViewModel(application: Application) :
|
||||||
/** The current list data derived from [currentAlbum]. */
|
/** The current list data derived from [currentAlbum]. */
|
||||||
val albumList: StateFlow<List<Item>>
|
val albumList: StateFlow<List<Item>>
|
||||||
get() = _albumList
|
get() = _albumList
|
||||||
/** Specifies how to update [albumList] when it changes. */
|
|
||||||
var albumListInstructions: DetailListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
/** The current [Sort] used for [Song]s in [albumList]. */
|
/** The current [Sort] used for [Song]s in [albumList]. */
|
||||||
var albumSongSort: Sort
|
var albumSongSort: Sort
|
||||||
get() = musicSettings.albumSongSort
|
get() = musicSettings.albumSongSort
|
||||||
set(value) {
|
set(value) {
|
||||||
musicSettings.albumSongSort = value
|
musicSettings.albumSongSort = value
|
||||||
// Refresh the album list to reflect the new sort. Make sure we only visually replace
|
// Refresh the album list to reflect the new sort.
|
||||||
// the song information, however.
|
currentAlbum.value?.let(::refreshAlbumList)
|
||||||
currentAlbum.value?.let { refreshAlbumList(it, true) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- ARTIST ---
|
// --- ARTIST ---
|
||||||
|
@ -102,18 +98,14 @@ class DetailViewModel(application: Application) :
|
||||||
private val _artistList = MutableStateFlow(listOf<Item>())
|
private val _artistList = MutableStateFlow(listOf<Item>())
|
||||||
/** The current list derived from [currentArtist]. */
|
/** The current list derived from [currentArtist]. */
|
||||||
val artistList: StateFlow<List<Item>> = _artistList
|
val artistList: StateFlow<List<Item>> = _artistList
|
||||||
/** Specifies how to update [artistList] when it changes. */
|
|
||||||
var artistListInstructions: DetailListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
/** The current [Sort] used for [Song]s in [artistList]. */
|
/** The current [Sort] used for [Song]s in [artistList]. */
|
||||||
var artistSongSort: Sort
|
var artistSongSort: Sort
|
||||||
get() = musicSettings.artistSongSort
|
get() = musicSettings.artistSongSort
|
||||||
set(value) {
|
set(value) {
|
||||||
musicSettings.artistSongSort = value
|
musicSettings.artistSongSort = value
|
||||||
// Refresh the artist list to reflect the new sort. Make sure we only visually replace
|
// Refresh the artist list to reflect the new sort.
|
||||||
// the song information, however.
|
currentArtist.value?.let(::refreshArtistList)
|
||||||
currentArtist.value?.let { refreshArtistList(it, true) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- GENRE ---
|
// --- GENRE ---
|
||||||
|
@ -126,18 +118,14 @@ class DetailViewModel(application: Application) :
|
||||||
private val _genreList = MutableStateFlow(listOf<Item>())
|
private val _genreList = MutableStateFlow(listOf<Item>())
|
||||||
/** The current list data derived from [currentGenre]. */
|
/** The current list data derived from [currentGenre]. */
|
||||||
val genreList: StateFlow<List<Item>> = _genreList
|
val genreList: StateFlow<List<Item>> = _genreList
|
||||||
/** Specifies how to update [genreList] when it changes. */
|
|
||||||
var genreListInstructions: DetailListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
/** The current [Sort] used for [Song]s in [genreList]. */
|
/** The current [Sort] used for [Song]s in [genreList]. */
|
||||||
var genreSongSort: Sort
|
var genreSongSort: Sort
|
||||||
get() = musicSettings.genreSongSort
|
get() = musicSettings.genreSongSort
|
||||||
set(value) {
|
set(value) {
|
||||||
musicSettings.genreSongSort = value
|
musicSettings.genreSongSort = value
|
||||||
// Refresh the genre list to reflect the new sort. Make sure we only visually replace
|
// Refresh the genre list to reflect the new sort.
|
||||||
// the song information, however.
|
currentGenre.value?.let(::refreshGenreList)
|
||||||
currentGenre.value?.let { refreshGenreList(it, true) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,19 +161,19 @@ class DetailViewModel(application: Application) :
|
||||||
|
|
||||||
val album = currentAlbum.value
|
val album = currentAlbum.value
|
||||||
if (album != null) {
|
if (album != null) {
|
||||||
_currentAlbum.value = library.sanitize(album)?.also { refreshAlbumList(it, false) }
|
_currentAlbum.value = library.sanitize(album)?.also(::refreshAlbumList)
|
||||||
logD("Updated genre to ${currentAlbum.value}")
|
logD("Updated genre to ${currentAlbum.value}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val artist = currentArtist.value
|
val artist = currentArtist.value
|
||||||
if (artist != null) {
|
if (artist != null) {
|
||||||
_currentArtist.value = library.sanitize(artist)?.also { refreshArtistList(it, false) }
|
_currentArtist.value = library.sanitize(artist)?.also(::refreshArtistList)
|
||||||
logD("Updated genre to ${currentArtist.value}")
|
logD("Updated genre to ${currentArtist.value}")
|
||||||
}
|
}
|
||||||
|
|
||||||
val genre = currentGenre.value
|
val genre = currentGenre.value
|
||||||
if (genre != null) {
|
if (genre != null) {
|
||||||
_currentGenre.value = library.sanitize(genre)?.also { refreshGenreList(it, false) }
|
_currentGenre.value = library.sanitize(genre)?.also(::refreshGenreList)
|
||||||
logD("Updated genre to ${currentGenre.value}")
|
logD("Updated genre to ${currentGenre.value}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,7 +203,7 @@ class DetailViewModel(application: Application) :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logD("Opening Album [uid: $uid]")
|
logD("Opening Album [uid: $uid]")
|
||||||
_currentAlbum.value = requireMusic<Album>(uid)?.also { refreshAlbumList(it, false) }
|
_currentAlbum.value = requireMusic<Album>(uid)?.also(::refreshAlbumList)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,7 +217,7 @@ class DetailViewModel(application: Application) :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logD("Opening Artist [uid: $uid]")
|
logD("Opening Artist [uid: $uid]")
|
||||||
_currentArtist.value = requireMusic<Artist>(uid)?.also { refreshArtistList(it, false) }
|
_currentArtist.value = requireMusic<Artist>(uid)?.also(::refreshArtistList)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -243,29 +231,7 @@ class DetailViewModel(application: Application) :
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logD("Opening Genre [uid: $uid]")
|
logD("Opening Genre [uid: $uid]")
|
||||||
_currentGenre.value = requireMusic<Genre>(uid)?.also { refreshGenreList(it, false) }
|
_currentGenre.value = requireMusic<Genre>(uid)?.also(::refreshGenreList)
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [DetailListInstructions] in [albumListInstructions] were performed.
|
|
||||||
*/
|
|
||||||
fun finishAlbumListInstructions() {
|
|
||||||
albumListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [DetailListInstructions] in [artistListInstructions] were
|
|
||||||
* performed.
|
|
||||||
*/
|
|
||||||
fun finishArtistListInstructions() {
|
|
||||||
artistListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [DetailListInstructions] in [genreListInstructions] were performed.
|
|
||||||
*/
|
|
||||||
fun finishGenreListInstructions() {
|
|
||||||
genreListInstructions = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun <T : Music> requireMusic(uid: Music.UID) = musicStore.library?.find<T>(uid)
|
private fun <T : Music> requireMusic(uid: Music.UID) = musicStore.library?.find<T>(uid)
|
||||||
|
@ -348,11 +314,11 @@ class DetailViewModel(application: Application) :
|
||||||
return SongProperties(bitrate, sampleRate, resolvedMimeType)
|
return SongProperties(bitrate, sampleRate, resolvedMimeType)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshAlbumList(album: Album, replace: Boolean): Int {
|
private fun refreshAlbumList(album: Album) {
|
||||||
logD("Refreshing album data")
|
logD("Refreshing album data")
|
||||||
val data = mutableListOf<Item>(album)
|
val data = mutableListOf<Item>(album)
|
||||||
data.add(SortHeader(R.string.lbl_songs))
|
data.add(SortHeader(R.string.lbl_songs))
|
||||||
val songsStartIndex = data.size
|
|
||||||
// To create a good user experience regarding disc numbers, we group the album's
|
// To create a good user experience regarding disc numbers, we group the album's
|
||||||
// songs up by disc and then delimit the groups by a disc header.
|
// songs up by disc and then delimit the groups by a disc header.
|
||||||
val songs = albumSongSort.songs(album.songs)
|
val songs = albumSongSort.songs(album.songs)
|
||||||
|
@ -368,17 +334,11 @@ class DetailViewModel(application: Application) :
|
||||||
// Album only has one disc, don't add any redundant headers
|
// Album only has one disc, don't add any redundant headers
|
||||||
data.addAll(songs)
|
data.addAll(songs)
|
||||||
}
|
}
|
||||||
albumListInstructions =
|
|
||||||
if (replace) {
|
|
||||||
DetailListInstructions.ReplaceRest(songsStartIndex)
|
|
||||||
} else {
|
|
||||||
DetailListInstructions.Diff
|
|
||||||
}
|
|
||||||
_albumList.value = data
|
_albumList.value = data
|
||||||
return songsStartIndex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshArtistList(artist: Artist, replace: Boolean) {
|
private fun refreshArtistList(artist: Artist) {
|
||||||
logD("Refreshing artist data")
|
logD("Refreshing artist data")
|
||||||
val data = mutableListOf<Item>(artist)
|
val data = mutableListOf<Item>(artist)
|
||||||
val albums = Sort(Sort.Mode.ByDate, false).albums(artist.albums)
|
val albums = Sort(Sort.Mode.ByDate, false).albums(artist.albums)
|
||||||
|
@ -411,40 +371,24 @@ class DetailViewModel(application: Application) :
|
||||||
data.addAll(entry.value)
|
data.addAll(entry.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
var songsStartIndex: Int? = null
|
|
||||||
// Artists may not be linked to any songs, only include a header entry if we have any.
|
// Artists may not be linked to any songs, only include a header entry if we have any.
|
||||||
if (artist.songs.isNotEmpty()) {
|
if (artist.songs.isNotEmpty()) {
|
||||||
logD("Songs present in this artist, adding header")
|
logD("Songs present in this artist, adding header")
|
||||||
data.add(SortHeader(R.string.lbl_songs))
|
data.add(SortHeader(R.string.lbl_songs))
|
||||||
songsStartIndex = data.size
|
|
||||||
data.addAll(artistSongSort.songs(artist.songs))
|
data.addAll(artistSongSort.songs(artist.songs))
|
||||||
}
|
}
|
||||||
|
|
||||||
artistListInstructions =
|
|
||||||
if (replace) {
|
|
||||||
DetailListInstructions.ReplaceRest(
|
|
||||||
requireNotNull(songsStartIndex) { "Cannot replace empty artist song list" })
|
|
||||||
} else {
|
|
||||||
DetailListInstructions.Diff
|
|
||||||
}
|
|
||||||
_artistList.value = data.toList()
|
_artistList.value = data.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refreshGenreList(genre: Genre, replace: Boolean) {
|
private fun refreshGenreList(genre: Genre) {
|
||||||
logD("Refreshing genre data")
|
logD("Refreshing genre data")
|
||||||
val data = mutableListOf<Item>(genre)
|
val data = mutableListOf<Item>(genre)
|
||||||
// Genre is guaranteed to always have artists and songs.
|
// Genre is guaranteed to always have artists and songs.
|
||||||
data.add(Header(R.string.lbl_artists))
|
data.add(Header(R.string.lbl_artists))
|
||||||
data.addAll(genre.artists)
|
data.addAll(genre.artists)
|
||||||
data.add(SortHeader(R.string.lbl_songs))
|
data.add(SortHeader(R.string.lbl_songs))
|
||||||
val songsStartIndex = data.size
|
|
||||||
data.addAll(genreSongSort.songs(genre.songs))
|
data.addAll(genreSongSort.songs(genre.songs))
|
||||||
genreListInstructions =
|
|
||||||
if (replace) {
|
|
||||||
DetailListInstructions.ReplaceRest(songsStartIndex)
|
|
||||||
} else {
|
|
||||||
DetailListInstructions.Diff
|
|
||||||
}
|
|
||||||
_genreList.value = data
|
_genreList.value = data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.oxycblt.auxio.detail.recycler.DetailAdapter
|
||||||
import org.oxycblt.auxio.detail.recycler.GenreDetailAdapter
|
import org.oxycblt.auxio.detail.recycler.GenreDetailAdapter
|
||||||
import org.oxycblt.auxio.list.Item
|
import org.oxycblt.auxio.list.Item
|
||||||
import org.oxycblt.auxio.list.ListFragment
|
import org.oxycblt.auxio.list.ListFragment
|
||||||
|
import org.oxycblt.auxio.list.adapter.BasicListInstructions
|
||||||
import org.oxycblt.auxio.music.Album
|
import org.oxycblt.auxio.music.Album
|
||||||
import org.oxycblt.auxio.music.Artist
|
import org.oxycblt.auxio.music.Artist
|
||||||
import org.oxycblt.auxio.music.Genre
|
import org.oxycblt.auxio.music.Genre
|
||||||
|
@ -218,9 +219,7 @@ class GenreDetailFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(items: List<Item>) {
|
private fun updateList(items: List<Item>) {
|
||||||
detailAdapter.submitList(
|
detailAdapter.submitList(items, BasicListInstructions.DIFF)
|
||||||
items, detailModel.genreListInstructions ?: DetailListInstructions.Diff)
|
|
||||||
detailModel.finishGenreListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selected: List<Music>) {
|
private fun updateSelection(selected: List<Music>) {
|
||||||
|
|
|
@ -20,23 +20,15 @@ package org.oxycblt.auxio.detail.recycler
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.appcompat.widget.TooltipCompat
|
import androidx.appcompat.widget.TooltipCompat
|
||||||
import androidx.recyclerview.widget.AdapterListUpdateCallback
|
|
||||||
import androidx.recyclerview.widget.AsyncDifferConfig
|
|
||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
import androidx.recyclerview.widget.ListUpdateCallback
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import org.oxycblt.auxio.IntegerTable
|
import org.oxycblt.auxio.IntegerTable
|
||||||
import org.oxycblt.auxio.databinding.ItemSortHeaderBinding
|
import org.oxycblt.auxio.databinding.ItemSortHeaderBinding
|
||||||
import org.oxycblt.auxio.detail.DetailListInstructions
|
|
||||||
import org.oxycblt.auxio.detail.SortHeader
|
import org.oxycblt.auxio.detail.SortHeader
|
||||||
import org.oxycblt.auxio.list.Header
|
import org.oxycblt.auxio.list.Header
|
||||||
import org.oxycblt.auxio.list.Item
|
import org.oxycblt.auxio.list.Item
|
||||||
import org.oxycblt.auxio.list.SelectableListListener
|
import org.oxycblt.auxio.list.SelectableListListener
|
||||||
import org.oxycblt.auxio.list.adapter.ListDiffer
|
import org.oxycblt.auxio.list.adapter.*
|
||||||
import org.oxycblt.auxio.list.adapter.SelectionIndicatorAdapter
|
|
||||||
import org.oxycblt.auxio.list.adapter.SimpleDiffCallback
|
|
||||||
import org.oxycblt.auxio.list.adapter.overwriteList
|
|
||||||
import org.oxycblt.auxio.list.recycler.*
|
import org.oxycblt.auxio.list.recycler.*
|
||||||
import org.oxycblt.auxio.music.Music
|
import org.oxycblt.auxio.music.Music
|
||||||
import org.oxycblt.auxio.util.context
|
import org.oxycblt.auxio.util.context
|
||||||
|
@ -53,8 +45,8 @@ abstract class DetailAdapter(
|
||||||
private val listener: Listener<*>,
|
private val listener: Listener<*>,
|
||||||
diffCallback: DiffUtil.ItemCallback<Item>
|
diffCallback: DiffUtil.ItemCallback<Item>
|
||||||
) :
|
) :
|
||||||
SelectionIndicatorAdapter<Item, DetailListInstructions, RecyclerView.ViewHolder>(
|
SelectionIndicatorAdapter<Item, BasicListInstructions, RecyclerView.ViewHolder>(
|
||||||
DetailListDiffer.Factory(diffCallback)),
|
ListDiffer.Async(diffCallback)),
|
||||||
AuxioRecyclerView.SpanSizeLookup {
|
AuxioRecyclerView.SpanSizeLookup {
|
||||||
|
|
||||||
override fun getItemViewType(position: Int) =
|
override fun getItemViewType(position: Int) =
|
||||||
|
@ -124,39 +116,6 @@ abstract class DetailAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class DetailListDiffer<T>(
|
|
||||||
private val updateCallback: ListUpdateCallback,
|
|
||||||
diffCallback: DiffUtil.ItemCallback<T>
|
|
||||||
) : ListDiffer<T, DetailListInstructions> {
|
|
||||||
private val inner =
|
|
||||||
AsyncListDiffer(updateCallback, AsyncDifferConfig.Builder(diffCallback).build())
|
|
||||||
|
|
||||||
override val currentList: List<T>
|
|
||||||
get() = inner.currentList
|
|
||||||
|
|
||||||
override fun submitList(
|
|
||||||
newList: List<T>,
|
|
||||||
instructions: DetailListInstructions,
|
|
||||||
onDone: () -> Unit
|
|
||||||
) {
|
|
||||||
when (instructions) {
|
|
||||||
is DetailListInstructions.Diff -> inner.submitList(newList, onDone)
|
|
||||||
is DetailListInstructions.ReplaceRest -> {
|
|
||||||
val amount = newList.size - instructions.at
|
|
||||||
updateCallback.onRemoved(instructions.at, amount)
|
|
||||||
inner.overwriteList(newList)
|
|
||||||
updateCallback.onInserted(instructions.at, amount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Factory<T>(private val diffCallback: DiffUtil.ItemCallback<T>) :
|
|
||||||
ListDiffer.Factory<T, DetailListInstructions>() {
|
|
||||||
override fun new(adapter: RecyclerView.Adapter<*>) =
|
|
||||||
DetailListDiffer(AdapterListUpdateCallback(adapter), diffCallback)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [RecyclerView.ViewHolder] that displays a [SortHeader], a variation on [Header] that adds a
|
* A [RecyclerView.ViewHolder] that displays a [SortHeader], a variation on [Header] that adds a
|
||||||
* button opening a menu for sorting. Use [from] to create an instance.
|
* button opening a menu for sorting. Use [from] to create an instance.
|
||||||
|
|
|
@ -45,17 +45,11 @@ class HomeViewModel(application: Application) :
|
||||||
/** A list of [Song]s, sorted by the preferred [Sort], to be shown in the home view. */
|
/** A list of [Song]s, sorted by the preferred [Sort], to be shown in the home view. */
|
||||||
val songsList: StateFlow<List<Song>>
|
val songsList: StateFlow<List<Song>>
|
||||||
get() = _songsList
|
get() = _songsList
|
||||||
/** Specifies how to update [songsList] when it changes. */
|
|
||||||
var songsListInstructions: BasicListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
private val _albumsLists = MutableStateFlow(listOf<Album>())
|
private val _albumsLists = MutableStateFlow(listOf<Album>())
|
||||||
/** A list of [Album]s, sorted by the preferred [Sort], to be shown in the home view. */
|
/** A list of [Album]s, sorted by the preferred [Sort], to be shown in the home view. */
|
||||||
val albumsList: StateFlow<List<Album>>
|
val albumsList: StateFlow<List<Album>>
|
||||||
get() = _albumsLists
|
get() = _albumsLists
|
||||||
/** Specifies how to update [albumsList] when it changes. */
|
|
||||||
var albumsListInstructions: BasicListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
private val _artistsList = MutableStateFlow(listOf<Artist>())
|
private val _artistsList = MutableStateFlow(listOf<Artist>())
|
||||||
/**
|
/**
|
||||||
|
@ -65,17 +59,11 @@ class HomeViewModel(application: Application) :
|
||||||
*/
|
*/
|
||||||
val artistsList: MutableStateFlow<List<Artist>>
|
val artistsList: MutableStateFlow<List<Artist>>
|
||||||
get() = _artistsList
|
get() = _artistsList
|
||||||
/** Specifies how to update [artistsList] when it changes. */
|
|
||||||
var artistsListInstructions: BasicListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
private val _genresList = MutableStateFlow(listOf<Genre>())
|
private val _genresList = MutableStateFlow(listOf<Genre>())
|
||||||
/** A list of [Genre]s, sorted by the preferred [Sort], to be shown in the home view. */
|
/** A list of [Genre]s, sorted by the preferred [Sort], to be shown in the home view. */
|
||||||
val genresList: StateFlow<List<Genre>>
|
val genresList: StateFlow<List<Genre>>
|
||||||
get() = _genresList
|
get() = _genresList
|
||||||
/** Specifies how to update [genresList] when it changes. */
|
|
||||||
var genresListInstructions: BasicListInstructions? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
/** The [MusicMode] to use when playing a [Song] from the UI. */
|
/** The [MusicMode] to use when playing a [Song] from the UI. */
|
||||||
val playbackMode: MusicMode
|
val playbackMode: MusicMode
|
||||||
|
@ -120,11 +108,8 @@ class HomeViewModel(application: Application) :
|
||||||
logD("Library changed, refreshing library")
|
logD("Library changed, refreshing library")
|
||||||
// Get the each list of items in the library to use as our list data.
|
// Get the each list of items in the library to use as our list data.
|
||||||
// Applying the preferred sorting to them.
|
// Applying the preferred sorting to them.
|
||||||
songsListInstructions = BasicListInstructions.DIFF
|
|
||||||
_songsList.value = musicSettings.songSort.songs(library.songs)
|
_songsList.value = musicSettings.songSort.songs(library.songs)
|
||||||
albumsListInstructions = BasicListInstructions.DIFF
|
|
||||||
_albumsLists.value = musicSettings.albumSort.albums(library.albums)
|
_albumsLists.value = musicSettings.albumSort.albums(library.albums)
|
||||||
artistsListInstructions = BasicListInstructions.DIFF
|
|
||||||
_artistsList.value =
|
_artistsList.value =
|
||||||
musicSettings.artistSort.artists(
|
musicSettings.artistSort.artists(
|
||||||
if (homeSettings.shouldHideCollaborators) {
|
if (homeSettings.shouldHideCollaborators) {
|
||||||
|
@ -133,7 +118,6 @@ class HomeViewModel(application: Application) :
|
||||||
} else {
|
} else {
|
||||||
library.artists
|
library.artists
|
||||||
})
|
})
|
||||||
genresListInstructions = BasicListInstructions.DIFF
|
|
||||||
_genresList.value = musicSettings.genreSort.genres(library.genres)
|
_genresList.value = musicSettings.genreSort.genres(library.genres)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,56 +157,23 @@ class HomeViewModel(application: Application) :
|
||||||
when (_currentTabMode.value) {
|
when (_currentTabMode.value) {
|
||||||
MusicMode.SONGS -> {
|
MusicMode.SONGS -> {
|
||||||
musicSettings.songSort = sort
|
musicSettings.songSort = sort
|
||||||
songsListInstructions = BasicListInstructions.REPLACE
|
|
||||||
_songsList.value = sort.songs(_songsList.value)
|
_songsList.value = sort.songs(_songsList.value)
|
||||||
}
|
}
|
||||||
MusicMode.ALBUMS -> {
|
MusicMode.ALBUMS -> {
|
||||||
musicSettings.albumSort = sort
|
musicSettings.albumSort = sort
|
||||||
albumsListInstructions = BasicListInstructions.REPLACE
|
|
||||||
_albumsLists.value = sort.albums(_albumsLists.value)
|
_albumsLists.value = sort.albums(_albumsLists.value)
|
||||||
}
|
}
|
||||||
MusicMode.ARTISTS -> {
|
MusicMode.ARTISTS -> {
|
||||||
musicSettings.artistSort = sort
|
musicSettings.artistSort = sort
|
||||||
artistsListInstructions = BasicListInstructions.REPLACE
|
|
||||||
_artistsList.value = sort.artists(_artistsList.value)
|
_artistsList.value = sort.artists(_artistsList.value)
|
||||||
}
|
}
|
||||||
MusicMode.GENRES -> {
|
MusicMode.GENRES -> {
|
||||||
musicSettings.genreSort = sort
|
musicSettings.genreSort = sort
|
||||||
genresListInstructions = BasicListInstructions.REPLACE
|
|
||||||
_genresList.value = sort.genres(_genresList.value)
|
_genresList.value = sort.genres(_genresList.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [BasicListInstructions] in [songsListInstructions] were performed.
|
|
||||||
*/
|
|
||||||
fun finishSongsListInstructions() {
|
|
||||||
songsListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [BasicListInstructions] in [albumsListInstructions] were performed.
|
|
||||||
*/
|
|
||||||
fun finishAlbumsListInstructions() {
|
|
||||||
albumsListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [BasicListInstructions] in [artistsListInstructions] were
|
|
||||||
* performed.
|
|
||||||
*/
|
|
||||||
fun finishArtistsListInstructions() {
|
|
||||||
artistsListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Signal that the specified [BasicListInstructions] in [genresListInstructions] were performed.
|
|
||||||
*/
|
|
||||||
fun finishGenresListInstructions() {
|
|
||||||
genresListInstructions = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update [currentTabMode] to reflect a new ViewPager2 position
|
* Update [currentTabMode] to reflect a new ViewPager2 position
|
||||||
* @param pagerPos The new position of the ViewPager2 instance.
|
* @param pagerPos The new position of the ViewPager2 instance.
|
||||||
|
|
|
@ -132,9 +132,7 @@ class AlbumListFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(albums: List<Album>) {
|
private fun updateList(albums: List<Album>) {
|
||||||
albumAdapter.submitList(
|
albumAdapter.submitList(albums, BasicListInstructions.REPLACE)
|
||||||
albums, homeModel.albumsListInstructions ?: BasicListInstructions.DIFF)
|
|
||||||
homeModel.finishAlbumsListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selection: List<Music>) {
|
private fun updateSelection(selection: List<Music>) {
|
||||||
|
@ -152,7 +150,7 @@ class AlbumListFragment :
|
||||||
*/
|
*/
|
||||||
private class AlbumAdapter(private val listener: SelectableListListener<Album>) :
|
private class AlbumAdapter(private val listener: SelectableListListener<Album>) :
|
||||||
SelectionIndicatorAdapter<Album, BasicListInstructions, AlbumViewHolder>(
|
SelectionIndicatorAdapter<Album, BasicListInstructions, AlbumViewHolder>(
|
||||||
ListDiffer.Async(AlbumViewHolder.DIFF_CALLBACK)) {
|
ListDiffer.Blocking(AlbumViewHolder.DIFF_CALLBACK)) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||||
AlbumViewHolder.from(parent)
|
AlbumViewHolder.from(parent)
|
||||||
|
|
|
@ -110,9 +110,7 @@ class ArtistListFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(artists: List<Artist>) {
|
private fun updateList(artists: List<Artist>) {
|
||||||
artistAdapter.submitList(
|
artistAdapter.submitList(artists, BasicListInstructions.REPLACE)
|
||||||
artists, homeModel.artistsListInstructions ?: BasicListInstructions.DIFF)
|
|
||||||
homeModel.finishArtistsListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selection: List<Music>) {
|
private fun updateSelection(selection: List<Music>) {
|
||||||
|
@ -130,7 +128,7 @@ class ArtistListFragment :
|
||||||
*/
|
*/
|
||||||
private class ArtistAdapter(private val listener: SelectableListListener<Artist>) :
|
private class ArtistAdapter(private val listener: SelectableListListener<Artist>) :
|
||||||
SelectionIndicatorAdapter<Artist, BasicListInstructions, ArtistViewHolder>(
|
SelectionIndicatorAdapter<Artist, BasicListInstructions, ArtistViewHolder>(
|
||||||
ListDiffer.Async(ArtistViewHolder.DIFF_CALLBACK)) {
|
ListDiffer.Blocking(ArtistViewHolder.DIFF_CALLBACK)) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||||
ArtistViewHolder.from(parent)
|
ArtistViewHolder.from(parent)
|
||||||
|
|
|
@ -109,9 +109,7 @@ class GenreListFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(artists: List<Genre>) {
|
private fun updateList(artists: List<Genre>) {
|
||||||
genreAdapter.submitList(
|
genreAdapter.submitList(artists, BasicListInstructions.REPLACE)
|
||||||
artists, homeModel.genresListInstructions ?: BasicListInstructions.DIFF)
|
|
||||||
homeModel.finishGenresListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selection: List<Music>) {
|
private fun updateSelection(selection: List<Music>) {
|
||||||
|
@ -129,7 +127,7 @@ class GenreListFragment :
|
||||||
*/
|
*/
|
||||||
private class GenreAdapter(private val listener: SelectableListListener<Genre>) :
|
private class GenreAdapter(private val listener: SelectableListListener<Genre>) :
|
||||||
SelectionIndicatorAdapter<Genre, BasicListInstructions, GenreViewHolder>(
|
SelectionIndicatorAdapter<Genre, BasicListInstructions, GenreViewHolder>(
|
||||||
ListDiffer.Async(GenreViewHolder.DIFF_CALLBACK)) {
|
ListDiffer.Blocking(GenreViewHolder.DIFF_CALLBACK)) {
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||||
GenreViewHolder.from(parent)
|
GenreViewHolder.from(parent)
|
||||||
|
|
||||||
|
|
|
@ -139,8 +139,7 @@ class SongListFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateList(songs: List<Song>) {
|
private fun updateList(songs: List<Song>) {
|
||||||
songAdapter.submitList(songs, homeModel.songsListInstructions ?: BasicListInstructions.DIFF)
|
songAdapter.submitList(songs, BasicListInstructions.REPLACE)
|
||||||
homeModel.finishSongsListInstructions()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSelection(selection: List<Music>) {
|
private fun updateSelection(selection: List<Music>) {
|
||||||
|
@ -162,7 +161,7 @@ class SongListFragment :
|
||||||
*/
|
*/
|
||||||
private class SongAdapter(private val listener: SelectableListListener<Song>) :
|
private class SongAdapter(private val listener: SelectableListListener<Song>) :
|
||||||
SelectionIndicatorAdapter<Song, BasicListInstructions, SongViewHolder>(
|
SelectionIndicatorAdapter<Song, BasicListInstructions, SongViewHolder>(
|
||||||
ListDiffer.Async(SongViewHolder.DIFF_CALLBACK)) {
|
ListDiffer.Blocking(SongViewHolder.DIFF_CALLBACK)) {
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) =
|
||||||
SongViewHolder.from(parent)
|
SongViewHolder.from(parent)
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023 Auxio Project
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.oxycblt.auxio.list.adapter
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
|
||||||
import java.lang.reflect.Field
|
|
||||||
import org.oxycblt.auxio.util.lazyReflectedField
|
|
||||||
import org.oxycblt.auxio.util.requireIs
|
|
||||||
|
|
||||||
val ASD_MAX_GENERATION_FIELD: Field by
|
|
||||||
lazyReflectedField(AsyncListDiffer::class, "mMaxScheduledGeneration")
|
|
||||||
val ASD_MUTABLE_LIST_FIELD: Field by lazyReflectedField(AsyncListDiffer::class, "mList")
|
|
||||||
val ASD_READ_ONLY_LIST_FIELD: Field by lazyReflectedField(AsyncListDiffer::class, "mReadOnlyList")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Force-update an [AsyncListDiffer] with new data. It's hard to state how incredibly dangerous this
|
|
||||||
* is, so only use it when absolutely necessary.
|
|
||||||
* @param newList The new list to write to the [AsyncListDiffer].
|
|
||||||
*/
|
|
||||||
fun <T> AsyncListDiffer<T>.overwriteList(newList: List<T>) {
|
|
||||||
// Should update the generation field to prevent any previous jobs from conflicting, then
|
|
||||||
// updates the mutable list to it's nullable value, and then updates the read-only list to
|
|
||||||
// it's non-nullable value.
|
|
||||||
ASD_MAX_GENERATION_FIELD.set(this, requireIs<Int>(ASD_MAX_GENERATION_FIELD.get(this)) + 1)
|
|
||||||
ASD_MUTABLE_LIST_FIELD.set(this, newList.ifEmpty { null })
|
|
||||||
ASD_READ_ONLY_LIST_FIELD.set(this, newList)
|
|
||||||
}
|
|
|
@ -112,7 +112,7 @@ private abstract class BasicListDiffer<T> : ListDiffer<T, BasicListInstructions>
|
||||||
}
|
}
|
||||||
|
|
||||||
private class RealAsyncListDiffer<T>(
|
private class RealAsyncListDiffer<T>(
|
||||||
private val updateCallback: ListUpdateCallback,
|
updateCallback: ListUpdateCallback,
|
||||||
diffCallback: DiffUtil.ItemCallback<T>
|
diffCallback: DiffUtil.ItemCallback<T>
|
||||||
) : BasicListDiffer<T>() {
|
) : BasicListDiffer<T>() {
|
||||||
private val inner =
|
private val inner =
|
||||||
|
@ -126,13 +126,9 @@ private class RealAsyncListDiffer<T>(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun replaceList(newList: List<T>, onDone: () -> Unit) {
|
override fun replaceList(newList: List<T>, onDone: () -> Unit) {
|
||||||
if (inner.currentList != newList) {
|
inner.submitList(null) {
|
||||||
val oldListSize = inner.currentList.size
|
inner.submitList(newList, onDone)
|
||||||
updateCallback.onRemoved(0, oldListSize)
|
|
||||||
inner.overwriteList(newList)
|
|
||||||
updateCallback.onInserted(0, newList.size)
|
|
||||||
}
|
}
|
||||||
onDone()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue