Add pluralStringRes helper for non-composable scope

This commit is contained in:
davotoula
2026-05-08 08:43:13 +02:00
parent 581a18de95
commit e8db6ec6d9
@@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui
import android.content.Context
import android.util.LruCache
import androidx.annotation.DrawableRes
import androidx.annotation.PluralsRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalConfiguration
@@ -131,6 +132,15 @@ fun stringRes(
)
}
// Plural resolver for non-composable scope (e.g. onClick callbacks). Not cached:
// the resolved string varies by `count` quantity and the resourceCache is keyed by id.
fun pluralStringRes(
ctx: Context,
@PluralsRes id: Int,
count: Int,
vararg formatArgs: Any?,
): String = ctx.resources.getQuantityString(id, count, *formatArgs)
/**
* This cache can only be used if the painter is the only copy on the screen
* It should store a separate Painter for each size. It's safe to just assume