feat: 优化代码

pull/112/head
kunfei 5 years ago
parent 18ff21fe1f
commit c1318a66d7
  1. 5
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt

@ -293,6 +293,11 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) :
fun getItem(position: Int): ITEM? = fun getItem(position: Int): ITEM? =
if (position in 0 until items.size) items[position] else null 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<ITEM> = items fun getItems(): List<ITEM> = items
protected open fun getItemViewType(item: ITEM, position: Int): Int { protected open fun getItemViewType(item: ITEM, position: Int): Int {

@ -155,7 +155,7 @@ class BgTextConfigDialog : DialogFragment() {
override fun registerListener(holder: ItemViewHolder) { override fun registerListener(holder: ItemViewHolder) {
holder.itemView.apply { holder.itemView.apply {
this.onClick { this.onClick {
getItem(holder.layoutPosition - getHeaderCount())?.let { getItemByLayoutPosition(holder.layoutPosition)?.let {
ReadBookConfig.durConfig.setBg(1, it) ReadBookConfig.durConfig.setBg(1, it)
ReadBookConfig.upBg() ReadBookConfig.upBg()
postEvent(EventBus.UP_CONFIG, false) postEvent(EventBus.UP_CONFIG, false)

Loading…
Cancel
Save