From c1318a66d7847796c801359b2f9d616380888be6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 22 Feb 2020 21:51:06 +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/CommonRecyclerAdapter.kt | 5 +++++ .../io/legado/app/ui/book/read/config/BgTextConfigDialog.kt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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 25e6b25c4..f864aa4e8 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 @@ -293,6 +293,11 @@ abstract class CommonRecyclerAdapter(protected val context: Context) : fun getItem(position: Int): ITEM? = if (position in 0 until items.size) items[position] else null + fun getItemByLayoutPosition(position: Int): ITEM? { + val pos = position - getHeaderCount() + return if (pos in 0 until items.size) items[pos] else null + } + fun getItems(): List = items protected open fun getItemViewType(item: ITEM, position: Int): Int { diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 01ad8c895..5a3d3ec8b 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -155,7 +155,7 @@ class BgTextConfigDialog : DialogFragment() { override fun registerListener(holder: ItemViewHolder) { holder.itemView.apply { this.onClick { - getItem(holder.layoutPosition - getHeaderCount())?.let { + getItemByLayoutPosition(holder.layoutPosition)?.let { ReadBookConfig.durConfig.setBg(1, it) ReadBookConfig.upBg() postEvent(EventBus.UP_CONFIG, false)