BaseFragment

pull/32/head
Invinciblelee 6 years ago
parent 9eedabc48d
commit 7e05769497
  1. 2
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 4
      app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt
  3. 10
      app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt
  4. 9
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt

@ -295,7 +295,7 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) : Rec
} }
else -> { else -> {
val holder = ItemViewHolder(inflater.inflate(itemDelegates.getValue(viewType).layoutID, parent, false)) val holder = ItemViewHolder(inflater.inflate(itemDelegates.getValue(viewType).layoutId, parent, false))
if (itemClickListener != null) { if (itemClickListener != null) {
holder.itemView.setOnClickListener { holder.itemView.setOnClickListener {

@ -7,9 +7,7 @@ import android.content.Context
* *
* item代理 * item代理
*/ */
abstract class ItemViewDelegate<in ITEM>(protected val context: Context) { abstract class ItemViewDelegate<in ITEM>(protected val context: Context, val layoutId: Int) {
abstract val layoutID: Int
abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>) abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>)

@ -5,22 +5,18 @@ import android.content.Context
/** /**
* Created by Invincible on 2017/12/15. * Created by Invincible on 2017/12/15.
*/ */
abstract class SimpleRecyclerAdapter<ITEM>(context: Context) : CommonRecyclerAdapter<ITEM>(context) { abstract class SimpleRecyclerAdapter<ITEM>(context: Context, private val layoutId: Int) :
CommonRecyclerAdapter<ITEM>(context) {
init { init {
addItemViewDelegate(object : ItemViewDelegate<ITEM>(context) { addItemViewDelegate(object : ItemViewDelegate<ITEM>(context, layoutId) {
override val layoutID: Int
get() = this@SimpleRecyclerAdapter.layoutID
override fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>) {
this@SimpleRecyclerAdapter.convert(holder, item, payloads) this@SimpleRecyclerAdapter.convert(holder, item, payloads)
} }
}) })
} }
abstract val layoutID: Int
abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>) abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList<Any>)
} }

@ -8,22 +8,17 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import kotlinx.android.synthetic.main.item_search.view.* import kotlinx.android.synthetic.main.item_search.view.*
class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context) { class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) {
init { init {
addItemViewDelegate(TestItemDelegate(context)) addItemViewDelegate(TestItemDelegate(context))
} }
override val layoutID: Int
get() = R.layout.item_search
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
holder.itemView.bookName.text = "我欲封天" holder.itemView.bookName.text = "我欲封天"
} }
internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context){ internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context, R.layout.item_search) {
override val layoutID: Int
get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.

Loading…
Cancel
Save