Add scroll management into the objects list.
This commit is contained in:
parent
3bda885411
commit
5db8e516ba
5 changed files with 51 additions and 38 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package com.pixelized.rplexicon.data.model
|
package com.pixelized.rplexicon.data.model
|
||||||
|
|
||||||
data class ObjectAction(
|
data class ObjectAction(
|
||||||
|
val prefix: String?,
|
||||||
val name: String,
|
val name: String,
|
||||||
val effect: Throw?,
|
val effect: Throw?,
|
||||||
)
|
)
|
||||||
|
|
@ -20,12 +20,12 @@ class ObjectActionParser @Inject constructor(
|
||||||
row.isNotEmpty() -> {
|
row.isNotEmpty() -> {
|
||||||
val character = row[0]?.toItem()
|
val character = row[0]?.toItem()
|
||||||
val name = row.parse(column = NAME)
|
val name = row.parse(column = NAME)
|
||||||
val effect = throwParser.parse(value = row.parse(column = EFFECT))
|
if (character != null && name != null) {
|
||||||
if (character != null && name != null && effect != null) {
|
|
||||||
objects.getOrPut(character) { mutableListOf() }.add(
|
objects.getOrPut(character) { mutableListOf() }.add(
|
||||||
ObjectAction(
|
ObjectAction(
|
||||||
|
prefix = row.parse(column = PREFIX),
|
||||||
name = name,
|
name = name,
|
||||||
effect = effect,
|
effect = throwParser.parse(value = row.parse(column = EFFECT)),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -37,8 +37,9 @@ class ObjectActionParser @Inject constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private val PREFIX = column("Préfix")
|
||||||
private val NAME = column("Nom")
|
private val NAME = column("Nom")
|
||||||
private val EFFECT = column("Effet")
|
private val EFFECT = column("Effet")
|
||||||
private val COLUMNS = listOf(NAME, EFFECT)
|
private val COLUMNS = listOf(PREFIX, NAME, EFFECT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -6,12 +6,11 @@ import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.material.minimumInteractiveComponentSize
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
|
|
@ -27,15 +26,17 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.pixelized.rplexicon.R
|
import com.pixelized.rplexicon.R
|
||||||
|
import com.pixelized.rplexicon.data.model.Throw
|
||||||
import com.pixelized.rplexicon.ui.theme.LexiconTheme
|
import com.pixelized.rplexicon.ui.theme.LexiconTheme
|
||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
data class ObjectItemUio(
|
data class ObjectItemUio(
|
||||||
|
val prefix: String?,
|
||||||
val name: String,
|
val name: String,
|
||||||
val original: String?,
|
val original: String?,
|
||||||
|
val effect: Throw?,
|
||||||
)
|
)
|
||||||
|
|
||||||
@OptIn(ExperimentalLayoutApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ObjectItem(
|
fun ObjectItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
|
@ -47,6 +48,7 @@ fun ObjectItem(
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable { onObject(item) }
|
.clickable { onObject(item) }
|
||||||
|
.minimumInteractiveComponentSize()
|
||||||
.padding(paddingValues = padding)
|
.padding(paddingValues = padding)
|
||||||
.then(other = modifier),
|
.then(other = modifier),
|
||||||
horizontalArrangement = Arrangement.spacedBy(space = 12.dp),
|
horizontalArrangement = Arrangement.spacedBy(space = 12.dp),
|
||||||
|
|
@ -54,21 +56,16 @@ fun ObjectItem(
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.weight(weight = 1f)
|
modifier = Modifier.weight(weight = 1f)
|
||||||
) {
|
|
||||||
FlowRow(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(space = 4.dp),
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.alignByBaseline(),
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
text = item.name,
|
text = item.prefix?.let { "$it${item.name}" } ?: item.name,
|
||||||
)
|
)
|
||||||
item.original?.let {
|
item.original?.let {
|
||||||
Text(
|
Text(
|
||||||
modifier = Modifier.alignByBaseline(),
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
fontWeight = FontWeight.Light,
|
fontWeight = FontWeight.Light,
|
||||||
fontStyle = FontStyle.Italic,
|
fontStyle = FontStyle.Italic,
|
||||||
|
|
@ -78,8 +75,8 @@ fun ObjectItem(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
if (item.effect != null) {
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
border = BorderStroke(
|
border = BorderStroke(
|
||||||
width = 1.dp,
|
width = 1.dp,
|
||||||
|
|
@ -93,6 +90,7 @@ fun ObjectItem(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@Preview(uiMode = UI_MODE_NIGHT_NO)
|
@Preview(uiMode = UI_MODE_NIGHT_NO)
|
||||||
|
|
@ -103,8 +101,10 @@ private fun ObjectItemPreview() {
|
||||||
ObjectItem(
|
ObjectItem(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
item = ObjectItemUio(
|
item = ObjectItemUio(
|
||||||
name = "Potion de guérison",
|
prefix = "Parchemin de ",
|
||||||
original = "Healing potion",
|
name = "Bénédiction",
|
||||||
|
original = "Blessing",
|
||||||
|
effect = Throw(1, 1, 0, emptyList()),
|
||||||
),
|
),
|
||||||
onObject = { },
|
onObject = { },
|
||||||
onUse = { },
|
onUse = { },
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import com.pixelized.rplexicon.data.model.Throw
|
||||||
import com.pixelized.rplexicon.ui.screens.character.composable.actions.ObjectItemUio
|
import com.pixelized.rplexicon.ui.screens.character.composable.actions.ObjectItemUio
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
@ -12,8 +13,16 @@ fun rememberObjectListStatePreview() = remember {
|
||||||
mutableStateOf(
|
mutableStateOf(
|
||||||
listOf(
|
listOf(
|
||||||
ObjectItemUio(
|
ObjectItemUio(
|
||||||
|
prefix = null,
|
||||||
name = "Potion de guérison",
|
name = "Potion de guérison",
|
||||||
original = "Healing potion",
|
original = "Healing potion",
|
||||||
|
effect = null,
|
||||||
|
),
|
||||||
|
ObjectItemUio(
|
||||||
|
prefix = "Parchemin de",
|
||||||
|
name = "Bénédiction",
|
||||||
|
original = "Blessing",
|
||||||
|
effect = Throw(1, 1, 0, emptyList()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,10 @@ class ObjectsViewModel @Inject constructor(
|
||||||
objectsRepository.data.collect { objects ->
|
objectsRepository.data.collect { objects ->
|
||||||
val data = objects[character]?.map {
|
val data = objects[character]?.map {
|
||||||
ObjectItemUio(
|
ObjectItemUio(
|
||||||
|
prefix = it.prefix,
|
||||||
name = it.name,
|
name = it.name,
|
||||||
original = descriptionRepository.find(name = it.name)?.original
|
original = descriptionRepository.find(name = it.name)?.original,
|
||||||
|
effect = it.effect,
|
||||||
)
|
)
|
||||||
} ?: emptyList()
|
} ?: emptyList()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue