mirror of
https://github.com/melihaksoy/Android-Kotlin-Modulerized-CleanArchitecture.git
synced 2026-01-16 22:16:55 +01:00
List lefover fixes
This commit is contained in:
@@ -9,16 +9,12 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
/**
|
||||
* Base adapter to reduce boilerplate on creating / binding view holders.
|
||||
*
|
||||
*
|
||||
*/
|
||||
abstract class BasePagingListAdapter<T>(
|
||||
callback: DiffUtil.ItemCallback<T>,
|
||||
private val clickListener: (T?) -> Unit
|
||||
private val clickListener: (T) -> Unit
|
||||
) : PagedListAdapter<T, BaseViewHolder<T>>(callback) {
|
||||
|
||||
private var itemClickListener: ((T) -> Unit)? = null
|
||||
|
||||
/**
|
||||
* This method will be called to create view holder to obfuscate layout inflation creation / process
|
||||
*
|
||||
@@ -46,14 +42,14 @@ abstract class BasePagingListAdapter<T>(
|
||||
* Calls [bind][BaseViewHolder.bind] on view holders
|
||||
*/
|
||||
override fun onBindViewHolder(holder: BaseViewHolder<T>, position: Int) {
|
||||
val item = getItem(position)
|
||||
getItem(position)?.also { item ->
|
||||
|
||||
holder.itemView.setOnClickListener { view ->
|
||||
clickListener(item)
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
clickListener(item)
|
||||
holder.bind(item)
|
||||
}
|
||||
|
||||
holder.bind(item)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,5 +64,5 @@ abstract class BaseViewHolder<T>(binding: ViewDataBinding) : RecyclerView.ViewHo
|
||||
* @param item entity
|
||||
* @param position position from adapter
|
||||
*/
|
||||
abstract fun bind(item: T?)
|
||||
abstract fun bind(item: T)
|
||||
}
|
||||
|
||||
@@ -70,8 +70,8 @@ class LaunchesFragment : BaseDaggerFragment<ListBinding>(), SwipeRefreshLayout.O
|
||||
//}
|
||||
}
|
||||
|
||||
private fun onItemSelected(item: LaunchEntity?) {
|
||||
startActivity(Actions.openDetailFor(item?.id ?: -1L))
|
||||
private fun onItemSelected(item: LaunchEntity) {
|
||||
startActivity(Actions.openDetailFor(item.id))
|
||||
}
|
||||
|
||||
//private fun onSearchExpand() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.melih.core.base.recycler.BaseViewHolder
|
||||
import com.melih.list.databinding.LaunchRowBinding
|
||||
import com.melih.repository.entities.LaunchEntity
|
||||
|
||||
class LaunchesAdapter(itemClickListener: (LaunchEntity?) -> Unit) : BasePagingListAdapter<LaunchEntity>(
|
||||
class LaunchesAdapter(itemClickListener: (LaunchEntity) -> Unit) : BasePagingListAdapter<LaunchEntity>(
|
||||
object : DiffUtil.ItemCallback<LaunchEntity>() {
|
||||
override fun areItemsTheSame(oldItem: LaunchEntity, newItem: LaunchEntity): Boolean =
|
||||
oldItem.id == newItem.id
|
||||
@@ -30,10 +30,10 @@ class LaunchesAdapter(itemClickListener: (LaunchEntity?) -> Unit) : BasePagingLi
|
||||
|
||||
class LaunchesViewHolder(private val binding: LaunchRowBinding) : BaseViewHolder<LaunchEntity>(binding) {
|
||||
|
||||
override fun bind(item: LaunchEntity?) {
|
||||
override fun bind(item: LaunchEntity) {
|
||||
binding.entity = item
|
||||
|
||||
val missions = item?.missions
|
||||
val missions = item.missions
|
||||
binding.tvDescription.text = if (!missions.isNullOrEmpty()) missions[0].description else ""
|
||||
|
||||
binding.executePendingBindings()
|
||||
|
||||
Reference in New Issue
Block a user