This commit is contained in:
Amine 2017-11-16 19:37:19 +01:00
parent 8e9fd9c985
commit 8fb339034f
2 changed files with 39 additions and 17 deletions

View File

@ -1,3 +1,7 @@
**master**
- Displaying the right number of items.
**1.5.4.12** **1.5.4.12**
- Fixed fab and toolbar issue (#113) - Fixed fab and toolbar issue (#113)

View File

@ -117,6 +117,10 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
private var recyclerViewScrollListener: RecyclerView.OnScrollListener? = null private var recyclerViewScrollListener: RecyclerView.OnScrollListener? = null
private lateinit var settings: SharedPreferences 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) is ItemListAdapter -> adapter.removeItemAtIndex(position)
} }
if (items.size > 0) if (items.size > 0) {
tabNewBadge.setText("${items.size}").maybeShow() badgeNew--
reloadBadgeContent()
}
else else
tabNewBadge.hide() tabNewBadge.hide()
@ -771,26 +777,38 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
api.stats.enqueue(object : Callback<Stats> { api.stats.enqueue(object : Callback<Stats> {
override fun onResponse(call: Call<Stats>, response: Response<Stats>) { override fun onResponse(call: Call<Stats>, response: Response<Stats>) {
if (response.body() != null) { if (response.body() != null) {
if (displayUnreadCount)
tabNewBadge badgeNew = response.body()!!.unread
.setText(response.body()!!.unread.toString()) badgeAll = response.body()!!.total
.maybeShow() badgeFavs = response.body()!!.starred
if (displayAllCount) { reloadBadgeContent()
tabArchiveBadge
.setText(response.body()!!.total.toString())
.maybeShow()
tabStarredBadge
.setText(response.body()!!.starred.toString())
.maybeShow()
} else {
tabArchiveBadge.removeBadge()
tabStarredBadge.removeBadge()
}
} }
} }
override fun onFailure(call: Call<Stats>, t: Throwable) {} override fun onFailure(call: Call<Stats>, 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 { } else {
tabNewBadge.removeBadge() tabNewBadge.removeBadge()
tabArchiveBadge.removeBadge() tabArchiveBadge.removeBadge()