|
|
@ -11,6 +11,7 @@ import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter |
|
|
|
import io.legado.app.base.adapter.RecyclerAdapter |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.appDb |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
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.ItemFilletTextBinding |
|
|
|
import io.legado.app.databinding.ItemFindBookBinding |
|
|
|
import io.legado.app.databinding.ItemFindBookBinding |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
@ -56,10 +57,27 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca |
|
|
|
Coroutine.async(scope) { |
|
|
|
Coroutine.async(scope) { |
|
|
|
item.getExploreKinds() |
|
|
|
item.getExploreKinds() |
|
|
|
}.onSuccess { kindList -> |
|
|
|
}.onSuccess { kindList -> |
|
|
|
if (!kindList.isNullOrEmpty()) { |
|
|
|
upKindList(flexbox, item.bookSourceUrl, kindList) |
|
|
|
|
|
|
|
}.onFinally { |
|
|
|
|
|
|
|
rotateLoading.hide() |
|
|
|
|
|
|
|
if (scrollTo >= 0) { |
|
|
|
|
|
|
|
callBack.scrollTo(scrollTo) |
|
|
|
|
|
|
|
scrollTo = -1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) |
|
|
|
|
|
|
|
binding.rotateLoading.hide() |
|
|
|
|
|
|
|
binding.flexbox.gone() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List<ExploreKind>) { |
|
|
|
|
|
|
|
if (!kinds.isNullOrEmpty()) { |
|
|
|
flexbox.visible() |
|
|
|
flexbox.visible() |
|
|
|
flexbox.removeAllViews() |
|
|
|
flexbox.removeAllViews() |
|
|
|
kindList.map { kind -> |
|
|
|
kinds.map { kind -> |
|
|
|
val tv = ItemFilletTextBinding.inflate( |
|
|
|
val tv = ItemFilletTextBinding.inflate( |
|
|
|
LayoutInflater.from(context), |
|
|
|
LayoutInflater.from(context), |
|
|
|
flexbox, |
|
|
|
flexbox, |
|
|
@ -67,32 +85,17 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca |
|
|
|
).root |
|
|
|
).root |
|
|
|
flexbox.addView(tv) |
|
|
|
flexbox.addView(tv) |
|
|
|
tv.text = kind.title |
|
|
|
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 |
|
|
|
val lp = tv.layoutParams as FlexboxLayout.LayoutParams |
|
|
|
lp.let { |
|
|
|
kind.style.let { style -> |
|
|
|
|
|
|
|
lp.flexGrow = style.layout_flexGrow |
|
|
|
} |
|
|
|
lp.flexShrink = style.layout_flexShrink |
|
|
|
} |
|
|
|
lp.alignSelf = style.alignSelf() |
|
|
|
} |
|
|
|
lp.flexBasisPercent = style.layout_flexBasisPercent |
|
|
|
}.onFinally { |
|
|
|
lp.isWrapBefore = style.layout_wrapBefore |
|
|
|
rotateLoading.hide() |
|
|
|
|
|
|
|
if (scrollTo >= 0) { |
|
|
|
|
|
|
|
callBack.scrollTo(scrollTo) |
|
|
|
|
|
|
|
scrollTo = -1 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
tv.setOnClickListener { |
|
|
|
|
|
|
|
callBack.openExplore(sourceUrl, kind.title, kind.url) |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) |
|
|
|
|
|
|
|
binding.rotateLoading.hide() |
|
|
|
|
|
|
|
binding.flexbox.gone() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -151,7 +154,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|
fun scrollTo(pos: Int) |
|
|
|
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 editSource(sourceUrl: String) |
|
|
|
fun toTop(source: BookSource) |
|
|
|
fun toTop(source: BookSource) |
|
|
|
} |
|
|
|
} |
|
|
|