From 9deda740085dd73e345946cb89c0570cccd5c175 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 9 Jul 2021 10:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E7=8E=B0=E7=95=8C=E9=9D=A2=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookSource.kt | 5 -- .../legado/app/data/entities/ExploreKind.kt | 31 ++++++++++ .../app/ui/main/explore/ExploreAdapter.kt | 57 ++++++++++--------- .../app/ui/main/explore/ExploreFragment.kt | 6 +- 4 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/ExploreKind.kt 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)