From 8fb339034f3f7c54ce96ea5f5277175dd95237e4 Mon Sep 17 00:00:00 2001 From: Amine Date: Thu, 16 Nov 2017 19:37:19 +0100 Subject: [PATCH] Fixed #117. --- CHANGELOG.md | 4 ++ .../bou/readerforselfoss/HomeActivity.kt | 52 +++++++++++++------ 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dce4af..43b0a43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +**master** + +- Displaying the right number of items. + **1.5.4.12** - Fixed fab and toolbar issue (#113) diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt index eb90a91..42a46af 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -117,6 +117,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { private var recyclerViewScrollListener: RecyclerView.OnScrollListener? = null private lateinit var settings: SharedPreferences + private var badgeNew: Int = -1 + private var badgeAll: Int = -1 + private var badgeFavs: Int = -1 + @@ -190,8 +194,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { is ItemListAdapter -> adapter.removeItemAtIndex(position) } - if (items.size > 0) - tabNewBadge.setText("${items.size}").maybeShow() + if (items.size > 0) { + badgeNew-- + reloadBadgeContent() + } else tabNewBadge.hide() @@ -771,26 +777,38 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { api.stats.enqueue(object : Callback { override fun onResponse(call: Call, response: Response) { if (response.body() != null) { - if (displayUnreadCount) - tabNewBadge - .setText(response.body()!!.unread.toString()) - .maybeShow() - if (displayAllCount) { - tabArchiveBadge - .setText(response.body()!!.total.toString()) - .maybeShow() - tabStarredBadge - .setText(response.body()!!.starred.toString()) - .maybeShow() - } else { - tabArchiveBadge.removeBadge() - tabStarredBadge.removeBadge() - } + + badgeNew = response.body()!!.unread + badgeAll = response.body()!!.total + badgeFavs = response.body()!!.starred + reloadBadgeContent() } } override fun onFailure(call: Call, t: Throwable) {} }) + } else { + reloadBadgeContent(succeeded = false) + } + } + + private fun reloadBadgeContent(succeeded: Boolean = true) { + if (succeeded) { + if (displayUnreadCount) + tabNewBadge + .setText(badgeNew.toString()) + .maybeShow() + if (displayAllCount) { + tabArchiveBadge + .setText(badgeAll.toString()) + .maybeShow() + tabStarredBadge + .setText(badgeFavs.toString()) + .maybeShow() + } else { + tabArchiveBadge.removeBadge() + tabStarredBadge.removeBadge() + } } else { tabNewBadge.removeBadge() tabArchiveBadge.removeBadge()