Simplify history page. Fix warnings.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-01-27 20:13:14 +01:00
parent 58d4fc0e43
commit cd8f1959af
11 changed files with 86 additions and 60 deletions

View File

@@ -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

View File

@@ -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 }

View File

@@ -1,3 +1,5 @@
@file:Suppress("unused")
package me.zobrist.tichucounter.ui
import androidx.compose.ui.graphics.Color

View File

@@ -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)) },
)
}
}
}

View File

@@ -46,7 +46,7 @@ interface IKeyBoardViewModel {
}
interface ICounterViewModel: IKeyBoardViewModel {
interface ICounterViewModel : IKeyBoardViewModel {
val roundScoreList: List<Round>
val totalScoreA: Int
val totalScoreB: Int
@@ -156,9 +156,9 @@ class CounterViewModel @Inject constructor(
}
override fun focusLastInput() {
when(lastFocused){
Focused.TEAM_A -> if(!isAFocused) requestFocusA.requestFocus()
Focused.TEAM_B -> if(!isBFocused) requestFocusB.requestFocus()
when (lastFocused) {
Focused.TEAM_A -> if (!isAFocused) requestFocusA.requestFocus()
Focused.TEAM_B -> if (!isBFocused) requestFocusB.requestFocus()
}
}
@@ -261,14 +261,14 @@ class CounterViewModel @Inject constructor(
override fun updateFocusStateA(state: Boolean) {
isAFocused = state
if(state){
if (state) {
lastFocused = Focused.TEAM_A
}
}
override fun updateFocusStateB(state: Boolean) {
isBFocused = state
if(state){
if (state) {
lastFocused = Focused.TEAM_B
}
}

View File

@@ -246,10 +246,9 @@ fun CenteredTextField(
onFocusStateChanged: (FocusState) -> Unit
) {
val modifier = if(focusRequester != null) {
val modifier = if (focusRequester != null) {
Modifier.focusRequester(focusRequester)
} else
{
} else {
Modifier
}
@@ -258,7 +257,7 @@ fun CenteredTextField(
value = value,
onValueChange = { },
placeholder = {
if(!focused){
if (!focused) {
Text(
placeholder,
textAlign = TextAlign.Center,
@@ -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)
)
}
}
}

View File

@@ -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)
}
}
}
}
}
}

View File

@@ -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()
}
}
}

View File

@@ -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)

View File

@@ -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>

View File

@@ -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>