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:
William Brawner 2022-11-11 21:20:58 -07:00
parent bbbbbeae0d
commit 365026e1a0

View file

@ -23,6 +23,7 @@ class EntryRepository @Inject constructor(
private val entryDao: EntryDao,
private val logger: Timber.Tree
) {
private val repositoryScope = CoroutineScope(Dispatchers.IO)
fun observeRead() = entryDao.observeRead()
fun observeStarred() = entryDao.observeStarred()
fun observeUnread() = entryDao.observeUnread()
@ -62,15 +63,19 @@ class EntryRepository @Inject constructor(
suspend fun markEntryRead(entry: Entry) {
entryDao.update(entry.copy(status = Entry.Status.READ))
retryOnFailure {
apiService.updateEntries(listOf(entry.id), Entry.Status.READ)
repositoryScope.launch {
retryOnFailure {
apiService.updateEntries(listOf(entry.id), Entry.Status.READ)
}
}
}
suspend fun markEntryUnread(entry: Entry) {
entryDao.update(entry.copy(status = Entry.Status.UNREAD))
retryOnFailure {
apiService.updateEntries(listOf(entry.id), Entry.Status.UNREAD)
repositoryScope.launch {
retryOnFailure {
apiService.updateEntries(listOf(entry.id), Entry.Status.UNREAD)
}
}
}