Use immutable collections in more places

This commit is contained in:
arkon
2023-11-11 22:43:50 -05:00
parent dd998be1e7
commit 336221a972
35 changed files with 252 additions and 152 deletions

View File

@ -36,6 +36,8 @@ dependencies {
implementation(compose.ui.tooling.preview)
implementation(compose.ui.util)
lintChecks(compose.lintchecks)
implementation(kotlinx.immutables)
}
tasks {

View File

@ -36,13 +36,14 @@ fun BadgeGroup(
@Composable
fun Badge(
text: String,
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.secondary,
textColor: Color = MaterialTheme.colorScheme.onSecondary,
shape: Shape = RectangleShape,
) {
Text(
text = text,
modifier = Modifier
modifier = modifier
.clip(shape)
.background(color)
.padding(horizontal = 3.dp, vertical = 1.dp),
@ -56,6 +57,7 @@ fun Badge(
@Composable
fun Badge(
imageVector: ImageVector,
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.secondary,
iconColor: Color = MaterialTheme.colorScheme.onSecondary,
shape: Shape = RectangleShape,
@ -86,7 +88,7 @@ fun Badge(
Text(
text = text,
inlineContent = inlineContent,
modifier = Modifier
modifier = modifier
.clip(shape)
.background(color)
.padding(horizontal = 3.dp, vertical = 1.dp),

View File

@ -41,6 +41,7 @@ import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
@ -54,7 +55,7 @@ import kotlin.math.absoluteValue
@Composable
fun WheelNumberPicker(
items: List<Number>,
items: ImmutableList<Number>,
modifier: Modifier = Modifier,
startIndex: Int = 0,
size: DpSize = DpSize(128.dp, 128.dp),
@ -78,7 +79,7 @@ fun WheelNumberPicker(
@Composable
fun WheelTextPicker(
items: List<String>,
items: ImmutableList<String>,
modifier: Modifier = Modifier,
startIndex: Int = 0,
size: DpSize = DpSize(128.dp, 128.dp),
@ -101,7 +102,7 @@ fun WheelTextPicker(
@Composable
private fun <T> WheelPicker(
items: List<T>,
items: ImmutableList<T>,
modifier: Modifier = Modifier,
startIndex: Int = 0,
size: DpSize = DpSize(128.dp, 128.dp),

View File

@ -23,6 +23,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastForEach
import kotlinx.collections.immutable.ImmutableList
import tachiyomi.presentation.core.components.ActionButton
import tachiyomi.presentation.core.components.material.padding
import tachiyomi.presentation.core.util.secondaryItemAlpha
@ -38,7 +39,7 @@ data class EmptyScreenAction(
fun EmptyScreen(
@StringRes textResource: Int,
modifier: Modifier = Modifier,
actions: List<EmptyScreenAction>? = null,
actions: ImmutableList<EmptyScreenAction>? = null,
) {
EmptyScreen(
message = stringResource(textResource),
@ -51,7 +52,7 @@ fun EmptyScreen(
fun EmptyScreen(
message: String,
modifier: Modifier = Modifier,
actions: List<EmptyScreenAction>? = null,
actions: ImmutableList<EmptyScreenAction>? = null,
) {
val face = remember { getRandomErrorFace() }
Column(
@ -98,7 +99,7 @@ fun EmptyScreen(
}
}
private val ERROR_FACES = listOf(
private val ErrorFaces = listOf(
"(・o・;)",
"Σ(ಠ_ಠ)",
"ಥ_ಥ",
@ -108,5 +109,5 @@ private val ERROR_FACES = listOf(
)
private fun getRandomErrorFace(): String {
return ERROR_FACES[Random.nextInt(ERROR_FACES.size)]
return ErrorFaces[Random.nextInt(ErrorFaces.size)]
}