pull/1654/merge
kunfei 3 years ago
parent 2be79303aa
commit 7097f4c0ec
  1. 6
      app/src/main/java/io/legado/app/base/adapter/DiffRecyclerAdapter.kt
  2. 8
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt
  4. 7
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt
  5. 10
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -48,11 +48,7 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context
fun setItems(items: List<ITEM>?) {
kotlin.runCatching {
if (items == null) {
asyncListDiffer.submitList(null)
} else {
asyncListDiffer.submitList(ArrayList(items))
}
asyncListDiffer.submitList(items?.toMutableList())
}
}

@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
@ -15,10 +15,8 @@ import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.applyTint
import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
/**
* 换封面
@ -68,15 +66,13 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover),
}
private fun initData() {
launch(Dispatchers.Default) {
whenStarted {
lifecycleScope.launchWhenStarted {
viewModel.dataFlow.conflate().collect {
adapter.setItems(it)
delay(1000)
}
}
}
}
override fun observeLiveBus() {
super.observeLiveBus()

@ -9,7 +9,7 @@ import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
@ -29,7 +29,6 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
@ -146,14 +145,12 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
}
binding.toolBar.menu.applyTint(requireContext())
}
launch(Dispatchers.Default) {
whenStarted {
lifecycleScope.launchWhenStarted {
viewModel.searchDataFlow.conflate().collect {
adapter.setItems(it)
delay(1000)
}
}
}
launch {
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
groups.clear()

@ -9,7 +9,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
@ -31,7 +31,6 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
@ -178,14 +177,12 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
}
binding.toolBar.menu.applyTint(requireContext())
}
launch(Dispatchers.Default) {
whenStarted {
lifecycleScope.launchWhenStarted {
viewModel.searchDataFlow.conflate().collect {
searchBookAdapter.setItems(it)
delay(1000)
}
}
}
launch {
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
groups.clear()

@ -11,7 +11,6 @@ import android.widget.TextView
import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.flexbox.FlexboxLayoutManager
@ -29,9 +28,12 @@ import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.recycler.LoadMoreView
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.*
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack,
@ -195,14 +197,12 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
}
private fun initData() {
lifecycleScope.launch(Dispatchers.Default) {
whenStarted {
lifecycleScope.launchWhenStarted {
viewModel.searchDataFlow.conflate().collect {
adapter.setItems(it)
delay(1000)
}
}
}
launch {
appDb.bookSourceDao.flowGroupEnabled().conflate().collect {
groups.clear()

Loading…
Cancel
Save