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