Simplify history page. Fix warnings.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
|
||||
class GameWithScoresExtension {
|
||||
}
|
||||
|
||||
fun GameWithScores.getTotalPoints(): Pair<Int, Int> {
|
||||
var scoreA = 0
|
||||
var scoreB = 0
|
||||
|
||||
@@ -83,7 +83,7 @@ class GameRepository @Inject constructor(
|
||||
withContext(Dispatchers.IO) {
|
||||
val active = activeGame
|
||||
active.modified = Date()
|
||||
val round = Round(active.uid!!, scoreA, scoreB)
|
||||
val round = Round(active.uid, scoreA, scoreB)
|
||||
roundDao.insert(round)
|
||||
gameDao.update(active)
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class GameRepository @Inject constructor(
|
||||
suspend fun deleteGame(uid: Long) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
gameDao.getGameById(uid).take(1).collect() {
|
||||
gameDao.getGameById(uid).take(1).collect {
|
||||
gameDao.delete(it)
|
||||
val rounds = roundDao.getAllForGame(it.uid)
|
||||
roundDao.delete(rounds)
|
||||
@@ -105,7 +105,7 @@ class GameRepository @Inject constructor(
|
||||
suspend fun deleteAllInactive() {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
gameDao.getAll().take(1).collect() { games ->
|
||||
gameDao.getAll().take(1).collect { games ->
|
||||
|
||||
val activeId = games.first { it.active }.uid
|
||||
val gamesToDelete = games.filter { !it.active }
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package me.zobrist.tichucounter.ui
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package me.zobrist.tichucounter.ui.composables
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
|
||||
@Composable
|
||||
fun <T> DropDownMenu(map: Map<T, Int>, selected: T, expanded: Boolean, onSelected: (T?) -> Unit) {
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onSelected(null) }
|
||||
) {
|
||||
map.forEach {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onSelected(it.key)
|
||||
},
|
||||
trailingIcon = {
|
||||
if (it.key == selected) {
|
||||
Icon(Icons.Outlined.Check, null)
|
||||
}
|
||||
},
|
||||
text = { Text(stringResource(it.value)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,8 +248,7 @@ fun CenteredTextField(
|
||||
|
||||
val modifier = if (focusRequester != null) {
|
||||
Modifier.focusRequester(focusRequester)
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
|
||||
@@ -275,8 +274,7 @@ fun CenteredTextField(
|
||||
onFocusStateChanged(it)
|
||||
}
|
||||
)
|
||||
if(focused)
|
||||
{
|
||||
if (focused) {
|
||||
val cursorColor = MaterialTheme.colorScheme.onSurface
|
||||
val infiniteTransition = rememberInfiniteTransition()
|
||||
val alpha by infiniteTransition.animateFloat(
|
||||
@@ -295,7 +293,8 @@ fun CenteredTextField(
|
||||
.padding(start = 3.dp, top = 15.dp, bottom = 15.dp)
|
||||
.width(1.dp)
|
||||
.fillMaxHeight(),
|
||||
color = cursorColor.copy(alpha = alpha))
|
||||
color = cursorColor.copy(alpha = alpha)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package me.zobrist.tichucounter.ui.history
|
||||
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
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.Delete
|
||||
import androidx.compose.material.icons.outlined.OpenInFull
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -19,6 +19,7 @@ import me.zobrist.tichucounter.data.GameWithScores
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
|
||||
@@ -103,7 +104,8 @@ fun HistoryListItem(
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(all = 4.dp),
|
||||
.padding(all = 4.dp)
|
||||
.clickable { onOpenClicked(game.game.uid) },
|
||||
colors = cardColor
|
||||
) {
|
||||
Row(
|
||||
@@ -130,16 +132,33 @@ fun HistoryListItem(
|
||||
Column(
|
||||
Modifier
|
||||
.wrapContentSize()
|
||||
.width(70.dp)
|
||||
.width(40.dp)
|
||||
) {
|
||||
|
||||
ElevatedButton(onClick = { onOpenClicked(game.game.uid) }, enabled = true) {
|
||||
Icon(Icons.Outlined.OpenInFull, null)
|
||||
}
|
||||
ElevatedButton(
|
||||
onClick = { onDeleteClicked(game.game.uid) }, enabled = !game.game.active
|
||||
if (!game.game.active) {
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
Icon(
|
||||
modifier = Modifier
|
||||
.padding(start = 20.dp, bottom = 20.dp)
|
||||
.clickable { expanded = true },
|
||||
imageVector = Icons.Outlined.MoreVert,
|
||||
contentDescription = null
|
||||
)
|
||||
|
||||
|
||||
DropDownMenu(
|
||||
mapOf("delete" to R.string.delete),
|
||||
"",
|
||||
expanded,
|
||||
) {
|
||||
Icon(Icons.Outlined.Delete, null)
|
||||
expanded = false
|
||||
it?.let {
|
||||
when (it) {
|
||||
"delete" -> onDeleteClicked(game.game.uid)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,8 +23,9 @@ class HistoryViewModel @Inject constructor(
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
|
||||
gameRepository.getAllWithRoundFlow().collect() { games ->
|
||||
gameAndHistory = games
|
||||
gameRepository.getAllWithRoundFlow().collect { games ->
|
||||
gameAndHistory =
|
||||
games.sortedBy { it.game.modified }.sortedBy { it.game.active }.reversed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment.Companion.End
|
||||
@@ -22,6 +21,7 @@ import me.zobrist.tichucounter.domain.KeepScreenOn
|
||||
import me.zobrist.tichucounter.domain.Language
|
||||
import me.zobrist.tichucounter.domain.Theme
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
|
||||
|
||||
val languageMap = mapOf(
|
||||
@@ -146,27 +146,6 @@ fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> DropDownMenu(map: Map<T, Int>, selected: T, expanded: Boolean, onSelected: (T?) -> Unit) {
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onSelected(null) }
|
||||
) {
|
||||
map.forEach {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onSelected(it.key)
|
||||
},
|
||||
trailingIcon = {
|
||||
if (it.key == selected) {
|
||||
Icon(Icons.Outlined.Check, null)
|
||||
}
|
||||
},
|
||||
text = { Text(stringResource(it.value)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||
|
||||
@@ -13,11 +13,10 @@
|
||||
<string name="on">Ein</string>
|
||||
<string name="off">Aus</string>
|
||||
<string name="newGame">Neues Spiel</string>
|
||||
<string name="created">"Erstellt: %s "</string>
|
||||
<string name="modified">Bearbeitet: %s</string>
|
||||
<string name="delete_inactive_title">Verlauf löschen</string>
|
||||
<string name="delete_inactive_text">Wirklich den gesamten Verlauf löschen? Diese Aktion kann nicht rückgängig gemacht werden.</string>
|
||||
<string name="cancel">Abbrechen</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="delete">Löschen</string>
|
||||
|
||||
</resources>
|
||||
@@ -16,10 +16,9 @@
|
||||
<string name="on">On</string>
|
||||
<string name="off">Off</string>
|
||||
<string name="newGame">New Game</string>
|
||||
<string name="created">Created: %s</string>
|
||||
<string name="modified">Modified: %s</string>
|
||||
<string name="delete_inactive_title">Delete history</string>
|
||||
<string name="delete_inactive_text">You really want to delete the the history? This action can\'t be undone.</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="delete">Delete</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user