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 b972cefe8..10c420ba0 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 @@ -118,6 +118,7 @@ data class BookSource( } fun getExploreKinds(): ArrayList? { + val exploreKinds = arrayListOf() exploreUrl?.let { var a = it if (a.isNotBlank()) { @@ -131,24 +132,22 @@ data class BookSource( bindings ).toString() } - val exploreKinds = arrayListOf() val b = a.split("(&&|\n)+".toRegex()) b.map { c -> val d = c.split("::") if (d.size > 1) exploreKinds.add(ExploreKind(d[0], d[1])) } - return exploreKinds } catch (e: Exception) { - e.printStackTrace() + exploreKinds.add(ExploreKind(e.localizedMessage)) } } } - return null + return exploreKinds } data class ExploreKind( var title: String, - var url: String + var url: String? = null ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt index 20c625bfa..a7f786bfe 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/FindBookAdapter.kt @@ -56,20 +56,22 @@ class FindBookAdapter(context: Context, private val scope: CoroutineScope, val c rotate_loading.show() Coroutine.async(scope) { item.getExploreKinds() - }.onSuccess { - it?.let { + }.onSuccess { kindList -> + if (!kindList.isNullOrEmpty()) { gl_child.visible() gl_child.removeAllViews() - it.map { kind -> + kindList.map { kind -> val tv = LayoutInflater.from(context) .inflate(R.layout.item_text, gl_child, false) tv.text_view.text = kind.title tv.text_view.onClick { - callBack.openExplore( - item.bookSourceUrl, - kind.title, - kind.url - ) + kind.url?.let { kindUrl -> + callBack.openExplore( + item.bookSourceUrl, + kind.title, + kindUrl + ) + } } gl_child.addView(tv) }