优化
This commit is contained in:
@@ -12,7 +12,7 @@ import io.legado.app.data.entities.SearchBook
|
||||
import io.legado.app.data.entities.SearchKeyword
|
||||
import io.legado.app.help.config.AppConfig
|
||||
import io.legado.app.model.webBook.SearchModel
|
||||
import io.legado.app.utils.DelayLiveData
|
||||
import io.legado.app.utils.ConflateLiveData
|
||||
import io.legado.app.utils.toastOnUi
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.mapLatest
|
||||
@@ -22,7 +22,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
|
||||
val handler = Handler(Looper.getMainLooper())
|
||||
val bookshelf = hashSetOf<String>()
|
||||
val upAdapterLiveData = MutableLiveData<String>()
|
||||
var searchBookLiveData = DelayLiveData<List<SearchBook>>(1000)
|
||||
var searchBookLiveData = ConflateLiveData<List<SearchBook>>(1000)
|
||||
val searchScope: SearchScope = SearchScope(AppConfig.searchScope)
|
||||
var searchFinishCallback: ((isEmpty: Boolean) -> Unit)? = null
|
||||
var isSearchLiveData = MutableLiveData<Boolean>()
|
||||
|
||||
+5
-1
@@ -4,7 +4,11 @@ import android.os.Handler
|
||||
import android.os.Looper
|
||||
import androidx.lifecycle.LiveData
|
||||
|
||||
class DelayLiveData<T>(val delay: Int) : LiveData<T>() {
|
||||
/**
|
||||
* 合并发送,只发送最新数据
|
||||
* @param delay 发送时间间隔
|
||||
*/
|
||||
class ConflateLiveData<T>(val delay: Int) : LiveData<T>() {
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private val sendRunnable = Runnable { sendData() }
|
||||
private var postTime = 0L
|
||||
Reference in New Issue
Block a user