From a14764674378b2e9e63ccdf8ee70d82af3801b80 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 4 Oct 2022 16:43:21 +0200 Subject: [PATCH] Correct mechanism of mark and unmark snackbars --- .../android/adapters/ItemsAdapter.kt | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt index b310bd0..6372944 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemsAdapter.kt @@ -28,7 +28,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte updateItems(this.items) } - private fun unmarkSnackbar(position: Int) { + private fun unmarkSnackbar(item: SelfossModel.Item, position: Int) { val s = Snackbar .make( app.findViewById(R.id.coordLayout), @@ -37,7 +37,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte ) .setAction(R.string.undo_string) { CoroutineScope(Dispatchers.IO).launch { - unreadItemAtIndex(position, false) + unreadItemAtIndex(item, position, false) } } @@ -47,7 +47,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte s.show() } - private fun markSnackbar(position: Int) { + private fun markSnackbar(item: SelfossModel.Item, position: Int) { val s = Snackbar .make( app.findViewById(R.id.coordLayout), @@ -55,7 +55,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte Snackbar.LENGTH_LONG ) .setAction(R.string.undo_string) { - readItemAtIndex(position) + readItemAtIndex(item, position) } val view = s.view @@ -66,37 +66,36 @@ abstract class ItemsAdapter : RecyclerView.Adapte fun handleItemAtIndex(position: Int) { if (items[position].unread) { - readItemAtIndex(position) + readItemAtIndex(items[position], position) } else { - unreadItemAtIndex(position) + unreadItemAtIndex(items[position], position) } } - private fun readItemAtIndex(position: Int, showSnackbar: Boolean = true) { - val i = items[position] + private fun readItemAtIndex(item: SelfossModel.Item, position: Int, showSnackbar: Boolean = true) { CoroutineScope(Dispatchers.IO).launch { - repository.markAsRead(i) + repository.markAsRead(item) } if (repository.displayedItems == ItemType.UNREAD) { - items.remove(i) + items.remove(item) notifyItemRemoved(position) updateItems(items) } else { notifyItemChanged(position) } if (showSnackbar) { - unmarkSnackbar(position) + unmarkSnackbar(item, position) } } - private fun unreadItemAtIndex(position: Int, showSnackbar: Boolean = true) { + private fun unreadItemAtIndex(item: SelfossModel.Item, position: Int, showSnackbar: Boolean = true) { CoroutineScope(Dispatchers.IO).launch { - repository.unmarkAsRead(items[position]) + repository.unmarkAsRead(item) } notifyItemChanged(position) if (showSnackbar) { - markSnackbar(position) + markSnackbar(item, position) } }