parent
a5d179441f
commit
8f72fb1b4a
@ -0,0 +1,32 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view |
||||||
|
|
||||||
|
import androidx.annotation.Nullable |
||||||
|
import androidx.recyclerview.widget.DiffUtil |
||||||
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
||||||
|
import timber.log.Timber |
||||||
|
|
||||||
|
class RowRepresentableDiffCallback(var newRows: List<RowRepresentable>, var oldRows: List<RowRepresentable>) : |
||||||
|
DiffUtil.Callback() { |
||||||
|
|
||||||
|
override fun getOldListSize(): Int { |
||||||
|
return oldRows.size |
||||||
|
} |
||||||
|
|
||||||
|
override fun getNewListSize(): Int { |
||||||
|
return newRows.size |
||||||
|
} |
||||||
|
|
||||||
|
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { |
||||||
|
return oldRows[oldItemPosition] === newRows[newItemPosition] |
||||||
|
} |
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { |
||||||
|
return oldRows[oldItemPosition] == newRows[newItemPosition] |
||||||
|
} |
||||||
|
|
||||||
|
@Nullable |
||||||
|
override fun getChangePayload(oldItemPosition: Int, newItemPosition: Int): Any? { |
||||||
|
//you can return particular field for changed item. |
||||||
|
return super.getChangePayload(oldItemPosition, newItemPosition) |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,46 @@ |
|||||||
|
package net.pokeranalytics.android.ui.view |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.graphics.PointF |
||||||
|
import android.util.DisplayMetrics |
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager |
||||||
|
import androidx.recyclerview.widget.LinearSmoothScroller |
||||||
|
import androidx.recyclerview.widget.RecyclerView |
||||||
|
|
||||||
|
/** |
||||||
|
* SmoothScrollLinearLayoutManager |
||||||
|
*/ |
||||||
|
class SmoothScrollLinearLayoutManager(context: Context) : |
||||||
|
LinearLayoutManager(context, RecyclerView.VERTICAL, false) { |
||||||
|
|
||||||
|
companion object { |
||||||
|
private const val MILLISECONDS_PER_INCH = 100f |
||||||
|
} |
||||||
|
|
||||||
|
override fun smoothScrollToPosition( |
||||||
|
recyclerView: RecyclerView, state: RecyclerView.State?, |
||||||
|
position: Int |
||||||
|
) { |
||||||
|
val smoothScroller = TopSnappedSmoothScroller(recyclerView.context) |
||||||
|
smoothScroller.targetPosition = position |
||||||
|
startSmoothScroll(smoothScroller) |
||||||
|
} |
||||||
|
|
||||||
|
private inner class TopSnappedSmoothScroller(context: Context) : LinearSmoothScroller(context) { |
||||||
|
|
||||||
|
override fun computeScrollVectorForPosition(targetPosition: Int): PointF? { |
||||||
|
return this@SmoothScrollLinearLayoutManager |
||||||
|
.computeScrollVectorForPosition(targetPosition) |
||||||
|
} |
||||||
|
|
||||||
|
override fun getVerticalSnapPreference(): Int { |
||||||
|
return SNAP_TO_START |
||||||
|
} |
||||||
|
|
||||||
|
override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics): Float { |
||||||
|
return MILLISECONDS_PER_INCH / displayMetrics.densityDpi |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue