pull/32/head
kunfei 5 years ago
parent 65b1001d1b
commit 55b8ecf73a
  1. 33
      app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt
  2. 47
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt

@ -1,5 +1,8 @@
package io.legado.app.data.entities.rule package io.legado.app.data.entities.rule
import io.legado.app.constant.AppConst
import javax.script.SimpleBindings
data class ExploreRule( data class ExploreRule(
var exploreUrl: String? = null, var exploreUrl: String? = null,
override var bookList: String? = null, override var bookList: String? = null,
@ -14,8 +17,36 @@ data class ExploreRule(
override var wordCount: String? = null override var wordCount: String? = null
) : BookListRule { ) : BookListRule {
fun getExploreKinds(baseUrl: String): ArrayList<ExploreKind>? {
exploreUrl?.let {
var a = it
if (a.isNotBlank()) {
try {
if (it.startsWith("<js>", false)) {
val bindings = SimpleBindings()
bindings["baseUrl"] = baseUrl
a = AppConst.SCRIPT_ENGINE.eval(
a.substring(4, a.lastIndexOf("<")),
bindings
).toString()
}
val exploreKinds = arrayListOf<ExploreKind>()
val b = a.split("(&&|\n)+".toRegex())
b.map { c ->
val d = c.split("::")
exploreKinds.add(ExploreKind(d[0], d[1]))
}
return exploreKinds
} catch (e: Exception) {
e.printStackTrace()
}
}
}
return null
}
data class ExploreUrl( data class ExploreKind(
var title: String, var title: String,
var url: String var url: String
) )

@ -4,6 +4,7 @@ import android.graphics.drawable.GradientDrawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.paging.PagedListAdapter import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -13,6 +14,7 @@ import io.legado.app.lib.theme.ColorUtils
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.android.synthetic.main.item_find_book.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) { class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -33,26 +35,33 @@ class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_find_book, parent, false)) return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_find_book, parent, false))
} }
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { override fun onBindViewHolder(holder: MyViewHolder, position: Int): Unit =
currentList?.get(position)?.let { with(holder.itemView) {
holder.bind(it, position == exIndex) currentList?.get(position)?.let { bookSource ->
} val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable
} bgShape?.setStroke(2, ColorUtils.getRandomColor())
tv_name.text = bookSource.bookSourceName
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { ll_title.onClick {
val oldEx = exIndex
fun bind(bookSource: BookSource, ex: Boolean) = with(itemView) { exIndex = position
val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable notifyItemChanged(oldEx)
bgShape?.setStroke(2, ColorUtils.getRandomColor()) notifyItemChanged(position)
tv_name.text = bookSource.bookSourceName }
if (ex) { if (exIndex == position) {
gl_child.invisible() gl_child.invisible()
bookSource.getExploreRule().exploreUrl?.let { bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let {
it.map { kind ->
val tv = TextView(context)
tv.text = kind.title
tv.onClick { }
gl_child.addView(tv)
}
}
} else {
gl_child.gone()
} }
} else {
gl_child.gone()
}
} }
} }
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view)
} }
Loading…
Cancel
Save