Thin the app's comments
The same pass the server had, on the Kotlin side: comments restating what the code says are gone, and the ones recording a measurement, a constraint or an incident are kept but cut to a few lines each. 6540 comment lines to 5674, and 920 lines off the app. Two doc comments had drifted onto the item above the one they describe -- `contextAfter`'s onto `sessionWorking` in Events.kt, and `UsageMonitor`'s equivalent on the server was fixed in the previous commit. Each is back on its own item, which is the only non-comment line this diff moves. The comments are reflowed to the column limit at their own indentation: several were written wide, and ktfmt re-wrapped them into lines holding a single orphan word. `/tmp` script, not kept -- ktfmt is idempotent over the result, which is the check. Left alone deliberately: this codebase's remaining comment density is high because the comments carry things the code cannot say -- what a null means, what a number was measured against, which bug a guard exists for. Of the 238 one-line doc comments in the app, five were pure restatement of the name and were removed; the rest each say something the signature does not. ktfmtFormat, compileDebugKotlin, lintDebug and testDebugUnitTest pass; cargo test (127), clippy --all-targets and fmt still clean. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
79682f03a7
commit
edc39c7371
68 files changed
+2077
-2997
No files matched your search
@@ -28,14 +28,13 @@ import androidx.compose.ui.layout.layout
|
||||
import androidx.core.view.WindowCompat
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
// Bumped whenever enrollment lands via an aiapp:// intent so the
|
||||
// composition below re-reads the stored settings.
|
||||
// Bumped whenever enrollment lands via an aiapp:// intent so the composition below re-reads the
|
||||
// stored settings.
|
||||
private var settingsVersion by mutableIntStateOf(0)
|
||||
|
||||
// The session a notification tap asked for, or null if nothing has. The
|
||||
// serial is what makes a second tap on the same session's notification a
|
||||
// second request: without it the two compare equal and the composition
|
||||
// below has nothing to react to.
|
||||
// The session a notification tap asked for, or null if nothing has. The serial is what makes a
|
||||
// second tap on the same session's notification a second request: without it the two compare
|
||||
// equal and the composition below has nothing to react to.
|
||||
private var openRequest by mutableStateOf<SessionOpenRequest?>(null)
|
||||
private var opens = 0
|
||||
|
||||
@@ -43,8 +42,8 @@ class MainActivity : ComponentActivity() {
|
||||
private var shareRequest by mutableStateOf<ShareRequest?>(null)
|
||||
private var shares = 0
|
||||
|
||||
// Registered up front since permission launchers must be registered
|
||||
// before the activity reaches STARTED.
|
||||
// Registered up front since permission launchers must be registered before the activity reaches
|
||||
// STARTED.
|
||||
private val requestLocalNetworkPermission =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
||||
|
||||
@@ -52,8 +51,8 @@ class MainActivity : ComponentActivity() {
|
||||
* The service starts either way, and posts nothing if this is refused.
|
||||
*
|
||||
* Deliberately not gated on the answer: the permission can be granted later from Android's own
|
||||
* settings, and a service that only ever started at the moment it was granted would then stay
|
||||
* down until the app was launched again -- which is the case notifications exist to avoid.
|
||||
* settings, and a service that only ever started at the moment it was granted would stay down
|
||||
* until the app was launched again.
|
||||
*/
|
||||
private val requestNotificationPermission =
|
||||
registerForActivityResult(ActivityResultContracts.RequestPermission()) {}
|
||||
@@ -64,21 +63,17 @@ class MainActivity : ComponentActivity() {
|
||||
// Before anything else that could throw, so the first crash of a launch is caught too.
|
||||
installCrashLog(this)
|
||||
|
||||
// Transparent status bar on every version; the Surface below paints
|
||||
// through underneath it and content insets itself. Same reasoning
|
||||
// as dev-updater's MainActivity.
|
||||
// Transparent status bar on every version; the Surface below paints through underneath it
|
||||
// and content insets itself. Same reasoning as dev-updater's MainActivity.
|
||||
enableEdgeToEdge()
|
||||
// Dark status-bar icons only over a light background, decided from the scheme rather
|
||||
// than fixed. It was hardcoded to `true` -- dark icons -- which was right against the
|
||||
// default light surface and became unreadable the moment the app wore Catppuccin Mocha.
|
||||
// Asking the colour means a future palette change cannot reintroduce that: whatever
|
||||
// `background` becomes, the icons follow it.
|
||||
// Dark status-bar icons only over a light background, decided from the scheme rather than
|
||||
// fixed. It was hardcoded to `true`, which was right against the default light surface and
|
||||
// became unreadable the moment the app wore Catppuccin Mocha.
|
||||
WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars =
|
||||
AiAppColors.background.luminance() > 0.5f
|
||||
|
||||
// Android 17+ silently drops local-network traffic without this;
|
||||
// requested up front because a denial is invisible at the socket
|
||||
// layer (it just times out).
|
||||
// Android 17+ silently drops local-network traffic without this; requested up front because
|
||||
// a denial is invisible at the socket layer (it just times out).
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.CINNAMON_BUN) {
|
||||
requestLocalNetworkPermission.launch(Manifest.permission.ACCESS_LOCAL_NETWORK)
|
||||
}
|
||||
@@ -88,16 +83,14 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
handleIntent(intent)
|
||||
// After enrollment, so a first launch that arrives with a token
|
||||
// starts the service with something to connect to rather than
|
||||
// stopping it and waiting for the next launch.
|
||||
// After enrollment, so a first launch that arrives with a token starts the service with
|
||||
// something to connect to rather than stopping it and waiting for the next launch.
|
||||
NotificationService.sync(this)
|
||||
|
||||
setContent {
|
||||
// Selection colours with the theme rather than at each place text is drawn: the
|
||||
// transcript is one selection container, and a selection that ran from a reply into
|
||||
// the code block under it would otherwise change colour halfway. See
|
||||
// [AiAppSelectionColors].
|
||||
// transcript is one selection container, and a selection that ran from a reply into the
|
||||
// code block under it would otherwise change colour halfway.
|
||||
MaterialTheme(colorScheme = AiAppColors) {
|
||||
CompositionLocalProvider(LocalTextSelectionColors provides AiAppSelectionColors) {
|
||||
Surface(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -107,8 +100,7 @@ class MainActivity : ComponentActivity() {
|
||||
// the frame's draw phase is where Compose's measurement lands, and
|
||||
// a report saying "draw is high" cannot otherwise say whether the
|
||||
// cost is the transcript or the chrome around it. The keyboard is
|
||||
// the case that made it matter -- every frame of the IME animation
|
||||
// relays out and re-records this whole box.
|
||||
// the case that made it matter.
|
||||
Modifier.layout { measurable, constraints ->
|
||||
val started = System.nanoTime()
|
||||
val placeable = measurable.measure(constraints)
|
||||
@@ -135,19 +127,16 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
.fillMaxSize()
|
||||
.statusBarsPadding()
|
||||
// The gesture strip at the bottom of most
|
||||
// phones. Without it the send row sits under
|
||||
// the swipe area, where a tap is as likely to
|
||||
// navigate away as to press a button.
|
||||
// The gesture strip at the bottom of most phones. Without it
|
||||
// the send row sits under the swipe area, where a tap is as
|
||||
// likely to navigate away as to press a button.
|
||||
//
|
||||
// No imePadding here, deliberately: applied at the root it
|
||||
// resizes this whole box on every frame of the keyboard
|
||||
// animation, which re-measures, re-places and re-records every
|
||||
// screen's entire tree per frame -- measured above as most of
|
||||
// the frame budget. Each screen takes the keyboard itself
|
||||
// (AppRoot wraps the ordinary ones; the session screen moves
|
||||
// only its composer and transcript), so the per-frame cost is
|
||||
// scoped to what actually moves.
|
||||
// screen's entire tree per frame. Each screen takes the
|
||||
// keyboard itself, so the per-frame cost is scoped to what
|
||||
// actually moves.
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
AppRoot(settingsVersion, openRequest, shareRequest)
|
||||
@@ -158,9 +147,8 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// launchMode="singleTop": an enrollment scan, or a notification tapped
|
||||
// while the app is open, lands here rather than in a second activity
|
||||
// instance.
|
||||
// launchMode="singleTop": an enrollment scan, or a notification tapped while the app is open,
|
||||
// lands here rather than in a second activity instance.
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
handleIntent(intent)
|
||||
@@ -171,8 +159,7 @@ class MainActivity : ComponentActivity() {
|
||||
*
|
||||
* Three things arrive this way -- a share from another app, and an `aiapp://` URI that is
|
||||
* either an enrollment code or a notification naming a session. The URIs are told apart by host
|
||||
* rather than by two entry points, so a further kind is a branch here rather than another
|
||||
* intent to remember to handle.
|
||||
* rather than by two entry points, so a further kind is a branch here.
|
||||
*/
|
||||
private fun handleIntent(intent: Intent?) {
|
||||
intent ?: return
|
||||
@@ -195,8 +182,8 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
saveServerSettings(this, settings)
|
||||
settingsVersion++
|
||||
// Enrolling is the moment there is a backend to watch, and
|
||||
// re-enrolling elsewhere is the moment the old one stops being it.
|
||||
// Enrolling is the moment there is a backend to watch, and re-enrolling elsewhere is the
|
||||
// moment the old one stops being it.
|
||||
NotificationService.sync(this)
|
||||
Toast.makeText(this, "Enrolled with ${settings.baseUrl}", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user