Format all files.

This commit is contained in:
2022-12-27 19:04:55 +01:00
parent 17ed7d18f6
commit 70da57df9c
6 changed files with 21 additions and 38 deletions

View File

@@ -14,14 +14,13 @@ import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import me.zobrist.tichucounter.databinding.ActivityMainBinding
import me.zobrist.tichucounter.data.Round
import me.zobrist.tichucounter.databinding.ActivityMainBinding
import me.zobrist.tichucounter.domain.Tichu
import me.zobrist.tichucounter.domain.getAbsoluteDifference
import me.zobrist.tichucounter.fragments.HistoryListViewModel
import me.zobrist.tichucounter.fragments.KeyboardViewModel
import me.zobrist.tichucounter.repository.GameRepository
import java.util.*
import javax.inject.Inject
@AndroidEntryPoint
@@ -32,8 +31,10 @@ class MainActivity : AppCompatActivity() {
private val keyboardViewModel: KeyboardViewModel by viewModels()
private val historyListViewModel: HistoryListViewModel by viewModels()
@Inject lateinit var tichu: Tichu
@Inject lateinit var gameRepository: GameRepository
@Inject
lateinit var tichu: Tichu
@Inject
lateinit var gameRepository: GameRepository
private var ignoreNextUpdate: Boolean = false
@@ -51,8 +52,7 @@ class MainActivity : AppCompatActivity() {
GlobalScope.launch(Dispatchers.IO) {
val game = gameRepository.getActiveGame()
if(game == null)
{
if (game == null) {
val game = gameRepository.newGame()
}
}
@@ -162,8 +162,7 @@ class MainActivity : AppCompatActivity() {
R.id.action_undo -> {
GlobalScope.launch(Dispatchers.IO) {
val history = gameRepository.getActiveRoundHistory()
if(history.isNotEmpty())
{
if (history.isNotEmpty()) {
gameRepository.removeRoundFromHistory(history.last())
historyListViewModel.updateAll()
}

View File

@@ -1,9 +1,7 @@
package me.zobrist.tichucounter.data
import DateConverter
import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverter
@Database(entities = [Round::class, Game::class], version = 1)
abstract class AppDatabase : RoomDatabase() {

View File

@@ -1,13 +1,12 @@
package me.zobrist.tichucounter.data
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.Date
@Entity
data class Game(
val active: Boolean,
var nameA: String,
var nameB: String,
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
@PrimaryKey(autoGenerate = true) val uid: Long? = null
)

View File

@@ -1,6 +1,5 @@
package me.zobrist.tichucounter.data
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@@ -9,4 +8,5 @@ data class Round(
var gameId: Long,
var scoreA: Int?,
var scoreB: Int?,
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
@PrimaryKey(autoGenerate = true) val uid: Long? = null
)

View File

@@ -20,7 +20,6 @@ class HistoryListViewModel @Inject constructor(val gameRepository: GameRepositor
private val _scrollDown: SingleLiveEvent<Boolean> = SingleLiveEvent()
val totalScoreA: LiveData<Int>
get() {
return _totalScoreA

View File

@@ -8,7 +8,10 @@ import me.zobrist.tichucounter.data.Round
import me.zobrist.tichucounter.data.RoundDao
import javax.inject.Inject
class GameRepository @Inject constructor(private val gameDao: GameDao, private val roundDao: RoundDao) {
class GameRepository @Inject constructor(
private val gameDao: GameDao,
private val roundDao: RoundDao
) {
suspend fun newGame(): Game {
return withContext(Dispatchers.IO) {
@@ -17,7 +20,6 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
setActive(id)
return@withContext gameDao.getActive()
}
}
suspend fun getActiveGame(): Game {
@@ -26,45 +28,31 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
}
}
suspend fun setActive(game: Game)
{
withContext(Dispatchers.IO) {
game.uid?.let { gameDao.setActive(it) }
game.uid?.let { gameDao.setOthersInactive(it) }
}
}
suspend fun setActive(id: Long)
{
suspend fun setActive(id: Long) {
withContext(Dispatchers.IO) {
gameDao.setActive(id)
gameDao.setOthersInactive(id)
}
}
suspend fun getActiveRoundHistory(): List<Round>
{
suspend fun getActiveRoundHistory(): List<Round> {
return withContext(Dispatchers.IO) {
val active = getActiveGame()
if(active?.uid != null)
{
if (active?.uid != null) {
return@withContext roundDao.getAllForGame(active.uid)
}
else {
} else {
return@withContext listOf<Round>()
}
}
}
suspend fun removeRoundFromHistory(round: Round)
{
suspend fun removeRoundFromHistory(round: Round) {
withContext(Dispatchers.IO) {
roundDao.delete(round)
}
}
suspend fun addRoundToActiveGame(scoreA: Int, scoreB: Int)
{
suspend fun addRoundToActiveGame(scoreA: Int, scoreB: Int) {
withContext(Dispatchers.IO) {
val active = getActiveGame()
val round = Round(active.uid!!, scoreA, scoreB)