From a450ab2a3be0f6a9b031fcfd4dda75327ef11064 Mon Sep 17 00:00:00 2001 From: Amine Bou Date: Sat, 7 Apr 2018 18:51:39 +0200 Subject: [PATCH] Handling items with multiple tags. --- .../apps/amine/bou/readerforselfoss/HomeActivity.kt | 6 ++++-- .../amine/bou/readerforselfoss/utils/ItemsUtils.kt | 11 ++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) 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 d73dd75..8b21dc1 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/HomeActivity.kt @@ -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.customtabs.CustomTabActivityHelper import apps.amine.bou.readerforselfoss.utils.drawer.CustomUrlPrimaryDrawerItem +import apps.amine.bou.readerforselfoss.utils.flattenTags import apps.amine.bou.readerforselfoss.utils.longHash import co.zsmb.materialdrawerkt.builders.accountHeader import co.zsmb.materialdrawerkt.builders.drawer @@ -225,8 +226,9 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { badgeNew-- reloadBadgeContent() + val tagHashes = i.tags.split(",").map { it.longHash() } tagsBadge = tagsBadge.map { - if (it.key == i.tags.longHash()) { + if (tagHashes.contains(it.key)) { (it.key to (it.value - 1)) } else { (it.key to it.value) @@ -1078,7 +1080,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { swipeRefreshLayout.isRefreshing = false val ids = allItems.map { it.id } val itemsByTag: Map = - allItems + allItems.flattenTags() .groupBy { it.tags.longHash() } .map { it.key to it.value.size } .toMap() diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt index fb6eb03..6b81aca 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/utils/ItemsUtils.kt @@ -43,4 +43,13 @@ fun Item.sourceAndDateText(): String { fun Item.toggleStar(): Item { this.starred = !this.starred return this -} \ No newline at end of file +} + +fun List.flattenTags(): List = + this.flatMap { + val item = it + val tags: List = it.tags.split(",") + tags.map { + item.copy(tags = it.trim()) + } + } \ No newline at end of file