Commit 2f5ff3e9 authored by Eugene Shapovalov's avatar Eugene Shapovalov 💬

Fixed bug associated with blinking items after update target list.

parent 1606dadd
package ru.terrakok.gitlabclient.ui.global.list
import android.support.v7.util.DiffUtil
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 04.01.18.
*/
class DiffCallback(
private val newData: List<Any>,
private val oldData: List<Any>
) : DiffUtil.Callback() {
override fun getOldListSize() = oldData.size
override fun getNewListSize() = newData.size
//without optimization at the moment
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int) = oldData[oldItemPosition] === newData[newItemPosition]
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int) = oldData[oldItemPosition] == newData[newItemPosition]
}
\ No newline at end of file
......@@ -4,16 +4,16 @@ import android.support.v7.util.DiffUtil
import android.support.v7.widget.RecyclerView
import com.hannesdorfmann.adapterdelegates3.ListDelegationAdapter
import ru.terrakok.gitlabclient.entity.app.target.TargetHeader
import ru.terrakok.gitlabclient.ui.global.list.DiffCallback
import ru.terrakok.gitlabclient.ui.global.list.ProgressAdapterDelegate
import ru.terrakok.gitlabclient.ui.global.list.ProgressItem
import ru.terrakok.gitlabclient.ui.global.list.TargetHeaderAdapterDelegate
class TargetsAdapter(
userClickListener: (Long) -> Unit,
clickListener: (TargetHeader) -> Unit,
private val nextListener: () -> Unit
userClickListener: (Long) -> Unit,
clickListener: (TargetHeader) -> Unit,
private val nextListener: () -> Unit
) : ListDelegationAdapter<MutableList<Any>>() {
init {
items = mutableListOf()
delegatesManager.addDelegate(TargetHeaderAdapterDelegate(userClickListener, clickListener))
......@@ -49,9 +49,45 @@ class TargetsAdapter(
private fun isProgress() = items.isNotEmpty() && items.last() is ProgressItem
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int, payloads: MutableList<Any?>) {
override fun onBindViewHolder(
holder: RecyclerView.ViewHolder,
position: Int,
payloads: MutableList<Any?>
) {
super.onBindViewHolder(holder, position, payloads)
if (position == items.size - 10) nextListener()
}
private inner class DiffCallback(
private val newItems: List<Any>,
private val oldItems: List<Any>
) : DiffUtil.Callback() {
override fun getOldListSize() = oldItems.size
override fun getNewListSize() = newItems.size
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return if (newItem is TargetHeader && oldItem is TargetHeader) {
newItem.target == oldItem.target && newItem.targetId == oldItem.targetId
&& newItem.date == oldItem.date
} else {
newItem is ProgressItem && oldItem is ProgressItem
}
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
return if (newItem is TargetHeader && oldItem is TargetHeader) {
newItem == oldItem
} else {
true
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment