Compare commits
122 Commits
1.1.0Beta1
...
2.3.3
| Author | SHA1 | Date | |
|---|---|---|---|
| cf5c408464 | |||
| fdf8c5c7df | |||
| 7ed3a29c5b | |||
| 9434d1f1b9 | |||
| 9abff51cb8 | |||
| 93f51b9220 | |||
| 8bb2b9bf20 | |||
| 00569666be | |||
| 2cf6578378 | |||
| fbcf9af761 | |||
| 80039a5f94 | |||
| 1c6674373f | |||
| 67e803f913 | |||
| 4c01fe13a8 | |||
| 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 | |||
| 34e64e6e50 | |||
| 694989a917 | |||
| 1e8e72557d | |||
| 2e40d0315c | |||
| 9ddbdb698c | |||
| c40d473fa5 | |||
| 507944794f | |||
| 068e36c5f6 | |||
| 7e722feb27 | |||
| fb4c83d60a | |||
| 0c80e05f5c | |||
| 8ca82d1734 | |||
| 9385deeb24 | |||
| fadd206e9e | |||
| 6768391caf | |||
| aa3e68dc5c | |||
| a2b84640b1 | |||
| 895264de2a | |||
| 3ec8c27b96 | |||
| 343d1d8e75 | |||
| 801a17d759 | |||
| 8e26f6b337 | |||
| 9e658853eb | |||
| 5a229d6c57 | |||
| bcc3bd3848 | |||
| 17d861403e | |||
| a1f344580d | |||
| b3bdbfbc05 | |||
| a611de6da4 | |||
| 4108512139 | |||
| 30723f7862 | |||
| 661b88b961 | |||
| c41816898e | |||
| 2e8d6a7a4e | |||
| ae0f85bec0 | |||
| e1e25ff607 | |||
| 6aedb0d7f9 | |||
| 48374c5980 | |||
| 02213f41b6 | |||
| 9ae0890f71 | |||
| cd8f1959af | |||
| 58d4fc0e43 | |||
| c71b608a7b | |||
| 89f2e3ecd5 | |||
| f52bfa64ce | |||
| 4346af3d2b | |||
| ca88bd1054 | |||
| c54f63736e | |||
| 8d24e46687 | |||
| f40b66077b | |||
| 9ca830a707 | |||
| db58e475d1 | |||
| 33e57bcfd7 | |||
| c1567efe52 | |||
| 4d37e77f55 | |||
| 984afb610f | |||
| c3c6c253bc | |||
| 9189d79982 | |||
| ad0236556e | |||
| 52a73bf204 | |||
| 6d0192df18 | |||
| 63f213bc75 | |||
| 68a5d34e45 | |||
| 98ea66772f | |||
| 84a63a2bcb | |||
| c5de57c416 |
74
.drone.yml
@@ -1,74 +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: daffda8b-5840-4a65-b6d0-73b991facfb6
|
||||
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=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: daffda8b-5840-4a65-b6d0-73b991facfb6
|
||||
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
|
||||
44
.gitea/workflows/buildAndroid.yaml
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: app-release
|
||||
retention-days: 10
|
||||
path: app/build/outputs/**/release/app-release.*
|
||||
|
||||
- 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
|
||||
1
.gitignore
vendored
@@ -15,3 +15,4 @@
|
||||
.idea
|
||||
keystore.properties
|
||||
version.properties
|
||||
.vscode/
|
||||
|
||||
@@ -3,6 +3,7 @@ plugins {
|
||||
id 'kotlin-android'
|
||||
id 'com.google.dagger.hilt.android'
|
||||
id 'kotlin-kapt'
|
||||
id 'com.google.devtools.ksp'
|
||||
}
|
||||
|
||||
// Create a variable called keystorePropertiesFile, and initialize it to your
|
||||
@@ -15,6 +16,8 @@ def versionPropertiesFile = rootProject.file("version.properties")
|
||||
def keystoreProperties = new Properties()
|
||||
def versionProperties = new Properties()
|
||||
|
||||
def versionMajor = 2
|
||||
def versionMinor = 3
|
||||
|
||||
// Load your keystore.properties file into the keystoreProperties object.
|
||||
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
|
||||
@@ -22,20 +25,26 @@ versionProperties.load(new FileInputStream(versionPropertiesFile))
|
||||
|
||||
|
||||
android {
|
||||
compileSdkVersion 33
|
||||
compileSdk 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId "me.zobrist.tichucounter"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 33
|
||||
targetSdkVersion 34
|
||||
versionCode versionProperties["versionCode"].toInteger()
|
||||
versionName "1.1.0Beta1"
|
||||
resConfigs 'de', 'en'
|
||||
versionName "${versionMajor}.${versionMinor}.${versionProperties["versionCode"].toInteger()}"
|
||||
resourceConfigurations += ['de', 'en']
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
multiDexEnabled true
|
||||
vectorDrawables {
|
||||
useSupportLibrary true
|
||||
}
|
||||
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
|
||||
}
|
||||
}
|
||||
}
|
||||
signingConfigs {
|
||||
create("release") {
|
||||
@@ -55,20 +64,19 @@ android {
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding = true
|
||||
compose = true
|
||||
}
|
||||
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.3.2"
|
||||
kotlinCompilerExtensionVersion = "1.5.14"
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
sourceCompatibility JavaVersion.VERSION_17
|
||||
targetCompatibility JavaVersion.VERSION_17
|
||||
}
|
||||
kotlinOptions {
|
||||
jvmTarget = '1.8'
|
||||
jvmTarget = '17'
|
||||
}
|
||||
namespace 'me.zobrist.tichucounter'
|
||||
packagingOptions {
|
||||
@@ -81,44 +89,44 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
implementation 'androidx.core:core-ktx:1.9.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.6.0-rc01'
|
||||
implementation "androidx.compose.material3:material3:1.0.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.8.9'
|
||||
implementation 'androidx.core:core-ktx:1.13.1'
|
||||
implementation 'androidx.appcompat:appcompat:1.7.0'
|
||||
implementation "androidx.compose.material3:material3:1.2.1"
|
||||
implementation 'com.google.android.play:review:2.0.1'
|
||||
implementation 'com.google.android.play:review-ktx:2.0.1'
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
|
||||
implementation 'androidx.navigation:navigation-fragment-ktx:2.7.7'
|
||||
implementation 'androidx.navigation:navigation-ui-ktx:2.7.7'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.5.5'
|
||||
implementation 'androidx.preference:preference-ktx:1.2.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.2.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
|
||||
implementation 'androidx.compose.material:material-icons-extended:1.3.1'
|
||||
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.8.4'
|
||||
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.8.4'
|
||||
implementation 'androidx.fragment:fragment-ktx:1.8.2'
|
||||
implementation 'androidx.preference:preference-ktx:1.2.1'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.3.2'
|
||||
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.4'
|
||||
implementation 'androidx.compose.material:material-icons-extended:1.6.8'
|
||||
implementation "com.google.accompanist:accompanist-systemuicontroller:0.27.0"
|
||||
implementation 'androidx.activity:activity-compose:1.6.1'
|
||||
implementation "androidx.compose.ui:ui:1.3.3"
|
||||
implementation "androidx.compose.ui:ui-tooling-preview:1.3.3"
|
||||
implementation "androidx.compose.runtime:runtime-livedata:1.3.3"
|
||||
implementation "androidx.navigation:navigation-compose:2.5.3"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
|
||||
implementation 'androidx.activity:activity-compose:1.9.1'
|
||||
implementation "androidx.compose.ui:ui:1.6.8"
|
||||
implementation "androidx.compose.ui:ui-tooling-preview:1.6.8"
|
||||
implementation "androidx.compose.runtime:runtime-livedata:1.6.8"
|
||||
implementation "androidx.navigation:navigation-compose:2.7.7"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.8.4"
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
implementation "com.google.dagger:hilt-android:2.44"
|
||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.3.3"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:1.3.3"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:1.3.3"
|
||||
kapt "com.google.dagger:hilt-compiler:2.44"
|
||||
implementation "androidx.room:room-runtime:2.5.0"
|
||||
annotationProcessor "androidx.room:room-compiler:2.5.0"
|
||||
kapt "androidx.room:room-compiler:2.5.0"
|
||||
implementation "androidx.room:room-ktx:2.5.0"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.2.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
|
||||
implementation "com.google.dagger:hilt-android:2.51.1"
|
||||
androidTestImplementation "androidx.compose.ui:ui-test-junit4:1.6.8"
|
||||
debugImplementation "androidx.compose.ui:ui-tooling:1.6.8"
|
||||
debugImplementation "androidx.compose.ui:ui-test-manifest:1.6.8"
|
||||
kapt "com.google.dagger:hilt-compiler:2.51.1"
|
||||
annotationProcessor "androidx.room:room-compiler:2.6.1"
|
||||
implementation "androidx.room:room-runtime:2.6.1"
|
||||
ksp "androidx.room:room-compiler:2.6.1"
|
||||
implementation "androidx.room:room-ktx:2.6.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.7"
|
||||
}
|
||||
|
||||
// Allow references to generated code
|
||||
|
||||
102
app/schemas/me.zobrist.tichucounter.data.AppDatabase/1.json
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 1,
|
||||
"identityHash": "1739540cd7d5436941316932a1036d83",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Round",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`gameId` INTEGER NOT NULL, `scoreA` INTEGER NOT NULL, `scoreB` INTEGER NOT NULL, `uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "gameId",
|
||||
"columnName": "gameId",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "scoreA",
|
||||
"columnName": "scoreA",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "scoreB",
|
||||
"columnName": "scoreB",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uid",
|
||||
"columnName": "uid",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"uid"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Game",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`active` INTEGER NOT NULL, `nameA` TEXT NOT NULL, `nameB` TEXT NOT NULL, `created` INTEGER NOT NULL, `modified` INTEGER NOT NULL, `uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "active",
|
||||
"columnName": "active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "nameA",
|
||||
"columnName": "nameA",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "nameB",
|
||||
"columnName": "nameB",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "created",
|
||||
"columnName": "created",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modified",
|
||||
"columnName": "modified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uid",
|
||||
"columnName": "uid",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"uid"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1739540cd7d5436941316932a1036d83')"
|
||||
]
|
||||
}
|
||||
}
|
||||
102
app/schemas/me.zobrist.tichucounter.data.AppDatabase/2.json
Normal file
@@ -0,0 +1,102 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 2,
|
||||
"identityHash": "1739540cd7d5436941316932a1036d83",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Round",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`gameId` INTEGER NOT NULL, `scoreA` INTEGER NOT NULL, `scoreB` INTEGER NOT NULL, `uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "gameId",
|
||||
"columnName": "gameId",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "scoreA",
|
||||
"columnName": "scoreA",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "scoreB",
|
||||
"columnName": "scoreB",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uid",
|
||||
"columnName": "uid",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"uid"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "Game",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`active` INTEGER NOT NULL, `nameA` TEXT NOT NULL, `nameB` TEXT NOT NULL, `created` INTEGER NOT NULL, `modified` INTEGER NOT NULL, `uid` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "active",
|
||||
"columnName": "active",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "nameA",
|
||||
"columnName": "nameA",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "nameB",
|
||||
"columnName": "nameB",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "created",
|
||||
"columnName": "created",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "modified",
|
||||
"columnName": "modified",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "uid",
|
||||
"columnName": "uid",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"autoGenerate": true,
|
||||
"columnNames": [
|
||||
"uid"
|
||||
]
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"views": [],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1739540cd7d5436941316932a1036d83')"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ExampleInstrumentedTest {
|
||||
@Test
|
||||
fun useAppContext() {
|
||||
// Context of the app under test.
|
||||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
assertEquals("me.zobrist.tichucounter", appContext.packageName)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,275 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import me.zobrist.tichucounter.data.AppDatabase
|
||||
import me.zobrist.tichucounter.data.GameDao
|
||||
import me.zobrist.tichucounter.data.RoundDao
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import org.junit.After
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RepositoryInstrumentedTest {
|
||||
private lateinit var gameDao: GameDao
|
||||
private lateinit var roundDao: RoundDao
|
||||
private lateinit var repository: GameRepository
|
||||
private lateinit var db: AppDatabase
|
||||
|
||||
@Before
|
||||
fun createDb() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
db = Room.inMemoryDatabaseBuilder(
|
||||
context, AppDatabase::class.java
|
||||
).build()
|
||||
roundDao = db.roundDao()
|
||||
gameDao = db.gameDao()
|
||||
|
||||
repository = GameRepository(gameDao, roundDao)
|
||||
}
|
||||
|
||||
@After
|
||||
@Throws(IOException::class)
|
||||
fun closeDb() {
|
||||
db.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun gameInitialisation() = runTest {
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
assertEquals("TeamA", it.game.nameA)
|
||||
assertEquals("TeamB", it.game.nameB)
|
||||
assertTrue(it.game.active)
|
||||
assertEquals(0, it.rounds.count())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun modifyNames() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
repository.updateActiveTeamName(nameA = "aaa")
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
assertEquals("aaa", it.game.nameA)
|
||||
assertEquals("TeamB", it.game.nameB)
|
||||
}
|
||||
|
||||
repository.updateActiveTeamName(nameB = "bbb")
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
assertEquals("aaa", it.game.nameA)
|
||||
assertEquals("bbb", it.game.nameB)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun newGame() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
assertEquals(6, it.count())
|
||||
|
||||
var uid: Long = 1
|
||||
it.forEach { game ->
|
||||
assertEquals(uid++, game.game.uid)
|
||||
assertEquals(0, game.rounds.count())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun setActive() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
val filtered = it.filter { it.game.active }
|
||||
assertEquals(1, filtered.count())
|
||||
assertEquals(6, filtered.first().game.uid)
|
||||
}
|
||||
|
||||
repository.setActive(2)
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
val filtered = it.filter { it.game.active }
|
||||
assertEquals(1, filtered.count())
|
||||
assertEquals(2, filtered.first().game.uid)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun addRoundToActiveGame() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
|
||||
|
||||
repository.addRoundToActiveGame(1, 1)
|
||||
repository.addRoundToActiveGame(2, 2)
|
||||
repository.addRoundToActiveGame(3, 3)
|
||||
repository.addRoundToActiveGame(4, 4)
|
||||
repository.addRoundToActiveGame(5, 5)
|
||||
repository.addRoundToActiveGame(6, 6)
|
||||
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
val filtered = it.filter { it.rounds.isNotEmpty() }
|
||||
assertEquals(1, filtered.count())
|
||||
assertEquals(6, filtered.first().rounds.count())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun lastRound() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
repository.newGame()
|
||||
|
||||
assertNull(repository.getLastRound())
|
||||
|
||||
repository.addRoundToActiveGame(1, 1)
|
||||
repository.addRoundToActiveGame(2, 2)
|
||||
repository.addRoundToActiveGame(3, 3)
|
||||
repository.addRoundToActiveGame(4, 4)
|
||||
repository.addRoundToActiveGame(5, 5)
|
||||
repository.addRoundToActiveGame(6, 6)
|
||||
|
||||
var lastRound = repository.getLastRound()
|
||||
assertEquals(6, lastRound?.scoreA)
|
||||
assertEquals(6, lastRound?.scoreB)
|
||||
|
||||
repository.deleteLastRound()
|
||||
|
||||
lastRound = repository.getLastRound()
|
||||
assertEquals(5, lastRound?.scoreA)
|
||||
assertEquals(5, lastRound?.scoreB)
|
||||
|
||||
repository.deleteLastRound()
|
||||
repository.deleteLastRound()
|
||||
repository.deleteLastRound()
|
||||
repository.deleteLastRound()
|
||||
repository.deleteLastRound()
|
||||
|
||||
assertNull(repository.getLastRound())
|
||||
|
||||
// No error thrown
|
||||
repository.deleteLastRound()
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun deleteInactive() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
for (i in 1..6) {
|
||||
repository.newGame()
|
||||
repository.addRoundToActiveGame(1, 1)
|
||||
repository.addRoundToActiveGame(2, 2)
|
||||
repository.addRoundToActiveGame(3, 3)
|
||||
repository.addRoundToActiveGame(4, 4)
|
||||
repository.addRoundToActiveGame(5, 5)
|
||||
repository.addRoundToActiveGame(6, 6)
|
||||
}
|
||||
assertEquals(6 * 6, roundDao.getAll().count())
|
||||
|
||||
repository.deleteAllInactive()
|
||||
|
||||
// Consists of two transactions. Delete games then delete rounds.
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
assertEquals(1, it.count())
|
||||
assertEquals(6, it.first().rounds.count())
|
||||
}
|
||||
assertEquals(6, roundDao.getAll().count())
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun deleteById() = runTest {
|
||||
|
||||
repository.getActiveGameFlow().take(1).collect {
|
||||
}
|
||||
|
||||
for (i in 1..6) {
|
||||
repository.newGame()
|
||||
repository.addRoundToActiveGame(1, 1)
|
||||
repository.addRoundToActiveGame(2, 2)
|
||||
repository.addRoundToActiveGame(3, 3)
|
||||
repository.addRoundToActiveGame(4, 4)
|
||||
repository.addRoundToActiveGame(5, 5)
|
||||
repository.addRoundToActiveGame(6, 6)
|
||||
}
|
||||
|
||||
// Non existing Id
|
||||
repository.deleteGame(10)
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
assertEquals(7, it.count())
|
||||
}
|
||||
|
||||
// Non existing Id
|
||||
val toDelete: Long = 3
|
||||
repository.deleteGame(toDelete)
|
||||
|
||||
repository.getAllWithRoundFlow().take(1).collect() { it ->
|
||||
assertEquals(6, it.count())
|
||||
assertEquals(0, it.count { it.game.uid == toDelete })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:localeConfig="@xml/locales_config"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
|
||||
|
Before Width: | Height: | Size: 65 KiB After Width: | Height: | Size: 28 KiB |
@@ -1,83 +0,0 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import me.zobrist.tichucounter.domain.Language
|
||||
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||
import me.zobrist.tichucounter.domain.Theme
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
abstract class BaseActivity : AppCompatActivity(),
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Inject
|
||||
lateinit var settingsAdapter: SettingsAdapter
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
keepScreenOn(settingsAdapter.keepScreenOn)
|
||||
updateTheme(settingsAdapter.theme)
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
PreferenceManager.getDefaultSharedPreferences(this)
|
||||
.unregisterOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) {
|
||||
when (key) {
|
||||
settingsAdapter.language::class.simpleName -> setLanguage(settingsAdapter.language)
|
||||
settingsAdapter.keepScreenOn::class.simpleName -> keepScreenOn(settingsAdapter.keepScreenOn)
|
||||
settingsAdapter.theme::class.simpleName -> updateTheme(settingsAdapter.theme)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun updateTheme(theme: Theme) {
|
||||
|
||||
val themeValue = when (theme) {
|
||||
Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
Theme.DEFAULT -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
|
||||
if (themeValue != AppCompatDelegate.getDefaultNightMode()) {
|
||||
AppCompatDelegate.setDefaultNightMode(themeValue)
|
||||
delegate.applyDayNight()
|
||||
}
|
||||
}
|
||||
|
||||
private fun keepScreenOn(keepOn: Boolean) {
|
||||
if (keepOn) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setLanguage(language: Language) {
|
||||
val currentLocale = AppCompatDelegate.getApplicationLocales()[0].toString()
|
||||
|
||||
if (language.value != null && language.value != currentLocale) {
|
||||
val newLocale = LocaleListCompat.forLanguageTags(language.value)
|
||||
AppCompatDelegate.setApplicationLocales(newLocale)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,40 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.*
|
||||
import androidx.compose.material.icons.outlined.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material.icons.automirrored.outlined.List
|
||||
import androidx.compose.material.icons.automirrored.outlined.Redo
|
||||
import androidx.compose.material.icons.automirrored.outlined.Undo
|
||||
import androidx.compose.material.icons.outlined.Calculate
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material.icons.outlined.Keyboard
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
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.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavDestination.Companion.hierarchy
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
@@ -26,35 +44,88 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.domain.NavigationAction
|
||||
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.MainViewModel
|
||||
import me.zobrist.tichucounter.ui.counter.*
|
||||
import me.zobrist.tichucounter.ui.about.AboutView
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
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.HistoryViewModel
|
||||
import me.zobrist.tichucounter.ui.layout.DrawerContent
|
||||
import me.zobrist.tichucounter.ui.layout.TopBar
|
||||
import me.zobrist.tichucounter.ui.settings.SettingsView
|
||||
import me.zobrist.tichucounter.ui.settings.SettingsViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : BaseActivity() {
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var gameRepository: GameRepository
|
||||
lateinit var settingsAdapter: SettingsAdapter
|
||||
|
||||
@Inject
|
||||
lateinit var repository: GameRepository
|
||||
|
||||
@Inject
|
||||
lateinit var reviewService: ReviewService
|
||||
|
||||
private val counterViewModel: CounterViewModel by viewModels()
|
||||
private val historyViewModel: HistoryViewModel by viewModels()
|
||||
private val settingsViewModel: SettingsViewModel by viewModels()
|
||||
private val mainViewModel: MainViewModel by viewModels()
|
||||
|
||||
private var requestReview: Boolean = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
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 {
|
||||
AppTheme() {
|
||||
AppTheme {
|
||||
val systemUiController = rememberSystemUiController()
|
||||
systemUiController.setStatusBarColor(MaterialTheme.colorScheme.background)
|
||||
NavigationDrawer()
|
||||
@@ -62,105 +133,27 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun MyScaffoldLayout(
|
||||
drawerState: DrawerState,
|
||||
scope: CoroutineScope,
|
||||
navController: NavHostController
|
||||
) {
|
||||
private fun changeLanguage(language: Language) {
|
||||
AppCompatDelegate.setApplicationLocales(language.value)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopBar(
|
||||
mainViewModel.topBarTitle,
|
||||
mainViewModel.topBarIcon,
|
||||
{ mainViewModel.onNavigateClicked() },
|
||||
mainViewModel.topBarActions
|
||||
)
|
||||
}) {
|
||||
private fun changeTheme(theme: Theme) {
|
||||
val themeValue = when (theme) {
|
||||
Theme.LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
|
||||
Theme.DARK -> AppCompatDelegate.MODE_NIGHT_YES
|
||||
Theme.DEFAULT -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
}
|
||||
AppCompatDelegate.setDefaultNightMode(themeValue)
|
||||
}
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = "counter",
|
||||
modifier = Modifier.padding(it)
|
||||
) {
|
||||
composable("counter") {
|
||||
Counter(counterViewModel)
|
||||
mainViewModel.topBarActions = (listOf(
|
||||
TopBarAction(
|
||||
Icons.Outlined.Undo,
|
||||
mainViewModel.isUndoActionActive
|
||||
) { mainViewModel.undoLastRound() },
|
||||
TopBarAction(
|
||||
Icons.Outlined.Redo,
|
||||
mainViewModel.isRedoActionActive
|
||||
) { mainViewModel.redoLastRound() }
|
||||
|
||||
))
|
||||
mainViewModel.topBarIcon = Icons.Outlined.Menu
|
||||
mainViewModel.topBarTitle = stringResource(R.string.app_name)
|
||||
mainViewModel.topBarNavigationAction =
|
||||
NavigationAction { scope.launch { drawerState.open() } }
|
||||
}
|
||||
composable("history") {
|
||||
HistoryList(historyViewModel)
|
||||
mainViewModel.topBarActions = emptyList()
|
||||
mainViewModel.topBarIcon = Icons.Outlined.ArrowBack
|
||||
mainViewModel.topBarTitle = stringResource(R.string.menu_history)
|
||||
mainViewModel.topBarNavigationAction =
|
||||
NavigationAction { navController.navigate("counter") }
|
||||
}
|
||||
composable("settings") {
|
||||
SettingsView(settingsViewModel)
|
||||
mainViewModel.topBarActions = emptyList()
|
||||
mainViewModel.topBarIcon = Icons.Outlined.ArrowBack
|
||||
mainViewModel.topBarTitle = stringResource(R.string.menu_settings)
|
||||
mainViewModel.topBarNavigationAction =
|
||||
NavigationAction { navController.navigate("counter") }
|
||||
}
|
||||
}
|
||||
private fun setKeepScreenOn(keepOn: KeepScreenOn) {
|
||||
if (keepOn.value) {
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
} else {
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun TopBar(
|
||||
title: String,
|
||||
icon: ImageVector,
|
||||
navigateAction: () -> Unit,
|
||||
actions: List<TopBarAction>
|
||||
) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
title,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { navigateAction() }) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = "Localized description"
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
actions.forEach {
|
||||
IconButton(onClick = { it.action() }, enabled = it.isActive) {
|
||||
Icon(
|
||||
imageVector = it.imageVector,
|
||||
contentDescription = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun NavigationDrawer() {
|
||||
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
||||
@@ -168,79 +161,153 @@ class MainActivity : BaseActivity() {
|
||||
val navController = rememberNavController()
|
||||
|
||||
val items = listOf(
|
||||
Screen("history", Icons.Outlined.List, R.string.menu_history),Screen("settings", Icons.Outlined.Settings, R.string.menu_settings)
|
||||
DrawerItem(
|
||||
Route.COUNTER,
|
||||
Icons.Outlined.Calculate,
|
||||
stringResource(R.string.menu_counter)
|
||||
),
|
||||
DrawerItem(
|
||||
Route.HISTORY,
|
||||
Icons.AutoMirrored.Outlined.List,
|
||||
stringResource(R.string.menu_history)
|
||||
),
|
||||
DrawerItem(
|
||||
Route.SETTINGS,
|
||||
Icons.Outlined.Settings,
|
||||
stringResource(R.string.menu_settings)
|
||||
),
|
||||
DrawerItem(
|
||||
Route.ABOUT,
|
||||
Icons.Outlined.Info,
|
||||
stringResource(R.string.menu_about)
|
||||
)
|
||||
)
|
||||
|
||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||
val currentDestination = navBackStackEntry?.destination
|
||||
val currentDestination =
|
||||
Route.valueOf(navBackStackEntry?.destination?.route ?: Route.COUNTER.name)
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
gesturesEnabled = drawerState.isOpen,
|
||||
drawerContent = {
|
||||
ModalDrawerSheet {
|
||||
DrawerContent(
|
||||
drawerItems = items,
|
||||
selectedDrawerItem = items.first { it.route == currentDestination }) {
|
||||
scope.launch {
|
||||
drawerState.close()
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(Icons.Outlined.RestartAlt, contentDescription = null) },
|
||||
colors = NavigationDrawerItemDefaults.colors(
|
||||
unselectedContainerColor = MaterialTheme.colorScheme.secondaryContainer
|
||||
),
|
||||
label = { Text(stringResource(R.string.newGame)) },
|
||||
selected = false,
|
||||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
mainViewModel.newGame()
|
||||
navController.navigate("counter") {
|
||||
// Pop up to the start destination of the graph to
|
||||
// avoid building up a large stack of destinations
|
||||
// on the back stack as users select items
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
// Avoid multiple copies of the same destination when
|
||||
// reselecting the same item
|
||||
launchSingleTop = true
|
||||
// Restore state when reselecting a previously selected item
|
||||
restoreState = true
|
||||
navController.navigate(it)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(20.dp))
|
||||
|
||||
Divider()
|
||||
|
||||
items.forEach { screen ->
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(screen.icon, contentDescription = null) },
|
||||
label = { Text(stringResource(screen.resourceId)) },
|
||||
selected = currentDestination?.hierarchy?.any { it.route == screen.route } == true,
|
||||
onClick = {
|
||||
scope.launch { drawerState.close() }
|
||||
navController.navigate(screen.route) {
|
||||
// Pop up to the start destination of the graph to
|
||||
// avoid building up a large stack of destinations
|
||||
// on the back stack as users select items
|
||||
popUpTo(navController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
// Avoid multiple copies of the same destination when
|
||||
// reselecting the same item
|
||||
launchSingleTop = true
|
||||
// Restore state when reselecting a previously selected item
|
||||
restoreState = true
|
||||
) {
|
||||
MyScaffoldLayout(
|
||||
drawerState,
|
||||
scope,
|
||||
navController,
|
||||
counterViewModel.keyboardHidden && (currentDestination == Route.COUNTER)
|
||||
) { counterViewModel.showKeyboard() }
|
||||
}
|
||||
},
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun MyScaffoldLayout(
|
||||
drawerState: DrawerState,
|
||||
scope: CoroutineScope,
|
||||
navController: NavHostController,
|
||||
showFab: Boolean,
|
||||
fabAction: () -> Unit
|
||||
) {
|
||||
|
||||
var topBarState by remember { mutableStateOf(TopBarState()) }
|
||||
val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
|
||||
|
||||
Scaffold(
|
||||
snackbarHost = { SnackbarHost(snackbarHostState) },
|
||||
floatingActionButton = {
|
||||
if (showFab) {
|
||||
FloatingActionButton(
|
||||
onClick = { fabAction() }) {
|
||||
Icon(Icons.Outlined.Keyboard, null)
|
||||
}
|
||||
}
|
||||
},
|
||||
content = { MyScaffoldLayout(drawerState, scope, navController) }
|
||||
)
|
||||
topBar = { TopBar(topBarState) }) { paddings ->
|
||||
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = Route.COUNTER.name,
|
||||
modifier = Modifier.padding(paddings)
|
||||
) {
|
||||
this.composable(Route.COUNTER.name) {
|
||||
|
||||
var expanded by remember { mutableStateOf(false) }
|
||||
|
||||
topBarState = TopBarState(
|
||||
title = stringResource(R.string.app_name),
|
||||
actions = (listOf(
|
||||
TopBarAction(
|
||||
Icons.AutoMirrored.Outlined.Undo,
|
||||
mainViewModel.isUndoActionActive,
|
||||
{ mainViewModel.undoLastRound() }),
|
||||
TopBarAction(
|
||||
Icons.AutoMirrored.Outlined.Redo,
|
||||
mainViewModel.isRedoActionActive,
|
||||
{ mainViewModel.redoLastRound() }),
|
||||
TopBarAction(
|
||||
Icons.Outlined.MoreVert,
|
||||
mainViewModel.activeGameHasRounds,
|
||||
{ expanded = true }
|
||||
) {
|
||||
val newGameTranslated = stringResource(R.string.new_game)
|
||||
DropDownMenu(
|
||||
listOf(newGameTranslated),
|
||||
"",
|
||||
expanded,
|
||||
) {
|
||||
expanded = false
|
||||
it?.let {
|
||||
when (it) {
|
||||
newGameTranslated -> lifecycleScope.launch { repository.newGame() }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
))
|
||||
) {
|
||||
scope.launch {
|
||||
currentFocus?.clearFocus()
|
||||
drawerState.open()
|
||||
}
|
||||
}
|
||||
|
||||
private class Screen(val route: String, val icon: ImageVector, @StringRes val resourceId: Int)
|
||||
Counter(counterViewModel)
|
||||
}
|
||||
composable(Route.HISTORY.name) {
|
||||
topBarState =
|
||||
TopBarState(title = stringResource(R.string.menu_history)) { scope.launch { drawerState.open() } }
|
||||
|
||||
HistoryList(
|
||||
historyViewModel,
|
||||
snackbarHostState
|
||||
) { navController.navigate(Route.COUNTER) }
|
||||
}
|
||||
composable(Route.SETTINGS.name) {
|
||||
topBarState =
|
||||
TopBarState(title = stringResource(R.string.menu_settings)) { scope.launch { drawerState.open() } }
|
||||
|
||||
SettingsView(settingsViewModel)
|
||||
}
|
||||
|
||||
composable(Route.ABOUT.name) {
|
||||
topBarState =
|
||||
TopBarState(title = stringResource(R.string.menu_about)) { scope.launch { drawerState.open() } }
|
||||
|
||||
AboutView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package me.zobrist.tichucounter.data
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
|
||||
@Database(entities = [Round::class, Game::class], version = 1)
|
||||
@TypeConverters(DateConverter::class)
|
||||
|
||||
@@ -16,4 +16,7 @@ interface DaoBase<T> {
|
||||
|
||||
@Delete
|
||||
fun delete(entity: T)
|
||||
|
||||
@Delete
|
||||
fun delete(entity: List<T>)
|
||||
}
|
||||
@@ -2,7 +2,7 @@ package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.ProvidedTypeConverter
|
||||
import androidx.room.TypeConverter
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
|
||||
@ProvidedTypeConverter
|
||||
object DateConverter {
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.util.*
|
||||
|
||||
@Entity
|
||||
data class Game(
|
||||
override var active: Boolean,
|
||||
override var nameA: String,
|
||||
override var nameB: String,
|
||||
override val created: Date,
|
||||
override var modified: Date,
|
||||
@PrimaryKey(autoGenerate = true) override val uid: Long? = null
|
||||
) : IGame, IEntity
|
||||
@@ -1,17 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import java.util.*
|
||||
|
||||
@Entity
|
||||
data class GameAndScore(
|
||||
override var active: Boolean,
|
||||
override var nameA: String,
|
||||
override var nameB: String,
|
||||
override val created: Date,
|
||||
override var modified: Date,
|
||||
override var gameId: Long,
|
||||
override var scoreA: Int,
|
||||
override var scoreB: Int,
|
||||
) : IGame, IRound {
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.*
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import androidx.room.Transaction
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
|
||||
|
||||
@Dao
|
||||
@@ -10,25 +13,23 @@ interface GameDao : DaoBase<Game> {
|
||||
@Query("SELECT * FROM game")
|
||||
fun getAll(): Flow<List<Game>>
|
||||
|
||||
@Query(
|
||||
"SELECT active, " +
|
||||
"nameA, " +
|
||||
"nameB, " +
|
||||
"created, " +
|
||||
"modified, " +
|
||||
"game.uid as gameId, " +
|
||||
"COALESCE(SUM(round.scoreA), 0) as scoreA, " +
|
||||
"COALESCE(SUM(round.scoreB), 0) as scoreB " +
|
||||
"FROM game " +
|
||||
"LEFT JOIN round ON round.gameId = game.uid GROUP BY game.uid ORDER BY modified DESC"
|
||||
)
|
||||
fun getAllWithPoints(): Flow<List<GameAndScore>>
|
||||
@Transaction
|
||||
@Query("SELECT * FROM game")
|
||||
fun getGamesWithRounds(): Flow<List<GameWithScores>>
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT * FROM game WHERE active is 1")
|
||||
fun getActiveWithRounds(): Flow<GameWithScores?>
|
||||
|
||||
@Query("SELECT * FROM game WHERE uid is :gameId")
|
||||
fun getGameById(gameId: Long): Flow<Game>
|
||||
fun getGameById(gameId: Long): Game
|
||||
|
||||
@Query("SELECT * FROM game WHERE active is 1")
|
||||
fun getActive(): Flow<Game?>
|
||||
fun getActiveAsFlow(): Flow<Game?>
|
||||
|
||||
@Query("SELECT * FROM game WHERE active is 1")
|
||||
fun getActive(): Game?
|
||||
|
||||
|
||||
@Query("UPDATE game SET active = 1 WHERE uid is :gameId;")
|
||||
fun setActive(gameId: Long)
|
||||
@@ -36,4 +37,7 @@ interface GameDao : DaoBase<Game> {
|
||||
@Query("UPDATE game SET active = 0 WHERE uid is not :gameId;")
|
||||
fun setOthersInactive(gameId: Long)
|
||||
|
||||
@Query("SELECT names FROM (SELECT nameA AS names FROM game UNION ALL SELECT nameB AS names FROM game) GROUP BY names")
|
||||
fun getDistinctTeamNames(): Flow<List<String>>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.Embedded
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Relation
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
|
||||
@Entity
|
||||
data class GameWithScores(
|
||||
@Embedded val game: Game = Game(),
|
||||
@Relation(
|
||||
parentColumn = "uid",
|
||||
entityColumn = "gameId"
|
||||
)
|
||||
val rounds: List<Round> = emptyList()
|
||||
)
|
||||
@@ -1,5 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
interface IEntity {
|
||||
val uid: Long?
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import java.util.*
|
||||
|
||||
interface IGame {
|
||||
var active: Boolean
|
||||
var nameA: String
|
||||
var nameB: String
|
||||
val created: Date
|
||||
var modified: Date
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
interface IRound {
|
||||
var gameId: Long
|
||||
var scoreA: Int
|
||||
var scoreB: Int
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Round(
|
||||
override var gameId: Long,
|
||||
override var scoreA: Int,
|
||||
override var scoreB: Int,
|
||||
@PrimaryKey(autoGenerate = true) override val uid: Long? = null
|
||||
) : IRound, IEntity
|
||||
@@ -1,27 +1,16 @@
|
||||
package me.zobrist.tichucounter.data
|
||||
|
||||
import androidx.room.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
|
||||
@Dao
|
||||
interface RoundDao : DaoBase<Round> {
|
||||
|
||||
@Query("SELECT * FROM round")
|
||||
fun getAll(): List<Round>
|
||||
|
||||
@Query("SELECT * FROM round WHERE gameId is :gameId")
|
||||
fun getAllForGame(gameId: Long?): List<Round>
|
||||
|
||||
@Query(
|
||||
"SELECT gameId, SUM(scoreA) as scoreA, SUM(scoreB) as scoreB " +
|
||||
"FROM round " +
|
||||
"LEFT JOIN game ON game.uid = round.gameId " +
|
||||
"WHERE game.active == 1"
|
||||
)
|
||||
fun getRoundSumForActiveGame(): Flow<Round>
|
||||
|
||||
@Query(
|
||||
"SELECT gameId, scoreA, scoreB, round.uid " +
|
||||
"FROM round " +
|
||||
"LEFT JOIN game ON game.uid = round.gameId " +
|
||||
"WHERE game.active == 1"
|
||||
)
|
||||
fun getForActiveGame(): Flow<List<Round>>
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package me.zobrist.tichucounter.data.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import java.util.Date
|
||||
|
||||
@Entity
|
||||
data class Game(
|
||||
var active: Boolean = true,
|
||||
var nameA: String = "TeamA",
|
||||
var nameB: String = "TeamB",
|
||||
val created: Date = Date(),
|
||||
var modified: Date = Date(),
|
||||
@PrimaryKey(autoGenerate = true) override val uid: Long = 0
|
||||
) : IEntity
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.zobrist.tichucounter.data.entity
|
||||
|
||||
interface IEntity {
|
||||
val uid: Long
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.zobrist.tichucounter.data.entity
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity
|
||||
data class Round(
|
||||
var gameId: Long,
|
||||
var scoreA: Int,
|
||||
var scoreB: Int,
|
||||
@PrimaryKey(autoGenerate = true) override val uid: Long = 0
|
||||
) : IEntity
|
||||
@@ -0,0 +1,5 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class DrawerItem(val route: Route, val menuIcon: ImageVector, val menuName: String)
|
||||
@@ -0,0 +1,14 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
|
||||
fun GameWithScores.getTotalPoints(): Pair<Int, Int> {
|
||||
var scoreA = 0
|
||||
var scoreB = 0
|
||||
|
||||
this.rounds.forEach {
|
||||
scoreA += it.scoreA
|
||||
scoreB += it.scoreB
|
||||
}
|
||||
return Pair(scoreA, scoreB)
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import kotlin.math.abs
|
||||
|
||||
|
||||
fun Int.isMultipleOf5(): Boolean {
|
||||
return (this % 5) == 0
|
||||
@@ -11,6 +9,3 @@ fun Int.isMultipleOf100(): Boolean {
|
||||
return (this % 100) == 0
|
||||
}
|
||||
|
||||
fun Int.getAbsoluteDifference(other: Int): Int {
|
||||
return abs(this - other)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.navigation.NavController
|
||||
|
||||
fun NavController.navigate(route: Route) {
|
||||
this.navigate(route.name) {
|
||||
// Pop up to the start destination of the graph to
|
||||
// avoid building up a large stack of destinations
|
||||
// on the back stack as users select items
|
||||
popUpTo(Route.COUNTER.name) {
|
||||
saveState = true
|
||||
}
|
||||
// Avoid multiple copies of the same destination when
|
||||
// reselecting the same item
|
||||
launchSingleTop = true
|
||||
// Restore state when reselecting a previously selected item
|
||||
restoreState = true
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
class NavigationAction(val aciton: () -> Unit)
|
||||
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
enum class Route { COUNTER, HISTORY, SETTINGS, ABOUT }
|
||||
@@ -1,65 +1,112 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import android.content.Context
|
||||
import androidx.appcompat.app.AppCompatDelegate.getApplicationLocales
|
||||
import androidx.core.os.LocaleListCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
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.Singleton
|
||||
|
||||
enum class Theme { DEFAULT, DARK, LIGHT }
|
||||
enum class Language(val value: String) { ENGLISH("en"), GERMAN("de") }
|
||||
enum class Language(val value: LocaleListCompat) {
|
||||
DEFAULT(LocaleListCompat.getEmptyLocaleList()),
|
||||
ENGLISH(LocaleListCompat.forLanguageTags("en")),
|
||||
GERMAN(LocaleListCompat.forLanguageTags("de"))
|
||||
}
|
||||
|
||||
enum class KeepScreenOn(val value: Boolean) { ON(true), OFF(false) }
|
||||
|
||||
typealias VictoryPoints = Int
|
||||
typealias GameWon = Boolean
|
||||
|
||||
@Singleton
|
||||
class SettingsAdapter @Inject constructor(@ApplicationContext private val context: Context) {
|
||||
|
||||
private val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
|
||||
val language: Language
|
||||
get() {
|
||||
var setting = sharedPreferences.getString(Language::class.simpleName, null)
|
||||
if (setting == null) {
|
||||
setCurrentLanguage()
|
||||
setting =
|
||||
sharedPreferences.getString(Language::class.simpleName, Language.ENGLISH.name)
|
||||
}
|
||||
return enumValueOf(setting!!)
|
||||
val language = MutableStateFlow(Language.DEFAULT)
|
||||
|
||||
val theme = MutableStateFlow(Theme.DEFAULT)
|
||||
|
||||
val keepScreenOn = MutableStateFlow(KeepScreenOn.OFF)
|
||||
|
||||
val victoryPoints = MutableStateFlow(0)
|
||||
|
||||
val gameFinished = MutableStateFlow(false)
|
||||
|
||||
init {
|
||||
language.value = try {
|
||||
enumValueOf(sharedPreferences.getString(Language::class.simpleName, null)!!)
|
||||
} catch (_: NullPointerException) {
|
||||
Language.DEFAULT
|
||||
}
|
||||
|
||||
val theme: Theme
|
||||
get() {
|
||||
val setting = sharedPreferences.getString(Theme::class.simpleName, Theme.DEFAULT.name)
|
||||
return enumValueOf(setting!!)
|
||||
theme.value = try {
|
||||
enumValueOf(sharedPreferences.getString(Theme::class.simpleName, null)!!)
|
||||
} catch (_: java.lang.Exception) {
|
||||
Theme.DEFAULT
|
||||
}
|
||||
|
||||
val keepScreenOn: Boolean
|
||||
get() {
|
||||
return sharedPreferences.getBoolean("keep_screen_on", false)
|
||||
keepScreenOn.value = try {
|
||||
enumValueOf(sharedPreferences.getString(KeepScreenOn::class.simpleName, null)!!)
|
||||
} catch (_: java.lang.Exception) {
|
||||
KeepScreenOn.OFF
|
||||
}
|
||||
|
||||
private fun setCurrentLanguage() {
|
||||
var setting = when (getApplicationLocales()[0].toString()) {
|
||||
"de" -> Language.GERMAN
|
||||
else -> Language.ENGLISH
|
||||
victoryPoints.value = sharedPreferences.getInt(VictoryPoints::class.simpleName, 1000)
|
||||
|
||||
gameFinished.value = sharedPreferences.getBoolean(GameWon::class.simpleName, false)
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
language.collect {
|
||||
updatePreference(Language::class.simpleName, it.name)
|
||||
}
|
||||
setLanguage(setting)
|
||||
}
|
||||
|
||||
fun setLanguage(language: Language) {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
theme.collect {
|
||||
updatePreference(Theme::class.simpleName, it.name)
|
||||
}
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
keepScreenOn.collect {
|
||||
updatePreference(KeepScreenOn::class.simpleName, it.name)
|
||||
}
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
victoryPoints.collect {
|
||||
updatePreference(VictoryPoints::class.simpleName, it)
|
||||
}
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
gameFinished.collect {
|
||||
updatePreference(GameWon::class.simpleName, it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updatePreference(name: String?, value: String) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putString(Language::class.simpleName, language.name)
|
||||
editor.commit()
|
||||
editor.putString(name, value)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun setTheme(theme: Theme) {
|
||||
private fun updatePreference(name: String?, value: Boolean) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putString(Theme::class.simpleName, theme.name)
|
||||
editor.commit()
|
||||
editor.putBoolean(name, value)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
fun setKeepScreenOn(setting: Boolean) {
|
||||
private fun updatePreference(name: String?, value: Int) {
|
||||
val editor = sharedPreferences.edit()
|
||||
editor.putBoolean("keep_screen_on", setting)
|
||||
editor.commit()
|
||||
editor.putInt(name, value)
|
||||
editor.apply()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
fun String.digitCount(): Int {
|
||||
var count = 0
|
||||
this.forEach {
|
||||
if (it.isDigit()) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@ import javax.inject.Inject
|
||||
class Tichu @Inject constructor() {
|
||||
|
||||
fun calculateOtherScore(score: Int): Int? {
|
||||
if (score == null) {
|
||||
return null
|
||||
}
|
||||
if (!score.isMultipleOf5()) {
|
||||
return null
|
||||
}
|
||||
@@ -24,6 +21,6 @@ class Tichu @Inject constructor() {
|
||||
if (scoreA == null || scoreB == null) {
|
||||
return false
|
||||
}
|
||||
return (scoreA!!.isMultipleOf5()) && scoreB!!.isMultipleOf5() && (scoreA!! + scoreB!!).isMultipleOf100()
|
||||
return (scoreA.isMultipleOf5()) && scoreB.isMultipleOf5() && (scoreA + scoreB).isMultipleOf100()
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
class TopBarAction(val imageVector: ImageVector, val isActive: Boolean, val action: () -> Unit)
|
||||
class TopBarAction(
|
||||
val imageVector: ImageVector,
|
||||
val isActive: Boolean,
|
||||
val action: () -> Unit,
|
||||
val composeCode: @Composable () -> Unit = {}
|
||||
)
|
||||
@@ -0,0 +1,12 @@
|
||||
package me.zobrist.tichucounter.domain
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Menu
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
|
||||
data class TopBarState(
|
||||
var title: String = "",
|
||||
var icon: ImageVector = Icons.Outlined.Menu,
|
||||
var actions: List<TopBarAction> = emptyList(),
|
||||
var onNavigate: () -> Unit = {}
|
||||
)
|
||||
@@ -1,55 +0,0 @@
|
||||
package me.zobrist.tichucounter.framework
|
||||
|
||||
import android.util.Log
|
||||
import androidx.annotation.MainThread
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
/**
|
||||
* A lifecycle-aware observable that sends only new updates after subscription, used for events like
|
||||
* navigation and Snackbar messages.
|
||||
*
|
||||
*
|
||||
* This avoids a common problem with events: on configuration change (like rotation) an update
|
||||
* can be emitted if the observer is active. This LiveData only calls the observable if there's an
|
||||
* explicit call to setValue() or call().
|
||||
*
|
||||
*
|
||||
* Note that only one observer is going to be notified of changes.
|
||||
*/
|
||||
class SingleLiveEvent<T> : MutableLiveData<T>() {
|
||||
private val pending = AtomicBoolean(false)
|
||||
|
||||
@MainThread
|
||||
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
|
||||
if (hasActiveObservers()) {
|
||||
Log.w(TAG, "Multiple observers registered but only one will be notified of changes.")
|
||||
}
|
||||
// Observe the internal MutableLiveData
|
||||
super.observe(owner) { t ->
|
||||
if (pending.compareAndSet(true, false)) {
|
||||
observer.onChanged(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MainThread
|
||||
override fun setValue(t: T?) {
|
||||
pending.set(true)
|
||||
super.setValue(t)
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for cases where T is Void, to make calls cleaner.
|
||||
*/
|
||||
@MainThread
|
||||
fun call() {
|
||||
value = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val TAG = "me.zobrist.tichucounter.framework.SingleLiveEvent"
|
||||
}
|
||||
}
|
||||
@@ -2,13 +2,19 @@ package me.zobrist.tichucounter.repository
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
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.withContext
|
||||
import me.zobrist.tichucounter.data.Game
|
||||
import me.zobrist.tichucounter.data.GameDao
|
||||
import me.zobrist.tichucounter.data.Round
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
import me.zobrist.tichucounter.data.RoundDao
|
||||
import java.util.*
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import java.util.Date
|
||||
import javax.inject.Inject
|
||||
|
||||
class GameRepository @Inject constructor(
|
||||
@@ -16,20 +22,19 @@ class GameRepository @Inject constructor(
|
||||
private val roundDao: RoundDao
|
||||
) {
|
||||
|
||||
private var _activeGame: Game? = null
|
||||
private var activeGame: Game = Game(true, "TeamA", "TeamB", Date(), Date())
|
||||
|
||||
val activeGame: Game
|
||||
get() {
|
||||
return _activeGame!!
|
||||
}
|
||||
private val newGameFlow = MutableStateFlow(Game())
|
||||
|
||||
private var deletedGame: GameWithScores? = null
|
||||
|
||||
init {
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
gameDao.getActive().collect {
|
||||
gameDao.getActiveAsFlow().collect {
|
||||
if (it == null) {
|
||||
gameDao.insert(Game(true, "TeamA", "TeamB", Date(), Date()))
|
||||
newGame()
|
||||
} else {
|
||||
_activeGame = it
|
||||
activeGame = it
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,20 +42,30 @@ class GameRepository @Inject constructor(
|
||||
|
||||
suspend fun newGame() {
|
||||
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)
|
||||
newGameFlow.value = gameDao.getGameById(id)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateGame(game: Game) {
|
||||
game.modified = Date()
|
||||
suspend fun updateActiveTeamName(nameA: String? = null, nameB: String? = null) {
|
||||
|
||||
val newA = nameA ?: activeGame.nameA
|
||||
val newB = nameB ?: activeGame.nameB
|
||||
|
||||
if (newA == activeGame.nameA && newB == activeGame.nameB) {
|
||||
return
|
||||
}
|
||||
|
||||
activeGame.modified = Date()
|
||||
activeGame.nameA = newA
|
||||
activeGame.nameB = newB
|
||||
withContext(Dispatchers.IO) {
|
||||
gameDao.update(game)
|
||||
gameDao.update(activeGame)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun setActive(id: Long) {
|
||||
suspend fun setActive(id: Long) {
|
||||
withContext(Dispatchers.IO) {
|
||||
gameDao.setActive(id)
|
||||
gameDao.setOthersInactive(id)
|
||||
@@ -80,9 +95,72 @@ class GameRepository @Inject constructor(
|
||||
withContext(Dispatchers.IO) {
|
||||
val active = activeGame
|
||||
active.modified = Date()
|
||||
val round = Round(active.uid!!, scoreA, scoreB)
|
||||
val round = Round(active.uid, scoreA, scoreB)
|
||||
roundDao.insert(round)
|
||||
gameDao.update(active)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteGame(uid: Long) {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val game = gameDao.getGameById(uid)
|
||||
val rounds = roundDao.getAllForGame(game.uid)
|
||||
|
||||
deletedGame = GameWithScores(game, rounds)
|
||||
|
||||
gameDao.delete(game)
|
||||
roundDao.delete(rounds)
|
||||
} catch (_: NullPointerException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun restoreLastDeletedGame() {
|
||||
if (deletedGame == null) {
|
||||
return
|
||||
}
|
||||
val revert = deletedGame!!
|
||||
deletedGame = null
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
gameDao.insert(revert.game)
|
||||
|
||||
revert.rounds.forEach {
|
||||
roundDao.insert(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun deleteAllInactive() {
|
||||
withContext(Dispatchers.IO) {
|
||||
try {
|
||||
gameDao.getAll().take(1).collect { games ->
|
||||
|
||||
val gamesToDelete = games.filter { it.uid != activeGame.uid }
|
||||
val roundsToDelete = roundDao.getAll().filter { it.gameId != activeGame.uid }
|
||||
|
||||
gameDao.delete(gamesToDelete)
|
||||
roundDao.delete(roundsToDelete)
|
||||
}
|
||||
} catch (_: NullPointerException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getActiveGameFlow(): Flow<GameWithScores> {
|
||||
return gameDao.getActiveWithRounds().filter { it != null }.map { it!! }
|
||||
}
|
||||
|
||||
fun getAllWithRoundFlow(): Flow<List<GameWithScores>> {
|
||||
return gameDao.getGamesWithRounds()
|
||||
}
|
||||
|
||||
fun getDistinctTeamNames(): Flow<List<String>> {
|
||||
return gameDao.getDistinctTeamNames()
|
||||
}
|
||||
|
||||
fun getNewGameStarted(): Flow<Game> {
|
||||
return newGameFlow
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
@file:Suppress("unused")
|
||||
|
||||
package me.zobrist.tichucounter.ui
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val md_theme_light_primary = Color(0xFFBE0034)
|
||||
val md_theme_light_primary = Color(0xFF9C404D)
|
||||
val md_theme_light_onPrimary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_primaryContainer = Color(0xFFFFDADA)
|
||||
val md_theme_light_onPrimaryContainer = Color(0xFF40000B)
|
||||
val md_theme_light_secondary = Color(0xFF6E5D00)
|
||||
val md_theme_light_primaryContainer = Color(0xFFFFDADB)
|
||||
val md_theme_light_onPrimaryContainer = Color(0xFF40000F)
|
||||
val md_theme_light_secondary = Color(0xFF765659)
|
||||
val md_theme_light_onSecondary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_secondaryContainer = Color(0xFFFFE261)
|
||||
val md_theme_light_onSecondaryContainer = Color(0xFF221B00)
|
||||
val md_theme_light_tertiary = Color(0xFF76592F)
|
||||
val md_theme_light_secondaryContainer = Color(0xFFFFDADB)
|
||||
val md_theme_light_onSecondaryContainer = Color(0xFF2C1517)
|
||||
val md_theme_light_tertiary = Color(0xFF775930)
|
||||
val md_theme_light_onTertiary = Color(0xFFFFFFFF)
|
||||
val md_theme_light_tertiaryContainer = Color(0xFFFFDDB1)
|
||||
val md_theme_light_onTertiaryContainer = Color(0xFF291800)
|
||||
val md_theme_light_tertiaryContainer = Color(0xFFFFDDB5)
|
||||
val md_theme_light_onTertiaryContainer = Color(0xFF2A1800)
|
||||
val md_theme_light_error = Color(0xFFBA1A1A)
|
||||
val md_theme_light_errorContainer = Color(0xFFFFDAD6)
|
||||
val md_theme_light_onError = Color(0xFFFFFFFF)
|
||||
@@ -22,29 +24,29 @@ val md_theme_light_background = Color(0xFFFFFBFF)
|
||||
val md_theme_light_onBackground = Color(0xFF201A1A)
|
||||
val md_theme_light_surface = Color(0xFFFFFBFF)
|
||||
val md_theme_light_onSurface = Color(0xFF201A1A)
|
||||
val md_theme_light_surfaceVariant = Color(0xFFF4DDDD)
|
||||
val md_theme_light_onSurfaceVariant = Color(0xFF524343)
|
||||
val md_theme_light_outline = Color(0xFF857373)
|
||||
val md_theme_light_inverseOnSurface = Color(0xFFFBEEED)
|
||||
val md_theme_light_surfaceVariant = Color(0xFFF4DDDE)
|
||||
val md_theme_light_onSurfaceVariant = Color(0xFF524344)
|
||||
val md_theme_light_outline = Color(0xFF857374)
|
||||
val md_theme_light_inverseOnSurface = Color(0xFFFBEEEE)
|
||||
val md_theme_light_inverseSurface = Color(0xFF362F2F)
|
||||
val md_theme_light_inversePrimary = Color(0xFFFFB3B5)
|
||||
val md_theme_light_inversePrimary = Color(0xFFFFB2B9)
|
||||
val md_theme_light_shadow = Color(0xFF000000)
|
||||
val md_theme_light_surfaceTint = Color(0xFFBE0034)
|
||||
val md_theme_light_outlineVariant = Color(0xFFD7C1C1)
|
||||
val md_theme_light_surfaceTint = Color(0xFF9C404D)
|
||||
val md_theme_light_outlineVariant = Color(0xFFD7C1C2)
|
||||
val md_theme_light_scrim = Color(0xFF000000)
|
||||
|
||||
val md_theme_dark_primary = Color(0xFFFFB3B5)
|
||||
val md_theme_dark_onPrimary = Color(0xFF680018)
|
||||
val md_theme_dark_primaryContainer = Color(0xFF920026)
|
||||
val md_theme_dark_onPrimaryContainer = Color(0xFFFFDADA)
|
||||
val md_theme_dark_secondary = Color(0xFFE6C500)
|
||||
val md_theme_dark_onSecondary = Color(0xFF3A3000)
|
||||
val md_theme_dark_secondaryContainer = Color(0xFF534600)
|
||||
val md_theme_dark_onSecondaryContainer = Color(0xFFFFE261)
|
||||
val md_theme_dark_tertiary = Color(0xFFE6C18D)
|
||||
val md_theme_dark_onTertiary = Color(0xFF422C05)
|
||||
val md_theme_dark_tertiaryContainer = Color(0xFF5C421A)
|
||||
val md_theme_dark_onTertiaryContainer = Color(0xFFFFDDB1)
|
||||
val md_theme_dark_primary = Color(0xFFFFB2B9)
|
||||
val md_theme_dark_onPrimary = Color(0xFF5F1222)
|
||||
val md_theme_dark_primaryContainer = Color(0xFF7D2937)
|
||||
val md_theme_dark_onPrimaryContainer = Color(0xFFFFDADB)
|
||||
val md_theme_dark_secondary = Color(0xFFE5BDBF)
|
||||
val md_theme_dark_onSecondary = Color(0xFF44292C)
|
||||
val md_theme_dark_secondaryContainer = Color(0xFF5C3F41)
|
||||
val md_theme_dark_onSecondaryContainer = Color(0xFFFFDADB)
|
||||
val md_theme_dark_tertiary = Color(0xFFE8C08E)
|
||||
val md_theme_dark_onTertiary = Color(0xFF442B06)
|
||||
val md_theme_dark_tertiaryContainer = Color(0xFF5D411B)
|
||||
val md_theme_dark_onTertiaryContainer = Color(0xFFFFDDB5)
|
||||
val md_theme_dark_error = Color(0xFFFFB4AB)
|
||||
val md_theme_dark_errorContainer = Color(0xFF93000A)
|
||||
val md_theme_dark_onError = Color(0xFF690005)
|
||||
@@ -53,16 +55,16 @@ val md_theme_dark_background = Color(0xFF201A1A)
|
||||
val md_theme_dark_onBackground = Color(0xFFECE0DF)
|
||||
val md_theme_dark_surface = Color(0xFF201A1A)
|
||||
val md_theme_dark_onSurface = Color(0xFFECE0DF)
|
||||
val md_theme_dark_surfaceVariant = Color(0xFF524343)
|
||||
val md_theme_dark_onSurfaceVariant = Color(0xFFD7C1C1)
|
||||
val md_theme_dark_outline = Color(0xFF9F8C8C)
|
||||
val md_theme_dark_surfaceVariant = Color(0xFF524344)
|
||||
val md_theme_dark_onSurfaceVariant = Color(0xFFD7C1C2)
|
||||
val md_theme_dark_outline = Color(0xFF9F8C8D)
|
||||
val md_theme_dark_inverseOnSurface = Color(0xFF201A1A)
|
||||
val md_theme_dark_inverseSurface = Color(0xFFECE0DF)
|
||||
val md_theme_dark_inversePrimary = Color(0xFFBE0034)
|
||||
val md_theme_dark_inversePrimary = Color(0xFF9C404D)
|
||||
val md_theme_dark_shadow = Color(0xFF000000)
|
||||
val md_theme_dark_surfaceTint = Color(0xFFFFB3B5)
|
||||
val md_theme_dark_outlineVariant = Color(0xFF524343)
|
||||
val md_theme_dark_surfaceTint = Color(0xFFFFB2B9)
|
||||
val md_theme_dark_outlineVariant = Color(0xFF524344)
|
||||
val md_theme_dark_scrim = Color(0xFF000000)
|
||||
|
||||
|
||||
val seed = Color(0xFFED0043)
|
||||
val seed = Color(0xFF833842)
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package me.zobrist.tichucounter.ui
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -10,48 +8,56 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.Round
|
||||
import me.zobrist.tichucounter.data.RoundDao
|
||||
import me.zobrist.tichucounter.domain.NavigationAction
|
||||
import me.zobrist.tichucounter.domain.TopBarAction
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class MainViewModel @Inject constructor(
|
||||
private val gameRepository: GameRepository,
|
||||
roundDao: RoundDao
|
||||
private val gameRepository: GameRepository
|
||||
) : ViewModel() {
|
||||
|
||||
|
||||
private var redoRounds = mutableStateListOf<Round>()
|
||||
private var expectedRoundCount = 0
|
||||
|
||||
var topBarTitle by mutableStateOf("")
|
||||
var topBarActions by mutableStateOf(emptyList<TopBarAction>())
|
||||
var topBarIcon by mutableStateOf(Icons.Filled.Menu)
|
||||
var isUndoActionActive by mutableStateOf(false)
|
||||
var topBarNavigationAction by mutableStateOf(NavigationAction {})
|
||||
|
||||
val isRedoActionActive: Boolean
|
||||
get() = redoRounds.isNotEmpty()
|
||||
|
||||
var activeGameHasRounds by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
private var newGame: Game? = null
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
roundDao.getForActiveGame().collect() {
|
||||
isUndoActionActive = it.isNotEmpty()
|
||||
|
||||
if (expectedRoundCount != it.count()) {
|
||||
gameRepository.getActiveGameFlow().collect {
|
||||
|
||||
activeGameHasRounds = it.rounds.isNotEmpty() == true
|
||||
|
||||
isUndoActionActive = it.rounds.isNotEmpty()
|
||||
|
||||
if (expectedRoundCount != it.rounds.count()) {
|
||||
redoRounds.clear()
|
||||
}
|
||||
|
||||
expectedRoundCount = it.count()
|
||||
}
|
||||
expectedRoundCount = it.rounds.count()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun onNavigateClicked() {
|
||||
topBarNavigationAction.aciton()
|
||||
viewModelScope.launch {
|
||||
gameRepository.getNewGameStarted().collect {
|
||||
if (newGame == null) {
|
||||
newGame = it
|
||||
return@collect
|
||||
}
|
||||
redoRounds.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun undoLastRound() {
|
||||
@@ -76,15 +82,4 @@ class MainViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearRedoList() {
|
||||
redoRounds.clear()
|
||||
}
|
||||
|
||||
fun newGame() {
|
||||
viewModelScope.launch {
|
||||
redoRounds.clear()
|
||||
gameRepository.newGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,11 @@ package me.zobrist.tichucounter.ui
|
||||
|
||||
import android.os.Build
|
||||
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.ui.platform.LocalContext
|
||||
|
||||
@@ -75,7 +79,7 @@ private val DarkColors = darkColorScheme(
|
||||
@Composable
|
||||
fun AppTheme(
|
||||
useDarkTheme: Boolean = isSystemInDarkTheme(),
|
||||
content: @Composable() () -> Unit
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
|
||||
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
||||
|
||||
109
app/src/main/java/me/zobrist/tichucounter/ui/about/AboutView.kt
Normal file
@@ -0,0 +1,109 @@
|
||||
package me.zobrist.tichucounter.ui.about
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
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.outlined.Mail
|
||||
import androidx.compose.material.icons.outlined.Shop
|
||||
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.ui.Alignment.Companion.Top
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.BuildConfig
|
||||
import me.zobrist.tichucounter.R
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
|
||||
|
||||
@Composable
|
||||
fun AboutView() {
|
||||
|
||||
val uriHandler = LocalUriHandler.current
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(
|
||||
top = 20.dp,
|
||||
start = 20.dp,
|
||||
end = 20.dp,
|
||||
bottom = 40.dp
|
||||
),
|
||||
|
||||
) {
|
||||
|
||||
Row {
|
||||
Image(
|
||||
modifier = Modifier
|
||||
.padding(end = 10.dp)
|
||||
.align(Top)
|
||||
.size(75.dp)
|
||||
.background(
|
||||
color = Color.Red,
|
||||
shape = ShapeDefaults.Medium
|
||||
),
|
||||
painter = painterResource(R.drawable.tichu_logo),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.None
|
||||
)
|
||||
|
||||
Column {
|
||||
Text(
|
||||
text = stringResource(id = R.string.app_name),
|
||||
style = MaterialTheme.typography.headlineMedium
|
||||
)
|
||||
Text(text = "V" + BuildConfig.VERSION_NAME)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 30.dp),
|
||||
onClick = { uriHandler.openUri("market://details?id=me.zobrist.tichucounter") }
|
||||
) {
|
||||
Icon(imageVector = Icons.Outlined.Shop, contentDescription = null)
|
||||
Text(stringResource(id = R.string.play_store))
|
||||
}
|
||||
|
||||
Button(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 30.dp),
|
||||
onClick = { uriHandler.openUri("mailto:app@zobrist.me") }
|
||||
) {
|
||||
Icon(imageVector = Icons.Outlined.Mail, contentDescription = null)
|
||||
Text(stringResource(id = R.string.contact_us))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||
@Composable
|
||||
fun AboutViewPreview() {
|
||||
AppTheme {
|
||||
Surface {
|
||||
AboutView()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package me.zobrist.tichucounter.ui.composables
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
|
||||
@Composable
|
||||
fun <T> DropDownMenu(
|
||||
list: Collection<T>,
|
||||
selected: T,
|
||||
expanded: Boolean,
|
||||
onSelected: (T?) -> Unit
|
||||
) {
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { onSelected(null) }
|
||||
) {
|
||||
list.forEach {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onSelected(it)
|
||||
},
|
||||
trailingIcon = {
|
||||
if (it == selected) {
|
||||
Icon(Icons.Outlined.Check, null)
|
||||
}
|
||||
},
|
||||
text = { Text(it.toString()) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package me.zobrist.tichucounter.ui.composables
|
||||
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
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.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.layout.onSizeChanged
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalFocusManager
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TypeaheadTextField(
|
||||
value: String,
|
||||
items: List<String>,
|
||||
onValueChange: (String) -> Unit,
|
||||
modifier: Modifier,
|
||||
colors: TextFieldColors,
|
||||
textStyle: TextStyle
|
||||
) {
|
||||
|
||||
var isFocused by remember { mutableStateOf(false) }
|
||||
val focusManager = LocalFocusManager.current
|
||||
|
||||
ExposedDropdownMenuBox(
|
||||
expanded = isFocused,
|
||||
modifier = modifier,
|
||||
onExpandedChange = {}
|
||||
) {
|
||||
|
||||
var dropDownWidth by remember { mutableIntStateOf(0) }
|
||||
|
||||
TextField(
|
||||
value = value,
|
||||
textStyle = textStyle,
|
||||
onValueChange = {
|
||||
onValueChange(it)
|
||||
},
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
focusManager.clearFocus()
|
||||
}
|
||||
),
|
||||
modifier = Modifier
|
||||
.menuAnchor()
|
||||
.onFocusChanged {
|
||||
isFocused = it.isFocused
|
||||
}
|
||||
.onSizeChanged { dropDownWidth = it.width }
|
||||
.onKeyEvent { event ->
|
||||
if (event.key == Key.Back || event.key == Key.Enter) {
|
||||
focusManager.clearFocus()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
colors = colors
|
||||
)
|
||||
ExposedDropdownMenu(
|
||||
expanded = isFocused && items.isNotEmpty(),
|
||||
modifier = Modifier
|
||||
.width(with(LocalDensity.current) { dropDownWidth.toDp() }),
|
||||
onDismissRequest = { }
|
||||
) {
|
||||
|
||||
items.forEach {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onValueChange(it)
|
||||
focusManager.clearFocus()
|
||||
},
|
||||
text = { Text(it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,22 +3,46 @@ package me.zobrist.tichucounter.ui.counter
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Column
|
||||
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.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.mutableIntStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import me.zobrist.tichucounter.data.Round
|
||||
import me.zobrist.tichucounter.R
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
|
||||
|
||||
@Composable
|
||||
fun Counter(viewModel: ICounterViewModel = PreviewViewModel()) {
|
||||
|
||||
var orientation by remember { mutableStateOf(Configuration.ORIENTATION_PORTRAIT) }
|
||||
var orientation by remember { mutableIntStateOf(Configuration.ORIENTATION_PORTRAIT) }
|
||||
orientation = LocalConfiguration.current.orientation
|
||||
|
||||
if (viewModel.showVictoryDialog) {
|
||||
GameVictoryDialog(
|
||||
viewModel.totalScoreA,
|
||||
viewModel.totalScoreB,
|
||||
viewModel.teamNameA,
|
||||
viewModel.teamNameB,
|
||||
{ viewModel.victoryDialogExecuted(false) })
|
||||
{
|
||||
viewModel.victoryDialogExecuted(true)
|
||||
}
|
||||
}
|
||||
|
||||
Surface {
|
||||
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
Landscape(viewModel)
|
||||
@@ -35,6 +59,8 @@ fun Landscape(viewModel: ICounterViewModel) {
|
||||
TeamNamesView(
|
||||
viewModel.teamNameA,
|
||||
viewModel.teamNameB,
|
||||
viewModel.teamNameSuggestionsA,
|
||||
viewModel.teamNameSuggestionsB,
|
||||
{ viewModel.updateNameA(it) },
|
||||
{ viewModel.updateNameB(it) }
|
||||
)
|
||||
@@ -49,23 +75,12 @@ fun Landscape(viewModel: ICounterViewModel) {
|
||||
Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
|
||||
if (!viewModel.keyboardHidden) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardView(
|
||||
viewModel.currentScoreA,
|
||||
viewModel.currentScoreB,
|
||||
viewModel.requestFocusA,
|
||||
viewModel.enableSubmit,
|
||||
{ viewModel.updateFocusStateA(it) },
|
||||
{ viewModel.updateFocusStateB(it) },
|
||||
{ viewModel.digitClicked(it) },
|
||||
{ viewModel.addSub100Clicked(it) },
|
||||
{ viewModel.deleteClicked() },
|
||||
{ viewModel.negateClicked() }
|
||||
) { viewModel.submitClicked() }
|
||||
KeyBoardView(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -75,6 +90,8 @@ fun Portrait(viewModel: ICounterViewModel) {
|
||||
TeamNamesView(
|
||||
viewModel.teamNameA,
|
||||
viewModel.teamNameB,
|
||||
viewModel.teamNameSuggestionsA,
|
||||
viewModel.teamNameSuggestionsB,
|
||||
{ viewModel.updateNameA(it) },
|
||||
{ viewModel.updateNameB(it) }
|
||||
)
|
||||
@@ -89,18 +106,9 @@ fun Portrait(viewModel: ICounterViewModel) {
|
||||
Modifier.weight(1f)
|
||||
)
|
||||
|
||||
KeyboardView(
|
||||
viewModel.currentScoreA,
|
||||
viewModel.currentScoreB,
|
||||
viewModel.requestFocusA,
|
||||
viewModel.enableSubmit,
|
||||
{ viewModel.updateFocusStateA(it) },
|
||||
{ viewModel.updateFocusStateB(it) },
|
||||
{ viewModel.digitClicked(it) },
|
||||
{ viewModel.addSub100Clicked(it) },
|
||||
{ viewModel.deleteClicked() },
|
||||
{ viewModel.negateClicked() }
|
||||
) { viewModel.submitClicked() }
|
||||
if (!viewModel.keyboardHidden) {
|
||||
KeyBoardView(viewModel = viewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,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 {
|
||||
override var roundScoreList: List<Round> =
|
||||
listOf(Round(1, 10, 90), Round(1, 50, 50), Round(1, 70, 30))
|
||||
@@ -123,14 +179,21 @@ internal class PreviewViewModel : ICounterViewModel {
|
||||
override var teamNameB: String = "Team B"
|
||||
override var currentScoreA: String = ""
|
||||
override var currentScoreB: String = "45"
|
||||
override var enableSubmit: Boolean = false
|
||||
override var isValidRound: Boolean = false
|
||||
override var isAFocused: Boolean = false
|
||||
override var isBFocused: Boolean = false
|
||||
override var requestFocusA: FocusRequester = FocusRequester()
|
||||
override var requestFocusB: FocusRequester = FocusRequester()
|
||||
override var activeValue: String = currentScoreA
|
||||
override var inactiveValue: String = currentScoreB
|
||||
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 teamNameSuggestionsB: List<String> =
|
||||
listOf("TeamA", "asdffd", "TeamB", "really really long Team Name that is way too long")
|
||||
override var showVictoryDialog: Boolean = false
|
||||
|
||||
override fun giveFocusToAIfNone() {
|
||||
override fun focusLastInput() {
|
||||
}
|
||||
|
||||
override fun updateOtherScore() {
|
||||
@@ -155,19 +218,31 @@ internal class PreviewViewModel : ICounterViewModel {
|
||||
override fun addSub100Clicked(toAdd: Int) {
|
||||
}
|
||||
|
||||
override fun deleteClicked() {
|
||||
}
|
||||
|
||||
override fun updateNameA(value: String) {
|
||||
}
|
||||
|
||||
override fun updateNameB(value: String) {
|
||||
}
|
||||
|
||||
override fun victoryDialogExecuted(result: Boolean) {
|
||||
}
|
||||
|
||||
override fun updateFocusStateA(state: Boolean) {
|
||||
}
|
||||
|
||||
override fun updateFocusStateB(state: Boolean) {
|
||||
}
|
||||
|
||||
override fun swapInputScores() {
|
||||
}
|
||||
|
||||
override fun hideKeyboard() {
|
||||
}
|
||||
|
||||
override fun showKeyboard() {
|
||||
}
|
||||
|
||||
override fun deleteState(pressed: Boolean) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,41 @@
|
||||
package me.zobrist.tichucounter.ui.counter
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.GameDao
|
||||
import me.zobrist.tichucounter.data.Round
|
||||
import me.zobrist.tichucounter.data.RoundDao
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||
import me.zobrist.tichucounter.domain.Tichu
|
||||
import me.zobrist.tichucounter.domain.digitCount
|
||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
interface ICounterViewModel {
|
||||
var roundScoreList: List<Round>
|
||||
var totalScoreA: Int
|
||||
var totalScoreB: Int
|
||||
var teamNameA: String
|
||||
var teamNameB: String
|
||||
var currentScoreA: String
|
||||
var currentScoreB: String
|
||||
var enableSubmit: Boolean
|
||||
var isAFocused: Boolean
|
||||
var isBFocused: Boolean
|
||||
var requestFocusA: FocusRequester
|
||||
var activeValue: String
|
||||
var inactiveValue: String
|
||||
private enum class Focused { TEAM_A, TEAM_B }
|
||||
|
||||
fun giveFocusToAIfNone()
|
||||
interface IKeyBoardViewModel {
|
||||
|
||||
val currentScoreA: String
|
||||
val currentScoreB: String
|
||||
val isValidRound: Boolean
|
||||
val isAFocused: Boolean
|
||||
val isBFocused: Boolean
|
||||
val requestFocusA: FocusRequester
|
||||
val requestFocusB: FocusRequester
|
||||
val activeValue: String
|
||||
val inactiveValue: String
|
||||
val keyboardHidden: Boolean
|
||||
|
||||
fun focusLastInput()
|
||||
fun updateOtherScore()
|
||||
fun isValidTichuRound(): Boolean
|
||||
fun updateSubmitButton()
|
||||
@@ -38,42 +43,83 @@ interface ICounterViewModel {
|
||||
fun digitClicked(digit: String)
|
||||
fun negateClicked()
|
||||
fun addSub100Clicked(toAdd: Int)
|
||||
fun deleteClicked()
|
||||
fun updateNameA(value: String)
|
||||
fun updateNameB(value: String)
|
||||
fun updateFocusStateA(state: Boolean)
|
||||
fun updateFocusStateB(state: Boolean)
|
||||
fun swapInputScores()
|
||||
fun hideKeyboard()
|
||||
fun showKeyboard()
|
||||
fun deleteState(pressed: Boolean)
|
||||
|
||||
}
|
||||
|
||||
interface ICounterViewModel : IKeyBoardViewModel {
|
||||
val roundScoreList: List<Round>
|
||||
val totalScoreA: Int
|
||||
val totalScoreB: Int
|
||||
val teamNameA: String
|
||||
val teamNameB: String
|
||||
val teamNameSuggestionsA: List<String>
|
||||
val teamNameSuggestionsB: List<String>
|
||||
val showVictoryDialog: Boolean
|
||||
|
||||
fun updateNameA(value: String)
|
||||
fun updateNameB(value: String)
|
||||
fun victoryDialogExecuted(result: Boolean)
|
||||
}
|
||||
|
||||
@HiltViewModel
|
||||
class CounterViewModel @Inject constructor(
|
||||
private val gameRepository: GameRepository,
|
||||
private val roundDao: RoundDao,
|
||||
private val gameDao: GameDao
|
||||
private val settings: SettingsAdapter
|
||||
) :
|
||||
ViewModel(), ICounterViewModel {
|
||||
|
||||
override var roundScoreList by mutableStateOf(emptyList<Round>())
|
||||
private set
|
||||
|
||||
override var totalScoreA by mutableStateOf(0)
|
||||
override var totalScoreA by mutableIntStateOf(0)
|
||||
private set
|
||||
|
||||
override var totalScoreB by mutableStateOf(0)
|
||||
override var totalScoreB by mutableIntStateOf(0)
|
||||
private set
|
||||
|
||||
override var teamNameA by mutableStateOf("")
|
||||
private set
|
||||
|
||||
override var teamNameB by mutableStateOf("")
|
||||
private set
|
||||
|
||||
override var currentScoreA by mutableStateOf("")
|
||||
private set
|
||||
|
||||
override var currentScoreB by mutableStateOf("")
|
||||
private set
|
||||
|
||||
override var enableSubmit by mutableStateOf(false)
|
||||
override var isValidRound by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
override var isAFocused by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
override var isBFocused by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
override var requestFocusA by mutableStateOf(FocusRequester())
|
||||
private set
|
||||
|
||||
override var requestFocusB by mutableStateOf(FocusRequester())
|
||||
private set
|
||||
|
||||
override var keyboardHidden by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
override var teamNameSuggestionsA by mutableStateOf(listOf<String>())
|
||||
private set
|
||||
|
||||
override var teamNameSuggestionsB by mutableStateOf(listOf<String>())
|
||||
private set
|
||||
override var showVictoryDialog by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
override var activeValue: String
|
||||
get() {
|
||||
@@ -107,33 +153,90 @@ class CounterViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private var lastFocused = Focused.TEAM_A
|
||||
|
||||
private var deletePressed = false
|
||||
|
||||
private var deleteJob: Job? = null
|
||||
|
||||
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 {
|
||||
viewModelScope.launch {
|
||||
roundDao.getForActiveGame().collect {
|
||||
roundScoreList = it
|
||||
}
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
gameDao.getActive().collect {
|
||||
gameRepository.getActiveGameFlow().collect {
|
||||
if (it != null) {
|
||||
teamNameA = it.nameA
|
||||
teamNameB = it.nameB
|
||||
val score = it.getTotalPoints()
|
||||
|
||||
roundScoreList = it.rounds
|
||||
totalScoreA = score.first
|
||||
totalScoreB = score.second
|
||||
|
||||
teamNameA = it.game.nameA
|
||||
teamNameB = it.game.nameB
|
||||
|
||||
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 {
|
||||
roundDao.getRoundSumForActiveGame().collect { score ->
|
||||
totalScoreA = score.scoreA
|
||||
totalScoreB = score.scoreB
|
||||
gameRepository.getDistinctTeamNames().collect {
|
||||
distinctTeamNames = it
|
||||
|
||||
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 giveFocusToAIfNone() {
|
||||
if (!isAFocused && !isBFocused) {
|
||||
requestFocusA.requestFocus()
|
||||
override fun focusLastInput() {
|
||||
when (lastFocused) {
|
||||
Focused.TEAM_A -> if (!isAFocused) requestFocusA.requestFocus()
|
||||
Focused.TEAM_B -> if (!isBFocused) requestFocusB.requestFocus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +265,7 @@ class CounterViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
override fun updateSubmitButton() {
|
||||
enableSubmit = isValidTichuRound()
|
||||
isValidRound = isValidTichuRound()
|
||||
}
|
||||
|
||||
override fun submitClicked() {
|
||||
@@ -171,19 +274,31 @@ class CounterViewModel @Inject constructor(
|
||||
}
|
||||
currentScoreA = ""
|
||||
currentScoreB = ""
|
||||
enableSubmit = false
|
||||
isValidRound = false
|
||||
}
|
||||
|
||||
override fun digitClicked(digit: String) {
|
||||
giveFocusToAIfNone()
|
||||
focusLastInput()
|
||||
|
||||
|
||||
if (activeValue.digitCount() >= 5) {
|
||||
// 5 digits is enough
|
||||
return
|
||||
}
|
||||
|
||||
val newValue = activeValue + digit
|
||||
|
||||
try {
|
||||
activeValue = newValue.toInt().toString()
|
||||
} catch (_: NumberFormatException) {
|
||||
}
|
||||
|
||||
activeValue += digit
|
||||
updateOtherScore()
|
||||
updateSubmitButton()
|
||||
}
|
||||
|
||||
override fun negateClicked() {
|
||||
giveFocusToAIfNone()
|
||||
focusLastInput()
|
||||
|
||||
activeValue = if (activeValue.contains("-")) {
|
||||
activeValue.replace("-", "")
|
||||
@@ -195,7 +310,7 @@ class CounterViewModel @Inject constructor(
|
||||
}
|
||||
|
||||
override fun addSub100Clicked(toAdd: Int) {
|
||||
giveFocusToAIfNone()
|
||||
focusLastInput()
|
||||
|
||||
activeValue = try {
|
||||
val temp = activeValue.toInt() + toAdd
|
||||
@@ -210,7 +325,72 @@ class CounterViewModel @Inject constructor(
|
||||
updateSubmitButton()
|
||||
}
|
||||
|
||||
override fun deleteClicked() {
|
||||
override fun updateNameA(value: String) {
|
||||
teamNameA = value
|
||||
viewModelScope.launch {
|
||||
gameRepository.updateActiveTeamName(nameA = value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateNameB(value: String) {
|
||||
teamNameB = value
|
||||
viewModelScope.launch {
|
||||
gameRepository.updateActiveTeamName(nameB = value)
|
||||
}
|
||||
}
|
||||
|
||||
override fun victoryDialogExecuted(result: Boolean) {
|
||||
showVictoryDialog = false
|
||||
settings.gameFinished.value = true
|
||||
|
||||
if (result) {
|
||||
viewModelScope.launch {
|
||||
gameRepository.newGame()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateFocusStateA(state: Boolean) {
|
||||
isAFocused = state
|
||||
if (state) {
|
||||
lastFocused = Focused.TEAM_A
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateFocusStateB(state: Boolean) {
|
||||
isBFocused = state
|
||||
if (state) {
|
||||
lastFocused = Focused.TEAM_B
|
||||
}
|
||||
}
|
||||
|
||||
override fun swapInputScores() {
|
||||
val swap = currentScoreA
|
||||
currentScoreA = currentScoreB
|
||||
currentScoreB = swap
|
||||
}
|
||||
|
||||
override fun hideKeyboard() {
|
||||
keyboardHidden = true
|
||||
}
|
||||
|
||||
override fun showKeyboard() {
|
||||
keyboardHidden = false
|
||||
}
|
||||
|
||||
override fun deleteState(pressed: Boolean) {
|
||||
deletePressed = pressed
|
||||
|
||||
if (deletePressed) {
|
||||
if (deleteJob?.isActive != true) {
|
||||
deleteJob = deleteRepeatedlyUntilRelease()
|
||||
}
|
||||
} else {
|
||||
deleteJob?.cancel()
|
||||
}
|
||||
}
|
||||
|
||||
private fun deleteLastDigitActive() {
|
||||
if (activeValue != "") {
|
||||
activeValue = activeValue.dropLast(1)
|
||||
}
|
||||
@@ -218,27 +398,29 @@ class CounterViewModel @Inject constructor(
|
||||
updateSubmitButton()
|
||||
}
|
||||
|
||||
override fun updateNameA(value: String) {
|
||||
viewModelScope.launch {
|
||||
val game = gameRepository.activeGame
|
||||
game.nameA = value
|
||||
gameRepository.updateGame(game)
|
||||
private fun deleteRepeatedlyUntilRelease(): Job {
|
||||
return viewModelScope.launch {
|
||||
deleteLastDigitActive()
|
||||
delay(500)
|
||||
while (deletePressed) {
|
||||
deleteLastDigitActive()
|
||||
delay(100)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateNameB(value: String) {
|
||||
viewModelScope.launch {
|
||||
val game = gameRepository.activeGame
|
||||
game.nameB = value
|
||||
gameRepository.updateGame(game)
|
||||
}
|
||||
private fun buildTeamNameSuggestions() {
|
||||
teamNameSuggestionsA = buildTypeaheadList(distinctTeamNames, teamNameA)
|
||||
teamNameSuggestionsB = buildTypeaheadList(distinctTeamNames, teamNameB)
|
||||
}
|
||||
|
||||
override fun updateFocusStateA(state: Boolean) {
|
||||
isAFocused = state
|
||||
private fun buildTypeaheadList(rawList: List<String>, currentInput: String): List<String> {
|
||||
var filtered = rawList.filter { it.isNotEmpty() && it != currentInput }
|
||||
|
||||
if (currentInput.isNotEmpty()) {
|
||||
filtered = filtered.filter { it.contains(currentInput, ignoreCase = true) }
|
||||
}
|
||||
|
||||
override fun updateFocusStateB(state: Boolean) {
|
||||
isBFocused = state
|
||||
return filtered.sorted().sortedBy { it.length }.take(10)
|
||||
}
|
||||
}
|
||||
@@ -1,72 +1,134 @@
|
||||
package me.zobrist.tichucounter.ui.counter
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.*
|
||||
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.collectIsPressedAsState
|
||||
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.outlined.Backspace
|
||||
import androidx.compose.material.icons.automirrored.outlined.Backspace
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.material.icons.outlined.KeyboardHide
|
||||
import androidx.compose.material.icons.outlined.SwapHoriz
|
||||
import androidx.compose.material3.ElevatedButton
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
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.ui.ExperimentalComposeUiApi
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.scale
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.FocusState
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusChanged
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.LocalConfiguration
|
||||
import androidx.compose.ui.platform.LocalTextInputService
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
|
||||
@Composable
|
||||
fun KeyBoardView(viewModel: IKeyBoardViewModel) {
|
||||
KeyboardView(
|
||||
viewModel.currentScoreA,
|
||||
viewModel.currentScoreB,
|
||||
viewModel.requestFocusA,
|
||||
viewModel.requestFocusB,
|
||||
viewModel.isValidRound,
|
||||
viewModel.isAFocused,
|
||||
viewModel.isBFocused,
|
||||
{ viewModel.updateFocusStateA(it) },
|
||||
{ viewModel.updateFocusStateB(it) },
|
||||
{ viewModel.digitClicked(it) },
|
||||
{ viewModel.addSub100Clicked(it) },
|
||||
{ viewModel.negateClicked() },
|
||||
{ viewModel.submitClicked() },
|
||||
{ viewModel.hideKeyboard() },
|
||||
{ viewModel.swapInputScores() },
|
||||
{ viewModel.deleteState(it) }
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalComposeUiApi::class)
|
||||
@Composable
|
||||
fun KeyboardView(
|
||||
scoreA: String,
|
||||
scoreB: String,
|
||||
requestFocus: FocusRequester,
|
||||
enableSubmit: Boolean,
|
||||
requestFocusA: FocusRequester,
|
||||
requestFocusB: FocusRequester,
|
||||
isValidScore: Boolean,
|
||||
focusStateA: Boolean,
|
||||
focusStateB: Boolean,
|
||||
updateFocusStateA: (Boolean) -> Unit,
|
||||
updateFocusStateB: (Boolean) -> Unit,
|
||||
digitClicked: (String) -> Unit,
|
||||
addSub100Clicked: (Int) -> Unit,
|
||||
deleteClicked: () -> Unit,
|
||||
negateClicked: () -> Unit,
|
||||
submitClicked: () -> Unit
|
||||
submitClicked: () -> Unit,
|
||||
hideKeyboardClicked: () -> Unit,
|
||||
onSwapClicked: () -> Unit,
|
||||
deleteButtonPressedState: (Boolean) -> Unit
|
||||
) {
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
|
||||
Column {
|
||||
Row {
|
||||
Row(Modifier.height(IntrinsicSize.Max)) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
CenteredTextField(
|
||||
scoreA,
|
||||
"0",
|
||||
Modifier
|
||||
.focusRequester(requestFocus)
|
||||
.onFocusChanged {
|
||||
keyboardController?.hide()
|
||||
updateFocusStateA(it.isFocused)
|
||||
}
|
||||
)
|
||||
focusStateA,
|
||||
requestFocusA
|
||||
) { updateFocusStateA(it.isFocused) }
|
||||
|
||||
}
|
||||
Surface(
|
||||
Modifier
|
||||
.wrapContentWidth()
|
||||
.fillMaxHeight(),
|
||||
tonalElevation = 3.dp,
|
||||
shape = MaterialTheme.shapes.extraSmall
|
||||
) {
|
||||
Column {
|
||||
IconButton(onClick = onSwapClicked, enabled = isValidScore) {
|
||||
Icon(Icons.Outlined.SwapHoriz, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
|
||||
CenteredTextField(
|
||||
scoreB,
|
||||
"0",
|
||||
Modifier
|
||||
.onFocusChanged {
|
||||
keyboardController?.hide()
|
||||
focusStateB,
|
||||
requestFocusB
|
||||
) {
|
||||
updateFocusStateB(it.isFocused)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Row {
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardTextButton("1") {
|
||||
@@ -129,16 +191,23 @@ fun KeyboardView(
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardIconButton(Icons.Outlined.Backspace) {
|
||||
deleteClicked()
|
||||
}
|
||||
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val deletePressed by interactionSource.collectIsPressedAsState()
|
||||
|
||||
deleteButtonPressedState(deletePressed)
|
||||
|
||||
KeyboardIconButton(
|
||||
icon = Icons.AutoMirrored.Outlined.Backspace,
|
||||
interactionSource = interactionSource
|
||||
) {}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardTextButton("+/-") {
|
||||
negateClicked()
|
||||
KeyboardIconButton(Icons.Outlined.KeyboardHide) {
|
||||
hideKeyboardClicked()
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
@@ -146,8 +215,14 @@ fun KeyboardView(
|
||||
digitClicked("0")
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(2f)) {
|
||||
KeyboardIconButton(Icons.Outlined.Check, enableSubmit) {
|
||||
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardTextButton("+/-") {
|
||||
negateClicked()
|
||||
}
|
||||
}
|
||||
Column(Modifier.weight(1f)) {
|
||||
KeyboardIconButton(Icons.Outlined.Check, isValidScore) {
|
||||
submitClicked()
|
||||
}
|
||||
}
|
||||
@@ -157,19 +232,42 @@ fun KeyboardView(
|
||||
|
||||
@Composable
|
||||
fun KeyboardTextButton(text: String, onClicked: () -> Unit) {
|
||||
|
||||
val configuration = LocalConfiguration.current
|
||||
|
||||
val screenWidth = configuration.screenWidthDp.dp
|
||||
|
||||
val style = if (screenWidth < 350.dp) {
|
||||
MaterialTheme.typography.labelSmall
|
||||
} else {
|
||||
MaterialTheme.typography.labelLarge
|
||||
}
|
||||
|
||||
ElevatedButton(
|
||||
modifier = Modifier.fillMaxWidth().height(50.dp).padding(2.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
.padding(2.dp),
|
||||
onClick = { onClicked() },
|
||||
) { Text(text) }
|
||||
) { Text(text, style = style) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun KeyboardIconButton(icon: ImageVector, enabled: Boolean = true, onClicked: () -> Unit) {
|
||||
fun KeyboardIconButton(
|
||||
icon: ImageVector,
|
||||
enabled: Boolean = true,
|
||||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
|
||||
onClicked: () -> Unit
|
||||
) {
|
||||
|
||||
ElevatedButton(
|
||||
onClick = { onClicked() },
|
||||
modifier = Modifier.fillMaxWidth().height(50.dp).padding(2.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
.padding(2.dp),
|
||||
enabled = enabled,
|
||||
interactionSource = interactionSource
|
||||
) {
|
||||
Icon(
|
||||
icon,
|
||||
@@ -178,28 +276,70 @@ fun KeyboardIconButton(icon: ImageVector, enabled: Boolean = true, onClicked: ()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun CenteredTextField(
|
||||
value: String,
|
||||
placeholder: String,
|
||||
modifier: Modifier,
|
||||
focused: Boolean,
|
||||
focusRequester: FocusRequester? = null,
|
||||
onFocusStateChanged: (FocusState) -> Unit
|
||||
) {
|
||||
|
||||
val modifier = if (focusRequester != null) {
|
||||
Modifier.focusRequester(focusRequester)
|
||||
} else {
|
||||
Modifier
|
||||
}
|
||||
|
||||
Box(contentAlignment = Alignment.Center) {
|
||||
CompositionLocalProvider(LocalTextInputService provides null) {
|
||||
TextField(
|
||||
value = value,
|
||||
onValueChange = { },
|
||||
placeholder = {
|
||||
if (!focused) {
|
||||
Text(
|
||||
placeholder,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
}
|
||||
},
|
||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||
singleLine = true,
|
||||
readOnly = true,
|
||||
modifier = modifier.fillMaxWidth()
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.onFocusChanged {
|
||||
onFocusStateChanged(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (focused) {
|
||||
val cursorColor = MaterialTheme.colorScheme.onSurface
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "blinkingCursor")
|
||||
val alpha by infiniteTransition.animateFloat(
|
||||
0f,
|
||||
cursorColor.alpha,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(500),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
), label = "blinkingCursor"
|
||||
)
|
||||
Row {
|
||||
|
||||
Text(text = value, color = cursorColor.copy(alpha = 0f))
|
||||
HorizontalDivider(
|
||||
modifier = Modifier
|
||||
.padding(start = 3.dp, top = 15.dp, bottom = 15.dp)
|
||||
.width(1.dp)
|
||||
.fillMaxHeight(),
|
||||
color = cursorColor.copy(alpha = alpha)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -210,17 +350,22 @@ fun KeyboardViewPreview() {
|
||||
AppTheme {
|
||||
Surface {
|
||||
KeyboardView(
|
||||
"",
|
||||
"350",
|
||||
"10",
|
||||
"190",
|
||||
FocusRequester(),
|
||||
false,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
{})
|
||||
FocusRequester(),
|
||||
isValidScore = false,
|
||||
focusStateA = true,
|
||||
focusStateB = false,
|
||||
updateFocusStateA = {},
|
||||
updateFocusStateB = {},
|
||||
digitClicked = {},
|
||||
addSub100Clicked = {},
|
||||
negateClicked = {},
|
||||
submitClicked = {},
|
||||
hideKeyboardClicked = {},
|
||||
onSwapClicked = {},
|
||||
deleteButtonPressedState = {})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@@ -18,7 +17,7 @@ import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.Round
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
|
||||
@Composable
|
||||
@@ -28,7 +27,7 @@ fun RoundListView(rounds: List<Round>, modifier: Modifier) {
|
||||
|
||||
LazyColumn(state = lazyListState, modifier = modifier) {
|
||||
itemsIndexed(rounds) { index, item ->
|
||||
RoundListItem(item, index, lazyListState)
|
||||
RoundListItem(item, index)
|
||||
}
|
||||
|
||||
scope.launch {
|
||||
@@ -38,7 +37,7 @@ fun RoundListView(rounds: List<Round>, modifier: Modifier) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun RoundListItem(round: Round, index: Int, lazyListState: LazyListState) {
|
||||
private fun RoundListItem(round: Round, index: Int) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -51,7 +50,7 @@ private fun RoundListItem(round: Round, index: Int, lazyListState: LazyListState
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
Text(
|
||||
text = index.toString(),
|
||||
text = (index + 1).toString(),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
modifier = Modifier.weight(1f),
|
||||
textAlign = TextAlign.Center
|
||||
|
||||
@@ -1,39 +1,57 @@
|
||||
package me.zobrist.tichucounter.ui.counter
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.*
|
||||
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.surfaceColorAtElevation
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
import me.zobrist.tichucounter.ui.composables.TypeaheadTextField
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TeamNamesView(
|
||||
nameA: String,
|
||||
nameB: String,
|
||||
nameSuggestionsA: List<String>,
|
||||
nameSuggestionsB: List<String>,
|
||||
updateA: (String) -> Unit,
|
||||
updateB: (String) -> Unit
|
||||
) {
|
||||
Row() {
|
||||
TextField(
|
||||
value = nameA,
|
||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||
onValueChange = { updateA(it) },
|
||||
singleLine = true,
|
||||
modifier = Modifier.weight(1f)
|
||||
|
||||
val containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(1.dp)
|
||||
val color = TextFieldDefaults.colors(
|
||||
focusedContainerColor = containerColor,
|
||||
unfocusedContainerColor = containerColor,
|
||||
disabledContainerColor = containerColor,
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = nameB,
|
||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center),
|
||||
onValueChange = { updateB(it) },
|
||||
singleLine = true,
|
||||
modifier = Modifier.weight(1f)
|
||||
Row {
|
||||
|
||||
TypeaheadTextField(
|
||||
value = nameA,
|
||||
items = nameSuggestionsA,
|
||||
onValueChange = { updateA(it) },
|
||||
modifier = Modifier.weight(1f),
|
||||
colors = color,
|
||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center)
|
||||
)
|
||||
|
||||
TypeaheadTextField(
|
||||
value = nameB,
|
||||
items = nameSuggestionsB,
|
||||
onValueChange = { updateB(it) },
|
||||
modifier = Modifier.weight(1f),
|
||||
colors = color,
|
||||
textStyle = LocalTextStyle.current.copy(textAlign = TextAlign.Center)
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +60,6 @@ fun TeamNamesView(
|
||||
@Composable
|
||||
private fun TeamNamesViewPreview() {
|
||||
AppTheme {
|
||||
TeamNamesView("TeamA", "TeamB", {}, {})
|
||||
TeamNamesView("TeamA", "TeamB", listOf("Test1", "Test3"), listOf("Test3", "Test5"), {}, {})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.ElevatedCard
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
@@ -19,8 +20,8 @@ import me.zobrist.tichucounter.ui.AppTheme
|
||||
@Composable
|
||||
fun TeamScoresView(scoreA: Int, scoreB: Int) {
|
||||
|
||||
ElevatedCard() {
|
||||
Row() {
|
||||
ElevatedCard(elevation = CardDefaults.elevatedCardElevation(3.dp)) {
|
||||
Row {
|
||||
Text(
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
text = scoreA.toString(),
|
||||
|
||||
@@ -1,78 +1,372 @@
|
||||
package me.zobrist.tichucounter.ui.history
|
||||
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
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.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
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.RestartAlt
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Card
|
||||
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.SwipeToDismissBox
|
||||
import androidx.compose.material3.SwipeToDismissBoxValue
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.rememberSwipeToDismissBoxState
|
||||
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.TopEnd
|
||||
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.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.data.GameAndScore
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.R
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
import me.zobrist.tichucounter.data.entity.Game
|
||||
import me.zobrist.tichucounter.data.entity.Round
|
||||
import me.zobrist.tichucounter.domain.getTotalPoints
|
||||
import java.text.DateFormat
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
|
||||
|
||||
@Composable
|
||||
fun HistoryList(viewModel: HistoryViewModel) {
|
||||
HistoryList(viewModel.gameAndHistory)
|
||||
fun HistoryList(
|
||||
viewModel: HistoryViewModel,
|
||||
snackbarHostState: SnackbarHostState,
|
||||
navigateToCalculator: () -> Unit,
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val lazyListState = rememberLazyListState()
|
||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||
|
||||
|
||||
DeleteConfirmDialog(showDeleteDialog) {
|
||||
showDeleteDialog = false
|
||||
if (it) {
|
||||
viewModel.deleteAllInactiveGames()
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
games = viewModel.gameAndHistory,
|
||||
onOpenClicked = {
|
||||
scope.launch {
|
||||
viewModel.activateGame(it)
|
||||
lazyListState.animateScrollToItem(0)
|
||||
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = activatedMessage,
|
||||
actionLabel = activatedActionLabel,
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
|
||||
if (result == SnackbarResult.ActionPerformed) {
|
||||
navigateToCalculator()
|
||||
}
|
||||
}
|
||||
},
|
||||
onDeleteClicked = {
|
||||
scope.launch {
|
||||
viewModel.deleteGame(it)
|
||||
|
||||
snackbarHostState.currentSnackbarData?.dismiss()
|
||||
val result = snackbarHostState.showSnackbar(
|
||||
message = deletedMessage,
|
||||
actionLabel = deletedActionLabel,
|
||||
duration = SnackbarDuration.Short
|
||||
)
|
||||
|
||||
if (result == SnackbarResult.Dismissed) {
|
||||
viewModel.deleteGame(it)
|
||||
} else {
|
||||
viewModel.restoreLastDeletedGame()
|
||||
}
|
||||
}
|
||||
},
|
||||
onDeleteAllClicked = { showDeleteDialog = true },
|
||||
lazyListState = lazyListState
|
||||
)
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun HistoryList(games: List<GameAndScore>) {
|
||||
LazyColumn {
|
||||
items(games) {
|
||||
HistoryListItem(it)
|
||||
fun DeleteConfirmDialog(show: Boolean = true, onExecuted: (Boolean) -> Unit = {}) {
|
||||
if (show) {
|
||||
|
||||
AlertDialog(
|
||||
onDismissRequest = { onExecuted(false) },
|
||||
dismissButton = {
|
||||
TextButton({ onExecuted(false) }) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton({ onExecuted(true) }) {
|
||||
Text(stringResource(R.string.ok))
|
||||
}
|
||||
},
|
||||
title = { Text(stringResource(R.string.delete_inactive_title)) },
|
||||
text = { Text(stringResource(R.string.delete_inactive_text)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun HistoryList(
|
||||
games: List<GameWithScores>,
|
||||
onOpenClicked: (gameId: Long) -> Unit,
|
||||
onDeleteClicked: (gameId: Long) -> Unit,
|
||||
onDeleteAllClicked: () -> Unit,
|
||||
lazyListState: LazyListState = LazyListState(),
|
||||
) {
|
||||
Row {
|
||||
LazyColumn(state = lazyListState) {
|
||||
items(
|
||||
items = games,
|
||||
key = { it.hashCode() }) {
|
||||
if (it.game.active) {
|
||||
HistoryListItem(
|
||||
it,
|
||||
Modifier
|
||||
.animateItemPlacement()
|
||||
.padding(2.dp)
|
||||
)
|
||||
} else {
|
||||
DismissibleHistoryListItem(
|
||||
it,
|
||||
Modifier.animateItemPlacement(),
|
||||
onOpenClicked,
|
||||
onDeleteClicked
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
Button(enabled = games.count() > 1,
|
||||
modifier = Modifier
|
||||
.padding(start = 4.dp, end = 4.dp, top = 10.dp)
|
||||
.align(CenterVertically)
|
||||
.fillMaxWidth()
|
||||
.animateItemPlacement(),
|
||||
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 =
|
||||
rememberSwipeToDismissBoxState(positionalThreshold = { with(density) { 100.dp.toPx() } },
|
||||
|
||||
confirmValueChange = {
|
||||
if (it == SwipeToDismissBoxValue.EndToStart) {
|
||||
onDeleteClicked(game.game.uid)
|
||||
}
|
||||
if (it == SwipeToDismissBoxValue.StartToEnd) {
|
||||
onOpenClicked(game.game.uid)
|
||||
}
|
||||
true
|
||||
})
|
||||
|
||||
SwipeToDismissBox(
|
||||
modifier = modifier,
|
||||
state = dismissState,
|
||||
enableDismissFromEndToStart = true,
|
||||
enableDismissFromStartToEnd = true,
|
||||
backgroundContent = {
|
||||
ItemBackground(dismissState.targetValue)
|
||||
}, content = {
|
||||
HistoryListItem(game = game, modifier = Modifier.padding(2.dp))
|
||||
})
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun ItemBackground(
|
||||
dismissBoxValue: SwipeToDismissBoxValue
|
||||
) {
|
||||
val backgroundColor by animateColorAsState(
|
||||
when (dismissBoxValue) {
|
||||
SwipeToDismissBoxValue.EndToStart -> MaterialTheme.colorScheme.error
|
||||
SwipeToDismissBoxValue.StartToEnd -> MaterialTheme.colorScheme.primary
|
||||
else -> MaterialTheme.colorScheme.background
|
||||
|
||||
}, label = ""
|
||||
)
|
||||
val textColor by animateColorAsState(
|
||||
when (dismissBoxValue) {
|
||||
SwipeToDismissBoxValue.EndToStart -> MaterialTheme.colorScheme.onError
|
||||
SwipeToDismissBoxValue.StartToEnd -> MaterialTheme.colorScheme.onPrimary
|
||||
else -> MaterialTheme.colorScheme.onBackground
|
||||
|
||||
}, label = ""
|
||||
)
|
||||
val scale by animateFloatAsState(
|
||||
if (dismissBoxValue == SwipeToDismissBoxValue.Settled) 0.75f else 1f, label = ""
|
||||
)
|
||||
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = 2.dp, bottom = 2.dp)
|
||||
.background(backgroundColor)
|
||||
.padding(horizontal = 10.dp),
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.align(Alignment.CenterStart)
|
||||
) {
|
||||
Icon(
|
||||
Icons.Outlined.RestartAlt,
|
||||
contentDescription = null,
|
||||
tint = textColor,
|
||||
modifier = Modifier.scale(scale),
|
||||
)
|
||||
Text(text = stringResource(id = R.string.continue_play), color = textColor)
|
||||
}
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.align(Alignment.CenterEnd)
|
||||
|
||||
) {
|
||||
Icon(
|
||||
Icons.Outlined.Delete,
|
||||
contentDescription = null,
|
||||
tint = textColor,
|
||||
modifier = Modifier.scale(scale),
|
||||
)
|
||||
Text(text = stringResource(id = R.string.delete), color = textColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Preview
|
||||
@Composable
|
||||
fun HistoryListItem(game: GameAndScore) {
|
||||
private fun BackgroundPreview() {
|
||||
Column {
|
||||
Box(modifier = Modifier.height(60.dp))
|
||||
{
|
||||
ItemBackground(SwipeToDismissBoxValue.Settled)
|
||||
}
|
||||
Box(modifier = Modifier.height(60.dp))
|
||||
{
|
||||
ItemBackground(SwipeToDismissBoxValue.EndToStart)
|
||||
}
|
||||
Box(modifier = Modifier.height(60.dp))
|
||||
{
|
||||
ItemBackground(SwipeToDismissBoxValue.StartToEnd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun HistoryListItem(
|
||||
game: GameWithScores, modifier: Modifier = Modifier
|
||||
) {
|
||||
val format =
|
||||
DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, Locale.getDefault())
|
||||
|
||||
val totalScores = game.getTotalPoints()
|
||||
|
||||
Card(
|
||||
modifier = Modifier
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(all = 4.dp),
|
||||
) {
|
||||
Column(
|
||||
Modifier
|
||||
.padding(all = 12.dp),
|
||||
Row(
|
||||
Modifier.padding(all = 12.dp)
|
||||
) {
|
||||
Row() {
|
||||
Box(modifier = modifier.fillMaxSize()) {
|
||||
Column {
|
||||
Text(
|
||||
text = game.nameA,
|
||||
text = game.game.nameA + " vs " + game.game.nameB,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
Text(
|
||||
text = game.scoreA.toString(),
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
text = totalScores.first.toString() + " : " + totalScores.second.toString(),
|
||||
style = MaterialTheme.typography.bodyLarge
|
||||
)
|
||||
}
|
||||
Row() {
|
||||
Spacer(modifier = Modifier.padding(5.dp))
|
||||
Text(
|
||||
text = game.nameB,
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
Text(
|
||||
text = game.scoreB.toString(),
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
}
|
||||
Row() {
|
||||
Text(
|
||||
text = format.format(game.modified),
|
||||
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
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.active),
|
||||
style = MaterialTheme.typography.labelSmall
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,12 +374,19 @@ fun HistoryListItem(game: GameAndScore) {
|
||||
@Preview
|
||||
@Composable
|
||||
private fun HistoryListPreview() {
|
||||
val tempData = listOf<GameAndScore>(
|
||||
GameAndScore(false, "abc", "def", Date(), Date(), 1, 10, 50),
|
||||
GameAndScore(true, "ADTH", "dogfg", Date(), Date(), 2, 20, 60),
|
||||
GameAndScore(false, "TeamA3", "TeamB3", Date(), Date(), 3, 30, 70),
|
||||
GameAndScore(false, "TeamA4", "TeamB4", Date(), Date(), 4, 40, 80),
|
||||
GameAndScore(false, "TeamA5", "TeamB5", Date(), Date(), 5, 50, 90)
|
||||
val tempData = listOf(
|
||||
GameWithScores(
|
||||
Game(true, "abcsdf sdaf asdf sdf ", "defsadf asdf sadf ", Date(), Date()),
|
||||
listOf(Round(1, 550, 500))
|
||||
), GameWithScores(
|
||||
Game(false, "ADTH", "dogfg", Date(), Date()), listOf(Round(2, 20, 60))
|
||||
), GameWithScores(
|
||||
Game(false, "TeamA3 langer Name", "TeamB3", Date(), Date()), listOf(Round(3, 30, 70))
|
||||
), 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, {}, {}, {})
|
||||
}
|
||||
|
||||
@@ -7,24 +7,54 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import me.zobrist.tichucounter.data.GameAndScore
|
||||
import me.zobrist.tichucounter.data.GameDao
|
||||
import me.zobrist.tichucounter.data.GameWithScores
|
||||
import me.zobrist.tichucounter.repository.GameRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
|
||||
@HiltViewModel
|
||||
class HistoryViewModel @Inject constructor(
|
||||
private val gameDao: GameDao
|
||||
private val gameRepository: GameRepository
|
||||
) : ViewModel() {
|
||||
|
||||
var gameAndHistory by mutableStateOf(emptyList<GameAndScore>())
|
||||
var gameAndHistory by mutableStateOf(emptyList<GameWithScores>())
|
||||
private set
|
||||
|
||||
private var fullList: List<GameWithScores> = emptyList()
|
||||
|
||||
init {
|
||||
viewModelScope.launch {
|
||||
gameDao.getAllWithPoints().collect { games ->
|
||||
gameAndHistory = games
|
||||
|
||||
gameRepository.getAllWithRoundFlow().collect { games ->
|
||||
fullList =
|
||||
games.sortedBy { it.game.modified }.sortedBy { it.game.active }.reversed()
|
||||
gameAndHistory = fullList
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteGame(gameId: Long) {
|
||||
viewModelScope.launch {
|
||||
gameRepository.deleteGame(gameId)
|
||||
}
|
||||
}
|
||||
|
||||
fun restoreLastDeletedGame() {
|
||||
viewModelScope.launch {
|
||||
gameRepository.restoreLastDeletedGame()
|
||||
}
|
||||
}
|
||||
|
||||
fun activateGame(gameId: Long) {
|
||||
viewModelScope.launch {
|
||||
gameRepository.setActive(gameId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun deleteAllInactiveGames() {
|
||||
viewModelScope.launch {
|
||||
gameRepository.deleteAllInactive()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package me.zobrist.tichucounter.ui.layout
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.List
|
||||
import androidx.compose.material.icons.outlined.Calculate
|
||||
import androidx.compose.material.icons.outlined.Settings
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
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.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.R
|
||||
import me.zobrist.tichucounter.domain.DrawerItem
|
||||
import me.zobrist.tichucounter.domain.Route
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
|
||||
@Composable
|
||||
fun DrawerContent(
|
||||
drawerItems: List<DrawerItem>,
|
||||
selectedDrawerItem: DrawerItem,
|
||||
onElementClicked: (Route) -> Unit
|
||||
) {
|
||||
|
||||
ModalDrawerSheet {
|
||||
|
||||
Text(
|
||||
modifier = Modifier.padding(start = 10.dp, top = 10.dp),
|
||||
text = stringResource(R.string.app_name),
|
||||
style = MaterialTheme.typography.headlineSmall
|
||||
)
|
||||
HorizontalDivider(modifier = Modifier.padding(10.dp))
|
||||
|
||||
drawerItems.forEach { screen ->
|
||||
NavigationDrawerItem(
|
||||
icon = { Icon(screen.menuIcon, contentDescription = null) },
|
||||
label = { Text(screen.menuName) },
|
||||
selected = screen == selectedDrawerItem,
|
||||
onClick = { onElementClicked(screen.route) },
|
||||
modifier = Modifier.padding(NavigationDrawerItemDefaults.ItemPadding)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||
@Composable
|
||||
fun DrawerContentPreview() {
|
||||
|
||||
val counter = DrawerItem(Route.COUNTER, Icons.Outlined.Calculate, "Counter")
|
||||
val history = DrawerItem(Route.HISTORY, Icons.AutoMirrored.Outlined.List, "History")
|
||||
val settings = DrawerItem(Route.SETTINGS, Icons.Outlined.Settings, "Settings")
|
||||
AppTheme {
|
||||
Surface {
|
||||
DrawerContent(
|
||||
listOf(counter, history, settings),
|
||||
counter
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package me.zobrist.tichucounter.ui.layout
|
||||
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import me.zobrist.tichucounter.domain.TopBarAction
|
||||
import me.zobrist.tichucounter.domain.TopBarState
|
||||
|
||||
@Composable
|
||||
fun TopBar(topBarState: TopBarState) {
|
||||
TopBar(
|
||||
topBarState.title,
|
||||
topBarState.icon,
|
||||
topBarState.onNavigate,
|
||||
topBarState.actions
|
||||
)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun TopBar(
|
||||
title: String,
|
||||
icon: ImageVector,
|
||||
navigateAction: () -> Unit,
|
||||
actions: List<TopBarAction>
|
||||
) {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
title,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { navigateAction() }) {
|
||||
Icon(
|
||||
imageVector = icon,
|
||||
contentDescription = "Localized description"
|
||||
)
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
actions.forEach {
|
||||
IconButton(onClick = { it.action() }, enabled = it.isActive) {
|
||||
Icon(
|
||||
imageVector = it.imageVector,
|
||||
contentDescription = null,
|
||||
)
|
||||
it.composeCode()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -2,12 +2,22 @@ package me.zobrist.tichucounter.ui.settings
|
||||
|
||||
import android.content.res.Configuration
|
||||
import androidx.compose.foundation.clickable
|
||||
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.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.ArrowDropDown
|
||||
import androidx.compose.material.icons.outlined.Check
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material3.Icon
|
||||
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.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
@@ -15,12 +25,15 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import me.zobrist.tichucounter.R
|
||||
import me.zobrist.tichucounter.domain.KeepScreenOn
|
||||
import me.zobrist.tichucounter.domain.Language
|
||||
import me.zobrist.tichucounter.domain.Theme
|
||||
import me.zobrist.tichucounter.ui.AppTheme
|
||||
import me.zobrist.tichucounter.ui.composables.DropDownMenu
|
||||
|
||||
|
||||
val languageMap = mapOf(
|
||||
Language.DEFAULT to R.string.android_default_text,
|
||||
Language.ENGLISH to R.string.english,
|
||||
Language.GERMAN to R.string.german
|
||||
)
|
||||
@@ -31,16 +44,19 @@ val themeMap = mapOf(
|
||||
Theme.LIGHT to R.string.light
|
||||
)
|
||||
|
||||
val victoryPointsList = listOf(500, 1000, 1500, 2000)
|
||||
|
||||
@Composable
|
||||
fun SettingsView(viewModel: SettingsViewModel) {
|
||||
SettingsView(
|
||||
viewModel.screenOn,
|
||||
viewModel.screenOn.value,
|
||||
viewModel.language,
|
||||
viewModel.theme,
|
||||
viewModel.victoryPoints,
|
||||
{ viewModel.updateScreenOn(it) },
|
||||
{ viewModel.updateLanguage(it) },
|
||||
{ viewModel.updateTheme(it) })
|
||||
{ viewModel.updateTheme(it) },
|
||||
{ viewModel.updateVictoryPoints(it) })
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -48,15 +64,26 @@ fun SettingsView(
|
||||
valueScreenOn: Boolean = true,
|
||||
valueLanguage: Language = Language.ENGLISH,
|
||||
valueTheme: Theme = Theme.DARK,
|
||||
updateScreenOn: (Boolean) -> Unit = {},
|
||||
valueVictoryPoints: Int = 1000,
|
||||
updateScreenOn: (KeepScreenOn) -> 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(
|
||||
stringResource(R.string.keep_screen_on),
|
||||
valueScreenOn
|
||||
) { updateScreenOn(it) }
|
||||
) { updateScreenOn(if (it) KeepScreenOn.ON else KeepScreenOn.OFF) }
|
||||
|
||||
StringSetting(
|
||||
stringResource(R.string.choose_language_text),
|
||||
@@ -69,16 +96,27 @@ fun SettingsView(
|
||||
themeMap,
|
||||
valueTheme,
|
||||
) { updateTheme(it) }
|
||||
|
||||
Text(
|
||||
text = stringResource(R.string.game),
|
||||
style = MaterialTheme.typography.headlineMedium
|
||||
)
|
||||
|
||||
|
||||
ListSetting(
|
||||
stringResource(R.string.victory_points),
|
||||
victoryPointsList,
|
||||
valueVictoryPoints
|
||||
) { updateVictoryPoints(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun BooleanSetting(name: String, value: Boolean, updateValue: (Boolean) -> Unit) {
|
||||
|
||||
Row(
|
||||
Modifier
|
||||
.padding(20.dp)
|
||||
.padding(bottom = 15.dp, top = 5.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Column(Modifier.weight(5f)) {
|
||||
@@ -107,16 +145,32 @@ fun BooleanSetting(name: String, value: Boolean, updateValue: (Boolean) -> Unit)
|
||||
@Composable
|
||||
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) }
|
||||
|
||||
Row(
|
||||
Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(20.dp)
|
||||
.padding(bottom = 15.dp, top = 5.dp)
|
||||
.clickable { expanded = true }) {
|
||||
Column(Modifier.weight(5f)) {
|
||||
Text(name, style = MaterialTheme.typography.bodyLarge, overflow = TextOverflow.Ellipsis)
|
||||
Text(stringResource(map[selected]!!), style = MaterialTheme.typography.labelLarge)
|
||||
Text(
|
||||
selected.toString(),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
)
|
||||
}
|
||||
|
||||
Column(Modifier.weight(1f)) {
|
||||
@@ -125,36 +179,27 @@ fun <T> StringSetting(name: String, map: Map<T, Int>, selected: T, onSelected: (
|
||||
contentDescription = null,
|
||||
modifier = Modifier.align(End)
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = expanded,
|
||||
onDismissRequest = { expanded = false }
|
||||
DropDownMenu(
|
||||
list,
|
||||
selected,
|
||||
expanded,
|
||||
) {
|
||||
map.forEach {
|
||||
DropdownMenuItem(
|
||||
onClick = {
|
||||
onSelected(it.key)
|
||||
expanded = false
|
||||
},
|
||||
text = { Text(stringResource(it.value)) },
|
||||
trailingIcon = {
|
||||
if (it.key == selected) {
|
||||
Icon(Icons.Outlined.Check, contentDescription = null)
|
||||
}
|
||||
})
|
||||
it?.let { onSelected(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Preview(name = "Light Mode")
|
||||
@Preview(name = "Dark Mode", uiMode = Configuration.UI_MODE_NIGHT_YES, showBackground = true)
|
||||
@Composable
|
||||
fun SettingsViewPreview() {
|
||||
|
||||
AppTheme() {
|
||||
Surface() {
|
||||
AppTheme {
|
||||
Surface {
|
||||
SettingsView()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package me.zobrist.tichucounter.ui.settings
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import me.zobrist.tichucounter.domain.KeepScreenOn
|
||||
import me.zobrist.tichucounter.domain.Language
|
||||
import me.zobrist.tichucounter.domain.SettingsAdapter
|
||||
import me.zobrist.tichucounter.domain.Theme
|
||||
@@ -14,28 +16,35 @@ import javax.inject.Inject
|
||||
class SettingsViewModel @Inject constructor(private val settings: SettingsAdapter) : ViewModel() {
|
||||
|
||||
|
||||
var language by mutableStateOf(settings.language)
|
||||
var language by mutableStateOf(settings.language.value)
|
||||
private set
|
||||
|
||||
var theme by mutableStateOf(settings.theme)
|
||||
var theme by mutableStateOf(settings.theme.value)
|
||||
private set
|
||||
|
||||
var screenOn by mutableStateOf(false)
|
||||
var screenOn by mutableStateOf(settings.keepScreenOn.value)
|
||||
private set
|
||||
|
||||
var victoryPoints by mutableIntStateOf(settings.victoryPoints.value)
|
||||
private set
|
||||
|
||||
fun updateLanguage(language: Language) {
|
||||
settings.setLanguage(language)
|
||||
this.language = settings.language
|
||||
settings.language.value = language
|
||||
this.language = language
|
||||
}
|
||||
|
||||
fun updateTheme(theme: Theme) {
|
||||
settings.setTheme(theme)
|
||||
this.theme = settings.theme
|
||||
settings.theme.value = theme
|
||||
this.theme = theme
|
||||
}
|
||||
|
||||
fun updateScreenOn(value: Boolean) {
|
||||
settings.setKeepScreenOn(value)
|
||||
screenOn = settings.keepScreenOn
|
||||
fun updateScreenOn(value: KeepScreenOn) {
|
||||
settings.keepScreenOn.value = value
|
||||
screenOn = value
|
||||
}
|
||||
|
||||
fun updateVictoryPoints(value: Int) {
|
||||
settings.victoryPoints.value = value
|
||||
victoryPoints = value
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6zm16,-4H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-8,12.5v-9l6,4.5 -6,4.5z" />
|
||||
</vector>
|
||||
@@ -1,10 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/primaryColor"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:autoMirrored="true"
|
||||
android:tint="#FFFFFF"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/primaryColor"
|
||||
android:pathData="M12.5,8c-2.65,0 -5.05,0.99 -6.9,2.6L2,7v9h9l-3.62,-3.62c1.39,-1.16 3.16,-1.88 5.12,-1.88 3.54,0 6.55,2.31 7.6,5.5l2.37,-0.78C21.08,11.03 17.15,8 12.5,8z" />
|
||||
</vector>
|
||||
54
app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="50.684"
|
||||
android:viewportHeight="39.77">
|
||||
<group
|
||||
android:scaleX="0.46444446"
|
||||
android:scaleY="0.36443365"
|
||||
android:translateX="13.572049"
|
||||
android:translateY="12.638237">
|
||||
<path
|
||||
android:fillColor="#ffff00"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#ffff00"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
</group>
|
||||
</vector>
|
||||
@@ -1,9 +0,0 @@
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<gradient
|
||||
android:angle="135"
|
||||
android:centerColor="#009688"
|
||||
android:endColor="#00695C"
|
||||
android:startColor="#4DB6AC"
|
||||
android:type="linear" />
|
||||
</shape>
|
||||
48
app/src/main/res/drawable/tichu_logo.xml
Normal file
@@ -0,0 +1,48 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="50.684dp"
|
||||
android:height="39.77dp"
|
||||
android:viewportWidth="50.684"
|
||||
android:viewportHeight="39.77">
|
||||
<path
|
||||
android:fillColor="#ffff00"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#ffff00"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
<path
|
||||
android:fillColor="#000000"
|
||||
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:strokeColor="#000000"
|
||||
android:strokeLineCap="butt"
|
||||
android:strokeLineJoin="miter" />
|
||||
</vector>
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@color/ic_launcher_background" />
|
||||
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.4 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.4 KiB |
|
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 14 KiB |
@@ -1,29 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="clear">Neues Spiel starten</string>
|
||||
<string name="undo">Letzte Runde löschen</string>
|
||||
<string name="choose_theme_text">Theme auswählen</string>
|
||||
<string name="keep_screen_on">Bildschirm eingeschaltet lassen</string>
|
||||
<string name="confirmNew">Möchten Sie wirklich ein neues Spiel starten?</string>
|
||||
<string name="yes">Ja</string>
|
||||
<string name="no">Nein</string>
|
||||
<string name="back">Zurück</string>
|
||||
<string name="choose_language_text">Sprache wählen</string>
|
||||
<string name="android_default_text">Android Standard</string>
|
||||
<string name="english">Englisch</string>
|
||||
<string name="german">Deutsch</string>
|
||||
<string name="light">Hell</string>
|
||||
<string name="dark">Dunkel</string>
|
||||
<string name="settings">Einstellungen</string>
|
||||
<string name="display">Anzeige</string>
|
||||
<string name="activate">Aktivieren</string>
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="menu_history">Verlauf</string>
|
||||
<string name="menu_settings">Einstellungen</string>
|
||||
<string name="menu_counter">Counter</string>
|
||||
<string name="submit">Übermitteln</string>
|
||||
<string name="on">Ein</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_text">Wirklich den gesamten Verlauf löschen? Diese Aktion kann nicht rückgängig gemacht werden.</string>
|
||||
<string name="cancel">Abbrechen</string>
|
||||
<string name="ok">Ok</string>
|
||||
<string name="delete">Löschen</string>
|
||||
<string name="deleteAll">Alle löschen</string>
|
||||
<string name="active">Aktives Spiel</string>
|
||||
<string name="inactive">Vergangene Spiele</string>
|
||||
<string name="menu_counter">Counter</string>
|
||||
<string name="menu_about">About</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>
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">48dp</dimen>
|
||||
</resources>
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">200dp</dimen>
|
||||
</resources>
|
||||
@@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">48dp</dimen>
|
||||
</resources>
|
||||
@@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="primaryColor">#d50000</color>
|
||||
<color name="primaryLightColor">#ff5131</color>
|
||||
<color name="primaryDarkColor">#9b0000</color>
|
||||
<color name="secondaryColor">#ffccbc</color>
|
||||
<color name="secondaryLightColor">#ffffee</color>
|
||||
<color name="secondaryDarkColor">#cb9b8c</color>
|
||||
<color name="primaryTextColor">#ffffff</color>
|
||||
<color name="secondaryTextColor">#000000</color>
|
||||
|
||||
</resources>
|
||||
@@ -1,9 +0,0 @@
|
||||
<resources>
|
||||
<!-- Default screen margins, per the Android Design guidelines. -->
|
||||
<dimen name="activity_horizontal_margin">16dp</dimen>
|
||||
<dimen name="activity_vertical_margin">16dp</dimen>
|
||||
<dimen name="nav_header_vertical_spacing">8dp</dimen>
|
||||
<dimen name="nav_header_height">176dp</dimen>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
<dimen name="text_margin">16dp</dimen>
|
||||
</resources>
|
||||
@@ -1,8 +0,0 @@
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item name="ic_menu_camera" type="drawable">@android:drawable/ic_menu_camera</item>
|
||||
<item name="ic_menu_gallery" type="drawable">@android:drawable/ic_menu_gallery</item>
|
||||
<item name="ic_menu_slideshow" type="drawable">@android:drawable/ic_menu_slideshow</item>
|
||||
<item name="ic_menu_manage" type="drawable">@android:drawable/ic_menu_manage</item>
|
||||
<item name="ic_menu_share" type="drawable">@android:drawable/ic_menu_share</item>
|
||||
<item name="ic_menu_send" type="drawable">@android:drawable/ic_menu_send</item>
|
||||
</resources>
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="ic_launcher_background">@color/primaryColor</color>
|
||||
<color name="ic_launcher_background">#DC0E00</color>
|
||||
</resources>
|
||||
@@ -1,34 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name" translatable="false">Tichu Counter</string>
|
||||
<string name="team_a" translatable="false">Team A</string>
|
||||
<string name="team_b" translatable="false">Team B</string>
|
||||
<string name="title_activity_settings" translatable="false">SettingsActivity</string>
|
||||
|
||||
<string name="clear">Start new game</string>
|
||||
<string name="undo">Undo last round</string>
|
||||
<string name="choose_theme_text">Choose theme</string>
|
||||
<string name="keep_screen_on">Keep screen on</string>
|
||||
<string name="confirmNew">Do you really want to start a new Game?</string>
|
||||
<string name="yes">Yes</string>
|
||||
<string name="no">No</string>
|
||||
<string name="back">Back</string>
|
||||
<string name="choose_language_text">Choose language</string>
|
||||
<string name="android_default_text">Android Default</string>
|
||||
<string name="english">English</string>
|
||||
<string name="german">German</string>
|
||||
<string name="light">Light</string>
|
||||
<string name="dark">Dark</string>
|
||||
<string name="display">Display</string>
|
||||
<string name="settings">Settings</string>
|
||||
|
||||
<string name="menu_counter">Counter</string>
|
||||
<string name="menu_history">History</string>
|
||||
<string name="menu_settings">Settings</string>
|
||||
<string name="activate">Activate</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="submit">Submit</string>
|
||||
<string name="on">On</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_text">You really want to delete the history? This action can\'t be undone.</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="ok">OK</string>
|
||||
<string name="delete">Delete</string>
|
||||
<string name="deleteAll">Delete all</string>
|
||||
<string name="active">Current Game</string>
|
||||
<string name="inactive">Old Games</string>
|
||||
<string name="menu_counter">Counter</string>
|
||||
<string name="menu_about">About</string>
|
||||
<string name="contact_us">Contact us</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>
|
||||
@@ -1,8 +1,5 @@
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar"></style>
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar" />
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.MaterialComponents.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light" />
|
||||
</resources>
|
||||
@@ -0,0 +1,22 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
import me.zobrist.tichucounter.domain.digitCount
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class StringExtensionTest {
|
||||
@Test
|
||||
fun calculation_isCorrect() {
|
||||
assertEquals(0, "-".digitCount())
|
||||
assertEquals(0, "".digitCount())
|
||||
assertEquals(2, "-10".digitCount())
|
||||
assertEquals(2, "10".digitCount())
|
||||
assertEquals(10, "1234567890".digitCount())
|
||||
assertEquals(10, "-1234567890".digitCount())
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.zobrist.tichucounter
|
||||
|
||||
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
|
||||
|
||||
/**
|
||||
|
||||
14
build.gradle
@@ -1,15 +1,12 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
buildscript {
|
||||
ext {
|
||||
compose_version = '1.1.1'
|
||||
}
|
||||
ext.kotlin_version = "1.7.20"
|
||||
ext.kotlin_version = "1.9.24"
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.4.0'
|
||||
classpath 'com.android.tools.build:gradle:8.5.2'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
@@ -18,8 +15,9 @@ buildscript {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id 'com.google.dagger.hilt.android' version '2.44' apply false
|
||||
id 'com.google.dagger.hilt.android' version '2.51.1' apply false
|
||||
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
|
||||
id 'com.google.devtools.ksp' version '1.9.24-1.0.20' apply false
|
||||
}
|
||||
|
||||
allprojects {
|
||||
@@ -28,7 +26,3 @@ allprojects {
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
@@ -19,3 +19,6 @@ android.useAndroidX=true
|
||||
android.enableJetifier=false
|
||||
# Kotlin code style for this project: "official" or "obsolete":
|
||||
kotlin.code.style=official
|
||||
android.defaults.buildfeatures.buildconfig=true
|
||||
android.nonTransitiveRClass=true
|
||||
android.nonFinalResIds=false
|
||||
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip
|
||||
|
||||