From 412119a3f1fb9aeebabe27e2cf9d81f280dff2af Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 10 Feb 2022 16:58:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/main/explore/ExploreAdapter.kt | 9 +++++---- .../io/legado/app/ui/main/explore/ExploreFragment.kt | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt index 5f7f9cb3b..e5617fd6c 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt @@ -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(context) { private val recycler = arrayListOf() @@ -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?) diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 7c321c9ca..86ceded1c 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -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(R.layout.fragment_explo ExploreAdapter.CallBack { override val viewModel by viewModels() 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(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) {