This commit is contained in:
@@ -162,22 +162,9 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
}
|
||||
composable("history") {
|
||||
|
||||
var openDialog by remember { mutableStateOf(false) }
|
||||
HistoryList(historyViewModel) { navController.navigate("counter") }
|
||||
|
||||
HistoryList(historyViewModel, openDialog, { deleteAll ->
|
||||
if (deleteAll) {
|
||||
mainViewModel.deleteAllInactiveGames()
|
||||
}
|
||||
openDialog = false
|
||||
}) { navController.navigate("counter") }
|
||||
topBarActions = listOf(
|
||||
TopBarAction(
|
||||
Icons.Outlined.DeleteForever,
|
||||
true
|
||||
) {
|
||||
openDialog = true
|
||||
}
|
||||
)
|
||||
topBarActions = emptyList()
|
||||
topBarIcon = Icons.Outlined.Menu
|
||||
topBarTitle = stringResource(R.string.menu_history)
|
||||
topBarNavigationAction =
|
||||
|
||||
@@ -72,10 +72,4 @@ class MainViewModel @Inject constructor(
|
||||
gameRepository.newGame()
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteAllInactiveGames() {
|
||||
viewModelScope.launch {
|
||||
gameRepository.deleteAllInactive()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.DeleteForever
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -27,19 +29,27 @@ import java.util.*
|
||||
@Composable
|
||||
fun HistoryList(
|
||||
viewModel: HistoryViewModel,
|
||||
showDeleteDialog: Boolean,
|
||||
onDialogExecuted: (Boolean) -> Unit,
|
||||
navigateToCalculator: () -> Unit
|
||||
) {
|
||||
|
||||
DeleteConfirmDialog(showDeleteDialog, onDialogExecuted)
|
||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||
|
||||
HistoryList(viewModel.gameAndHistory,
|
||||
DeleteConfirmDialog(showDeleteDialog) {
|
||||
showDeleteDialog = false
|
||||
if (it) {
|
||||
viewModel.deleteAllInactiveGames()
|
||||
}
|
||||
}
|
||||
|
||||
HistoryList(
|
||||
viewModel.gameAndHistory,
|
||||
{
|
||||
viewModel.activateGame(it)
|
||||
navigateToCalculator()
|
||||
},
|
||||
{ viewModel.deleteGame(it) })
|
||||
{ viewModel.deleteGame(it) },
|
||||
{ showDeleteDialog = true },
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@@ -71,13 +81,49 @@ fun DeleteConfirmDialog(show: Boolean = true, onExecuted: (Boolean) -> Unit = {}
|
||||
fun HistoryList(
|
||||
games: List<GameWithScores>,
|
||||
onOpenClicked: (GameId: Long) -> Unit,
|
||||
onDeleteClicked: (GameId: Long) -> Unit
|
||||
onDeleteClicked: (GameId: Long) -> Unit,
|
||||
onDeleteAllClicked: () -> Unit
|
||||
|
||||
) {
|
||||
Row {
|
||||
LazyColumn {
|
||||
items(games) {
|
||||
item {
|
||||
Text(
|
||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp),
|
||||
text = stringResource(R.string.active),
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
}
|
||||
items(games.filter { it.game.active }) {
|
||||
HistoryListItem(it, onOpenClicked, onDeleteClicked)
|
||||
}
|
||||
|
||||
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(games.filter { !it.game.active }) {
|
||||
HistoryListItem(it, onOpenClicked, onDeleteClicked)
|
||||
}
|
||||
|
||||
item {
|
||||
Button(
|
||||
enabled = games.count() > 1,
|
||||
modifier = Modifier
|
||||
.padding(start = 4.dp, end = 4.dp, top = 10.dp)
|
||||
.align(CenterVertically)
|
||||
.fillMaxWidth(),
|
||||
onClick = { onDeleteAllClicked() }) {
|
||||
Icon(imageVector = Icons.Outlined.DeleteForever, contentDescription = null)
|
||||
Text(text = stringResource(id = R.string.deleteAll))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,5 +236,5 @@ private fun HistoryListPreview() {
|
||||
listOf(Round(5, 50, 90))
|
||||
)
|
||||
)
|
||||
HistoryList(tempData, {}) {}
|
||||
HistoryList(tempData, {}, {}) {}
|
||||
}
|
||||
|
||||
@@ -42,4 +42,9 @@ class HistoryViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
}
|
||||
fun deleteAllInactiveGames() {
|
||||
viewModelScope.launch {
|
||||
gameRepository.deleteAllInactive()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,5 +18,8 @@
|
||||
<string name="cancel">Abbrechen</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="deleteAll">Alle löschen</string>
|
||||
<string name="active">Aktives Spiel</string>
|
||||
<string name="inactive">Vergangene Spiele</string>
|
||||
|
||||
</resources>
|
||||
@@ -21,4 +21,7 @@
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="deleteAll">Delete all</string>
|
||||
<string name="active">Current Game</string>
|
||||
<string name="inactive">Past Games</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user