feature/swipe-actions #44
@@ -10,9 +10,12 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
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.foundation.layout.requiredHeight
|
||||||
|
import androidx.compose.foundation.layout.requiredWidth
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
@@ -22,9 +25,9 @@ import androidx.compose.material.icons.outlined.Delete
|
|||||||
import androidx.compose.material.icons.outlined.DeleteForever
|
import androidx.compose.material.icons.outlined.DeleteForever
|
||||||
import androidx.compose.material.icons.outlined.RestartAlt
|
import androidx.compose.material.icons.outlined.RestartAlt
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
|
||||||
import androidx.compose.material3.DismissDirection
|
import androidx.compose.material3.DismissDirection
|
||||||
import androidx.compose.material3.DismissValue
|
import androidx.compose.material3.DismissValue
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -45,6 +48,7 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
||||||
|
import androidx.compose.ui.Alignment.Companion.TopEnd
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
@@ -161,33 +165,23 @@ fun HistoryList(
|
|||||||
) {
|
) {
|
||||||
Row {
|
Row {
|
||||||
LazyColumn(state = lazyListState) {
|
LazyColumn(state = lazyListState) {
|
||||||
item {
|
items(
|
||||||
Text(
|
items = games,
|
||||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp),
|
key = { it.hashCode() }) {
|
||||||
text = stringResource(R.string.active),
|
if (it.game.active) {
|
||||||
style = MaterialTheme.typography.headlineSmall
|
HistoryListItem(
|
||||||
|
it,
|
||||||
|
Modifier.animateItemPlacement()
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
items(games.filter { it.game.active }) {
|
|
||||||
HistoryListItem(it, Modifier.animateItemPlacement())
|
|
||||||
}
|
|
||||||
|
|
||||||
if (games.count() > 1) {
|
|
||||||
item {
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp, top = 10.dp),
|
|
||||||
text = stringResource(R.string.inactive),
|
|
||||||
style = MaterialTheme.typography.headlineSmall
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
items(items = games.filter { !it.game.active }, key = {
|
|
||||||
it.hashCode()
|
|
||||||
}) {
|
|
||||||
DismissibleHistoryListItem(
|
DismissibleHistoryListItem(
|
||||||
it, onOpenClicked, onDeleteClicked, Modifier.animateItemPlacement()
|
it,
|
||||||
|
Modifier.animateItemPlacement(),
|
||||||
|
onOpenClicked,
|
||||||
|
onDeleteClicked
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Button(enabled = games.count() > 1,
|
Button(enabled = games.count() > 1,
|
||||||
@@ -203,16 +197,17 @@ fun HistoryList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun DismissibleHistoryListItem(
|
fun DismissibleHistoryListItem(
|
||||||
game: GameWithScores,
|
game: GameWithScores,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
onOpenClicked: (gameId: Long) -> Unit,
|
onOpenClicked: (gameId: Long) -> Unit,
|
||||||
onDeleteClicked: (gameId: Long) -> Unit,
|
onDeleteClicked: (gameId: Long) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
@@ -228,7 +223,18 @@ fun DismissibleHistoryListItem(
|
|||||||
true
|
true
|
||||||
})
|
})
|
||||||
|
|
||||||
SwipeToDismiss(modifier = modifier, state = dismissState, background = {
|
val directions = if (game.game.active) {
|
||||||
|
setOf()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setOf(DismissDirection.EndToStart, DismissDirection.StartToEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeToDismiss(
|
||||||
|
modifier = modifier,
|
||||||
|
state = dismissState,
|
||||||
|
directions = directions,
|
||||||
|
background = {
|
||||||
val direction = dismissState.dismissDirection ?: return@SwipeToDismiss
|
val direction = dismissState.dismissDirection ?: return@SwipeToDismiss
|
||||||
val color by animateColorAsState(
|
val color by animateColorAsState(
|
||||||
when (dismissState.targetValue) {
|
when (dismissState.targetValue) {
|
||||||
@@ -275,6 +281,7 @@ fun DismissibleHistoryListItem(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HistoryListItem(
|
fun HistoryListItem(
|
||||||
game: GameWithScores, modifier: Modifier = Modifier
|
game: GameWithScores, modifier: Modifier = Modifier
|
||||||
@@ -282,25 +289,18 @@ fun HistoryListItem(
|
|||||||
val format =
|
val format =
|
||||||
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
||||||
|
|
||||||
|
|
||||||
val cardColor = if (game.game.active) {
|
|
||||||
CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
CardDefaults.cardColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
val totalScores = game.getTotalPoints()
|
val totalScores = game.getTotalPoints()
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 4.dp), colors = cardColor
|
.padding(all = 4.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
Modifier.padding(all = 12.dp)
|
Modifier.padding(all = 12.dp)
|
||||||
) {
|
) {
|
||||||
Column(Modifier.weight(4f)) {
|
Box( modifier = modifier.fillMaxSize()) {
|
||||||
|
Column {
|
||||||
Text(
|
Text(
|
||||||
text = game.game.nameA + " vs " + game.game.nameB,
|
text = game.game.nameA + " vs " + game.game.nameB,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
@@ -317,6 +317,18 @@ fun HistoryListItem(
|
|||||||
style = MaterialTheme.typography.labelSmall
|
style = MaterialTheme.typography.labelSmall
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
if (game.game.active) {
|
||||||
|
Badge(
|
||||||
|
modifier = Modifier.align(TopEnd),
|
||||||
|
contentColor = MaterialTheme.colorScheme.onPrimary,
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(id = R.string.active),
|
||||||
|
style = MaterialTheme.typography.labelSmall
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -326,7 +338,7 @@ fun HistoryListItem(
|
|||||||
private fun HistoryListPreview() {
|
private fun HistoryListPreview() {
|
||||||
val tempData = listOf(
|
val tempData = listOf(
|
||||||
GameWithScores(
|
GameWithScores(
|
||||||
Game(true, "abc", "def", Date(), Date()), listOf(Round(1, 550, 500))
|
Game(true, "abcsdf sdaf asdf sdf ", "defsadf asdf sadf ", Date(), Date()), listOf(Round(1, 550, 500))
|
||||||
), GameWithScores(
|
), GameWithScores(
|
||||||
Game(false, "ADTH", "dogfg", Date(), Date()), listOf(Round(2, 20, 60))
|
Game(false, "ADTH", "dogfg", Date(), Date()), listOf(Round(2, 20, 60))
|
||||||
), GameWithScores(
|
), GameWithScores(
|
||||||
|
|||||||
Reference in New Issue
Block a user