Switch to different ktlint plugin

Should be better at incremental builds.
To format, run `./gradlew ktlintFormat`.
This commit is contained in:
arkon
2023-09-01 23:02:18 -04:00
parent 772db51593
commit d29b7c4e57
69 changed files with 628 additions and 291 deletions

View File

@ -182,7 +182,10 @@ fun AdaptiveSheet(
shape = MaterialTheme.shapes.extraLarge,
tonalElevation = tonalElevation,
content = {
BackHandler(enabled = anchoredDraggableState.targetValue == 0, onBack = internalOnDismissRequest)
BackHandler(
enabled = anchoredDraggableState.targetValue == 0,
onBack = internalOnDismissRequest,
)
content()
},
)
@ -200,49 +203,50 @@ fun AdaptiveSheet(
}
}
private fun <T> AnchoredDraggableState<T>.preUpPostDownNestedScrollConnection() = object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
val delta = available.toFloat()
return if (delta < 0 && source == NestedScrollSource.Drag) {
dispatchRawDelta(delta).toOffset()
} else {
Offset.Zero
private fun <T> AnchoredDraggableState<T>.preUpPostDownNestedScrollConnection() =
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
val delta = available.toFloat()
return if (delta < 0 && source == NestedScrollSource.Drag) {
dispatchRawDelta(delta).toOffset()
} else {
Offset.Zero
}
}
}
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource,
): Offset {
return if (source == NestedScrollSource.Drag) {
dispatchRawDelta(available.toFloat()).toOffset()
} else {
Offset.Zero
override fun onPostScroll(
consumed: Offset,
available: Offset,
source: NestedScrollSource,
): Offset {
return if (source == NestedScrollSource.Drag) {
dispatchRawDelta(available.toFloat()).toOffset()
} else {
Offset.Zero
}
}
}
override suspend fun onPreFling(available: Velocity): Velocity {
val toFling = available.toFloat()
return if (toFling < 0 && offset > anchors.minAnchor()) {
settle(toFling)
// since we go to the anchor with tween settling, consume all for the best UX
available
} else {
Velocity.Zero
override suspend fun onPreFling(available: Velocity): Velocity {
val toFling = available.toFloat()
return if (toFling < 0 && offset > anchors.minAnchor()) {
settle(toFling)
// since we go to the anchor with tween settling, consume all for the best UX
available
} else {
Velocity.Zero
}
}
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
settle(velocity = available.toFloat())
return available
}
private fun Float.toOffset(): Offset = Offset(0f, this)
@JvmName("velocityToFloat")
private fun Velocity.toFloat() = this.y
@JvmName("offsetToFloat")
private fun Offset.toFloat(): Float = this.y
}
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
settle(velocity = available.toFloat())
return available
}
private fun Float.toOffset(): Offset = Offset(0f, this)
@JvmName("velocityToFloat")
private fun Velocity.toFloat() = this.y
@JvmName("offsetToFloat")
private fun Offset.toFloat(): Float = this.y
}

View File

