Don't restart search if query is unchanged
This commit is contained in:
parent
cb5fe404e2
commit
a3be3188fa
@ -28,7 +28,7 @@ class SearchVM : ViewModel(), KoinComponent {
|
|||||||
private val websearchRepository: WebsearchRepository by inject()
|
private val websearchRepository: WebsearchRepository by inject()
|
||||||
|
|
||||||
val isSearching = MutableLiveData(false)
|
val isSearching = MutableLiveData(false)
|
||||||
val searchQuery = MutableLiveData("")
|
val searchQuery = MutableLiveData<String>("")
|
||||||
val isSearchEmpty = MutableLiveData(true)
|
val isSearchEmpty = MutableLiveData(true)
|
||||||
|
|
||||||
val showLabels = dataStore.data.map { it.grid.showLabels }.asLiveData()
|
val showLabels = dataStore.data.map { it.grid.showLabels }.asLiveData()
|
||||||
@ -55,11 +55,12 @@ class SearchVM : ViewModel(), KoinComponent {
|
|||||||
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(), replay = 1)
|
.shareIn(viewModelScope, SharingStarted.WhileSubscribed(), replay = 1)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
search("")
|
search("", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
var searchJob: Job? = null
|
var searchJob: Job? = null
|
||||||
fun search(query: String) {
|
fun search(query: String, forceRestart: Boolean = false) {
|
||||||
|
if (searchQuery.value == query && !forceRestart) return
|
||||||
searchQuery.value = query
|
searchQuery.value = query
|
||||||
isSearchEmpty.value = query.isEmpty()
|
isSearchEmpty.value = query.isEmpty()
|
||||||
hiddenResults.value = emptyList()
|
hiddenResults.value = emptyList()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user