mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use data service item action to handle library list changes
This commit is contained in:
parent
89099d4431
commit
7d20c6ca91
1 changed files with 4 additions and 28 deletions
|
|
@ -8,9 +8,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import app.omnivore.omnivore.*
|
||||
import app.omnivore.omnivore.dataService.DataService
|
||||
import app.omnivore.omnivore.dataService.sync
|
||||
import app.omnivore.omnivore.dataService.syncOfflineItemsWithServerIfNeeded
|
||||
import app.omnivore.omnivore.dataService.*
|
||||
import app.omnivore.omnivore.networking.*
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemCardData
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemCardDataWithLabels
|
||||
|
|
@ -137,44 +135,22 @@ class LibraryViewModel @Inject constructor(
|
|||
fun handleSavedItemAction(itemID: String, action: SavedItemAction) {
|
||||
when (action) {
|
||||
SavedItemAction.Delete -> {
|
||||
removeItemFromList(itemID)
|
||||
|
||||
viewModelScope.launch {
|
||||
networker.deleteSavedItem(itemID)
|
||||
dataService.deleteSavedItem(itemID)
|
||||
}
|
||||
}
|
||||
SavedItemAction.Archive -> {
|
||||
removeItemFromList(itemID)
|
||||
viewModelScope.launch {
|
||||
networker.archiveSavedItem(itemID)
|
||||
dataService.archiveSavedItem(itemID)
|
||||
}
|
||||
}
|
||||
SavedItemAction.Unarchive -> {
|
||||
removeItemFromList(itemID)
|
||||
viewModelScope.launch {
|
||||
networker.unarchiveSavedItem(itemID)
|
||||
dataService.unarchiveSavedItem(itemID)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun removeItemFromList(itemID: String) {
|
||||
viewModelScope.launch {
|
||||
withContext(Dispatchers.IO) {
|
||||
dataService.db.savedItemDao().deleteById(itemID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchQuery(): String {
|
||||
var query = "in:inbox sort:saved"
|
||||
|
||||
if (searchTextLiveData.value != "") {
|
||||
query = query.plus(" ${searchTextLiveData.value}")
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
}
|
||||
|
||||
enum class SavedItemAction {
|
||||
|
|
|
|||
Loading…
Reference in a new issue