Change primary key to long. Implement newGame menu option.
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:
@@ -178,7 +178,10 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun clearAll() {
|
||||
//historyListViewModel.clearAll()
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
gameRepository.newGame()
|
||||
historyListViewModel.updateAll()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,4 +10,4 @@ data class Game(
|
||||
val active: Boolean,
|
||||
var nameA: String,
|
||||
var nameB: String,
|
||||
@PrimaryKey(autoGenerate = true) val uid: Int? = null)
|
||||
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
|
||||
@@ -12,19 +12,19 @@ interface GameDao {
|
||||
fun getAll(): List<Game>
|
||||
|
||||
@Query("SELECT * FROM game WHERE uid is :gameId")
|
||||
fun getGameById(gameId: Int): Game
|
||||
fun getGameById(gameId: Long): Game
|
||||
|
||||
@Query("SELECT * FROM game WHERE active is 1")
|
||||
fun getActive(): Game
|
||||
|
||||
@Query("UPDATE game SET active = 1 WHERE uid is :gameId;")
|
||||
fun setActive(gameId: Int)
|
||||
fun setActive(gameId: Long)
|
||||
|
||||
@Query("UPDATE game SET active = 0 WHERE uid is not :gameId;")
|
||||
fun setOthersInactive(gameId: Int)
|
||||
fun setOthersInactive(gameId: Long)
|
||||
|
||||
@Insert
|
||||
fun insertAll(vararg users: Game)
|
||||
fun insert(game: Game): Long
|
||||
|
||||
@Delete
|
||||
fun delete(round: Game)
|
||||
|
||||
@@ -6,7 +6,7 @@ import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Round(
|
||||
var gameId: Int,
|
||||
var gameId: Long,
|
||||
var scoreA: Int?,
|
||||
var scoreB: Int?,
|
||||
@PrimaryKey(autoGenerate = true) val uid: Int? = null)
|
||||
@PrimaryKey(autoGenerate = true) val uid: Long? = null)
|
||||
@@ -12,7 +12,7 @@ interface RoundDao {
|
||||
fun getAll(): List<Round>
|
||||
|
||||
@Query("SELECT * FROM round WHERE gameId is :gameId")
|
||||
fun getAllForGame(gameId: Int?): List<Round>
|
||||
fun getAllForGame(gameId: Long?): List<Round>
|
||||
|
||||
@Insert
|
||||
fun insertAll(vararg rounds: Round)
|
||||
|
||||
@@ -13,8 +13,8 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
|
||||
suspend fun newGame(): Game {
|
||||
return withContext(Dispatchers.IO) {
|
||||
val game = Game(true, "TeamA", "TeamB")
|
||||
gameDao.insertAll(game)
|
||||
setActive(game)
|
||||
val id = gameDao.insert(game)
|
||||
setActive(id)
|
||||
return@withContext gameDao.getActive()
|
||||
}
|
||||
|
||||
@@ -34,6 +34,14 @@ class GameRepository @Inject constructor(private val gameDao: GameDao, private
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun setActive(id: Long)
|
||||
{
|
||||
withContext(Dispatchers.IO) {
|
||||
gameDao.setActive(id)
|
||||
gameDao.setOthersInactive(id)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getActiveRoundHistory(): List<Round>
|
||||
{
|
||||
return withContext(Dispatchers.IO) {
|
||||
|
||||
Reference in New Issue
Block a user