This commit is contained in:
kunfei
2022-02-10 16:58:57 +08:00
parent e885c30cac
commit 412119a3f1
2 changed files with 10 additions and 5 deletions

View File

@@ -23,7 +23,7 @@ import io.legado.app.utils.*
import kotlinx.coroutines.CoroutineScope
import splitties.views.onLongClick
class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) :
class ExploreAdapter(context: Context, val callBack: CallBack) :
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) {
private val recycler = arrayListOf<View>()
@@ -56,7 +56,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
if (scrollTo >= 0) {
callBack.scrollTo(scrollTo)
}
Coroutine.async(scope) {
Coroutine.async(callBack.scope) {
item.exploreKinds
}.onSuccess { kindList ->
upKindList(flexbox, item.bookSourceUrl, kindList)
@@ -167,12 +167,12 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
putExtra("type", "bookSource")
putExtra("key", source.bookSourceUrl)
}
R.id.menu_refresh -> Coroutine.async(scope) {
R.id.menu_refresh -> Coroutine.async(callBack.scope) {
ACache.get(context, "explore").remove(source.bookSourceUrl)
}.onSuccess {
callBack.refreshData()
}
R.id.menu_del -> Coroutine.async(scope) {
R.id.menu_del -> Coroutine.async(callBack.scope) {
appDb.bookSourceDao.delete(source)
}
}
@@ -183,6 +183,7 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca
}
interface CallBack {
val scope: CoroutineScope
fun refreshData()
fun scrollTo(pos: Int)
fun openExplore(sourceUrl: String, title: String, exploreUrl: String?)

View File

@@ -24,6 +24,7 @@ import io.legado.app.ui.book.explore.ExploreShowActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
@@ -35,7 +36,7 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
ExploreAdapter.CallBack {
override val viewModel by viewModels<ExploreViewModel>()
private val binding by viewBinding(FragmentExploreBinding::bind)
private val adapter by lazy { ExploreAdapter(requireContext(), lifecycleScope, this) }
private val adapter by lazy { ExploreAdapter(requireContext(), this) }
private val linearLayoutManager by lazy { LinearLayoutManager(context) }
private val searchView: SearchView by lazy {
binding.titleBar.findViewById(R.id.search_view)
@@ -142,6 +143,9 @@ class ExploreFragment : VMBaseFragment<ExploreViewModel>(R.layout.fragment_explo
}
}
override val scope: CoroutineScope
get() = lifecycleScope
override fun onCompatOptionsItemSelected(item: MenuItem) {
super.onCompatOptionsItemSelected(item)
if (item.groupId == R.id.menu_group_text) {