fix: Ollama pct parsing use Float then Int for decimal percentages
toIntOrNull() returns null for 35.1, causing 0% display. toFloatOrNull()?.toInt() handles decimal percentages correctly.
This commit is contained in:
parent
2926e8ebb2
commit
65e4dc5a2f
@ -438,7 +438,7 @@ private fun OllamaUsageCard(state: State) {
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
UsageWindowRow(
|
||||
label = "5 小时",
|
||||
pct = extras["session.pct"]?.toIntOrNull(),
|
||||
pct = extras["session.pct"]?.toFloatOrNull()?.toInt(),
|
||||
resetInSec = extras["session.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 }
|
||||
)
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
@ -446,7 +446,7 @@ private fun OllamaUsageCard(state: State) {
|
||||
Spacer(modifier = Modifier.height(14.dp))
|
||||
UsageWindowRow(
|
||||
label = "每周",
|
||||
pct = extras["weekly.pct"]?.toIntOrNull(),
|
||||
pct = extras["weekly.pct"]?.toFloatOrNull()?.toInt(),
|
||||
resetInSec = extras["weekly.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 }
|
||||
)
|
||||
}
|
||||
|
||||
@ -184,10 +184,10 @@ class OpenCodeGoWidgetProvider : AppWidgetProvider() {
|
||||
ServiceType.OLLAMA -> {
|
||||
setRowLabel(views, "5h", "每周", "Plan")
|
||||
populateRow(views, R.id.row1_pct, R.id.row1_bar, R.id.row1_reset,
|
||||
pct = extras["session.pct"]?.toIntOrNull(),
|
||||
pct = extras["session.pct"]?.toFloatOrNull()?.toInt(),
|
||||
resetSec = extras["session.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 })
|
||||
populateRow(views, R.id.row2_pct, R.id.row2_bar, R.id.row2_reset,
|
||||
pct = extras["weekly.pct"]?.toIntOrNull(),
|
||||
pct = extras["weekly.pct"]?.toFloatOrNull()?.toInt(),
|
||||
resetSec = extras["weekly.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 })
|
||||
// Plan 信息放在第三行
|
||||
val plan = extras["plan"] ?: "—"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user