Fixed issue with read/unread cont when swiping.

This commit is contained in:
aminecmi 2019-01-13 13:47:46 +01:00
parent 6d7c4b40f6
commit 722b6cc06d
2 changed files with 14 additions and 8 deletions

View File

@ -247,14 +247,18 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
val i = items.elementAtOrNull(position) val i = items.elementAtOrNull(position)
if (i != null) { if (i != null) {
val adapter = recyclerView.adapter val adapter = recyclerView.adapter as ItemsAdapter<*>
when (adapter) { val wasItemUnread = adapter.unreadItemStatusAtIndex(position)
is ItemCardAdapter -> adapter.handleItemAtIndex(position)
is ItemListAdapter -> adapter.handleItemAtIndex(position) adapter.handleItemAtIndex(position)
if (wasItemUnread) {
badgeNew--
} else {
badgeNew++
} }
badgeNew--
reloadBadgeContent() reloadBadgeContent()
val tagHashes = i.tags.tags.split(",").map { it.longHash() } val tagHashes = i.tags.tags.split(",").map { it.longHash() }

View File

@ -132,15 +132,17 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte
} }
fun handleItemAtIndex(position: Int) { fun handleItemAtIndex(position: Int) {
val i = items[position] if (unreadItemStatusAtIndex(position)) {
if (i.unread) {
readItemAtIndex(position) readItemAtIndex(position)
} else { } else {
unreadItemAtIndex(position) unreadItemAtIndex(position)
} }
} }
fun unreadItemStatusAtIndex(position: Int): Boolean {
return items[position].unread
}
private fun readItemAtIndex(position: Int) { private fun readItemAtIndex(position: Int) {
val i = items[position] val i = items[position]
items.remove(i) items.remove(i)