diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index f5843f486..fcdb4ee7b 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -171,11 +171,6 @@ data class BookSource( private fun equal(a: String?, b: String?) = a == b || (a.isNullOrEmpty() && b.isNullOrEmpty()) - data class ExploreKind( - var title: String, - var url: String? = null, - ) - class Converters { @TypeConverter fun exploreRuleToString(exploreRule: ExploreRule?): String = GSON.toJson(exploreRule) diff --git a/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt new file mode 100644 index 000000000..f683a7fef --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/ExploreKind.kt @@ -0,0 +1,31 @@ +package io.legado.app.data.entities + +data class ExploreKind( + val title: String, + val url: String? = null, + val style: Style = Style() +) { + + data class Style( + val layout_flexGrow: Float = 0F, + val layout_flexShrink: Float = 1F, + val layout_alignSelf: String = "auto", + val layout_flexBasisPercent: Float = -1F, + val layout_wrapBefore: Boolean = false, + ) { + + fun alignSelf(): Int { + return when (layout_alignSelf) { + "auto" -> -1 + "flex_start" -> 0 + "flex_end" -> 1 + "center" -> 2 + "baseline" -> 3 + "stretch" -> 4 + else -> -1 + } + } + + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index dce02afaa..85c1a03b2 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -11,6 +11,7 @@ import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.RecyclerAdapter import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource +import io.legado.app.data.entities.ExploreKind import io.legado.app.databinding.ItemFilletTextBinding import io.legado.app.databinding.ItemFindBookBinding import io.legado.app.help.coroutine.Coroutine @@ -56,32 +57,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca Coroutine.async(scope) { item.getExploreKinds() }.onSuccess { kindList -> - if (!kindList.isNullOrEmpty()) { - flexbox.visible() - flexbox.removeAllViews() - kindList.map { kind -> - val tv = ItemFilletTextBinding.inflate( - LayoutInflater.from(context), - flexbox, - false - ).root - flexbox.addView(tv) - tv.text = kind.title - if (!kind.url.isNullOrEmpty()) { - tv.setOnClickListener { - callBack.openExplore( - item.bookSourceUrl, - kind.title, - kind.url.toString() - ) - } - } - val lp = tv.layoutParams as FlexboxLayout.LayoutParams - lp.let { - - } - } - } + upKindList(flexbox, item.bookSourceUrl, kindList) }.onFinally { rotateLoading.hide() if (scrollTo >= 0) { @@ -97,6 +73,33 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca } } + private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List) { + if (!kinds.isNullOrEmpty()) { + flexbox.visible() + flexbox.removeAllViews() + kinds.map { kind -> + val tv = ItemFilletTextBinding.inflate( + LayoutInflater.from(context), + flexbox, + false + ).root + flexbox.addView(tv) + tv.text = kind.title + val lp = tv.layoutParams as FlexboxLayout.LayoutParams + kind.style.let { style -> + lp.flexGrow = style.layout_flexGrow + lp.flexShrink = style.layout_flexShrink + lp.alignSelf = style.alignSelf() + lp.flexBasisPercent = style.layout_flexBasisPercent + lp.isWrapBefore = style.layout_wrapBefore + } + tv.setOnClickListener { + callBack.openExplore(sourceUrl, kind.title, kind.url) + } + } + } + } + override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { binding.apply { llTitle.setOnClickListener { @@ -151,7 +154,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca interface CallBack { fun scrollTo(pos: Int) - fun openExplore(sourceUrl: String, title: String, exploreUrl: String) + fun openExplore(sourceUrl: String, title: String, exploreUrl: String?) fun editSource(sourceUrl: String) fun toTop(source: BookSource) } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 359ec8dea..8e78d53bb 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -154,10 +154,8 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_explo (binding.rvFind.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(pos, 0) } - override fun openExplore(sourceUrl: String, title: String, exploreUrl: String) { - if (exploreUrl.isBlank()) { - return - } + override fun openExplore(sourceUrl: String, title: String, exploreUrl: String?) { + if (exploreUrl.isNullOrBlank()) return startActivity { putExtra("exploreName", title) putExtra("sourceUrl", sourceUrl)