Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c6674373f | |||
| 67e803f913 | |||
| 2d30de8855 | |||
| 45ae61584d | |||
| fa9786de04 | |||
| 461dc4a30c | |||
| 44246e329e | |||
| c968d2ee91 | |||
| 1a2002e812 | |||
| c3c0f09313 | |||
| 81a0d680e9 | |||
| 27cb2f670b | |||
| 6a96749501 | |||
| 2fa4e218e5 | |||
| 2599e3320a | |||
| c97d98704b | |||
| 37bbf45ce0 | |||
| dbef6e047a | |||
| 450c8a1547 | |||
| 536b5b7fd2 | |||
| 57b02ce74a | |||
| 4e4653da97 | |||
| e5041c98e1 | |||
| 8521247c58 | |||
| 7108af4cf4 | |||
| 55a2293b6c | |||
| c8098fc904 | |||
| ec3b51051a | |||
| 07219bffb4 | |||
| ff5495249f | |||
| 217370079d | |||
| add100146d | |||
| ceebe92f8b | |||
| 4f87321e2c | |||
| 81c540c2a5 | |||
| a45043424e | |||
| 18326e952f | |||
| 1819802748 | |||
| a099659b2c | |||
| 61745c95a4 | |||
| 164cf6900f | |||
| 89ab0afaf5 | |||
| 9d8de2dd3c | |||
| fcb8c12454 | |||
| a2b84640b1 | |||
| 30723f7862 |
75
.drone.yml
75
.drone.yml
@@ -1,75 +0,0 @@
|
|||||||
---
|
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: Android
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: prepare signing
|
|
||||||
image: busybox
|
|
||||||
environment:
|
|
||||||
STOREPASSWORD:
|
|
||||||
from_secret: StorePassword
|
|
||||||
KEYPASSWORD:
|
|
||||||
from_secret: KeyPassword
|
|
||||||
commands:
|
|
||||||
- touch keystore.properties
|
|
||||||
- echo "storePassword=$STOREPASSWORD" >> keystore.properties
|
|
||||||
- echo "keyPassword=$KEYPASSWORD" >> keystore.properties
|
|
||||||
- echo "keyAlias=key0" >> keystore.properties
|
|
||||||
- echo "storeFile=../AndroidKey" >> keystore.properties
|
|
||||||
|
|
||||||
- name: generate versionCode
|
|
||||||
image: busybox
|
|
||||||
commands:
|
|
||||||
- touch version.properties
|
|
||||||
- let timestamp=$(date +%s)/10
|
|
||||||
- echo "versionCode=$timestamp" >> version.properties
|
|
||||||
|
|
||||||
- name: build
|
|
||||||
image: mingc/android-build-box
|
|
||||||
commands:
|
|
||||||
- ./gradlew test
|
|
||||||
- ./gradlew assembleRelease
|
|
||||||
- ./gradlew bundleRelease
|
|
||||||
|
|
||||||
- name: deploy latest build
|
|
||||||
image: curlimages/curl
|
|
||||||
environment:
|
|
||||||
SEAFILE_API_KEY:
|
|
||||||
from_secret: SeafileApiKey
|
|
||||||
APK_FILE: app/build/outputs/apk/release/app-release.apk
|
|
||||||
BUNDLE_FILE: app/build/outputs/bundle/release/app-release.aab
|
|
||||||
SEAFILE_REPO: 6debeef9-121e-46ba-acc7-81e109fdcbdd
|
|
||||||
commands:
|
|
||||||
- 'UPLOAD_URL=$(curl -H "Authorization: Token $SEAFILE_API_KEY" https://seafile.zobrist.me/api2/repos/$SEAFILE_REPO/upload-link/ | tr -d "\"")'
|
|
||||||
- echo $UPLOAD_URL
|
|
||||||
- 'curl -H "Authorization: Token $SEAFILE_API_KEY" -F file=@$APK_FILE -F parent_dir=/ -F relative_path=latest/ -F replace=1 "$UPLOAD_URL"'
|
|
||||||
- 'curl -H "Authorization: Token $SEAFILE_API_KEY" -F file=@$BUNDLE_FILE -F parent_dir=/ -F relative_path=latest/ -F replace=1 "$UPLOAD_URL"'
|
|
||||||
|
|
||||||
- name: deploy tagged build
|
|
||||||
image: curlimages/curl
|
|
||||||
environment:
|
|
||||||
SEAFILE_API_KEY:
|
|
||||||
from_secret: SeafileApiKey
|
|
||||||
APK_FILE: app/build/outputs/apk/release/app-release.apk
|
|
||||||
BUNDLE_FILE: app/build/outputs/bundle/release/app-release.aab
|
|
||||||
SEAFILE_REPO: 6debeef9-121e-46ba-acc7-81e109fdcbdd
|
|
||||||
commands:
|
|
||||||
- 'UPLOAD_URL=$(curl -H "Authorization: Token $SEAFILE_API_KEY" https://seafile.zobrist.me/api2/repos/$SEAFILE_REPO/upload-link/ | tr -d "\"")'
|
|
||||||
- 'curl -H "Authorization: Token $SEAFILE_API_KEY" -F file=@$APK_FILE -F parent_dir=/ -F relative_path=tagged/$DRONE_TAG/ -F replace=1 "$UPLOAD_URL"'
|
|
||||||
- 'curl -H "Authorization: Token $SEAFILE_API_KEY" -F file=@$BUNDLE_FILE -F parent_dir=/ -F relative_path=tagged/$DRONE_TAG/ -F replace=1 "$UPLOAD_URL"'
|
|
||||||
- 'curl -d "operation=rename&newname=app-release$DRONE_TAG.apk" -H "Authorization: Token $SEAFILE_API_KEY" https://seafile.zobrist.me/api2/repos/$SEAFILE_REPO/file/?p=/tagged/$DRONE_TAG/app-release.apk'
|
|
||||||
- 'curl -d "operation=rename&newname=app-release$DRONE_TAG.aab" -H "Authorization: Token $SEAFILE_API_KEY" https://seafile.zobrist.me/api2/repos/$SEAFILE_REPO/file/?p=/tagged/$DRONE_TAG/app-release.aab'
|
|
||||||
when:
|
|
||||||
event:
|
|
||||||
- tag
|
|
||||||
|
|
||||||
- name: slack notification
|
|
||||||
image: plugins/slack
|
|
||||||
settings:
|
|
||||||
webhook:
|
|
||||||
from_secret: SlackWebhook
|
|
||||||
when:
|
|
||||||
status:
|
|
||||||
- failure
|
|
||||||
- success
|
|
||||||
48
.gitea/workflows/buildAndroid.yaml
Normal file
48
.gitea/workflows/buildAndroid.yaml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
name: Build Android
|
||||||
|
on: [pull_request, push]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest-android
|
||||||
|
steps:
|
||||||
|
- name: Checkout the code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Prepare signing
|
||||||
|
run: |
|
||||||
|
touch keystore.properties
|
||||||
|
echo "storePassword=${{ secrets.STOREPASSWORD }}" >> keystore.properties
|
||||||
|
echo "keyPassword=${{ secrets.KEYPASSWORD }}" >> keystore.properties
|
||||||
|
echo "keyAlias=key0" >> keystore.properties
|
||||||
|
echo "storeFile=../AndroidKey" >> keystore.properties
|
||||||
|
|
||||||
|
- name: Generate versionCode
|
||||||
|
run: |
|
||||||
|
touch version.properties
|
||||||
|
let timestamp=$(date +%s)/10
|
||||||
|
echo "versionCode=$timestamp" >> version.properties
|
||||||
|
|
||||||
|
- name: Test the app
|
||||||
|
run: ./gradlew test
|
||||||
|
|
||||||
|
- name: Build apk
|
||||||
|
run: ./gradlew assembleRelease
|
||||||
|
|
||||||
|
- name: Build abb
|
||||||
|
run: ./gradlew bundleRelease
|
||||||
|
|
||||||
|
- name: Deploy latest to Nextcloud
|
||||||
|
run: |
|
||||||
|
curl -k -u "${{ secrets.NEXTCLOUD_USERNAME }}:${{ secrets.NEXTCLOUD_PASSWORD }}" -T "app/build/outputs/apk/release/app-release.apk" "https://nextcloud.zobrist.me/remote.php/dav/files/deploy/TichuCounter/latest/app-release.apk"
|
||||||
|
curl -k -u "${{ secrets.NEXTCLOUD_USERNAME }}:${{ secrets.NEXTCLOUD_PASSWORD }}" -T "app/build/outputs/bundle/release/app-release.aab" "https://nextcloud.zobrist.me/remote.php/dav/files/deploy/TichuCounter/latest/app-release.aab"
|
||||||
|
|
||||||
|
- name: Deploy tagged build to Nextcloud
|
||||||
|
run: |
|
||||||
|
curl -k -u "${{ secrets.NEXTCLOUD_USERNAME }}:${{ secrets.NEXTCLOUD_PASSWORD }}" -T "app/build/outputs/apk/release/app-release.apk" "https://nextcloud.zobrist.me/remote.php/dav/files/deploy/TichuCounter/tagged/app-release-${GITHUB_REF_NAME##*/}.apk"
|
||||||
|
curl -k -u "${{ secrets.NEXTCLOUD_USERNAME }}:${{ secrets.NEXTCLOUD_PASSWORD }}" -T "app/build/outputs/bundle/release/app-release.aab" "https://nextcloud.zobrist.me/remote.php/dav/files/deploy/TichuCounter/tagged/app-release-${GITHUB_REF_NAME##*/}.aab"
|
||||||
|
|
||||||
|
- uses: https://github.com/ravsamhq/notify-slack-action@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
status: ${{ job.status }} # required
|
||||||
|
env:
|
||||||
|
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
|
||||||
@@ -16,7 +16,7 @@ def keystoreProperties = new Properties()
|
|||||||
def versionProperties = new Properties()
|
def versionProperties = new Properties()
|
||||||
|
|
||||||
def versionMajor = 2
|
def versionMajor = 2
|
||||||
def versionMinor = 2
|
def versionMinor = 3
|
||||||
|
|
||||||
// Load your keystore.properties file into the keystoreProperties object.
|
// Load your keystore.properties file into the keystoreProperties object.
|
||||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||||
@@ -24,12 +24,12 @@ versionProperties.load(new FileInputStream(versionPropertiesFile))
|
|||||||
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 33
|
compileSdk 34
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "me.zobrist.tichucounter"
|
applicationId "me.zobrist.tichucounter"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 33
|
targetSdkVersion 34
|
||||||
versionCode versionProperties["versionCode"].toInteger()
|
versionCode versionProperties["versionCode"].toInteger()
|
||||||
versionName "${versionMajor}.${versionMinor}.${versionProperties["versionCode"].toInteger()}"
|
versionName "${versionMajor}.${versionMinor}.${versionProperties["versionCode"].toInteger()}"
|
||||||
resourceConfigurations += ['de', 'en']
|
resourceConfigurations += ['de', 'en']
|
||||||
@@ -63,12 +63,11 @@ android {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
|
||||||
compose = true
|
compose = true
|
||||||
}
|
}
|
||||||
|
|
||||||
composeOptions {
|
composeOptions {
|
||||||
kotlinCompilerExtensionVersion = "1.4.7"
|
kotlinCompilerExtensionVersion = "1.4.8"
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
@@ -89,44 +88,44 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
implementation 'androidx.core:core-ktx:1.10.0'
|
implementation 'androidx.core:core-ktx:1.10.1'
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.0-rc01'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation "androidx.compose.material3:material3:1.0.1"
|
implementation "androidx.compose.material3:material3:1.1.1"
|
||||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||||
implementation 'com.google.android.play:core-ktx:1.8.1'
|
implementation 'com.google.android.play:core-ktx:1.8.1'
|
||||||
implementation 'com.google.code.gson:gson:2.9.0'
|
implementation 'com.google.code.gson:gson:2.9.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
|
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.1'
|
||||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
|
implementation 'androidx.navigation:navigation-ui-ktx:2.7.1'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.6.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1'
|
||||||
implementation 'androidx.fragment:fragment-ktx:1.5.7'
|
implementation 'androidx.fragment:fragment-ktx:1.6.1'
|
||||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.3.0'
|
implementation 'androidx.recyclerview:recyclerview:1.3.1'
|
||||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
|
||||||
implementation 'androidx.compose.material:material-icons-extended:1.4.3'
|
implementation 'androidx.compose.material:material-icons-extended:1.5.0'
|
||||||
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"
|
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"
|
||||||
implementation 'androidx.activity:activity-compose:1.7.1'
|
implementation 'androidx.activity:activity-compose:1.7.2'
|
||||||
implementation "androidx.compose.ui:ui:1.4.3"
|
implementation "androidx.compose.ui:ui:1.5.0"
|
||||||
implementation "androidx.compose.ui:ui-tooling-preview:1.4.3"
|
implementation "androidx.compose.ui:ui-tooling-preview:1.5.0"
|
||||||
implementation "androidx.compose.runtime:runtime-livedata:1.4.3"
|
implementation "androidx.compose.runtime:runtime-livedata:1.5.0"
|
||||||
implementation "androidx.navigation:navigation-compose:2.5.3"
|
implementation "androidx.navigation:navigation-compose:2.7.1"
|
||||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
|
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.1"
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||||
implementation "com.google.dagger:hilt-android:2.44"
|
implementation "com.google.dagger:hilt-android:2.44"
|
||||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.4.3"
|
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.5.0"
|
||||||
debugImplementation "androidx.compose.ui:ui-tooling:1.4.3"
|
debugImplementation "androidx.compose.ui:ui-tooling:1.5.0"
|
||||||
debugImplementation "androidx.compose.ui:ui-test-manifest:1.4.3"
|
debugImplementation "androidx.compose.ui:ui-test-manifest:1.5.0"
|
||||||
kapt "com.google.dagger:hilt-compiler:2.44"
|
kapt "com.google.dagger:hilt-compiler:2.44"
|
||||||
implementation "androidx.room:room-runtime:2.5.1"
|
implementation "androidx.room:room-runtime:2.5.2"
|
||||||
annotationProcessor "androidx.room:room-compiler:2.5.1"
|
annotationProcessor "androidx.room:room-compiler:2.5.2"
|
||||||
kapt "androidx.room:room-compiler:2.5.1"
|
kapt "androidx.room:room-compiler:2.5.2"
|
||||||
implementation "androidx.room:room-ktx:2.5.1"
|
implementation "androidx.room:room-ktx:2.5.2"
|
||||||
implementation "androidx.multidex:multidex:2.0.1"
|
implementation "androidx.multidex:multidex:2.0.1"
|
||||||
api "androidx.navigation:navigation-fragment-ktx:2.5.3"
|
api "androidx.navigation:navigation-fragment-ktx:2.7.1"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow references to generated code
|
// Allow references to generated code
|
||||||
|
|||||||
@@ -6,30 +6,61 @@ import androidx.activity.compose.setContent
|
|||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.outlined.Calculate
|
||||||
import androidx.compose.material.icons.outlined.*
|
import androidx.compose.material.icons.outlined.Info
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material.icons.outlined.Keyboard
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material.icons.outlined.List
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.material.icons.outlined.MoreVert
|
||||||
|
import androidx.compose.material.icons.outlined.Redo
|
||||||
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
|
import androidx.compose.material.icons.outlined.Undo
|
||||||
|
import androidx.compose.material3.DrawerState
|
||||||
|
import androidx.compose.material3.DrawerValue
|
||||||
|
import androidx.compose.material3.FloatingActionButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ModalNavigationDrawer
|
||||||
|
import androidx.compose.material3.Scaffold
|
||||||
|
import androidx.compose.material3.SnackbarHost
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
|
import androidx.compose.material3.rememberDrawerState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.zobrist.tichucounter.domain.*
|
import me.zobrist.tichucounter.domain.DrawerItem
|
||||||
|
import me.zobrist.tichucounter.domain.KeepScreenOn
|
||||||
|
import me.zobrist.tichucounter.domain.Language
|
||||||
|
import me.zobrist.tichucounter.domain.ReviewService
|
||||||
|
import me.zobrist.tichucounter.domain.Route
|
||||||
|
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||||
|
import me.zobrist.tichucounter.domain.Theme
|
||||||
|
import me.zobrist.tichucounter.domain.TopBarAction
|
||||||
|
import me.zobrist.tichucounter.domain.TopBarState
|
||||||
|
import me.zobrist.tichucounter.domain.navigate
|
||||||
|
import me.zobrist.tichucounter.repository.GameRepository
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
import me.zobrist.tichucounter.ui.MainViewModel
|
import me.zobrist.tichucounter.ui.MainViewModel
|
||||||
import me.zobrist.tichucounter.ui.about.AboutView
|
import me.zobrist.tichucounter.ui.about.AboutView
|
||||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||||
import me.zobrist.tichucounter.ui.counter.*
|
import me.zobrist.tichucounter.ui.counter.Counter
|
||||||
|
import me.zobrist.tichucounter.ui.counter.CounterViewModel
|
||||||
import me.zobrist.tichucounter.ui.history.HistoryList
|
import me.zobrist.tichucounter.ui.history.HistoryList
|
||||||
import me.zobrist.tichucounter.ui.history.HistoryViewModel
|
import me.zobrist.tichucounter.ui.history.HistoryViewModel
|
||||||
import me.zobrist.tichucounter.ui.layout.DrawerContent
|
import me.zobrist.tichucounter.ui.layout.DrawerContent
|
||||||
@@ -39,21 +70,59 @@ import me.zobrist.tichucounter.ui.settings.SettingsViewModel
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var settingsAdapter: SettingsAdapter
|
lateinit var settingsAdapter: SettingsAdapter
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var repository: GameRepository
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var reviewService: ReviewService
|
||||||
|
|
||||||
private val counterViewModel: CounterViewModel by viewModels()
|
private val counterViewModel: CounterViewModel by viewModels()
|
||||||
private val historyViewModel: HistoryViewModel by viewModels()
|
private val historyViewModel: HistoryViewModel by viewModels()
|
||||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||||
private val mainViewModel: MainViewModel by viewModels()
|
private val mainViewModel: MainViewModel by viewModels()
|
||||||
|
|
||||||
|
private var requestReview: Boolean = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
settingsAdapter.registerOnChangeListener(this)
|
changeTheme(settingsAdapter.theme.value)
|
||||||
|
setKeepScreenOn(settingsAdapter.keepScreenOn.value)
|
||||||
|
changeLanguage(settingsAdapter.language.value)
|
||||||
|
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
settingsAdapter.theme.collect {
|
||||||
|
changeTheme(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lifecycleScope.launch {
|
||||||
|
settingsAdapter.keepScreenOn.collect {
|
||||||
|
setKeepScreenOn(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lifecycleScope.launch {
|
||||||
|
settingsAdapter.language.collect {
|
||||||
|
changeLanguage(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lifecycleScope.launch {
|
||||||
|
settingsAdapter.gameFinished.collect {
|
||||||
|
if (!requestReview) {
|
||||||
|
requestReview = true
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
if (it) {
|
||||||
|
reviewService.request()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
AppTheme {
|
AppTheme {
|
||||||
@@ -64,16 +133,11 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
private fun changeLanguage(language: Language) {
|
||||||
super.onDestroy()
|
|
||||||
settingsAdapter.unregisterOnChangeListener(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLanguageChanged(language: Language) {
|
|
||||||
AppCompatDelegate.setApplicationLocales(language.value)
|
AppCompatDelegate.setApplicationLocales(language.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onThemeChanged(theme: Theme) {
|
private fun changeTheme(theme: Theme) {
|
||||||
val themeValue = when (theme) {
|
val themeValue = when (theme) {
|
||||||
Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||||
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||||
@@ -82,7 +146,7 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
AppCompatDelegate.setDefaultNightMode(themeValue)
|
AppCompatDelegate.setDefaultNightMode(themeValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScreenOnChanged(keepOn: KeepScreenOn) {
|
private fun setKeepScreenOn(keepOn: KeepScreenOn) {
|
||||||
if (keepOn.value) {
|
if (keepOn.value) {
|
||||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
} else {
|
} else {
|
||||||
@@ -90,7 +154,6 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun NavigationDrawer() {
|
private fun NavigationDrawer() {
|
||||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||||
@@ -144,7 +207,6 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MyScaffoldLayout(
|
fun MyScaffoldLayout(
|
||||||
drawerState: DrawerState,
|
drawerState: DrawerState,
|
||||||
@@ -155,8 +217,10 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
var topBarState by remember { mutableStateOf(TopBarState()) }
|
var topBarState by remember { mutableStateOf(TopBarState()) }
|
||||||
|
var snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
if (showFab) {
|
if (showFab) {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
@@ -172,7 +236,7 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
startDestination = Route.COUNTER.name,
|
startDestination = Route.COUNTER.name,
|
||||||
modifier = Modifier.padding(paddings)
|
modifier = Modifier.padding(paddings)
|
||||||
) {
|
) {
|
||||||
composable(Route.COUNTER) {
|
this.composable(Route.COUNTER.name.toString()) {
|
||||||
|
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -192,42 +256,48 @@ class MainActivity : AppCompatActivity(), ISettingsChangeListener {
|
|||||||
mainViewModel.activeGameHasRounds,
|
mainViewModel.activeGameHasRounds,
|
||||||
{ expanded = true }
|
{ expanded = true }
|
||||||
) {
|
) {
|
||||||
|
val newGameTranslated = stringResource(R.string.new_game)
|
||||||
DropDownMenu(
|
DropDownMenu(
|
||||||
mapOf("new" to R.string.newGame),
|
listOf(newGameTranslated),
|
||||||
"",
|
"",
|
||||||
expanded,
|
expanded,
|
||||||
) {
|
) {
|
||||||
expanded = false
|
expanded = false
|
||||||
it?.let {
|
it?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
"new" -> mainViewModel.newGame()
|
newGameTranslated -> lifecycleScope.launch { repository.newGame() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
))
|
))
|
||||||
) { scope.launch {
|
) {
|
||||||
currentFocus?.clearFocus()
|
scope.launch {
|
||||||
drawerState.open()
|
currentFocus?.clearFocus()
|
||||||
} }
|
drawerState.open()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Counter(counterViewModel)
|
Counter(counterViewModel)
|
||||||
}
|
}
|
||||||
composable(Route.HISTORY) {
|
composable(Route.HISTORY.name) {
|
||||||
topBarState =
|
topBarState =
|
||||||
TopBarState(title = stringResource(R.string.menu_history)) { scope.launch { drawerState.open() } }
|
TopBarState(title = stringResource(R.string.menu_history)) { scope.launch { drawerState.open() } }
|
||||||
|
|
||||||
HistoryList(historyViewModel) { navController.navigate(Route.COUNTER) }
|
HistoryList(
|
||||||
|
historyViewModel,
|
||||||
|
snackbarHostState
|
||||||
|
) { navController.navigate(Route.COUNTER) }
|
||||||
}
|
}
|
||||||
composable(Route.SETTINGS) {
|
composable(Route.SETTINGS.name) {
|
||||||
topBarState =
|
topBarState =
|
||||||
TopBarState(title = stringResource(R.string.menu_settings)) { scope.launch { drawerState.open() } }
|
TopBarState(title = stringResource(R.string.menu_settings)) { scope.launch { drawerState.open() } }
|
||||||
|
|
||||||
SettingsView(settingsViewModel)
|
SettingsView(settingsViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(Route.ABOUT) {
|
composable(Route.ABOUT.name) {
|
||||||
topBarState =
|
topBarState =
|
||||||
TopBarState(title = stringResource(R.string.menu_about)) { scope.launch { drawerState.open() } }
|
TopBarState(title = stringResource(R.string.menu_about)) { scope.launch { drawerState.open() } }
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package me.zobrist.tichucounter.data
|
|||||||
|
|
||||||
import androidx.room.ProvidedTypeConverter
|
import androidx.room.ProvidedTypeConverter
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
|
|
||||||
@ProvidedTypeConverter
|
@ProvidedTypeConverter
|
||||||
object DateConverter {
|
object DateConverter {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package me.zobrist.tichucounter.data.entity
|
|||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
data class Game(
|
data class Game(
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package me.zobrist.tichucounter.domain
|
package me.zobrist.tichucounter.domain
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.*
|
|
||||||
import androidx.navigation.compose.composable
|
|
||||||
|
|
||||||
fun NavController.navigate(route: Route) {
|
fun NavController.navigate(route: Route) {
|
||||||
this.navigate(route.name) {
|
this.navigate(route.name) {
|
||||||
@@ -19,12 +17,3 @@ fun NavController.navigate(route: Route) {
|
|||||||
restoreState = true
|
restoreState = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun NavGraphBuilder.composable(
|
|
||||||
route: Route,
|
|
||||||
arguments: List<NamedNavArgument> = emptyList(),
|
|
||||||
deepLinks: List<NavDeepLink> = emptyList(),
|
|
||||||
content: @Composable (NavBackStackEntry) -> Unit
|
|
||||||
) {
|
|
||||||
this.composable(route.name, arguments, deepLinks, content)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package me.zobrist.tichucounter.domain
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
|
import com.google.android.play.core.review.ReviewManagerFactory
|
||||||
|
import dagger.hilt.android.qualifiers.ActivityContext
|
||||||
|
import java.util.Date
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class ReviewService @Inject constructor(@ActivityContext private val appContext: Context) {
|
||||||
|
|
||||||
|
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(appContext)
|
||||||
|
|
||||||
|
private val THREE_MONTHS: Long = 7776000000
|
||||||
|
|
||||||
|
private var requestCalled: Int
|
||||||
|
get() = sharedPreferences.getInt("requestCalled", 0)
|
||||||
|
set(value) {
|
||||||
|
val editor = sharedPreferences.edit()
|
||||||
|
editor.putInt("requestCalled", value)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
private var nextReviewedDate: Date
|
||||||
|
get() = Date(sharedPreferences.getLong("lastReviewedDate", 0))
|
||||||
|
set(value) {
|
||||||
|
val editor = sharedPreferences.edit()
|
||||||
|
editor.putLong("lastReviewedDate", value.time)
|
||||||
|
editor.apply()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun request() {
|
||||||
|
requestCalled += 1
|
||||||
|
|
||||||
|
if (requestCalled >= 3) {
|
||||||
|
if (nextReviewedDate.time < System.currentTimeMillis()) {
|
||||||
|
requestCalled = 0
|
||||||
|
nextReviewedDate = Date(System.currentTimeMillis() + THREE_MONTHS)
|
||||||
|
|
||||||
|
val manager = ReviewManagerFactory.create(appContext)
|
||||||
|
|
||||||
|
val request = manager.requestReviewFlow()
|
||||||
|
request.addOnCompleteListener { task ->
|
||||||
|
if (task.isSuccessful) {
|
||||||
|
// We got the ReviewInfo object
|
||||||
|
val reviewInfo = task.result
|
||||||
|
manager.launchReviewFlow(appContext as Activity, reviewInfo)
|
||||||
|
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,10 @@ import android.content.Context
|
|||||||
import androidx.core.os.LocaleListCompat
|
import androidx.core.os.LocaleListCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@@ -16,77 +20,76 @@ enum class Language(val value: LocaleListCompat) {
|
|||||||
|
|
||||||
enum class KeepScreenOn(val value: Boolean) { ON(true), OFF(false) }
|
enum class KeepScreenOn(val value: Boolean) { ON(true), OFF(false) }
|
||||||
|
|
||||||
interface ISettingsChangeListener {
|
typealias VictoryPoints = Int
|
||||||
fun onLanguageChanged(language: Language)
|
typealias GameWon = Boolean
|
||||||
fun onThemeChanged(theme: Theme)
|
|
||||||
fun onScreenOnChanged(keepOn: KeepScreenOn)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class SettingsAdapter @Inject constructor(@ApplicationContext private val context: Context) {
|
class SettingsAdapter @Inject constructor(@ApplicationContext private val context: Context) {
|
||||||
|
|
||||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||||
private var listenerList = mutableListOf<ISettingsChangeListener>()
|
|
||||||
|
|
||||||
var language: Language
|
val language = MutableStateFlow(Language.DEFAULT)
|
||||||
private set
|
|
||||||
|
|
||||||
var theme: Theme
|
val theme = MutableStateFlow(Theme.DEFAULT)
|
||||||
private set
|
|
||||||
|
|
||||||
var keepScreenOn: KeepScreenOn
|
val keepScreenOn = MutableStateFlow(KeepScreenOn.OFF)
|
||||||
private set
|
|
||||||
|
val victoryPoints = MutableStateFlow(0)
|
||||||
|
|
||||||
|
val gameFinished = MutableStateFlow(false)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
language = try {
|
language.value = try {
|
||||||
enumValueOf(sharedPreferences.getString(Language::class.simpleName, null)!!)
|
enumValueOf(sharedPreferences.getString(Language::class.simpleName, null)!!)
|
||||||
} catch (_: NullPointerException) {
|
} catch (_: NullPointerException) {
|
||||||
Language.DEFAULT
|
Language.DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
theme = try {
|
theme.value = try {
|
||||||
enumValueOf(sharedPreferences.getString(Theme::class.simpleName, null)!!)
|
enumValueOf(sharedPreferences.getString(Theme::class.simpleName, null)!!)
|
||||||
} catch (_: java.lang.Exception) {
|
} catch (_: java.lang.Exception) {
|
||||||
Theme.DEFAULT
|
Theme.DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
keepScreenOn = try {
|
keepScreenOn.value = try {
|
||||||
enumValueOf(sharedPreferences.getString(KeepScreenOn::class.simpleName, null)!!)
|
enumValueOf(sharedPreferences.getString(KeepScreenOn::class.simpleName, null)!!)
|
||||||
} catch (_: java.lang.Exception) {
|
} catch (_: java.lang.Exception) {
|
||||||
KeepScreenOn.OFF
|
KeepScreenOn.OFF
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun registerOnChangeListener(listener: ISettingsChangeListener) {
|
victoryPoints.value = sharedPreferences.getInt(VictoryPoints::class.simpleName, 1000)
|
||||||
listenerList.add(listener)
|
|
||||||
|
|
||||||
listener.onThemeChanged(theme)
|
gameFinished.value = sharedPreferences.getBoolean(GameWon::class.simpleName, false)
|
||||||
listener.onLanguageChanged(language)
|
|
||||||
listener.onScreenOnChanged(keepScreenOn)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unregisterOnChangeListener(listener: ISettingsChangeListener?) {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
if (listener != null) {
|
language.collect {
|
||||||
listenerList.remove(listener)
|
updatePreference(Language::class.simpleName, it.name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun setLanguage(language: Language) {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
this.language = language
|
theme.collect {
|
||||||
updatePreference(Language::class.simpleName, language.name)
|
updatePreference(Theme::class.simpleName, it.name)
|
||||||
notifyListeners(language)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setTheme(theme: Theme) {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
this.theme = theme
|
keepScreenOn.collect {
|
||||||
updatePreference(Theme::class.simpleName, theme.name)
|
updatePreference(KeepScreenOn::class.simpleName, it.name)
|
||||||
notifyListeners(theme)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setKeepScreenOn(setting: KeepScreenOn) {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
this.keepScreenOn = setting
|
victoryPoints.collect {
|
||||||
updatePreference(KeepScreenOn::class.simpleName, setting.name)
|
updatePreference(VictoryPoints::class.simpleName, it)
|
||||||
notifyListeners(setting)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
|
gameFinished.collect {
|
||||||
|
updatePreference(GameWon::class.simpleName, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updatePreference(name: String?, value: String) {
|
private fun updatePreference(name: String?, value: String) {
|
||||||
@@ -95,22 +98,15 @@ class SettingsAdapter @Inject constructor(@ApplicationContext private val contex
|
|||||||
editor.apply()
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyListeners(language: Language) {
|
private fun updatePreference(name: String?, value: Boolean) {
|
||||||
listenerList.forEach {
|
val editor = sharedPreferences.edit()
|
||||||
it.onLanguageChanged(language)
|
editor.putBoolean(name, value)
|
||||||
}
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyListeners(theme: Theme) {
|
private fun updatePreference(name: String?, value: Int) {
|
||||||
listenerList.forEach {
|
val editor = sharedPreferences.edit()
|
||||||
it.onThemeChanged(theme)
|
editor.putInt(name, value)
|
||||||
}
|
editor.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun notifyListeners(keepScreenOn: KeepScreenOn) {
|
|
||||||
listenerList.forEach {
|
|
||||||
it.onScreenOnChanged(keepScreenOn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,11 @@ package me.zobrist.tichucounter.repository
|
|||||||
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.filter
|
||||||
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.take
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import me.zobrist.tichucounter.data.GameDao
|
import me.zobrist.tichucounter.data.GameDao
|
||||||
@@ -10,7 +14,7 @@ import me.zobrist.tichucounter.data.GameWithScores
|
|||||||
import me.zobrist.tichucounter.data.RoundDao
|
import me.zobrist.tichucounter.data.RoundDao
|
||||||
import me.zobrist.tichucounter.data.entity.Game
|
import me.zobrist.tichucounter.data.entity.Game
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class GameRepository @Inject constructor(
|
class GameRepository @Inject constructor(
|
||||||
@@ -18,9 +22,10 @@ class GameRepository @Inject constructor(
|
|||||||
private val roundDao: RoundDao
|
private val roundDao: RoundDao
|
||||||
) {
|
) {
|
||||||
|
|
||||||
private var activeGame: Game = Game(true, "TeamA", "TeamB", Date(), Date())
|
var activeGame: Game = Game(true, "TeamA", "TeamB", Date(), Date())
|
||||||
|
private set
|
||||||
|
|
||||||
private var distinctTeamNames: List<String> = listOf()
|
private val newGameFlow = MutableStateFlow(Game())
|
||||||
|
|
||||||
init {
|
init {
|
||||||
CoroutineScope(Dispatchers.IO).launch {
|
CoroutineScope(Dispatchers.IO).launch {
|
||||||
@@ -38,6 +43,7 @@ class GameRepository @Inject constructor(
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val id = gameDao.insert(Game(true, activeGame.nameA, activeGame.nameB, Date(), Date()))
|
val id = gameDao.insert(Game(true, activeGame.nameA, activeGame.nameB, Date(), Date()))
|
||||||
setActive(id)
|
setActive(id)
|
||||||
|
newGameFlow.value = gameDao.getGameById(id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,6 +137,10 @@ class GameRepository @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getDistinctTeamNames(): Flow<List<String>> {
|
fun getDistinctTeamNames(): Flow<List<String>> {
|
||||||
return gameDao.getDistinctTeamNames()
|
return gameDao.getDistinctTeamNames()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getNewGameStarted(): Flow<Game> {
|
||||||
|
return newGameFlow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ 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.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import me.zobrist.tichucounter.data.entity.Game
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import me.zobrist.tichucounter.repository.GameRepository
|
import me.zobrist.tichucounter.repository.GameRepository
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@@ -29,6 +30,8 @@ class MainViewModel @Inject constructor(
|
|||||||
var activeGameHasRounds by mutableStateOf(false)
|
var activeGameHasRounds by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
private var newGame: Game? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
||||||
@@ -45,6 +48,16 @@ class MainViewModel @Inject constructor(
|
|||||||
expectedRoundCount = it.rounds.count()
|
expectedRoundCount = it.rounds.count()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viewModelScope.launch {
|
||||||
|
gameRepository.getNewGameStarted().collect {
|
||||||
|
if (newGame == null) {
|
||||||
|
newGame = it
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
redoRounds.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun undoLastRound() {
|
fun undoLastRound() {
|
||||||
@@ -69,11 +82,4 @@ class MainViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun newGame() {
|
|
||||||
viewModelScope.launch {
|
|
||||||
redoRounds.clear()
|
|
||||||
gameRepository.newGame()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,11 @@ package me.zobrist.tichucounter.ui
|
|||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.darkColorScheme
|
||||||
|
import androidx.compose.material3.dynamicDarkColorScheme
|
||||||
|
import androidx.compose.material3.dynamicLightColorScheme
|
||||||
|
import androidx.compose.material3.lightColorScheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,20 @@ package me.zobrist.tichucounter.ui.about
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Mail
|
import androidx.compose.material.icons.outlined.Mail
|
||||||
import androidx.compose.material.icons.outlined.Shop
|
import androidx.compose.material.icons.outlined.Shop
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ShapeDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment.Companion.Top
|
import androidx.compose.ui.Alignment.Companion.Top
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@@ -39,7 +48,7 @@ fun AboutView() {
|
|||||||
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Row() {
|
Row {
|
||||||
Image(
|
Image(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(end = 10.dp)
|
.padding(end = 10.dp)
|
||||||
@@ -92,7 +101,7 @@ fun AboutView() {
|
|||||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||||
@Composable
|
@Composable
|
||||||
fun AboutViewPreview() {
|
fun AboutViewPreview() {
|
||||||
AppTheme() {
|
AppTheme {
|
||||||
Surface {
|
Surface {
|
||||||
AboutView()
|
AboutView()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,25 +7,29 @@ import androidx.compose.material3.DropdownMenuItem
|
|||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun <T> DropDownMenu(map: Map<T, Int>, selected: T, expanded: Boolean, onSelected: (T?) -> Unit) {
|
fun <T> DropDownMenu(
|
||||||
|
list: Collection<T>,
|
||||||
|
selected: T,
|
||||||
|
expanded: Boolean,
|
||||||
|
onSelected: (T?) -> Unit
|
||||||
|
) {
|
||||||
DropdownMenu(
|
DropdownMenu(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onDismissRequest = { onSelected(null) }
|
onDismissRequest = { onSelected(null) }
|
||||||
) {
|
) {
|
||||||
map.forEach {
|
list.forEach {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = {
|
onClick = {
|
||||||
onSelected(it.key)
|
onSelected(it)
|
||||||
},
|
},
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
if (it.key == selected) {
|
if (it == selected) {
|
||||||
Icon(Icons.Outlined.Check, null)
|
Icon(Icons.Outlined.Check, null)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
text = { Text(stringResource(it.value)) },
|
text = { Text(it.toString()) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,17 @@ package me.zobrist.tichucounter.ui.composables
|
|||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.ExposedDropdownMenuBox
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.material3.TextFieldColors
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.ExperimentalComposeUiApi
|
import androidx.compose.ui.ExperimentalComposeUiApi
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
@@ -61,30 +70,31 @@ fun TypeaheadTextField(
|
|||||||
}
|
}
|
||||||
.onSizeChanged { dropDownWidth = it.width }
|
.onSizeChanged { dropDownWidth = it.width }
|
||||||
.onKeyEvent { event ->
|
.onKeyEvent { event ->
|
||||||
if (event.key == Key.Back || event.key == Key.Enter) {
|
if (event.key == Key.Back || event.key == Key.Enter) {
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
true
|
true
|
||||||
}
|
} else {
|
||||||
false
|
false
|
||||||
},
|
}
|
||||||
|
},
|
||||||
colors = colors
|
colors = colors
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = isFocused && items.isNotEmpty(),
|
expanded = isFocused && items.isNotEmpty(),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(with(LocalDensity.current){dropDownWidth.toDp()}),
|
.width(with(LocalDensity.current) { dropDownWidth.toDp() }),
|
||||||
onDismissRequest = { }
|
onDismissRequest = { }
|
||||||
) {
|
) {
|
||||||
|
|
||||||
items.forEach {
|
items.forEach {
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
onClick = {
|
onClick = {
|
||||||
onValueChange(it)
|
onValueChange(it)
|
||||||
focusManager.clearFocus()
|
focusManager.clearFocus()
|
||||||
},
|
},
|
||||||
text = { Text(it) },
|
text = { Text(it) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,12 +3,24 @@ package me.zobrist.tichucounter.ui.counter
|
|||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.EmojiEvents
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import me.zobrist.tichucounter.R
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
|
|
||||||
@@ -19,6 +31,18 @@ fun Counter(viewModel: ICounterViewModel = PreviewViewModel()) {
|
|||||||
var orientation by remember { mutableStateOf(Configuration.ORIENTATION_PORTRAIT) }
|
var orientation by remember { mutableStateOf(Configuration.ORIENTATION_PORTRAIT) }
|
||||||
orientation = LocalConfiguration.current.orientation
|
orientation = LocalConfiguration.current.orientation
|
||||||
|
|
||||||
|
if (viewModel.showVictoryDialog) {
|
||||||
|
GameVictoryDialog(
|
||||||
|
viewModel.totalScoreA,
|
||||||
|
viewModel.totalScoreB,
|
||||||
|
viewModel.teamNameA,
|
||||||
|
viewModel.teamNameB,
|
||||||
|
{ viewModel.victoryDialogExecuted(false) })
|
||||||
|
{
|
||||||
|
viewModel.victoryDialogExecuted(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Surface {
|
Surface {
|
||||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
Landscape(viewModel)
|
Landscape(viewModel)
|
||||||
@@ -98,6 +122,54 @@ fun CounterViewPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Preview()
|
||||||
|
@Composable
|
||||||
|
fun GameVictoryDialog(
|
||||||
|
pointsA: Int = 2000,
|
||||||
|
pointsB: Int = 50,
|
||||||
|
nameA: String = "nameA",
|
||||||
|
nameB: String = "nameB",
|
||||||
|
onDismiss: () -> Unit = {},
|
||||||
|
onNewGame: () -> Unit = {},
|
||||||
|
) {
|
||||||
|
|
||||||
|
val winner = if (pointsA > pointsB) {
|
||||||
|
nameA
|
||||||
|
} else {
|
||||||
|
nameB
|
||||||
|
}
|
||||||
|
|
||||||
|
val message = if (pointsA == pointsB) {
|
||||||
|
stringResource(R.string.draw_message, winner, 100)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.victory_message)
|
||||||
|
}
|
||||||
|
|
||||||
|
val title = if (pointsA == pointsB) {
|
||||||
|
stringResource(R.string.draw_title)
|
||||||
|
} else {
|
||||||
|
stringResource(R.string.victory_title, winner)
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = { onDismiss() },
|
||||||
|
dismissButton = {
|
||||||
|
TextButton({ onDismiss() }) {
|
||||||
|
Text(stringResource(R.string.abort))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton({ onNewGame() }) {
|
||||||
|
Text(stringResource(R.string.new_game))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
icon = { Icon(Icons.Outlined.EmojiEvents, null) },
|
||||||
|
title = { Text(title) },
|
||||||
|
text = { Text(message) }
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
internal class PreviewViewModel : ICounterViewModel {
|
internal class PreviewViewModel : ICounterViewModel {
|
||||||
override var roundScoreList: List<Round> =
|
override var roundScoreList: List<Round> =
|
||||||
listOf(Round(1, 10, 90), Round(1, 50, 50), Round(1, 70, 30))
|
listOf(Round(1, 10, 90), Round(1, 50, 50), Round(1, 70, 30))
|
||||||
@@ -115,8 +187,11 @@ internal class PreviewViewModel : ICounterViewModel {
|
|||||||
override var activeValue: String = currentScoreA
|
override var activeValue: String = currentScoreA
|
||||||
override var inactiveValue: String = currentScoreB
|
override var inactiveValue: String = currentScoreB
|
||||||
override var keyboardHidden: Boolean = false
|
override var keyboardHidden: Boolean = false
|
||||||
override val teamNameSuggestionsA: List<String> = listOf("TeamA", "asdffd", "TeamB", "really really long Team Name that is way too long")
|
override val teamNameSuggestionsA: List<String> =
|
||||||
override val teamNameSuggestionsB: List<String> = listOf("TeamA", "asdffd", "TeamB", "really really long Team Name that is way too long")
|
listOf("TeamA", "asdffd", "TeamB", "really really long Team Name that is way too long")
|
||||||
|
override val teamNameSuggestionsB: List<String> =
|
||||||
|
listOf("TeamA", "asdffd", "TeamB", "really really long Team Name that is way too long")
|
||||||
|
override var showVictoryDialog: Boolean = false
|
||||||
|
|
||||||
override fun focusLastInput() {
|
override fun focusLastInput() {
|
||||||
}
|
}
|
||||||
@@ -149,6 +224,9 @@ internal class PreviewViewModel : ICounterViewModel {
|
|||||||
override fun updateNameB(value: String) {
|
override fun updateNameB(value: String) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun victoryDialogExecuted(result: Boolean) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateFocusStateA(state: Boolean) {
|
override fun updateFocusStateA(state: Boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package me.zobrist.tichucounter.ui.counter
|
package me.zobrist.tichucounter.ui.counter
|
||||||
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
@@ -10,10 +10,10 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collect
|
|
||||||
import kotlinx.coroutines.flow.take
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import me.zobrist.tichucounter.data.entity.Game
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
|
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||||
import me.zobrist.tichucounter.domain.Tichu
|
import me.zobrist.tichucounter.domain.Tichu
|
||||||
import me.zobrist.tichucounter.domain.digitCount
|
import me.zobrist.tichucounter.domain.digitCount
|
||||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||||
@@ -60,24 +60,27 @@ interface ICounterViewModel : IKeyBoardViewModel {
|
|||||||
val teamNameB: String
|
val teamNameB: String
|
||||||
val teamNameSuggestionsA: List<String>
|
val teamNameSuggestionsA: List<String>
|
||||||
val teamNameSuggestionsB: List<String>
|
val teamNameSuggestionsB: List<String>
|
||||||
|
val showVictoryDialog: Boolean
|
||||||
|
|
||||||
fun updateNameA(value: String)
|
fun updateNameA(value: String)
|
||||||
fun updateNameB(value: String)
|
fun updateNameB(value: String)
|
||||||
|
fun victoryDialogExecuted(result: Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class CounterViewModel @Inject constructor(
|
class CounterViewModel @Inject constructor(
|
||||||
private val gameRepository: GameRepository
|
private val gameRepository: GameRepository,
|
||||||
|
private val settings: SettingsAdapter
|
||||||
) :
|
) :
|
||||||
ViewModel(), ICounterViewModel {
|
ViewModel(), ICounterViewModel {
|
||||||
|
|
||||||
override var roundScoreList by mutableStateOf(emptyList<Round>())
|
override var roundScoreList by mutableStateOf(emptyList<Round>())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override var totalScoreA by mutableStateOf(0)
|
override var totalScoreA by mutableIntStateOf(0)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override var totalScoreB by mutableStateOf(0)
|
override var totalScoreB by mutableIntStateOf(0)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
override var teamNameA by mutableStateOf("")
|
override var teamNameA by mutableStateOf("")
|
||||||
@@ -115,6 +118,8 @@ class CounterViewModel @Inject constructor(
|
|||||||
|
|
||||||
override var teamNameSuggestionsB by mutableStateOf(listOf<String>())
|
override var teamNameSuggestionsB by mutableStateOf(listOf<String>())
|
||||||
private set
|
private set
|
||||||
|
override var showVictoryDialog by mutableStateOf(false)
|
||||||
|
private set
|
||||||
|
|
||||||
override var activeValue: String
|
override var activeValue: String
|
||||||
get() {
|
get() {
|
||||||
@@ -157,11 +162,18 @@ class CounterViewModel @Inject constructor(
|
|||||||
|
|
||||||
private var distinctTeamNames = listOf<String>()
|
private var distinctTeamNames = listOf<String>()
|
||||||
|
|
||||||
|
private var lastGame: Game? = null
|
||||||
|
private var lastVictoryPoints: Int? = null
|
||||||
|
|
||||||
|
private val gameWon: Boolean
|
||||||
|
get() = totalScoreA >= settings.victoryPoints.value || totalScoreB >= settings.victoryPoints.value
|
||||||
|
|
||||||
|
private var lastRoundCount: Int = 0
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
gameRepository.getActiveGameFlow().collect {
|
gameRepository.getActiveGameFlow().collect {
|
||||||
if (it != null) {
|
if (it != null) {
|
||||||
|
|
||||||
val score = it.getTotalPoints()
|
val score = it.getTotalPoints()
|
||||||
|
|
||||||
roundScoreList = it.rounds
|
roundScoreList = it.rounds
|
||||||
@@ -173,17 +185,52 @@ class CounterViewModel @Inject constructor(
|
|||||||
|
|
||||||
buildTeamNameSuggestions()
|
buildTeamNameSuggestions()
|
||||||
|
|
||||||
|
// Game has changed
|
||||||
|
if (it.game.uid != lastGame?.uid) {
|
||||||
|
if (lastGame != null) {
|
||||||
|
settings.gameFinished.value = false
|
||||||
|
}
|
||||||
|
lastGame = it.game
|
||||||
|
lastRoundCount = it.rounds.size
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
|
||||||
|
// Game winning condition
|
||||||
|
if (!settings.gameFinished.value) {
|
||||||
|
if (gameWon) {
|
||||||
|
showVictoryDialog = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undo game winning if rounds were removed
|
||||||
|
if (lastRoundCount > it.rounds.size) {
|
||||||
|
if (!gameWon) {
|
||||||
|
settings.gameFinished.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastRoundCount = it.rounds.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
gameRepository.getDistinctTeamNames().collect() {
|
gameRepository.getDistinctTeamNames().collect {
|
||||||
distinctTeamNames = it
|
distinctTeamNames = it
|
||||||
|
|
||||||
buildTeamNameSuggestions()
|
buildTeamNameSuggestions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
viewModelScope.launch {
|
||||||
|
settings.victoryPoints.collect {
|
||||||
|
if (lastVictoryPoints == null) {
|
||||||
|
lastVictoryPoints = it
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
|
||||||
|
// Game was already won and will be won also with new settings
|
||||||
|
settings.gameFinished.value = settings.gameFinished.value && gameWon
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun focusLastInput() {
|
override fun focusLastInput() {
|
||||||
@@ -292,6 +339,17 @@ class CounterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun victoryDialogExecuted(result: Boolean) {
|
||||||
|
showVictoryDialog = false
|
||||||
|
settings.gameFinished.value = true
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
gameRepository.newGame()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun updateFocusStateA(state: Boolean) {
|
override fun updateFocusStateA(state: Boolean) {
|
||||||
isAFocused = state
|
isAFocused = state
|
||||||
if (state) {
|
if (state) {
|
||||||
@@ -351,17 +409,16 @@ class CounterViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildTeamNameSuggestions(){
|
private fun buildTeamNameSuggestions() {
|
||||||
teamNameSuggestionsA = buildTypeaheadList(distinctTeamNames, teamNameA)
|
teamNameSuggestionsA = buildTypeaheadList(distinctTeamNames, teamNameA)
|
||||||
teamNameSuggestionsB = buildTypeaheadList(distinctTeamNames, teamNameB)
|
teamNameSuggestionsB = buildTypeaheadList(distinctTeamNames, teamNameB)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildTypeaheadList(rawList: List<String>, currentInput: String ): List<String> {
|
private fun buildTypeaheadList(rawList: List<String>, currentInput: String): List<String> {
|
||||||
var filtered = rawList.filter { it.isNotEmpty() && it != currentInput }
|
var filtered = rawList.filter { it.isNotEmpty() && it != currentInput }
|
||||||
|
|
||||||
if(currentInput.isNotEmpty())
|
if (currentInput.isNotEmpty()) {
|
||||||
{
|
filtered = filtered.filter { it.contains(currentInput, ignoreCase = true) }
|
||||||
filtered = filtered.filter { it.contains(currentInput) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered.sorted().sortedBy { it.length }.take(10)
|
return filtered.sorted().sortedBy { it.length }.take(10)
|
||||||
|
|||||||
@@ -1,17 +1,41 @@
|
|||||||
package me.zobrist.tichucounter.ui.counter
|
package me.zobrist.tichucounter.ui.counter
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.animation.core.*
|
import androidx.compose.animation.core.RepeatMode
|
||||||
|
import androidx.compose.animation.core.animateFloat
|
||||||
|
import androidx.compose.animation.core.infiniteRepeatable
|
||||||
|
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||||
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.foundation.layout.wrapContentWidth
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.Backspace
|
import androidx.compose.material.icons.outlined.Backspace
|
||||||
import androidx.compose.material.icons.outlined.Check
|
import androidx.compose.material.icons.outlined.Check
|
||||||
import androidx.compose.material.icons.outlined.KeyboardHide
|
import androidx.compose.material.icons.outlined.KeyboardHide
|
||||||
import androidx.compose.material.icons.outlined.SwapHoriz
|
import androidx.compose.material.icons.outlined.SwapHoriz
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.Divider
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.ElevatedButton
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.CompositionLocalProvider
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.FocusRequester
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
@@ -20,6 +44,7 @@ import androidx.compose.ui.focus.focusRequester
|
|||||||
import androidx.compose.ui.focus.onFocusChanged
|
import androidx.compose.ui.focus.onFocusChanged
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
|
import androidx.compose.ui.platform.LocalTextInputService
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -251,7 +276,6 @@ fun KeyboardIconButton(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CenteredTextField(
|
fun CenteredTextField(
|
||||||
value: String,
|
value: String,
|
||||||
@@ -268,37 +292,40 @@ fun CenteredTextField(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Box(contentAlignment = Alignment.Center) {
|
Box(contentAlignment = Alignment.Center) {
|
||||||
TextField(
|
CompositionLocalProvider(LocalTextInputService provides null) {
|
||||||
value = value,
|
TextField(
|
||||||
onValueChange = { },
|
value = value,
|
||||||
placeholder = {
|
onValueChange = { },
|
||||||
if (!focused) {
|
placeholder = {
|
||||||
Text(
|
if (!focused) {
|
||||||
placeholder,
|
Text(
|
||||||
textAlign = TextAlign.Center,
|
placeholder,
|
||||||
modifier = Modifier.fillMaxWidth()
|
textAlign = TextAlign.Center,
|
||||||
)
|
modifier = Modifier.fillMaxWidth()
|
||||||
}
|
)
|
||||||
},
|
}
|
||||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
},
|
||||||
singleLine = true,
|
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||||
readOnly = true,
|
singleLine = true,
|
||||||
modifier = modifier
|
readOnly = true,
|
||||||
.fillMaxWidth()
|
modifier = modifier
|
||||||
.onFocusChanged {
|
.fillMaxWidth()
|
||||||
onFocusStateChanged(it)
|
.onFocusChanged {
|
||||||
}
|
onFocusStateChanged(it)
|
||||||
)
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (focused) {
|
if (focused) {
|
||||||
val cursorColor = MaterialTheme.colorScheme.onSurface
|
val cursorColor = MaterialTheme.colorScheme.onSurface
|
||||||
val infiniteTransition = rememberInfiniteTransition()
|
val infiniteTransition = rememberInfiniteTransition(label = "blinkingCursor")
|
||||||
val alpha by infiniteTransition.animateFloat(
|
val alpha by infiniteTransition.animateFloat(
|
||||||
0f,
|
0f,
|
||||||
cursorColor.alpha,
|
cursorColor.alpha,
|
||||||
animationSpec = infiniteRepeatable(
|
animationSpec = infiniteRepeatable(
|
||||||
animation = tween(500),
|
animation = tween(500),
|
||||||
repeatMode = RepeatMode.Reverse
|
repeatMode = RepeatMode.Reverse
|
||||||
)
|
), label = "blinkingCursor"
|
||||||
)
|
)
|
||||||
Row {
|
Row {
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
package me.zobrist.tichucounter.ui.counter
|
package me.zobrist.tichucounter.ui.counter
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.TextFieldDefaults
|
||||||
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.focus.onFocusChanged
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
import me.zobrist.tichucounter.ui.composables.TypeaheadTextField
|
import me.zobrist.tichucounter.ui.composables.TypeaheadTextField
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TeamNamesView(
|
fun TeamNamesView(
|
||||||
nameA: String,
|
nameA: String,
|
||||||
@@ -25,8 +24,11 @@ fun TeamNamesView(
|
|||||||
updateB: (String) -> Unit
|
updateB: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val color = TextFieldDefaults.textFieldColors(
|
val containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
|
val color = TextFieldDefaults.colors(
|
||||||
|
focusedContainerColor = containerColor,
|
||||||
|
unfocusedContainerColor = containerColor,
|
||||||
|
disabledContainerColor = containerColor,
|
||||||
)
|
)
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import android.content.res.Configuration
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
|||||||
@@ -1,39 +1,80 @@
|
|||||||
package me.zobrist.tichucounter.ui.history
|
package me.zobrist.tichucounter.ui.history
|
||||||
|
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.animation.core.animateFloatAsState
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.outlined.Delete
|
||||||
import androidx.compose.material.icons.outlined.DeleteForever
|
import androidx.compose.material.icons.outlined.DeleteForever
|
||||||
import androidx.compose.material.icons.outlined.MoreVert
|
import androidx.compose.material.icons.outlined.RestartAlt
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.Badge
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.DismissDirection
|
||||||
|
import androidx.compose.material3.DismissValue
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.SnackbarDuration
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
|
import androidx.compose.material3.SnackbarResult
|
||||||
|
import androidx.compose.material3.SwipeToDismiss
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.material3.rememberDismissState
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
import androidx.compose.ui.Alignment.Companion.CenterVertically
|
||||||
|
import androidx.compose.ui.Alignment.Companion.TopEnd
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.scale
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import me.zobrist.tichucounter.R
|
import me.zobrist.tichucounter.R
|
||||||
import me.zobrist.tichucounter.data.GameWithScores
|
import me.zobrist.tichucounter.data.GameWithScores
|
||||||
import me.zobrist.tichucounter.data.entity.Game
|
import me.zobrist.tichucounter.data.entity.Game
|
||||||
import me.zobrist.tichucounter.data.entity.Round
|
import me.zobrist.tichucounter.data.entity.Round
|
||||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
|
||||||
import java.text.DateFormat
|
import java.text.DateFormat
|
||||||
import java.util.*
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun HistoryList(
|
fun HistoryList(
|
||||||
viewModel: HistoryViewModel,
|
viewModel: HistoryViewModel,
|
||||||
navigateToCalculator: () -> Unit
|
snackbarHostState: SnackbarHostState,
|
||||||
|
navigateToCalculator: () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val lazyListState = rememberLazyListState()
|
||||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
|
|
||||||
DeleteConfirmDialog(showDeleteDialog) {
|
DeleteConfirmDialog(showDeleteDialog) {
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
if (it) {
|
if (it) {
|
||||||
@@ -41,14 +82,48 @@ fun HistoryList(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val deletedMessage = stringResource(id = R.string.delete_success)
|
||||||
|
val deletedActionLabel = stringResource(id = R.string.undo_question)
|
||||||
|
|
||||||
|
val activatedMessage = stringResource(id = R.string.activated_success)
|
||||||
|
val activatedActionLabel = stringResource(id = R.string.to_calculator_question)
|
||||||
|
|
||||||
HistoryList(
|
HistoryList(
|
||||||
viewModel.gameAndHistory,
|
games = viewModel.gameAndHistory,
|
||||||
{
|
onOpenClicked = {
|
||||||
viewModel.activateGame(it)
|
scope.launch {
|
||||||
navigateToCalculator()
|
viewModel.activateGame(it)
|
||||||
|
lazyListState.animateScrollToItem(0)
|
||||||
|
|
||||||
|
val result = snackbarHostState.showSnackbar(
|
||||||
|
message = activatedMessage,
|
||||||
|
actionLabel = activatedActionLabel,
|
||||||
|
duration = SnackbarDuration.Short
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result == SnackbarResult.ActionPerformed) {
|
||||||
|
navigateToCalculator()
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{ viewModel.deleteGame(it) },
|
onDeleteClicked = {
|
||||||
{ showDeleteDialog = true },
|
scope.launch {
|
||||||
|
viewModel.markToDelete(it)
|
||||||
|
val result = snackbarHostState.showSnackbar(
|
||||||
|
message = deletedMessage,
|
||||||
|
actionLabel = deletedActionLabel,
|
||||||
|
duration = SnackbarDuration.Short
|
||||||
|
)
|
||||||
|
|
||||||
|
if (result == SnackbarResult.Dismissed) {
|
||||||
|
viewModel.deleteGame(it)
|
||||||
|
} else {
|
||||||
|
viewModel.unmarkToDelete(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onDeleteAllClicked = { showDeleteDialog = true },
|
||||||
|
lazyListState = lazyListState
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,14 +135,12 @@ fun DeleteConfirmDialog(show: Boolean = true, onExecuted: (Boolean) -> Unit = {}
|
|||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { onExecuted(false) },
|
onDismissRequest = { onExecuted(false) },
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton({ onExecuted(false) })
|
TextButton({ onExecuted(false) }) {
|
||||||
{
|
|
||||||
Text(stringResource(R.string.cancel))
|
Text(stringResource(R.string.cancel))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
TextButton({ onExecuted(true) })
|
TextButton({ onExecuted(true) }) {
|
||||||
{
|
|
||||||
Text(stringResource(R.string.ok))
|
Text(stringResource(R.string.ok))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -77,133 +150,193 @@ fun DeleteConfirmDialog(show: Boolean = true, onExecuted: (Boolean) -> Unit = {}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HistoryList(
|
fun HistoryList(
|
||||||
games: List<GameWithScores>,
|
games: List<GameWithScores>,
|
||||||
onOpenClicked: (GameId: Long) -> Unit,
|
onOpenClicked: (gameId: Long) -> Unit,
|
||||||
onDeleteClicked: (GameId: Long) -> Unit,
|
onDeleteClicked: (gameId: Long) -> Unit,
|
||||||
onDeleteAllClicked: () -> Unit
|
onDeleteAllClicked: () -> Unit,
|
||||||
|
lazyListState: LazyListState = LazyListState(),
|
||||||
) {
|
) {
|
||||||
Row {
|
Row {
|
||||||
LazyColumn {
|
LazyColumn(state = lazyListState) {
|
||||||
item {
|
items(
|
||||||
Text(
|
items = games,
|
||||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp),
|
key = { it.hashCode() }) {
|
||||||
text = stringResource(R.string.active),
|
if (it.game.active) {
|
||||||
style = MaterialTheme.typography.headlineSmall
|
HistoryListItem(
|
||||||
)
|
it,
|
||||||
}
|
Modifier
|
||||||
items(games.filter { it.game.active }) {
|
.animateItemPlacement()
|
||||||
HistoryListItem(it, onOpenClicked, onDeleteClicked)
|
.padding(2.dp)
|
||||||
}
|
)
|
||||||
|
} else {
|
||||||
if (games.count() > 1) {
|
DismissibleHistoryListItem(
|
||||||
item {
|
it,
|
||||||
Text(
|
Modifier.animateItemPlacement(),
|
||||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp, top = 10.dp),
|
onOpenClicked,
|
||||||
text = stringResource(R.string.inactive),
|
onDeleteClicked
|
||||||
style = MaterialTheme.typography.headlineSmall
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
items(games.filter { !it.game.active }) {
|
item {
|
||||||
HistoryListItem(it, onOpenClicked, onDeleteClicked)
|
Button(enabled = games.count() > 1,
|
||||||
}
|
modifier = Modifier
|
||||||
|
.padding(start = 4.dp, end = 4.dp, top = 10.dp)
|
||||||
item {
|
.align(CenterVertically)
|
||||||
Button(
|
.fillMaxWidth()
|
||||||
enabled = games.count() > 1,
|
.animateItemPlacement(),
|
||||||
modifier = Modifier
|
onClick = { onDeleteAllClicked() }) {
|
||||||
.padding(start = 4.dp, end = 4.dp, top = 10.dp)
|
Icon(imageVector = Icons.Outlined.DeleteForever, contentDescription = null)
|
||||||
.align(CenterVertically)
|
Text(text = stringResource(id = R.string.deleteAll))
|
||||||
.fillMaxWidth(),
|
|
||||||
onClick = { onDeleteAllClicked() }) {
|
|
||||||
Icon(imageVector = Icons.Outlined.DeleteForever, contentDescription = null)
|
|
||||||
Text(text = stringResource(id = R.string.deleteAll))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun DismissibleHistoryListItem(
|
||||||
|
game: GameWithScores,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
onOpenClicked: (gameId: Long) -> Unit,
|
||||||
|
onDeleteClicked: (gameId: Long) -> Unit,
|
||||||
|
) {
|
||||||
|
|
||||||
|
val density = LocalDensity.current
|
||||||
|
val dismissState =
|
||||||
|
rememberDismissState(positionalThreshold = { with(density) { 100.dp.toPx() } },
|
||||||
|
confirmValueChange = {
|
||||||
|
if (it == DismissValue.DismissedToStart) {
|
||||||
|
onDeleteClicked(game.game.uid)
|
||||||
|
}
|
||||||
|
if (it == DismissValue.DismissedToEnd) {
|
||||||
|
onOpenClicked(game.game.uid)
|
||||||
|
}
|
||||||
|
true
|
||||||
|
})
|
||||||
|
|
||||||
|
val directions = if (game.game.active) {
|
||||||
|
setOf()
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setOf(DismissDirection.EndToStart, DismissDirection.StartToEnd)
|
||||||
|
}
|
||||||
|
|
||||||
|
SwipeToDismiss(
|
||||||
|
modifier = modifier,
|
||||||
|
state = dismissState,
|
||||||
|
directions = directions,
|
||||||
|
background = {
|
||||||
|
val direction = dismissState.dismissDirection ?: return@SwipeToDismiss
|
||||||
|
val color by animateColorAsState(
|
||||||
|
when (dismissState.targetValue) {
|
||||||
|
DismissValue.DismissedToStart -> MaterialTheme.colorScheme.error
|
||||||
|
DismissValue.DismissedToEnd -> MaterialTheme.colorScheme.primary
|
||||||
|
else -> MaterialTheme.colorScheme.background
|
||||||
|
|
||||||
|
}, label = ""
|
||||||
|
)
|
||||||
|
val textColor by animateColorAsState(
|
||||||
|
when (dismissState.targetValue) {
|
||||||
|
DismissValue.DismissedToStart -> MaterialTheme.colorScheme.onError
|
||||||
|
DismissValue.DismissedToEnd -> MaterialTheme.colorScheme.onPrimary
|
||||||
|
else -> MaterialTheme.colorScheme.onBackground
|
||||||
|
|
||||||
|
}, label = ""
|
||||||
|
)
|
||||||
|
val alignment = when (direction) {
|
||||||
|
DismissDirection.StartToEnd -> Alignment.CenterStart
|
||||||
|
DismissDirection.EndToStart -> Alignment.CenterEnd
|
||||||
|
}
|
||||||
|
val icon = when (direction) {
|
||||||
|
DismissDirection.StartToEnd -> Icons.Outlined.RestartAlt
|
||||||
|
DismissDirection.EndToStart -> Icons.Outlined.Delete
|
||||||
|
}
|
||||||
|
val text = when (direction) {
|
||||||
|
DismissDirection.StartToEnd -> stringResource(id = R.string.continue_play)
|
||||||
|
DismissDirection.EndToStart -> stringResource(id = R.string.delete)
|
||||||
|
}
|
||||||
|
val scale by animateFloatAsState(
|
||||||
|
if (dismissState.targetValue == DismissValue.Default) 0.75f else 1f, label = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(top = 2.dp, bottom = 2.dp)
|
||||||
|
.background(color)
|
||||||
|
.padding(horizontal = 10.dp),
|
||||||
|
contentAlignment = alignment
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
icon,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.scale(scale),
|
||||||
|
tint = textColor
|
||||||
|
)
|
||||||
|
Text(text = text, color = textColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, dismissContent = {
|
||||||
|
HistoryListItem(game = game, modifier = Modifier.padding(2.dp))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun HistoryListItem(
|
fun HistoryListItem(
|
||||||
game: GameWithScores,
|
game: GameWithScores, modifier: Modifier = Modifier
|
||||||
onOpenClicked: (GameId: Long) -> Unit,
|
|
||||||
onDeleteClicked: (GameId: Long) -> Unit
|
|
||||||
) {
|
) {
|
||||||
val format =
|
val format =
|
||||||
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
||||||
|
|
||||||
|
|
||||||
val cardColor = if (game.game.active) {
|
|
||||||
CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.secondaryContainer)
|
|
||||||
|
|
||||||
} else {
|
|
||||||
CardDefaults.cardColors()
|
|
||||||
}
|
|
||||||
|
|
||||||
val totalScores = game.getTotalPoints()
|
val totalScores = game.getTotalPoints()
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(all = 4.dp)
|
|
||||||
.clickable { onOpenClicked(game.game.uid) },
|
|
||||||
colors = cardColor
|
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
Modifier
|
Modifier.padding(all = 12.dp)
|
||||||
.padding(all = 12.dp)
|
|
||||||
) {
|
) {
|
||||||
Column(Modifier.weight(4f)) {
|
Box(modifier = modifier.fillMaxSize()) {
|
||||||
Text(
|
Column {
|
||||||
text = game.game.nameA + " vs " + game.game.nameB,
|
Text(
|
||||||
maxLines = 1,
|
text = game.game.nameA + " vs " + game.game.nameB,
|
||||||
overflow = TextOverflow.Ellipsis,
|
maxLines = 1,
|
||||||
style = MaterialTheme.typography.headlineSmall
|
overflow = TextOverflow.Ellipsis,
|
||||||
)
|
style = MaterialTheme.typography.headlineSmall
|
||||||
Text(
|
|
||||||
text = totalScores.first.toString() + " : " + totalScores.second.toString(),
|
|
||||||
style = MaterialTheme.typography.bodyLarge
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.padding(5.dp))
|
|
||||||
Text(
|
|
||||||
text = format.format(game.game.modified),
|
|
||||||
style = MaterialTheme.typography.labelSmall
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Column(
|
|
||||||
Modifier
|
|
||||||
.wrapContentSize()
|
|
||||||
.width(40.dp)
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (!game.game.active) {
|
|
||||||
var expanded by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = 20.dp, bottom = 20.dp)
|
|
||||||
.clickable { expanded = true },
|
|
||||||
imageVector = Icons.Outlined.MoreVert,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
)
|
||||||
|
Text(
|
||||||
|
text = totalScores.first.toString() + " : " + totalScores.second.toString(),
|
||||||
DropDownMenu(
|
style = MaterialTheme.typography.bodyLarge
|
||||||
mapOf("delete" to R.string.delete),
|
)
|
||||||
"",
|
Spacer(modifier = Modifier.padding(5.dp))
|
||||||
expanded,
|
Text(
|
||||||
|
text = format.format(game.game.modified),
|
||||||
|
style = MaterialTheme.typography.labelSmall
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (game.game.active) {
|
||||||
|
Badge(
|
||||||
|
modifier = Modifier.align(TopEnd),
|
||||||
|
contentColor = MaterialTheme.colorScheme.onPrimary,
|
||||||
|
containerColor = MaterialTheme.colorScheme.primary
|
||||||
) {
|
) {
|
||||||
expanded = false
|
Text(
|
||||||
it?.let {
|
text = stringResource(id = R.string.active),
|
||||||
when (it) {
|
style = MaterialTheme.typography.labelSmall
|
||||||
"delete" -> onDeleteClicked(game.game.uid)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -216,25 +349,17 @@ fun HistoryListItem(
|
|||||||
private fun HistoryListPreview() {
|
private fun HistoryListPreview() {
|
||||||
val tempData = listOf(
|
val tempData = listOf(
|
||||||
GameWithScores(
|
GameWithScores(
|
||||||
Game(true, "abc", "def", Date(), Date()),
|
Game(true, "abcsdf sdaf asdf sdf ", "defsadf asdf sadf ", Date(), Date()),
|
||||||
listOf(Round(1, 550, 500))
|
listOf(Round(1, 550, 500))
|
||||||
),
|
), GameWithScores(
|
||||||
GameWithScores(
|
Game(false, "ADTH", "dogfg", Date(), Date()), listOf(Round(2, 20, 60))
|
||||||
Game(false, "ADTH", "dogfg", Date(), Date()),
|
), GameWithScores(
|
||||||
listOf(Round(2, 20, 60))
|
Game(false, "TeamA3 langer Name", "TeamB3", Date(), Date()), listOf(Round(3, 30, 70))
|
||||||
),
|
), GameWithScores(
|
||||||
GameWithScores(
|
Game(false, "TeamA4", "TeamB4", Date(), Date()), listOf(Round(4, 40, 80))
|
||||||
Game(false, "TeamA3 langer Name", "TeamB3", Date(), Date()),
|
), GameWithScores(
|
||||||
listOf(Round(3, 30, 70))
|
Game(false, "TeamA5", "TeamB5", Date(), Date()), listOf(Round(5, 50, 90))
|
||||||
),
|
|
||||||
GameWithScores(
|
|
||||||
Game(false, "TeamA4", "TeamB4", Date(), Date()),
|
|
||||||
listOf(Round(4, 40, 80))
|
|
||||||
),
|
|
||||||
GameWithScores(
|
|
||||||
Game(false, "TeamA5", "TeamB5", Date(), Date()),
|
|
||||||
listOf(Round(5, 50, 90))
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
HistoryList(tempData, {}, {}) {}
|
HistoryList(tempData, {}, {}, {})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,16 +20,27 @@ class HistoryViewModel @Inject constructor(
|
|||||||
var gameAndHistory by mutableStateOf(emptyList<GameWithScores>())
|
var gameAndHistory by mutableStateOf(emptyList<GameWithScores>())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
private var fullList: List<GameWithScores> = emptyList()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|
||||||
gameRepository.getAllWithRoundFlow().collect { games ->
|
gameRepository.getAllWithRoundFlow().collect { games ->
|
||||||
gameAndHistory =
|
fullList =
|
||||||
games.sortedBy { it.game.modified }.sortedBy { it.game.active }.reversed()
|
games.sortedBy { it.game.modified }.sortedBy { it.game.active }.reversed()
|
||||||
|
gameAndHistory = fullList
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun markToDelete(gameId: Long) {
|
||||||
|
gameAndHistory = fullList.filter { it.game.uid != gameId }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun unmarkToDelete(gameId: Long) {
|
||||||
|
gameAndHistory = fullList
|
||||||
|
}
|
||||||
|
|
||||||
fun deleteGame(gameId: Long) {
|
fun deleteGame(gameId: Long) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
gameRepository.deleteGame(gameId)
|
gameRepository.deleteGame(gameId)
|
||||||
|
|||||||
@@ -1,22 +1,29 @@
|
|||||||
package me.zobrist.tichucounter.ui.layout
|
package me.zobrist.tichucounter.ui.layout
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.outlined.Calculate
|
||||||
import androidx.compose.material.icons.outlined.*
|
import androidx.compose.material.icons.outlined.List
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material.icons.outlined.Settings
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.Divider
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.ModalDrawerSheet
|
||||||
|
import androidx.compose.material3.NavigationDrawerItem
|
||||||
|
import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import me.zobrist.tichucounter.R
|
import me.zobrist.tichucounter.R
|
||||||
import me.zobrist.tichucounter.domain.*
|
import me.zobrist.tichucounter.domain.DrawerItem
|
||||||
|
import me.zobrist.tichucounter.domain.Route
|
||||||
import me.zobrist.tichucounter.ui.AppTheme
|
import me.zobrist.tichucounter.ui.AppTheme
|
||||||
import me.zobrist.tichucounter.ui.counter.*
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DrawerContent(
|
fun DrawerContent(
|
||||||
drawerItems: List<DrawerItem>,
|
drawerItems: List<DrawerItem>,
|
||||||
|
|||||||
@@ -8,8 +8,16 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.material3.Switch
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment.Companion.End
|
import androidx.compose.ui.Alignment.Companion.End
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -36,6 +44,7 @@ val themeMap = mapOf(
|
|||||||
Theme.LIGHT to R.string.light
|
Theme.LIGHT to R.string.light
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val victoryPointsList = listOf(500, 1000, 1500, 2000)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SettingsView(viewModel: SettingsViewModel) {
|
fun SettingsView(viewModel: SettingsViewModel) {
|
||||||
@@ -43,9 +52,11 @@ fun SettingsView(viewModel: SettingsViewModel) {
|
|||||||
viewModel.screenOn.value,
|
viewModel.screenOn.value,
|
||||||
viewModel.language,
|
viewModel.language,
|
||||||
viewModel.theme,
|
viewModel.theme,
|
||||||
|
viewModel.victoryPoints,
|
||||||
{ viewModel.updateScreenOn(it) },
|
{ viewModel.updateScreenOn(it) },
|
||||||
{ viewModel.updateLanguage(it) },
|
{ viewModel.updateLanguage(it) },
|
||||||
{ viewModel.updateTheme(it) })
|
{ viewModel.updateTheme(it) },
|
||||||
|
{ viewModel.updateVictoryPoints(it) })
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -53,11 +64,22 @@ fun SettingsView(
|
|||||||
valueScreenOn: Boolean = true,
|
valueScreenOn: Boolean = true,
|
||||||
valueLanguage: Language = Language.ENGLISH,
|
valueLanguage: Language = Language.ENGLISH,
|
||||||
valueTheme: Theme = Theme.DARK,
|
valueTheme: Theme = Theme.DARK,
|
||||||
|
valueVictoryPoints: Int = 1000,
|
||||||
updateScreenOn: (KeepScreenOn) -> Unit = {},
|
updateScreenOn: (KeepScreenOn) -> Unit = {},
|
||||||
updateLanguage: (Language) -> Unit = {},
|
updateLanguage: (Language) -> Unit = {},
|
||||||
updateTheme: (Theme) -> Unit = {}
|
updateTheme: (Theme) -> Unit = {},
|
||||||
|
updateVictoryPoints: (Int) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
Column {
|
Column(
|
||||||
|
Modifier
|
||||||
|
.padding(20.dp)
|
||||||
|
) {
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.display),
|
||||||
|
style = MaterialTheme.typography.headlineMedium
|
||||||
|
)
|
||||||
|
|
||||||
BooleanSetting(
|
BooleanSetting(
|
||||||
stringResource(R.string.keep_screen_on),
|
stringResource(R.string.keep_screen_on),
|
||||||
valueScreenOn
|
valueScreenOn
|
||||||
@@ -74,6 +96,18 @@ fun SettingsView(
|
|||||||
themeMap,
|
themeMap,
|
||||||
valueTheme,
|
valueTheme,
|
||||||
) { updateTheme(it) }
|
) { updateTheme(it) }
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.game),
|
||||||
|
style = MaterialTheme.typography.headlineMedium
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
ListSetting(
|
||||||
|
stringResource(R.string.victory_points),
|
||||||
|
victoryPointsList,
|
||||||
|
valueVictoryPoints
|
||||||
|
) { updateVictoryPoints(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +116,7 @@ fun BooleanSetting(name: String, value: Boolean, updateValue: (Boolean) -> Unit)
|
|||||||
|
|
||||||
Row(
|
Row(
|
||||||
Modifier
|
Modifier
|
||||||
.padding(20.dp)
|
.padding(bottom = 15.dp, top = 5.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Column(Modifier.weight(5f)) {
|
Column(Modifier.weight(5f)) {
|
||||||
@@ -111,21 +145,32 @@ fun BooleanSetting(name: String, value: Boolean, updateValue: (Boolean) -> Unit)
|
|||||||
@Composable
|
@Composable
|
||||||
fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (T) -> Unit) {
|
fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (T) -> Unit) {
|
||||||
|
|
||||||
|
val translated = map.map { it.key to stringResource(it.value) }.toMap()
|
||||||
|
val getValue = map.map { stringResource(it.value) to it.key }.toMap()
|
||||||
|
|
||||||
|
ListSetting(
|
||||||
|
name,
|
||||||
|
translated.values,
|
||||||
|
translated[selected]
|
||||||
|
) { getValue[it]?.let { it1 -> onSelected(it1) } }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun <T> ListSetting(name: String, list: Collection<T>, selected: T, onSelected: (T) -> Unit) {
|
||||||
|
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
Modifier
|
Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(20.dp)
|
.padding(bottom = 15.dp, top = 5.dp)
|
||||||
.clickable { expanded = true }) {
|
.clickable { expanded = true }) {
|
||||||
Column(Modifier.weight(5f)) {
|
Column(Modifier.weight(5f)) {
|
||||||
Text(name, style = MaterialTheme.typography.bodyLarge, overflow = TextOverflow.Ellipsis)
|
Text(name, style = MaterialTheme.typography.bodyLarge, overflow = TextOverflow.Ellipsis)
|
||||||
map[selected]?.let {
|
Text(
|
||||||
Text(
|
selected.toString(),
|
||||||
stringResource(it),
|
style = MaterialTheme.typography.labelLarge
|
||||||
style = MaterialTheme.typography.labelLarge
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(Modifier.weight(1f)) {
|
Column(Modifier.weight(1f)) {
|
||||||
@@ -134,15 +179,15 @@ fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (
|
|||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.align(End)
|
modifier = Modifier.align(End)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
|
|
||||||
DropDownMenu(
|
DropDownMenu(
|
||||||
map,
|
list,
|
||||||
selected,
|
selected,
|
||||||
expanded,
|
expanded,
|
||||||
) {
|
) {
|
||||||
expanded = false
|
expanded = false
|
||||||
it?.let { onSelected(it) }
|
it?.let { onSelected(it) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,20 +204,3 @@ fun SettingsViewPreview() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(name = "Light Mode")
|
|
||||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
|
||||||
@Composable
|
|
||||||
fun StringSettingPreview() {
|
|
||||||
|
|
||||||
AppTheme {
|
|
||||||
Surface {
|
|
||||||
DropDownMenu(
|
|
||||||
themeMap,
|
|
||||||
Theme.LIGHT,
|
|
||||||
true,
|
|
||||||
) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package me.zobrist.tichucounter.ui.settings
|
package me.zobrist.tichucounter.ui.settings
|
||||||
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
@@ -15,28 +16,35 @@ import javax.inject.Inject
|
|||||||
class SettingsViewModel @Inject constructor(private val settings: SettingsAdapter) : ViewModel() {
|
class SettingsViewModel @Inject constructor(private val settings: SettingsAdapter) : ViewModel() {
|
||||||
|
|
||||||
|
|
||||||
var language by mutableStateOf(settings.language)
|
var language by mutableStateOf(settings.language.value)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var theme by mutableStateOf(settings.theme)
|
var theme by mutableStateOf(settings.theme.value)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var screenOn by mutableStateOf(settings.keepScreenOn)
|
var screenOn by mutableStateOf(settings.keepScreenOn.value)
|
||||||
|
private set
|
||||||
|
|
||||||
|
var victoryPoints by mutableIntStateOf(settings.victoryPoints.value)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
fun updateLanguage(language: Language) {
|
fun updateLanguage(language: Language) {
|
||||||
settings.setLanguage(language)
|
settings.language.value = language
|
||||||
this.language = settings.language
|
this.language = language
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateTheme(theme: Theme) {
|
fun updateTheme(theme: Theme) {
|
||||||
settings.setTheme(theme)
|
settings.theme.value = theme
|
||||||
this.theme = settings.theme
|
this.theme = theme
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateScreenOn(value: KeepScreenOn) {
|
fun updateScreenOn(value: KeepScreenOn) {
|
||||||
settings.setKeepScreenOn(value)
|
settings.keepScreenOn.value = value
|
||||||
screenOn = settings.keepScreenOn
|
screenOn = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun updateVictoryPoints(value: Int) {
|
||||||
|
settings.victoryPoints.value = value
|
||||||
|
victoryPoints = value
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -3,51 +3,52 @@
|
|||||||
android:height="108dp"
|
android:height="108dp"
|
||||||
android:viewportWidth="50.684"
|
android:viewportWidth="50.684"
|
||||||
android:viewportHeight="39.77">
|
android:viewportHeight="39.77">
|
||||||
<group android:scaleX="0.46444446"
|
<group
|
||||||
android:scaleY="0.36443365"
|
android:scaleX="0.46444446"
|
||||||
android:translateX="13.572049"
|
android:scaleY="0.36443365"
|
||||||
android:translateY="12.638237">
|
android:translateX="13.572049"
|
||||||
<path
|
android:translateY="12.638237">
|
||||||
android:pathData="m25.885,0.371 l-25.752,0.047 0.094,9.167 8.174,0.094 -0.094,29.957 9.592,-0.094 -0.047,-29.957h8.08z"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#ffff00"
|
||||||
android:strokeWidth="0.26458300000000001"
|
android:pathData="m25.885,0.371 l-25.752,0.047 0.094,9.167 8.174,0.094 -0.094,29.957 9.592,-0.094 -0.047,-29.957h8.08z"
|
||||||
android:fillColor="#ffff00"
|
android:strokeWidth="0.26458300000000001"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
<path
|
android:strokeLineJoin="miter" />
|
||||||
android:pathData="m50.503,39.494 l-0.047,-9.214h-10.773c-0.738,-0.009 -2.147,-0.64 -2.139,-1.95 0.009,-1.415 0.012,-16.903 0.012,-16.903 -0.001,-1.41 1.227,-2.055 1.89,-2.079l11.009,-0.142 0.094,-9.072 -11.86,0.189c-2.609,0.059 -10.536,2.804 -10.537,13.23 -0,10.079 0.218,15.921 0.218,15.921 0.223,4.386 5.741,9.979 10.125,9.99l12.006,0.03z"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#ffff00"
|
||||||
android:strokeWidth="0.26458300000000001"
|
android:pathData="m50.503,39.494 l-0.047,-9.214h-10.773c-0.738,-0.009 -2.147,-0.64 -2.139,-1.95 0.009,-1.415 0.012,-16.903 0.012,-16.903 -0.001,-1.41 1.227,-2.055 1.89,-2.079l11.009,-0.142 0.094,-9.072 -11.86,0.189c-2.609,0.059 -10.536,2.804 -10.537,13.23 -0,10.079 0.218,15.921 0.218,15.921 0.223,4.386 5.741,9.979 10.125,9.99l12.006,0.03z"
|
||||||
android:fillColor="#ffff00"
|
android:strokeWidth="0.26458300000000001"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
<path
|
android:strokeLineJoin="miter" />
|
||||||
android:pathData="m8.403,10.083c0.049,-0.713 -0.112,-0.88 -0.029,-2.095 0.366,-1.278 9.609,-5.62 16.985,-2.65 0.403,0.162 0.5,-0.375 0.299,-0.467 -2.964,-2.692 -13.318,-8.128 -25.314,0.286l8.059,4.521"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#000000"
|
||||||
android:strokeWidth="0.264583"
|
android:pathData="m8.403,10.083c0.049,-0.713 -0.112,-0.88 -0.029,-2.095 0.366,-1.278 9.609,-5.62 16.985,-2.65 0.403,0.162 0.5,-0.375 0.299,-0.467 -2.964,-2.692 -13.318,-8.128 -25.314,0.286l8.059,4.521"
|
||||||
android:fillColor="#000000"
|
android:strokeWidth="0.264583"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
<path
|
android:strokeLineJoin="miter" />
|
||||||
android:pathData="m13.09,39.45 l-4.651,-7.072 1.436,-0.155c1.716,-3.55 8.698,-15.304 2.46,-24.75 -0.307,-0.496 0.802,-2.297 1.512,-0.563 5.772,10.547 5.161,23.028 -0.757,32.54z"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#000000"
|
||||||
android:strokeWidth="0.264583"
|
android:pathData="m13.09,39.45 l-4.651,-7.072 1.436,-0.155c1.716,-3.55 8.698,-15.304 2.46,-24.75 -0.307,-0.496 0.802,-2.297 1.512,-0.563 5.772,10.547 5.161,23.028 -0.757,32.54z"
|
||||||
android:fillColor="#000000"
|
android:strokeWidth="0.264583"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
<path
|
android:strokeLineJoin="miter" />
|
||||||
android:pathData="m42.812,9.194 l7.51,-4.144c-4.938,-5.973 -14.39,-7.27 -20.302,4.385 -0.2,0.447 0.901,0.888 1.106,0.649 5.387,-7.535 11.325,-3.968 11.686,-2.476 0.158,0.461 0.006,1.054 0.001,1.585z"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#000000"
|
||||||
android:strokeWidth="0.264583"
|
android:pathData="m42.812,9.194 l7.51,-4.144c-4.938,-5.973 -14.39,-7.27 -20.302,4.385 -0.2,0.447 0.901,0.888 1.106,0.649 5.387,-7.535 11.325,-3.968 11.686,-2.476 0.158,0.461 0.006,1.054 0.001,1.585z"
|
||||||
android:fillColor="#000000"
|
android:strokeWidth="0.264583"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
<path
|
android:strokeLineJoin="miter" />
|
||||||
android:pathData="m42.429,30.41 l7.935,4.743c-13.982,13.838 -26.059,-8.724 -21.01,-24.194 0.143,-0.438 1.306,-0.12 1.201,0.408 -1.411,6.97 1.621,22.234 11.726,20.975z"
|
<path
|
||||||
android:strokeLineJoin="miter"
|
android:fillColor="#000000"
|
||||||
android:strokeWidth="0.264583"
|
android:pathData="m42.429,30.41 l7.935,4.743c-13.982,13.838 -26.059,-8.724 -21.01,-24.194 0.143,-0.438 1.306,-0.12 1.201,0.408 -1.411,6.97 1.621,22.234 11.726,20.975z"
|
||||||
android:fillColor="#000000"
|
android:strokeWidth="0.264583"
|
||||||
android:strokeColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineCap="butt"
|
||||||
</group>
|
android:strokeLineJoin="miter" />
|
||||||
|
</group>
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -3,46 +3,46 @@
|
|||||||
android:height="39.77dp"
|
android:height="39.77dp"
|
||||||
android:viewportWidth="50.684"
|
android:viewportWidth="50.684"
|
||||||
android:viewportHeight="39.77">
|
android:viewportHeight="39.77">
|
||||||
<path
|
<path
|
||||||
android:pathData="m25.885,0.371 l-25.752,0.047 0.094,9.167 8.174,0.094 -0.094,29.957 9.592,-0.094 -0.047,-29.957h8.08z"
|
android:fillColor="#ffff00"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m25.885,0.371 l-25.752,0.047 0.094,9.167 8.174,0.094 -0.094,29.957 9.592,-0.094 -0.047,-29.957h8.08z"
|
||||||
android:strokeWidth="0.26458300000000001"
|
android:strokeWidth="0.26458300000000001"
|
||||||
android:fillColor="#ffff00"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
<path
|
<path
|
||||||
android:pathData="m50.503,39.494 l-0.047,-9.214h-10.773c-0.738,-0.009 -2.147,-0.64 -2.139,-1.95 0.009,-1.415 0.012,-16.903 0.012,-16.903 -0.001,-1.41 1.227,-2.055 1.89,-2.079l11.009,-0.142 0.094,-9.072 -11.86,0.189c-2.609,0.059 -10.536,2.804 -10.537,13.23 -0,10.079 0.218,15.921 0.218,15.921 0.223,4.386 5.741,9.979 10.125,9.99l12.006,0.03z"
|
android:fillColor="#ffff00"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m50.503,39.494 l-0.047,-9.214h-10.773c-0.738,-0.009 -2.147,-0.64 -2.139,-1.95 0.009,-1.415 0.012,-16.903 0.012,-16.903 -0.001,-1.41 1.227,-2.055 1.89,-2.079l11.009,-0.142 0.094,-9.072 -11.86,0.189c-2.609,0.059 -10.536,2.804 -10.537,13.23 -0,10.079 0.218,15.921 0.218,15.921 0.223,4.386 5.741,9.979 10.125,9.99l12.006,0.03z"
|
||||||
android:strokeWidth="0.26458300000000001"
|
android:strokeWidth="0.26458300000000001"
|
||||||
android:fillColor="#ffff00"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
<path
|
<path
|
||||||
android:pathData="m8.403,10.083c0.049,-0.713 -0.112,-0.88 -0.029,-2.095 0.366,-1.278 9.609,-5.62 16.985,-2.65 0.403,0.162 0.5,-0.375 0.299,-0.467 -2.964,-2.692 -13.318,-8.128 -25.314,0.286l8.059,4.521"
|
android:fillColor="#000000"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m8.403,10.083c0.049,-0.713 -0.112,-0.88 -0.029,-2.095 0.366,-1.278 9.609,-5.62 16.985,-2.65 0.403,0.162 0.5,-0.375 0.299,-0.467 -2.964,-2.692 -13.318,-8.128 -25.314,0.286l8.059,4.521"
|
||||||
android:strokeWidth="0.264583"
|
android:strokeWidth="0.264583"
|
||||||
android:fillColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
<path
|
<path
|
||||||
android:pathData="m13.09,39.45 l-4.651,-7.072 1.436,-0.155c1.716,-3.55 8.698,-15.304 2.46,-24.75 -0.307,-0.496 0.802,-2.297 1.512,-0.563 5.772,10.547 5.161,23.028 -0.757,32.54z"
|
android:fillColor="#000000"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m13.09,39.45 l-4.651,-7.072 1.436,-0.155c1.716,-3.55 8.698,-15.304 2.46,-24.75 -0.307,-0.496 0.802,-2.297 1.512,-0.563 5.772,10.547 5.161,23.028 -0.757,32.54z"
|
||||||
android:strokeWidth="0.264583"
|
android:strokeWidth="0.264583"
|
||||||
android:fillColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
<path
|
<path
|
||||||
android:pathData="m42.812,9.194 l7.51,-4.144c-4.938,-5.973 -14.39,-7.27 -20.302,4.385 -0.2,0.447 0.901,0.888 1.106,0.649 5.387,-7.535 11.325,-3.968 11.686,-2.476 0.158,0.461 0.006,1.054 0.001,1.585z"
|
android:fillColor="#000000"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m42.812,9.194 l7.51,-4.144c-4.938,-5.973 -14.39,-7.27 -20.302,4.385 -0.2,0.447 0.901,0.888 1.106,0.649 5.387,-7.535 11.325,-3.968 11.686,-2.476 0.158,0.461 0.006,1.054 0.001,1.585z"
|
||||||
android:strokeWidth="0.264583"
|
android:strokeWidth="0.264583"
|
||||||
android:fillColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
<path
|
<path
|
||||||
android:pathData="m42.429,30.41 l7.935,4.743c-13.982,13.838 -26.059,-8.724 -21.01,-24.194 0.143,-0.438 1.306,-0.12 1.201,0.408 -1.411,6.97 1.621,22.234 11.726,20.975z"
|
android:fillColor="#000000"
|
||||||
android:strokeLineJoin="miter"
|
android:pathData="m42.429,30.41 l7.935,4.743c-13.982,13.838 -26.059,-8.724 -21.01,-24.194 0.143,-0.438 1.306,-0.12 1.201,0.408 -1.411,6.97 1.621,22.234 11.726,20.975z"
|
||||||
android:strokeWidth="0.264583"
|
android:strokeWidth="0.264583"
|
||||||
android:fillColor="#000000"
|
android:strokeColor="#000000"
|
||||||
android:strokeColor="#000000"
|
android:strokeLineCap="butt"
|
||||||
android:strokeLineCap="butt"/>
|
android:strokeLineJoin="miter" />
|
||||||
</vector>
|
</vector>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background" />
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@color/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background" />
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<string name="menu_settings">Einstellungen</string>
|
<string name="menu_settings">Einstellungen</string>
|
||||||
<string name="on">Ein</string>
|
<string name="on">Ein</string>
|
||||||
<string name="off">Aus</string>
|
<string name="off">Aus</string>
|
||||||
<string name="newGame">Neues Spiel</string>
|
<string name="new_game">Neues Spiel</string>
|
||||||
<string name="delete_inactive_title">Verlauf löschen</string>
|
<string name="delete_inactive_title">Verlauf löschen</string>
|
||||||
<string name="delete_inactive_text">Wirklich den gesamten Verlauf löschen? Diese Aktion kann nicht rückgängig gemacht werden.</string>
|
<string name="delete_inactive_text">Wirklich den gesamten Verlauf löschen? Diese Aktion kann nicht rückgängig gemacht werden.</string>
|
||||||
<string name="cancel">Abbrechen</string>
|
<string name="cancel">Abbrechen</string>
|
||||||
@@ -24,5 +24,17 @@
|
|||||||
<string name="menu_counter">Counter</string>
|
<string name="menu_counter">Counter</string>
|
||||||
<string name="menu_about">About</string>
|
<string name="menu_about">About</string>
|
||||||
<string name="contact_us">Schreib uns</string>
|
<string name="contact_us">Schreib uns</string>
|
||||||
|
<string name="continue_play">Weiterspielen</string>
|
||||||
|
<string name="delete_success">Spiel gelöscht.</string>
|
||||||
|
<string name="undo_question">RÜCKGÄNGIG</string>
|
||||||
|
<string name="activated_success">Spiel aktiviert.</string>
|
||||||
|
<string name="to_calculator_question">WEITERSPIELEN</string>
|
||||||
|
<string name="display">Anzeige</string>
|
||||||
|
<string name="game">Spiel</string>
|
||||||
|
<string name="victory_points">Siegespunkte</string>
|
||||||
|
<string name="victory_title">%1$s hat gewonnen</string>
|
||||||
|
<string name="draw_message">Sieht aus, als ob ihr ein neues Spiel starten solltet, um das endgültig zu klären.</string>
|
||||||
|
<string name="draw_title">Unentschieden</string>
|
||||||
|
<string name="victory_message">Herzliche Gratulation! Wie wäre es mit einer Revanche?</string>
|
||||||
|
<string name="abort">Abbrechen</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -15,9 +15,9 @@
|
|||||||
<string name="menu_settings">Settings</string>
|
<string name="menu_settings">Settings</string>
|
||||||
<string name="on">On</string>
|
<string name="on">On</string>
|
||||||
<string name="off">Off</string>
|
<string name="off">Off</string>
|
||||||
<string name="newGame">New Game</string>
|
<string name="new_game">New Game</string>
|
||||||
<string name="delete_inactive_title">Delete history</string>
|
<string name="delete_inactive_title">Delete history</string>
|
||||||
<string name="delete_inactive_text">You really want to delete the the history? This action can\'t be undone.</string>
|
<string name="delete_inactive_text">You really want to delete the history? This action can\'t be undone.</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="ok">OK</string>
|
<string name="ok">OK</string>
|
||||||
<string name="delete">Delete</string>
|
<string name="delete">Delete</string>
|
||||||
@@ -28,4 +28,17 @@
|
|||||||
<string name="menu_about">About</string>
|
<string name="menu_about">About</string>
|
||||||
<string name="contact_us">Contact us</string>
|
<string name="contact_us">Contact us</string>
|
||||||
<string name="play_store" translatable="false">Play Store</string>
|
<string name="play_store" translatable="false">Play Store</string>
|
||||||
|
<string name="continue_play">Continue game</string>
|
||||||
|
<string name="delete_success">Game deleted.</string>
|
||||||
|
<string name="undo_question">UNDO</string>
|
||||||
|
<string name="activated_success">Game activated.</string>
|
||||||
|
<string name="to_calculator_question">CONTINUE PLAYING</string>
|
||||||
|
<string name="display">Display</string>
|
||||||
|
<string name="game">Game</string>
|
||||||
|
<string name="victory_points">Victory points</string>
|
||||||
|
<string name="victory_title">%1$s won the game</string>
|
||||||
|
<string name="draw_message">Looks like you should start a new game to settle this for good.</string>
|
||||||
|
<string name="draw_title">Draw</string>
|
||||||
|
<string name="victory_message">Congratulations! How about a rematch?</string>
|
||||||
|
<string name="abort">Abort</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package me.zobrist.tichucounter
|
package me.zobrist.tichucounter
|
||||||
|
|
||||||
import me.zobrist.tichucounter.domain.Tichu
|
import me.zobrist.tichucounter.domain.Tichu
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertFalse
|
||||||
|
import org.junit.Assert.assertTrue
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = "1.8.21"
|
ext.kotlin_version = "1.8.22"
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:8.0.1'
|
classpath 'com.android.tools.build:gradle:8.1.1'
|
||||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
@@ -26,6 +26,6 @@ allprojects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
tasks.register('clean', Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user