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
|
package me.zobrist.tichucounter.domain
|
||||||
|
|
||||||
import me.zobrist.tichucounter.data.GameWithScores
|
import me.zobrist.tichucounter.data.GameWithScores
|
||||||
|
|
||||||
class GameWithScoresExtension {
|
|
||||||
}
|
|
||||||
|
|
||||||
fun GameWithScores.getTotalPoints(): Pair<Int, Int> {
|
fun GameWithScores.getTotalPoints(): Pair<Int, Int> {
|
||||||
var scoreA = 0
|
var scoreA = 0
|
||||||
var scoreB = 0
|
var scoreB = 0
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class GameRepository @Inject constructor(
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val active = activeGame
|
val active = activeGame
|
||||||
active.modified = Date()
|
active.modified = Date()
|
||||||
val round = Round(active.uid!!, scoreA, scoreB)
|
val round = Round(active.uid, scoreA, scoreB)
|
||||||
roundDao.insert(round)
|
roundDao.insert(round)
|
||||||
gameDao.update(active)
|
gameDao.update(active)
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ class GameRepository @Inject constructor(
|
|||||||
suspend fun deleteGame(uid: Long) {
|
suspend fun deleteGame(uid: Long) {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
gameDao.getGameById(uid).take(1).collect() {
|
gameDao.getGameById(uid).take(1).collect {
|
||||||
gameDao.delete(it)
|
gameDao.delete(it)
|
||||||
val rounds = roundDao.getAllForGame(it.uid)
|
val rounds = roundDao.getAllForGame(it.uid)
|
||||||
roundDao.delete(rounds)
|
roundDao.delete(rounds)
|
||||||
@@ -105,7 +105,7 @@ class GameRepository @Inject constructor(
|
|||||||
suspend fun deleteAllInactive() {
|
suspend fun deleteAllInactive() {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
gameDao.getAll().take(1).collect() { games ->
|
gameDao.getAll().take(1).collect { games ->
|
||||||
|
|
||||||
val activeId = games.first { it.active }.uid
|
val activeId = games.first { it.active }.uid
|
||||||
val gamesToDelete = games.filter { !it.active }
|
val gamesToDelete = games.filter { !it.active }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
@file:Suppress("unused")
|
||||||
|
|
||||||
package me.zobrist.tichucounter.ui
|
package me.zobrist.tichucounter.ui
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
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)) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -46,7 +46,7 @@ interface IKeyBoardViewModel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ICounterViewModel: IKeyBoardViewModel {
|
interface ICounterViewModel : IKeyBoardViewModel {
|
||||||
val roundScoreList: List<Round>
|
val roundScoreList: List<Round>
|
||||||
val totalScoreA: Int
|
val totalScoreA: Int
|
||||||
val totalScoreB: Int
|
val totalScoreB: Int
|
||||||
@@ -156,9 +156,9 @@ class CounterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun focusLastInput() {
|
override fun focusLastInput() {
|
||||||
when(lastFocused){
|
when (lastFocused) {
|
||||||
Focused.TEAM_A -> if(!isAFocused) requestFocusA.requestFocus()
|
Focused.TEAM_A -> if (!isAFocused) requestFocusA.requestFocus()
|
||||||
Focused.TEAM_B -> if(!isBFocused) requestFocusB.requestFocus()
|
Focused.TEAM_B -> if (!isBFocused) requestFocusB.requestFocus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,14 +261,14 @@ class CounterViewModel @Inject constructor(
|
|||||||
|
|
||||||
override fun updateFocusStateA(state: Boolean) {
|
override fun updateFocusStateA(state: Boolean) {
|
||||||
isAFocused = state
|
isAFocused = state
|
||||||
if(state){
|
if (state) {
|
||||||
lastFocused = Focused.TEAM_A
|
lastFocused = Focused.TEAM_A
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun updateFocusStateB(state: Boolean) {
|
override fun updateFocusStateB(state: Boolean) {
|
||||||
isBFocused = state
|
isBFocused = state
|
||||||
if(state){
|
if (state) {
|
||||||
lastFocused = Focused.TEAM_B
|
lastFocused = Focused.TEAM_B
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,10 +246,9 @@ fun CenteredTextField(
|
|||||||
onFocusStateChanged: (FocusState) -> Unit
|
onFocusStateChanged: (FocusState) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val modifier = if(focusRequester != null) {
|
val modifier = if (focusRequester != null) {
|
||||||
Modifier.focusRequester(focusRequester)
|
Modifier.focusRequester(focusRequester)
|
||||||
} else
|
} else {
|
||||||
{
|
|
||||||
Modifier
|
Modifier
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +257,7 @@ fun CenteredTextField(
|
|||||||
value = value,
|
value = value,
|
||||||
onValueChange = { },
|
onValueChange = { },
|
||||||
placeholder = {
|
placeholder = {
|
||||||
if(!focused){
|
if (!focused) {
|
||||||
Text(
|
Text(
|
||||||
placeholder,
|
placeholder,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
@@ -275,8 +274,7 @@ fun CenteredTextField(
|
|||||||
onFocusStateChanged(it)
|
onFocusStateChanged(it)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if(focused)
|
if (focused) {
|
||||||
{
|
|
||||||
val cursorColor = MaterialTheme.colorScheme.onSurface
|
val cursorColor = MaterialTheme.colorScheme.onSurface
|
||||||
val infiniteTransition = rememberInfiniteTransition()
|
val infiniteTransition = rememberInfiniteTransition()
|
||||||
val alpha by infiniteTransition.animateFloat(
|
val alpha by infiniteTransition.animateFloat(
|
||||||
@@ -295,7 +293,8 @@ fun CenteredTextField(
|
|||||||
.padding(start = 3.dp, top = 15.dp, bottom = 15.dp)
|
.padding(start = 3.dp, top = 15.dp, bottom = 15.dp)
|
||||||
.width(1.dp)
|
.width(1.dp)
|
||||||
.fillMaxHeight(),
|
.fillMaxHeight(),
|
||||||
color = cursorColor.copy(alpha = alpha))
|
color = cursorColor.copy(alpha = alpha)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package me.zobrist.tichucounter.ui.history
|
package me.zobrist.tichucounter.ui.history
|
||||||
|
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Delete
|
import androidx.compose.material.icons.outlined.MoreVert
|
||||||
import androidx.compose.material.icons.outlined.OpenInFull
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
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.Game
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||||
|
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@@ -103,7 +104,8 @@ fun HistoryListItem(
|
|||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 4.dp),
|
.padding(all = 4.dp)
|
||||||
|
.clickable { onOpenClicked(game.game.uid) },
|
||||||
colors = cardColor
|
colors = cardColor
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -130,16 +132,33 @@ fun HistoryListItem(
|
|||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.wrapContentSize()
|
.wrapContentSize()
|
||||||
.width(70.dp)
|
.width(40.dp)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
ElevatedButton(onClick = { onOpenClicked(game.game.uid) }, enabled = true) {
|
if (!game.game.active) {
|
||||||
Icon(Icons.Outlined.OpenInFull, null)
|
var expanded by remember { mutableStateOf(false) }
|
||||||
}
|
|
||||||
ElevatedButton(
|
Icon(
|
||||||
onClick = { onDeleteClicked(game.game.uid) }, enabled = !game.game.active
|
modifier = Modifier
|
||||||
) {
|
.padding(start = 20.dp, bottom = 20.dp)
|
||||||
Icon(Icons.Outlined.Delete, null)
|
.clickable { expanded = true },
|
||||||
|
imageVector = Icons.Outlined.MoreVert,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
DropDownMenu(
|
||||||
|
mapOf("delete" to R.string.delete),
|
||||||
|
"",
|
||||||
|
expanded,
|
||||||
|
) {
|
||||||
|
expanded = false
|
||||||
|
it?.let {
|
||||||
|
when (it) {
|
||||||
|
"delete" -> onDeleteClicked(game.game.uid)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ class HistoryViewModel @Inject constructor(
|
|||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
||||||
gameRepository.getAllWithRoundFlow().collect() { games ->
|
gameRepository.getAllWithRoundFlow().collect { games ->
|
||||||
gameAndHistory = 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.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||||
import androidx.compose.material.icons.outlined.Check
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment.Companion.End
|
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.Language
|
||||||
import me.zobrist.tichucounter.domain.Theme
|
import me.zobrist.tichucounter.domain.Theme
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
|
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||||
|
|
||||||
|
|
||||||
val languageMap = mapOf(
|
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 = "Light Mode")
|
||||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||||
|
|||||||
@@ -13,11 +13,10 @@
|
|||||||
<string name="on">Ein</string>
|
<string name="on">Ein</string>
|
||||||
<string name="off">Aus</string>
|
<string name="off">Aus</string>
|
||||||
<string name="newGame">Neues Spiel</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_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="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="cancel">Abbrechen</string>
|
||||||
<string name="ok">Ok</string>
|
<string name="ok">Ok</string>
|
||||||
|
<string name="delete">Löschen</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -16,10 +16,9 @@
|
|||||||
<string name="on">On</string>
|
<string name="on">On</string>
|
||||||
<string name="off">Off</string>
|
<string name="off">Off</string>
|
||||||
<string name="newGame">New Game</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_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="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="cancel">Cancel</string>
|
||||||
<string name="ok">Ok</string>
|
<string name="ok">Ok</string>
|
||||||
|
<string name="delete">Delete</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user