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.MainViewModel
|
||||
import me.zobrist.tichucounter.ui.TopBar
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
import me.zobrist.tichucounter.ui.counter.*
|
||||
import me.zobrist.tichucounter.ui.history.HistoryList
|
||||
import me.zobrist.tichucounter.ui.history.HistoryViewModel
|
||||
@@ -126,24 +127,45 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
{ topBarNavigationAction.action() },
|
||||
topBarActions
|
||||
)
|
||||
}) {
|
||||
}) { paddings ->
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = "counter",
|
||||
modifier = Modifier.padding(it)
|
||||
modifier = Modifier.padding(paddings)
|
||||
) {
|
||||
composable("counter") {
|
||||
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
Counter(counterViewModel)
|
||||
topBarActions = (listOf(
|
||||
TopBarAction(
|
||||
Icons.Outlined.Undo,
|
||||
mainViewModel.isUndoActionActive
|
||||
) { mainViewModel.undoLastRound() },
|
||||
mainViewModel.isUndoActionActive,
|
||||
{ mainViewModel.undoLastRound() }),
|
||||
TopBarAction(
|
||||
Icons.Outlined.Redo,
|
||||
mainViewModel.isRedoActionActive
|
||||
) { mainViewModel.redoLastRound() }
|
||||
mainViewModel.isRedoActionActive,
|
||||
{ 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
|
||||
@@ -198,29 +220,6 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
||||
|
||||
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 ->
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(screen.icon, contentDescription = null) },
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
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
|
||||
) : ViewModel() {
|
||||
|
||||
|
||||
private var redoRounds = mutableStateListOf<Round>()
|
||||
private var expectedRoundCount = 0
|
||||
|
||||
@@ -25,11 +26,16 @@ class MainViewModel @Inject constructor(
|
||||
val isRedoActionActive: Boolean
|
||||
get() = redoRounds.isNotEmpty()
|
||||
|
||||
var activeGameHasRounds by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
|
||||
gameRepository.getActiveGameFlow().collect {
|
||||
|
||||
activeGameHasRounds = it?.rounds?.isNotEmpty() == true
|
||||
|
||||
if (it != null) {
|
||||
isUndoActionActive = it.rounds.isNotEmpty()
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ fun TopBar(
|
||||
imageVector = it.imageVector,
|
||||
contentDescription = null,
|
||||
)
|
||||
it.composeCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user