Move new game back to app bar.
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:
@@ -33,6 +33,7 @@ import me.zobrist.tichucounter.repository.GameRepository
|
|||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
import me.zobrist.tichucounter.ui.MainViewModel
|
import me.zobrist.tichucounter.ui.MainViewModel
|
||||||
import me.zobrist.tichucounter.ui.TopBar
|
import me.zobrist.tichucounter.ui.TopBar
|
||||||
|
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||||
import me.zobrist.tichucounter.ui.counter.*
|
import me.zobrist.tichucounter.ui.counter.*
|
||||||
import me.zobrist.tichucounter.ui.history.HistoryList
|
import me.zobrist.tichucounter.ui.history.HistoryList
|
||||||
import me.zobrist.tichucounter.ui.history.HistoryViewModel
|
import me.zobrist.tichucounter.ui.history.HistoryViewModel
|
||||||
@@ -126,24 +127,45 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
{ topBarNavigationAction.action() },
|
{ topBarNavigationAction.action() },
|
||||||
topBarActions
|
topBarActions
|
||||||
)
|
)
|
||||||
}) {
|
}) { paddings ->
|
||||||
|
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = "counter",
|
startDestination = "counter",
|
||||||
modifier = Modifier.padding(it)
|
modifier = Modifier.padding(paddings)
|
||||||
) {
|
) {
|
||||||
composable("counter") {
|
composable("counter") {
|
||||||
|
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Counter(counterViewModel)
|
Counter(counterViewModel)
|
||||||
topBarActions = (listOf(
|
topBarActions = (listOf(
|
||||||
TopBarAction(
|
TopBarAction(
|
||||||
Icons.Outlined.Undo,
|
Icons.Outlined.Undo,
|
||||||
mainViewModel.isUndoActionActive
|
mainViewModel.isUndoActionActive,
|
||||||
) { mainViewModel.undoLastRound() },
|
{ mainViewModel.undoLastRound() }),
|
||||||
TopBarAction(
|
TopBarAction(
|
||||||
Icons.Outlined.Redo,
|
Icons.Outlined.Redo,
|
||||||
mainViewModel.isRedoActionActive
|
mainViewModel.isRedoActionActive,
|
||||||
) { mainViewModel.redoLastRound() }
|
{ mainViewModel.redoLastRound() }),
|
||||||
|
TopBarAction(
|
||||||
|
Icons.Outlined.MoreVert,
|
||||||
|
mainViewModel.activeGameHasRounds,
|
||||||
|
{ expanded = true }
|
||||||
|
) {
|
||||||
|
DropDownMenu(
|
||||||
|
mapOf("new" to R.string.newGame),
|
||||||
|
"",
|
||||||
|
expanded,
|
||||||
|
) {
|
||||||
|
expanded = false
|
||||||
|
it?.let {
|
||||||
|
when (it) {
|
||||||
|
"new" -> mainViewModel.newGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
))
|
))
|
||||||
topBarIcon = Icons.Outlined.Menu
|
topBarIcon = Icons.Outlined.Menu
|
||||||
@@ -198,29 +220,6 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
|
|
||||||
Spacer(Modifier.height(20.dp))
|
Spacer(Modifier.height(20.dp))
|
||||||
|
|
||||||
NavigationDrawerItem(
|
|
||||||
icon = { Icon(Icons.Outlined.RestartAlt, contentDescription = null) },
|
|
||||||
colors = NavigationDrawerItemDefaults.colors(
|
|
||||||
unselectedContainerColor = MaterialTheme.colorScheme.primaryContainer
|
|
||||||
),
|
|
||||||
label = { Text(stringResource(R.string.newGame)) },
|
|
||||||
selected = false,
|
|
||||||
onClick = {
|
|
||||||
scope.launch { drawerState.close() }
|
|
||||||
mainViewModel.newGame()
|
|
||||||
navController.navigate("counter") {
|
|
||||||
popUpTo(navController.graph.findStartDestination().id) {
|
|
||||||
saveState = true
|
|
||||||
}
|
|
||||||
launchSingleTop = true
|
|
||||||
restoreState = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
|
||||||
)
|
|
||||||
|
|
||||||
Divider(Modifier.padding(top = 20.dp, bottom = 20.dp))
|
|
||||||
|
|
||||||
items.forEach { screen ->
|
items.forEach { screen ->
|
||||||
NavigationDrawerItem(
|
NavigationDrawerItem(
|
||||||
icon = { Icon(screen.icon, contentDescription = null) },
|
icon = { Icon(screen.icon, contentDescription = null) },
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package me.zobrist.tichucounter.domain
|
package me.zobrist.tichucounter.domain
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
|
||||||
class TopBarAction(val imageVector: ImageVector, val isActive: Boolean, val action: () -> Unit)
|
class TopBarAction(val imageVector: ImageVector, val isActive: Boolean, val action: () -> Unit, val composeCode: @Composable () -> Unit = {})
|
||||||
@@ -17,6 +17,7 @@ class MainViewModel @Inject constructor(
|
|||||||
private val gameRepository: GameRepository
|
private val gameRepository: GameRepository
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
private var redoRounds = mutableStateListOf<Round>()
|
private var redoRounds = mutableStateListOf<Round>()
|
||||||
private var expectedRoundCount = 0
|
private var expectedRoundCount = 0
|
||||||
|
|
||||||
@@ -25,11 +26,16 @@ class MainViewModel @Inject constructor(
|
|||||||
val isRedoActionActive: Boolean
|
val isRedoActionActive: Boolean
|
||||||
get() = redoRounds.isNotEmpty()
|
get() = redoRounds.isNotEmpty()
|
||||||
|
|
||||||
|
var activeGameHasRounds by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
||||||
gameRepository.getActiveGameFlow().collect {
|
gameRepository.getActiveGameFlow().collect {
|
||||||
|
|
||||||
|
activeGameHasRounds = it?.rounds?.isNotEmpty() == true
|
||||||
|
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
isUndoActionActive = it.rounds.isNotEmpty()
|
isUndoActionActive = it.rounds.isNotEmpty()
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ fun TopBar(
|
|||||||
imageVector = it.imageVector,
|
imageVector = it.imageVector,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
)
|
)
|
||||||
|
it.composeCode()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user