mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat(widget): Add Local Stats glance widget (#4642)
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
parent
692ad78c80
commit
9970d31520
23 changed files with 1256 additions and 24 deletions
|
|
@ -18,23 +18,36 @@ package org.meshtastic.core.resources
|
|||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.jetbrains.compose.resources.StringResource
|
||||
import org.jetbrains.compose.resources.getString
|
||||
import org.jetbrains.compose.resources.getString as composeGetString
|
||||
|
||||
/** Retrieves a string from the [StringResource] in a blocking manner. Use primarily in non-composable code. */
|
||||
fun getString(stringResource: StringResource): String = runBlocking {
|
||||
org.jetbrains.compose.resources.getString(stringResource)
|
||||
}
|
||||
fun getString(stringResource: StringResource): String = runBlocking { composeGetString(stringResource) }
|
||||
|
||||
/** Retrieves a formatted string from the [StringResource] in a blocking manner. */
|
||||
fun getString(stringResource: StringResource, vararg formatArgs: Any): String = runBlocking {
|
||||
val resolvedArgs =
|
||||
formatArgs.map { arg ->
|
||||
if (arg is StringResource) {
|
||||
getString(arg)
|
||||
} else {
|
||||
arg
|
||||
}
|
||||
}
|
||||
@Suppress("SpreadOperator")
|
||||
org.jetbrains.compose.resources.getString(stringResource, *resolvedArgs.toTypedArray())
|
||||
getStringSuspend(stringResource, *formatArgs)
|
||||
}
|
||||
|
||||
/** Retrieves a string from the [StringResource] in a suspending manner. */
|
||||
suspend fun getStringSuspend(stringResource: StringResource): String = composeGetString(stringResource)
|
||||
|
||||
/** Retrieves a formatted string from the [StringResource] in a suspending manner. */
|
||||
suspend fun getStringSuspend(stringResource: StringResource, vararg formatArgs: Any): String {
|
||||
val resolvedArgs =
|
||||
formatArgs
|
||||
.map { arg ->
|
||||
if (arg is StringResource) {
|
||||
// Resolve nested StringResources recursively
|
||||
getStringSuspend(arg)
|
||||
} else {
|
||||
arg
|
||||
}
|
||||
}
|
||||
.toTypedArray()
|
||||
|
||||
// Compose Multiplatform doesn't fully support complex formatting like %.2f
|
||||
// Fetch the raw string and format it using standard Java String.format.
|
||||
val rawString = composeGetString(stringResource)
|
||||
@Suppress("SpreadOperator")
|
||||
return String.format(java.util.Locale.getDefault(), rawString, *resolvedArgs)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue