diff --git a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt index 61f7e4e2d..a20bb60ab 100644 --- a/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt +++ b/app/src/main/java/io/legado/app/data/entities/rule/ExploreRule.kt @@ -36,7 +36,8 @@ data class ExploreRule( val b = a.split("(&&|\n)+".toRegex()) b.map { c -> val d = c.split("::") - exploreKinds.add(ExploreKind(d[0], d[1])) + if (d.size > 1) + exploreKinds.add(ExploreKind(d[0], d[1])) } return exploreKinds } catch (e: Exception) { diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt index 9dec52302..c57b6a36c 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt @@ -10,15 +10,18 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.data.entities.BookSource +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.theme.ColorUtils import io.legado.app.utils.gone import io.legado.app.utils.visible import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.android.synthetic.main.item_text.view.* +import kotlinx.coroutines.CoroutineScope import org.jetbrains.anko.sdk27.listeners.onClick -class FindBookAdapter:PagedListAdapter(DIFF_CALLBACK) { +class FindBookAdapter(private val scope: CoroutineScope) : + PagedListAdapter(DIFF_CALLBACK) { var exIndex = 0 @@ -58,26 +61,30 @@ class FindBookAdapter:PagedListAdapter } if (exIndex == position) { gl_child.visible() - bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let { - var rowNum = 0 - var columnNum = 0 - gl_child.removeAllViews() - it.map { kind -> - val tv = LayoutInflater.from(context) - .inflate(R.layout.item_text, gl_child, false) - tv.text_view.text = kind.title - val rowSpecs = GridLayout.spec(rowNum, 1.0f) - val colSpecs = GridLayout.spec(columnNum, 1.0f) - val params = GridLayout.LayoutParams(rowSpecs, colSpecs) - gl_child.addView(tv, params) - if (columnNum < 2) { - columnNum++ - } else { - columnNum = 0 - rowNum++ - } - tv.onClick { + Coroutine.async(scope) { + bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl) + }.onSuccess { + it?.let { + var rowNum = 0 + var columnNum = 0 + gl_child.removeAllViews() + it.map { kind -> + val tv = LayoutInflater.from(context) + .inflate(R.layout.item_text, gl_child, false) + tv.text_view.text = kind.title + val rowSpecs = GridLayout.spec(rowNum, 1.0f) + val colSpecs = GridLayout.spec(columnNum, 1.0f) + val params = GridLayout.LayoutParams(rowSpecs, colSpecs) + gl_child.addView(tv, params) + if (columnNum < 2) { + columnNum++ + } else { + columnNum = 0 + rowNum++ + } + tv.onClick { + } } } } diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt index 60e3bef88..e991b501a 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt @@ -34,7 +34,7 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book) { private fun initRecyclerView() { ATH.applyEdgeEffectColor(rv_find) rv_find.layoutManager = LinearLayoutManager(context) - adapter = FindBookAdapter() + adapter = FindBookAdapter(this) rv_find.adapter = adapter }