Skip to content

Commit

Permalink
Fixes state of bottom app bar if the current grid is still getting ca…
Browse files Browse the repository at this point in the history
…lculated
  • Loading branch information
meikpiep committed Jan 9, 2025
1 parent a2a9dc5 commit bca0854
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class MainActivity : AppCompatActivity() {
val preferences = PreferenceManager.getDefaultSharedPreferences(this.applicationContext)
preferences.registerOnSharedPreferenceChangeListener(specialListener)

bottomAppBarService.updateAppBarState()
navigationViewService.updateMainBottomBarMargins()

val viewModel: MainViewModel by viewModels()
Expand All @@ -113,6 +112,8 @@ class MainActivity : AppCompatActivity() {

private fun reactOnUiState(state: MainUiState) {
runOnUiThread {
bottomAppBarService.updateAppBarState(state)

when (state) {
MainUiState.CALCULATING_NEW_GRID ->
{
Expand All @@ -132,16 +133,13 @@ class MainActivity : AppCompatActivity() {

updateMainGridCellShape()
updateNumeralSystemIcon()
bottomAppBarService.updateAppBarState()

binding.gridview.reCreate()
binding.gridview.invalidate()
}

MainUiState.ALREADY_SOLVED -> bottomAppBarService.updateAppBarState()
MainUiState.ALREADY_SOLVED -> {}
MainUiState.SOLVED -> {
bottomAppBarService.updateAppBarState()

if (!game.grid.isCheated()) {
KonfettiStarter(binding.konfettiView).startKonfetti()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,22 @@ class MainBottomAppBarService(
}
}

fun updateAppBarState() {
if (game.grid.isSolved()) {
binding.hint.hide()

undoButton.visibility = View.GONE
eraserButton?.visibility = View.GONE

solveHelperMenuItems().forEach { it.setVisible(false) }
} else {
fun updateAppBarState(state: MainUiState) {
if (state == MainUiState.PLAYING) {
binding.hint.isEnabled = true
binding.hint.show()

undoButton.visibility = View.VISIBLE
undoButton.isEnabled = game.undoManager.undoPossible()

solveHelperMenuItems().forEach { it.setVisible(true) }
} else {
binding.hint.hide()

undoButton.visibility = View.GONE
eraserButton?.visibility = View.GONE

solveHelperMenuItems().forEach { it.setVisible(false) }
}
}

Expand Down

0 comments on commit bca0854

Please sign in to comment.