Handle Entry network operations in the background
Previously the UI had to wait on the network request to complete or fail before updating.
This commit is contained in:
parent
bbbbbeae0d
commit
365026e1a0
1 changed files with 9 additions and 4 deletions
|
@ -23,6 +23,7 @@ class EntryRepository @Inject constructor(
|
||||||
private val entryDao: EntryDao,
|
private val entryDao: EntryDao,
|
||||||
private val logger: Timber.Tree
|
private val logger: Timber.Tree
|
||||||
) {
|
) {
|
||||||
|
private val repositoryScope = CoroutineScope(Dispatchers.IO)
|
||||||
fun observeRead() = entryDao.observeRead()
|
fun observeRead() = entryDao.observeRead()
|
||||||
fun observeStarred() = entryDao.observeStarred()
|
fun observeStarred() = entryDao.observeStarred()
|
||||||
fun observeUnread() = entryDao.observeUnread()
|
fun observeUnread() = entryDao.observeUnread()
|
||||||
|
@ -62,17 +63,21 @@ class EntryRepository @Inject constructor(
|
||||||
|
|
||||||
suspend fun markEntryRead(entry: Entry) {
|
suspend fun markEntryRead(entry: Entry) {
|
||||||
entryDao.update(entry.copy(status = Entry.Status.READ))
|
entryDao.update(entry.copy(status = Entry.Status.READ))
|
||||||
|
repositoryScope.launch {
|
||||||
retryOnFailure {
|
retryOnFailure {
|
||||||
apiService.updateEntries(listOf(entry.id), Entry.Status.READ)
|
apiService.updateEntries(listOf(entry.id), Entry.Status.READ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun markEntryUnread(entry: Entry) {
|
suspend fun markEntryUnread(entry: Entry) {
|
||||||
entryDao.update(entry.copy(status = Entry.Status.UNREAD))
|
entryDao.update(entry.copy(status = Entry.Status.UNREAD))
|
||||||
|
repositoryScope.launch {
|
||||||
retryOnFailure {
|
retryOnFailure {
|
||||||
apiService.updateEntries(listOf(entry.id), Entry.Status.UNREAD)
|
apiService.updateEntries(listOf(entry.id), Entry.Status.UNREAD)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun toggleStar(entry: Entry) {
|
suspend fun toggleStar(entry: Entry) {
|
||||||
entryDao.update(entry.copy(starred = !entry.starred))
|
entryDao.update(entry.copy(starred = !entry.starred))
|
||||||
|
|
Loading…
Reference in a new issue