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. 14
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverDialog.kt
  3. 13
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt
  5. 16
      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>?) { fun setItems(items: List<ITEM>?) {
kotlin.runCatching { kotlin.runCatching {
if (items == null) { asyncListDiffer.submitList(items?.toMutableList())
asyncListDiffer.submitList(null)
} else {
asyncListDiffer.submitList(ArrayList(items))
}
} }
} }

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

@ -9,7 +9,7 @@ import androidx.appcompat.widget.SearchView
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R 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.ui.widget.recycler.VerticalDivider
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.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -146,12 +145,10 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
} }
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
launch(Dispatchers.Default) { lifecycleScope.launchWhenStarted {
whenStarted { viewModel.searchDataFlow.conflate().collect {
viewModel.searchDataFlow.conflate().collect { adapter.setItems(it)
adapter.setItems(it) delay(1000)
delay(1000)
}
} }
} }
launch { launch {

@ -9,7 +9,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.fragment.app.viewModels import androidx.fragment.app.viewModels
import androidx.lifecycle.whenStarted import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment 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.ui.widget.recycler.VerticalDivider
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.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -178,12 +177,10 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
} }
binding.toolBar.menu.applyTint(requireContext()) binding.toolBar.menu.applyTint(requireContext())
} }
launch(Dispatchers.Default) { lifecycleScope.launchWhenStarted {
whenStarted { viewModel.searchDataFlow.conflate().collect {
viewModel.searchDataFlow.conflate().collect { searchBookAdapter.setItems(it)
searchBookAdapter.setItems(it) delay(1000)
delay(1000)
}
} }
} }
launch { launch {

@ -11,7 +11,6 @@ import android.widget.TextView
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenStarted
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.flexbox.FlexboxLayoutManager 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.ui.widget.recycler.LoadMoreView
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.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.conflate import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(), class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel>(),
BookAdapter.CallBack, BookAdapter.CallBack,
@ -195,12 +197,10 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
} }
private fun initData() { private fun initData() {
lifecycleScope.launch(Dispatchers.Default) { lifecycleScope.launchWhenStarted {
whenStarted { viewModel.searchDataFlow.conflate().collect {
viewModel.searchDataFlow.conflate().collect { adapter.setItems(it)
adapter.setItems(it) delay(1000)
delay(1000)
}
} }
} }
launch { launch {

Loading…
Cancel
Save