From a8d6b38ba08c0642039df990f96680999d9e8265 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 5 Jun 2021 21:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E5=88=86=E7=BB=84=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/bookshelf/style2/BaseBooksAdapter.kt | 22 ++++++++++--------- .../main/bookshelf/style2/BooksAdapterGrid.kt | 4 ++-- .../main/bookshelf/style2/BooksAdapterList.kt | 4 ++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt index 1ad12187f..15132959a 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BaseBooksAdapter.kt @@ -6,8 +6,10 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.data.entities.Book -abstract class BaseBooksAdapter(val context: Context) : - RecyclerView.Adapter() { +abstract class BaseBooksAdapter( + val context: Context, + val callBack: CallBack +) : RecyclerView.Adapter() { val diffItemCallback: DiffUtil.ItemCallback get() = object : DiffUtil.ItemCallback() { @@ -62,14 +64,14 @@ abstract class BaseBooksAdapter(val context: Conte } fun notification(bookUrl: String) { -// for (i in 0 until itemCount) { -// getItem(i)?.let { -// if (it.bookUrl == bookUrl) { -// notifyItemChanged(i, bundleOf(Pair("refresh", null))) -// return -// } -// } -// } + for (i in 0 until itemCount) { + callBack.getItem(i).let { + if (it is Book && it.bookUrl == bookUrl) { + notifyItemChanged(i, bundleOf(Pair("refresh", null))) + return + } + } + } } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt index 5e89d351b..eaa8e8a9d 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt @@ -13,8 +13,8 @@ import io.legado.app.help.AppConfig import io.legado.app.utils.invisible import splitties.views.onLongClick -class BooksAdapterGrid(context: Context, private val callBack: CallBack) : - BaseBooksAdapter(context) { +class BooksAdapterGrid(context: Context, callBack: CallBack) : + BaseBooksAdapter(context, callBack) { override fun getItemCount(): Int { return callBack.getItemCount() diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt index 3130076dd..755772eaa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt @@ -15,8 +15,8 @@ import io.legado.app.utils.invisible import io.legado.app.utils.visible import splitties.views.onLongClick -class BooksAdapterList(context: Context, private val callBack: CallBack) : - BaseBooksAdapter(context) { +class BooksAdapterList(context: Context, callBack: CallBack) : + BaseBooksAdapter(context, callBack) { override fun getItemCount(): Int { return callBack.getItemCount()