mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-16 09:20:37 +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.
|
||||
*/
|
||||
@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
|
||||
internal var selectionType: SelectionType = SelectionType.MULTIPLE
|
||||
@ -41,7 +42,7 @@ class BaseAdapter<T : Identifiable> : MultiTypeAdapter(), FastScrollRecyclerView
|
||||
private val diffCallback = GenericDiffCallback<T>()
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
setHasStableIds(!allowDuplicateEntries)
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
|
@ -43,14 +43,7 @@ class TrackViewBinder(
|
||||
override fun onBindViewHolder(holder: TrackViewHolder, item: Identifiable) {
|
||||
val diffAdapter = adapter as BaseAdapter<*>
|
||||
|
||||
val track: Track = when (item) {
|
||||
is Track -> {
|
||||
item
|
||||
}
|
||||
else -> {
|
||||
return
|
||||
}
|
||||
}
|
||||
val track = (item as? Track) ?: return
|
||||
|
||||
// Remove observer before binding
|
||||
holder.observableChecked.removeObservers(lifecycleOwner)
|
||||
@ -59,7 +52,7 @@ class TrackViewBinder(
|
||||
song = track,
|
||||
checkable = checkable,
|
||||
draggable = draggable,
|
||||
diffAdapter.isSelected(item.longId)
|
||||
diffAdapter.isSelected(track.longId)
|
||||
)
|
||||
|
||||
holder.itemView.setOnLongClickListener {
|
||||
@ -110,7 +103,7 @@ class TrackViewBinder(
|
||||
diffAdapter.selectionRevision.observe(
|
||||
lifecycleOwner
|
||||
) {
|
||||
val newStatus = diffAdapter.isSelected(item.longId)
|
||||
val newStatus = diffAdapter.isSelected(track.longId)
|
||||
|
||||
if (newStatus != holder.check.isChecked) holder.check.isChecked = newStatus
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ class PlayerFragment :
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private val viewAdapter: BaseAdapter<Identifiable> by lazy {
|
||||
BaseAdapter()
|
||||
BaseAdapter(allowDuplicateEntries = true)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user