From bb3620ddf343dad98301446eab9109a47e9ceac0 Mon Sep 17 00:00:00 2001 From: Zhanty Date: Fri, 19 Jul 2019 14:42:10 +0800 Subject: [PATCH] update RvAdapter --- .../adapter/recycler/SimpleRecyclerAdapter.kt | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt b/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt index fb3bdbd..6c6d357 100644 --- a/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt +++ b/lib_base/src/main/java/com/android/base/adapter/recycler/SimpleRecyclerAdapter.kt @@ -15,12 +15,12 @@ import com.android.base.kotlin.KtViewHolder */ abstract class SimpleRecyclerAdapter(context: Context, data: List? = null) : RecyclerAdapter(context, data) { - private var mLayoutInflater: LayoutInflater = LayoutInflater.from(mContext) + private var layoutInflater: LayoutInflater = LayoutInflater.from(mContext) final override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KtViewHolder { val layout = provideLayout(parent, viewType) val itemView = if (layout is Int) { - mLayoutInflater.inflate(layout, parent, false) + layoutInflater.inflate(layout, parent, false) } else layout as View return KtViewHolder(itemView).apply { @@ -28,31 +28,15 @@ abstract class SimpleRecyclerAdapter(context: Context, data: List? = null) } } - protected fun onViewHolderCreated(ktViewHolder: KtViewHolder) { - - } + protected open fun onViewHolderCreated(viewHolder: KtViewHolder) = Unit /**provide a layout id or a View*/ abstract fun provideLayout(parent: ViewGroup, viewType: Int): Any - override fun getItemViewType(position: Int): Int { - return TYPE_ITEM - } - override fun onBindViewHolder(viewHolder: KtViewHolder, position: Int) { - if (viewHolder.itemViewType == TYPE_ITEM) { - bind(viewHolder, getItem(position)) - } else { - bindOtherTypes(viewHolder, position) - } + bind(viewHolder, getItem(position)) } protected abstract fun bind(viewHolder: KtViewHolder, item: T) - protected open fun bindOtherTypes(viewHolder: ViewHolder, position: Int) {} - - companion object { - protected const val TYPE_ITEM = 0 - } - } \ No newline at end of file