From 76cecb4c1aeda44a6b22d2c16a9a8d04bee3f9a8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 15 Feb 2020 12:18:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/base/adapter/ItemViewDelegate.kt | 4 ++++ .../io/legado/app/base/adapter/SimpleRecyclerAdapter.kt | 4 ++++ .../legado/app/ui/changesource/ChangeSourceViewModel.kt | 8 +++----- 3 files changed, 11 insertions(+), 5 deletions(-) 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 2ac1090f2..d5e92e236 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 @@ -9,6 +9,10 @@ import android.content.Context */ abstract class ItemViewDelegate(protected val context: Context, val layoutId: Int) { + /** + * 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题, + * 使用getItem(holder.layoutPosition)来获取item + */ 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/base/adapter/SimpleRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/SimpleRecyclerAdapter.kt index c65cfabf4..baf40e487 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 @@ -18,5 +18,9 @@ abstract class SimpleRecyclerAdapter(context: Context, private val layoutI }) } + /** + * 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题, + * 使用getItem(holder.layoutPosition)来获取item + */ 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/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 8633021f2..13b145a1e 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -27,7 +27,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio var author: String = "" private var task: Coroutine<*>? = null private var screenKey: String = "" - private val searchBooks = linkedSetOf() + private val searchBooks = hashSetOf() fun initData(arguments: Bundle?) { arguments?.let { bundle -> @@ -50,10 +50,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } private fun upAdapter() { - execute { - val books = searchBooks.toList() - searchBooksLiveData.postValue(books.sortedBy { it.originOrder }) - } + val books = searchBooks.toList() + searchBooksLiveData.postValue(books.sortedBy { it.originOrder }) } private fun searchFinish(searchBook: SearchBook) {