Add Konsist test to check that toPersistentList() is not used.

Same for `toPersistentSet()` and `toPersistentMap()`.
Fix existing issues.
This commit is contained in:
Benoit Marty 2025-10-08 14:25:15 +02:00
parent 2fa1b9d448
commit 67c9daa0bf
85 changed files with 305 additions and 254 deletions

View file

@ -35,7 +35,7 @@ import io.element.android.libraries.designsystem.components.media.drawWaveform
import io.element.android.libraries.designsystem.preview.ElementPreview
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.toImmutableList
import java.lang.Float.min
private const val DEFAULT_GRAPHICS_LAYER_ALPHA: Float = 0.99F
@ -62,21 +62,21 @@ fun LiveWaveformView(
Box(
contentAlignment = Alignment.CenterEnd,
modifier = modifier
.fillMaxWidth()
.height(waveFormHeight)
.onSizeChanged { parentWidth = it.width }
.fillMaxWidth()
.height(waveFormHeight)
.onSizeChanged { parentWidth = it.width }
) {
Canvas(
modifier = Modifier
.width(Dp(waveformWidth))
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
.then(modifier)
.width(Dp(waveformWidth))
.graphicsLayer(alpha = DEFAULT_GRAPHICS_LAYER_ALPHA)
.then(modifier)
) {
val width = min(waveformWidth, parentWidth.toFloat())
canvasSize = DpSize(width.dp, size.height.toDp())
val countThatFitsWidth = (parentWidth.toFloat() / (lineWidth.toPx() + linePadding.toPx())).toInt()
drawWaveform(
waveformData = levels.takeLast(countThatFitsWidth).toPersistentList(),
waveformData = levels.takeLast(countThatFitsWidth).toImmutableList(),
canvasSizePx = Size(canvasSize.width.toPx(), size.height),
brush = brush,
lineWidth = lineWidth,
@ -91,11 +91,11 @@ fun LiveWaveformView(
internal fun LiveWaveformViewPreview() = ElementPreview {
Column {
LiveWaveformView(
levels = List(100) { it.toFloat() / 100 }.toPersistentList(),
levels = List(100) { it.toFloat() / 100 }.toImmutableList(),
modifier = Modifier.height(34.dp),
)
LiveWaveformView(
levels = List(40) { it.toFloat() / 40 }.toPersistentList(),
levels = List(40) { it.toFloat() / 40 }.toImmutableList(),
modifier = Modifier.height(34.dp),
)
}

View file

@ -35,7 +35,7 @@ import io.element.android.libraries.designsystem.preview.PreviewsDayNight
import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.ui.utils.time.formatShort
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toPersistentList
import kotlinx.collections.immutable.toImmutableList
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
@ -101,5 +101,5 @@ private fun RedRecordingDot() {
@PreviewsDayNight
@Composable
internal fun VoiceMessageRecordingPreview() = ElementPreview {
VoiceMessageRecording(List(100) { it.toFloat() / 100 }.toPersistentList(), 0.seconds)
VoiceMessageRecording(List(100) { it.toFloat() / 100 }.toImmutableList(), 0.seconds)
}