This commit is contained in:
@@ -4,14 +4,14 @@
|
|||||||
<application
|
<application
|
||||||
android:name=".framework.TichuCounterApplication"
|
android:name=".framework.TichuCounterApplication"
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
|
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||||
android:fullBackupContent="@xml/backup_descriptor"
|
android:fullBackupContent="@xml/backup_descriptor"
|
||||||
android:icon="@mipmap/ic_launcher"
|
android:icon="@mipmap/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:localeConfig="@xml/locales_config"
|
android:localeConfig="@xml/locales_config"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme"
|
android:theme="@style/AppTheme">
|
||||||
android:dataExtractionRules="@xml/data_extraction_rules">
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
|
|||||||
@@ -11,5 +11,5 @@ data class Game(
|
|||||||
override var nameB: String,
|
override var nameB: String,
|
||||||
override val created: Date,
|
override val created: Date,
|
||||||
override var modified: Date,
|
override var modified: Date,
|
||||||
@PrimaryKey(autoGenerate = true) override val uid: Long? = null
|
@PrimaryKey(autoGenerate = true) override val uid: Long? = null
|
||||||
) : IGame, IEntity
|
) : IGame, IEntity
|
||||||
@@ -10,9 +10,18 @@ interface GameDao : DaoBase<Game> {
|
|||||||
@Query("SELECT * FROM game")
|
@Query("SELECT * FROM game")
|
||||||
fun getAll(): Flow<List<Game>>
|
fun getAll(): Flow<List<Game>>
|
||||||
|
|
||||||
@Query("SELECT *, SUM(round.scoreA) as scoreA, SUM(round.scoreB) as scoreB, SUM(round.scoreB) as scoreB " +
|
@Query(
|
||||||
"FROM game " +
|
"SELECT active, " +
|
||||||
"LEFT JOIN round ON round.gameId = game.uid GROUP BY game.uid ORDER BY modified DESC")
|
"nameA, " +
|
||||||
|
"nameB, " +
|
||||||
|
"created, " +
|
||||||
|
"modified, " +
|
||||||
|
"game.uid as gameId, " +
|
||||||
|
"COALESCE(SUM(round.scoreA), 0) as scoreA, " +
|
||||||
|
"COALESCE(SUM(round.scoreB), 0) as scoreB " +
|
||||||
|
"FROM game " +
|
||||||
|
"LEFT JOIN round ON round.gameId = game.uid GROUP BY game.uid ORDER BY modified DESC"
|
||||||
|
)
|
||||||
fun getAllWithPoints(): Flow<List<GameAndScore>>
|
fun getAllWithPoints(): Flow<List<GameAndScore>>
|
||||||
|
|
||||||
@Query("SELECT * FROM game WHERE uid is :gameId")
|
@Query("SELECT * FROM game WHERE uid is :gameId")
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ interface RoundDao : DaoBase<Round> {
|
|||||||
"LEFT JOIN game ON game.uid = round.gameId " +
|
"LEFT JOIN game ON game.uid = round.gameId " +
|
||||||
"WHERE game.active == 1"
|
"WHERE game.active == 1"
|
||||||
)
|
)
|
||||||
fun getRoundSumForActiveGame() : Flow<Round>
|
fun getRoundSumForActiveGame(): Flow<Round>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT gameId, scoreA, scoreB, round.uid " +
|
"SELECT gameId, scoreA, scoreB, round.uid " +
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
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
|
||||||
|
|
||||||
@@ -21,8 +19,8 @@ class TeamScoresViewModel @Inject constructor(private val roundDao: RoundDao) :
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
||||||
roundDao.getRoundSumForActiveGame().collect { score ->
|
roundDao.getRoundSumForActiveGame().collect { score ->
|
||||||
_scoreA.value = if(score?.scoreA != null) score.scoreA else 0
|
_scoreA.value = if (score?.scoreA != null) score.scoreA else 0
|
||||||
_scoreB.value = if(score?.scoreB != null) score.scoreB else 0
|
_scoreB.value = if (score?.scoreB != null) score.scoreB else 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
package me.zobrist.tichucounter.ui.history
|
package me.zobrist.tichucounter.ui.history
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import me.zobrist.tichucounter.R
|
import me.zobrist.tichucounter.R
|
||||||
|
|
||||||
|
|||||||
@@ -5,21 +5,24 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import me.zobrist.tichucounter.data.GameAndScore
|
import me.zobrist.tichucounter.data.GameAndScore
|
||||||
import me.zobrist.tichucounter.data.GameDao
|
import me.zobrist.tichucounter.data.GameDao
|
||||||
import me.zobrist.tichucounter.data.RoundDao
|
import me.zobrist.tichucounter.data.RoundDao
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class HistoryFragmentViewModel @Inject constructor(private val gameDao: GameDao, private val roundDao: RoundDao) : ViewModel() {
|
class HistoryFragmentViewModel @Inject constructor(
|
||||||
|
private val gameDao: GameDao,
|
||||||
|
private val roundDao: RoundDao
|
||||||
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _gameAndHistory: MutableLiveData<List<GameAndScore>> = MutableLiveData()
|
private val _gameAndHistory: MutableLiveData<List<GameAndScore>> = MutableLiveData()
|
||||||
|
|
||||||
val gameAndHistory: LiveData<List<GameAndScore>>
|
val gameAndHistory: LiveData<List<GameAndScore>>
|
||||||
get() { return _gameAndHistory}
|
get() {
|
||||||
|
return _gameAndHistory
|
||||||
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
package me.zobrist.tichucounter.ui.history
|
package me.zobrist.tichucounter.ui.history
|
||||||
|
|
||||||
import android.provider.Settings.Global.getString
|
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.res.TypedArrayUtils
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import me.zobrist.tichucounter.R
|
|
||||||
import me.zobrist.tichucounter.data.GameAndScore
|
import me.zobrist.tichucounter.data.GameAndScore
|
||||||
import me.zobrist.tichucounter.databinding.FragmentHistoryBinding
|
import me.zobrist.tichucounter.databinding.FragmentHistoryBinding
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical">
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -18,24 +17,23 @@
|
|||||||
android:id="@+id/card_title"
|
android:id="@+id/card_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?attr/textAppearanceHeadline6"
|
android:textAppearance="?attr/textAppearanceHeadline6" />
|
||||||
/>
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/card_secondary"
|
android:id="@+id/card_secondary"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:textAppearance="?attr/textAppearanceBody2"
|
android:textAppearance="?attr/textAppearanceBody2"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
/>
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/card_supporting"
|
android:id="@+id/card_supporting"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:textAppearance="?attr/textAppearanceBody2"
|
android:textAppearance="?attr/textAppearanceBody2"
|
||||||
android:textColor="?android:attr/textColorSecondary"
|
android:textColor="?android:attr/textColorSecondary" />
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user