Format all files.
This commit is contained in:
@@ -14,14 +14,13 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
|
||||||
import me.zobrist.tichucounter.data.Round
|
import me.zobrist.tichucounter.data.Round
|
||||||
|
import me.zobrist.tichucounter.databinding.ActivityMainBinding
|
||||||
import me.zobrist.tichucounter.domain.Tichu
|
import me.zobrist.tichucounter.domain.Tichu
|
||||||
import me.zobrist.tichucounter.domain.getAbsoluteDifference
|
import me.zobrist.tichucounter.domain.getAbsoluteDifference
|
||||||
import me.zobrist.tichucounter.fragments.HistoryListViewModel
|
import me.zobrist.tichucounter.fragments.HistoryListViewModel
|
||||||
import me.zobrist.tichucounter.fragments.KeyboardViewModel
|
import me.zobrist.tichucounter.fragments.KeyboardViewModel
|
||||||
import me.zobrist.tichucounter.repository.GameRepository
|
import me.zobrist.tichucounter.repository.GameRepository
|
||||||
import java.util.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -32,8 +31,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private val keyboardViewModel: KeyboardViewModel by viewModels()
|
private val keyboardViewModel: KeyboardViewModel by viewModels()
|
||||||
private val historyListViewModel: HistoryListViewModel by viewModels()
|
private val historyListViewModel: HistoryListViewModel by viewModels()
|
||||||
|
|
||||||
@Inject lateinit var tichu: Tichu
|
@Inject
|
||||||
@Inject lateinit var gameRepository: GameRepository
|
lateinit var tichu: Tichu
|
||||||
|
@Inject
|
||||||
|
lateinit var gameRepository: GameRepository
|
||||||
|
|
||||||
private var ignoreNextUpdate: Boolean = false
|
private var ignoreNextUpdate: Boolean = false
|
||||||
|
|
||||||
@@ -51,8 +52,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val game = gameRepository.getActiveGame()
|
val game = gameRepository.getActiveGame()
|
||||||
|
|
||||||
if(game == null)
|
if (game == null) {
|
||||||
{
|
|
||||||
val game = gameRepository.newGame()
|
val game = gameRepository.newGame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -162,8 +162,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
R.id.action_undo -> {
|
R.id.action_undo -> {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
val history = gameRepository.getActiveRoundHistory()
|
val history = gameRepository.getActiveRoundHistory()
|
||||||
if(history.isNotEmpty())
|
if (history.isNotEmpty()) {
|
||||||
{
|
|
||||||
gameRepository.removeRoundFromHistory(history.last())
|
gameRepository.removeRoundFromHistory(history.last())
|
||||||
historyListViewModel.updateAll()
|
historyListViewModel.updateAll()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package me.zobrist.tichucounter.data
|
package me.zobrist.tichucounter.data
|
||||||
|
|
||||||
import DateConverter
|
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.RoomDatabase
|
import androidx.room.RoomDatabase
|
||||||
import androidx.room.TypeConverter
|
|
||||||
|
|
||||||
@Database(entities = [Round::class, Game::class], version = 1)
|
@Database(entities = [Round::class, Game::class], version = 1)
|
||||||
abstract class AppDatabase : RoomDatabase() {
|
abstract class AppDatabase : RoomDatabase() {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package me.zobrist.tichucounter.data
|
package me.zobrist.tichucounter.data
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Game(
|
data class Game(
|
||||||
val active: Boolean,
|
val active: Boolean,
|
||||||
var nameA: String,
|
var nameA: String,
|
||||||
var nameB: String,
|
var nameB: String,
|
||||||
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
|
@PrimaryKey(autoGenerate = true) val uid: Long? = null
|
||||||
|
)
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package me.zobrist.tichucounter.data
|
package me.zobrist.tichucounter.data
|
||||||
|
|
||||||
import androidx.room.ColumnInfo
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@@ -9,4 +8,5 @@ data class Round(
|
|||||||
var gameId: Long,
|
var gameId: Long,
|
||||||
var scoreA: Int?,
|
var scoreA: Int?,
|
||||||
var scoreB: Int?,
|
var scoreB: Int?,
|
||||||
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
|
@PrimaryKey(autoGenerate = true) val uid: Long? = null
|
||||||
|
)
|
||||||
@@ -20,7 +20,6 @@ class HistoryListViewModel @Inject constructor(val gameRepository: GameRepositor
|
|||||||
private val _scrollDown: SingleLiveEvent<Boolean> = SingleLiveEvent()
|
private val _scrollDown: SingleLiveEvent<Boolean> = SingleLiveEvent()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
val totalScoreA: LiveData<Int>
|
val totalScoreA: LiveData<Int>
|
||||||
get() {
|
get() {
|
||||||
return _totalScoreA
|
return _totalScoreA
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import me.zobrist.tichucounter.data.Round
|
|||||||
import me.zobrist.tichucounter.data.RoundDao
|
import me.zobrist.tichucounter.data.RoundDao
|
||||||
import javax.inject.Inject
|
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 {
|
suspend fun newGame(): Game {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
@@ -17,7 +20,6 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
|
|||||||
setActive(id)
|
setActive(id)
|
||||||
return@withContext gameDao.getActive()
|
return@withContext gameDao.getActive()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getActiveGame(): Game {
|
suspend fun getActiveGame(): Game {
|
||||||
@@ -26,45 +28,31 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun setActive(game: Game)
|
suspend fun setActive(id: Long) {
|
||||||
{
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
game.uid?.let { gameDao.setActive(it) }
|
|
||||||
game.uid?.let { gameDao.setOthersInactive(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun setActive(id: Long)
|
|
||||||
{
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
gameDao.setActive(id)
|
gameDao.setActive(id)
|
||||||
gameDao.setOthersInactive(id)
|
gameDao.setOthersInactive(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getActiveRoundHistory(): List<Round>
|
suspend fun getActiveRoundHistory(): List<Round> {
|
||||||
{
|
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
val active = getActiveGame()
|
val active = getActiveGame()
|
||||||
if(active?.uid != null)
|
if (active?.uid != null) {
|
||||||
{
|
|
||||||
return@withContext roundDao.getAllForGame(active.uid)
|
return@withContext roundDao.getAllForGame(active.uid)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return@withContext listOf<Round>()
|
return@withContext listOf<Round>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun removeRoundFromHistory(round: Round)
|
suspend fun removeRoundFromHistory(round: Round) {
|
||||||
{
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
roundDao.delete(round)
|
roundDao.delete(round)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun addRoundToActiveGame(scoreA: Int, scoreB: Int)
|
suspend fun addRoundToActiveGame(scoreA: Int, scoreB: Int) {
|
||||||
{
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val active = getActiveGame()
|
val active = getActiveGame()
|
||||||
val round = Round(active.uid!!, scoreA, scoreB)
|
val round = Round(active.uid!!, scoreA, scoreB)
|
||||||
|
|||||||
Reference in New Issue
Block a user