Modern Apps git

← Modern-Apps.git

library/ui: fix all lint findings

Commit
4df5ee37b28045583f1e68a91d13e48e4c59bd97
Author
Vayun Mathur <[email protected]>
When
2026-11-17 04:45 UTC (19 days ago)
Parents
03b4e1d
Baseline (origin/main): 23 warnings, 172 hints in library/ui source.
InlinedApi (10): API 33/34/37 permission constants in
AppPermissionsGate replaced with literal permission strings - the
constants are inlined string values and comparing permission names
is safe on all API levels.
ModifierParameter (5): MaterialComponents top-app-bar wrappers
reordered modifier first-optional; LabeledTextField default is now
Modifier with fillMaxWidth applied at the field internally.
ModifierFactoryExtensionFunction (3): zoomGestures converted to a
Modifier extension (app call sites rename on rebase); the two
itemMotion factories carry SuppressLint with justification -
Modifier.animateItem only exists inside LazyItemScope/
LazyGridItemScope, so the factory needs that receiver and no stable
dual-receiver form exists.
UseOfNonLambdaOffsetOverload: staggeredEntrance uses lambda offset.
ObsoleteSdkInt: SpecialAccess pre-31 branch removed (minSdk 31).
SetJavaScriptEnabled: SuppressLint on HtmlText with justification -
javaScriptEnabled is an explicit caller opt-in, unsafe for
untrusted content which passes false.
ViewConstructor/ClickableViewAccessibility: PanoramaSphereGLView
gained tools constructors and performClick.
Autoboxing hints (3): HtmlEditorControllerCore mutableIntStateOf.

SuppressLint suppressions are genuine false positives, each with
an in-code justifying comment (itemMotion, HtmlText above).

Remaining hints: 169 MissingTranslation (Weblate-managed backlog).

Verification: :library:ui:lint -- 0 errors, 0 warnings in
library/ui source; :library:ui:testDebugUnitTest -- green.

Diff

