diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt index 2e4e61a4a..921210083 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt @@ -1,5 +1,8 @@ package io.legado.app.data.entities.rule +import io.legado.app.constant.AppConst +import javax.script.SimpleBindings + data class ExploreRule( var exploreUrl: String? = null, override var bookList: String? = null, @@ -14,8 +17,36 @@ data class ExploreRule( override var wordCount: String? = null ) : BookListRule { + fun getExploreKinds(baseUrl: String): ArrayList? { + exploreUrl?.let { + var a = it + if (a.isNotBlank()) { + try { + if (it.startsWith("", false)) { + + val bindings = SimpleBindings() + bindings["baseUrl"] = baseUrl + a = AppConst.SCRIPT_ENGINE.eval( + a.substring(4, a.lastIndexOf("<")), + bindings + ).toString() + } + val exploreKinds = arrayListOf() + 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 url: String ) diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt index af0ae836f..ff89cf48a 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt @@ -4,6 +4,7 @@ import android.graphics.drawable.GradientDrawable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.TextView import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil 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.invisible import kotlinx.android.synthetic.main.item_find_book.view.* +import org.jetbrains.anko.sdk27.listeners.onClick class FindBookAdapter:PagedListAdapter(DIFF_CALLBACK) { @@ -33,26 +35,33 @@ class FindBookAdapter:PagedListAdapter return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_find_book, parent, false)) } - override fun onBindViewHolder(holder: MyViewHolder, position: Int) { - currentList?.get(position)?.let { - holder.bind(it, position == exIndex) - } - } - - class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { - - fun bind(bookSource: BookSource, ex: Boolean) = with(itemView) { - val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable - bgShape?.setStroke(2, ColorUtils.getRandomColor()) - tv_name.text = bookSource.bookSourceName - if (ex) { - gl_child.invisible() - bookSource.getExploreRule().exploreUrl?.let { - + override fun onBindViewHolder(holder: MyViewHolder, position: Int): Unit = + with(holder.itemView) { + currentList?.get(position)?.let { bookSource -> + val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable + bgShape?.setStroke(2, ColorUtils.getRandomColor()) + tv_name.text = bookSource.bookSourceName + ll_title.onClick { + val oldEx = exIndex + exIndex = position + notifyItemChanged(oldEx) + notifyItemChanged(position) + } + if (exIndex == position) { + gl_child.invisible() + 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) } \ No newline at end of file