pull/1604/head
kunfei 3 years ago
parent e885c30cac
commit 412119a3f1
  1. 9
      app/src/main/java/io/legado/app/ui/main/explore/ExploreAdapter.kt
  2. 6
      app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt

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

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

Loading…
Cancel
Save