Implement undo last round.
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:
@@ -148,7 +148,10 @@ class MainActivity : AppCompatActivity() {
|
||||
builder.setMessage(getString(R.string.confirmClear)).setTitle(R.string.clear)
|
||||
.setCancelable(false).setPositiveButton(getString(R.string.yes)) { dialog, _ ->
|
||||
dialog.dismiss()
|
||||
clearAll()
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
gameRepository.newGame()
|
||||
historyListViewModel.updateAll()
|
||||
}
|
||||
}.setNegativeButton(getString(R.string.no)) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
@@ -157,7 +160,14 @@ class MainActivity : AppCompatActivity() {
|
||||
true
|
||||
}
|
||||
R.id.action_undo -> {
|
||||
//historyListViewModel.revertLastRound()
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val history = gameRepository.getActiveRoundHistory()
|
||||
if(history.isNotEmpty())
|
||||
{
|
||||
gameRepository.removeRoundFromHistory(history.last())
|
||||
historyListViewModel.updateAll()
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.action_theme -> {
|
||||
@@ -177,14 +187,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearAll() {
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
gameRepository.newGame()
|
||||
historyListViewModel.updateAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun chooseThemeDialog() {
|
||||
|
||||
val builder = AlertDialog.Builder(this)
|
||||
|
||||
@@ -81,10 +81,12 @@ class HistoryListViewModel @Inject constructor(val gameRepository: GameRepositor
|
||||
fun updateAll() {
|
||||
viewModelScope.launch {
|
||||
val scores = gameRepository.getActiveRoundHistory()
|
||||
getHistoryA(scores)
|
||||
getHistoryB(scores)
|
||||
getScoreA(scores)
|
||||
getScoreB(scores)
|
||||
if (scores != null) {
|
||||
getHistoryA(scores)
|
||||
getHistoryB(scores)
|
||||
getScoreA(scores)
|
||||
getScoreB(scores)
|
||||
}
|
||||
scrollDown()
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,20 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
|
||||
{
|
||||
return withContext(Dispatchers.IO) {
|
||||
val active = getActiveGame()
|
||||
return@withContext roundDao.getAllForGame(active?.uid)
|
||||
if(active?.uid != null)
|
||||
{
|
||||
return@withContext roundDao.getAllForGame(active.uid)
|
||||
}
|
||||
else {
|
||||
return@withContext listOf<Round>()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun removeRoundFromHistory(round: Round)
|
||||
{
|
||||
withContext(Dispatchers.IO) {
|
||||
roundDao.delete(round)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user