From cb67f1de526e6120db363f67035966f365467912 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 11 Nov 2023 18:13:44 -0500 Subject: [PATCH] Add Compose lint checks Still need to address most of them though. --- app/build.gradle.kts | 1 + .../presentation/manga/components/MangaDialogs.kt | 2 +- .../presentation/track/TrackInfoDialogSelector.kt | 4 ++-- gradle/androidx.versions.toml | 1 - gradle/compose.versions.toml | 4 ++++ presentation-core/build.gradle.kts | 1 + .../presentation/core/components/ActionButton.kt | 2 +- .../presentation/core/components/AdaptiveSheet.kt | 2 +- .../core/components/CollapsibleBox.kt | 5 ++++- .../core/components/LabeledCheckbox.kt | 2 +- .../presentation/core/components/LinkIcon.kt | 7 ++++++- .../core/components/ListGroupHeader.kt | 5 ++++- .../presentation/core/components/SettingsItems.kt | 4 ++-- .../presentation/core/components/TwoPanelBox.kt | 4 ++-- .../presentation/core/components/WheelPicker.kt | 6 +++--- .../components/material/FloatingActionButton.kt | 15 ++++++++++++--- .../core/components/material/IconToggleButton.kt | 2 +- .../presentation/core/components/material/Tabs.kt | 2 ++ presentation-widget/build.gradle.kts | 3 ++- .../widget/BaseUpdatesGridGlanceWidget.kt | 2 +- .../widget/components/UpdatesMangaCover.kt | 5 ++++- .../widget/components/UpdatesWidget.kt | 4 ++-- 22 files changed, 57 insertions(+), 26 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 943d88031..13b7d3caa 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -167,6 +167,7 @@ dependencies { implementation(compose.accompanist.permissions) implementation(compose.accompanist.themeadapter) implementation(compose.accompanist.systemuicontroller) + lintChecks(compose.lintchecks) implementation(androidx.paging.runtime) implementation(androidx.paging.compose) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt index 94f34eec2..1fd1dd021 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaDialogs.kt @@ -75,8 +75,8 @@ fun SetIntervalDialog( } } WheelTextPicker( - size = size, items = items, + size = size, startIndex = selectedInterval, onSelectionChanged = { selectedInterval = it }, ) diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt index 012fc0466..a4faba194 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt @@ -102,9 +102,9 @@ fun TrackChapterSelector( title = stringResource(R.string.chapters), content = { WheelNumberPicker( + items = range.toList(), modifier = Modifier.align(Alignment.Center), startIndex = selection, - items = range.toList(), onSelectionChanged = { onSelectionChange(it) }, ) }, @@ -125,9 +125,9 @@ fun TrackScoreSelector( title = stringResource(R.string.score), content = { WheelTextPicker( + items = selections, modifier = Modifier.align(Alignment.Center), startIndex = selections.indexOf(selection).takeIf { it > 0 } ?: (selections.size / 2), - items = selections, onSelectionChanged = { onSelectionChange(selections[it]) }, ) }, diff --git a/gradle/androidx.versions.toml b/gradle/androidx.versions.toml index c3df15095..2fd9332a4 100644 --- a/gradle/androidx.versions.toml +++ b/gradle/androidx.versions.toml @@ -14,7 +14,6 @@ corektx = "androidx.core:core-ktx:1.12.0" splashscreen = "androidx.core:core-splashscreen:1.0.1" recyclerview = "androidx.recyclerview:recyclerview:1.3.2" viewpager = "androidx.viewpager:viewpager:1.1.0-alpha01" -glance = "androidx.glance:glance-appwidget:1.0.0" profileinstaller = "androidx.profileinstaller:profileinstaller:1.3.1" lifecycle-common = { module = "androidx.lifecycle:lifecycle-common", version.ref = "lifecycle_version" } diff --git a/gradle/compose.versions.toml b/gradle/compose.versions.toml index 492bc2c38..fbac9ac7f 100644 --- a/gradle/compose.versions.toml +++ b/gradle/compose.versions.toml @@ -19,7 +19,11 @@ material-icons = { module = "androidx.compose.material:material-icons-extended" # Some components aren't available in Material3 material-core = { module = "androidx.compose.material:material" } +glance = "androidx.glance:glance-appwidget:1.0.0" + accompanist-webview = { module = "com.google.accompanist:accompanist-webview", version.ref = "accompanist" } accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanist" } accompanist-themeadapter = { module = "com.google.accompanist:accompanist-themeadapter-material3", version.ref = "accompanist" } accompanist-systemuicontroller = { module = "com.google.accompanist:accompanist-systemuicontroller", version.ref = "accompanist" } + +lintchecks = { module = "com.slack.lint.compose:compose-lint-checks", version = "1.2.0" } \ No newline at end of file diff --git a/presentation-core/build.gradle.kts b/presentation-core/build.gradle.kts index 9c87d7465..b578de913 100644 --- a/presentation-core/build.gradle.kts +++ b/presentation-core/build.gradle.kts @@ -35,6 +35,7 @@ dependencies { debugImplementation(compose.ui.tooling) implementation(compose.ui.tooling.preview) implementation(compose.ui.util) + lintChecks(compose.lintchecks) } tasks { diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ActionButton.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ActionButton.kt index 54cbd9cdd..4aa09cde5 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ActionButton.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ActionButton.kt @@ -14,10 +14,10 @@ import androidx.compose.ui.unit.dp @Composable fun ActionButton( - modifier: Modifier = Modifier, title: String, icon: ImageVector, onClick: () -> Unit, + modifier: Modifier = Modifier, ) { TextButton( modifier = modifier, diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt index 51fb672ee..51089cf52 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/AdaptiveSheet.kt @@ -56,11 +56,11 @@ private val sheetAnimationSpec = tween(durationMillis = 350) @Composable fun AdaptiveSheet( - modifier: Modifier = Modifier, isTabletUi: Boolean, tonalElevation: Dp, enableSwipeDismiss: Boolean, onDismissRequest: () -> Unit, + modifier: Modifier = Modifier, content: @Composable () -> Unit, ) { val density = LocalDensity.current diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt index ffd4b84e9..b70cb2705 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/CollapsibleBox.kt @@ -23,7 +23,10 @@ import androidx.compose.ui.unit.dp import tachiyomi.presentation.core.theme.header @Composable -fun CollapsibleBox(heading: String, content: @Composable () -> Unit) { +fun CollapsibleBox( + heading: String, + content: @Composable () -> Unit, +) { var expanded by remember { mutableStateOf(false) } Column { diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LabeledCheckbox.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LabeledCheckbox.kt index f2039cd36..e40293841 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LabeledCheckbox.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LabeledCheckbox.kt @@ -17,10 +17,10 @@ import androidx.compose.ui.unit.dp @Composable fun LabeledCheckbox( - modifier: Modifier = Modifier, label: String, checked: Boolean, onCheckedChange: (Boolean) -> Unit, + modifier: Modifier = Modifier, enabled: Boolean = true, ) { Row( diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt index 86d1225b5..b1e1e8245 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/LinkIcon.kt @@ -11,7 +11,12 @@ import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.unit.dp @Composable -fun LinkIcon(modifier: Modifier = Modifier, label: String, icon: ImageVector, url: String) { +fun LinkIcon( + label: String, + icon: ImageVector, + url: String, + modifier: Modifier = Modifier, +) { val uriHandler = LocalUriHandler.current IconButton( modifier = modifier.padding(4.dp), diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt index 2fe128746..1aaba373e 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/ListGroupHeader.kt @@ -9,7 +9,10 @@ import androidx.compose.ui.text.font.FontWeight import tachiyomi.presentation.core.components.material.padding @Composable -fun ListGroupHeader(modifier: Modifier = Modifier, text: String) { +fun ListGroupHeader( + text: String, + modifier: Modifier = Modifier, +) { Text( text = text, modifier = modifier diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt index 4f339dc49..c949fa7ce 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/SettingsItems.kt @@ -156,11 +156,11 @@ fun RadioItem(label: String, selected: Boolean, onClick: () -> Unit) { @Composable fun SliderItem( label: String, - min: Int = 0, - max: Int, value: Int, valueText: String, onChange: (Int) -> Unit, + max: Int, + min: Int = 0, ) { val haptic = LocalHapticFeedback.current diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/TwoPanelBox.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/TwoPanelBox.kt index a3a97dcd1..8dbc88693 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/TwoPanelBox.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/TwoPanelBox.kt @@ -17,10 +17,10 @@ import androidx.compose.ui.unit.dp @Composable fun TwoPanelBox( - modifier: Modifier = Modifier, - contentWindowInsets: WindowInsets = WindowInsets(0), startContent: @Composable BoxScope.() -> Unit, endContent: @Composable BoxScope.() -> Unit, + modifier: Modifier = Modifier, + contentWindowInsets: WindowInsets = WindowInsets(0), ) { val direction = LocalLayoutDirection.current val padding = contentWindowInsets.asPaddingValues() diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt index 6d24aa545..d13b96a7b 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/WheelPicker.kt @@ -54,9 +54,9 @@ import kotlin.math.absoluteValue @Composable fun WheelNumberPicker( + items: List, modifier: Modifier = Modifier, startIndex: Int = 0, - items: List, size: DpSize = DpSize(128.dp, 128.dp), onSelectionChanged: (index: Int) -> Unit = {}, backgroundContent: (@Composable (size: DpSize) -> Unit)? = { @@ -78,9 +78,9 @@ fun WheelNumberPicker( @Composable fun WheelTextPicker( + items: List, modifier: Modifier = Modifier, startIndex: Int = 0, - items: List, size: DpSize = DpSize(128.dp, 128.dp), onSelectionChanged: (index: Int) -> Unit = {}, backgroundContent: (@Composable (size: DpSize) -> Unit)? = { @@ -101,9 +101,9 @@ fun WheelTextPicker( @Composable private fun WheelPicker( + items: List, modifier: Modifier = Modifier, startIndex: Int = 0, - items: List, size: DpSize = DpSize(128.dp, 128.dp), onSelectionChanged: (index: Int) -> Unit = {}, manualInputType: KeyboardType? = null, diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/FloatingActionButton.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/FloatingActionButton.kt index 645e318f3..fd1fa8c4b 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/FloatingActionButton.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/FloatingActionButton.kt @@ -46,7 +46,10 @@ fun ExtendedFloatingActionButton( contentColor: Color = contentColorFor(containerColor), elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(), ) { - val minWidth by animateDpAsState(if (expanded) ExtendedFabMinimumWidth else FabContainerWidth) + val minWidth by animateDpAsState( + targetValue = if (expanded) ExtendedFabMinimumWidth else FabContainerWidth, + label = "minWidth", + ) FloatingActionButton( modifier = modifier.sizeIn(minWidth = minWidth), onClick = onClick, @@ -56,8 +59,14 @@ fun ExtendedFloatingActionButton( contentColor = contentColor, elevation = elevation, ) { - val startPadding by animateDpAsState(if (expanded) ExtendedFabIconSize / 2 else 0.dp) - val endPadding by animateDpAsState(if (expanded) ExtendedFabTextPadding else 0.dp) + val startPadding by animateDpAsState( + targetValue = if (expanded) ExtendedFabIconSize / 2 else 0.dp, + label = "startPadding", + ) + val endPadding by animateDpAsState( + targetValue = if (expanded) ExtendedFabTextPadding else 0.dp, + label = "endPadding", + ) Row( modifier = Modifier.padding(start = startPadding, end = endPadding), diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconToggleButton.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconToggleButton.kt index 2abcc4b39..d00cc8657 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconToggleButton.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/IconToggleButton.kt @@ -20,9 +20,9 @@ import androidx.compose.ui.unit.dp fun IconToggleButton( checked: Boolean, onCheckedChange: (Boolean) -> Unit, - modifier: Modifier = Modifier, imageVector: ImageVector, title: String, + modifier: Modifier = Modifier, ) { FilledIconToggleButton( checked = checked, diff --git a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt index 0770d577a..23d65d07f 100644 --- a/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt +++ b/presentation-core/src/main/java/tachiyomi/presentation/core/components/material/Tabs.kt @@ -36,10 +36,12 @@ private fun Modifier.tabIndicatorOffset( val currentTabWidth by animateDpAsState( targetValue = currentTabPosition.width, animationSpec = spring(stiffness = Spring.StiffnessMediumLow), + label = "currentTabWidth", ) val offset by animateDpAsState( targetValue = currentTabPosition.left + (currentTabWidth * currentPageOffsetFraction), animationSpec = spring(stiffness = Spring.StiffnessMediumLow), + label = "offset", ) Modifier .offset { IntOffset(x = offset.roundToPx(), y = 0) } diff --git a/presentation-widget/build.gradle.kts b/presentation-widget/build.gradle.kts index 9c5c0ec65..95777e4a4 100644 --- a/presentation-widget/build.gradle.kts +++ b/presentation-widget/build.gradle.kts @@ -25,7 +25,8 @@ dependencies { implementation(project(":domain")) implementation(project(":presentation-core")) - implementation(androidx.glance) + implementation(compose.glance) + lintChecks(compose.lintchecks) implementation(platform(libs.coil.bom)) implementation(libs.coil.core) diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt index 26e1cd918..c28f818a6 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/BaseUpdatesGridGlanceWidget.kt @@ -95,10 +95,10 @@ abstract class BaseUpdatesGridGlanceWidget( val data by flow.collectAsState(initial = null) UpdatesWidget( data = data, - modifier = containerModifier, contentColor = foreground, topPadding = topPadding, bottomPadding = bottomPadding, + modifier = containerModifier, ) } } diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt index 5b537f45d..076d25d74 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesMangaCover.kt @@ -17,7 +17,10 @@ val CoverWidth = 58.dp val CoverHeight = 87.dp @Composable -fun UpdatesMangaCover(modifier: GlanceModifier = GlanceModifier, cover: Bitmap?) { +fun UpdatesMangaCover( + cover: Bitmap?, + modifier: GlanceModifier = GlanceModifier, +) { Box( modifier = modifier .size(width = CoverWidth, height = CoverHeight) diff --git a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt index 46f8d26e6..53ebadfa9 100644 --- a/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt +++ b/presentation-widget/src/main/java/tachiyomi/presentation/widget/components/UpdatesWidget.kt @@ -29,10 +29,10 @@ import tachiyomi.presentation.widget.util.stringResource @Composable fun UpdatesWidget( data: List>?, - modifier: GlanceModifier = GlanceModifier, contentColor: ColorProvider, topPadding: Dp, bottomPadding: Dp, + modifier: GlanceModifier = GlanceModifier, ) { Box( contentAlignment = Alignment.Center, @@ -83,8 +83,8 @@ fun UpdatesWidget( addCategory(mangaId.toString()) } UpdatesMangaCover( - modifier = GlanceModifier.clickable(actionStartActivity(intent)), cover = cover, + modifier = GlanceModifier.clickable(actionStartActivity(intent)), ) } }