From a14764674378b2e9e63ccdf8ee70d82af3801b80 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 4 Oct 2022 16:43:21 +0200 Subject: [PATCH 1/2] 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) } } From 1d2e5069b862630bca81c66dd06146bbc04b6307 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Tue, 4 Oct 2022 16:47:13 +0200 Subject: [PATCH 2/2] Avoid double snackbar generation --- .../apps/readerforselfossv2/android/adapters/ItemsAdapter.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6372944..bca124b 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 @@ -55,7 +55,7 @@ abstract class ItemsAdapter : RecyclerView.Adapte Snackbar.LENGTH_LONG ) .setAction(R.string.undo_string) { - readItemAtIndex(item, position) + readItemAtIndex(item, position, false) } val view = s.view