Handling items with multiple tags.

This commit is contained in:
Amine Bou 2018-04-07 18:51:39 +02:00
parent db89fe5aad
commit a450ab2a3b
2 changed files with 14 additions and 3 deletions

View File

@ -39,6 +39,7 @@ import apps.amine.bou.readerforselfoss.utils.bottombar.removeBadge
import apps.amine.bou.readerforselfoss.utils.checkApkVersion import apps.amine.bou.readerforselfoss.utils.checkApkVersion
import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper
import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem
import apps.amine.bou.readerforselfoss.utils.flattenTags
import apps.amine.bou.readerforselfoss.utils.longHash import apps.amine.bou.readerforselfoss.utils.longHash
import co.zsmb.materialdrawerkt.builders.accountHeader import co.zsmb.materialdrawerkt.builders.accountHeader
import co.zsmb.materialdrawerkt.builders.drawer import co.zsmb.materialdrawerkt.builders.drawer
@ -225,8 +226,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
badgeNew-- badgeNew--
reloadBadgeContent() reloadBadgeContent()
val tagHashes = i.tags.split(",").map { it.longHash() }
tagsBadge = tagsBadge.map { tagsBadge = tagsBadge.map {
if (it.key == i.tags.longHash()) { if (tagHashes.contains(it.key)) {
(it.key to (it.value - 1)) (it.key to (it.value - 1))
} else { } else {
(it.key to it.value) (it.key to it.value)
@ -1078,7 +1080,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false
val ids = allItems.map { it.id } val ids = allItems.map { it.id }
val itemsByTag: Map<Long, Int> = val itemsByTag: Map<Long, Int> =
allItems allItems.flattenTags()
.groupBy { it.tags.longHash() } .groupBy { it.tags.longHash() }
.map { it.key to it.value.size } .map { it.key to it.value.size }
.toMap() .toMap()

View File

@ -44,3 +44,12 @@ fun Item.toggleStar(): Item {
this.starred = !this.starred this.starred = !this.starred
return this return this
} }
fun List<Item>.flattenTags(): List<Item> =
this.flatMap {
val item = it
val tags: List<String> = it.tags.split(",")
tags.map {
item.copy(tags = it.trim())
}
}