diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt index cdfa03d7b..59fc6952b 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt @@ -196,20 +196,20 @@ class AnalyzeByJSoup { private fun filterElements(elements: Elements, rules: Array?): Elements { if (rules == null || rules.size < 2) return elements - val selectedEls = Elements() - for (ele in elements) { + val result = Elements() + for (element in elements) { var isOk = false when (rules[0]) { - "class" -> isOk = ele.getElementsByClass(rules[1]).size > 0 - "id" -> isOk = ele.getElementById(rules[1]) != null - "tag" -> isOk = ele.getElementsByTag(rules[1]).size > 0 - "text" -> isOk = ele.getElementsContainingOwnText(rules[1]).size > 0 + "class" -> isOk = element.getElementsByClass(rules[1]).size > 0 + "id" -> isOk = element.getElementById(rules[1]) != null + "tag" -> isOk = element.getElementsByTag(rules[1]).size > 0 + "text" -> isOk = element.getElementsContainingOwnText(rules[1]).size > 0 } if (isOk) { - selectedEls.add(ele) + result.add(element) } } - return selectedEls + return result } /** diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt new file mode 100644 index 000000000..335ff8520 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt @@ -0,0 +1,42 @@ +package io.legado.app.ui.book.read.config + +import android.content.Context +import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter +import io.legado.app.constant.EventBus +import io.legado.app.help.ImageLoader +import io.legado.app.help.ReadBookConfig +import io.legado.app.utils.postEvent +import kotlinx.android.synthetic.main.item_bg_image.view.* +import org.jetbrains.anko.sdk27.listeners.onClick +import java.io.File + +class BgAdapter(context: Context, val textColor: Int) : + SimpleRecyclerAdapter(context, R.layout.item_bg_image) { + + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + with(holder.itemView) { + ImageLoader.load( + context, + context.assets.open("bg${File.separator}$item").readBytes() + ) + .centerCrop() + .into(iv_bg) + tv_name.setTextColor(textColor) + tv_name.text = item.substringBeforeLast(".") + } + } + + override fun registerListener(holder: ItemViewHolder) { + holder.itemView.apply { + this.onClick { + getItemByLayoutPosition(holder.layoutPosition)?.let { + ReadBookConfig.durConfig.setCurBg(1, it) + ReadBookConfig.upBg() + postEvent(EventBus.UP_CONFIG, false) + } + } + } + } +} \ No newline at end of file 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 a41bf4003..bd7f3d32d 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 @@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.config import android.annotation.SuppressLint import android.app.Activity.RESULT_OK -import android.content.Context import android.content.DialogInterface import android.content.Intent import android.graphics.Color @@ -14,10 +13,7 @@ import androidx.documentfile.provider.DocumentFile import com.jaredrummler.android.colorpicker.ColorPickerDialog import io.legado.app.R import io.legado.app.base.BaseDialogFragment -import io.legado.app.base.adapter.ItemViewHolder -import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.constant.EventBus -import io.legado.app.help.ImageLoader import io.legado.app.help.ReadBookConfig import io.legado.app.help.http.HttpHelper import io.legado.app.help.permission.Permissions @@ -53,8 +49,8 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { private val requestCodeImport = 132 private val configFileName = "readConfig.zip" private lateinit var adapter: BgAdapter - var primaryTextColor = 0 - var secondaryTextColor = 0 + private var primaryTextColor = 0 + private var secondaryTextColor = 0 override fun onStart() { super.onStart() @@ -109,7 +105,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { @SuppressLint("InflateParams") private fun initData() = with(ReadBookConfig.durConfig) { sw_dark_status_icon.isChecked = curStatusIconDark() - adapter = BgAdapter(requireContext()) + adapter = BgAdapter(requireContext(), secondaryTextColor) recycler_view.adapter = adapter val headerView = LayoutInflater.from(requireContext()) .inflate(R.layout.item_bg_image, recycler_view, false) @@ -189,35 +185,6 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { startActivityForResult(intent, requestCodeBg) } - inner class BgAdapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_bg_image) { - - override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { - with(holder.itemView) { - ImageLoader.load( - context, - context.assets.open("bg${File.separator}$item").readBytes() - ) - .centerCrop() - .into(iv_bg) - tv_name.setTextColor(secondaryTextColor) - tv_name.text = item.substringBeforeLast(".") - } - } - - override fun registerListener(holder: ItemViewHolder) { - holder.itemView.apply { - this.onClick { - getItemByLayoutPosition(holder.layoutPosition)?.let { - ReadBookConfig.durConfig.setCurBg(1, it) - ReadBookConfig.upBg() - postEvent(EventBus.UP_CONFIG, false) - } - } - } - } - } - @Suppress("BlockingMethodInNonBlockingContext") private fun exportConfig(uri: Uri) { execute {