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