mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-18 18:17:43 +03:00
Don't assume Stable ids for playlist
This commit is contained in:
parent
c3c241466c
commit
9b9e552b95
@ -26,7 +26,8 @@ import timber.log.Timber
|
|||||||
* It should be kept generic enough that it can be used a Base for all lists in the app.
|
* It should be kept generic enough that it can be used a Base for all lists in the app.
|
||||||
*/
|
*/
|
||||||
@Suppress("unused", "UNUSED_PARAMETER")
|
@Suppress("unused", "UNUSED_PARAMETER")
|
||||||
class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView.SectionedAdapter {
|
class BaseAdapter<T : Identifiable>(allowDuplicateEntries: Boolean = false) :
|
||||||
|
MultiTypeAdapter(), FastScrollRecyclerView.SectionedAdapter {
|
||||||
|
|
||||||
// Update the BoundedTreeSet if selection type is changed
|
// Update the BoundedTreeSet if selection type is changed
|
||||||
internal var selectionType: SelectionType = SelectionType.MULTIPLE
|
internal var selectionType: SelectionType = SelectionType.MULTIPLE
|
||||||
@ -41,7 +42,7 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
|
|||||||
private val diffCallback = GenericDiffCallback<T>()
|
private val diffCallback = GenericDiffCallback<T>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setHasStableIds(true)
|
setHasStableIds(!allowDuplicateEntries)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
|
@ -43,14 +43,7 @@ class TrackViewBinder(
|
|||||||
override fun onBindViewHolder(holder: TrackViewHolder, item: Identifiable) {
|
override fun onBindViewHolder(holder: TrackViewHolder, item: Identifiable) {
|
||||||
val diffAdapter = adapter as BaseAdapter<*>
|
val diffAdapter = adapter as BaseAdapter<*>
|
||||||
|
|
||||||
val track: Track = when (item) {
|
val track = (item as? Track) ?: return
|
||||||
is Track -> {
|
|
||||||
item
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove observer before binding
|
// Remove observer before binding
|
||||||
holder.observableChecked.removeObservers(lifecycleOwner)
|
holder.observableChecked.removeObservers(lifecycleOwner)
|
||||||
@ -59,7 +52,7 @@ class TrackViewBinder(
|
|||||||
song = track,
|
song = track,
|
||||||
checkable = checkable,
|
checkable = checkable,
|
||||||
draggable = draggable,
|
draggable = draggable,
|
||||||
diffAdapter.isSelected(item.longId)
|
diffAdapter.isSelected(track.longId)
|
||||||
)
|
)
|
||||||
|
|
||||||
holder.itemView.setOnLongClickListener {
|
holder.itemView.setOnLongClickListener {
|
||||||
@ -110,7 +103,7 @@ class TrackViewBinder(
|
|||||||
diffAdapter.selectionRevision.observe(
|
diffAdapter.selectionRevision.observe(
|
||||||
lifecycleOwner
|
lifecycleOwner
|
||||||
) {
|
) {
|
||||||
val newStatus = diffAdapter.isSelected(item.longId)
|
val newStatus = diffAdapter.isSelected(track.longId)
|
||||||
|
|
||||||
if (newStatus != holder.check.isChecked) holder.check.isChecked = newStatus
|
if (newStatus != holder.check.isChecked) holder.check.isChecked = newStatus
|
||||||
}
|
}
|
||||||
|
@ -176,7 +176,7 @@ class PlayerFragment :
|
|||||||
private val binding get() = _binding!!
|
private val binding get() = _binding!!
|
||||||
|
|
||||||
private val viewAdapter: BaseAdapter<Identifiable> by lazy {
|
private val viewAdapter: BaseAdapter<Identifiable> by lazy {
|
||||||
BaseAdapter()
|
BaseAdapter(allowDuplicateEntries = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user