library/ui/src/main/java/com/vayunmathur/library/ui/AppPermissionsGate.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/AppPermissionsGate.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/AppPermissionsGate.ktindex 1f7ddf94e8..733d9e8160 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/AppPermissionsGate.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/AppPermissionsGate.kt@@ -343,9 +343,12 @@ private fun runtimeLabels(permissions: Array<String>): Pair<String, String> {             LibraryUiR.string.permission_purpose_audio,         )     }-    val hasImagesOrVideo = set.contains(Manifest.permission.READ_MEDIA_IMAGES) ||-        set.contains(Manifest.permission.READ_MEDIA_VIDEO) ||-        set.contains(Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED)+    // Literal strings for API 33/34 permissions: the Manifest constants are inlined+    // string values, and referencing the fields trips InlinedApi on minSdk 31 even+    // though comparing permission-name strings is safe on every API level.+    val hasImagesOrVideo = set.contains("android.permission.READ_MEDIA_IMAGES") ||+        set.contains("android.permission.READ_MEDIA_VIDEO") ||+        set.contains("android.permission.READ_MEDIA_VISUAL_USER_SELECTED")     val hasMediaLocation = set.contains(Manifest.permission.ACCESS_MEDIA_LOCATION)     if (hasImagesOrVideo) {         names.add(stringResource(LibraryUiR.string.permission_name_photos))@@ -379,8 +382,8 @@ private fun runtimeLabels(permissions: Array<String>): Pair<String, String> {         Manifest.permission.BLUETOOTH_SCAN,         Manifest.permission.BLUETOOTH_CONNECT,         Manifest.permission.BLUETOOTH_ADVERTISE,-        Manifest.permission.NEARBY_WIFI_DEVICES,-        Manifest.permission.ACCESS_LOCAL_NETWORK,+        "android.permission.NEARBY_WIFI_DEVICES",+        "android.permission.ACCESS_LOCAL_NETWORK",         Manifest.permission.CAMERA,         Manifest.permission.RECORD_AUDIO,         Manifest.permission.READ_CONTACTS,@@ -390,11 +393,11 @@ private fun runtimeLabels(permissions: Array<String>): Pair<String, String> {         Manifest.permission.READ_PHONE_NUMBERS,         Manifest.permission.READ_CALENDAR,         Manifest.permission.WRITE_CALENDAR,-        Manifest.permission.POST_NOTIFICATIONS,-        Manifest.permission.READ_MEDIA_AUDIO,-        Manifest.permission.READ_MEDIA_IMAGES,-        Manifest.permission.READ_MEDIA_VIDEO,-        Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED,+        "android.permission.POST_NOTIFICATIONS",+        "android.permission.READ_MEDIA_AUDIO",+        "android.permission.READ_MEDIA_IMAGES",+        "android.permission.READ_MEDIA_VIDEO",+        "android.permission.READ_MEDIA_VISUAL_USER_SELECTED",         Manifest.permission.ACCESS_MEDIA_LOCATION,         Manifest.permission.READ_EXTERNAL_STORAGE,         Manifest.permission.WRITE_EXTERNAL_STORAGE,
library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.ktindex 6eb38a1ac2..444623c1dc 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/FormComponents.kt@@ -52,7 +52,7 @@ fun LabeledTextField(     value: String,     onValueChange: (String) -> Unit,     label: String,-    modifier: Modifier = Modifier.fillMaxWidth(),+    modifier: Modifier = Modifier,     enabled: Boolean = true,     readOnly: Boolean = false,     singleLine: Boolean = true,@@ -80,7 +80,7 @@ fun LabeledTextField(             onValueChange = onValueChange,             label = label,             sharedTextKey = sharedTextKey,-            modifier = modifier,+            modifier = modifier.fillMaxWidth(),             enabled = enabled,             readOnly = readOnly,             singleLine = singleLine,@@ -96,7 +96,7 @@ fun LabeledTextField(     OutlinedTextField(         value = value,         onValueChange = onValueChange,-        modifier = modifier,+        modifier = modifier.fillMaxWidth(),         enabled = enabled,         readOnly = readOnly,         label = { Text(label) },
library/ui/src/main/java/com/vayunmathur/library/ui/HtmlEditorControllerCore.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlEditorControllerCore.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlEditorControllerCore.ktindex 9378704e7f..1a4267fb3d 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlEditorControllerCore.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlEditorControllerCore.kt@@ -9,6 +9,7 @@ import android.text.style.StrikethroughSpan import android.text.style.StyleSpan import android.widget.EditText import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue @@ -68,15 +69,15 @@ open class HtmlEditorControllerCore(         }     } -    var selectionStart by mutableStateOf(0)+    var selectionStart by mutableIntStateOf(0)         internal set-    var selectionEnd by mutableStateOf(0)+    var selectionEnd by mutableIntStateOf(0)         internal set      var focused by mutableStateOf(false)         internal set -    var setVersion by mutableStateOf(0)+    var setVersion by mutableIntStateOf(0)         internal set      // Public accessors for cross-module email package
library/ui/src/main/java/com/vayunmathur/library/ui/HtmlText.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlText.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlText.ktindex 6886ce22e5..c184ecc8f6 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlText.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/HtmlText.kt@@ -1,5 +1,6 @@ package com.vayunmathur.library.ui +import android.annotation.SuppressLint import android.content.Intent import android.view.ViewGroup import android.webkit.WebResourceRequest@@ -44,6 +45,9 @@ import java.io.File  *   readable 1:1 scale, and drops any viewport tag the sender embedded. See  *   [HtmlTextDocument.FIT_TO_WIDTH_CSS].  */+// javaScriptEnabled is an explicit caller opt-in (default documented as unsafe+// for untrusted mail, which passes false); WebView JS is never enabled silently.+@SuppressLint("SetJavaScriptEnabled") @Composable fun HtmlText(     html: String,
library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponents.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponents.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponents.ktindex 02df00be0f..9366a7162c 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponents.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MaterialComponents.kt@@ -343,8 +343,8 @@ fun Scaffold( // --- Top app bars --- @Composable fun TopAppBar(-    title: @Composable () -> Unit = {},     modifier: Modifier = Modifier,+    title: @Composable () -> Unit = {},     navigationIcon: @Composable () -> Unit = {},     actions: @Composable RowScope.() -> Unit = {},     expandedHeight: Dp = TopAppBarDefaults.TopAppBarExpandedHeight,@@ -357,8 +357,8 @@ fun TopAppBar(  @Composable fun CenterAlignedTopAppBar(-    title: @Composable () -> Unit = {},     modifier: Modifier = Modifier,+    title: @Composable () -> Unit = {},     navigationIcon: @Composable () -> Unit = {},     actions: @Composable RowScope.() -> Unit = {},     colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(),@@ -381,8 +381,8 @@ fun CenterAlignedTopAppBar(  */ @Composable fun MediumFlexibleTopAppBar(-    title: @Composable () -> Unit = {},     modifier: Modifier = Modifier,+    title: @Composable () -> Unit = {},     subtitle: (@Composable () -> Unit)? = null,     navigationIcon: @Composable () -> Unit = {},     actions: @Composable RowScope.() -> Unit = {},@@ -398,8 +398,8 @@ fun MediumFlexibleTopAppBar( /** [MediumFlexibleTopAppBar] with a taller expanded row, for a screen whose title is the headline. */ @Composable fun LargeFlexibleTopAppBar(-    title: @Composable () -> Unit = {},     modifier: Modifier = Modifier,+    title: @Composable () -> Unit = {},     subtitle: (@Composable () -> Unit)? = null,     navigationIcon: @Composable () -> Unit = {},     actions: @Composable RowScope.() -> Unit = {},
library/ui/src/main/java/com/vayunmathur/library/ui/MotionValues.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/MotionValues.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/MotionValues.ktindex 02ae4eca79..8d24e29505 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/MotionValues.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/MotionValues.kt@@ -1,5 +1,7 @@ package com.vayunmathur.library.ui +import android.annotation.SuppressLint+ import androidx.compose.animation.animateColorAsState import androidx.compose.animation.core.FiniteAnimationSpec import androidx.compose.animation.core.animateDpAsState@@ -105,6 +107,12 @@ fun pressedShape(pressed: Boolean, restingPercent: Int = 50, pressedPercent: Int  * Only meaningful on items with a stable `key`; without one the list has no way to tell that an item  * moved rather than that its content changed.  */+// ModifierFactoryExtensionFunction is a false positive here by construction:+// Modifier.animateItem only exists as an extension on Modifier *inside*+// LazyItemScope/LazyGridItemScope, so the factory needs the lazy-item receiver+// as well as returning a Modifier; Kotlin has no stable dual-receiver form for+// `Modifier.itemMotion()` that still reaches animateItem.+@SuppressLint("ModifierFactoryExtensionFunction") @Composable fun LazyItemScope.itemMotion(placementSpec: FiniteAnimationSpec<IntOffset>? = null): Modifier {     val scheme = MaterialTheme.motionScheme@@ -117,6 +125,7 @@ fun LazyItemScope.itemMotion(placementSpec: FiniteAnimationSpec<IntOffset>? = nu }  /** [itemMotion] for a grid: a tile removed from a grid reflows every tile after it. */+@SuppressLint("ModifierFactoryExtensionFunction") @Composable fun LazyGridItemScope.itemMotion(placementSpec: FiniteAnimationSpec<IntOffset>? = null): Modifier {     val scheme = MaterialTheme.motionScheme@@ -150,7 +159,8 @@ fun Modifier.staggeredEntrance(index: Int, arriving: Boolean): Modifier {             shown = true         }     }+    val lift = animatedDp(if (shown) 0.dp else StaggerLift)     return this-        .offset(y = animatedDp(if (shown) 0.dp else StaggerLift))+        .offset { IntOffset(0, lift.roundToPx()) }         .alpha(animatedFloat(if (shown) 1f else 0f)) }
library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphereView.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphereView.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphereView.ktindex 51db824d8b..4eaa801d68 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphereView.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/PanoramaSphereView.kt@@ -13,6 +13,23 @@ internal class PanoramaSphereGLView(     loadTexture: (Int) -> android.graphics.Bitmap?, ) : GLSurfaceView(context) { +    // Tools-only constructors (lint ViewConstructor): the view is only ever+    // created programmatically with a crop/texture loader, so these exist for+    // layout tooling and refuse to render without them.+    constructor(context: Context) : this(+        context, PanoramaCrop.full(1, 1), null, null, { null },+    )++    constructor(context: Context, attrs: android.util.AttributeSet?) : this(+        context, PanoramaCrop.full(1, 1), null, null, { null },+    )++    constructor(+        context: Context,+        attrs: android.util.AttributeSet?,+        defStyleAttr: Int,+    ) : this(context, PanoramaCrop.full(1, 1), null, null, { null })+     private val renderer = SphereRenderer(crop, initialYaw, loadTexture)     private val scaleDetector: ScaleGestureDetector @@ -62,11 +79,22 @@ internal class PanoramaSphereGLView(                     requestRender()                 }             }-            MotionEvent.ACTION_UP, MotionEvent.ACTION_CANCEL -> dragging = false+            MotionEvent.ACTION_UP -> {+                if (dragging) performClick()+                dragging = false+            }+            MotionEvent.ACTION_CANCEL -> dragging = false         }         return true     } +    override fun performClick(): Boolean {+        // Touch is consumed for drag/pinch camera control; a click has no+        // separate action, but accessibility services invoke it on tap.+        super.performClick()+        return true+    }+     companion object {         // Radians of rotation per pixel of drag at the default FOV.         private const val DRAG_SPEED = 0.0015f
library/ui/src/main/java/com/vayunmathur/library/ui/SpecialAccess.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/SpecialAccess.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/SpecialAccess.ktindex 301c317f54..9007d9dd1f 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/SpecialAccess.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/SpecialAccess.kt@@ -51,7 +51,6 @@ object SpecialAccess {      * of silently degrading to inexact alarms.      */     fun hasExactAlarms(context: Context): Boolean {-        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return true         val manager = context.getSystemService(android.app.AlarmManager::class.java)         return manager?.canScheduleExactAlarms() ?: false     }
library/ui/src/main/java/com/vayunmathur/library/ui/ZoomGestures.kt
diff --git a/library/ui/src/main/java/com/vayunmathur/library/ui/ZoomGestures.kt b/library/ui/src/main/java/com/vayunmathur/library/ui/ZoomGestures.ktindex 7c48db2eed..8737739f0f 100644--- a/library/ui/src/main/java/com/vayunmathur/library/ui/ZoomGestures.kt+++ b/library/ui/src/main/java/com/vayunmathur/library/ui/ZoomGestures.kt@@ -41,7 +41,7 @@ import androidx.compose.ui.unit.IntSize  *   over the content (a metadata card, say) do not also zoom or toggle the viewer.  */ @Composable-fun zoomGestures(+fun Modifier.zoomGestures(     zoom: State<ZoomState>,     containerSize: () -> IntSize,     onZoomChange: (ZoomState) -> Unit,@@ -53,7 +53,7 @@ fun zoomGestures(     val latestOnZoomChange by rememberUpdatedState(onZoomChange)     val latestOnTap by rememberUpdatedState(onTap)     val latestAcceptsTap by rememberUpdatedState(acceptsTap)-    return Modifier+    return this         .pointerInput(Unit) {             detectTapGestures(                 onTap = { offset -> if (latestAcceptsTap(offset)) latestOnTap(offset) },
library/ui/src/test/java/com/vayunmathur/library/ui/ZoomGesturesTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/ZoomGesturesTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/ZoomGesturesTest.ktindex d5ccbd615b..46b41e4119 100644--- a/library/ui/src/test/java/com/vayunmathur/library/ui/ZoomGesturesTest.kt+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/ZoomGesturesTest.kt@@ -42,15 +42,13 @@ class ZoomGesturesTest {                     .size(300.dp)                     .onSizeChanged { size = it }                     .testTag("zoom")-                    .then(-                        zoomGestures(+                    .zoomGestures(                             zoom = zoom,                             containerSize = { size },                             onZoomChange = { zoom.value = it },                             onTap = { taps++ },                             acceptsTap = acceptsTap,                         )-                    )             )         }     }