implement recycler view for userlist

This commit is contained in:
Carlos Martinez
2020-02-02 22:35:44 -03:00
parent 451d14ad95
commit 7d4432278e
8 changed files with 176 additions and 36 deletions

View File

@@ -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()
}

View File

@@ -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)
}

View File

@@ -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)