Refactor functions
This commit is contained in:
parent
49abc081b6
commit
8949f78177
@ -178,13 +178,9 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun markAsReadById(id: Int): Boolean {
|
suspend fun markAsReadById(id: Int): Boolean =
|
||||||
var success = false
|
isNetworkAvailable() && api.markAsRead(id.toString())?.isSuccess == true
|
||||||
if (isNetworkAvailable()) {
|
|
||||||
success = api.markAsRead(id.toString())?.isSuccess == true
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun unmarkAsRead(item: SelfossModel.Item): Boolean {
|
suspend fun unmarkAsRead(item: SelfossModel.Item): Boolean {
|
||||||
val success = unmarkAsReadById(item.id)
|
val success = unmarkAsReadById(item.id)
|
||||||
@ -195,13 +191,8 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unmarkAsReadById(id: Int): Boolean {
|
suspend fun unmarkAsReadById(id: Int): Boolean =
|
||||||
var success = false
|
isNetworkAvailable() && api.unmarkAsRead(id.toString())?.isSuccess == true
|
||||||
if (isNetworkAvailable()) {
|
|
||||||
success = api.unmarkAsRead(id.toString())?.isSuccess == true
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun starr(item: SelfossModel.Item): Boolean {
|
suspend fun starr(item: SelfossModel.Item): Boolean {
|
||||||
val success = starrById(item.id)
|
val success = starrById(item.id)
|
||||||
@ -212,13 +203,8 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun starrById(id: Int): Boolean {
|
suspend fun starrById(id: Int): Boolean =
|
||||||
var success = false
|
isNetworkAvailable() && api.starr(id.toString())?.isSuccess == true
|
||||||
if (isNetworkAvailable()) {
|
|
||||||
success = api.starr(id.toString())?.isSuccess == true
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun unstarr(item: SelfossModel.Item): Boolean {
|
suspend fun unstarr(item: SelfossModel.Item): Boolean {
|
||||||
val success = unstarrById(item.id)
|
val success = unstarrById(item.id)
|
||||||
@ -229,22 +215,15 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun unstarrById(id: Int): Boolean {
|
suspend fun unstarrById(id: Int): Boolean =
|
||||||
var success = false
|
isNetworkAvailable() && api.unstarr(id.toString())?.isSuccess == true
|
||||||
if (isNetworkAvailable()) {
|
|
||||||
success = api.unstarr(id.toString())?.isSuccess == true
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
|
||||||
var success = false
|
var success = false
|
||||||
if (isNetworkAvailable()) {
|
|
||||||
success = api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
if (isNetworkAvailable() && api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true) {
|
||||||
|
success = true
|
||||||
for (item in items) {
|
for (item in items) {
|
||||||
markAsReadLocally(item)
|
markAsReadLocally(item)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user