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)