@ -37,9 +37,7 @@ import androidx.compose.ui.tooling.preview.Preview
* By always rotating we give the feedback to the user that the application isn't 'stuck'.
*/
@Composable
fun CombinedCircularProgressIndicator(
progress: Float,
) {
fun CombinedCircularProgressIndicator(progress: Float) {
val animatedProgress by animateFloatAsState(
targetValue = progress,
animationSpec = ProgressIndicatorDefaults.ProgressAnimationSpec,

View File

@ -23,10 +23,7 @@ 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 {

View File

@ -11,12 +11,7 @@ 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(modifier: Modifier = Modifier, label: String, icon: ImageVector, url: String) {
val uriHandler = LocalUriHandler.current
IconButton(
modifier = modifier.padding(4.dp),

View File

@ -9,10 +9,7 @@ import androidx.compose.ui.text.font.FontWeight
import tachiyomi.presentation.core.components.material.padding
@Composable
fun ListGroupHeader(
modifier: Modifier = Modifier,
text: String,
) {
fun ListGroupHeader(modifier: Modifier = Modifier, text: String) {
Text(
text = text,
modifier = modifier

View File

@ -51,16 +51,12 @@ object SettingsItemsPaddings {
}
@Composable
fun HeadingItem(
@StringRes labelRes: Int,
) {
fun HeadingItem(@StringRes labelRes: Int) {
HeadingItem(stringResource(labelRes))
}
@Composable
fun HeadingItem(
text: String,
) {
fun HeadingItem(text: String) {
Text(
text = text,
style = MaterialTheme.typography.header,
@ -74,11 +70,7 @@ fun HeadingItem(
}
@Composable
fun IconItem(
label: String,
icon: ImageVector,
onClick: () -> Unit,
) {
fun IconItem(label: String, icon: ImageVector, onClick: () -> Unit) {
BaseSettingsItem(
label = label,
widget = {
@ -93,11 +85,7 @@ fun IconItem(
}
@Composable
fun SortItem(
label: String,
sortDescending: Boolean?,
onClick: () -> Unit,
) {
fun SortItem(label: String, sortDescending: Boolean?, onClick: () -> Unit) {
val arrowIcon = when (sortDescending) {
true -> Icons.Default.ArrowDownward
false -> Icons.Default.ArrowUpward
@ -122,10 +110,7 @@ fun SortItem(
}
@Composable
fun CheckboxItem(
label: String,
pref: Preference<Boolean>,
) {
fun CheckboxItem(label: String, pref: Preference<Boolean>) {
val checked by pref.collectAsState()
CheckboxItem(
label = label,
@ -135,11 +120,7 @@ fun CheckboxItem(
}
@Composable
fun CheckboxItem(
label: String,
checked: Boolean,
onClick: () -> Unit,
) {
fun CheckboxItem(label: String, checked: Boolean, onClick: () -> Unit) {
BaseSettingsItem(
label = label,
widget = {
@ -153,11 +134,7 @@ fun CheckboxItem(
}
@Composable
fun RadioItem(
label: String,
selected: Boolean,
onClick: () -> Unit,
) {
fun RadioItem(label: String, selected: Boolean, onClick: () -> Unit) {
BaseSettingsItem(
label = label,
widget = {
@ -314,11 +291,7 @@ fun TriStateItem(
}
@Composable
fun TextItem(
label: String,
value: String,
onChange: (String) -> Unit,
) {
fun TextItem(label: String, value: String, onChange: (String) -> Unit) {
OutlinedTextField(
modifier = Modifier
.fillMaxWidth()
@ -331,10 +304,7 @@ fun TextItem(
}
@Composable
fun SettingsChipRow(
@StringRes labelRes: Int,
content: @Composable FlowRowScope.() -> Unit,
) {
fun SettingsChipRow(@StringRes labelRes: Int, content: @Composable FlowRowScope.() -> Unit) {
Column {
HeadingItem(labelRes)
FlowRow(

View File

@ -197,7 +197,8 @@ private fun rememberColumnWidthSums(
horizontalArrangement,
contentPadding,
) {
{ constraints ->
{
constraints ->
require(constraints.maxWidth != Constraints.Infinity) {
"LazyVerticalGrid's width should be bound by parent"
}

View File

@ -30,7 +30,9 @@ fun AlertDialogContent(
title = title,
content = {
Column {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onSurfaceVariant,
) {
val textStyle = MaterialTheme.typography.bodyMedium
ProvideTextStyle(textStyle) {
Box(
@ -54,7 +56,9 @@ fun AlertDialogContent(
)
.align(Alignment.End),
) {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.primary) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.primary,
) {
val textStyle = MaterialTheme.typography.labelLarge
ProvideTextStyle(value = textStyle, content = buttons)
}
@ -86,7 +90,9 @@ fun AlertDialogContent(
.fillMaxWidth(),
) {
icon?.let {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.secondary) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.secondary,
) {
Box(
Modifier
.padding(IconPadding)
@ -97,7 +103,9 @@ fun AlertDialogContent(
}
}
title?.let {
CompositionLocalProvider(LocalContentColor provides MaterialTheme.colorScheme.onSurface) {
CompositionLocalProvider(
LocalContentColor provides MaterialTheme.colorScheme.onSurface,
) {
val textStyle = MaterialTheme.typography.headlineSmall
ProvideTextStyle(textStyle) {
Box(

View File

@ -64,20 +64,19 @@ fun TextButton(
),
contentPadding: PaddingValues = M3ButtonDefaults.TextButtonContentPadding,
content: @Composable RowScope.() -> Unit,
) =
Button(
onClick = onClick,
modifier = modifier,
onLongClick = onLongClick,
enabled = enabled,
interactionSource = interactionSource,
elevation = elevation,
shape = shape,
border = border,
colors = colors,
contentPadding = contentPadding,
content = content,
)
) = Button(
onClick = onClick,
modifier = modifier,
onLongClick = onLongClick,
enabled = enabled,
interactionSource = interactionSource,
elevation = elevation,
shape = shape,
border = border,
colors = colors,
contentPadding = contentPadding,
content = content,
)
/**
* Button with additional onLongClick functionality.

View File

@ -48,7 +48,10 @@ fun NavigationRail(
.padding(vertical = MaterialTheme.padding.tiny)
.selectableGroup(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(MaterialTheme.padding.tiny, alignment = Alignment.CenterVertically),
verticalArrangement = Arrangement.spacedBy(
MaterialTheme.padding.tiny,
alignment = Alignment.CenterVertically,
),
) {
if (header != null) {
header()

View File

@ -99,7 +99,9 @@ import kotlin.math.max
@Composable
fun Scaffold(
modifier: Modifier = Modifier,
topBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(rememberTopAppBarState()),
topBarScrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior(
rememberTopAppBarState(),
),
topBar: @Composable (TopAppBarScrollBehavior) -> Unit = {},
bottomBar: @Composable () -> Unit = {},
startBar: @Composable () -> Unit = {},
@ -116,7 +118,11 @@ fun Scaffold(
androidx.compose.material3.Surface(
modifier = Modifier
.nestedScroll(topBarScrollBehavior.nestedScrollConnection)
.onConsumedWindowInsetsChanged { remainingWindowInsets.insets = contentWindowInsets.exclude(it) }
.onConsumedWindowInsetsChanged {
remainingWindowInsets.insets = contentWindowInsets.exclude(
it,
)
}
.then(modifier),
color = containerColor,
contentColor = contentColor,
@ -271,7 +277,10 @@ private fun ScaffoldLayout(
} else {
max(bottomBarHeightPx.toDp(), fabOffsetDp)
},
start = max(insets.calculateStartPadding((this@SubcomposeLayout).layoutDirection), startBarWidth.toDp()),
start = max(
insets.calculateStartPadding((this@SubcomposeLayout).layoutDirection),
startBarWidth.toDp(),
),
end = insets.calculateEndPadding((this@SubcomposeLayout).layoutDirection),
)
content(innerPadding)

View File

@ -104,9 +104,7 @@ private fun surfaceColorAtElevation(color: Color, elevation: Dp): Color {
}
}
private fun ColorScheme.surfaceColorAtElevation(
elevation: Dp,
): Color {
private fun ColorScheme.surfaceColorAtElevation(elevation: Dp): Color {
if (elevation == 0.dp) return surface
val alpha = ((4.5f * ln(elevation.value + 1)) + 2f) / 100f
return surfaceTint.copy(alpha = alpha).compositeOver(surface)

View File

@ -46,10 +46,7 @@ private fun Modifier.tabIndicatorOffset(
}
@Composable
fun TabIndicator(
currentTabPosition: TabPosition,
currentPageOffsetFraction: Float,
) {
fun TabIndicator(currentTabPosition: TabPosition, currentPageOffsetFraction: Float) {
SecondaryIndicator(
modifier = Modifier
.tabIndicatorOffset(currentTabPosition, currentPageOffsetFraction)
@ -59,10 +56,7 @@ fun TabIndicator(
}
@Composable
fun TabText(
text: String,
badgeCount: Int? = null,
) {
fun TabText(text: String, badgeCount: Int? = null) {
val pillAlpha = if (isSystemInDarkTheme()) 0.12f else 0.08f
Row(