From 8d44ad8866ad156599a5448496a7f8ff0691456f Mon Sep 17 00:00:00 2001 From: Koitharu Date: Tue, 25 Feb 2025 08:53:45 +0200 Subject: [PATCH] Safe way to getQuantityString --- .../kotatsu/alternatives/ui/AlternativeAD.kt | 14 ++++++++++++-- .../koitharu/kotatsu/core/ui/model/DateTimeAgo.kt | 9 +++++---- .../koitharu/kotatsu/core/util/ext/Resources.kt | 9 +++++++++ .../koitharu/kotatsu/core/util/ext/Throwable.kt | 7 ++++--- .../koitharu/kotatsu/details/data/ReadingTime.kt | 9 +++++---- .../koitharu/kotatsu/details/ui/DetailsActivity.kt | 3 ++- .../download/ui/dialog/DownloadDialogFragment.kt | 9 +++++---- .../kotatsu/download/ui/list/DownloadItemAD.kt | 3 ++- .../favourites/ui/categories/adapter/CategoryAD.kt | 5 +++-- .../kotatsu/local/ui/info/LocalInfoDialog.kt | 3 ++- .../kotatsu/settings/DownloadsSettingsFragment.kt | 3 ++- .../kotatsu/settings/RootSettingsFragment.kt | 3 ++- .../settings/sources/SourcesSettingsFragment.kt | 3 ++- .../storage/StorageManageSettingsFragment.kt | 7 ++++--- .../kotatsu/suggestions/ui/SuggestionsWorker.kt | 3 ++- .../kotatsu/tracker/ui/feed/adapter/FeedItemAD.kt | 3 ++- .../tracker/work/TrackerNotificationHelper.kt | 6 +++--- 17 files changed, 66 insertions(+), 33 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativeAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativeAD.kt index 9af518747..3575ded7b 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativeAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/alternatives/ui/AlternativeAD.kt @@ -27,6 +27,7 @@ import org.koitharu.kotatsu.core.ui.list.AdapterDelegateClickListenerAdapter import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.defaultPlaceholders import org.koitharu.kotatsu.core.util.ext.enqueueWith +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaExtra import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.newImageRequest @@ -61,7 +62,13 @@ fun alternativeAD( } binding.textViewSubtitle.text = buildSpannedString { if (item.chaptersCount > 0) { - append(context.resources.getQuantityString(R.plurals.chapters, item.chaptersCount, item.chaptersCount)) + append( + context.resources.getQuantityStringSafe( + R.plurals.chapters, + item.chaptersCount, + item.chaptersCount, + ), + ) } else { append(context.getString(R.string.no_chapters)) } @@ -77,7 +84,10 @@ fun alternativeAD( } } } - binding.progressView.setProgress(item.mangaModel.progress, ListModelDiffCallback.PAYLOAD_PROGRESS_CHANGED in payloads) + binding.progressView.setProgress( + item.mangaModel.progress, + ListModelDiffCallback.PAYLOAD_PROGRESS_CHANGED in payloads, + ) binding.chipSource.also { chip -> chip.text = item.manga.source.getTitle(chip.context) ImageRequest.Builder(context) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt index 285a6ce0a..263621a5c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/model/DateTimeAgo.kt @@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.ui.model import android.content.Context import android.text.format.DateUtils import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.toMillis import java.time.LocalDate @@ -22,7 +23,7 @@ sealed class DateTimeAgo { data class MinutesAgo(val minutes: Int) : DateTimeAgo() { override fun format(context: Context): String { - return context.resources.getQuantityString( + return context.resources.getQuantityStringSafe( R.plurals.minutes_ago, minutes, minutes, @@ -34,7 +35,7 @@ sealed class DateTimeAgo { data class HoursAgo(val hours: Int) : DateTimeAgo() { override fun format(context: Context): String { - return context.resources.getQuantityString( + return context.resources.getQuantityStringSafe( R.plurals.hours_ago, hours, hours, @@ -66,7 +67,7 @@ sealed class DateTimeAgo { data class DaysAgo(val days: Int) : DateTimeAgo() { override fun format(context: Context): String { - return context.resources.getQuantityString(R.plurals.days_ago, days, days) + return context.resources.getQuantityStringSafe(R.plurals.days_ago, days, days) } override fun toString() = "days_ago_$days" @@ -77,7 +78,7 @@ sealed class DateTimeAgo { return if (months == 0) { context.getString(R.string.this_month) } else { - context.resources.getQuantityString( + context.resources.getQuantityStringSafe( R.plurals.months_ago, months, months, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Resources.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Resources.kt index 4cfa36ecf..c62c597cb 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Resources.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Resources.kt @@ -3,6 +3,7 @@ package org.koitharu.kotatsu.core.util.ext import android.annotation.SuppressLint import android.content.Context import android.content.res.Resources +import androidx.annotation.PluralsRes import androidx.annotation.Px import androidx.core.util.TypedValueCompat import kotlin.math.roundToInt @@ -25,3 +26,11 @@ fun Context.getSystemBoolean(resName: String, fallback: Boolean): Boolean { fallback } } + +fun Resources.getQuantityStringSafe(@PluralsRes resId: Int, quantity: Int, vararg formatArgs: Any): String = try { + getQuantityString(resId, quantity, *formatArgs) +} catch (e: Resources.NotFoundException) { + e.report(silent = true) + e.printStackTraceDebug() + formatArgs.firstOrNull()?.toString() ?: quantity.toString() +} diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt index 3e518cde0..719ac2135 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/Throwable.kt @@ -12,6 +12,7 @@ import okio.ProtocolException import org.acra.ktx.sendSilentlyWithAcra import org.acra.ktx.sendWithAcra import org.jsoup.HttpStatusException +import org.koitharu.kotatsu.BuildConfig import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.exceptions.BadBackupFormatException import org.koitharu.kotatsu.core.exceptions.CaughtException @@ -207,10 +208,10 @@ fun Throwable.isNetworkError(): Boolean { fun Throwable.report(silent: Boolean = false) { val exception = CaughtException(this) - if (silent) { - exception.sendSilentlyWithAcra() - } else { + if (!silent) { exception.sendWithAcra() + } else if (!BuildConfig.DEBUG) { + exception.sendSilentlyWithAcra() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/data/ReadingTime.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/data/ReadingTime.kt index aa9c48bf4..bcc56c06d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/data/ReadingTime.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/data/ReadingTime.kt @@ -2,6 +2,7 @@ package org.koitharu.kotatsu.details.data import android.content.res.Resources import org.koitharu.kotatsu.R +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe data class ReadingTime( val minutes: Int, @@ -11,12 +12,12 @@ data class ReadingTime( fun format(resources: Resources): String = when { hours == 0 && minutes == 0 -> resources.getString(R.string.less_than_minute) - hours == 0 -> resources.getQuantityString(R.plurals.minutes, minutes, minutes) - minutes == 0 -> resources.getQuantityString(R.plurals.hours, hours, hours) + hours == 0 -> resources.getQuantityStringSafe(R.plurals.minutes, minutes, minutes) + minutes == 0 -> resources.getQuantityStringSafe(R.plurals.hours, hours, hours) else -> resources.getString( R.string.remaining_time_pattern, - resources.getQuantityString(R.plurals.hours, hours, hours), - resources.getQuantityString(R.plurals.minutes, minutes, minutes), + resources.getQuantityStringSafe(R.plurals.hours, hours, hours), + resources.getQuantityStringSafe(R.plurals.minutes, minutes, minutes), ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 3cc077011..8c3eff8d1 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -73,6 +73,7 @@ import org.koitharu.kotatsu.core.util.ext.defaultPlaceholders import org.koitharu.kotatsu.core.util.ext.drawable import org.koitharu.kotatsu.core.util.ext.drawableStart import org.koitharu.kotatsu.core.util.ext.enqueueWith +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.isTextTruncated import org.koitharu.kotatsu.core.util.ext.joinToStringWithLimit import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra @@ -477,7 +478,7 @@ class DetailsActivity : info.totalChapters == 0 -> getString(R.string.no_chapters) info.totalChapters == -1 -> getString(R.string.error_occurred) - else -> resources.getQuantityString(R.plurals.chapters, info.totalChapters, info.totalChapters) + else -> resources.getQuantityStringSafe(R.plurals.chapters, info.totalChapters, info.totalChapters) .withEstimatedTime(info.estimatedTime) } textViewProgress.textAndVisible = if (info.percent <= 0f) { diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/dialog/DownloadDialogFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/dialog/DownloadDialogFragment.kt index 51d435bcd..3a4762f63 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/dialog/DownloadDialogFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/dialog/DownloadDialogFragment.kt @@ -24,6 +24,7 @@ import org.koitharu.kotatsu.core.ui.AlertDialogFragment import org.koitharu.kotatsu.core.ui.widgets.TwoLinesItemView import org.koitharu.kotatsu.core.util.ext.findActivity import org.koitharu.kotatsu.core.util.ext.getDisplayMessage +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.joinToStringWithLimit import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent @@ -169,7 +170,7 @@ class DownloadDialogFragment : AlertDialogFragment(), Vie with(viewBinding ?: return) { // Whole manga optionWholeManga.subtitle = if (options.wholeManga.chaptersCount > 0) { - resources.getQuantityString( + resources.getQuantityStringSafe( R.plurals.chapters, options.wholeManga.chaptersCount, options.wholeManga.chaptersCount, @@ -185,7 +186,7 @@ class DownloadDialogFragment : AlertDialogFragment(), Vie it.selectedBranch, ) optionWholeBranch.subtitle = if (it.chaptersCount > 0) { - resources.getQuantityString( + resources.getQuantityStringSafe( R.plurals.chapters, it.chaptersCount, it.chaptersCount, @@ -199,7 +200,7 @@ class DownloadDialogFragment : AlertDialogFragment(), Vie options.firstChapters?.let { optionFirstChapters.title = resources.getString( R.string.download_option_first_n_chapters, - resources.getQuantityString( + resources.getQuantityStringSafe( R.plurals.chapters, it.chaptersCount, it.chaptersCount, @@ -215,7 +216,7 @@ class DownloadDialogFragment : AlertDialogFragment(), Vie } else { resources.getString( R.string.download_option_next_unread_n_chapters, - resources.getQuantityString( + resources.getQuantityStringSafe( R.plurals.chapters, it.chaptersCount, it.chaptersCount, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadItemAD.kt index 0b3175086..549289096 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/list/DownloadItemAD.kt @@ -21,6 +21,7 @@ import org.koitharu.kotatsu.core.ui.BaseListAdapter import org.koitharu.kotatsu.core.ui.image.TrimTransformation import org.koitharu.kotatsu.core.util.ext.defaultPlaceholders import org.koitharu.kotatsu.core.util.ext.enqueueWith +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.newImageRequest import org.koitharu.kotatsu.core.util.ext.textAndVisible @@ -161,7 +162,7 @@ fun downloadItemAD( binding.progressBar.isEnabled = true binding.textViewPercent.isVisible = false if (item.chaptersDownloaded > 0) { - binding.textViewDetails.text = context.resources.getQuantityString( + binding.textViewDetails.text = context.resources.getQuantityStringSafe( R.plurals.chapters, item.chaptersDownloaded, item.chaptersDownloaded, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt index ea4e032dd..96a86abb0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/ui/categories/adapter/CategoryAD.kt @@ -24,6 +24,7 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.util.ext.enqueueWith import org.koitharu.kotatsu.core.util.ext.getAnimationDuration +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.getThemeColor import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.newImageRequest @@ -79,7 +80,7 @@ fun categoryAD( binding.textViewSubtitle.text = if (item.mangaCount == 0) { getString(R.string.empty) } else { - context.resources.getQuantityString( + context.resources.getQuantityStringSafe( R.plurals.items, item.mangaCount, item.mangaCount, @@ -139,7 +140,7 @@ fun allCategoriesAD( binding.textViewSubtitle.text = if (item.mangaCount == 0) { getString(R.string.empty) } else { - context.resources.getQuantityString( + context.resources.getQuantityStringSafe( R.plurals.items, item.mangaCount, item.mangaCount, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/info/LocalInfoDialog.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/info/LocalInfoDialog.kt index 9569350a8..126913b7d 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/info/LocalInfoDialog.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/ui/info/LocalInfoDialog.kt @@ -16,6 +16,7 @@ import org.koitharu.kotatsu.core.ui.AlertDialogFragment import org.koitharu.kotatsu.core.ui.widgets.SegmentedBarView import org.koitharu.kotatsu.core.util.FileSize import org.koitharu.kotatsu.core.util.KotatsuColors +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.core.util.ext.setProgressIcon @@ -73,7 +74,7 @@ class LocalInfoDialog : AlertDialogFragment(), View.OnCl } else { c.getString( R.string.chapters_deleted_pattern, - c.resources.getQuantityString(R.plurals.chapters, result.first, result.first), + c.resources.getQuantityStringSafe(R.plurals.chapters, result.first, result.first), FileSize.BYTES.format(c, result.second), ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/DownloadsSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/DownloadsSettingsFragment.kt index 1afb711b7..c2d17832c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/DownloadsSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/DownloadsSettingsFragment.kt @@ -20,6 +20,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.prefs.DownloadFormat import org.koitharu.kotatsu.core.prefs.TriStateOption import org.koitharu.kotatsu.core.ui.BasePreferenceFragment +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.resolveFile import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat @@ -145,7 +146,7 @@ class DownloadsSettingsFragment : private fun Preference.bindDirectoriesCount() { viewLifecycleScope.launch { val dirs = storageManager.getReadableDirs().size - summary = resources.getQuantityString(R.plurals.items, dirs, dirs) + summary = resources.getQuantityStringSafe(R.plurals.items, dirs, dirs) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/RootSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/RootSettingsFragment.kt index eef3efd0c..1fd9f1449 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/RootSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/RootSettingsFragment.kt @@ -12,6 +12,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.ui.BasePreferenceFragment import org.koitharu.kotatsu.core.util.ext.addMenuProvider +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.settings.search.SettingsSearchMenuProvider import org.koitharu.kotatsu.settings.search.SettingsSearchViewModel @@ -42,7 +43,7 @@ class RootSettingsFragment : BasePreferenceFragment(0) { pref.summary = if (it >= 0) { getString(R.string.enabled_d_of_d, it, total) } else { - resources.getQuantityString(R.plurals.items, total, total) + resources.getQuantityStringSafe(R.plurals.items, total, total) } } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsFragment.kt index 66d91e725..f59ca7015 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/sources/SourcesSettingsFragment.kt @@ -12,6 +12,7 @@ import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.nav.router import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.ui.BasePreferenceFragment +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.setDefaultValueCompat import org.koitharu.kotatsu.explore.data.SourcesSortOrder @@ -37,7 +38,7 @@ class SourcesSettingsFragment : BasePreferenceFragment(R.string.remote_sources), findPreference(AppSettings.KEY_REMOTE_SOURCES)?.let { pref -> viewModel.enabledSourcesCount.observe(viewLifecycleOwner) { pref.summary = if (it >= 0) { - resources.getQuantityString(R.plurals.items, it, it) + resources.getQuantityStringSafe(R.plurals.items, it, it) } else { null } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/settings/userdata/storage/StorageManageSettingsFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/settings/userdata/storage/StorageManageSettingsFragment.kt index d4dac487d..59b30d50a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/settings/userdata/storage/StorageManageSettingsFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/settings/userdata/storage/StorageManageSettingsFragment.kt @@ -14,6 +14,7 @@ import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.ui.BasePreferenceFragment import org.koitharu.kotatsu.core.ui.util.ReversibleActionObserver import org.koitharu.kotatsu.core.util.FileSize +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.observe import org.koitharu.kotatsu.core.util.ext.observeEvent import org.koitharu.kotatsu.local.data.CacheDir @@ -38,7 +39,7 @@ class StorageManageSettingsFragment : BasePreferenceFragment(R.string.storage_us pref.summary = if (it < 0) { view.context.getString(R.string.loading_) } else { - pref.context.resources.getQuantityString(R.plurals.items, it, it) + pref.context.resources.getQuantityStringSafe(R.plurals.items, it, it) } } } @@ -47,7 +48,7 @@ class StorageManageSettingsFragment : BasePreferenceFragment(R.string.storage_us pref.summary = if (it < 0) { view.context.getString(R.string.loading_) } else { - pref.context.resources.getQuantityString(R.plurals.items, it, it) + pref.context.resources.getQuantityStringSafe(R.plurals.items, it, it) } } } @@ -118,7 +119,7 @@ class StorageManageSettingsFragment : BasePreferenceFragment(R.string.storage_us } else { c.getString( R.string.chapters_deleted_pattern, - c.resources.getQuantityString(R.plurals.chapters, result.first, result.first), + c.resources.getQuantityStringSafe(R.plurals.chapters, result.first, result.first), FileSize.BYTES.format(c, result.second), ) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt index 7f55dddcd..199c17735 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/suggestions/ui/SuggestionsWorker.kt @@ -58,6 +58,7 @@ import org.koitharu.kotatsu.core.util.ext.awaitUniqueWorkInfoByName import org.koitharu.kotatsu.core.util.ext.awaitWorkInfosByTag import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission import org.koitharu.kotatsu.core.util.ext.flatten +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.printStackTraceDebug import org.koitharu.kotatsu.core.util.ext.sanitize @@ -311,7 +312,7 @@ class SuggestionsWorker @AssistedInject constructor( appendLine() bold { append( - applicationContext.resources.getQuantityString( + applicationContext.resources.getQuantityStringSafe( R.plurals.chapters, chaptersCount, chaptersCount, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/adapter/FeedItemAD.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/adapter/FeedItemAD.kt index 0f67d0f1f..75b71b11a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/adapter/FeedItemAD.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/adapter/FeedItemAD.kt @@ -10,6 +10,7 @@ import org.koitharu.kotatsu.core.ui.list.OnListItemClickListener import org.koitharu.kotatsu.core.util.ext.defaultPlaceholders import org.koitharu.kotatsu.core.util.ext.drawableStart import org.koitharu.kotatsu.core.util.ext.enqueueWith +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.newImageRequest import org.koitharu.kotatsu.databinding.ItemFeedBinding @@ -37,7 +38,7 @@ fun feedItemAD( enqueueWith(coil) } binding.textViewTitle.text = item.title - binding.textViewSummary.text = context.resources.getQuantityString( + binding.textViewSummary.text = context.resources.getQuantityStringSafe( R.plurals.new_chapters, item.count, item.count, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt index f2f166b45..8fe22a445 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/work/TrackerNotificationHelper.kt @@ -14,12 +14,12 @@ import androidx.core.app.PendingIntentCompat import androidx.core.content.ContextCompat import coil3.ImageLoader import coil3.request.ImageRequest -import dagger.hilt.android.qualifiers.ApplicationContext import org.koitharu.kotatsu.R import org.koitharu.kotatsu.core.LocalizedAppContext import org.koitharu.kotatsu.core.nav.AppRouter import org.koitharu.kotatsu.core.prefs.AppSettings import org.koitharu.kotatsu.core.util.ext.checkNotificationPermission +import org.koitharu.kotatsu.core.util.ext.getQuantityStringSafe import org.koitharu.kotatsu.core.util.ext.mangaSourceExtra import org.koitharu.kotatsu.core.util.ext.toBitmapOrNull import org.koitharu.kotatsu.parsers.model.Manga @@ -55,7 +55,7 @@ class TrackerNotificationHelper @Inject constructor( } val id = manga.url.hashCode() val builder = NotificationCompat.Builder(applicationContext, CHANNEL_ID) - val summary = applicationContext.resources.getQuantityString( + val summary = applicationContext.resources.getQuantityStringSafe( R.plurals.new_chapters, newChapters.size, newChapters.size, @@ -107,7 +107,7 @@ class TrackerNotificationHelper @Inject constructor( val newChaptersCount = notifications.sumOf { it.newChapters } val builder = NotificationCompat.Builder(applicationContext, CHANNEL_ID) with(builder) { - val title = applicationContext.resources.getQuantityString( + val title = applicationContext.resources.getQuantityStringSafe( R.plurals.new_chapters, newChaptersCount, newChaptersCount,