From 7e05769497e5097b521f0164cdc8a9ad0b1046bc Mon Sep 17 00:00:00 2001 From: Invinciblelee <1760316362@qq.com> Date: Wed, 5 Jun 2019 17:15:42 +0800 Subject: [PATCH] BaseFragment --- .../legado/app/base/adapter/CommonRecyclerAdapter.kt | 2 +- .../io/legado/app/base/adapter/ItemViewDelegate.kt | 4 +--- .../legado/app/base/adapter/SimpleRecyclerAdapter.kt | 10 +++------- .../main/java/io/legado/app/ui/search/SearchAdapter.kt | 9 ++------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt index ce7b3d4a6..bd0cea427 100644 --- a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt @@ -295,7 +295,7 @@ abstract class CommonRecyclerAdapter(protected val context: Context) : Rec } 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) { holder.itemView.setOnClickListener { diff --git a/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt b/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt index 789ca250e..e3ec89060 100644 --- a/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt +++ b/app/src/main/java/io/legado/app/base/adapter/ItemViewDelegate.kt @@ -7,9 +7,7 @@ import android.content.Context * * item代理, */ -abstract class ItemViewDelegate(protected val context: Context) { - - abstract val layoutID: Int +abstract class ItemViewDelegate(protected val context: Context, val layoutId: Int) { abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) diff --git a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt index 176098f50..c65cfabf4 100644 --- a/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt @@ -5,22 +5,18 @@ import android.content.Context /** * Created by Invincible on 2017/12/15. */ -abstract class SimpleRecyclerAdapter(context: Context) : CommonRecyclerAdapter(context) { +abstract class SimpleRecyclerAdapter(context: Context, private val layoutId: Int) : + CommonRecyclerAdapter(context) { init { - addItemViewDelegate(object : ItemViewDelegate(context) { - override val layoutID: Int - get() = this@SimpleRecyclerAdapter.layoutID + addItemViewDelegate(object : ItemViewDelegate(context, layoutId) { override fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) { this@SimpleRecyclerAdapter.convert(holder, item, payloads) } }) - } - abstract val layoutID: Int - abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt index a23ee7605..d4658b9fb 100644 --- a/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt @@ -8,22 +8,17 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchBook import kotlinx.android.synthetic.main.item_search.view.* -class SearchAdapter(context: Context) : SimpleRecyclerAdapter(context) { +class SearchAdapter(context: Context) : SimpleRecyclerAdapter(context, R.layout.item_search) { init { addItemViewDelegate(TestItemDelegate(context)) } - override val layoutID: Int - get() = R.layout.item_search - override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { holder.itemView.bookName.text = "我欲封天" } - internal class TestItemDelegate(context: Context) : ItemViewDelegate(context){ - override val layoutID: Int - get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates. + internal class TestItemDelegate(context: Context) : ItemViewDelegate(context, R.layout.item_search) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates.