Take ktfmt's defaults for the Kotlin half

The server half went to rustfmt's defaults earlier today; this is the same
move for the app, and the same reasoning. Kotlin ships no formatter with
the Gradle build, so the question was which to adopt: ktfmt is Kotlin-org
owned now (it moved from facebook/ktfmt), is a formatter rather than a
configurable linter, and has essentially nothing to tune -- which is what
rule 27 is asking for. ktlint's .editorconfig surface is the thing that
rule warns against, and detekt is static analysis, whose job Android Lint
already does here.

One setting, and it is a choice between the tool's own two styles rather
than a tuning: kotlinLangStyle() is the 4-space one, which is what this
code already was. The 2-space default would have reindented every file to
say nothing.

  ./gradlew :androidApp:ktfmtFormat   to apply
  ./gradlew :androidApp:ktfmtCheck    to verify

Formatting only. The one thing worth checking by hand was the generated
PEM constant, since a leading newline there costs Android's
CertificateFactory its preamble sniff and fails at runtime nowhere near
the cause: ktfmt moved `.trimMargin()` onto its own line and left the
template alone, and the regenerated constant still starts at the opening
quotes.

Verified after: ktfmtCheck, compileDebugKotlin and lintDebug all pass, and
the APK builds.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017xn8nHw1tw1R6PtiY1eEtw
This commit is contained in:
irisandClaude Opus 5 committed 2026-08-28 04:03:14 -04:00
1 parent dde5042b12
commit 0c13090d70
16 files changed
+585 -496

No files matched your search

@@ -26,11 +26,11 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import java.time.Duration
import java.time.OffsetDateTime
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.time.Duration
import java.time.OffsetDateTime
private val WARN_COLOR = Color(0xFFB26A00)
private val OVER_COLOR = Color(0xFFB3261E)
@@ -44,11 +44,12 @@ fun UsageScreen(settings: ServerSettings, onBack: () -> Unit) {
fun refresh() {
state = LoadState.Loading
scope.launch {
state = try {
withContext(Dispatchers.IO) { LoadState.Loaded(fetchUsage(settings)) }
} catch (e: ApiException) {
LoadState.failed(e)
}
state =
try {
withContext(Dispatchers.IO) { LoadState.Loaded(fetchUsage(settings)) }
} catch (e: ApiException) {
LoadState.failed(e)
}
}
}
LaunchedEffect(Unit) { refresh() }
@@ -68,37 +69,39 @@ fun UsageScreen(settings: ServerSettings, onBack: () -> Unit) {
when (val current = state) {
is LoadState.Loading -> CircularProgressIndicator()
is LoadState.Error -> Text(current.message, color = MaterialTheme.colorScheme.error)
is LoadState.Loaded -> current.value.forEach { snapshot ->
Card(Modifier.fillMaxWidth()) {
Column(Modifier.padding(16.dp)) {
Text(snapshot.provider, style = MaterialTheme.typography.titleMedium)
Spacer(Modifier.height(8.dp))
if (!snapshot.available) {
Text(
snapshot.error ?: "Unavailable",
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodyMedium,
)
}
snapshot.windows.forEach { window ->
WindowBar(window)
Spacer(Modifier.height(12.dp))
is LoadState.Loaded ->
current.value.forEach { snapshot ->
Card(Modifier.fillMaxWidth()) {
Column(Modifier.padding(16.dp)) {
Text(snapshot.provider, style = MaterialTheme.typography.titleMedium)
Spacer(Modifier.height(8.dp))
if (!snapshot.available) {
Text(
snapshot.error ?: "Unavailable",
color = MaterialTheme.colorScheme.error,
style = MaterialTheme.typography.bodyMedium,
)
}
snapshot.windows.forEach { window ->
WindowBar(window)
Spacer(Modifier.height(12.dp))
}
}
}
Spacer(Modifier.height(12.dp))
}
Spacer(Modifier.height(12.dp))
}
}
}
}
@Composable
private fun WindowBar(window: UsageWindow) {
val color = when {
window.percent >= 95 -> OVER_COLOR
window.percent >= 75 -> WARN_COLOR
else -> MaterialTheme.colorScheme.primary
}
val color =
when {
window.percent >= 95 -> OVER_COLOR
window.percent >= 75 -> WARN_COLOR
else -> MaterialTheme.colorScheme.primary
}
Column {
Row(modifier = Modifier.fillMaxWidth()) {
Text(
@@ -126,14 +129,15 @@ private fun WindowBar(window: UsageWindow) {
}
/** "in 3h 12m" -- close enough for deciding whether to start a big task. */
private fun formatReset(resetsAt: String): String = try {
val until = Duration.between(OffsetDateTime.now(), OffsetDateTime.parse(resetsAt))
when {
until.isNegative -> "soon"
until.toHours() >= 24 -> "in ${until.toDays()}d ${until.toHours() % 24}h"
until.toHours() > 0 -> "in ${until.toHours()}h ${until.toMinutes() % 60}m"
else -> "in ${until.toMinutes()}m"
private fun formatReset(resetsAt: String): String =
try {
val until = Duration.between(OffsetDateTime.now(), OffsetDateTime.parse(resetsAt))
when {
until.isNegative -> "soon"
until.toHours() >= 24 -> "in ${until.toDays()}d ${until.toHours() % 24}h"
until.toHours() > 0 -> "in ${until.toHours()}h ${until.toMinutes() % 60}m"
else -> "in ${until.toMinutes()}m"
}
} catch (_: Exception) {
"at $resetsAt"
}
} catch (_: Exception) {
"at $resetsAt"
}