mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
discard old search results when new results come in
This commit is contained in:
parent
8faf23d4ba
commit
8349a05dfd
1 changed files with 15 additions and 15 deletions
|
|
@ -56,10 +56,24 @@ class LibraryViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun load(clearPreviousSearch: Boolean = false) {
|
||||
viewModelScope.launch {
|
||||
if (searchTextLiveData.value != "") {
|
||||
performSearch(clearPreviousSearch)
|
||||
} else {
|
||||
syncItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun syncItems() {
|
||||
val syncStart = LocalDateTime.now()
|
||||
val lastSyncDate = getLastSyncTime() ?: LocalDateTime.MIN
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
isRefreshing = false
|
||||
}
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
performItemSync(cursor = null, since = lastSyncDate.toString(), count = 0)
|
||||
}
|
||||
|
|
@ -80,10 +94,6 @@ class LibraryViewModel @Inject constructor(
|
|||
val items = dataService.db.savedItemDao().getLibraryData()
|
||||
|
||||
itemsLiveData.postValue(items)
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
isRefreshing = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +118,7 @@ class LibraryViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
val previousItems = if (clearPreviousSearch) listOf() else searchedItems
|
||||
searchedItems = previousItems.plus(searchResult.cardsData)
|
||||
searchedItems = searchResult.cardsData
|
||||
itemsLiveData.postValue(searchedItems)
|
||||
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
|
|
@ -116,16 +126,6 @@ class LibraryViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun load(clearPreviousSearch: Boolean = false) {
|
||||
viewModelScope.launch {
|
||||
if (searchTextLiveData.value != "") {
|
||||
performSearch(clearPreviousSearch)
|
||||
} else {
|
||||
syncItems()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun handleSavedItemAction(itemID: String, action: SavedItemAction) {
|
||||
when (action) {
|
||||
SavedItemAction.Delete -> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue