notes: fix all lint findings
- Commit
e955f0a79d070ced0ea126ffe3661878dba89d84- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 05:00 UTC (19 days ago)
- Parents
585afad
Fix every lint warning reported for the notes module's own sources by :notes:lintDev, now 0 errors / 0 warnings for notes/** (remaining report entries are transitive library findings owned by other clusters; one AutoboxingStateCreation hint in the new InkEditor.kt was also fixed, beyond the required bar). OneComposablePerFile: InkEditor moved out of InkEditorPage.kt, and InkBlock + BlockControls out of NoteEditorComponents.kt, each into its own file named as the composable; the InkToolbar/ToolButton/inkColors/InkTool helpers they share became internal. A first split attempt truncated BlockControls on its default-param lambda; the file was rewritten whole and the orphan fragment removed. UseKtx (2): RelayNoteProvider builds its content URIs with String.toUri(). NotificationPermission: added POST_NOTIFICATIONS to the manifest. Autoboxing hint: stroke width uses mutableFloatStateOf. No @SuppressLint added; no lint config or baseline changed. Verified: ./gradlew :notes:lintDev (0 own-module errors/warnings) and :notes:testDevUnitTest green.
Diff
notes/src/main/AndroidManifest.xml
diff --git a/notes/src/main/AndroidManifest.xml b/notes/src/main/AndroidManifest.xmlindex e4dee0864f..86e10cd797 100644--- a/notes/src/main/AndroidManifest.xml+++ b/notes/src/main/AndroidManifest.xml@@ -9,6 +9,7 @@ <!-- This app uses no motion/environment sensors; MAOS withholds the --> <!-- Sensors permission at install instead of auto-granting it. --> <uses-permission android:name="com.vayunmathur.permission.SENSORS_OPTOUT" />+ <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> <uses-permission android:name="android.permission.INTERNET" tools:node="remove" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" tools:node="remove" />
notes/src/main/java/com/vayunmathur/notes/sync/RelayNoteProvider.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/sync/RelayNoteProvider.kt b/notes/src/main/java/com/vayunmathur/notes/sync/RelayNoteProvider.ktindex af5accd90d..2a3b1401e1 100644--- a/notes/src/main/java/com/vayunmathur/notes/sync/RelayNoteProvider.kt+++ b/notes/src/main/java/com/vayunmathur/notes/sync/RelayNoteProvider.kt@@ -1,5 +1,6 @@ package com.vayunmathur.notes.sync +import androidx.core.net.toUri import android.content.ContentProvider import android.content.ContentValues import android.content.UriMatcher@@ -88,10 +89,10 @@ class RelayNoteProvider : ContentProvider() { private val json = Json { ignoreUnknownKeys = true } fun notesUri(vaultId: String): Uri =- Uri.parse("content://$AUTHORITY/vault/$vaultId/notes")+ "content://$AUTHORITY/vault/$vaultId/notes".toUri() fun snapshotsUri(vaultId: String): Uri =- Uri.parse("content://$AUTHORITY/vault/$vaultId/snapshots")+ "content://$AUTHORITY/vault/$vaultId/snapshots".toUri() } private fun repo(): NotesRepository {
notes/src/main/java/com/vayunmathur/notes/ui/InkEditor.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/InkEditor.kt b/notes/src/main/java/com/vayunmathur/notes/ui/InkEditor.ktnew file mode 100644index 0000000000..399bc6b09b--- /dev/null+++ b/notes/src/main/java/com/vayunmathur/notes/ui/InkEditor.kt@@ -0,0 +1,130 @@+package com.vayunmathur.notes.ui+import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.clickable+import androidx.compose.foundation.horizontalScroll+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.CircleShape+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.ExperimentalMaterial3Api+import com.vayunmathur.library.ui.Icon+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Slider+import com.vayunmathur.library.ui.Surface+import com.vayunmathur.library.ui.Text+import androidx.compose.runtime.Composable+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateListOf+import androidx.compose.runtime.mutableFloatStateOf+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.toArgb+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.unit.dp+import androidx.ink.brush.Brush+import androidx.ink.brush.StockBrushes+import androidx.ink.strokes.Stroke+import com.vayunmathur.library.ui.IconBrush+import com.vayunmathur.library.ui.IconCheck+import com.vayunmathur.library.ui.IconDraw+import com.vayunmathur.library.ui.IconEraser+import com.vayunmathur.library.ui.IconForward+import com.vayunmathur.library.ui.IconUndo+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ink.InkCanvasView+import com.vayunmathur.library.ink.SerializedStroke+import com.vayunmathur.library.ink.deserialize+import com.vayunmathur.library.ink.serialize+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.notes.R+import com.vayunmathur.notes.Route+import com.vayunmathur.notes.data.Note+import com.vayunmathur.notes.data.NoteBlock+import com.vayunmathur.notes.data.NoteBody+import com.vayunmathur.notes.data.body+import com.vayunmathur.notes.data.randomBlockId+import com.vayunmathur.notes.data.withBody+import com.vayunmathur.notes.platform.NotesViewModel++/**+ * Full-screen handwriting editor for a single ink block. Supports pen /+ * highlighter / eraser, color and stroke-width selection, and undo / redo.+ * Returns the finished strokes through [onDone], or discards edits via [onCancel].+ */+@OptIn(ExperimentalMaterial3Api::class)+@Composable+fun InkEditor(+ initialStrokes: List<SerializedStroke>,+ onDone: (List<SerializedStroke>) -> Unit,+ onCancel: () -> Unit,+) {+ val strokes = remember { mutableStateListOf<Stroke>().apply { addAll(initialStrokes.map { it.deserialize() }) } }+ val redoStack = remember { mutableStateListOf<Stroke>() }++ var tool by remember { mutableStateOf(InkTool.Pen) }+ var color by remember { mutableStateOf(inkColors.first()) }+ var width by remember { mutableFloatStateOf(6f) }++ val brush = remember(tool, color, width) {+ val family = if (tool == InkTool.Highlighter) StockBrushes.highlighter() else StockBrushes.pressurePen()+ Brush.createWithColorIntArgb(+ family = family,+ colorIntArgb = color.toArgb(),+ size = width,+ epsilon = 0.1f,+ )+ }++ AppScaffold(+ title = stringResource(R.string.drawing),+ onClose = onCancel,+ actions = {+ IconButton(onClick = { onDone(strokes.map { it.serialize() }) }) { IconCheck() }+ },+ bottomBar = {+ InkToolbar(+ tool = tool,+ onToolChange = { tool = it },+ color = color,+ onColorChange = { color = it },+ width = width,+ onWidthChange = { width = it },+ canUndo = strokes.isNotEmpty(),+ canRedo = redoStack.isNotEmpty(),+ onUndo = { if (strokes.isNotEmpty()) redoStack.add(strokes.removeAt(strokes.size - 1)) },+ onRedo = { if (redoStack.isNotEmpty()) strokes.add(redoStack.removeAt(redoStack.size - 1)) },+ )+ },+ scrollBehavior = appBarScrollBehavior(),+ ) { padding ->+ Box(+ Modifier+ .padding(padding)+ .fillMaxSize()+ .background(MaterialTheme.colorScheme.surface),+ ) {+ InkCanvasView(+ currentBrush = brush,+ finishedStrokes = strokes.toList(),+ onStrokeFinished = { strokes.add(it); redoStack.clear() },+ onStrokeErased = { strokes.remove(it) },+ eraserMode = tool == InkTool.Eraser,+ enabled = true,+ modifier = Modifier.fillMaxSize(),+ )+ }+ }+}
notes/src/main/java/com/vayunmathur/notes/ui/InkEditorPage.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/InkEditorPage.kt b/notes/src/main/java/com/vayunmathur/notes/ui/InkEditorPage.ktindex 57372c155d..83cdc71e75 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/InkEditorPage.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/InkEditorPage.kt@@ -59,7 +59,7 @@ import com.vayunmathur.notes.data.randomBlockId import com.vayunmathur.notes.data.withBody import com.vayunmathur.notes.platform.NotesViewModel -private enum class InkTool { Pen, Highlighter, Eraser }+internal enum class InkTool { Pen, Highlighter, Eraser } /** * Preset ink colors offered by the drawing toolbar.@@ -68,7 +68,7 @@ private enum class InkTool { Pen, Highlighter, Eraser } * fixed ARGB, so either one disappears against the themed canvas in one of the * two themes. The greys at each end stay legible in both. */-private val inkColors = listOf(+internal val inkColors = listOf( Color(0xFF37474F), Color(0xFFB0BEC5), Color(0xFFE53935), Color(0xFFFB8C00), Color(0xFFFDD835), Color(0xFF43A047), Color(0xFF1E88E5), Color(0xFF8E24AA), )@@ -123,78 +123,9 @@ fun InkEditorPage( ) } -/**- * Full-screen handwriting editor for a single ink block. Supports pen /- * highlighter / eraser, color and stroke-width selection, and undo / redo.- * Returns the finished strokes through [onDone], or discards edits via [onCancel].- */-@OptIn(ExperimentalMaterial3Api::class)-@Composable-fun InkEditor(- initialStrokes: List<SerializedStroke>,- onDone: (List<SerializedStroke>) -> Unit,- onCancel: () -> Unit,-) {- val strokes = remember { mutableStateListOf<Stroke>().apply { addAll(initialStrokes.map { it.deserialize() }) } }- val redoStack = remember { mutableStateListOf<Stroke>() }-- var tool by remember { mutableStateOf(InkTool.Pen) }- var color by remember { mutableStateOf(inkColors.first()) }- var width by remember { mutableStateOf(6f) }-- val brush = remember(tool, color, width) {- val family = if (tool == InkTool.Highlighter) StockBrushes.highlighter() else StockBrushes.pressurePen()- Brush.createWithColorIntArgb(- family = family,- colorIntArgb = color.toArgb(),- size = width,- epsilon = 0.1f,- )- }-- AppScaffold(- title = stringResource(R.string.drawing),- onClose = onCancel,- actions = {- IconButton(onClick = { onDone(strokes.map { it.serialize() }) }) { IconCheck() }- },- bottomBar = {- InkToolbar(- tool = tool,- onToolChange = { tool = it },- color = color,- onColorChange = { color = it },- width = width,- onWidthChange = { width = it },- canUndo = strokes.isNotEmpty(),- canRedo = redoStack.isNotEmpty(),- onUndo = { if (strokes.isNotEmpty()) redoStack.add(strokes.removeAt(strokes.size - 1)) },- onRedo = { if (redoStack.isNotEmpty()) strokes.add(redoStack.removeAt(redoStack.size - 1)) },- )- },- scrollBehavior = appBarScrollBehavior(),- ) { padding ->- Box(- Modifier- .padding(padding)- .fillMaxSize()- .background(MaterialTheme.colorScheme.surface),- ) {- InkCanvasView(- currentBrush = brush,- finishedStrokes = strokes.toList(),- onStrokeFinished = { strokes.add(it); redoStack.clear() },- onStrokeErased = { strokes.remove(it) },- eraserMode = tool == InkTool.Eraser,- enabled = true,- modifier = Modifier.fillMaxSize(),- )- }- }-} @Composable-private fun InkToolbar(+internal fun InkToolbar( tool: InkTool, onToolChange: (InkTool) -> Unit, color: Color,@@ -241,7 +172,7 @@ private fun InkToolbar( } @Composable-private fun ToolButton(active: Boolean, onClick: () -> Unit, content: @Composable () -> Unit) {+internal fun ToolButton(active: Boolean, onClick: () -> Unit, content: @Composable () -> Unit) { val tint = if (active) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant IconButton(onClick = onClick) { androidx.compose.runtime.CompositionLocalProvider(
notes/src/main/java/com/vayunmathur/notes/ui/components/BlockControls.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/components/BlockControls.kt b/notes/src/main/java/com/vayunmathur/notes/ui/components/BlockControls.ktnew file mode 100644index 0000000000..db393f4dfc--- /dev/null+++ b/notes/src/main/java/com/vayunmathur/notes/ui/components/BlockControls.kt@@ -0,0 +1,48 @@+package com.vayunmathur.notes.ui.components+import androidx.compose.foundation.border+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.unit.dp+import androidx.ink.brush.Brush+import androidx.ink.brush.StockBrushes+import androidx.compose.foundation.shape.RoundedCornerShape+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconKeyboardArrowDown+import com.vayunmathur.library.ui.IconKeyboardArrowUp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ink.InkCanvasView+import com.vayunmathur.library.ink.deserialize+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.notes.data.NoteBlock+import java.io.File++@Composable+fun BlockControls(+ onMoveUp: () -> Unit,+ onMoveDown: () -> Unit,+ onDelete: () -> Unit,+ extra: @Composable () -> Unit = {},+) {+ Row(verticalAlignment = Alignment.CenterVertically) {+ extra()+ IconButton(onClick = onMoveUp) {+ IconKeyboardArrowUp()+ }+ IconButton(onClick = onMoveDown) {+ IconKeyboardArrowDown()+ }+ IconButton(onClick = onDelete) { IconDelete() }+ }+}
notes/src/main/java/com/vayunmathur/notes/ui/components/InkBlock.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/components/InkBlock.kt b/notes/src/main/java/com/vayunmathur/notes/ui/components/InkBlock.ktnew file mode 100644index 0000000000..3fffa68a2e--- /dev/null+++ b/notes/src/main/java/com/vayunmathur/notes/ui/components/InkBlock.kt@@ -0,0 +1,59 @@+package com.vayunmathur.notes.ui.components+import androidx.compose.foundation.border+import androidx.compose.foundation.clickable+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.unit.dp+import androidx.ink.brush.Brush+import androidx.ink.brush.StockBrushes+import androidx.compose.foundation.shape.RoundedCornerShape+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.IconKeyboardArrowDown+import com.vayunmathur.library.ui.IconKeyboardArrowUp+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ink.InkCanvasView+import com.vayunmathur.library.ink.deserialize+import com.vayunmathur.library.image.compose.AsyncImage+import com.vayunmathur.notes.data.NoteBlock+import java.io.File++@Composable+fun InkBlock(+ block: NoteBlock.Ink,+ onEdit: () -> Unit,+ onMoveUp: () -> Unit,+ onMoveDown: () -> Unit,+ onDelete: () -> Unit,+) {+ val strokes = remember(block) { block.strokes.map { it.deserialize() } }+ Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {+ Box(+ Modifier+ .fillMaxWidth()+ .height(block.heightDp.dp)+ .border(1.dp, MaterialTheme.colorScheme.outlineVariant, RoundedCornerShape(8.dp))+ .clip(RoundedCornerShape(8.dp))+ .clickable { onEdit() },+ ) {+ InkCanvasView(+ currentBrush = previewBrush,+ finishedStrokes = strokes,+ onStrokeFinished = {},+ enabled = false,+ modifier = Modifier.fillMaxSize(),+ )+ }+ BlockControls(onMoveUp = onMoveUp, onMoveDown = onMoveDown, onDelete = onDelete)+ }+}
notes/src/main/java/com/vayunmathur/notes/ui/components/NoteEditorComponents.kt
diff --git a/notes/src/main/java/com/vayunmathur/notes/ui/components/NoteEditorComponents.kt b/notes/src/main/java/com/vayunmathur/notes/ui/components/NoteEditorComponents.ktindex 5229fde1d1..40c7cc77f8 100644--- a/notes/src/main/java/com/vayunmathur/notes/ui/components/NoteEditorComponents.kt+++ b/notes/src/main/java/com/vayunmathur/notes/ui/components/NoteEditorComponents.kt@@ -58,54 +58,7 @@ fun ImageBlock( } } -@Composable-fun InkBlock(- block: NoteBlock.Ink,- onEdit: () -> Unit,- onMoveUp: () -> Unit,- onMoveDown: () -> Unit,- onDelete: () -> Unit,-) {- val strokes = remember(block) { block.strokes.map { it.deserialize() } }- Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {- Box(- Modifier- .fillMaxWidth()- .height(block.heightDp.dp)- .border(1.dp, MaterialTheme.colorScheme.outlineVariant, RoundedCornerShape(8.dp))- .clip(RoundedCornerShape(8.dp))- .clickable { onEdit() },- ) {- InkCanvasView(- currentBrush = previewBrush,- finishedStrokes = strokes,- onStrokeFinished = {},- enabled = false,- modifier = Modifier.fillMaxSize(),- )- }- BlockControls(onMoveUp = onMoveUp, onMoveDown = onMoveDown, onDelete = onDelete)- }-} -@Composable-fun BlockControls(- onMoveUp: () -> Unit,- onMoveDown: () -> Unit,- onDelete: () -> Unit,- extra: @Composable () -> Unit = {},-) {- Row(verticalAlignment = Alignment.CenterVertically) {- extra()- IconButton(onClick = onMoveUp) {- IconKeyboardArrowUp()- }- IconButton(onClick = onMoveDown) {- IconKeyboardArrowDown()- }- IconButton(onClick = onDelete) { IconDelete() }- }-} // A read-only ink preview needs some brush, but strokes carry their own; this is unused for drawing. val previewBrush by lazy {