From 0215b66098ec1fae2c1f9f845345c6bc67cb812d Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 11 Sep 2022 19:11:50 +0200 Subject: [PATCH] Count the downloads under each header instead of count the number of headers (#7990) --- .../eu/kanade/tachiyomi/ui/download/DownloadController.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt index 709291102..ec46f6e63 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt @@ -25,6 +25,7 @@ import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.rememberTopAppBarState import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -106,6 +107,9 @@ class DownloadController : override fun ComposeContent() { val context = LocalContext.current val downloadList by presenter.state.collectAsState() + val downloadCount by remember { + derivedStateOf { downloadList.sumOf { it.subItems.size } } + } val scrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()) var fabExpanded by remember { mutableStateOf(true) } @@ -142,10 +146,10 @@ class DownloadController : modifier = Modifier.weight(1f, false), overflow = TextOverflow.Ellipsis, ) - if (downloadList.isNotEmpty()) { + if (downloadCount > 0) { val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f Pill( - text = "${downloadList.size}", + text = "$downloadCount", modifier = Modifier.padding(start = 4.dp), color = MaterialTheme.colorScheme.onBackground .copy(alpha = pillAlpha),