发现界面添加自定义样式

pull/1111/head
gedoor 3 years ago
parent c6c07234f8
commit 9deda74008
  1. 5
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 31
      app/src/main/java/io/legado/app/data/entities/ExploreKind.kt
  3. 57
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  4. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.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)

@ -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
}
}
}
}

@ -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<ExploreKind>) {
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)
}

@ -154,10 +154,8 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(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<ExploreShowActivity> {
putExtra("exploreName", title)
putExtra("sourceUrl", sourceUrl)

Loading…
Cancel
Save