pull/433/head
gedoor 4 years ago
parent 57f3220fb6
commit 3cfbd0d071
  1. 16
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeByJSoup.kt
  2. 42
      app/src/main/java/io/legado/app/ui/book/read/config/BgAdapter.kt
  3. 39
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt

@ -196,20 +196,20 @@ class AnalyzeByJSoup {
private fun filterElements(elements: Elements, rules: Array<String>?): Elements { private fun filterElements(elements: Elements, rules: Array<String>?): Elements {
if (rules == null || rules.size < 2) return elements if (rules == null || rules.size < 2) return elements
val selectedEls = Elements() val result = Elements()
for (ele in elements) { for (element in elements) {
var isOk = false var isOk = false
when (rules[0]) { when (rules[0]) {
"class" -> isOk = ele.getElementsByClass(rules[1]).size > 0 "class" -> isOk = element.getElementsByClass(rules[1]).size > 0
"id" -> isOk = ele.getElementById(rules[1]) != null "id" -> isOk = element.getElementById(rules[1]) != null
"tag" -> isOk = ele.getElementsByTag(rules[1]).size > 0 "tag" -> isOk = element.getElementsByTag(rules[1]).size > 0
"text" -> isOk = ele.getElementsContainingOwnText(rules[1]).size > 0 "text" -> isOk = element.getElementsContainingOwnText(rules[1]).size > 0
} }
if (isOk) { if (isOk) {
selectedEls.add(ele) result.add(element)
} }
} }
return selectedEls return result
} }
/** /**

@ -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<String>(context, R.layout.item_bg_image) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
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)
}
}
}
}
}

@ -2,7 +2,6 @@ package io.legado.app.ui.book.read.config
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Activity.RESULT_OK import android.app.Activity.RESULT_OK
import android.content.Context
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.graphics.Color import android.graphics.Color
@ -14,10 +13,7 @@ import androidx.documentfile.provider.DocumentFile
import com.jaredrummler.android.colorpicker.ColorPickerDialog import com.jaredrummler.android.colorpicker.ColorPickerDialog
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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.constant.EventBus
import io.legado.app.help.ImageLoader
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.Permissions
@ -53,8 +49,8 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
private val requestCodeImport = 132 private val requestCodeImport = 132
private val configFileName = "readConfig.zip" private val configFileName = "readConfig.zip"
private lateinit var adapter: BgAdapter private lateinit var adapter: BgAdapter
var primaryTextColor = 0 private var primaryTextColor = 0
var secondaryTextColor = 0 private var secondaryTextColor = 0
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
@ -109,7 +105,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
private fun initData() = with(ReadBookConfig.durConfig) { private fun initData() = with(ReadBookConfig.durConfig) {
sw_dark_status_icon.isChecked = curStatusIconDark() sw_dark_status_icon.isChecked = curStatusIconDark()
adapter = BgAdapter(requireContext()) adapter = BgAdapter(requireContext(), secondaryTextColor)
recycler_view.adapter = adapter recycler_view.adapter = adapter
val headerView = LayoutInflater.from(requireContext()) val headerView = LayoutInflater.from(requireContext())
.inflate(R.layout.item_bg_image, recycler_view, false) .inflate(R.layout.item_bg_image, recycler_view, false)
@ -189,35 +185,6 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack {
startActivityForResult(intent, requestCodeBg) startActivityForResult(intent, requestCodeBg)
} }
inner class BgAdapter(context: Context) :
SimpleRecyclerAdapter<String>(context, R.layout.item_bg_image) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
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") @Suppress("BlockingMethodInNonBlockingContext")
private fun exportConfig(uri: Uri) { private fun exportConfig(uri: Uri) {
execute { execute {

Loading…
Cancel
Save