Simplify local item changes
This commit is contained in:
parent
1890297c9d
commit
7f8d04618a
@ -147,7 +147,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
|||||||
val success = api.markAsRead(id.toString())?.isSuccess == true
|
val success = api.markAsRead(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
markAsReadLocally(id)
|
markAsReadLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
|||||||
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
val success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
unmarkAsReadLocally(id)
|
unmarkAsReadLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
@ -167,7 +167,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
|||||||
val success = api.starr(id.toString())?.isSuccess == true
|
val success = api.starr(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
starrLocally(id)
|
starrLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
@ -177,7 +177,7 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
|||||||
val success = api.unstarr(id.toString())?.isSuccess == true
|
val success = api.unstarr(id.toString())?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
unstarrLocally(id)
|
unstarrLocally(items.first {it.id == id})
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
@ -188,41 +188,42 @@ class RepositoryImpl(private val api: SelfossApi, private val apiDetails: ApiDet
|
|||||||
val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true
|
val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
for (id in ids) {
|
val itemsToMark = items.filter { it.id in ids }
|
||||||
markAsReadLocally(id)
|
for (item in itemsToMark) {
|
||||||
|
markAsReadLocally(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun markAsReadLocally(id: Int) {
|
private fun markAsReadLocally(item: SelfossModel.Item) {
|
||||||
// TODO: Mark also in the database
|
// TODO: Mark also in the database
|
||||||
if (items.first {it.id == id}.unread) {
|
if (item.unread) {
|
||||||
items.first {it.id == id}.unread = false
|
item.unread = false
|
||||||
badgeUnread -= 1
|
badgeUnread -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unmarkAsReadLocally(id: Int) {
|
private fun unmarkAsReadLocally(item: SelfossModel.Item) {
|
||||||
// TODO: Mark also in the database
|
// TODO: Mark also in the database
|
||||||
if (!items.first {it.id == id}.unread) {
|
if (!item.unread) {
|
||||||
items.first {it.id == id}.unread = true
|
item.unread = true
|
||||||
badgeUnread += 1
|
badgeUnread += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun starrLocally(id: Int) {
|
private fun starrLocally(item: SelfossModel.Item) {
|
||||||
// TODO: Mark also in the database
|
// TODO: Mark also in the database
|
||||||
if (!items.first {it.id == id}.starred) {
|
if (!item.starred) {
|
||||||
items.first {it.id == id}.starred = true
|
item.starred = true
|
||||||
badgeStarred += 1
|
badgeStarred += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun unstarrLocally(id: Int) {
|
private fun unstarrLocally(item: SelfossModel.Item) {
|
||||||
// TODO: Mark also in the database
|
// TODO: Mark also in the database
|
||||||
if (items.first {it.id == id}.starred) {
|
if (item.starred) {
|
||||||
items.first {it.id == id}.starred = false
|
item.starred = false
|
||||||
badgeStarred -= 1
|
badgeStarred -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user