mirror of
https://github.com/imcarlost/Friendlists.git
synced 2026-04-10 02:46:54 -04:00
implement recycler view for userlist
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
|
||||
fun Context.toast(message: String) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import androidx.recyclerview.widget.DiffUtil
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
fun <T> RecyclerView.Adapter<*>.autoNotify(oldList: List<T>, newList: List<T>, compare: (T, T) -> Boolean) {
|
||||
val diff = DiffUtil.calculateDiff(object : DiffUtil.Callback() {
|
||||
|
||||
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return compare(oldList[oldItemPosition], newList[newItemPosition])
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
|
||||
return oldList[oldItemPosition] == newList[newItemPosition]
|
||||
}
|
||||
|
||||
override fun getOldListSize() = oldList.size
|
||||
|
||||
override fun getNewListSize() = newList.size
|
||||
})
|
||||
|
||||
diff.dispatchUpdatesTo(this)
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.hako.base.extensions
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
|
||||
fun ViewGroup.inflate(@LayoutRes layout: Int, attachToRoot: Boolean = false) =
|
||||
fun ViewGroup.inflate(@LayoutRes layout: Int, attachToRoot: Boolean = false): View =
|
||||
LayoutInflater
|
||||
.from(context)
|
||||
.inflate(layout, this, attachToRoot)
|
||||
|
||||
Reference in New Issue
Block a user