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:
WaterRain 2026-07-06 22:25:36 +00:00
parent 2926e8ebb2
commit 65e4dc5a2f
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions

View File

@ -438,7 +438,7 @@ private fun OllamaUsageCard(state: State) {
Spacer(modifier = Modifier.height(12.dp)) Spacer(modifier = Modifier.height(12.dp))
UsageWindowRow( UsageWindowRow(
label = "5 小时", 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 } resetInSec = extras["session.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 }
) )
Spacer(modifier = Modifier.height(14.dp)) Spacer(modifier = Modifier.height(14.dp))
@ -446,7 +446,7 @@ private fun OllamaUsageCard(state: State) {
Spacer(modifier = Modifier.height(14.dp)) Spacer(modifier = Modifier.height(14.dp))
UsageWindowRow( UsageWindowRow(
label = "每周", 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 } resetInSec = extras["weekly.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 }
) )
} }

View File

@ -184,10 +184,10 @@ class OpenCodeGoWidgetProvider : AppWidgetProvider() {
ServiceType.OLLAMA -> { ServiceType.OLLAMA -> {
setRowLabel(views, "5h", "每周", "Plan") setRowLabel(views, "5h", "每周", "Plan")
populateRow(views, R.id.row1_pct, R.id.row1_bar, R.id.row1_reset, 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 }) 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, 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 }) resetSec = extras["weekly.resetAt"]?.toLongOrNull()?.let { (it - System.currentTimeMillis()) / 1000 }?.takeIf { it > 0 })
// Plan 信息放在第三行 // Plan 信息放在第三行
val plan = extras["plan"] ?: "—" val plan = extras["plan"] ?: "—"