Handling items with multiple tags.
This commit is contained in:
parent
db89fe5aad
commit
a450ab2a3b
@ -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()
|
||||||
|
@ -43,4 +43,13 @@ fun Item.sourceAndDateText(): String {
|
|||||||
fun Item.toggleStar(): Item {
|
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())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user