pull/1111/head
gedoor 3 years ago
parent 9180a4c40d
commit c49e6bae53
  1. 2
      app/build.gradle
  2. 16
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 21
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  4. 3
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt
  5. 2
      app/src/main/res/layout/item_find_book.xml

@ -135,7 +135,7 @@ dependencies {
implementation 'androidx.viewpager2:viewpager2:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
implementation 'com.google.android.flexbox:flexbox:3.0.0' implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation 'com.google.code.gson:gson:2.8.6' implementation 'com.google.code.gson:gson:2.8.7'
implementation 'androidx.webkit:webkit:1.4.0' implementation 'androidx.webkit:webkit:1.4.0'
//media //media

@ -101,12 +101,12 @@ data class BookSource(
} }
fun getExploreKinds() = arrayListOf<ExploreKind>().apply { fun getExploreKinds() = arrayListOf<ExploreKind>().apply {
exploreUrl?.let { urlRule -> exploreUrl?.let { exploreUrl ->
var a = urlRule var a = exploreUrl
if (a.isNotBlank()) { if (a.isNotBlank()) {
kotlin.runCatching { kotlin.runCatching {
if (urlRule.startsWith("<js>", false) if (exploreUrl.startsWith("<js>", false)
|| urlRule.startsWith("@js", false) || exploreUrl.startsWith("@js", false)
) { ) {
val aCache = ACache.get(appCtx, "explore") val aCache = ACache.get(appCtx, "explore")
a = aCache.getAsString(bookSourceUrl) ?: "" a = aCache.getAsString(bookSourceUrl) ?: ""
@ -116,10 +116,10 @@ data class BookSource(
bindings["java"] = this bindings["java"] = this
bindings["cookie"] = CookieStore bindings["cookie"] = CookieStore
bindings["cache"] = CacheManager bindings["cache"] = CacheManager
val jsStr = if (urlRule.startsWith("@")) { val jsStr = if (exploreUrl.startsWith("@")) {
urlRule.substring(3) exploreUrl.substring(3)
} else { } else {
urlRule.substring(4, urlRule.lastIndexOf("<")) exploreUrl.substring(4, exploreUrl.lastIndexOf("<"))
} }
a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString() a = AppConst.SCRIPT_ENGINE.eval(jsStr, bindings).toString()
aCache.put(bookSourceUrl, a) aCache.put(bookSourceUrl, a)
@ -173,7 +173,7 @@ data class BookSource(
data class ExploreKind( data class ExploreKind(
var title: String, var title: String,
var url: String? = null var url: String? = null,
) )
class Converters { class Converters {

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.PopupMenu import android.widget.PopupMenu
import com.google.android.flexbox.FlexboxLayout
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.base.adapter.RecyclerAdapter
@ -56,18 +57,18 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
item.getExploreKinds() item.getExploreKinds()
}.onSuccess { kindList -> }.onSuccess { kindList ->
if (!kindList.isNullOrEmpty()) { if (!kindList.isNullOrEmpty()) {
glChild.visible() flexbox.visible()
glChild.removeAllViews() flexbox.removeAllViews()
kindList.map { kind -> kindList.map { kind ->
val tv = ItemFilletTextBinding.inflate( val tv = ItemFilletTextBinding.inflate(
LayoutInflater.from(context), LayoutInflater.from(context),
glChild, flexbox,
false false
) ).root
glChild.addView(tv.root) flexbox.addView(tv)
tv.textView.text = kind.title tv.text = kind.title
if (!kind.url.isNullOrEmpty()) { if (!kind.url.isNullOrEmpty()) {
tv.textView.setOnClickListener { tv.setOnClickListener {
callBack.openExplore( callBack.openExplore(
item.bookSourceUrl, item.bookSourceUrl,
kind.title, kind.title,
@ -75,6 +76,10 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
) )
} }
} }
val lp = tv.layoutParams as FlexboxLayout.LayoutParams
lp.let {
}
} }
} }
}.onFinally { }.onFinally {
@ -87,7 +92,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
} else { } else {
binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) binding.ivStatus.setImageResource(R.drawable.ic_arrow_right)
binding.rotateLoading.hide() binding.rotateLoading.hide()
binding.glChild.gone() binding.flexbox.gone()
} }
} }
} }

@ -155,6 +155,9 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
} }
override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) {
if (exploreUrl.isBlank()) {
return
}
startActivity<ExploreShowActivity> { startActivity<ExploreShowActivity> {
putExtra("exploreName", title) putExtra("exploreName", title)
putExtra("sourceUrl", sourceUrl) putExtra("sourceUrl", sourceUrl)

@ -56,7 +56,7 @@
android:layout_gravity="center"> android:layout_gravity="center">
<com.google.android.flexbox.FlexboxLayout <com.google.android.flexbox.FlexboxLayout
android:id="@+id/gl_child" android:id="@+id/flexbox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:clipToPadding="false" android:clipToPadding="false"

Loading…
Cancel
Save