pull/32/head
kunfei 5 years ago
parent 8d85662aa1
commit fd74bcedcf
  1. 9
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  2. 18
      app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt

@ -118,6 +118,7 @@ data class BookSource(
} }
fun getExploreKinds(): ArrayList<ExploreKind>? { fun getExploreKinds(): ArrayList<ExploreKind>? {
val exploreKinds = arrayListOf<ExploreKind>()
exploreUrl?.let { exploreUrl?.let {
var a = it var a = it
if (a.isNotBlank()) { if (a.isNotBlank()) {
@ -131,24 +132,22 @@ data class BookSource(
bindings bindings
).toString() ).toString()
} }
val exploreKinds = arrayListOf<ExploreKind>()
val b = a.split("(&&|\n)+".toRegex()) val b = a.split("(&&|\n)+".toRegex())
b.map { c -> b.map { c ->
val d = c.split("::") val d = c.split("::")
if (d.size > 1) if (d.size > 1)
exploreKinds.add(ExploreKind(d[0], d[1])) exploreKinds.add(ExploreKind(d[0], d[1]))
} }
return exploreKinds
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() exploreKinds.add(ExploreKind(e.localizedMessage))
} }
} }
} }
return null return exploreKinds
} }
data class ExploreKind( data class ExploreKind(
var title: String, var title: String,
var url: String var url: String? = null
) )
} }

@ -56,20 +56,22 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c
rotate_loading.show() rotate_loading.show()
Coroutine.async(scope) { Coroutine.async(scope) {
item.getExploreKinds() item.getExploreKinds()
}.onSuccess { }.onSuccess { kindList ->
it?.let { if (!kindList.isNullOrEmpty()) {
gl_child.visible() gl_child.visible()
gl_child.removeAllViews() gl_child.removeAllViews()
it.map { kind -> kindList.map { kind ->
val tv = LayoutInflater.from(context) val tv = LayoutInflater.from(context)
.inflate(R.layout.item_text, gl_child, false) .inflate(R.layout.item_text, gl_child, false)
tv.text_view.text = kind.title tv.text_view.text = kind.title
tv.text_view.onClick { tv.text_view.onClick {
callBack.openExplore( kind.url?.let { kindUrl ->
item.bookSourceUrl, callBack.openExplore(
kind.title, item.bookSourceUrl,
kind.url kind.title,
) kindUrl
)
}
} }
gl_child.addView(tv) gl_child.addView(tv)
} }

Loading…
Cancel
Save