From 6b396dba24da202228bc3aead3df5a1c51beef40 Mon Sep 17 00:00:00 2001 From: Fabian Zobrist Date: Fri, 6 Jan 2023 22:15:07 +0100 Subject: [PATCH] Refromat code. --- app/src/main/AndroidManifest.xml | 4 ++-- .../java/me/zobrist/tichucounter/data/Game.kt | 2 +- .../java/me/zobrist/tichucounter/data/GameDao.kt | 15 ++++++++++++--- .../me/zobrist/tichucounter/data/RoundDao.kt | 2 +- .../ui/counter/TeamScoresViewModel.kt | 6 ++---- .../tichucounter/ui/history/HistoryFragment.kt | 8 ++++---- .../ui/history/HistoryFragmentViewModel.kt | 11 +++++++---- .../ui/history/MyGameRecyclerViewAdapter.kt | 5 +---- app/src/main/res/layout/fragment_history.xml | 16 +++++++--------- 9 files changed, 37 insertions(+), 32 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1248009..66ba258 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -4,14 +4,14 @@ + android:theme="@style/AppTheme"> { @Query("SELECT * FROM game") fun getAll(): Flow> - @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> @Query("SELECT * FROM game WHERE uid is :gameId") diff --git a/app/src/main/java/me/zobrist/tichucounter/data/RoundDao.kt b/app/src/main/java/me/zobrist/tichucounter/data/RoundDao.kt index 4c1a69d..11159b3 100644 --- a/app/src/main/java/me/zobrist/tichucounter/data/RoundDao.kt +++ b/app/src/main/java/me/zobrist/tichucounter/data/RoundDao.kt @@ -15,7 +15,7 @@ interface RoundDao : DaoBase { "LEFT JOIN game ON game.uid = round.gameId " + "WHERE game.active == 1" ) - fun getRoundSumForActiveGame() : Flow + fun getRoundSumForActiveGame(): Flow @Query( "SELECT gameId, scoreA, scoreB, round.uid " + diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/counter/TeamScoresViewModel.kt b/app/src/main/java/me/zobrist/tichucounter/ui/counter/TeamScoresViewModel.kt index 4bd604c..490c4c3 100644 --- a/app/src/main/java/me/zobrist/tichucounter/ui/counter/TeamScoresViewModel.kt +++ b/app/src/main/java/me/zobrist/tichucounter/ui/counter/TeamScoresViewModel.kt @@ -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 } } } diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragment.kt b/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragment.kt index d9f2eb1..ce96490 100644 --- a/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragment.kt +++ b/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragment.kt @@ -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 diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragmentViewModel.kt b/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragmentViewModel.kt index a3d964a..3bb8fb9 100644 --- a/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragmentViewModel.kt +++ b/app/src/main/java/me/zobrist/tichucounter/ui/history/HistoryFragmentViewModel.kt @@ -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> = MutableLiveData() val gameAndHistory: LiveData> - get() { return _gameAndHistory} + get() { + return _gameAndHistory + } init { viewModelScope.launch { diff --git a/app/src/main/java/me/zobrist/tichucounter/ui/history/MyGameRecyclerViewAdapter.kt b/app/src/main/java/me/zobrist/tichucounter/ui/history/MyGameRecyclerViewAdapter.kt index 277b899..13f6dbc 100644 --- a/app/src/main/java/me/zobrist/tichucounter/ui/history/MyGameRecyclerViewAdapter.kt +++ b/app/src/main/java/me/zobrist/tichucounter/ui/history/MyGameRecyclerViewAdapter.kt @@ -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 diff --git a/app/src/main/res/layout/fragment_history.xml b/app/src/main/res/layout/fragment_history.xml index 1dcab05..33f1e2e 100644 --- a/app/src/main/res/layout/fragment_history.xml +++ b/app/src/main/res/layout/fragment_history.xml @@ -1,10 +1,9 @@ - + android:orientation="vertical"> + android:textAppearance="?attr/textAppearanceHeadline6" /> + + android:textColor="?android:attr/textColorSecondary" /> + + android:textColor="?android:attr/textColorSecondary" />