mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -46,13 +46,14 @@ abstract class DiffRecyclerAdapter<ITEM, VB : ViewBinding>(protected val context
|
||||
recyclerView.adapter = this
|
||||
}
|
||||
|
||||
/**
|
||||
* items与上一次提交的对象必须不同,如果指向相同地址即使数据变化也不会刷新
|
||||
*/
|
||||
@Synchronized
|
||||
fun setItems(items: List<ITEM>?) {
|
||||
kotlin.runCatching {
|
||||
asyncListDiffer.submitList(items)
|
||||
if (items == null) {
|
||||
asyncListDiffer.submitList(null)
|
||||
} else {
|
||||
asyncListDiffer.submitList(ArrayList(items))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import io.legado.app.utils.applyTint
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,7 @@ class ChangeCoverDialog() : BaseDialogFragment(R.layout.dialog_change_cover),
|
||||
private fun initData() {
|
||||
launch {
|
||||
viewModel.dataFlow
|
||||
.conflate()
|
||||
.collect {
|
||||
adapter.setItems(it)
|
||||
delay(1000)
|
||||
|
||||
@@ -18,7 +18,6 @@ import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import java.util.*
|
||||
import java.util.concurrent.Executors
|
||||
@@ -56,8 +55,7 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
|
||||
searchBooks.clear()
|
||||
searchSuccess = null
|
||||
}
|
||||
}.conflate()
|
||||
.flowOn(IO)
|
||||
}.flowOn(IO)
|
||||
|
||||
@Volatile
|
||||
private var searchIndex = -1
|
||||
|
||||
@@ -29,6 +29,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@@ -145,6 +146,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
|
||||
}
|
||||
launch {
|
||||
viewModel.searchDataFlow
|
||||
.conflate()
|
||||
.collect {
|
||||
adapter.setItems(it)
|
||||
delay(1000)
|
||||
|
||||
@@ -22,7 +22,6 @@ import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import splitties.init.appCtx
|
||||
@@ -55,11 +54,11 @@ class ChangeBookSourceViewModel(application: Application) : BaseViewModel(applic
|
||||
searchBook.name.contains(screenKey) -> searchBooks.add(searchBook)
|
||||
else -> return
|
||||
}
|
||||
trySend(searchBooks)
|
||||
trySend(arrayOf(searchBooks))
|
||||
}
|
||||
|
||||
override fun upAdapter() {
|
||||
trySend(searchBooks)
|
||||
trySend(arrayOf(searchBooks))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,7 +66,7 @@ class ChangeBookSourceViewModel(application: Application) : BaseViewModel(applic
|
||||
getDbSearchBooks().let {
|
||||
searchBooks.clear()
|
||||
searchBooks.addAll(it)
|
||||
trySend(searchBooks)
|
||||
trySend(arrayOf(searchBooks))
|
||||
}
|
||||
|
||||
if (searchBooks.size <= 1) {
|
||||
@@ -77,10 +76,9 @@ class ChangeBookSourceViewModel(application: Application) : BaseViewModel(applic
|
||||
awaitClose {
|
||||
searchCallback = null
|
||||
}
|
||||
}.conflate()
|
||||
.map {
|
||||
searchBooks.sortedBy { it.originOrder }
|
||||
}.flowOn(IO)
|
||||
}.map {
|
||||
searchBooks.sortedBy { it.originOrder }
|
||||
}.flowOn(IO)
|
||||
|
||||
@Volatile
|
||||
private var searchIndex = -1
|
||||
|
||||
@@ -31,6 +31,7 @@ import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||
import io.legado.app.utils.*
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
@@ -177,6 +178,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
|
||||
}
|
||||
launch {
|
||||
viewModel.searchDataFlow
|
||||
.conflate()
|
||||
.collect {
|
||||
searchBookAdapter.setItems(it)
|
||||
delay(1000)
|
||||
|
||||
@@ -24,7 +24,6 @@ import kotlinx.coroutines.ExecutorCoroutineDispatcher
|
||||
import kotlinx.coroutines.asCoroutineDispatcher
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import splitties.init.appCtx
|
||||
@@ -83,10 +82,9 @@ class ChangeChapterSourceViewModel(application: Application) : BaseViewModel(app
|
||||
awaitClose {
|
||||
searchCallback = null
|
||||
}
|
||||
}.conflate()
|
||||
.map {
|
||||
searchBooks.sortedBy { it.originOrder }
|
||||
}.flowOn(IO)
|
||||
}.map {
|
||||
searchBooks.sortedBy { it.originOrder }
|
||||
}.flowOn(IO)
|
||||
|
||||
@Volatile
|
||||
private var searchIndex = -1
|
||||
|
||||
@@ -30,6 +30,7 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
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
|
||||
|
||||
@@ -197,6 +198,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
private fun initData() {
|
||||
launch {
|
||||
viewModel.searchDataFlow
|
||||
.conflate()
|
||||
.collect {
|
||||
adapter.setItems(it)
|
||||
delay(1000)
|
||||
|
||||
@@ -10,7 +10,6 @@ import io.legado.app.data.entities.SearchKeyword
|
||||
import io.legado.app.model.webBook.SearchModel
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
|
||||
class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
private val searchModel = SearchModel(viewModelScope)
|
||||
@@ -48,7 +47,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
awaitClose {
|
||||
searchModel.unRegisterCallback()
|
||||
}
|
||||
}.conflate()
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始搜索
|
||||
|
||||
Reference in New Issue
Block a user