From 02b3718aa1b998079b5da53fe3535ec02fcfdc2d Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 14 Oct 2022 09:21:19 +0700 Subject: [PATCH] Use Compose's existing method to get plural string (#8194) --- .../manga/components/ChapterHeader.kt | 4 +-- .../manga/components/MangaInfoHeader.kt | 4 +-- .../eu/kanade/presentation/more/MoreScreen.kt | 10 +++--- .../eu/kanade/presentation/util/Resources.kt | 31 ------------------- 4 files changed, 9 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/ChapterHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/ChapterHeader.kt index 6ff00e35c..92d141958 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/ChapterHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/ChapterHeader.kt @@ -14,9 +14,9 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import eu.kanade.presentation.util.quantityStringResource import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.getResourceColor @@ -37,7 +37,7 @@ fun ChapterHeader( text = if (chapterCount == null) { stringResource(R.string.chapters) } else { - quantityStringResource(id = R.plurals.manga_num_chapters, quantity = chapterCount) + pluralStringResource(id = R.plurals.manga_num_chapters, count = chapterCount, chapterCount) }, style = MaterialTheme.typography.titleMedium, modifier = Modifier.weight(1f), diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index 1c90273bf..9357d6c27 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -63,6 +63,7 @@ import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.SubcomposeLayout import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow @@ -76,7 +77,6 @@ import eu.kanade.domain.manga.model.Manga import eu.kanade.presentation.components.MangaCover import eu.kanade.presentation.components.TextButton import eu.kanade.presentation.util.clickableNoIndication -import eu.kanade.presentation.util.quantityStringResource import eu.kanade.presentation.util.secondaryItemAlpha import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.source.model.SManga @@ -184,7 +184,7 @@ fun MangaActionRow( title = if (trackingCount == 0) { stringResource(R.string.manga_tracking_tab) } else { - quantityStringResource(id = R.plurals.num_trackers, quantity = trackingCount, trackingCount) + pluralStringResource(id = R.plurals.num_trackers, count = trackingCount, trackingCount) }, icon = if (trackingCount == 0) Icons.Default.Sync else Icons.Default.Done, color = if (trackingCount == 0) defaultActionButtonColor else MaterialTheme.colorScheme.primary, diff --git a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt index edb7ccbc0..b2ba82016 100644 --- a/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/MoreScreen.kt @@ -16,13 +16,13 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.vector.rememberVectorPainter import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.pluralStringResource import androidx.compose.ui.res.stringResource import eu.kanade.presentation.components.AppStateBanners import eu.kanade.presentation.components.Divider import eu.kanade.presentation.components.PreferenceRow import eu.kanade.presentation.components.ScrollbarLazyColumn import eu.kanade.presentation.components.SwitchPreference -import eu.kanade.presentation.util.quantityStringResource import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.more.DownloadQueueState import eu.kanade.tachiyomi.ui.more.MoreController @@ -86,9 +86,9 @@ fun MoreScreen( stringResource(R.string.paused) } else { "${stringResource(R.string.paused)} • ${ - quantityStringResource( - R.plurals.download_queue_summary, - pending, + pluralStringResource( + id = R.plurals.download_queue_summary, + count = pending, pending, ) }" @@ -96,7 +96,7 @@ fun MoreScreen( } is DownloadQueueState.Downloading -> { val pending = (downloadQueueState as DownloadQueueState.Downloading).pending - quantityStringResource(R.plurals.download_queue_summary, pending, pending) + pluralStringResource(id = R.plurals.download_queue_summary, count = pending, pending) } }, painter = rememberVectorPainter(Icons.Outlined.GetApp), diff --git a/app/src/main/java/eu/kanade/presentation/util/Resources.kt b/app/src/main/java/eu/kanade/presentation/util/Resources.kt index 6f3f11a39..44d9968b9 100644 --- a/app/src/main/java/eu/kanade/presentation/util/Resources.kt +++ b/app/src/main/java/eu/kanade/presentation/util/Resources.kt @@ -2,9 +2,7 @@ package eu.kanade.presentation.util import android.content.res.Resources import androidx.annotation.DrawableRes -import androidx.annotation.PluralsRes import androidx.compose.runtime.Composable -import androidx.compose.runtime.ReadOnlyComposable import androidx.compose.runtime.remember import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter @@ -12,35 +10,6 @@ import androidx.compose.ui.platform.LocalContext import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.toBitmap -/** - * Load a quantity string resource. - * - * @param id the resource identifier - * @param quantity The number used to get the string for the current language's plural rules. - * @return the string data associated with the resource - */ -@Composable -@ReadOnlyComposable -fun quantityStringResource(@PluralsRes id: Int, quantity: Int): String { - val context = LocalContext.current - return context.resources.getQuantityString(id, quantity, quantity) -} - -/** - * Load a quantity string resource with formatting. - * - * @param id the resource identifier - * @param quantity The number used to get the string for the current language's plural rules. - * @param formatArgs the format arguments - * @return the string data associated with the resource - */ -@Composable -@ReadOnlyComposable -fun quantityStringResource(@PluralsRes id: Int, quantity: Int, vararg formatArgs: Any): String { - val context = LocalContext.current - return context.resources.getQuantityString(id, quantity, *formatArgs) -} - /** * Create a BitmapPainter from an drawable resource. *