Last fixes.
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build was killed

This commit is contained in:
aminecmi 2022-08-16 21:34:29 +02:00
parent 33333ca998
commit 4d29ee0b92
7 changed files with 54 additions and 38 deletions

View File

@ -1074,7 +1074,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) { if (this@HomeActivity.isNetworkAvailable(null, offlineShortcut)) {
CoroutineScope(Dispatchers.Main).launch { CoroutineScope(Dispatchers.Main).launch {
val success = repository.markAllAsRead(items.map { it.id }) val success = repository.markAllAsRead(items)
if (success) { if (success) {
Toast.makeText( Toast.makeText(
this@HomeActivity, this@HomeActivity,
@ -1153,10 +1153,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
actions.forEach { action -> actions.forEach { action ->
when { when {
action.read -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action) action.read -> doAndReportOnFail(repository.markAsReadById(action.articleId.toInt()), action)
action.unread -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action) action.unread -> doAndReportOnFail(repository.unmarkAsReadById(action.articleId.toInt()), action)
action.starred -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action) action.starred -> doAndReportOnFail(repository.starrById(action.articleId.toInt()), action)
action.unstarred -> doAndReportOnFail(repository.markAsRead(action.articleId.toInt()), action) action.unstarred -> doAndReportOnFail(repository.unstarrById(action.articleId.toInt()), action)
} }
} }
} }

View File

@ -112,7 +112,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
private fun readItem(item: SelfossModel.Item) { private fun readItem(item: SelfossModel.Item) {
if (markOnScroll) { if (markOnScroll) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(item.id) repository.markAsRead(item)
// TODO: Handle failure // TODO: Handle failure
} }
} }
@ -207,13 +207,13 @@ class ReaderActivity : AppCompatActivity(), DIAware {
R.id.star -> { R.id.star -> {
if (allItems[binding.pager.currentItem].starred) { if (allItems[binding.pager.currentItem].starred) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unstarr(allItems[binding.pager.currentItem].id) repository.unstarr(allItems[binding.pager.currentItem])
// TODO: Handle failure // TODO: Handle failure
} }
afterUnsave() afterUnsave()
} else { } else {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.starr(allItems[binding.pager.currentItem].id) repository.starr(allItems[binding.pager.currentItem])
// TODO: Handle failure // TODO: Handle failure
} }
afterSave() afterSave()

View File

@ -113,14 +113,14 @@ class ItemCardAdapter(
if (c.isNetworkAvailable()) { if (c.isNetworkAvailable()) {
if (item.starred) { if (item.starred) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unstarr(item.id) repository.unstarr(item)
// TODO: Handle failure // TODO: Handle failure
} }
item.starred = false item.starred = false
binding.favButton.isSelected = false binding.favButton.isSelected = false
} else { } else {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.starr(item.id) repository.starr(item)
// TODO: Handle failure // TODO: Handle failure
} }
item.starred = true item.starred = true

View File

@ -79,7 +79,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) { private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) {
val i = items[position] val i = items[position]
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(i.id) repository.markAsRead(i)
} }
if (repository.displayedItems == ItemType.UNREAD) { if (repository.displayedItems == ItemType.UNREAD) {
items.remove(i) items.remove(i)
@ -95,7 +95,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) { private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unmarkAsRead(items[position].id) repository.unmarkAsRead(items[position])
// Todo: SharedItems.unreadItem(app, api, db, items[position]) // Todo: SharedItems.unreadItem(app, api, db, items[position])
// TODO: update db // TODO: update db

View File

@ -76,19 +76,19 @@ override fun doWork(): Result {
actions.forEach { action -> actions.forEach { action ->
when { when {
action.read -> doAndReportOnFail( action.read -> doAndReportOnFail(
repository.markAsRead(action.articleId.toInt()), repository.markAsReadById(action.articleId.toInt()),
action action
) )
action.unread -> doAndReportOnFail( action.unread -> doAndReportOnFail(
repository.unmarkAsRead(action.articleId.toInt()), repository.unmarkAsReadById(action.articleId.toInt()),
action action
) )
action.starred -> doAndReportOnFail( action.starred -> doAndReportOnFail(
repository.starr(action.articleId.toInt()), repository.starrById(action.articleId.toInt()),
action action
) )
action.unstarred -> doAndReportOnFail( action.unstarred -> doAndReportOnFail(
repository.unstarr(action.articleId.toInt()), repository.unstarrById(action.articleId.toInt()),
action action
) )
} }

View File

@ -169,7 +169,7 @@ class ArticleFragment : Fragment(), DIAware {
R.id.unread_action -> if (context != null) { R.id.unread_action -> if (context != null) {
if (this@ArticleFragment.item.unread) { if (this@ArticleFragment.item.unread) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.markAsRead(this@ArticleFragment.item.id) repository.markAsRead(this@ArticleFragment.item)
} }
this@ArticleFragment.item.unread = false this@ArticleFragment.item.unread = false
Toast.makeText( Toast.makeText(
@ -179,7 +179,7 @@ class ArticleFragment : Fragment(), DIAware {
).show() ).show()
} else { } else {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {
repository.unmarkAsRead(this@ArticleFragment.item.id) repository.unmarkAsRead(this@ArticleFragment.item)
} }
this@ArticleFragment.item.unread = true this@ArticleFragment.item.unread = true
Toast.makeText( Toast.makeText(

View File

@ -121,54 +121,70 @@ class Repository(private val api: SelfossApi, private val apiDetails: ApiDetails
return api.sources() return api.sources()
} }
suspend fun markAsRead(id: Int): Boolean { suspend fun markAsRead(item: SelfossModel.Item): Boolean {
// TODO: Check internet connection // TODO: Check internet connection
val success = api.markAsRead(id.toString())?.isSuccess == true val success = markAsReadById(item.id)
if (success) { if (success) {
markAsReadLocally(items.first {it.id == id}) markAsReadLocally(item)
} }
return success return success
} }
suspend fun unmarkAsRead(id: Int): Boolean { suspend fun markAsReadById(id: Int): Boolean {
// TODO: Check internet connection // TODO: Check internet connection
val success = api.unmarkAsRead(id.toString())?.isSuccess == true return api.markAsRead(id.toString())?.isSuccess == true
}
suspend fun unmarkAsRead(item: SelfossModel.Item): Boolean {
val success = unmarkAsReadById(item.id)
if (success) { if (success) {
unmarkAsReadLocally(items.first {it.id == id}) unmarkAsReadLocally(item)
} }
return success return success
} }
suspend fun starr(id: Int): Boolean { suspend fun unmarkAsReadById(id: Int): Boolean {
// TODO: Check internet connection
return api.unmarkAsRead(id.toString())?.isSuccess == true
}
suspend fun starr(item: SelfossModel.Item): Boolean {
val success = starrById(item.id)
if (success) {
starrLocally(item)
}
return success
}
suspend fun starrById(id: Int): Boolean {
// TODO: Check success, store in DB // TODO: Check success, store in DB
val success = api.starr(id.toString())?.isSuccess == true return api.starr(id.toString())?.isSuccess == true
}
suspend fun unstarr(item: SelfossModel.Item): Boolean {
val success = unstarrById(item.id)
if (success) { if (success) {
starrLocally(items.first {it.id == id}) unstarrLocally(item)
} }
return success return success
} }
suspend fun unstarr(id: Int): Boolean { suspend fun unstarrById(id: Int): Boolean {
// TODO: Check internet connection // TODO: Check internet connection
val success = api.unstarr(id.toString())?.isSuccess == true return api.unstarr(id.toString())?.isSuccess == true
if (success) {
unstarrLocally(items.first {it.id == id})
}
return success
} }
suspend fun markAllAsRead(ids: List<Int>): Boolean { suspend fun markAllAsRead(items: ArrayList<SelfossModel.Item>): Boolean {
// TODO: Check Internet connectivity, store in DB // TODO: Check Internet connectivity, store in DB
val success = api.markAllAsRead(ids.map { it.toString() })?.isSuccess == true val success = api.markAllAsRead(items.map { it.id.toString() })?.isSuccess == true
if (success) { if (success) {
val itemsToMark = items.filter { it.id in ids } for (item in items) {
for (item in itemsToMark) {
markAsReadLocally(item) markAsReadLocally(item)
} }
} }