Register edits locally through the repository

This commit is contained in:
davide 2022-07-25 14:08:57 +02:00
parent 924f4da1ec
commit 73e6742cee

View File

@ -140,15 +140,8 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
} }
override suspend fun markAsRead(id: Int): Boolean { override suspend fun markAsRead(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check internet connection
api.markAsRead(id.toString()) val success = api.markAsRead(id.toString())?.isSuccess == true
badgeUnread -= 1
return true
}
override suspend fun unmarkAsRead(id: Int): Boolean {
// TODO: Check success, store in DB
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
if (success) { if (success) {
markAsReadLocally(id) markAsReadLocally(id)
@ -156,18 +149,34 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
return success return success
} }
override suspend fun unmarkAsRead(id: Int): Boolean {
// TODO: Check internet connection
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
if (success) {
unmarkAsReadLocally(id)
}
return success
}
override suspend fun starr(id: Int): Boolean { override suspend fun starr(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check success, store in DB
api.starr(id.toString()) val success = api.starr(id.toString())?.isSuccess == true
badgeStarred += 1
return true if (success) {
starrLocally(id)
}
return success
} }
override suspend fun unstarr(id: Int): Boolean { override suspend fun unstarr(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check internet connection
api.unstarr(id.toString()) val success = api.unstarr(id.toString())?.isSuccess == true
badgeStarred -= 1
return true if (success) {
unstarrLocally(id)
}
return success
} }
override suspend fun markAllAsRead(ids: List<Int>): Boolean { override suspend fun markAllAsRead(ids: List<Int>): Boolean {
@ -191,6 +200,30 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
} }
} }
private fun unmarkAsReadLocally(id: Int) {
// TODO: Mark also in the database
if (!items.first {it.id == id}.unread) {
items.first {it.id == id}.unread = true
badgeUnread += 1
}
}
private fun starrLocally(id: Int) {
// TODO: Mark also in the database
if (!items.first {it.id == id}.starred) {
items.first {it.id == id}.starred = true
badgeStarred += 1
}
}
private fun unstarrLocally(id: Int) {
// TODO: Mark also in the database
if (items.first {it.id == id}.starred) {
items.first {it.id == id}.starred = false
badgeStarred -= 1
}
}
override suspend fun createSource( override suspend fun createSource(
title: String, title: String,
url: String, url: String,