Makefile, linting, and formatting
This commit is contained in:
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.{json,yml,yaml}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
77
.gitattributes
vendored
Normal file
77
.gitattributes
vendored
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# Auto detect text files and perform LF normalization
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
# Source code files
|
||||||
|
*.swift text eol=lf
|
||||||
|
*.kt text eol=lf
|
||||||
|
*.kts text eol=lf
|
||||||
|
*.java text eol=lf
|
||||||
|
*.go text eol=lf
|
||||||
|
*.py text eol=lf
|
||||||
|
*.ts text eol=lf
|
||||||
|
*.tsx text eol=lf
|
||||||
|
*.js text eol=lf
|
||||||
|
*.jsx text eol=lf
|
||||||
|
*.mjs text eol=lf
|
||||||
|
*.cjs text eol=lf
|
||||||
|
|
||||||
|
# Configuration files
|
||||||
|
*.json text eol=lf
|
||||||
|
*.yml text eol=lf
|
||||||
|
*.yaml text eol=lf
|
||||||
|
*.toml text eol=lf
|
||||||
|
*.xml text eol=lf
|
||||||
|
*.plist text eol=lf
|
||||||
|
*.properties text eol=lf
|
||||||
|
*.gradle text eol=lf
|
||||||
|
*.md text eol=lf
|
||||||
|
|
||||||
|
# Shell scripts
|
||||||
|
*.sh text eol=lf
|
||||||
|
*.bash text eol=lf
|
||||||
|
*.zsh text eol=lf
|
||||||
|
|
||||||
|
# Windows batch files
|
||||||
|
*.bat text eol=crlf
|
||||||
|
*.cmd text eol=crlf
|
||||||
|
|
||||||
|
# Binary files
|
||||||
|
*.png binary
|
||||||
|
*.jpg binary
|
||||||
|
*.jpeg binary
|
||||||
|
*.gif binary
|
||||||
|
*.ico binary
|
||||||
|
*.webp binary
|
||||||
|
*.pdf binary
|
||||||
|
*.zip binary
|
||||||
|
*.tar binary
|
||||||
|
*.gz binary
|
||||||
|
*.jar binary
|
||||||
|
*.aar binary
|
||||||
|
*.apk binary
|
||||||
|
*.ipa binary
|
||||||
|
*.xcassets binary
|
||||||
|
*.ttf binary
|
||||||
|
*.otf binary
|
||||||
|
*.woff binary
|
||||||
|
*.woff2 binary
|
||||||
|
*.eot binary
|
||||||
|
|
||||||
|
# Xcode files
|
||||||
|
*.pbxproj merge=union
|
||||||
|
*.xcworkspacedata text eol=lf
|
||||||
|
*.xcscheme text eol=lf
|
||||||
|
|
||||||
|
# Gradle wrapper
|
||||||
|
gradlew text eol=lf
|
||||||
|
gradlew.bat text eol=crlf
|
||||||
|
gradle-wrapper.jar binary
|
||||||
|
|
||||||
|
# Lock files
|
||||||
|
*.lock text -diff
|
||||||
|
package-lock.json text -diff
|
||||||
|
pnpm-lock.yaml text -diff
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
LICENSE text eol=lf
|
||||||
|
README.md text eol=lf
|
||||||
46
.gitignore
vendored
46
.gitignore
vendored
@@ -9,6 +9,11 @@ local.properties
|
|||||||
# Log/OS Files
|
# Log/OS Files
|
||||||
*.log
|
*.log
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.DS_Store?
|
||||||
|
._*
|
||||||
|
.Spotlight-V100
|
||||||
|
.Trashes
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
# Android Studio generated files and folders
|
# Android Studio generated files and folders
|
||||||
captures/
|
captures/
|
||||||
@@ -34,3 +39,44 @@ google-services.json
|
|||||||
|
|
||||||
# Android Profiling
|
# Android Profiling
|
||||||
*.hprof
|
*.hprof
|
||||||
|
|
||||||
|
# iOS/Xcode
|
||||||
|
ios/build/
|
||||||
|
ios/DerivedData/
|
||||||
|
ios/*.xcuserstate
|
||||||
|
ios/**/xcuserdata/
|
||||||
|
ios/**/*.xcuserstate
|
||||||
|
*.xccheckout
|
||||||
|
*.moved-aside
|
||||||
|
*.pbxuser
|
||||||
|
!default.pbxuser
|
||||||
|
*.mode1v3
|
||||||
|
!default.mode1v3
|
||||||
|
*.mode2v3
|
||||||
|
!default.mode2v3
|
||||||
|
*.perspectivev3
|
||||||
|
!default.perspectivev3
|
||||||
|
*.hmap
|
||||||
|
*.ipa
|
||||||
|
*.dSYM.zip
|
||||||
|
*.dSYM
|
||||||
|
timeline.xctimeline
|
||||||
|
playground.xcworkspace
|
||||||
|
|
||||||
|
# CocoaPods
|
||||||
|
ios/Pods/
|
||||||
|
ios/Podfile.lock
|
||||||
|
|
||||||
|
# Swift Package Manager
|
||||||
|
ios/.swiftpm/
|
||||||
|
ios/Package.resolved
|
||||||
|
.build/
|
||||||
|
|
||||||
|
# fastlane
|
||||||
|
fastlane/report.xml
|
||||||
|
fastlane/Preview.html
|
||||||
|
fastlane/screenshots/**/*.png
|
||||||
|
fastlane/test_output
|
||||||
|
|
||||||
|
# Code Injection
|
||||||
|
iOSInjectionProject/
|
||||||
|
|||||||
90
Makefile
Normal file
90
Makefile
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Ascently Makefile
|
||||||
|
|
||||||
|
.PHONY: help android-lint android-format android-build android-test \
|
||||||
|
ios-lint ios-format ios-build ios-test clean
|
||||||
|
|
||||||
|
# Default target
|
||||||
|
help:
|
||||||
|
@echo "Ascently Dev Commands"
|
||||||
|
@echo "=============================="
|
||||||
|
@echo ""
|
||||||
|
@echo "Android:"
|
||||||
|
@echo " make android-lint: Run Detekt static analysis"
|
||||||
|
@echo " make android-format: Check code formatting with Spotless"
|
||||||
|
@echo " make android-format-fix: Auto-fix code formatting"
|
||||||
|
@echo " make android-build: Build debug APK"
|
||||||
|
@echo " make android-release: Build release APK"
|
||||||
|
@echo " make android-test: Run unit tests"
|
||||||
|
@echo ""
|
||||||
|
@echo "iOS:"
|
||||||
|
@echo " make ios-lint: Run SwiftLint"
|
||||||
|
@echo " make ios-lint-fix: Run SwiftLint with auto-fix"
|
||||||
|
@echo " make ios-format: Run SwiftFormat (dry-run)"
|
||||||
|
@echo " make ios-format-fix: Run SwiftFormat with auto-fix"
|
||||||
|
@echo " make ios-build: Build iOS app"
|
||||||
|
@echo ""
|
||||||
|
@echo "General:"
|
||||||
|
@echo " make lint: Run linters for both platforms"
|
||||||
|
@echo " make format: Check formatting for both platforms"
|
||||||
|
@echo " make clean: Clean build artifacts"
|
||||||
|
|
||||||
|
# Android commands
|
||||||
|
android-lint:
|
||||||
|
cd android && ./gradlew detekt
|
||||||
|
|
||||||
|
android-format:
|
||||||
|
cd android && ./gradlew spotlessCheck
|
||||||
|
|
||||||
|
android-format-fix:
|
||||||
|
cd android && ./gradlew spotlessApply
|
||||||
|
|
||||||
|
android-build:
|
||||||
|
cd android && ./gradlew assembleDebug
|
||||||
|
|
||||||
|
android-release:
|
||||||
|
cd android && ./gradlew assembleRelease
|
||||||
|
|
||||||
|
android-test:
|
||||||
|
cd android && ./gradlew test
|
||||||
|
|
||||||
|
# iOS commands (requires SwiftLint and SwiftFormat!!!)
|
||||||
|
ios-lint:
|
||||||
|
@if command -v swiftlint >/dev/null 2>&1; then \
|
||||||
|
cd ios && swiftlint; \
|
||||||
|
else \
|
||||||
|
echo "SwiftLint not installed. Install with: brew install swiftlint"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
ios-lint-fix:
|
||||||
|
@if command -v swiftlint >/dev/null 2>&1; then \
|
||||||
|
cd ios && swiftlint --fix; \
|
||||||
|
else \
|
||||||
|
echo "SwiftLint not installed. Install with: brew install swiftlint"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
ios-format:
|
||||||
|
@if command -v swiftformat >/dev/null 2>&1; then \
|
||||||
|
cd ios && swiftformat . --lint; \
|
||||||
|
else \
|
||||||
|
echo "SwiftFormat not installed. Install with: brew install swiftformat"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
ios-format-fix:
|
||||||
|
@if command -v swiftformat >/dev/null 2>&1; then \
|
||||||
|
cd ios && swiftformat .; \
|
||||||
|
else \
|
||||||
|
echo "SwiftFormat not installed. Install with: brew install swiftformat"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
ios-build:
|
||||||
|
cd ios && xcodebuild -project Ascently.xcodeproj -scheme Ascently -configuration Debug build
|
||||||
|
|
||||||
|
# Combined commands
|
||||||
|
lint: android-lint ios-lint
|
||||||
|
|
||||||
|
format: android-format ios-format
|
||||||
|
|
||||||
|
# Clean
|
||||||
|
clean:
|
||||||
|
cd android && ./gradlew clean
|
||||||
|
rm -rf ios/build ios/DerivedData
|
||||||
31
android/.editorconfig
Normal file
31
android/.editorconfig
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.{kt,kts}]
|
||||||
|
indent_size = 4
|
||||||
|
max_line_length = 220
|
||||||
|
ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
|
||||||
|
ktlint_standard_no-wildcard-imports = disabled
|
||||||
|
ktlint_standard_package-name = disabled
|
||||||
|
|
||||||
|
[*.{xml,gradle}]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[*.properties]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.toml]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
@@ -6,6 +6,8 @@ plugins {
|
|||||||
alias(libs.plugins.kotlin.compose)
|
alias(libs.plugins.kotlin.compose)
|
||||||
alias(libs.plugins.kotlin.serialization)
|
alias(libs.plugins.kotlin.serialization)
|
||||||
alias(libs.plugins.ksp)
|
alias(libs.plugins.ksp)
|
||||||
|
alias(libs.plugins.detekt)
|
||||||
|
alias(libs.plugins.spotless)
|
||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -16,8 +18,8 @@ android {
|
|||||||
applicationId = "com.atridad.ascently"
|
applicationId = "com.atridad.ascently"
|
||||||
minSdk = 31
|
minSdk = 31
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 48
|
versionCode = 49
|
||||||
versionName = "2.4.0"
|
versionName = "2.4.1"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -26,8 +28,8 @@ android {
|
|||||||
release {
|
release {
|
||||||
isMinifyEnabled = true
|
isMinifyEnabled = true
|
||||||
proguardFiles(
|
proguardFiles(
|
||||||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||||||
"proguard-rules.pro"
|
"proguard-rules.pro",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,7 @@ dependencies {
|
|||||||
implementation(libs.coil.compose)
|
implementation(libs.coil.compose)
|
||||||
|
|
||||||
// Health Connect
|
// Health Connect
|
||||||
implementation("androidx.health.connect:connect-client:1.1.0-alpha07")
|
implementation(libs.health.connect)
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
@@ -99,6 +101,51 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||||
debugImplementation(libs.androidx.ui.tooling)
|
debugImplementation(libs.androidx.ui.tooling)
|
||||||
debugImplementation(libs.androidx.ui.test.manifest)
|
debugImplementation(libs.androidx.ui.test.manifest)
|
||||||
debugImplementation(libs.androidx.ui.tooling)
|
}
|
||||||
debugImplementation(libs.androidx.ui.test.manifest)
|
|
||||||
|
// Detekt configuration
|
||||||
|
detekt {
|
||||||
|
config.setFrom(files("$rootDir/detekt.yml"))
|
||||||
|
buildUponDefaultConfig = true
|
||||||
|
allRules = false
|
||||||
|
parallel = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Spotless configuration for code formatting
|
||||||
|
spotless {
|
||||||
|
kotlin {
|
||||||
|
target("**/*.kt")
|
||||||
|
targetExclude("**/build/**/*.kt")
|
||||||
|
ktlint("1.2.1")
|
||||||
|
.editorConfigOverride(
|
||||||
|
mapOf(
|
||||||
|
"ktlint_standard_no-wildcard-imports" to "disabled",
|
||||||
|
"ktlint_standard_package-name" to "disabled",
|
||||||
|
"ktlint_standard_function-naming" to "disabled",
|
||||||
|
"ktlint_standard_filename" to "disabled",
|
||||||
|
"ktlint_standard_value-parameter-comment" to "disabled",
|
||||||
|
"ktlint_standard_comment-wrapping" to "disabled",
|
||||||
|
"ktlint_standard_multiline-expression-wrapping" to "disabled",
|
||||||
|
"ktlint_standard_string-template-indent" to "disabled",
|
||||||
|
"ktlint_standard_property-naming" to "disabled",
|
||||||
|
"ktlint_standard_class-naming" to "disabled",
|
||||||
|
"ktlint_standard_backing-property-naming" to "disabled",
|
||||||
|
"ktlint_standard_function-signature" to "disabled",
|
||||||
|
"ktlint_standard_parameter-list-wrapping" to "disabled",
|
||||||
|
"ktlint_standard_max-line-length" to "disabled",
|
||||||
|
"max_line_length" to "off",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
kotlinGradle {
|
||||||
|
target("**/*.kts")
|
||||||
|
targetExclude("**/build/**/*.kts")
|
||||||
|
ktlint("1.2.1")
|
||||||
|
.editorConfigOverride(
|
||||||
|
mapOf(
|
||||||
|
"ktlint_standard_no-wildcard-imports" to "disabled",
|
||||||
|
"max_line_length" to "off",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
70
android/app/proguard-rules.pro
vendored
70
android/app/proguard-rules.pro
vendored
@@ -5,17 +5,69 @@
|
|||||||
# For more details, see
|
# For more details, see
|
||||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Preserve line number information for debugging stack traces
|
||||||
|
-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# Hide the original source file name
|
||||||
|
-renamesourcefileattribute SourceFile
|
||||||
|
|
||||||
|
# Keep generic signatures for Kotlin
|
||||||
|
-keepattributes Signature
|
||||||
|
|
||||||
|
# Keep annotations
|
||||||
|
-keepattributes *Annotation*
|
||||||
|
|
||||||
|
# Room Database
|
||||||
|
-keep class * extends androidx.room.RoomDatabase
|
||||||
|
-keep @androidx.room.Entity class *
|
||||||
|
-keepclassmembers class * {
|
||||||
|
@androidx.room.* <fields>;
|
||||||
|
@androidx.room.* <methods>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Kotlinx Serialization
|
||||||
|
-keepattributes *Annotation*, InnerClasses
|
||||||
|
-dontnote kotlinx.serialization.AnnotationsKt
|
||||||
|
|
||||||
|
-keepclassmembers class kotlinx.serialization.json.** {
|
||||||
|
*** Companion;
|
||||||
|
}
|
||||||
|
-keepclasseswithmembers class kotlinx.serialization.json.** {
|
||||||
|
kotlinx.serialization.KSerializer serializer(...);
|
||||||
|
}
|
||||||
|
|
||||||
|
-keep,includedescriptorclasses class com.atridad.ascently.**$$serializer { *; }
|
||||||
|
-keepclassmembers class com.atridad.ascently.** {
|
||||||
|
*** Companion;
|
||||||
|
}
|
||||||
|
-keepclasseswithmembers class com.atridad.ascently.** {
|
||||||
|
kotlinx.serialization.KSerializer serializer(...);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Keep data classes used for serialization
|
||||||
|
-keep class com.atridad.ascently.data.model.** { *; }
|
||||||
|
-keep class com.atridad.ascently.data.format.** { *; }
|
||||||
|
|
||||||
|
# Coroutines
|
||||||
|
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
|
||||||
|
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
|
||||||
|
-keepclassmembers class kotlinx.coroutines.** {
|
||||||
|
volatile <fields>;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Health Connect
|
||||||
|
-keep class androidx.health.connect.client.** { *; }
|
||||||
|
-keep interface androidx.health.connect.client.** { *; }
|
||||||
|
|
||||||
|
# Coil Image Loading
|
||||||
|
-keep class coil.** { *; }
|
||||||
|
|
||||||
|
# Keep Compose
|
||||||
|
-keep class androidx.compose.** { *; }
|
||||||
|
|
||||||
# If your project uses WebView with JS, uncomment the following
|
# If your project uses WebView with JS, uncomment the following
|
||||||
# and specify the fully qualified class name to the JavaScript interface
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
# class:
|
# class:
|
||||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
# public *;
|
# public *;
|
||||||
#}
|
#}
|
||||||
|
|
||||||
# Uncomment this to preserve the line number information for
|
|
||||||
# debugging stack traces.
|
|
||||||
#-keepattributes SourceFile,LineNumberTable
|
|
||||||
|
|
||||||
# If you keep the line number information, uncomment this to
|
|
||||||
# hide the original source file name.
|
|
||||||
#-renamesourcefileattribute SourceFile
|
|
||||||
@@ -37,9 +37,9 @@ class MainActivity : ComponentActivity() {
|
|||||||
AscentlyTheme {
|
AscentlyTheme {
|
||||||
Surface(modifier = Modifier.fillMaxSize()) {
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
AscentlyApp(
|
AscentlyApp(
|
||||||
shortcutAction = shortcutAction,
|
shortcutAction = shortcutAction,
|
||||||
lastUsedGymId = lastUsedGymId,
|
lastUsedGymId = lastUsedGymId,
|
||||||
onShortcutActionProcessed = { clearShortcutAction() }
|
onShortcutActionProcessed = { clearShortcutAction() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,75 +6,74 @@ import kotlinx.serialization.encodeToString
|
|||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
class Converters {
|
class Converters {
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromClimbTypeList(value: List<ClimbType>): String {
|
fun fromClimbTypeList(value: List<ClimbType>): String {
|
||||||
return Json.encodeToString(value)
|
return Json.encodeToString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toClimbTypeList(value: String): List<ClimbType> {
|
fun toClimbTypeList(value: String): List<ClimbType> {
|
||||||
return Json.decodeFromString(value)
|
return Json.decodeFromString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromDifficultySystemList(value: List<DifficultySystem>): String {
|
fun fromDifficultySystemList(value: List<DifficultySystem>): String {
|
||||||
return Json.encodeToString(value)
|
return Json.encodeToString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toDifficultySystemList(value: String): List<DifficultySystem> {
|
fun toDifficultySystemList(value: String): List<DifficultySystem> {
|
||||||
return Json.decodeFromString(value)
|
return Json.decodeFromString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromStringList(value: List<String>): String {
|
fun fromStringList(value: List<String>): String {
|
||||||
return Json.encodeToString(value)
|
return Json.encodeToString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toStringList(value: String): List<String> {
|
fun toStringList(value: String): List<String> {
|
||||||
return Json.decodeFromString(value)
|
return Json.decodeFromString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromDifficultyGrade(value: DifficultyGrade): String {
|
fun fromDifficultyGrade(value: DifficultyGrade): String {
|
||||||
return Json.encodeToString(value)
|
return Json.encodeToString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toDifficultyGrade(value: String): DifficultyGrade {
|
fun toDifficultyGrade(value: String): DifficultyGrade {
|
||||||
return Json.decodeFromString(value)
|
return Json.decodeFromString(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromClimbType(value: ClimbType): String {
|
fun fromClimbType(value: ClimbType): String {
|
||||||
return value.name
|
return value.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toClimbType(value: String): ClimbType {
|
fun toClimbType(value: String): ClimbType {
|
||||||
return ClimbType.valueOf(value)
|
return ClimbType.valueOf(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromAttemptResult(value: AttemptResult): String {
|
fun fromAttemptResult(value: AttemptResult): String {
|
||||||
return value.name
|
return value.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toAttemptResult(value: String): AttemptResult {
|
fun toAttemptResult(value: String): AttemptResult {
|
||||||
return AttemptResult.valueOf(value)
|
return AttemptResult.valueOf(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun fromSessionStatus(value: SessionStatus): String {
|
fun fromSessionStatus(value: SessionStatus): String {
|
||||||
return value.name
|
return value.name
|
||||||
}
|
}
|
||||||
|
|
||||||
@TypeConverter
|
@TypeConverter
|
||||||
fun toSessionStatus(value: String): SessionStatus {
|
fun toSessionStatus(value: String): SessionStatus {
|
||||||
return SessionStatus.valueOf(value)
|
return SessionStatus.valueOf(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ import com.atridad.ascently.data.database.dao.*
|
|||||||
import com.atridad.ascently.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
entities = [Gym::class, Problem::class, ClimbSession::class, Attempt::class],
|
entities = [Gym::class, Problem::class, ClimbSession::class, Attempt::class],
|
||||||
version = 6,
|
version = 6,
|
||||||
exportSchema = false
|
exportSchema = false,
|
||||||
)
|
)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class AscentlyDatabase : RoomDatabase() {
|
abstract class AscentlyDatabase : RoomDatabase() {
|
||||||
@@ -27,79 +27,79 @@ abstract class AscentlyDatabase : RoomDatabase() {
|
|||||||
@Volatile private var INSTANCE: AscentlyDatabase? = null
|
@Volatile private var INSTANCE: AscentlyDatabase? = null
|
||||||
|
|
||||||
val MIGRATION_4_5 =
|
val MIGRATION_4_5 =
|
||||||
object : Migration(4, 5) {
|
object : Migration(4, 5) {
|
||||||
override fun migrate(db: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
val cursor = db.query("PRAGMA table_info(climb_sessions)")
|
val cursor = db.query("PRAGMA table_info(climb_sessions)")
|
||||||
val existingColumns = mutableSetOf<String>()
|
val existingColumns = mutableSetOf<String>()
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val columnName = cursor.getString(cursor.getColumnIndexOrThrow("name"))
|
val columnName = cursor.getString(cursor.getColumnIndexOrThrow("name"))
|
||||||
existingColumns.add(columnName)
|
existingColumns.add(columnName)
|
||||||
}
|
}
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
if (!existingColumns.contains("startTime")) {
|
|
||||||
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN startTime TEXT")
|
|
||||||
}
|
|
||||||
if (!existingColumns.contains("endTime")) {
|
|
||||||
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN endTime TEXT")
|
|
||||||
}
|
|
||||||
if (!existingColumns.contains("status")) {
|
|
||||||
db.execSQL(
|
|
||||||
"ALTER TABLE climb_sessions ADD COLUMN status TEXT NOT NULL DEFAULT 'COMPLETED'"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (!existingColumns.contains("startTime")) {
|
||||||
|
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN startTime TEXT")
|
||||||
|
}
|
||||||
|
if (!existingColumns.contains("endTime")) {
|
||||||
|
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN endTime TEXT")
|
||||||
|
}
|
||||||
|
if (!existingColumns.contains("status")) {
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"UPDATE climb_sessions SET startTime = createdAt WHERE startTime IS NULL"
|
"ALTER TABLE climb_sessions ADD COLUMN status TEXT NOT NULL DEFAULT 'COMPLETED'",
|
||||||
)
|
|
||||||
db.execSQL(
|
|
||||||
"UPDATE climb_sessions SET status = 'COMPLETED' WHERE status IS NULL OR status = ''"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
db.execSQL(
|
||||||
|
"UPDATE climb_sessions SET startTime = createdAt WHERE startTime IS NULL",
|
||||||
|
)
|
||||||
|
db.execSQL(
|
||||||
|
"UPDATE climb_sessions SET status = 'COMPLETED' WHERE status IS NULL OR status = ''",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val MIGRATION_5_6 =
|
val MIGRATION_5_6 =
|
||||||
object : Migration(5, 6) {
|
object : Migration(5, 6) {
|
||||||
override fun migrate(db: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
// Add updatedAt column to attempts table
|
// Add updatedAt column to attempts table
|
||||||
val cursor = db.query("PRAGMA table_info(attempts)")
|
val cursor = db.query("PRAGMA table_info(attempts)")
|
||||||
val existingColumns = mutableSetOf<String>()
|
val existingColumns = mutableSetOf<String>()
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
while (cursor.moveToNext()) {
|
||||||
val columnName = cursor.getString(cursor.getColumnIndexOrThrow("name"))
|
val columnName = cursor.getString(cursor.getColumnIndexOrThrow("name"))
|
||||||
existingColumns.add(columnName)
|
existingColumns.add(columnName)
|
||||||
}
|
}
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
if (!existingColumns.contains("updatedAt")) {
|
if (!existingColumns.contains("updatedAt")) {
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"ALTER TABLE attempts ADD COLUMN updatedAt TEXT NOT NULL DEFAULT ''"
|
"ALTER TABLE attempts ADD COLUMN updatedAt TEXT NOT NULL DEFAULT ''",
|
||||||
)
|
)
|
||||||
// Set updatedAt to createdAt for existing records
|
// Set updatedAt to createdAt for existing records
|
||||||
db.execSQL(
|
db.execSQL(
|
||||||
"UPDATE attempts SET updatedAt = createdAt WHERE updatedAt = ''"
|
"UPDATE attempts SET updatedAt = createdAt WHERE updatedAt = ''",
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getDatabase(context: Context): AscentlyDatabase {
|
fun getDatabase(context: Context): AscentlyDatabase {
|
||||||
return INSTANCE
|
return INSTANCE
|
||||||
?: synchronized(this) {
|
?: synchronized(this) {
|
||||||
val instance =
|
val instance =
|
||||||
Room.databaseBuilder(
|
Room.databaseBuilder(
|
||||||
context.applicationContext,
|
context.applicationContext,
|
||||||
AscentlyDatabase::class.java,
|
AscentlyDatabase::class.java,
|
||||||
"ascently_database"
|
"ascently_database",
|
||||||
)
|
)
|
||||||
.addMigrations(MIGRATION_4_5, MIGRATION_5_6)
|
.addMigrations(MIGRATION_4_5, MIGRATION_5_6)
|
||||||
.enableMultiInstanceInvalidation()
|
.enableMultiInstanceInvalidation()
|
||||||
.fallbackToDestructiveMigration(false)
|
.fallbackToDestructiveMigration(false)
|
||||||
.build()
|
.build()
|
||||||
INSTANCE = instance
|
INSTANCE = instance
|
||||||
instance
|
instance
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,70 +7,70 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface AttemptDao {
|
interface AttemptDao {
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts ORDER BY timestamp DESC")
|
@Query("SELECT * FROM attempts ORDER BY timestamp DESC")
|
||||||
fun getAllAttempts(): Flow<List<Attempt>>
|
fun getAllAttempts(): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE id = :id")
|
@Query("SELECT * FROM attempts WHERE id = :id")
|
||||||
suspend fun getAttemptById(id: String): Attempt?
|
suspend fun getAttemptById(id: String): Attempt?
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE sessionId = :sessionId ORDER BY timestamp ASC")
|
@Query("SELECT * FROM attempts WHERE sessionId = :sessionId ORDER BY timestamp ASC")
|
||||||
fun getAttemptsBySession(sessionId: String): Flow<List<Attempt>>
|
fun getAttemptsBySession(sessionId: String): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE problemId = :problemId ORDER BY timestamp DESC")
|
@Query("SELECT * FROM attempts WHERE problemId = :problemId ORDER BY timestamp DESC")
|
||||||
fun getAttemptsByProblem(problemId: String): Flow<List<Attempt>>
|
fun getAttemptsByProblem(problemId: String): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE sessionId = :sessionId AND problemId = :problemId ORDER BY timestamp ASC")
|
@Query("SELECT * FROM attempts WHERE sessionId = :sessionId AND problemId = :problemId ORDER BY timestamp ASC")
|
||||||
fun getAttemptsBySessionAndProblem(sessionId: String, problemId: String): Flow<List<Attempt>>
|
fun getAttemptsBySessionAndProblem(sessionId: String, problemId: String): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE result = :result ORDER BY timestamp DESC")
|
@Query("SELECT * FROM attempts WHERE result = :result ORDER BY timestamp DESC")
|
||||||
fun getAttemptsByResult(result: AttemptResult): Flow<List<Attempt>>
|
fun getAttemptsByResult(result: AttemptResult): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE timestamp BETWEEN :startDate AND :endDate ORDER BY timestamp DESC")
|
@Query("SELECT * FROM attempts WHERE timestamp BETWEEN :startDate AND :endDate ORDER BY timestamp DESC")
|
||||||
fun getAttemptsInDateRange(startDate: String, endDate: String): Flow<List<Attempt>>
|
fun getAttemptsInDateRange(startDate: String, endDate: String): Flow<List<Attempt>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAttempt(attempt: Attempt)
|
suspend fun insertAttempt(attempt: Attempt)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertAttempts(attempts: List<Attempt>)
|
suspend fun insertAttempts(attempts: List<Attempt>)
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
suspend fun updateAttempt(attempt: Attempt)
|
suspend fun updateAttempt(attempt: Attempt)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun deleteAttempt(attempt: Attempt)
|
suspend fun deleteAttempt(attempt: Attempt)
|
||||||
|
|
||||||
@Query("DELETE FROM attempts WHERE id = :id")
|
@Query("DELETE FROM attempts WHERE id = :id")
|
||||||
suspend fun deleteAttemptById(id: String)
|
suspend fun deleteAttemptById(id: String)
|
||||||
|
|
||||||
@Query("DELETE FROM attempts WHERE sessionId = :sessionId")
|
@Query("DELETE FROM attempts WHERE sessionId = :sessionId")
|
||||||
suspend fun deleteAttemptsBySession(sessionId: String)
|
suspend fun deleteAttemptsBySession(sessionId: String)
|
||||||
|
|
||||||
@Query("DELETE FROM attempts WHERE problemId = :problemId")
|
@Query("DELETE FROM attempts WHERE problemId = :problemId")
|
||||||
suspend fun deleteAttemptsByProblem(problemId: String)
|
suspend fun deleteAttemptsByProblem(problemId: String)
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM attempts")
|
@Query("SELECT COUNT(*) FROM attempts")
|
||||||
suspend fun getAttemptsCount(): Int
|
suspend fun getAttemptsCount(): Int
|
||||||
|
|
||||||
@Query("DELETE FROM attempts")
|
@Query("DELETE FROM attempts")
|
||||||
suspend fun deleteAllAttempts()
|
suspend fun deleteAllAttempts()
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM attempts WHERE sessionId = :sessionId")
|
@Query("SELECT COUNT(*) FROM attempts WHERE sessionId = :sessionId")
|
||||||
suspend fun getAttemptsCountBySession(sessionId: String): Int
|
suspend fun getAttemptsCountBySession(sessionId: String): Int
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM attempts WHERE problemId = :problemId")
|
@Query("SELECT COUNT(*) FROM attempts WHERE problemId = :problemId")
|
||||||
suspend fun getAttemptsCountByProblem(problemId: String): Int
|
suspend fun getAttemptsCountByProblem(problemId: String): Int
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM attempts WHERE result = :result")
|
@Query("SELECT COUNT(*) FROM attempts WHERE result = :result")
|
||||||
suspend fun getAttemptsCountByResult(result: AttemptResult): Int
|
suspend fun getAttemptsCountByResult(result: AttemptResult): Int
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM attempts WHERE problemId = :problemId AND result IN ('SUCCESS', 'FLASH', 'REDPOINT', 'ONSIGHT')")
|
@Query("SELECT COUNT(*) FROM attempts WHERE problemId = :problemId AND result IN ('SUCCESS', 'FLASH', 'REDPOINT', 'ONSIGHT')")
|
||||||
suspend fun getSuccessfulAttemptsCountByProblem(problemId: String): Int
|
suspend fun getSuccessfulAttemptsCountByProblem(problemId: String): Int
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE problemId = :problemId AND result IN ('SUCCESS', 'FLASH', 'REDPOINT', 'ONSIGHT') ORDER BY timestamp ASC LIMIT 1")
|
@Query("SELECT * FROM attempts WHERE problemId = :problemId AND result IN ('SUCCESS', 'FLASH', 'REDPOINT', 'ONSIGHT') ORDER BY timestamp ASC LIMIT 1")
|
||||||
suspend fun getFirstSuccessfulAttempt(problemId: String): Attempt?
|
suspend fun getFirstSuccessfulAttempt(problemId: String): Attempt?
|
||||||
|
|
||||||
@Query("SELECT * FROM attempts WHERE problemId = :problemId ORDER BY timestamp DESC LIMIT 1")
|
@Query("SELECT * FROM attempts WHERE problemId = :problemId ORDER BY timestamp DESC LIMIT 1")
|
||||||
suspend fun getLatestAttemptForProblem(problemId: String): Attempt?
|
suspend fun getLatestAttemptForProblem(problemId: String): Attempt?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,61 +7,61 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface ClimbSessionDao {
|
interface ClimbSessionDao {
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions ORDER BY date DESC")
|
@Query("SELECT * FROM climb_sessions ORDER BY date DESC")
|
||||||
fun getAllSessions(): Flow<List<ClimbSession>>
|
fun getAllSessions(): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE id = :id")
|
@Query("SELECT * FROM climb_sessions WHERE id = :id")
|
||||||
suspend fun getSessionById(id: String): ClimbSession?
|
suspend fun getSessionById(id: String): ClimbSession?
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE gymId = :gymId ORDER BY date DESC")
|
@Query("SELECT * FROM climb_sessions WHERE gymId = :gymId ORDER BY date DESC")
|
||||||
fun getSessionsByGym(gymId: String): Flow<List<ClimbSession>>
|
fun getSessionsByGym(gymId: String): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE date = :date ORDER BY createdAt DESC")
|
@Query("SELECT * FROM climb_sessions WHERE date = :date ORDER BY createdAt DESC")
|
||||||
fun getSessionsByDate(date: String): Flow<List<ClimbSession>>
|
fun getSessionsByDate(date: String): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE date BETWEEN :startDate AND :endDate ORDER BY date DESC")
|
@Query("SELECT * FROM climb_sessions WHERE date BETWEEN :startDate AND :endDate ORDER BY date DESC")
|
||||||
fun getSessionsInDateRange(startDate: String, endDate: String): Flow<List<ClimbSession>>
|
fun getSessionsInDateRange(startDate: String, endDate: String): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions ORDER BY date DESC LIMIT :limit")
|
@Query("SELECT * FROM climb_sessions ORDER BY date DESC LIMIT :limit")
|
||||||
fun getRecentSessions(limit: Int = 10): Flow<List<ClimbSession>>
|
fun getRecentSessions(limit: Int = 10): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertSession(session: ClimbSession)
|
suspend fun insertSession(session: ClimbSession)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertSessions(sessions: List<ClimbSession>)
|
suspend fun insertSessions(sessions: List<ClimbSession>)
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
suspend fun updateSession(session: ClimbSession)
|
suspend fun updateSession(session: ClimbSession)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun deleteSession(session: ClimbSession)
|
suspend fun deleteSession(session: ClimbSession)
|
||||||
|
|
||||||
@Query("DELETE FROM climb_sessions WHERE id = :id")
|
@Query("DELETE FROM climb_sessions WHERE id = :id")
|
||||||
suspend fun deleteSessionById(id: String)
|
suspend fun deleteSessionById(id: String)
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM climb_sessions")
|
@Query("SELECT COUNT(*) FROM climb_sessions")
|
||||||
suspend fun getSessionsCount(): Int
|
suspend fun getSessionsCount(): Int
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM climb_sessions WHERE gymId = :gymId")
|
@Query("SELECT COUNT(*) FROM climb_sessions WHERE gymId = :gymId")
|
||||||
suspend fun getSessionsCountByGym(gymId: String): Int
|
suspend fun getSessionsCountByGym(gymId: String): Int
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM climb_sessions WHERE date BETWEEN :startDate AND :endDate")
|
@Query("SELECT COUNT(*) FROM climb_sessions WHERE date BETWEEN :startDate AND :endDate")
|
||||||
suspend fun getSessionsCountInDateRange(startDate: String, endDate: String): Int
|
suspend fun getSessionsCountInDateRange(startDate: String, endDate: String): Int
|
||||||
|
|
||||||
@Query("SELECT DISTINCT date FROM climb_sessions ORDER BY date DESC")
|
@Query("SELECT DISTINCT date FROM climb_sessions ORDER BY date DESC")
|
||||||
suspend fun getUniqueDates(): List<String>
|
suspend fun getUniqueDates(): List<String>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE status = :status ORDER BY date DESC")
|
@Query("SELECT * FROM climb_sessions WHERE status = :status ORDER BY date DESC")
|
||||||
fun getSessionsByStatus(status: SessionStatus): Flow<List<ClimbSession>>
|
fun getSessionsByStatus(status: SessionStatus): Flow<List<ClimbSession>>
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE status = 'ACTIVE' ORDER BY date DESC LIMIT 1")
|
@Query("SELECT * FROM climb_sessions WHERE status = 'ACTIVE' ORDER BY date DESC LIMIT 1")
|
||||||
suspend fun getActiveSession(): ClimbSession?
|
suspend fun getActiveSession(): ClimbSession?
|
||||||
|
|
||||||
@Query("DELETE FROM climb_sessions")
|
@Query("DELETE FROM climb_sessions")
|
||||||
suspend fun deleteAllSessions()
|
suspend fun deleteAllSessions()
|
||||||
|
|
||||||
@Query("SELECT * FROM climb_sessions WHERE status = 'ACTIVE' ORDER BY date DESC LIMIT 1")
|
@Query("SELECT * FROM climb_sessions WHERE status = 'ACTIVE' ORDER BY date DESC LIMIT 1")
|
||||||
fun getActiveSessionFlow(): Flow<ClimbSession?>
|
fun getActiveSessionFlow(): Flow<ClimbSession?>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,37 +7,37 @@ import kotlinx.coroutines.flow.Flow
|
|||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
interface GymDao {
|
interface GymDao {
|
||||||
|
|
||||||
@Query("SELECT * FROM gyms ORDER BY name ASC")
|
@Query("SELECT * FROM gyms ORDER BY name ASC")
|
||||||
fun getAllGyms(): Flow<List<Gym>>
|
fun getAllGyms(): Flow<List<Gym>>
|
||||||
|
|
||||||
@Query("SELECT * FROM gyms WHERE id = :id")
|
@Query("SELECT * FROM gyms WHERE id = :id")
|
||||||
suspend fun getGymById(id: String): Gym?
|
suspend fun getGymById(id: String): Gym?
|
||||||
|
|
||||||
@Query("SELECT * FROM gyms WHERE :climbType IN (supportedClimbTypes)")
|
@Query("SELECT * FROM gyms WHERE :climbType IN (supportedClimbTypes)")
|
||||||
fun getGymsByClimbType(climbType: ClimbType): Flow<List<Gym>>
|
fun getGymsByClimbType(climbType: ClimbType): Flow<List<Gym>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertGym(gym: Gym)
|
suspend fun insertGym(gym: Gym)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertGyms(gyms: List<Gym>)
|
suspend fun insertGyms(gyms: List<Gym>)
|
||||||
|
|
||||||
@Update
|
@Update
|
||||||
suspend fun updateGym(gym: Gym)
|
suspend fun updateGym(gym: Gym)
|
||||||
|
|
||||||
@Delete
|
@Delete
|
||||||
suspend fun deleteGym(gym: Gym)
|
suspend fun deleteGym(gym: Gym)
|
||||||
|
|
||||||
@Query("DELETE FROM gyms WHERE id = :id")
|
@Query("DELETE FROM gyms WHERE id = :id")
|
||||||
suspend fun deleteGymById(id: String)
|
suspend fun deleteGymById(id: String)
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM gyms")
|
@Query("SELECT COUNT(*) FROM gyms")
|
||||||
suspend fun getGymsCount(): Int
|
suspend fun getGymsCount(): Int
|
||||||
|
|
||||||
@Query("SELECT * FROM gyms WHERE name LIKE '%' || :searchQuery || '%' OR location LIKE '%' || :searchQuery || '%'")
|
@Query("SELECT * FROM gyms WHERE name LIKE '%' || :searchQuery || '%' OR location LIKE '%' || :searchQuery || '%'")
|
||||||
fun searchGyms(searchQuery: String): Flow<List<Gym>>
|
fun searchGyms(searchQuery: String): Flow<List<Gym>>
|
||||||
|
|
||||||
@Query("DELETE FROM gyms")
|
@Query("DELETE FROM gyms")
|
||||||
suspend fun deleteAllGyms()
|
suspend fun deleteAllGyms()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ interface ProblemDao {
|
|||||||
@Query("SELECT * FROM problems ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems ORDER BY updatedAt DESC")
|
||||||
fun getAllProblems(): Flow<List<Problem>>
|
fun getAllProblems(): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE id = :id") suspend fun getProblemById(id: String): Problem?
|
@Query("SELECT * FROM problems WHERE id = :id")
|
||||||
|
suspend fun getProblemById(id: String): Problem?
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE gymId = :gymId ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE gymId = :gymId ORDER BY updatedAt DESC")
|
||||||
fun getProblemsByGym(gymId: String): Flow<List<Problem>>
|
fun getProblemsByGym(gymId: String): Flow<List<Problem>>
|
||||||
@@ -20,7 +21,7 @@ interface ProblemDao {
|
|||||||
fun getProblemsByClimbType(climbType: ClimbType): Flow<List<Problem>>
|
fun getProblemsByClimbType(climbType: ClimbType): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"SELECT * FROM problems WHERE gymId = :gymId AND climbType = :climbType ORDER BY updatedAt DESC"
|
"SELECT * FROM problems WHERE gymId = :gymId AND climbType = :climbType ORDER BY updatedAt DESC",
|
||||||
)
|
)
|
||||||
fun getProblemsByGymAndType(gymId: String, climbType: ClimbType): Flow<List<Problem>>
|
fun getProblemsByGymAndType(gymId: String, climbType: ClimbType): Flow<List<Problem>>
|
||||||
|
|
||||||
@@ -30,7 +31,8 @@ interface ProblemDao {
|
|||||||
@Query("SELECT * FROM problems WHERE gymId = :gymId AND isActive = 1 ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE gymId = :gymId AND isActive = 1 ORDER BY updatedAt DESC")
|
||||||
fun getActiveProblemsByGym(gymId: String): Flow<List<Problem>>
|
fun getActiveProblemsByGym(gymId: String): Flow<List<Problem>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertProblem(problem: Problem)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
|
suspend fun insertProblem(problem: Problem)
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertProblems(problems: List<Problem>)
|
suspend fun insertProblems(problems: List<Problem>)
|
||||||
@@ -39,7 +41,8 @@ interface ProblemDao {
|
|||||||
|
|
||||||
@Delete suspend fun deleteProblem(problem: Problem)
|
@Delete suspend fun deleteProblem(problem: Problem)
|
||||||
|
|
||||||
@Query("DELETE FROM problems WHERE id = :id") suspend fun deleteProblemById(id: String)
|
@Query("DELETE FROM problems WHERE id = :id")
|
||||||
|
suspend fun deleteProblemById(id: String)
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM problems WHERE gymId = :gymId")
|
@Query("SELECT COUNT(*) FROM problems WHERE gymId = :gymId")
|
||||||
suspend fun getProblemsCountByGym(gymId: String): Int
|
suspend fun getProblemsCountByGym(gymId: String): Int
|
||||||
@@ -48,17 +51,19 @@ interface ProblemDao {
|
|||||||
suspend fun getActiveProblemsCount(): Int
|
suspend fun getActiveProblemsCount(): Int
|
||||||
|
|
||||||
@Query(
|
@Query(
|
||||||
"""
|
"""
|
||||||
SELECT * FROM problems
|
SELECT * FROM problems
|
||||||
WHERE (name LIKE '%' || :searchQuery || '%'
|
WHERE (name LIKE '%' || :searchQuery || '%'
|
||||||
OR description LIKE '%' || :searchQuery || '%'
|
OR description LIKE '%' || :searchQuery || '%'
|
||||||
OR location LIKE '%' || :searchQuery || '%')
|
OR location LIKE '%' || :searchQuery || '%')
|
||||||
ORDER BY updatedAt DESC
|
ORDER BY updatedAt DESC
|
||||||
"""
|
""",
|
||||||
)
|
)
|
||||||
fun searchProblems(searchQuery: String): Flow<List<Problem>>
|
fun searchProblems(searchQuery: String): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM problems") suspend fun getProblemsCount(): Int
|
@Query("SELECT COUNT(*) FROM problems")
|
||||||
|
suspend fun getProblemsCount(): Int
|
||||||
|
|
||||||
@Query("DELETE FROM problems") suspend fun deleteAllProblems()
|
@Query("DELETE FROM problems")
|
||||||
|
suspend fun deleteAllProblems()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,64 +6,64 @@ import kotlinx.serialization.Serializable
|
|||||||
// Root structure for Ascently backup data
|
// Root structure for Ascently backup data
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ClimbDataBackup(
|
data class ClimbDataBackup(
|
||||||
val exportedAt: String,
|
val exportedAt: String,
|
||||||
val version: String = "2.0",
|
val version: String = "2.0",
|
||||||
val formatVersion: String = "2.0",
|
val formatVersion: String = "2.0",
|
||||||
val gyms: List<BackupGym>,
|
val gyms: List<BackupGym>,
|
||||||
val problems: List<BackupProblem>,
|
val problems: List<BackupProblem>,
|
||||||
val sessions: List<BackupClimbSession>,
|
val sessions: List<BackupClimbSession>,
|
||||||
val attempts: List<BackupAttempt>,
|
val attempts: List<BackupAttempt>,
|
||||||
val deletedItems: List<DeletedItem> = emptyList()
|
val deletedItems: List<DeletedItem> = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DeletedItem(
|
data class DeletedItem(
|
||||||
val id: String,
|
val id: String,
|
||||||
val type: String, // "gym", "problem", "session", "attempt"
|
val type: String, // "gym", "problem", "session", "attempt"
|
||||||
val deletedAt: String
|
val deletedAt: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Platform-neutral gym representation for backup/restore
|
// Platform-neutral gym representation for backup/restore
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BackupGym(
|
data class BackupGym(
|
||||||
val id: String,
|
val id: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val location: String? = null,
|
val location: String? = null,
|
||||||
val supportedClimbTypes: List<ClimbType>,
|
val supportedClimbTypes: List<ClimbType>,
|
||||||
val difficultySystems: List<DifficultySystem>,
|
val difficultySystems: List<DifficultySystem>,
|
||||||
@kotlinx.serialization.SerialName("customDifficultyGrades")
|
@kotlinx.serialization.SerialName("customDifficultyGrades")
|
||||||
val customDifficultyGrades: List<String>? = null,
|
val customDifficultyGrades: List<String>? = null,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromGym(gym: Gym): BackupGym {
|
fun fromGym(gym: Gym): BackupGym {
|
||||||
return BackupGym(
|
return BackupGym(
|
||||||
id = gym.id,
|
id = gym.id,
|
||||||
name = gym.name,
|
name = gym.name,
|
||||||
location = gym.location,
|
location = gym.location,
|
||||||
supportedClimbTypes = gym.supportedClimbTypes,
|
supportedClimbTypes = gym.supportedClimbTypes,
|
||||||
difficultySystems = gym.difficultySystems,
|
difficultySystems = gym.difficultySystems,
|
||||||
customDifficultyGrades = gym.customDifficultyGrades.ifEmpty { null },
|
customDifficultyGrades = gym.customDifficultyGrades.ifEmpty { null },
|
||||||
notes = gym.notes,
|
notes = gym.notes,
|
||||||
createdAt = gym.createdAt,
|
createdAt = gym.createdAt,
|
||||||
updatedAt = gym.updatedAt
|
updatedAt = gym.updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toGym(): Gym {
|
fun toGym(): Gym {
|
||||||
return Gym(
|
return Gym(
|
||||||
id = id,
|
id = id,
|
||||||
name = name,
|
name = name,
|
||||||
location = location,
|
location = location,
|
||||||
supportedClimbTypes = supportedClimbTypes,
|
supportedClimbTypes = supportedClimbTypes,
|
||||||
difficultySystems = difficultySystems,
|
difficultySystems = difficultySystems,
|
||||||
customDifficultyGrades = customDifficultyGrades ?: emptyList(),
|
customDifficultyGrades = customDifficultyGrades ?: emptyList(),
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
updatedAt = updatedAt
|
updatedAt = updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,60 +71,63 @@ data class BackupGym(
|
|||||||
// Platform-neutral problem representation for backup/restore
|
// Platform-neutral problem representation for backup/restore
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BackupProblem(
|
data class BackupProblem(
|
||||||
val id: String,
|
val id: String,
|
||||||
val gymId: String,
|
val gymId: String,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val description: String? = null,
|
val description: String? = null,
|
||||||
val climbType: ClimbType,
|
val climbType: ClimbType,
|
||||||
val difficulty: DifficultyGrade,
|
val difficulty: DifficultyGrade,
|
||||||
val tags: List<String>? = null,
|
val tags: List<String>? = null,
|
||||||
val location: String? = null,
|
val location: String? = null,
|
||||||
val imagePaths: List<String>? = null,
|
val imagePaths: List<String>? = null,
|
||||||
val isActive: Boolean = true,
|
val isActive: Boolean = true,
|
||||||
val dateSet: String? = null,
|
val dateSet: String? = null,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromProblem(problem: Problem): BackupProblem {
|
fun fromProblem(problem: Problem): BackupProblem {
|
||||||
return BackupProblem(
|
return BackupProblem(
|
||||||
id = problem.id,
|
id = problem.id,
|
||||||
gymId = problem.gymId,
|
gymId = problem.gymId,
|
||||||
name = problem.name,
|
name = problem.name,
|
||||||
description = problem.description,
|
description = problem.description,
|
||||||
climbType = problem.climbType,
|
climbType = problem.climbType,
|
||||||
difficulty = problem.difficulty,
|
difficulty = problem.difficulty,
|
||||||
tags = problem.tags,
|
tags = problem.tags,
|
||||||
location = problem.location,
|
location = problem.location,
|
||||||
imagePaths =
|
imagePaths =
|
||||||
if (problem.imagePaths.isEmpty()) null
|
if (problem.imagePaths.isEmpty()) {
|
||||||
else problem.imagePaths.map { path -> path.substringAfterLast('/') },
|
null
|
||||||
isActive = problem.isActive,
|
} else {
|
||||||
dateSet = problem.dateSet,
|
problem.imagePaths.map { path -> path.substringAfterLast('/') }
|
||||||
notes = problem.notes,
|
},
|
||||||
createdAt = problem.createdAt,
|
isActive = problem.isActive,
|
||||||
updatedAt = problem.updatedAt
|
dateSet = problem.dateSet,
|
||||||
|
notes = problem.notes,
|
||||||
|
createdAt = problem.createdAt,
|
||||||
|
updatedAt = problem.updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toProblem(): Problem {
|
fun toProblem(): Problem {
|
||||||
return Problem(
|
return Problem(
|
||||||
id = id,
|
id = id,
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
name = name,
|
name = name,
|
||||||
description = description,
|
description = description,
|
||||||
climbType = climbType,
|
climbType = climbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
tags = tags ?: emptyList(),
|
tags = tags ?: emptyList(),
|
||||||
location = location,
|
location = location,
|
||||||
imagePaths = imagePaths ?: emptyList(),
|
imagePaths = imagePaths ?: emptyList(),
|
||||||
isActive = isActive,
|
isActive = isActive,
|
||||||
dateSet = dateSet,
|
dateSet = dateSet,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
updatedAt = updatedAt
|
updatedAt = updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,46 +139,46 @@ data class BackupProblem(
|
|||||||
// Platform-neutral climb session representation for backup/restore
|
// Platform-neutral climb session representation for backup/restore
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BackupClimbSession(
|
data class BackupClimbSession(
|
||||||
val id: String,
|
val id: String,
|
||||||
val gymId: String,
|
val gymId: String,
|
||||||
val date: String,
|
val date: String,
|
||||||
val startTime: String? = null,
|
val startTime: String? = null,
|
||||||
val endTime: String? = null,
|
val endTime: String? = null,
|
||||||
val duration: Long? = null,
|
val duration: Long? = null,
|
||||||
val status: SessionStatus,
|
val status: SessionStatus,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromClimbSession(session: ClimbSession): BackupClimbSession {
|
fun fromClimbSession(session: ClimbSession): BackupClimbSession {
|
||||||
return BackupClimbSession(
|
return BackupClimbSession(
|
||||||
id = session.id,
|
id = session.id,
|
||||||
gymId = session.gymId,
|
gymId = session.gymId,
|
||||||
date = session.date,
|
date = session.date,
|
||||||
startTime = session.startTime,
|
startTime = session.startTime,
|
||||||
endTime = session.endTime,
|
endTime = session.endTime,
|
||||||
duration = session.duration,
|
duration = session.duration,
|
||||||
status = session.status,
|
status = session.status,
|
||||||
notes = session.notes,
|
notes = session.notes,
|
||||||
createdAt = session.createdAt,
|
createdAt = session.createdAt,
|
||||||
updatedAt = session.updatedAt
|
updatedAt = session.updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toClimbSession(): ClimbSession {
|
fun toClimbSession(): ClimbSession {
|
||||||
return ClimbSession(
|
return ClimbSession(
|
||||||
id = id,
|
id = id,
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
date = date,
|
date = date,
|
||||||
startTime = startTime,
|
startTime = startTime,
|
||||||
endTime = endTime,
|
endTime = endTime,
|
||||||
duration = duration,
|
duration = duration,
|
||||||
status = status,
|
status = status,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
updatedAt = updatedAt
|
updatedAt = updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,49 +186,49 @@ data class BackupClimbSession(
|
|||||||
// Platform-neutral attempt representation for backup/restore
|
// Platform-neutral attempt representation for backup/restore
|
||||||
@Serializable
|
@Serializable
|
||||||
data class BackupAttempt(
|
data class BackupAttempt(
|
||||||
val id: String,
|
val id: String,
|
||||||
val sessionId: String,
|
val sessionId: String,
|
||||||
val problemId: String,
|
val problemId: String,
|
||||||
val result: AttemptResult,
|
val result: AttemptResult,
|
||||||
val highestHold: String? = null,
|
val highestHold: String? = null,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val duration: Long? = null,
|
val duration: Long? = null,
|
||||||
val restTime: Long? = null,
|
val restTime: Long? = null,
|
||||||
val timestamp: String,
|
val timestamp: String,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String? = null
|
val updatedAt: String? = null,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromAttempt(attempt: Attempt): BackupAttempt {
|
fun fromAttempt(attempt: Attempt): BackupAttempt {
|
||||||
return BackupAttempt(
|
return BackupAttempt(
|
||||||
id = attempt.id,
|
id = attempt.id,
|
||||||
sessionId = attempt.sessionId,
|
sessionId = attempt.sessionId,
|
||||||
problemId = attempt.problemId,
|
problemId = attempt.problemId,
|
||||||
result = attempt.result,
|
result = attempt.result,
|
||||||
highestHold = attempt.highestHold,
|
highestHold = attempt.highestHold,
|
||||||
notes = attempt.notes,
|
notes = attempt.notes,
|
||||||
duration = attempt.duration,
|
duration = attempt.duration,
|
||||||
restTime = attempt.restTime,
|
restTime = attempt.restTime,
|
||||||
timestamp = attempt.timestamp,
|
timestamp = attempt.timestamp,
|
||||||
createdAt = attempt.createdAt,
|
createdAt = attempt.createdAt,
|
||||||
updatedAt = attempt.updatedAt
|
updatedAt = attempt.updatedAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toAttempt(): Attempt {
|
fun toAttempt(): Attempt {
|
||||||
return Attempt(
|
return Attempt(
|
||||||
id = id,
|
id = id,
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
problemId = problemId,
|
problemId = problemId,
|
||||||
result = result,
|
result = result,
|
||||||
highestHold = highestHold,
|
highestHold = highestHold,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
duration = duration,
|
duration = duration,
|
||||||
restTime = restTime,
|
restTime = restTime,
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
updatedAt = updatedAt ?: createdAt
|
updatedAt = updatedAt ?: createdAt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.atridad.ascently.data.health
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import com.atridad.ascently.utils.AppLogger
|
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
import androidx.health.connect.client.HealthConnectClient
|
import androidx.health.connect.client.HealthConnectClient
|
||||||
import androidx.health.connect.client.PermissionController
|
import androidx.health.connect.client.PermissionController
|
||||||
@@ -14,14 +13,15 @@ import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
|||||||
import androidx.health.connect.client.units.Energy
|
import androidx.health.connect.client.units.Energy
|
||||||
import com.atridad.ascently.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.ascently.data.model.SessionStatus
|
import com.atridad.ascently.data.model.SessionStatus
|
||||||
|
import com.atridad.ascently.utils.AppLogger
|
||||||
import com.atridad.ascently.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import java.time.Duration
|
|
||||||
import java.time.Instant
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Health Connect manager for Ascently that syncs climbing sessions to Samsung Health, Google Fit,
|
* Health Connect manager for Ascently that syncs climbing sessions to Samsung Health, Google Fit,
|
||||||
@@ -52,7 +52,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
HealthPermission.getReadPermission(HeartRateRecord::class),
|
HealthPermission.getReadPermission(HeartRateRecord::class),
|
||||||
HealthPermission.getWritePermission(HeartRateRecord::class),
|
HealthPermission.getWritePermission(HeartRateRecord::class),
|
||||||
HealthPermission.getReadPermission(TotalCaloriesBurnedRecord::class),
|
HealthPermission.getReadPermission(TotalCaloriesBurnedRecord::class),
|
||||||
HealthPermission.getWritePermission(TotalCaloriesBurnedRecord::class)
|
HealthPermission.getWritePermission(TotalCaloriesBurnedRecord::class),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,8 +127,9 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
|
|
||||||
suspend fun isReady(): Boolean {
|
suspend fun isReady(): Boolean {
|
||||||
return try {
|
return try {
|
||||||
if (!_isEnabled.value || !_isCompatible.value || healthConnectClient == null)
|
if (!_isEnabled.value || !_isCompatible.value || healthConnectClient == null) {
|
||||||
return false
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
val isAvailable =
|
val isAvailable =
|
||||||
HealthConnectClient.getSdkStatus(context) == HealthConnectClient.SDK_AVAILABLE
|
HealthConnectClient.getSdkStatus(context) == HealthConnectClient.SDK_AVAILABLE
|
||||||
@@ -157,18 +158,18 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
suspend fun syncCompletedSession(
|
suspend fun syncCompletedSession(
|
||||||
session: ClimbSession,
|
session: ClimbSession,
|
||||||
gymName: String,
|
gymName: String,
|
||||||
attemptCount: Int = 0
|
attemptCount: Int = 0,
|
||||||
): Result<Unit> {
|
): Result<Unit> {
|
||||||
return try {
|
return try {
|
||||||
if (!isReady() || !_autoSync.value) {
|
if (!isReady() || !_autoSync.value) {
|
||||||
return Result.failure(
|
return Result.failure(
|
||||||
IllegalStateException("Health Connect not ready or auto-sync disabled")
|
IllegalStateException("Health Connect not ready or auto-sync disabled"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.status != SessionStatus.COMPLETED) {
|
if (session.status != SessionStatus.COMPLETED) {
|
||||||
return Result.failure(
|
return Result.failure(
|
||||||
IllegalArgumentException("Only completed sessions can be synced")
|
IllegalArgumentException("Only completed sessions can be synced"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
|
|
||||||
if (startTime == null || endTime == null) {
|
if (startTime == null || endTime == null) {
|
||||||
return Result.failure(
|
return Result.failure(
|
||||||
IllegalArgumentException("Session must have valid start and end times")
|
IllegalArgumentException("Session must have valid start and end times"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,12 +191,12 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
ExerciseSessionRecord(
|
ExerciseSessionRecord(
|
||||||
startTime = startTime,
|
startTime = startTime,
|
||||||
startZoneOffset =
|
startZoneOffset =
|
||||||
ZoneOffset.systemDefault().rules.getOffset(startTime),
|
ZoneOffset.systemDefault().rules.getOffset(startTime),
|
||||||
endTime = endTime,
|
endTime = endTime,
|
||||||
endZoneOffset = ZoneOffset.systemDefault().rules.getOffset(endTime),
|
endZoneOffset = ZoneOffset.systemDefault().rules.getOffset(endTime),
|
||||||
exerciseType =
|
exerciseType =
|
||||||
ExerciseSessionRecord.EXERCISE_TYPE_STRENGTH_TRAINING,
|
ExerciseSessionRecord.EXERCISE_TYPE_STRENGTH_TRAINING,
|
||||||
title = "Rock Climbing at $gymName"
|
title = "Rock Climbing at $gymName",
|
||||||
)
|
)
|
||||||
records.add(exerciseSession)
|
records.add(exerciseSession)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -211,11 +212,11 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
TotalCaloriesBurnedRecord(
|
TotalCaloriesBurnedRecord(
|
||||||
startTime = startTime,
|
startTime = startTime,
|
||||||
startZoneOffset =
|
startZoneOffset =
|
||||||
ZoneOffset.systemDefault().rules.getOffset(startTime),
|
ZoneOffset.systemDefault().rules.getOffset(startTime),
|
||||||
endTime = endTime,
|
endTime = endTime,
|
||||||
endZoneOffset =
|
endZoneOffset =
|
||||||
ZoneOffset.systemDefault().rules.getOffset(endTime),
|
ZoneOffset.systemDefault().rules.getOffset(endTime),
|
||||||
energy = Energy.calories(estimatedCalories)
|
energy = Energy.calories(estimatedCalories),
|
||||||
)
|
)
|
||||||
records.add(caloriesRecord)
|
records.add(caloriesRecord)
|
||||||
}
|
}
|
||||||
@@ -262,7 +263,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
suspend fun autoSyncCompletedSession(
|
suspend fun autoSyncCompletedSession(
|
||||||
session: ClimbSession,
|
session: ClimbSession,
|
||||||
gymName: String,
|
gymName: String,
|
||||||
attemptCount: Int = 0
|
attemptCount: Int = 0,
|
||||||
): Result<Unit> {
|
): Result<Unit> {
|
||||||
return if (_autoSync.value && isReady() && session.status == SessionStatus.COMPLETED) {
|
return if (_autoSync.value && isReady() && session.status == SessionStatus.COMPLETED) {
|
||||||
AppLogger.d(TAG) { "Auto-syncing completed session '${session.id}' to Health Connect..." }
|
AppLogger.d(TAG) { "Auto-syncing completed session '${session.id}' to Health Connect..." }
|
||||||
@@ -295,7 +296,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
private fun createHeartRateRecord(
|
private fun createHeartRateRecord(
|
||||||
startTime: Instant,
|
startTime: Instant,
|
||||||
endTime: Instant,
|
endTime: Instant,
|
||||||
attemptCount: Int
|
attemptCount: Int,
|
||||||
): HeartRateRecord? {
|
): HeartRateRecord? {
|
||||||
return try {
|
return try {
|
||||||
val samples = mutableListOf<HeartRateRecord.Sample>()
|
val samples = mutableListOf<HeartRateRecord.Sample>()
|
||||||
@@ -324,7 +325,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
startZoneOffset = ZoneOffset.systemDefault().rules.getOffset(startTime),
|
startZoneOffset = ZoneOffset.systemDefault().rules.getOffset(startTime),
|
||||||
endTime = endTime,
|
endTime = endTime,
|
||||||
endZoneOffset = ZoneOffset.systemDefault().rules.getOffset(endTime),
|
endZoneOffset = ZoneOffset.systemDefault().rules.getOffset(endTime),
|
||||||
samples = samples
|
samples = samples,
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
AppLogger.e(TAG, e) { "Error creating heart rate record" }
|
AppLogger.e(TAG, e) { "Error creating heart rate record" }
|
||||||
|
|||||||
@@ -12,65 +12,66 @@ enum class AttemptResult {
|
|||||||
SUCCESS,
|
SUCCESS,
|
||||||
FALL,
|
FALL,
|
||||||
NO_PROGRESS,
|
NO_PROGRESS,
|
||||||
FLASH
|
FLASH,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "attempts",
|
tableName = "attempts",
|
||||||
foreignKeys =
|
foreignKeys =
|
||||||
[
|
[
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = ClimbSession::class,
|
entity = ClimbSession::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["sessionId"],
|
childColumns = ["sessionId"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
),
|
),
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = Problem::class,
|
entity = Problem::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["problemId"],
|
childColumns = ["problemId"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
)],
|
),
|
||||||
indices = [Index(value = ["sessionId"]), Index(value = ["problemId"])]
|
],
|
||||||
|
indices = [Index(value = ["sessionId"]), Index(value = ["problemId"])],
|
||||||
)
|
)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Attempt(
|
data class Attempt(
|
||||||
@PrimaryKey val id: String,
|
@PrimaryKey val id: String,
|
||||||
val sessionId: String,
|
val sessionId: String,
|
||||||
val problemId: String,
|
val problemId: String,
|
||||||
val result: AttemptResult,
|
val result: AttemptResult,
|
||||||
val highestHold: String? = null,
|
val highestHold: String? = null,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val duration: Long? = null,
|
val duration: Long? = null,
|
||||||
val restTime: Long? = null,
|
val restTime: Long? = null,
|
||||||
val timestamp: String,
|
val timestamp: String,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(
|
fun create(
|
||||||
sessionId: String,
|
sessionId: String,
|
||||||
problemId: String,
|
problemId: String,
|
||||||
result: AttemptResult,
|
result: AttemptResult,
|
||||||
highestHold: String? = null,
|
highestHold: String? = null,
|
||||||
notes: String? = null,
|
notes: String? = null,
|
||||||
duration: Long? = null,
|
duration: Long? = null,
|
||||||
restTime: Long? = null,
|
restTime: Long? = null,
|
||||||
timestamp: String = DateFormatUtils.nowISO8601()
|
timestamp: String = DateFormatUtils.nowISO8601(),
|
||||||
): Attempt {
|
): Attempt {
|
||||||
val now = DateFormatUtils.nowISO8601()
|
val now = DateFormatUtils.nowISO8601()
|
||||||
return Attempt(
|
return Attempt(
|
||||||
id = java.util.UUID.randomUUID().toString(),
|
id = java.util.UUID.randomUUID().toString(),
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
problemId = problemId,
|
problemId = problemId,
|
||||||
result = result,
|
result = result,
|
||||||
highestHold = highestHold,
|
highestHold = highestHold,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
duration = duration,
|
duration = duration,
|
||||||
restTime = restTime,
|
restTime = restTime,
|
||||||
timestamp = timestamp,
|
timestamp = timestamp,
|
||||||
createdAt = now,
|
createdAt = now,
|
||||||
updatedAt = now
|
updatedAt = now,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,69 +11,74 @@ import kotlinx.serialization.Serializable
|
|||||||
enum class SessionStatus {
|
enum class SessionStatus {
|
||||||
ACTIVE,
|
ACTIVE,
|
||||||
COMPLETED,
|
COMPLETED,
|
||||||
PAUSED
|
PAUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "climb_sessions",
|
tableName = "climb_sessions",
|
||||||
foreignKeys =
|
foreignKeys =
|
||||||
[
|
[
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = Gym::class,
|
entity = Gym::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["gymId"],
|
childColumns = ["gymId"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
)],
|
),
|
||||||
indices = [Index(value = ["gymId"])]
|
],
|
||||||
|
indices = [Index(value = ["gymId"])],
|
||||||
)
|
)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ClimbSession(
|
data class ClimbSession(
|
||||||
@PrimaryKey val id: String,
|
@PrimaryKey val id: String,
|
||||||
val gymId: String,
|
val gymId: String,
|
||||||
val date: String,
|
val date: String,
|
||||||
val startTime: String? = null,
|
val startTime: String? = null,
|
||||||
val endTime: String? = null,
|
val endTime: String? = null,
|
||||||
val duration: Long? = null,
|
val duration: Long? = null,
|
||||||
val status: SessionStatus = SessionStatus.ACTIVE,
|
val status: SessionStatus = SessionStatus.ACTIVE,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(gymId: String, notes: String? = null): ClimbSession {
|
fun create(gymId: String, notes: String? = null): ClimbSession {
|
||||||
val now = DateFormatUtils.nowISO8601()
|
val now = DateFormatUtils.nowISO8601()
|
||||||
return ClimbSession(
|
return ClimbSession(
|
||||||
id = java.util.UUID.randomUUID().toString(),
|
id = java.util.UUID.randomUUID().toString(),
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
date = now,
|
date = now,
|
||||||
startTime = now,
|
startTime = now,
|
||||||
status = SessionStatus.ACTIVE,
|
status = SessionStatus.ACTIVE,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = now,
|
createdAt = now,
|
||||||
updatedAt = now
|
updatedAt = now,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ClimbSession.complete(): ClimbSession {
|
fun ClimbSession.complete(): ClimbSession {
|
||||||
val endTime = DateFormatUtils.nowISO8601()
|
val endTime = DateFormatUtils.nowISO8601()
|
||||||
val durationMinutes =
|
val durationMinutes =
|
||||||
if (startTime != null) {
|
if (startTime != null) {
|
||||||
try {
|
try {
|
||||||
val start = DateFormatUtils.parseISO8601(startTime)
|
val start = DateFormatUtils.parseISO8601(startTime)
|
||||||
val end = DateFormatUtils.parseISO8601(endTime)
|
val end = DateFormatUtils.parseISO8601(endTime)
|
||||||
if (start != null && end != null) {
|
if (start != null && end != null) {
|
||||||
java.time.Duration.between(start, end).toMinutes()
|
java.time.Duration.between(start, end).toMinutes()
|
||||||
} else null
|
} else {
|
||||||
} catch (_: Exception) {
|
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
} else null
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
return this.copy(
|
return this.copy(
|
||||||
endTime = endTime,
|
endTime = endTime,
|
||||||
duration = durationMinutes,
|
duration = durationMinutes,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
updatedAt = DateFormatUtils.nowISO8601()
|
updatedAt = DateFormatUtils.nowISO8601(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,13 @@ import kotlinx.serialization.Serializable
|
|||||||
@Serializable
|
@Serializable
|
||||||
enum class ClimbType {
|
enum class ClimbType {
|
||||||
ROPE,
|
ROPE,
|
||||||
BOULDER;
|
BOULDER,
|
||||||
|
;
|
||||||
|
|
||||||
val displayName: String
|
val displayName: String
|
||||||
get() =
|
get() =
|
||||||
when (this) {
|
when (this) {
|
||||||
ROPE -> "Rope"
|
ROPE -> "Rope"
|
||||||
BOULDER -> "Bouldering"
|
BOULDER -> "Bouldering"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,132 +10,133 @@ enum class DifficultySystem {
|
|||||||
|
|
||||||
// Rope
|
// Rope
|
||||||
YDS,
|
YDS,
|
||||||
CUSTOM;
|
CUSTOM,
|
||||||
|
;
|
||||||
|
|
||||||
val displayName: String
|
val displayName: String
|
||||||
get() =
|
get() =
|
||||||
when (this) {
|
when (this) {
|
||||||
V_SCALE -> "V Scale"
|
V_SCALE -> "V Scale"
|
||||||
FONT -> "Font Scale"
|
FONT -> "Font Scale"
|
||||||
YDS -> "YDS (Yosemite)"
|
YDS -> "YDS (Yosemite)"
|
||||||
CUSTOM -> "Custom"
|
CUSTOM -> "Custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
val isBoulderingSystem: Boolean
|
val isBoulderingSystem: Boolean
|
||||||
get() =
|
get() =
|
||||||
when (this) {
|
when (this) {
|
||||||
V_SCALE, FONT -> true
|
V_SCALE, FONT -> true
|
||||||
YDS -> false
|
YDS -> false
|
||||||
CUSTOM -> true
|
CUSTOM -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
val isRopeSystem: Boolean
|
val isRopeSystem: Boolean
|
||||||
get() =
|
get() =
|
||||||
when (this) {
|
when (this) {
|
||||||
YDS -> true
|
YDS -> true
|
||||||
V_SCALE, FONT -> false
|
V_SCALE, FONT -> false
|
||||||
CUSTOM -> true
|
CUSTOM -> true
|
||||||
}
|
}
|
||||||
|
|
||||||
val availableGrades: List<String>
|
val availableGrades: List<String>
|
||||||
get() =
|
get() =
|
||||||
when (this) {
|
when (this) {
|
||||||
V_SCALE ->
|
V_SCALE ->
|
||||||
listOf(
|
listOf(
|
||||||
"VB",
|
"VB",
|
||||||
"V0",
|
"V0",
|
||||||
"V1",
|
"V1",
|
||||||
"V2",
|
"V2",
|
||||||
"V3",
|
"V3",
|
||||||
"V4",
|
"V4",
|
||||||
"V5",
|
"V5",
|
||||||
"V6",
|
"V6",
|
||||||
"V7",
|
"V7",
|
||||||
"V8",
|
"V8",
|
||||||
"V9",
|
"V9",
|
||||||
"V10",
|
"V10",
|
||||||
"V11",
|
"V11",
|
||||||
"V12",
|
"V12",
|
||||||
"V13",
|
"V13",
|
||||||
"V14",
|
"V14",
|
||||||
"V15",
|
"V15",
|
||||||
"V16",
|
"V16",
|
||||||
"V17"
|
"V17",
|
||||||
)
|
)
|
||||||
FONT ->
|
FONT ->
|
||||||
listOf(
|
listOf(
|
||||||
"3",
|
"3",
|
||||||
"4A",
|
"4A",
|
||||||
"4B",
|
"4B",
|
||||||
"4C",
|
"4C",
|
||||||
"5A",
|
"5A",
|
||||||
"5B",
|
"5B",
|
||||||
"5C",
|
"5C",
|
||||||
"6A",
|
"6A",
|
||||||
"6A+",
|
"6A+",
|
||||||
"6B",
|
"6B",
|
||||||
"6B+",
|
"6B+",
|
||||||
"6C",
|
"6C",
|
||||||
"6C+",
|
"6C+",
|
||||||
"7A",
|
"7A",
|
||||||
"7A+",
|
"7A+",
|
||||||
"7B",
|
"7B",
|
||||||
"7B+",
|
"7B+",
|
||||||
"7C",
|
"7C",
|
||||||
"7C+",
|
"7C+",
|
||||||
"8A",
|
"8A",
|
||||||
"8A+",
|
"8A+",
|
||||||
"8B",
|
"8B",
|
||||||
"8B+",
|
"8B+",
|
||||||
"8C",
|
"8C",
|
||||||
"8C+"
|
"8C+",
|
||||||
)
|
)
|
||||||
YDS ->
|
YDS ->
|
||||||
listOf(
|
listOf(
|
||||||
"5.0",
|
"5.0",
|
||||||
"5.1",
|
"5.1",
|
||||||
"5.2",
|
"5.2",
|
||||||
"5.3",
|
"5.3",
|
||||||
"5.4",
|
"5.4",
|
||||||
"5.5",
|
"5.5",
|
||||||
"5.6",
|
"5.6",
|
||||||
"5.7",
|
"5.7",
|
||||||
"5.8",
|
"5.8",
|
||||||
"5.9",
|
"5.9",
|
||||||
"5.10a",
|
"5.10a",
|
||||||
"5.10b",
|
"5.10b",
|
||||||
"5.10c",
|
"5.10c",
|
||||||
"5.10d",
|
"5.10d",
|
||||||
"5.11a",
|
"5.11a",
|
||||||
"5.11b",
|
"5.11b",
|
||||||
"5.11c",
|
"5.11c",
|
||||||
"5.11d",
|
"5.11d",
|
||||||
"5.12a",
|
"5.12a",
|
||||||
"5.12b",
|
"5.12b",
|
||||||
"5.12c",
|
"5.12c",
|
||||||
"5.12d",
|
"5.12d",
|
||||||
"5.13a",
|
"5.13a",
|
||||||
"5.13b",
|
"5.13b",
|
||||||
"5.13c",
|
"5.13c",
|
||||||
"5.13d",
|
"5.13d",
|
||||||
"5.14a",
|
"5.14a",
|
||||||
"5.14b",
|
"5.14b",
|
||||||
"5.14c",
|
"5.14c",
|
||||||
"5.14d",
|
"5.14d",
|
||||||
"5.15a",
|
"5.15a",
|
||||||
"5.15b",
|
"5.15b",
|
||||||
"5.15c",
|
"5.15c",
|
||||||
"5.15d"
|
"5.15d",
|
||||||
)
|
)
|
||||||
CUSTOM -> emptyList()
|
CUSTOM -> emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun systemsForClimbType(climbType: ClimbType): List<DifficultySystem> =
|
fun systemsForClimbType(climbType: ClimbType): List<DifficultySystem> =
|
||||||
when (climbType) {
|
when (climbType) {
|
||||||
ClimbType.BOULDER -> entries.filter { it.isBoulderingSystem }
|
ClimbType.BOULDER -> entries.filter { it.isBoulderingSystem }
|
||||||
ClimbType.ROPE -> entries.filter { it.isRopeSystem }
|
ClimbType.ROPE -> entries.filter { it.isRopeSystem }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,8 +144,8 @@ enum class DifficultySystem {
|
|||||||
data class DifficultyGrade(val system: DifficultySystem, val grade: String, val numericValue: Int) {
|
data class DifficultyGrade(val system: DifficultySystem, val grade: String, val numericValue: Int) {
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
system: DifficultySystem,
|
system: DifficultySystem,
|
||||||
grade: String
|
grade: String,
|
||||||
) : this(system = system, grade = grade, numericValue = calculateNumericValue(system, grade))
|
) : this(system = system, grade = grade, numericValue = calculateNumericValue(system, grade))
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -155,79 +156,80 @@ data class DifficultyGrade(val system: DifficultySystem, val grade: String, val
|
|||||||
}
|
}
|
||||||
DifficultySystem.FONT -> {
|
DifficultySystem.FONT -> {
|
||||||
val fontMapping: Map<String, Int> =
|
val fontMapping: Map<String, Int> =
|
||||||
mapOf(
|
mapOf(
|
||||||
"3" to 3,
|
"3" to 3,
|
||||||
"4A" to 4,
|
"4A" to 4,
|
||||||
"4B" to 5,
|
"4B" to 5,
|
||||||
"4C" to 6,
|
"4C" to 6,
|
||||||
"5A" to 7,
|
"5A" to 7,
|
||||||
"5B" to 8,
|
"5B" to 8,
|
||||||
"5C" to 9,
|
"5C" to 9,
|
||||||
"6A" to 10,
|
"6A" to 10,
|
||||||
"6A+" to 11,
|
"6A+" to 11,
|
||||||
"6B" to 12,
|
"6B" to 12,
|
||||||
"6B+" to 13,
|
"6B+" to 13,
|
||||||
"6C" to 14,
|
"6C" to 14,
|
||||||
"6C+" to 15,
|
"6C+" to 15,
|
||||||
"7A" to 16,
|
"7A" to 16,
|
||||||
"7A+" to 17,
|
"7A+" to 17,
|
||||||
"7B" to 18,
|
"7B" to 18,
|
||||||
"7B+" to 19,
|
"7B+" to 19,
|
||||||
"7C" to 20,
|
"7C" to 20,
|
||||||
"7C+" to 21,
|
"7C+" to 21,
|
||||||
"8A" to 22,
|
"8A" to 22,
|
||||||
"8A+" to 23,
|
"8A+" to 23,
|
||||||
"8B" to 24,
|
"8B" to 24,
|
||||||
"8B+" to 25,
|
"8B+" to 25,
|
||||||
"8C" to 26,
|
"8C" to 26,
|
||||||
"8C+" to 27
|
"8C+" to 27,
|
||||||
)
|
)
|
||||||
fontMapping[grade] ?: 0
|
fontMapping[grade] ?: 0
|
||||||
}
|
}
|
||||||
DifficultySystem.YDS -> {
|
DifficultySystem.YDS -> {
|
||||||
val ydsMapping: Map<String, Int> =
|
val ydsMapping: Map<String, Int> =
|
||||||
mapOf(
|
mapOf(
|
||||||
"5.0" to 50,
|
"5.0" to 50,
|
||||||
"5.1" to 51,
|
"5.1" to 51,
|
||||||
"5.2" to 52,
|
"5.2" to 52,
|
||||||
"5.3" to 53,
|
"5.3" to 53,
|
||||||
"5.4" to 54,
|
"5.4" to 54,
|
||||||
"5.5" to 55,
|
"5.5" to 55,
|
||||||
"5.6" to 56,
|
"5.6" to 56,
|
||||||
"5.7" to 57,
|
"5.7" to 57,
|
||||||
"5.8" to 58,
|
"5.8" to 58,
|
||||||
"5.9" to 59,
|
"5.9" to 59,
|
||||||
"5.10a" to 60,
|
"5.10a" to 60,
|
||||||
"5.10b" to 61,
|
"5.10b" to 61,
|
||||||
"5.10c" to 62,
|
"5.10c" to 62,
|
||||||
"5.10d" to 63,
|
"5.10d" to 63,
|
||||||
"5.11a" to 64,
|
"5.11a" to 64,
|
||||||
"5.11b" to 65,
|
"5.11b" to 65,
|
||||||
"5.11c" to 66,
|
"5.11c" to 66,
|
||||||
"5.11d" to 67,
|
"5.11d" to 67,
|
||||||
"5.12a" to 68,
|
"5.12a" to 68,
|
||||||
"5.12b" to 69,
|
"5.12b" to 69,
|
||||||
"5.12c" to 70,
|
"5.12c" to 70,
|
||||||
"5.12d" to 71,
|
"5.12d" to 71,
|
||||||
"5.13a" to 72,
|
"5.13a" to 72,
|
||||||
"5.13b" to 73,
|
"5.13b" to 73,
|
||||||
"5.13c" to 74,
|
"5.13c" to 74,
|
||||||
"5.13d" to 75,
|
"5.13d" to 75,
|
||||||
"5.14a" to 76,
|
"5.14a" to 76,
|
||||||
"5.14b" to 77,
|
"5.14b" to 77,
|
||||||
"5.14c" to 78,
|
"5.14c" to 78,
|
||||||
"5.14d" to 79,
|
"5.14d" to 79,
|
||||||
"5.15a" to 80,
|
"5.15a" to 80,
|
||||||
"5.15b" to 81,
|
"5.15b" to 81,
|
||||||
"5.15c" to 82,
|
"5.15c" to 82,
|
||||||
"5.15d" to 83
|
"5.15d" to 83,
|
||||||
)
|
)
|
||||||
ydsMapping[grade] ?: 0
|
ydsMapping[grade] ?: 0
|
||||||
}
|
}
|
||||||
DifficultySystem.CUSTOM -> grade.toIntOrNull() ?: 0
|
DifficultySystem.CUSTOM -> grade.toIntOrNull() ?: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare this grade with another grade of the same system Returns negative if this grade is
|
* Compare this grade with another grade of the same system Returns negative if this grade is
|
||||||
* easier, positive if harder, 0 if equal
|
* easier, positive if harder, 0 if equal
|
||||||
|
|||||||
@@ -8,36 +8,36 @@ import kotlinx.serialization.Serializable
|
|||||||
@Entity(tableName = "gyms")
|
@Entity(tableName = "gyms")
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Gym(
|
data class Gym(
|
||||||
@PrimaryKey val id: String,
|
@PrimaryKey val id: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val location: String? = null,
|
val location: String? = null,
|
||||||
val supportedClimbTypes: List<ClimbType>,
|
val supportedClimbTypes: List<ClimbType>,
|
||||||
val difficultySystems: List<DifficultySystem>,
|
val difficultySystems: List<DifficultySystem>,
|
||||||
val customDifficultyGrades: List<String> = emptyList(),
|
val customDifficultyGrades: List<String> = emptyList(),
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(
|
fun create(
|
||||||
name: String,
|
name: String,
|
||||||
location: String? = null,
|
location: String? = null,
|
||||||
supportedClimbTypes: List<ClimbType>,
|
supportedClimbTypes: List<ClimbType>,
|
||||||
difficultySystems: List<DifficultySystem>,
|
difficultySystems: List<DifficultySystem>,
|
||||||
customDifficultyGrades: List<String> = emptyList(),
|
customDifficultyGrades: List<String> = emptyList(),
|
||||||
notes: String? = null
|
notes: String? = null,
|
||||||
): Gym {
|
): Gym {
|
||||||
val now = DateFormatUtils.nowISO8601()
|
val now = DateFormatUtils.nowISO8601()
|
||||||
return Gym(
|
return Gym(
|
||||||
id = java.util.UUID.randomUUID().toString(),
|
id = java.util.UUID.randomUUID().toString(),
|
||||||
name = name,
|
name = name,
|
||||||
location = location,
|
location = location,
|
||||||
supportedClimbTypes = supportedClimbTypes,
|
supportedClimbTypes = supportedClimbTypes,
|
||||||
difficultySystems = difficultySystems,
|
difficultySystems = difficultySystems,
|
||||||
customDifficultyGrades = customDifficultyGrades,
|
customDifficultyGrades = customDifficultyGrades,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = now,
|
createdAt = now,
|
||||||
updatedAt = now
|
updatedAt = now,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,63 +8,64 @@ import com.atridad.ascently.utils.DateFormatUtils
|
|||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "problems",
|
tableName = "problems",
|
||||||
foreignKeys =
|
foreignKeys =
|
||||||
[
|
[
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = Gym::class,
|
entity = Gym::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["gymId"],
|
childColumns = ["gymId"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE,
|
||||||
)],
|
),
|
||||||
indices = [Index(value = ["gymId"])]
|
],
|
||||||
|
indices = [Index(value = ["gymId"])],
|
||||||
)
|
)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Problem(
|
data class Problem(
|
||||||
@PrimaryKey val id: String,
|
@PrimaryKey val id: String,
|
||||||
val gymId: String,
|
val gymId: String,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val description: String? = null,
|
val description: String? = null,
|
||||||
val climbType: ClimbType,
|
val climbType: ClimbType,
|
||||||
val difficulty: DifficultyGrade,
|
val difficulty: DifficultyGrade,
|
||||||
val tags: List<String> = emptyList(),
|
val tags: List<String> = emptyList(),
|
||||||
val location: String? = null,
|
val location: String? = null,
|
||||||
val imagePaths: List<String> = emptyList(),
|
val imagePaths: List<String> = emptyList(),
|
||||||
val isActive: Boolean = true,
|
val isActive: Boolean = true,
|
||||||
val dateSet: String? = null,
|
val dateSet: String? = null,
|
||||||
val notes: String? = null,
|
val notes: String? = null,
|
||||||
val createdAt: String,
|
val createdAt: String,
|
||||||
val updatedAt: String
|
val updatedAt: String,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun create(
|
fun create(
|
||||||
gymId: String,
|
gymId: String,
|
||||||
name: String? = null,
|
name: String? = null,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
climbType: ClimbType,
|
climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade,
|
difficulty: DifficultyGrade,
|
||||||
tags: List<String> = emptyList(),
|
tags: List<String> = emptyList(),
|
||||||
location: String? = null,
|
location: String? = null,
|
||||||
imagePaths: List<String> = emptyList(),
|
imagePaths: List<String> = emptyList(),
|
||||||
dateSet: String? = null,
|
dateSet: String? = null,
|
||||||
notes: String? = null
|
notes: String? = null,
|
||||||
): Problem {
|
): Problem {
|
||||||
val now = DateFormatUtils.nowISO8601()
|
val now = DateFormatUtils.nowISO8601()
|
||||||
return Problem(
|
return Problem(
|
||||||
id = java.util.UUID.randomUUID().toString(),
|
id = java.util.UUID.randomUUID().toString(),
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
name = name,
|
name = name,
|
||||||
description = description,
|
description = description,
|
||||||
climbType = climbType,
|
climbType = climbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
tags = tags,
|
tags = tags,
|
||||||
location = location,
|
location = location,
|
||||||
imagePaths = imagePaths,
|
imagePaths = imagePaths,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = dateSet,
|
dateSet = dateSet,
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = now,
|
createdAt = now,
|
||||||
updatedAt = now
|
updatedAt = now,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import com.atridad.ascently.data.format.ClimbDataBackup
|
|||||||
import com.atridad.ascently.data.format.DeletedItem
|
import com.atridad.ascently.data.format.DeletedItem
|
||||||
import com.atridad.ascently.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import com.atridad.ascently.data.state.DataStateManager
|
import com.atridad.ascently.data.state.DataStateManager
|
||||||
import com.atridad.ascently.utils.DateFormatUtils
|
|
||||||
import com.atridad.ascently.utils.AppLogger
|
import com.atridad.ascently.utils.AppLogger
|
||||||
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import com.atridad.ascently.utils.ZipExportImportUtils
|
import com.atridad.ascently.utils.ZipExportImportUtils
|
||||||
import java.io.File
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ClimbRepository(database: AscentlyDatabase, private val context: Context) {
|
class ClimbRepository(database: AscentlyDatabase, private val context: Context) {
|
||||||
private val gymDao = database.gymDao()
|
private val gymDao = database.gymDao()
|
||||||
@@ -161,7 +161,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
gyms = allGyms.map { BackupGym.fromGym(it) },
|
gyms = allGyms.map { BackupGym.fromGym(it) },
|
||||||
problems = allProblems.map { BackupProblem.fromProblem(it) },
|
problems = allProblems.map { BackupProblem.fromProblem(it) },
|
||||||
sessions = allSessions.map { BackupClimbSession.fromClimbSession(it) },
|
sessions = allSessions.map { BackupClimbSession.fromClimbSession(it) },
|
||||||
attempts = allAttempts.map { BackupAttempt.fromAttempt(it) }
|
attempts = allAttempts.map { BackupAttempt.fromAttempt(it) },
|
||||||
)
|
)
|
||||||
|
|
||||||
val referencedImagePaths = allProblems.flatMap { it.imagePaths }.toSet()
|
val referencedImagePaths = allProblems.flatMap { it.imagePaths }.toSet()
|
||||||
@@ -172,7 +172,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
val imageFile =
|
val imageFile =
|
||||||
com.atridad.ascently.utils.ImageUtils.getImageFile(
|
com.atridad.ascently.utils.ImageUtils.getImageFile(
|
||||||
context,
|
context,
|
||||||
imagePath
|
imagePath,
|
||||||
)
|
)
|
||||||
imageFile.exists() && imageFile.length() > 0
|
imageFile.exists() && imageFile.length() > 0
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
@@ -185,7 +185,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
context = context,
|
context = context,
|
||||||
uri = uri,
|
uri = uri,
|
||||||
exportData = backupData,
|
exportData = backupData,
|
||||||
referencedImagePaths = validImagePaths
|
referencedImagePaths = validImagePaths,
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw Exception("Export failed: ${e.message}")
|
throw Exception("Export failed: ${e.message}")
|
||||||
@@ -229,7 +229,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
val updatedBackupProblems =
|
val updatedBackupProblems =
|
||||||
ZipExportImportUtils.updateProblemImagePaths(
|
ZipExportImportUtils.updateProblemImagePaths(
|
||||||
importData.problems,
|
importData.problems,
|
||||||
importResult.importedImagePaths
|
importResult.importedImagePaths,
|
||||||
)
|
)
|
||||||
|
|
||||||
updatedBackupProblems.forEach { backupProblem ->
|
updatedBackupProblems.forEach { backupProblem ->
|
||||||
@@ -237,7 +237,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
problemDao.insertProblem(backupProblem.toProblem())
|
problemDao.insertProblem(backupProblem.toProblem())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Failed to import problem '${backupProblem.name}': ${e.message}"
|
"Failed to import problem '${backupProblem.name}': ${e.message}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
currentDeletions.add(newDeletion)
|
currentDeletions.add(newDeletion)
|
||||||
|
|
||||||
val json = json.encodeToString(newDeletion)
|
val json = json.encodeToString(newDeletion)
|
||||||
deletionPreferences.edit { putString("deleted_${itemId}", json) }
|
deletionPreferences.edit { putString("deleted_$itemId", json) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDeletedItems(): List<DeletedItem> {
|
fun getDeletedItems(): List<DeletedItem> {
|
||||||
@@ -308,20 +308,20 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
gyms: List<Gym>,
|
gyms: List<Gym>,
|
||||||
problems: List<Problem>,
|
problems: List<Problem>,
|
||||||
sessions: List<ClimbSession>,
|
sessions: List<ClimbSession>,
|
||||||
attempts: List<Attempt>
|
attempts: List<Attempt>,
|
||||||
) {
|
) {
|
||||||
val gymIds = gyms.map { it.id }.toSet()
|
val gymIds = gyms.map { it.id }.toSet()
|
||||||
val invalidProblems = problems.filter { it.gymId !in gymIds }
|
val invalidProblems = problems.filter { it.gymId !in gymIds }
|
||||||
if (invalidProblems.isNotEmpty()) {
|
if (invalidProblems.isNotEmpty()) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Data integrity error: ${invalidProblems.size} problems reference non-existent gyms"
|
"Data integrity error: ${invalidProblems.size} problems reference non-existent gyms",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val invalidSessions = sessions.filter { it.gymId !in gymIds }
|
val invalidSessions = sessions.filter { it.gymId !in gymIds }
|
||||||
if (invalidSessions.isNotEmpty()) {
|
if (invalidSessions.isNotEmpty()) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Data integrity error: ${invalidSessions.size} sessions reference non-existent gyms"
|
"Data integrity error: ${invalidSessions.size} sessions reference non-existent gyms",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
|||||||
attempts.filter { it.problemId !in problemIds || it.sessionId !in sessionIds }
|
attempts.filter { it.problemId !in problemIds || it.sessionId !in sessionIds }
|
||||||
if (invalidAttempts.isNotEmpty()) {
|
if (invalidAttempts.isNotEmpty()) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Data integrity error: ${invalidAttempts.size} attempts reference non-existent problems or sessions"
|
"Data integrity error: ${invalidAttempts.size} attempts reference non-existent problems or sessions",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,11 +17,6 @@ import com.atridad.ascently.utils.AppLogger
|
|||||||
import com.atridad.ascently.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import com.atridad.ascently.utils.ImageNamingUtils
|
import com.atridad.ascently.utils.ImageNamingUtils
|
||||||
import com.atridad.ascently.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import java.io.IOException
|
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.Locale
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
@@ -34,10 +29,15 @@ import okhttp3.MediaType.Companion.toMediaType
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import java.io.IOException
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class AscentlySyncProvider(
|
class AscentlySyncProvider(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val repository: ClimbRepository
|
private val repository: ClimbRepository,
|
||||||
) : SyncProvider {
|
) : SyncProvider {
|
||||||
|
|
||||||
override val type: SyncProviderType = SyncProviderType.SERVER
|
override val type: SyncProviderType = SyncProviderType.SERVER
|
||||||
@@ -148,15 +148,15 @@ class AscentlySyncProvider(
|
|||||||
|
|
||||||
val hasLocalData =
|
val hasLocalData =
|
||||||
localBackup.gyms.isNotEmpty() ||
|
localBackup.gyms.isNotEmpty() ||
|
||||||
localBackup.problems.isNotEmpty() ||
|
localBackup.problems.isNotEmpty() ||
|
||||||
localBackup.sessions.isNotEmpty() ||
|
localBackup.sessions.isNotEmpty() ||
|
||||||
localBackup.attempts.isNotEmpty()
|
localBackup.attempts.isNotEmpty()
|
||||||
|
|
||||||
val hasServerData =
|
val hasServerData =
|
||||||
serverBackup.gyms.isNotEmpty() ||
|
serverBackup.gyms.isNotEmpty() ||
|
||||||
serverBackup.problems.isNotEmpty() ||
|
serverBackup.problems.isNotEmpty() ||
|
||||||
serverBackup.sessions.isNotEmpty() ||
|
serverBackup.sessions.isNotEmpty() ||
|
||||||
serverBackup.attempts.isNotEmpty()
|
serverBackup.attempts.isNotEmpty()
|
||||||
|
|
||||||
val lastSyncTimeStr = sharedPreferences.getString(Keys.LAST_SYNC_TIME, null)
|
val lastSyncTimeStr = sharedPreferences.getString(Keys.LAST_SYNC_TIME, null)
|
||||||
if (hasLocalData && hasServerData && lastSyncTimeStr != null) {
|
if (hasLocalData && hasServerData && lastSyncTimeStr != null) {
|
||||||
@@ -268,7 +268,7 @@ class AscentlySyncProvider(
|
|||||||
problems = modifiedProblems,
|
problems = modifiedProblems,
|
||||||
sessions = modifiedSessions,
|
sessions = modifiedSessions,
|
||||||
attempts = modifiedAttempts,
|
attempts = modifiedAttempts,
|
||||||
deletedItems = modifiedDeletions
|
deletedItems = modifiedDeletions,
|
||||||
)
|
)
|
||||||
|
|
||||||
val requestBody =
|
val requestBody =
|
||||||
@@ -303,7 +303,9 @@ class AscentlySyncProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
AppLogger.d(TAG) {
|
AppLogger.d(TAG) {
|
||||||
"Delta sync received: gyms=${deltaResponse.gyms.size}, problems=${deltaResponse.problems.size}, sessions=${deltaResponse.sessions.size}, attempts=${deltaResponse.attempts.size}, deletions=${deltaResponse.deletedItems.size}"
|
"Delta sync received: gyms=${deltaResponse.gyms.size}, " +
|
||||||
|
"problems=${deltaResponse.problems.size}, sessions=${deltaResponse.sessions.size}, " +
|
||||||
|
"attempts=${deltaResponse.attempts.size}, deletions=${deltaResponse.deletedItems.size}"
|
||||||
}
|
}
|
||||||
|
|
||||||
applyDeltaResponse(deltaResponse)
|
applyDeltaResponse(deltaResponse)
|
||||||
@@ -440,7 +442,7 @@ class AscentlySyncProvider(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun applyDeletions(
|
private suspend fun applyDeletions(
|
||||||
deletions: List<com.atridad.ascently.data.format.DeletedItem>
|
deletions: List<com.atridad.ascently.data.format.DeletedItem>,
|
||||||
) {
|
) {
|
||||||
val existingGyms = repository.getAllGyms().first()
|
val existingGyms = repository.getAllGyms().first()
|
||||||
val existingProblems = repository.getAllProblems().first()
|
val existingProblems = repository.getAllProblems().first()
|
||||||
@@ -502,7 +504,7 @@ class AscentlySyncProvider(
|
|||||||
gyms = emptyList(),
|
gyms = emptyList(),
|
||||||
problems = emptyList(),
|
problems = emptyList(),
|
||||||
sessions = emptyList(),
|
sessions = emptyList(),
|
||||||
attempts = emptyList()
|
attempts = emptyList(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -643,37 +645,37 @@ class AscentlySyncProvider(
|
|||||||
exportedAt = dataStateManager.getLastModified(),
|
exportedAt = dataStateManager.getLastModified(),
|
||||||
gyms = repository.getAllGyms().first().map { BackupGym.fromGym(it) },
|
gyms = repository.getAllGyms().first().map { BackupGym.fromGym(it) },
|
||||||
problems =
|
problems =
|
||||||
repository.getAllProblems().first().map { problem ->
|
repository.getAllProblems().first().map { problem ->
|
||||||
val backupProblem = BackupProblem.fromProblem(problem)
|
val backupProblem = BackupProblem.fromProblem(problem)
|
||||||
val normalizedImagePaths =
|
val normalizedImagePaths =
|
||||||
problem.imagePaths.mapIndexed { index, _ ->
|
problem.imagePaths.mapIndexed { index, _ ->
|
||||||
ImageNamingUtils.generateImageFilename(
|
ImageNamingUtils.generateImageFilename(
|
||||||
problem.id,
|
problem.id,
|
||||||
index
|
index,
|
||||||
)
|
)
|
||||||
}
|
|
||||||
if (normalizedImagePaths.isNotEmpty()) {
|
|
||||||
backupProblem.copy(imagePaths = normalizedImagePaths)
|
|
||||||
} else {
|
|
||||||
backupProblem
|
|
||||||
}
|
}
|
||||||
},
|
if (normalizedImagePaths.isNotEmpty()) {
|
||||||
|
backupProblem.copy(imagePaths = normalizedImagePaths)
|
||||||
|
} else {
|
||||||
|
backupProblem
|
||||||
|
}
|
||||||
|
},
|
||||||
sessions =
|
sessions =
|
||||||
repository.getAllSessions().first().map {
|
repository.getAllSessions().first().map {
|
||||||
BackupClimbSession.fromClimbSession(it)
|
BackupClimbSession.fromClimbSession(it)
|
||||||
},
|
},
|
||||||
attempts =
|
attempts =
|
||||||
repository.getAllAttempts().first().map {
|
repository.getAllAttempts().first().map {
|
||||||
BackupAttempt.fromAttempt(it)
|
BackupAttempt.fromAttempt(it)
|
||||||
},
|
},
|
||||||
deletedItems = repository.getDeletedItems()
|
deletedItems = repository.getDeletedItems(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun importBackupToRepository(
|
private suspend fun importBackupToRepository(
|
||||||
backup: ClimbDataBackup,
|
backup: ClimbDataBackup,
|
||||||
imagePathMapping: Map<String, String>
|
imagePathMapping: Map<String, String>,
|
||||||
) {
|
) {
|
||||||
val gyms = backup.gyms.map { it.toGym() }
|
val gyms = backup.gyms.map { it.toGym() }
|
||||||
val problems =
|
val problems =
|
||||||
|
|||||||
@@ -10,21 +10,21 @@ import kotlinx.serialization.Serializable
|
|||||||
/** Request structure for delta sync - sends only changes since last sync */
|
/** Request structure for delta sync - sends only changes since last sync */
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DeltaSyncRequest(
|
data class DeltaSyncRequest(
|
||||||
val lastSyncTime: String,
|
val lastSyncTime: String,
|
||||||
val gyms: List<BackupGym>,
|
val gyms: List<BackupGym>,
|
||||||
val problems: List<BackupProblem>,
|
val problems: List<BackupProblem>,
|
||||||
val sessions: List<BackupClimbSession>,
|
val sessions: List<BackupClimbSession>,
|
||||||
val attempts: List<BackupAttempt>,
|
val attempts: List<BackupAttempt>,
|
||||||
val deletedItems: List<DeletedItem>
|
val deletedItems: List<DeletedItem>,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Response structure for delta sync - receives only changes from server */
|
/** Response structure for delta sync - receives only changes from server */
|
||||||
@Serializable
|
@Serializable
|
||||||
data class DeltaSyncResponse(
|
data class DeltaSyncResponse(
|
||||||
val serverTime: String,
|
val serverTime: String,
|
||||||
val gyms: List<BackupGym>,
|
val gyms: List<BackupGym>,
|
||||||
val problems: List<BackupProblem>,
|
val problems: List<BackupProblem>,
|
||||||
val sessions: List<BackupClimbSession>,
|
val sessions: List<BackupClimbSession>,
|
||||||
val attempts: List<BackupAttempt>,
|
val attempts: List<BackupAttempt>,
|
||||||
val deletedItems: List<DeletedItem>
|
val deletedItems: List<DeletedItem>,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ interface SyncProvider {
|
|||||||
val type: SyncProviderType
|
val type: SyncProviderType
|
||||||
val isConfigured: StateFlow<Boolean>
|
val isConfigured: StateFlow<Boolean>
|
||||||
val isConnected: StateFlow<Boolean>
|
val isConnected: StateFlow<Boolean>
|
||||||
|
|
||||||
suspend fun sync()
|
suspend fun sync()
|
||||||
suspend fun testConnection()
|
suspend fun testConnection()
|
||||||
fun disconnect()
|
fun disconnect()
|
||||||
@@ -14,5 +14,5 @@ interface SyncProvider {
|
|||||||
|
|
||||||
enum class SyncProviderType {
|
enum class SyncProviderType {
|
||||||
NONE,
|
NONE,
|
||||||
SERVER
|
SERVER,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,10 +101,9 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
provider.sync()
|
provider.sync()
|
||||||
|
|
||||||
// Update last sync time from shared prefs (provider updates it)
|
// Update last sync time from shared prefs (provider updates it)
|
||||||
_lastSyncTime.value = sharedPreferences.getString(Keys.LAST_SYNC_TIME, null)
|
_lastSyncTime.value = sharedPreferences.getString(Keys.LAST_SYNC_TIME, null)
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_syncError.value = e.message
|
_syncError.value = e.message
|
||||||
throw e
|
throw e
|
||||||
|
|||||||
@@ -7,30 +7,30 @@ import androidx.compose.ui.graphics.vector.ImageVector
|
|||||||
data class BottomNavigationItem(val screen: Screen, val icon: ImageVector, val label: String)
|
data class BottomNavigationItem(val screen: Screen, val icon: ImageVector, val label: String)
|
||||||
|
|
||||||
val bottomNavigationItems =
|
val bottomNavigationItems =
|
||||||
listOf(
|
listOf(
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
screen = Screen.Sessions,
|
screen = Screen.Sessions,
|
||||||
icon = Icons.Default.PlayArrow,
|
icon = Icons.Default.PlayArrow,
|
||||||
label = "Sessions"
|
label = "Sessions",
|
||||||
),
|
),
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
screen = Screen.Problems,
|
screen = Screen.Problems,
|
||||||
icon = Icons.Default.Star,
|
icon = Icons.Default.Star,
|
||||||
label = "Problems"
|
label = "Problems",
|
||||||
),
|
),
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
screen = Screen.Analytics,
|
screen = Screen.Analytics,
|
||||||
icon = Icons.Default.Info,
|
icon = Icons.Default.Info,
|
||||||
label = "Analytics"
|
label = "Analytics",
|
||||||
),
|
),
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
screen = Screen.Gyms,
|
screen = Screen.Gyms,
|
||||||
icon = Icons.Default.LocationOn,
|
icon = Icons.Default.LocationOn,
|
||||||
label = "Gyms"
|
label = "Gyms",
|
||||||
),
|
),
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
screen = Screen.Settings,
|
screen = Screen.Settings,
|
||||||
icon = Icons.Default.Settings,
|
icon = Icons.Default.Settings,
|
||||||
label = "Settings"
|
label = "Settings",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -16,12 +16,12 @@ import com.atridad.ascently.data.database.AscentlyDatabase
|
|||||||
import com.atridad.ascently.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import com.atridad.ascently.utils.AppLogger
|
import com.atridad.ascently.utils.AppLogger
|
||||||
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.ZoneId
|
|
||||||
import java.time.temporal.ChronoUnit
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
import java.time.temporal.ChronoUnit
|
||||||
|
|
||||||
class SessionTrackingService : Service() {
|
class SessionTrackingService : Service() {
|
||||||
|
|
||||||
@@ -224,12 +224,12 @@ class SessionTrackingService : Service() {
|
|||||||
.addAction(
|
.addAction(
|
||||||
R.drawable.ic_mountains,
|
R.drawable.ic_mountains,
|
||||||
"Open Session",
|
"Open Session",
|
||||||
createOpenAppIntent()
|
createOpenAppIntent(),
|
||||||
)
|
)
|
||||||
.addAction(
|
.addAction(
|
||||||
android.R.drawable.ic_menu_close_clear_cancel,
|
android.R.drawable.ic_menu_close_clear_cancel,
|
||||||
"End Session",
|
"End Session",
|
||||||
createStopPendingIntent(sessionId)
|
createStopPendingIntent(sessionId),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Use Live Update
|
// Use Live Update
|
||||||
@@ -249,7 +249,7 @@ class SessionTrackingService : Service() {
|
|||||||
notificationBuilder
|
notificationBuilder
|
||||||
.setContentTitle("Climbing Session Active")
|
.setContentTitle("Climbing Session Active")
|
||||||
.setContentText(
|
.setContentText(
|
||||||
"${gym?.name ?: "Gym"} • ${attempts.size} attempts"
|
"${gym?.name ?: "Gym"} • ${attempts.size} attempts",
|
||||||
)
|
)
|
||||||
.setWhen(startTimeMillis)
|
.setWhen(startTimeMillis)
|
||||||
.setUsesChronometer(true)
|
.setUsesChronometer(true)
|
||||||
@@ -284,7 +284,7 @@ class SessionTrackingService : Service() {
|
|||||||
notificationBuilder
|
notificationBuilder
|
||||||
.setContentTitle("Climbing Session Active")
|
.setContentTitle("Climbing Session Active")
|
||||||
.setContentText(
|
.setContentText(
|
||||||
"${gym?.name ?: "Gym"} • $duration • ${attempts.size} attempts"
|
"${gym?.name ?: "Gym"} • $duration • ${attempts.size} attempts",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ class SessionTrackingService : Service() {
|
|||||||
this,
|
this,
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +319,7 @@ class SessionTrackingService : Service() {
|
|||||||
this,
|
this,
|
||||||
1,
|
1,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,7 +328,7 @@ class SessionTrackingService : Service() {
|
|||||||
NotificationChannel(
|
NotificationChannel(
|
||||||
CHANNEL_ID,
|
CHANNEL_ID,
|
||||||
"Session Tracking",
|
"Session Tracking",
|
||||||
NotificationManager.IMPORTANCE_DEFAULT
|
NotificationManager.IMPORTANCE_DEFAULT,
|
||||||
)
|
)
|
||||||
.apply {
|
.apply {
|
||||||
description = "Shows active climbing session information"
|
description = "Shows active climbing session information"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import com.atridad.ascently.utils.NotificationPermissionUtils
|
|||||||
fun AscentlyApp(
|
fun AscentlyApp(
|
||||||
shortcutAction: String? = null,
|
shortcutAction: String? = null,
|
||||||
lastUsedGymId: String? = null,
|
lastUsedGymId: String? = null,
|
||||||
onShortcutActionProcessed: () -> Unit = {}
|
onShortcutActionProcessed: () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -53,7 +53,7 @@ fun AscentlyApp(
|
|||||||
|
|
||||||
val permissionLauncher =
|
val permissionLauncher =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.RequestPermission()
|
contract = ActivityResultContracts.RequestPermission(),
|
||||||
) { isGranted: Boolean ->
|
) { isGranted: Boolean ->
|
||||||
if (!isGranted) {
|
if (!isGranted) {
|
||||||
showNotificationPermissionDialog = false
|
showNotificationPermissionDialog = false
|
||||||
@@ -90,7 +90,7 @@ fun AscentlyApp(
|
|||||||
context = context,
|
context = context,
|
||||||
hasActiveSession = activeSession != null,
|
hasActiveSession = activeSession != null,
|
||||||
hasGyms = gyms.isNotEmpty(),
|
hasGyms = gyms.isNotEmpty(),
|
||||||
lastUsedGym = if (activeSession == null && gyms.size > 1) lastUsedGym else null
|
lastUsedGym = if (activeSession == null && gyms.size > 1) lastUsedGym else null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ fun AscentlyApp(
|
|||||||
if (activeSession == null) {
|
if (activeSession == null) {
|
||||||
if (NotificationPermissionUtils.shouldRequestNotificationPermission() &&
|
if (NotificationPermissionUtils.shouldRequestNotificationPermission() &&
|
||||||
!NotificationPermissionUtils.isNotificationPermissionGranted(
|
!NotificationPermissionUtils.isNotificationPermissionGranted(
|
||||||
context
|
context,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
AppLogger.d("AscentlyApp") { "Showing notification permission dialog" }
|
AppLogger.d("AscentlyApp") { "Showing notification permission dialog" }
|
||||||
@@ -160,20 +160,20 @@ fun AscentlyApp(
|
|||||||
fabConfig?.let { config ->
|
fabConfig?.let { config ->
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
onClick = config.onClick,
|
onClick = config.onClick,
|
||||||
containerColor = MaterialTheme.colorScheme.primary
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = config.icon,
|
imageVector = config.icon,
|
||||||
contentDescription = config.contentDescription
|
contentDescription = config.contentDescription,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
) { innerPadding ->
|
) { innerPadding ->
|
||||||
NavHost(
|
NavHost(
|
||||||
navController = navController,
|
navController = navController,
|
||||||
startDestination = Screen.Sessions,
|
startDestination = Screen.Sessions,
|
||||||
modifier = Modifier.padding(innerPadding)
|
modifier = Modifier.padding(innerPadding),
|
||||||
) {
|
) {
|
||||||
composable<Screen.Sessions> {
|
composable<Screen.Sessions> {
|
||||||
LaunchedEffect(gyms, activeSession) {
|
LaunchedEffect(gyms, activeSession) {
|
||||||
@@ -187,14 +187,14 @@ fun AscentlyApp(
|
|||||||
.shouldRequestNotificationPermission() &&
|
.shouldRequestNotificationPermission() &&
|
||||||
!NotificationPermissionUtils
|
!NotificationPermissionUtils
|
||||||
.isNotificationPermissionGranted(
|
.isNotificationPermissionGranted(
|
||||||
context
|
context,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
showNotificationPermissionDialog = true
|
showNotificationPermissionDialog = true
|
||||||
} else {
|
} else {
|
||||||
navController.navigate(Screen.AddEditSession())
|
navController.navigate(Screen.AddEditSession())
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -204,7 +204,7 @@ fun AscentlyApp(
|
|||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateToSessionDetail = { sessionId ->
|
onNavigateToSessionDetail = { sessionId ->
|
||||||
navController.navigate(Screen.SessionDetail(sessionId))
|
navController.navigate(Screen.SessionDetail(sessionId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ fun AscentlyApp(
|
|||||||
contentDescription = "Add Problem",
|
contentDescription = "Add Problem",
|
||||||
onClick = {
|
onClick = {
|
||||||
navController.navigate(Screen.AddEditProblem())
|
navController.navigate(Screen.AddEditProblem())
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -227,7 +227,7 @@ fun AscentlyApp(
|
|||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateToProblemDetail = { problemId ->
|
onNavigateToProblemDetail = { problemId ->
|
||||||
navController.navigate(Screen.ProblemDetail(problemId))
|
navController.navigate(Screen.ProblemDetail(problemId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,14 +242,14 @@ fun AscentlyApp(
|
|||||||
FabConfig(
|
FabConfig(
|
||||||
icon = Icons.Default.Add,
|
icon = Icons.Default.Add,
|
||||||
contentDescription = "Add Gym",
|
contentDescription = "Add Gym",
|
||||||
onClick = { navController.navigate(Screen.AddEditGym()) }
|
onClick = { navController.navigate(Screen.AddEditGym()) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
GymsScreen(
|
GymsScreen(
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateToGymDetail = { gymId ->
|
onNavigateToGymDetail = { gymId ->
|
||||||
navController.navigate(Screen.GymDetail(gymId))
|
navController.navigate(Screen.GymDetail(gymId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ fun AscentlyApp(
|
|||||||
onNavigateBack = { navController.popBackStack() },
|
onNavigateBack = { navController.popBackStack() },
|
||||||
onNavigateToProblemDetail = { problemId ->
|
onNavigateToProblemDetail = { problemId ->
|
||||||
navController.navigate(Screen.ProblemDetail(problemId))
|
navController.navigate(Screen.ProblemDetail(problemId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,7 +280,7 @@ fun AscentlyApp(
|
|||||||
onNavigateBack = { navController.popBackStack() },
|
onNavigateBack = { navController.popBackStack() },
|
||||||
onNavigateToEdit = { problemId ->
|
onNavigateToEdit = { problemId ->
|
||||||
navController.navigate(Screen.AddEditProblem(problemId = problemId))
|
navController.navigate(Screen.AddEditProblem(problemId = problemId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +299,7 @@ fun AscentlyApp(
|
|||||||
},
|
},
|
||||||
onNavigateToProblemDetail = { problemId ->
|
onNavigateToProblemDetail = { problemId ->
|
||||||
navController.navigate(Screen.ProblemDetail(problemId))
|
navController.navigate(Screen.ProblemDetail(problemId))
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +309,7 @@ fun AscentlyApp(
|
|||||||
AddEditGymScreen(
|
AddEditGymScreen(
|
||||||
gymId = args.gymId,
|
gymId = args.gymId,
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateBack = { navController.popBackStack() }
|
onNavigateBack = { navController.popBackStack() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -320,7 +320,7 @@ fun AscentlyApp(
|
|||||||
problemId = args.problemId,
|
problemId = args.problemId,
|
||||||
gymId = args.gymId,
|
gymId = args.gymId,
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateBack = { navController.popBackStack() }
|
onNavigateBack = { navController.popBackStack() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +331,7 @@ fun AscentlyApp(
|
|||||||
sessionId = args.sessionId,
|
sessionId = args.sessionId,
|
||||||
gymId = args.gymId,
|
gymId = args.gymId,
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
onNavigateBack = { navController.popBackStack() }
|
onNavigateBack = { navController.popBackStack() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,9 +341,9 @@ fun AscentlyApp(
|
|||||||
onDismiss = { showNotificationPermissionDialog = false },
|
onDismiss = { showNotificationPermissionDialog = false },
|
||||||
onRequestPermission = {
|
onRequestPermission = {
|
||||||
permissionLauncher.launch(
|
permissionLauncher.launch(
|
||||||
NotificationPermissionUtils.getNotificationPermissionString()
|
NotificationPermissionUtils.getNotificationPermissionString(),
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,7 @@ fun AscentlyBottomNavigation(navController: NavHostController) {
|
|||||||
// Don't restore state - always start fresh when switching tabs
|
// Don't restore state - always start fresh when switching tabs
|
||||||
restoreState = false
|
restoreState = false
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -386,5 +386,5 @@ fun AscentlyBottomNavigation(navController: NavHostController) {
|
|||||||
data class FabConfig(
|
data class FabConfig(
|
||||||
val icon: androidx.compose.ui.graphics.vector.ImageVector,
|
val icon: androidx.compose.ui.graphics.vector.ImageVector,
|
||||||
val contentDescription: String,
|
val contentDescription: String,
|
||||||
val onClick: () -> Unit
|
val onClick: () -> Unit,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,81 +22,81 @@ fun ActiveSessionBanner(
|
|||||||
activeSession: ClimbSession?,
|
activeSession: ClimbSession?,
|
||||||
gym: Gym?,
|
gym: Gym?,
|
||||||
onSessionClick: () -> Unit,
|
onSessionClick: () -> Unit,
|
||||||
onEndSession: () -> Unit
|
onEndSession: () -> Unit,
|
||||||
) {
|
) {
|
||||||
if (activeSession != null) {
|
if (activeSession != null) {
|
||||||
// Add a timer that updates every second for real-time duration counting
|
// Add a timer that updates every second for real-time duration counting
|
||||||
var currentTime by remember { mutableStateOf(LocalDateTime.now()) }
|
var currentTime by remember { mutableStateOf(LocalDateTime.now()) }
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
while (true) {
|
while (true) {
|
||||||
delay(1000) // Update every second
|
delay(1000) // Update every second
|
||||||
currentTime = LocalDateTime.now()
|
currentTime = LocalDateTime.now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { onSessionClick() },
|
.clickable { onSessionClick() },
|
||||||
colors = CardDefaults.cardColors(
|
colors = CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp),
|
.padding(16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.PlayArrow,
|
Icons.Default.PlayArrow,
|
||||||
contentDescription = "Active session",
|
contentDescription = "Active session",
|
||||||
tint = MaterialTheme.colorScheme.primary,
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
modifier = Modifier.size(16.dp)
|
modifier = Modifier.size(16.dp),
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Active Session",
|
text = "Active Session",
|
||||||
style = MaterialTheme.typography.titleSmall,
|
style = MaterialTheme.typography.titleSmall,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = gym?.name ?: "Unknown Gym",
|
text = gym?.name ?: "Unknown Gym",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||||
)
|
)
|
||||||
|
|
||||||
activeSession.startTime?.let { startTime ->
|
activeSession.startTime?.let { startTime ->
|
||||||
val duration = calculateDuration(startTime, currentTime)
|
val duration = calculateDuration(startTime, currentTime)
|
||||||
Text(
|
Text(
|
||||||
text = duration,
|
text = duration,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.8f)
|
color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.8f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = onEndSession,
|
onClick = onEndSession,
|
||||||
colors = IconButtonDefaults.iconButtonColors(
|
colors = IconButtonDefaults.iconButtonColors(
|
||||||
containerColor = MaterialTheme.colorScheme.error,
|
containerColor = MaterialTheme.colorScheme.error,
|
||||||
contentColor = MaterialTheme.colorScheme.onError
|
contentColor = MaterialTheme.colorScheme.onError,
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = CustomIcons.Stop(MaterialTheme.colorScheme.onError),
|
imageVector = CustomIcons.Stop(MaterialTheme.colorScheme.onError),
|
||||||
contentDescription = "End session"
|
contentDescription = "End session",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ private fun calculateDuration(startTimeString: String, currentTime: LocalDateTim
|
|||||||
val hours = totalSeconds / 3600
|
val hours = totalSeconds / 3600
|
||||||
val minutes = (totalSeconds % 3600) / 60
|
val minutes = (totalSeconds % 3600) / 60
|
||||||
val seconds = totalSeconds % 60
|
val seconds = totalSeconds % 60
|
||||||
|
|
||||||
when {
|
when {
|
||||||
hours > 0 -> "${hours}h ${minutes}m ${seconds}s"
|
hours > 0 -> "${hours}h ${minutes}m ${seconds}s"
|
||||||
minutes > 0 -> "${minutes}m ${seconds}s"
|
minutes > 0 -> "${minutes}m ${seconds}s"
|
||||||
|
|||||||
@@ -23,25 +23,25 @@ data class BarChartDataPoint(val label: String, val value: Int, val gradeNumeric
|
|||||||
|
|
||||||
/** Configuration for bar chart styling */
|
/** Configuration for bar chart styling */
|
||||||
data class BarChartStyle(
|
data class BarChartStyle(
|
||||||
val barColor: Color,
|
val barColor: Color,
|
||||||
val gridColor: Color,
|
val gridColor: Color,
|
||||||
val textColor: Color,
|
val textColor: Color,
|
||||||
val backgroundColor: Color
|
val backgroundColor: Color,
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Custom Bar Chart for displaying grade distribution */
|
/** Custom Bar Chart for displaying grade distribution */
|
||||||
@Composable
|
@Composable
|
||||||
fun BarChart(
|
fun BarChart(
|
||||||
data: List<BarChartDataPoint>,
|
data: List<BarChartDataPoint>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
style: BarChartStyle =
|
style: BarChartStyle =
|
||||||
BarChartStyle(
|
BarChartStyle(
|
||||||
barColor = MaterialTheme.colorScheme.primary,
|
barColor = MaterialTheme.colorScheme.primary,
|
||||||
gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f),
|
gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f),
|
||||||
textColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
textColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
backgroundColor = MaterialTheme.colorScheme.surface
|
backgroundColor = MaterialTheme.colorScheme.surface,
|
||||||
),
|
),
|
||||||
showGrid: Boolean = true
|
showGrid: Boolean = true,
|
||||||
) {
|
) {
|
||||||
val textMeasurer = rememberTextMeasurer()
|
val textMeasurer = rememberTextMeasurer()
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
@@ -68,42 +68,44 @@ fun BarChart(
|
|||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
drawRect(
|
drawRect(
|
||||||
color = style.backgroundColor,
|
color = style.backgroundColor,
|
||||||
topLeft = Offset(padding, padding),
|
topLeft = Offset(padding, padding),
|
||||||
size = androidx.compose.ui.geometry.Size(chartWidth, chartHeight)
|
size = androidx.compose.ui.geometry.Size(chartWidth, chartHeight),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw grid
|
// Draw grid
|
||||||
if (showGrid) {
|
if (showGrid) {
|
||||||
drawGrid(
|
drawGrid(
|
||||||
padding = padding,
|
padding = padding,
|
||||||
chartWidth = chartWidth,
|
chartWidth = chartWidth,
|
||||||
chartHeight = chartHeight,
|
chartHeight = chartHeight,
|
||||||
gridColor = style.gridColor,
|
gridColor = style.gridColor,
|
||||||
maxValue = maxValue,
|
maxValue = maxValue,
|
||||||
textMeasurer = textMeasurer,
|
textMeasurer = textMeasurer,
|
||||||
textColor = style.textColor
|
textColor = style.textColor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw bars and labels
|
// Draw bars and labels
|
||||||
sortedData.forEachIndexed { index, dataPoint ->
|
sortedData.forEachIndexed { index, dataPoint ->
|
||||||
val barHeight =
|
val barHeight =
|
||||||
if (maxValue > 0) {
|
if (maxValue > 0) {
|
||||||
(dataPoint.value.toFloat() / maxValue.toFloat()) * chartHeight * 0.8f
|
(dataPoint.value.toFloat() / maxValue.toFloat()) * chartHeight * 0.8f
|
||||||
} else 0f
|
} else {
|
||||||
|
0f
|
||||||
|
}
|
||||||
|
|
||||||
val barX =
|
val barX =
|
||||||
padding +
|
padding +
|
||||||
barSpacing +
|
barSpacing +
|
||||||
index * (barWidth + barSpacing / (barCount - 1).coerceAtLeast(1))
|
index * (barWidth + barSpacing / (barCount - 1).coerceAtLeast(1))
|
||||||
val barY = padding + chartHeight - barHeight
|
val barY = padding + chartHeight - barHeight
|
||||||
|
|
||||||
// Draw bar
|
// Draw bar
|
||||||
drawRect(
|
drawRect(
|
||||||
color = style.barColor,
|
color = style.barColor,
|
||||||
topLeft = Offset(barX, barY),
|
topLeft = Offset(barX, barY),
|
||||||
size = androidx.compose.ui.geometry.Size(barWidth, barHeight)
|
size = androidx.compose.ui.geometry.Size(barWidth, barHeight),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw value on bar
|
// Draw value on bar
|
||||||
@@ -114,24 +116,24 @@ fun BarChart(
|
|||||||
|
|
||||||
// Position text
|
// Position text
|
||||||
val textY =
|
val textY =
|
||||||
if (barHeight > textSize.size.height + 8.dp.toPx()) {
|
if (barHeight > textSize.size.height + 8.dp.toPx()) {
|
||||||
barY + 8.dp.toPx()
|
barY + 8.dp.toPx()
|
||||||
} else {
|
} else {
|
||||||
barY - 4.dp.toPx()
|
barY - 4.dp.toPx()
|
||||||
}
|
}
|
||||||
|
|
||||||
val textColor =
|
val textColor =
|
||||||
if (barHeight > textSize.size.height + 8.dp.toPx()) {
|
if (barHeight > textSize.size.height + 8.dp.toPx()) {
|
||||||
Color.White
|
Color.White
|
||||||
} else {
|
} else {
|
||||||
style.textColor
|
style.textColor
|
||||||
}
|
}
|
||||||
|
|
||||||
drawText(
|
drawText(
|
||||||
textMeasurer = textMeasurer,
|
textMeasurer = textMeasurer,
|
||||||
text = valueText,
|
text = valueText,
|
||||||
style = textStyle.copy(color = textColor),
|
style = textStyle.copy(color = textColor),
|
||||||
topLeft = Offset(barX + barWidth / 2f - textSize.size.width / 2f, textY)
|
topLeft = Offset(barX + barWidth / 2f - textSize.size.width / 2f, textY),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,14 +143,14 @@ fun BarChart(
|
|||||||
val labelTextSize = textMeasurer.measure(gradeText, labelTextStyle)
|
val labelTextSize = textMeasurer.measure(gradeText, labelTextStyle)
|
||||||
|
|
||||||
drawText(
|
drawText(
|
||||||
textMeasurer = textMeasurer,
|
textMeasurer = textMeasurer,
|
||||||
text = gradeText,
|
text = gradeText,
|
||||||
style = labelTextStyle,
|
style = labelTextStyle,
|
||||||
topLeft =
|
topLeft =
|
||||||
Offset(
|
Offset(
|
||||||
barX + barWidth / 2f - labelTextSize.size.width / 2f,
|
barX + barWidth / 2f - labelTextSize.size.width / 2f,
|
||||||
padding + chartHeight + 8.dp.toPx()
|
padding + chartHeight + 8.dp.toPx(),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,37 +158,37 @@ fun BarChart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun DrawScope.drawGrid(
|
private fun DrawScope.drawGrid(
|
||||||
padding: Float,
|
padding: Float,
|
||||||
chartWidth: Float,
|
chartWidth: Float,
|
||||||
chartHeight: Float,
|
chartHeight: Float,
|
||||||
gridColor: Color,
|
gridColor: Color,
|
||||||
maxValue: Int,
|
maxValue: Int,
|
||||||
textMeasurer: TextMeasurer,
|
textMeasurer: TextMeasurer,
|
||||||
textColor: Color
|
textColor: Color,
|
||||||
) {
|
) {
|
||||||
val textStyle = TextStyle(color = textColor, fontSize = 10.sp)
|
val textStyle = TextStyle(color = textColor, fontSize = 10.sp)
|
||||||
|
|
||||||
// Horizontal grid lines
|
// Horizontal grid lines
|
||||||
val gridLines =
|
val gridLines =
|
||||||
when {
|
when {
|
||||||
maxValue <= 5 -> (0..maxValue).toList()
|
maxValue <= 5 -> (0..maxValue).toList()
|
||||||
maxValue <= 10 -> (0..maxValue step 2).toList()
|
maxValue <= 10 -> (0..maxValue step 2).toList()
|
||||||
maxValue <= 20 -> (0..maxValue step 5).toList()
|
maxValue <= 20 -> (0..maxValue step 5).toList()
|
||||||
else -> {
|
else -> {
|
||||||
val step = (maxValue / 5).coerceAtLeast(1)
|
val step = (maxValue / 5).coerceAtLeast(1)
|
||||||
(0..maxValue step step).toList()
|
(0..maxValue step step).toList()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gridLines.forEach { value ->
|
gridLines.forEach { value ->
|
||||||
val y = padding + chartHeight - (value.toFloat() / maxValue.toFloat()) * chartHeight * 0.8f
|
val y = padding + chartHeight - (value.toFloat() / maxValue.toFloat()) * chartHeight * 0.8f
|
||||||
|
|
||||||
// Draw grid line
|
// Draw grid line
|
||||||
drawLine(
|
drawLine(
|
||||||
color = gridColor,
|
color = gridColor,
|
||||||
start = Offset(padding, y),
|
start = Offset(padding, y),
|
||||||
end = Offset(padding + chartWidth, y),
|
end = Offset(padding + chartWidth, y),
|
||||||
strokeWidth = 1.dp.toPx()
|
strokeWidth = 1.dp.toPx(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw Y-axis label
|
// Draw Y-axis label
|
||||||
@@ -194,14 +196,14 @@ private fun DrawScope.drawGrid(
|
|||||||
val text = value.toString()
|
val text = value.toString()
|
||||||
val textSize = textMeasurer.measure(text, textStyle)
|
val textSize = textMeasurer.measure(text, textStyle)
|
||||||
drawText(
|
drawText(
|
||||||
textMeasurer = textMeasurer,
|
textMeasurer = textMeasurer,
|
||||||
text = text,
|
text = text,
|
||||||
style = textStyle,
|
style = textStyle,
|
||||||
topLeft =
|
topLeft =
|
||||||
Offset(
|
Offset(
|
||||||
padding - textSize.size.width - 8.dp.toPx(),
|
padding - textSize.size.width - 8.dp.toPx(),
|
||||||
y - textSize.size.height / 2f
|
y - textSize.size.height / 2f,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,44 +40,44 @@ fun FullscreenImageViewer(imagePaths: List<String>, initialIndex: Int = 0, onDis
|
|||||||
LaunchedEffect(pagerState.currentPage) {
|
LaunchedEffect(pagerState.currentPage) {
|
||||||
if (imagePaths.size > 1) {
|
if (imagePaths.size > 1) {
|
||||||
thumbnailListState.animateScrollToItem(
|
thumbnailListState.animateScrollToItem(
|
||||||
index = pagerState.currentPage,
|
index = pagerState.currentPage,
|
||||||
scrollOffset = -200
|
scrollOffset = -200,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
properties =
|
properties =
|
||||||
DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = true)
|
DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = true),
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier.fillMaxSize().background(Color.Black).systemBarsPadding()) {
|
Box(modifier = Modifier.fillMaxSize().background(Color.Black).systemBarsPadding()) {
|
||||||
// Main image pager
|
// Main image pager
|
||||||
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
|
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
|
||||||
OrientationAwareImage(
|
OrientationAwareImage(
|
||||||
imagePath = imagePaths[page],
|
imagePath = imagePaths[page],
|
||||||
contentDescription = "Full screen image",
|
contentDescription = "Full screen image",
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentScale = ContentScale.Fit
|
contentScale = ContentScale.Fit,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top bar with back button and counter
|
// Top bar with back button and counter
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxWidth().align(Alignment.TopStart),
|
modifier = Modifier.fillMaxWidth().align(Alignment.TopStart),
|
||||||
color = Color.Black.copy(alpha = 0.6f)
|
color = Color.Black.copy(alpha = 0.6f),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth().padding(horizontal = 4.dp, vertical = 8.dp),
|
Modifier.fillMaxWidth().padding(horizontal = 4.dp, vertical = 8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
// Back button
|
// Back button
|
||||||
IconButton(onClick = onDismiss) {
|
IconButton(onClick = onDismiss) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
contentDescription = "Close",
|
contentDescription = "Close",
|
||||||
tint = Color.White
|
tint = Color.White,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +86,9 @@ fun FullscreenImageViewer(imagePaths: List<String>, initialIndex: Int = 0, onDis
|
|||||||
// Image counter
|
// Image counter
|
||||||
if (imagePaths.size > 1) {
|
if (imagePaths.size > 1) {
|
||||||
Text(
|
Text(
|
||||||
text = "${pagerState.currentPage + 1} / ${imagePaths.size}",
|
text = "${pagerState.currentPage + 1} / ${imagePaths.size}",
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,56 +99,56 @@ fun FullscreenImageViewer(imagePaths: List<String>, initialIndex: Int = 0, onDis
|
|||||||
// Thumbnail strip at bottom (if multiple images)
|
// Thumbnail strip at bottom (if multiple images)
|
||||||
if (imagePaths.size > 1) {
|
if (imagePaths.size > 1) {
|
||||||
Surface(
|
Surface(
|
||||||
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter),
|
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter),
|
||||||
color = Color.Black.copy(alpha = 0.6f)
|
color = Color.Black.copy(alpha = 0.6f),
|
||||||
) {
|
) {
|
||||||
LazyRow(
|
LazyRow(
|
||||||
state = thumbnailListState,
|
state = thumbnailListState,
|
||||||
modifier = Modifier.padding(vertical = 12.dp),
|
modifier = Modifier.padding(vertical = 12.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
contentPadding = PaddingValues(horizontal = 16.dp)
|
contentPadding = PaddingValues(horizontal = 16.dp),
|
||||||
) {
|
) {
|
||||||
itemsIndexed(imagePaths) { index, imagePath ->
|
itemsIndexed(imagePaths) { index, imagePath ->
|
||||||
val isSelected = index == pagerState.currentPage
|
val isSelected = index == pagerState.currentPage
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.size(48.dp)
|
Modifier.size(48.dp)
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.clickable {
|
.clickable {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
pagerState.animateScrollToPage(index)
|
pagerState.animateScrollToPage(index)
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
OrientationAwareImage(
|
OrientationAwareImage(
|
||||||
imagePath = imagePath,
|
imagePath = imagePath,
|
||||||
contentDescription = "Thumbnail ${index + 1}",
|
contentDescription = "Thumbnail ${index + 1}",
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentScale = ContentScale.Crop
|
contentScale = ContentScale.Crop,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Selection indicator
|
// Selection indicator
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxSize()
|
Modifier.fillMaxSize()
|
||||||
.background(
|
.background(
|
||||||
Color.White.copy(alpha = 0.3f),
|
Color.White.copy(alpha = 0.3f),
|
||||||
RoundedCornerShape(8.dp)
|
RoundedCornerShape(8.dp),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxSize()
|
Modifier.fillMaxSize()
|
||||||
.background(
|
.background(
|
||||||
Color.Transparent,
|
Color.Transparent,
|
||||||
RoundedCornerShape(8.dp)
|
RoundedCornerShape(8.dp),
|
||||||
)
|
)
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.background(
|
.background(
|
||||||
Color.White.copy(alpha = 0.2f)
|
Color.White.copy(alpha = 0.2f),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import androidx.compose.ui.unit.dp
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImageDisplay(
|
fun ImageDisplay(
|
||||||
imagePaths: List<String>,
|
imagePaths: List<String>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
imageSize: Int = 120,
|
imageSize: Int = 120,
|
||||||
onImageClick: ((Int) -> Unit)? = null
|
onImageClick: ((Int) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
LocalContext.current
|
LocalContext.current
|
||||||
|
|
||||||
@@ -26,15 +26,15 @@ fun ImageDisplay(
|
|||||||
LazyRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
itemsIndexed(imagePaths) { index, imagePath ->
|
itemsIndexed(imagePaths) { index, imagePath ->
|
||||||
OrientationAwareImage(
|
OrientationAwareImage(
|
||||||
imagePath = imagePath,
|
imagePath = imagePath,
|
||||||
contentDescription = "Problem photo",
|
contentDescription = "Problem photo",
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.size(imageSize.dp)
|
Modifier.size(imageSize.dp)
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.clickable(enabled = onImageClick != null) {
|
.clickable(enabled = onImageClick != null) {
|
||||||
onImageClick?.invoke(index)
|
onImageClick?.invoke(index)
|
||||||
},
|
},
|
||||||
contentScale = ContentScale.Crop
|
contentScale = ContentScale.Crop,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,17 +43,17 @@ fun ImageDisplay(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImageDisplaySection(
|
fun ImageDisplaySection(
|
||||||
imagePaths: List<String>,
|
imagePaths: List<String>,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
title: String = "Photos",
|
title: String = "Photos",
|
||||||
onImageClick: ((Int) -> Unit)? = null
|
onImageClick: ((Int) -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (imagePaths.isNotEmpty()) {
|
if (imagePaths.isNotEmpty()) {
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
color = MaterialTheme.colorScheme.onSurface,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ import java.util.*
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ImagePicker(
|
fun ImagePicker(
|
||||||
imageUris: List<String>,
|
imageUris: List<String>,
|
||||||
onImagesChanged: (List<String>) -> Unit,
|
onImagesChanged: (List<String>) -> Unit,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
maxImages: Int = 5
|
maxImages: Int = 5,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var tempImageUris by remember { mutableStateOf(imageUris) }
|
var tempImageUris by remember { mutableStateOf(imageUris) }
|
||||||
@@ -44,83 +44,83 @@ fun ImagePicker(
|
|||||||
|
|
||||||
// Image picker launcher
|
// Image picker launcher
|
||||||
val imagePickerLauncher =
|
val imagePickerLauncher =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.GetMultipleContents()
|
contract = ActivityResultContracts.GetMultipleContents(),
|
||||||
) { uris ->
|
) { uris ->
|
||||||
if (uris.isNotEmpty()) {
|
if (uris.isNotEmpty()) {
|
||||||
val currentCount = tempImageUris.size
|
val currentCount = tempImageUris.size
|
||||||
val remainingSlots = maxImages - currentCount
|
val remainingSlots = maxImages - currentCount
|
||||||
val urisToProcess = uris.take(remainingSlots)
|
val urisToProcess = uris.take(remainingSlots)
|
||||||
|
|
||||||
// Process images
|
// Process images
|
||||||
val newImagePaths = mutableListOf<String>()
|
val newImagePaths = mutableListOf<String>()
|
||||||
urisToProcess.forEach { uri ->
|
urisToProcess.forEach { uri ->
|
||||||
val imagePath = ImageUtils.saveTemporaryImageFromUri(context, uri)
|
val imagePath = ImageUtils.saveTemporaryImageFromUri(context, uri)
|
||||||
if (imagePath != null) {
|
if (imagePath != null) {
|
||||||
newImagePaths.add(imagePath)
|
newImagePaths.add(imagePath)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (newImagePaths.isNotEmpty()) {
|
if (newImagePaths.isNotEmpty()) {
|
||||||
val updatedUris = tempImageUris + newImagePaths
|
val updatedUris = tempImageUris + newImagePaths
|
||||||
|
tempImageUris = updatedUris
|
||||||
|
onImagesChanged(updatedUris)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camera launcher
|
||||||
|
val cameraLauncher =
|
||||||
|
rememberLauncherForActivityResult(contract = ActivityResultContracts.TakePicture()) {
|
||||||
|
success ->
|
||||||
|
if (success) {
|
||||||
|
cameraImageUri?.let { uri ->
|
||||||
|
val imagePath = ImageUtils.saveTemporaryImageFromUri(context, uri)
|
||||||
|
if (imagePath != null) {
|
||||||
|
val updatedUris = tempImageUris + imagePath
|
||||||
tempImageUris = updatedUris
|
tempImageUris = updatedUris
|
||||||
onImagesChanged(updatedUris)
|
onImagesChanged(updatedUris)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Camera launcher
|
|
||||||
val cameraLauncher =
|
|
||||||
rememberLauncherForActivityResult(contract = ActivityResultContracts.TakePicture()) {
|
|
||||||
success ->
|
|
||||||
if (success) {
|
|
||||||
cameraImageUri?.let { uri ->
|
|
||||||
val imagePath = ImageUtils.saveTemporaryImageFromUri(context, uri)
|
|
||||||
if (imagePath != null) {
|
|
||||||
val updatedUris = tempImageUris + imagePath
|
|
||||||
tempImageUris = updatedUris
|
|
||||||
onImagesChanged(updatedUris)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Camera permission launcher
|
// Camera permission launcher
|
||||||
val cameraPermissionLauncher =
|
val cameraPermissionLauncher =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
contract = ActivityResultContracts.RequestPermission()
|
contract = ActivityResultContracts.RequestPermission(),
|
||||||
) { isGranted ->
|
) { isGranted ->
|
||||||
if (isGranted) {
|
if (isGranted) {
|
||||||
// Create image file for camera
|
// Create image file for camera
|
||||||
val imageFile = createImageFile(context)
|
val imageFile = createImageFile(context)
|
||||||
val uri =
|
val uri =
|
||||||
FileProvider.getUriForFile(
|
FileProvider.getUriForFile(
|
||||||
context,
|
context,
|
||||||
"${context.packageName}.fileprovider",
|
"${context.packageName}.fileprovider",
|
||||||
imageFile
|
imageFile,
|
||||||
)
|
)
|
||||||
cameraImageUri = uri
|
cameraImageUri = uri
|
||||||
cameraLauncher.launch(uri)
|
cameraLauncher.launch(uri)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Photos (${tempImageUris.size}/$maxImages)",
|
text = "Photos (${tempImageUris.size}/$maxImages)",
|
||||||
style = MaterialTheme.typography.titleMedium
|
style = MaterialTheme.typography.titleMedium,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (tempImageUris.size < maxImages) {
|
if (tempImageUris.size < maxImages) {
|
||||||
TextButton(onClick = { showImageSourceDialog = true }) {
|
TextButton(onClick = { showImageSourceDialog = true }) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Add,
|
Icons.Default.Add,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(16.dp)
|
modifier = Modifier.size(16.dp),
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
Text("Add Photos")
|
Text("Add Photos")
|
||||||
@@ -134,42 +134,42 @@ fun ImagePicker(
|
|||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
items(tempImageUris) { imagePath ->
|
items(tempImageUris) { imagePath ->
|
||||||
ImageItem(
|
ImageItem(
|
||||||
imagePath = imagePath,
|
imagePath = imagePath,
|
||||||
onRemove = {
|
onRemove = {
|
||||||
val updatedUris = tempImageUris.filter { it != imagePath }
|
val updatedUris = tempImageUris.filter { it != imagePath }
|
||||||
tempImageUris = updatedUris
|
tempImageUris = updatedUris
|
||||||
onImagesChanged(updatedUris)
|
onImagesChanged(updatedUris)
|
||||||
|
|
||||||
// Delete the image file
|
// Delete the image file
|
||||||
ImageUtils.deleteImage(context, imagePath)
|
ImageUtils.deleteImage(context, imagePath)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth().height(100.dp),
|
modifier = Modifier.fillMaxWidth().height(100.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(
|
MaterialTheme.colorScheme.surfaceVariant.copy(
|
||||||
alpha = 0.3f
|
alpha = 0.3f,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Add,
|
Icons.Default.Add,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant
|
tint = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Add photos of this problem",
|
text = "Add photos of this problem",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,67 +179,68 @@ fun ImagePicker(
|
|||||||
// Image Source Selection Dialog
|
// Image Source Selection Dialog
|
||||||
if (showImageSourceDialog) {
|
if (showImageSourceDialog) {
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { showImageSourceDialog = false },
|
onDismissRequest = { showImageSourceDialog = false },
|
||||||
title = { Text("Add Photo") },
|
title = { Text("Add Photo") },
|
||||||
text = { Text("Choose how you'd like to add a photo") },
|
text = { Text("Choose how you'd like to add a photo") },
|
||||||
confirmButton = {
|
confirmButton = {
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
showImageSourceDialog = false
|
showImageSourceDialog = false
|
||||||
imagePickerLauncher.launch("image/*")
|
imagePickerLauncher.launch("image/*")
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.PhotoLibrary,
|
Icons.Default.PhotoLibrary,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(16.dp)
|
modifier = Modifier.size(16.dp),
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
Text("Gallery")
|
Text("Gallery")
|
||||||
}
|
}
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
showImageSourceDialog = false
|
showImageSourceDialog = false
|
||||||
when (ContextCompat.checkSelfPermission(
|
when (
|
||||||
context,
|
ContextCompat.checkSelfPermission(
|
||||||
Manifest.permission.CAMERA
|
context,
|
||||||
)
|
Manifest.permission.CAMERA,
|
||||||
) {
|
)
|
||||||
PackageManager.PERMISSION_GRANTED -> {
|
) {
|
||||||
// Create image file for camera
|
PackageManager.PERMISSION_GRANTED -> {
|
||||||
val imageFile = createImageFile(context)
|
// Create image file for camera
|
||||||
val uri =
|
val imageFile = createImageFile(context)
|
||||||
FileProvider.getUriForFile(
|
val uri =
|
||||||
context,
|
FileProvider.getUriForFile(
|
||||||
"${context.packageName}.fileprovider",
|
context,
|
||||||
imageFile
|
"${context.packageName}.fileprovider",
|
||||||
)
|
imageFile,
|
||||||
cameraImageUri = uri
|
)
|
||||||
cameraLauncher.launch(uri)
|
cameraImageUri = uri
|
||||||
}
|
cameraLauncher.launch(uri)
|
||||||
else -> {
|
}
|
||||||
cameraPermissionLauncher.launch(
|
else -> {
|
||||||
Manifest.permission.CAMERA
|
cameraPermissionLauncher.launch(
|
||||||
)
|
Manifest.permission.CAMERA,
|
||||||
}
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
},
|
||||||
Icon(
|
) {
|
||||||
Icons.Default.CameraAlt,
|
Icon(
|
||||||
contentDescription = null,
|
Icons.Default.CameraAlt,
|
||||||
modifier = Modifier.size(16.dp)
|
contentDescription = null,
|
||||||
)
|
modifier = Modifier.size(16.dp),
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
)
|
||||||
Text("Camera")
|
Spacer(modifier = Modifier.width(4.dp))
|
||||||
}
|
Text("Camera")
|
||||||
}
|
}
|
||||||
},
|
|
||||||
dismissButton = {
|
|
||||||
TextButton(onClick = { showImageSourceDialog = false }) { Text("Cancel") }
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = { showImageSourceDialog = false }) { Text("Cancel") }
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -259,25 +260,25 @@ private fun ImageItem(imagePath: String, onRemove: () -> Unit, modifier: Modifie
|
|||||||
|
|
||||||
Box(modifier = modifier.size(80.dp)) {
|
Box(modifier = modifier.size(80.dp)) {
|
||||||
OrientationAwareImage(
|
OrientationAwareImage(
|
||||||
imagePath = imagePath,
|
imagePath = imagePath,
|
||||||
contentDescription = "Problem photo",
|
contentDescription = "Problem photo",
|
||||||
modifier = Modifier.fillMaxSize().clip(RoundedCornerShape(8.dp)),
|
modifier = Modifier.fillMaxSize().clip(RoundedCornerShape(8.dp)),
|
||||||
contentScale = ContentScale.Crop
|
contentScale = ContentScale.Crop,
|
||||||
)
|
)
|
||||||
|
|
||||||
IconButton(onClick = onRemove, modifier = Modifier.align(Alignment.TopEnd).size(24.dp)) {
|
IconButton(onClick = onRemove, modifier = Modifier.align(Alignment.TopEnd).size(24.dp)) {
|
||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.errorContainer
|
containerColor = MaterialTheme.colorScheme.errorContainer,
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Close,
|
Icons.Default.Close,
|
||||||
contentDescription = "Remove photo",
|
contentDescription = "Remove photo",
|
||||||
modifier = Modifier.fillMaxSize().padding(2.dp),
|
modifier = Modifier.fillMaxSize().padding(2.dp),
|
||||||
tint = MaterialTheme.colorScheme.onErrorContainer
|
tint = MaterialTheme.colorScheme.onErrorContainer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import androidx.compose.ui.unit.sp
|
|||||||
data class ChartDataPoint(
|
data class ChartDataPoint(
|
||||||
val x: Float,
|
val x: Float,
|
||||||
val y: Float,
|
val y: Float,
|
||||||
val label: String? = null
|
val label: String? = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,7 +37,7 @@ data class ChartStyle(
|
|||||||
val lineWidth: Float = 3f,
|
val lineWidth: Float = 3f,
|
||||||
val gridColor: Color,
|
val gridColor: Color,
|
||||||
val textColor: Color,
|
val textColor: Color,
|
||||||
val backgroundColor: Color
|
val backgroundColor: Color,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,59 +52,59 @@ fun LineChart(
|
|||||||
fillColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f),
|
fillColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.2f),
|
||||||
gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f),
|
gridColor = MaterialTheme.colorScheme.outline.copy(alpha = 0.3f),
|
||||||
textColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
textColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
backgroundColor = MaterialTheme.colorScheme.surface
|
backgroundColor = MaterialTheme.colorScheme.surface,
|
||||||
),
|
),
|
||||||
showGrid: Boolean = true,
|
showGrid: Boolean = true,
|
||||||
xAxisFormatter: (Float) -> String = { it.toString() },
|
xAxisFormatter: (Float) -> String = { it.toString() },
|
||||||
yAxisFormatter: (Float) -> String = { it.toString() }
|
yAxisFormatter: (Float) -> String = { it.toString() },
|
||||||
) {
|
) {
|
||||||
val textMeasurer = rememberTextMeasurer()
|
val textMeasurer = rememberTextMeasurer()
|
||||||
val density = LocalDensity.current
|
val density = LocalDensity.current
|
||||||
|
|
||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
Canvas(
|
Canvas(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(16.dp)
|
.padding(16.dp),
|
||||||
) {
|
) {
|
||||||
if (data.isEmpty()) return@Canvas
|
if (data.isEmpty()) return@Canvas
|
||||||
|
|
||||||
val padding = with(density) { 32.dp.toPx() }
|
val padding = with(density) { 32.dp.toPx() }
|
||||||
val chartWidth = size.width - padding * 2
|
val chartWidth = size.width - padding * 2
|
||||||
val chartHeight = size.height - padding * 2
|
val chartHeight = size.height - padding * 2
|
||||||
|
|
||||||
// Calculate data bounds
|
// Calculate data bounds
|
||||||
val dataMinY = data.minOf { it.y }
|
val dataMinY = data.minOf { it.y }
|
||||||
val dataMaxY = data.maxOf { it.y }
|
val dataMaxY = data.maxOf { it.y }
|
||||||
|
|
||||||
// Add some padding to Y-axis (10% above and below the data range)
|
// Add some padding to Y-axis (10% above and below the data range)
|
||||||
val yPadding = if (dataMaxY == dataMinY) 1f else (dataMaxY - dataMinY) * 0.1f
|
val yPadding = if (dataMaxY == dataMinY) 1f else (dataMaxY - dataMinY) * 0.1f
|
||||||
val minY = dataMinY - yPadding
|
val minY = dataMinY - yPadding
|
||||||
val maxY = dataMaxY + yPadding
|
val maxY = dataMaxY + yPadding
|
||||||
|
|
||||||
val minX = data.minOf { it.x }
|
val minX = data.minOf { it.x }
|
||||||
val maxX = data.maxOf { it.x }
|
val maxX = data.maxOf { it.x }
|
||||||
|
|
||||||
val xRange = if (maxX - minX == 0f) 1f else maxX - minX // Minimum range of 1 for single points
|
val xRange = if (maxX - minX == 0f) 1f else maxX - minX // Minimum range of 1 for single points
|
||||||
val yRange = maxY - minY
|
val yRange = maxY - minY
|
||||||
|
|
||||||
// Ensure we have valid ranges
|
// Ensure we have valid ranges
|
||||||
if (yRange == 0f) return@Canvas
|
if (yRange == 0f) return@Canvas
|
||||||
|
|
||||||
// Convert data points to screen coordinates
|
// Convert data points to screen coordinates
|
||||||
val screenPoints = data.map { point ->
|
val screenPoints = data.map { point ->
|
||||||
val x = padding + (point.x - minX) / xRange * chartWidth
|
val x = padding + (point.x - minX) / xRange * chartWidth
|
||||||
val y = padding + chartHeight - (point.y - minY) / yRange * chartHeight
|
val y = padding + chartHeight - (point.y - minY) / yRange * chartHeight
|
||||||
Offset(x, y)
|
Offset(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
drawRect(
|
drawRect(
|
||||||
color = style.backgroundColor,
|
color = style.backgroundColor,
|
||||||
topLeft = Offset(padding, padding),
|
topLeft = Offset(padding, padding),
|
||||||
size = androidx.compose.ui.geometry.Size(chartWidth, chartHeight)
|
size = androidx.compose.ui.geometry.Size(chartWidth, chartHeight),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw grid
|
// Draw grid
|
||||||
if (showGrid) {
|
if (showGrid) {
|
||||||
drawGrid(
|
drawGrid(
|
||||||
@@ -120,49 +120,49 @@ fun LineChart(
|
|||||||
textColor = style.textColor,
|
textColor = style.textColor,
|
||||||
xAxisFormatter = xAxisFormatter,
|
xAxisFormatter = xAxisFormatter,
|
||||||
yAxisFormatter = yAxisFormatter,
|
yAxisFormatter = yAxisFormatter,
|
||||||
actualDataPoints = data
|
actualDataPoints = data,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw area fill
|
// Draw area fill
|
||||||
if (screenPoints.size > 1) {
|
if (screenPoints.size > 1) {
|
||||||
drawAreaFill(
|
drawAreaFill(
|
||||||
points = screenPoints,
|
points = screenPoints,
|
||||||
padding = padding,
|
padding = padding,
|
||||||
chartHeight = chartHeight,
|
chartHeight = chartHeight,
|
||||||
fillColor = style.fillColor
|
fillColor = style.fillColor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw line
|
// Draw line
|
||||||
if (screenPoints.size > 1) {
|
if (screenPoints.size > 1) {
|
||||||
drawLine(
|
drawLine(
|
||||||
points = screenPoints,
|
points = screenPoints,
|
||||||
lineColor = style.lineColor,
|
lineColor = style.lineColor,
|
||||||
lineWidth = style.lineWidth
|
lineWidth = style.lineWidth,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw data points - more pronounced
|
// Draw data points - more pronounced
|
||||||
screenPoints.forEach { point ->
|
screenPoints.forEach { point ->
|
||||||
// Draw outer circle (larger)
|
// Draw outer circle (larger)
|
||||||
drawCircle(
|
drawCircle(
|
||||||
color = style.lineColor,
|
color = style.lineColor,
|
||||||
radius = 8f,
|
radius = 8f,
|
||||||
center = point
|
center = point,
|
||||||
)
|
)
|
||||||
// Draw inner circle (white center)
|
// Draw inner circle (white center)
|
||||||
drawCircle(
|
drawCircle(
|
||||||
color = style.backgroundColor,
|
color = style.backgroundColor,
|
||||||
radius = 5f,
|
radius = 5f,
|
||||||
center = point
|
center = point,
|
||||||
)
|
)
|
||||||
// Draw border for better visibility
|
// Draw border for better visibility
|
||||||
drawCircle(
|
drawCircle(
|
||||||
color = style.lineColor,
|
color = style.lineColor,
|
||||||
radius = 8f,
|
radius = 8f,
|
||||||
center = point,
|
center = point,
|
||||||
style = Stroke(width = 2f)
|
style = Stroke(width = 2f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,43 +182,43 @@ private fun DrawScope.drawGrid(
|
|||||||
textColor: Color,
|
textColor: Color,
|
||||||
xAxisFormatter: (Float) -> String,
|
xAxisFormatter: (Float) -> String,
|
||||||
yAxisFormatter: (Float) -> String,
|
yAxisFormatter: (Float) -> String,
|
||||||
actualDataPoints: List<ChartDataPoint>
|
actualDataPoints: List<ChartDataPoint>,
|
||||||
) {
|
) {
|
||||||
val textStyle = TextStyle(
|
val textStyle = TextStyle(
|
||||||
color = textColor,
|
color = textColor,
|
||||||
fontSize = 10.sp
|
fontSize = 10.sp,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw vertical grid lines (X-axis) - only at integer values for sessions
|
// Draw vertical grid lines (X-axis) - only at integer values for sessions
|
||||||
val xRange = maxX - minX
|
val xRange = maxX - minX
|
||||||
if (xRange > 0) {
|
if (xRange > 0) {
|
||||||
val startX = kotlin.math.ceil(minX).toInt()
|
val startX = kotlin.math.ceil(minX).toInt()
|
||||||
val endX = kotlin.math.floor(maxX).toInt()
|
val endX = kotlin.math.floor(maxX).toInt()
|
||||||
|
|
||||||
for (sessionNum in startX..endX) {
|
for (sessionNum in startX..endX) {
|
||||||
val x = padding + (sessionNum.toFloat() - minX) / xRange * chartWidth
|
val x = padding + (sessionNum.toFloat() - minX) / xRange * chartWidth
|
||||||
|
|
||||||
// Draw grid line
|
// Draw grid line
|
||||||
drawLine(
|
drawLine(
|
||||||
color = gridColor,
|
color = gridColor,
|
||||||
start = Offset(x, padding),
|
start = Offset(x, padding),
|
||||||
end = Offset(x, padding + chartHeight),
|
end = Offset(x, padding + chartHeight),
|
||||||
strokeWidth = 1.dp.toPx()
|
strokeWidth = 1.dp.toPx(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// X-axis labels removed per user request
|
// X-axis labels removed per user request
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw horizontal grid lines (Y-axis) - only at actual data point values
|
// Draw horizontal grid lines (Y-axis) - only at actual data point values
|
||||||
val yRange = maxY - minY
|
val yRange = maxY - minY
|
||||||
if (yRange > 0) {
|
if (yRange > 0) {
|
||||||
// Get unique Y values from actual data points
|
// Get unique Y values from actual data points
|
||||||
val actualYValues = actualDataPoints.map { kotlin.math.round(it.y).toInt() }.toSet()
|
val actualYValues = actualDataPoints.map { kotlin.math.round(it.y).toInt() }.toSet()
|
||||||
|
|
||||||
actualYValues.forEach { gradeValue ->
|
actualYValues.forEach { gradeValue ->
|
||||||
val y = padding + chartHeight - (gradeValue.toFloat() - minY) / yRange * chartHeight
|
val y = padding + chartHeight - (gradeValue.toFloat() - minY) / yRange * chartHeight
|
||||||
|
|
||||||
// Only draw if within chart bounds
|
// Only draw if within chart bounds
|
||||||
if (y >= padding && y <= padding + chartHeight) {
|
if (y >= padding && y <= padding + chartHeight) {
|
||||||
// Draw grid line
|
// Draw grid line
|
||||||
@@ -226,9 +226,9 @@ private fun DrawScope.drawGrid(
|
|||||||
color = gridColor,
|
color = gridColor,
|
||||||
start = Offset(padding, y),
|
start = Offset(padding, y),
|
||||||
end = Offset(padding + chartWidth, y),
|
end = Offset(padding + chartWidth, y),
|
||||||
strokeWidth = 1.dp.toPx()
|
strokeWidth = 1.dp.toPx(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Draw label
|
// Draw label
|
||||||
val text = yAxisFormatter(gradeValue.toFloat())
|
val text = yAxisFormatter(gradeValue.toFloat())
|
||||||
val textSize = textMeasurer.measure(text, textStyle)
|
val textSize = textMeasurer.measure(text, textStyle)
|
||||||
@@ -238,8 +238,8 @@ private fun DrawScope.drawGrid(
|
|||||||
style = textStyle,
|
style = textStyle,
|
||||||
topLeft = Offset(
|
topLeft = Offset(
|
||||||
padding - textSize.size.width - 8.dp.toPx(),
|
padding - textSize.size.width - 8.dp.toPx(),
|
||||||
y - textSize.size.height / 2f
|
y - textSize.size.height / 2f,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -250,38 +250,38 @@ private fun DrawScope.drawAreaFill(
|
|||||||
points: List<Offset>,
|
points: List<Offset>,
|
||||||
padding: Float,
|
padding: Float,
|
||||||
chartHeight: Float,
|
chartHeight: Float,
|
||||||
fillColor: Color
|
fillColor: Color,
|
||||||
) {
|
) {
|
||||||
val bottomY = padding + chartHeight // This represents the bottom of the chart area
|
val bottomY = padding + chartHeight // This represents the bottom of the chart area
|
||||||
|
|
||||||
val path = Path().apply {
|
val path = Path().apply {
|
||||||
// Start from bottom-left (at chart bottom level)
|
// Start from bottom-left (at chart bottom level)
|
||||||
moveTo(points.first().x, bottomY)
|
moveTo(points.first().x, bottomY)
|
||||||
|
|
||||||
// Draw to first point
|
// Draw to first point
|
||||||
lineTo(points.first().x, points.first().y)
|
lineTo(points.first().x, points.first().y)
|
||||||
|
|
||||||
// Draw line through all points
|
// Draw line through all points
|
||||||
for (i in 1 until points.size) {
|
for (i in 1 until points.size) {
|
||||||
lineTo(points[i].x, points[i].y)
|
lineTo(points[i].x, points[i].y)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the path by going to bottom-right (at chart bottom level) and back to start
|
// Close the path by going to bottom-right (at chart bottom level) and back to start
|
||||||
lineTo(points.last().x, bottomY)
|
lineTo(points.last().x, bottomY)
|
||||||
lineTo(points.first().x, bottomY)
|
lineTo(points.first().x, bottomY)
|
||||||
close()
|
close()
|
||||||
}
|
}
|
||||||
|
|
||||||
drawPath(
|
drawPath(
|
||||||
path = path,
|
path = path,
|
||||||
color = fillColor
|
color = fillColor,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun DrawScope.drawLine(
|
private fun DrawScope.drawLine(
|
||||||
points: List<Offset>,
|
points: List<Offset>,
|
||||||
lineColor: Color,
|
lineColor: Color,
|
||||||
lineWidth: Float
|
lineWidth: Float,
|
||||||
) {
|
) {
|
||||||
val path = Path().apply {
|
val path = Path().apply {
|
||||||
moveTo(points.first().x, points.first().y)
|
moveTo(points.first().x, points.first().y)
|
||||||
@@ -289,14 +289,14 @@ private fun DrawScope.drawLine(
|
|||||||
lineTo(points[i].x, points[i].y)
|
lineTo(points[i].x, points[i].y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
drawPath(
|
drawPath(
|
||||||
path = path,
|
path = path,
|
||||||
color = lineColor,
|
color = lineColor,
|
||||||
style = Stroke(
|
style = Stroke(
|
||||||
width = lineWidth,
|
width = lineWidth,
|
||||||
cap = StrokeCap.Round,
|
cap = StrokeCap.Round,
|
||||||
join = StrokeJoin.Round
|
join = StrokeJoin.Round,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,59 +15,59 @@ import androidx.compose.ui.window.DialogProperties
|
|||||||
@Composable
|
@Composable
|
||||||
fun NotificationPermissionDialog(onDismiss: () -> Unit, onRequestPermission: () -> Unit) {
|
fun NotificationPermissionDialog(onDismiss: () -> Unit, onRequestPermission: () -> Unit) {
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false),
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
shape = MaterialTheme.shapes.medium
|
shape = MaterialTheme.shapes.medium,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.padding(24.dp),
|
modifier = Modifier.padding(24.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Notifications,
|
imageVector = Icons.Default.Notifications,
|
||||||
contentDescription = "Notifications",
|
contentDescription = "Notifications",
|
||||||
modifier = Modifier.size(48.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "Enable Notifications",
|
text = "Enable Notifications",
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
fontWeight = MaterialTheme.typography.headlineSmall.fontWeight,
|
fontWeight = MaterialTheme.typography.headlineSmall.fontWeight,
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Ascently needs notification permission to show your active climbing session. This helps you track your progress and ensures the session doesn't get interrupted.",
|
"Ascently needs notification permission to show your active climbing session. This helps you track your progress and ensures the session doesn't get interrupted.",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
TextButton(onClick = onDismiss, modifier = Modifier.weight(1f)) {
|
TextButton(onClick = onDismiss, modifier = Modifier.weight(1f)) {
|
||||||
Text("Not Now")
|
Text("Not Now")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
onRequestPermission()
|
onRequestPermission()
|
||||||
onDismiss()
|
onDismiss()
|
||||||
},
|
},
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
) { Text("Enable") }
|
) { Text("Enable") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,39 +16,39 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import com.atridad.ascently.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import java.io.File
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OrientationAwareImage(
|
fun OrientationAwareImage(
|
||||||
imagePath: String,
|
imagePath: String,
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
contentDescription: String? = null,
|
contentDescription: String? = null,
|
||||||
contentScale: ContentScale = ContentScale.Fit
|
contentScale: ContentScale = ContentScale.Fit,
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var imageBitmap by
|
var imageBitmap by
|
||||||
remember(imagePath) { mutableStateOf<androidx.compose.ui.graphics.ImageBitmap?>(null) }
|
remember(imagePath) { mutableStateOf<androidx.compose.ui.graphics.ImageBitmap?>(null) }
|
||||||
var isLoading by remember(imagePath) { mutableStateOf(true) }
|
var isLoading by remember(imagePath) { mutableStateOf(true) }
|
||||||
|
|
||||||
LaunchedEffect(imagePath) {
|
LaunchedEffect(imagePath) {
|
||||||
isLoading = true
|
isLoading = true
|
||||||
val bitmap =
|
val bitmap =
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
try {
|
||||||
val imageFile = ImageUtils.getImageFile(context, imagePath)
|
val imageFile = ImageUtils.getImageFile(context, imagePath)
|
||||||
if (!imageFile.exists()) return@withContext null
|
if (!imageFile.exists()) return@withContext null
|
||||||
|
|
||||||
val originalBitmap =
|
val originalBitmap =
|
||||||
BitmapFactory.decodeFile(imageFile.absolutePath)
|
BitmapFactory.decodeFile(imageFile.absolutePath)
|
||||||
?: return@withContext null
|
?: return@withContext null
|
||||||
val correctedBitmap = correctImageOrientation(imageFile, originalBitmap)
|
val correctedBitmap = correctImageOrientation(imageFile, originalBitmap)
|
||||||
correctedBitmap.asImageBitmap()
|
correctedBitmap.asImageBitmap()
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
null
|
null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
imageBitmap = bitmap
|
imageBitmap = bitmap
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
@@ -59,10 +59,10 @@ fun OrientationAwareImage(
|
|||||||
} else {
|
} else {
|
||||||
imageBitmap?.let { bitmap ->
|
imageBitmap?.let { bitmap ->
|
||||||
Image(
|
Image(
|
||||||
bitmap = bitmap,
|
bitmap = bitmap,
|
||||||
contentDescription = contentDescription,
|
contentDescription = contentDescription,
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
contentScale = contentScale
|
contentScale = contentScale,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,16 +70,16 @@ fun OrientationAwareImage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun correctImageOrientation(
|
private fun correctImageOrientation(
|
||||||
imageFile: File,
|
imageFile: File,
|
||||||
bitmap: android.graphics.Bitmap
|
bitmap: android.graphics.Bitmap,
|
||||||
): android.graphics.Bitmap {
|
): android.graphics.Bitmap {
|
||||||
return try {
|
return try {
|
||||||
val exif = ExifInterface(imageFile.absolutePath)
|
val exif = ExifInterface(imageFile.absolutePath)
|
||||||
val orientation =
|
val orientation =
|
||||||
exif.getAttributeInt(
|
exif.getAttributeInt(
|
||||||
ExifInterface.TAG_ORIENTATION,
|
ExifInterface.TAG_ORIENTATION,
|
||||||
ExifInterface.ORIENTATION_NORMAL
|
ExifInterface.ORIENTATION_NORMAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
val matrix = Matrix()
|
val matrix = Matrix()
|
||||||
var needsTransform = false
|
var needsTransform = false
|
||||||
@@ -124,15 +124,15 @@ private fun correctImageOrientation(
|
|||||||
bitmap
|
bitmap
|
||||||
} else {
|
} else {
|
||||||
val rotatedBitmap =
|
val rotatedBitmap =
|
||||||
android.graphics.Bitmap.createBitmap(
|
android.graphics.Bitmap.createBitmap(
|
||||||
bitmap,
|
bitmap,
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
bitmap.width,
|
bitmap.width,
|
||||||
bitmap.height,
|
bitmap.height,
|
||||||
matrix,
|
matrix,
|
||||||
true
|
true,
|
||||||
)
|
)
|
||||||
if (rotatedBitmap != bitmap) {
|
if (rotatedBitmap != bitmap) {
|
||||||
bitmap.recycle()
|
bitmap.recycle()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,23 +26,23 @@ fun SyncIndicator(isSyncing: StateFlow<Boolean>, modifier: Modifier = Modifier)
|
|||||||
val syncing by isSyncing.collectAsState()
|
val syncing by isSyncing.collectAsState()
|
||||||
|
|
||||||
AnimatedVisibility(
|
AnimatedVisibility(
|
||||||
visible = syncing,
|
visible = syncing,
|
||||||
enter = scaleIn() + fadeIn(),
|
enter = scaleIn() + fadeIn(),
|
||||||
exit = scaleOut() + fadeOut(),
|
exit = scaleOut() + fadeOut(),
|
||||||
modifier = modifier
|
modifier = modifier,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.size(28.dp)
|
Modifier.size(28.dp)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape)
|
.background(MaterialTheme.colorScheme.primaryContainer, CircleShape)
|
||||||
.padding(6.dp),
|
.padding(6.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
CircularProgressIndicator(
|
CircularProgressIndicator(
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(16.dp),
|
||||||
strokeWidth = 2.dp,
|
strokeWidth = 2.dp,
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,19 +36,19 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
|
|
||||||
// Permission launcher
|
// Permission launcher
|
||||||
val permissionLauncher =
|
val permissionLauncher =
|
||||||
rememberLauncherForActivityResult(
|
rememberLauncherForActivityResult(
|
||||||
contract = healthConnectManager.getPermissionRequestContract()
|
contract = healthConnectManager.getPermissionRequestContract(),
|
||||||
) { _ ->
|
) { _ ->
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val allGranted = healthConnectManager.hasAllPermissions()
|
val allGranted = healthConnectManager.hasAllPermissions()
|
||||||
if (!allGranted) {
|
if (!allGranted) {
|
||||||
errorMessage =
|
errorMessage =
|
||||||
"Some Health Connect permissions were not granted. Please grant all permissions to enable syncing."
|
"Some Health Connect permissions were not granted. Please grant all permissions to enable syncing."
|
||||||
} else {
|
} else {
|
||||||
errorMessage = null
|
errorMessage = null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check Health Connect availability on first load
|
// Check Health Connect availability on first load
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
@@ -62,7 +62,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
errorMessage = "Health Connect is not available on this device"
|
errorMessage = "Health Connect is not available on this device"
|
||||||
} else if (!isCompatible) {
|
} else if (!isCompatible) {
|
||||||
errorMessage =
|
errorMessage =
|
||||||
"Health Connect API compatibility issue. Please update your device or the app."
|
"Health Connect API compatibility issue. Please update your device or the app."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -73,32 +73,32 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = modifier.fillMaxWidth(),
|
modifier = modifier.fillMaxWidth(),
|
||||||
shape = RoundedCornerShape(16.dp),
|
shape = RoundedCornerShape(16.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
// Header with icon and title
|
// Header with icon and title
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.HealthAndSafety,
|
imageVector = Icons.Default.HealthAndSafety,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint =
|
tint =
|
||||||
if (isHealthConnectAvailable && isEnabled && hasPermissions) {
|
if (isHealthConnectAvailable && isEnabled && hasPermissions) {
|
||||||
MaterialTheme.colorScheme.primary
|
MaterialTheme.colorScheme.primary
|
||||||
} else {
|
} else {
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant
|
MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
@@ -108,40 +108,40 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
text = "Health Connect",
|
text = "Health Connect",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
when {
|
when {
|
||||||
isLoading -> "Checking availability..."
|
isLoading -> "Checking availability..."
|
||||||
!isCompatible -> "API Issue"
|
!isCompatible -> "API Issue"
|
||||||
!isHealthConnectAvailable -> "Not available"
|
!isHealthConnectAvailable -> "Not available"
|
||||||
isEnabled && hasPermissions -> "Connected"
|
isEnabled && hasPermissions -> "Connected"
|
||||||
isEnabled && !hasPermissions -> "Needs permissions"
|
isEnabled && !hasPermissions -> "Needs permissions"
|
||||||
else -> "Disabled"
|
else -> "Disabled"
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color =
|
color =
|
||||||
when {
|
when {
|
||||||
isLoading ->
|
isLoading ->
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
alpha = 0.7f
|
alpha = 0.7f,
|
||||||
)
|
)
|
||||||
|
|
||||||
!isCompatible -> MaterialTheme.colorScheme.error
|
!isCompatible -> MaterialTheme.colorScheme.error
|
||||||
!isHealthConnectAvailable -> MaterialTheme.colorScheme.error
|
!isHealthConnectAvailable -> MaterialTheme.colorScheme.error
|
||||||
isEnabled && hasPermissions ->
|
isEnabled && hasPermissions ->
|
||||||
MaterialTheme.colorScheme.primary
|
MaterialTheme.colorScheme.primary
|
||||||
|
|
||||||
isEnabled && !hasPermissions ->
|
isEnabled && !hasPermissions ->
|
||||||
MaterialTheme.colorScheme.tertiary
|
MaterialTheme.colorScheme.tertiary
|
||||||
|
|
||||||
else ->
|
else ->
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
alpha = 0.7f
|
alpha = 0.7f,
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = isHealthConnectAvailable && !isLoading && isCompatible
|
enabled = isHealthConnectAvailable && !isLoading && isCompatible,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth(),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (!hasPermissions) {
|
if (!hasPermissions) {
|
||||||
@@ -187,12 +187,12 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.errorContainer.copy(
|
MaterialTheme.colorScheme.errorContainer.copy(
|
||||||
alpha = 0.3f
|
alpha = 0.3f,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
@@ -200,7 +200,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
imageVector = Icons.Default.Warning,
|
imageVector = Icons.Default.Warning,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(20.dp),
|
modifier = Modifier.size(20.dp),
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = MaterialTheme.colorScheme.error,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
@@ -209,7 +209,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
text = "Permissions needed",
|
text = "Permissions needed",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.Medium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,12 +217,12 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Grant Health Connect permissions to sync your climbing sessions",
|
"Grant Health Connect permissions to sync your climbing sessions",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color =
|
color =
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
alpha = 0.8f
|
alpha = 0.8f,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -243,7 +243,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text("Grant Permissions") }
|
) { Text("Grant Permissions") }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -251,10 +251,10 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Sync your climbing sessions to Samsung Health, Google Fit, and other fitness apps through Health Connect.",
|
"Sync your climbing sessions to Samsung Health, Google Fit, and other fitness apps through Health Connect.",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.8f)
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.8f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
errorMessage?.let { error ->
|
errorMessage?.let { error ->
|
||||||
@@ -263,22 +263,22 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
Card(
|
Card(
|
||||||
shape = RoundedCornerShape(8.dp),
|
shape = RoundedCornerShape(8.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.errorContainer.copy(
|
MaterialTheme.colorScheme.errorContainer.copy(
|
||||||
alpha = 0.5f
|
alpha = 0.5f,
|
||||||
)
|
),
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(12.dp),
|
modifier = Modifier.fillMaxWidth().padding(12.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Warning,
|
imageVector = Icons.Default.Warning,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(16.dp),
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = MaterialTheme.colorScheme.error,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
@@ -286,7 +286,7 @@ fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|||||||
Text(
|
Text(
|
||||||
text = error,
|
text = error,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onErrorContainer
|
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -28,26 +28,26 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
|||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.fillMaxSize().padding(16.dp),
|
modifier = Modifier.fillMaxSize().padding(16.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||||
) {
|
) {
|
||||||
item {
|
item {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "Ascently Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Analytics",
|
text = "Analytics",
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
||||||
}
|
}
|
||||||
@@ -56,10 +56,10 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
|||||||
// Overall Stats
|
// Overall Stats
|
||||||
item {
|
item {
|
||||||
OverallStatsCard(
|
OverallStatsCard(
|
||||||
totalSessions = sessions.size,
|
totalSessions = sessions.size,
|
||||||
totalProblems = problems.size,
|
totalProblems = problems.size,
|
||||||
totalAttempts = attempts.size,
|
totalAttempts = attempts.size,
|
||||||
totalGyms = gyms.size
|
totalGyms = gyms.size,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,14 +72,14 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
|||||||
// Favorite Gym
|
// Favorite Gym
|
||||||
item {
|
item {
|
||||||
val favoriteGym =
|
val favoriteGym =
|
||||||
sessions.groupBy { it.gymId }.maxByOrNull { it.value.size }?.let {
|
sessions.groupBy { it.gymId }.maxByOrNull { it.value.size }?.let {
|
||||||
(gymId, sessions) ->
|
(gymId, sessions) ->
|
||||||
gyms.find { it.id == gymId }?.name to sessions.size
|
gyms.find { it.id == gymId }?.name to sessions.size
|
||||||
}
|
}
|
||||||
|
|
||||||
FavoriteGymCard(
|
FavoriteGymCard(
|
||||||
gymName = favoriteGym?.first ?: "No sessions yet",
|
gymName = favoriteGym?.first ?: "No sessions yet",
|
||||||
sessionCount = favoriteGym?.second ?: 0
|
sessionCount = favoriteGym?.second ?: 0,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,16 +96,16 @@ fun OverallStatsCard(totalSessions: Int, totalProblems: Int, totalAttempts: Int,
|
|||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Overall Stats",
|
text = "Overall Stats",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
) {
|
) {
|
||||||
StatItem(label = "Sessions", value = totalSessions.toString())
|
StatItem(label = "Sessions", value = totalSessions.toString())
|
||||||
StatItem(label = "Problems", value = totalProblems.toString())
|
StatItem(label = "Problems", value = totalProblems.toString())
|
||||||
@@ -121,113 +121,113 @@ fun OverallStatsCard(totalSessions: Int, totalProblems: Int, totalAttempts: Int,
|
|||||||
fun GradeDistributionChartCard(gradeDistributionData: List<GradeDistributionDataPoint>) {
|
fun GradeDistributionChartCard(gradeDistributionData: List<GradeDistributionDataPoint>) {
|
||||||
// Find all grading systems that have been used in the data
|
// Find all grading systems that have been used in the data
|
||||||
val usedSystems =
|
val usedSystems =
|
||||||
remember(gradeDistributionData) {
|
remember(gradeDistributionData) {
|
||||||
gradeDistributionData.map { it.difficultySystem }.distinct()
|
gradeDistributionData.map { it.difficultySystem }.distinct()
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedSystem by
|
var selectedSystem by
|
||||||
remember(usedSystems) {
|
remember(usedSystems) {
|
||||||
mutableStateOf(usedSystems.firstOrNull() ?: DifficultySystem.V_SCALE)
|
mutableStateOf(usedSystems.firstOrNull() ?: DifficultySystem.V_SCALE)
|
||||||
}
|
}
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
var showAllTime by remember { mutableStateOf(true) }
|
var showAllTime by remember { mutableStateOf(true) }
|
||||||
|
|
||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Grade Distribution",
|
text = "Grade Distribution",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
// Toggles section
|
// Toggles section
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
// Time period toggle
|
// Time period toggle
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
// All Time button
|
// All Time button
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { showAllTime = true },
|
onClick = { showAllTime = true },
|
||||||
label = {
|
label = {
|
||||||
Text("All Time", style = MaterialTheme.typography.bodySmall)
|
Text("All Time", style = MaterialTheme.typography.bodySmall)
|
||||||
},
|
},
|
||||||
selected = showAllTime,
|
selected = showAllTime,
|
||||||
colors =
|
colors =
|
||||||
FilterChipDefaults.filterChipColors(
|
FilterChipDefaults.filterChipColors(
|
||||||
selectedContainerColor =
|
selectedContainerColor =
|
||||||
MaterialTheme.colorScheme.primary,
|
MaterialTheme.colorScheme.primary,
|
||||||
selectedLabelColor = MaterialTheme.colorScheme.onPrimary
|
selectedLabelColor = MaterialTheme.colorScheme.onPrimary,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// 7 Days button
|
// 7 Days button
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { showAllTime = false },
|
onClick = { showAllTime = false },
|
||||||
label = { Text("7 Days", style = MaterialTheme.typography.bodySmall) },
|
label = { Text("7 Days", style = MaterialTheme.typography.bodySmall) },
|
||||||
selected = !showAllTime,
|
selected = !showAllTime,
|
||||||
colors =
|
colors =
|
||||||
FilterChipDefaults.filterChipColors(
|
FilterChipDefaults.filterChipColors(
|
||||||
selectedContainerColor =
|
selectedContainerColor =
|
||||||
MaterialTheme.colorScheme.primary,
|
MaterialTheme.colorScheme.primary,
|
||||||
selectedLabelColor = MaterialTheme.colorScheme.onPrimary
|
selectedLabelColor = MaterialTheme.colorScheme.onPrimary,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scale selector dropdown
|
// Scale selector dropdown
|
||||||
if (usedSystems.size > 1) {
|
if (usedSystems.size > 1) {
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onExpandedChange = { expanded = !expanded }
|
onExpandedChange = { expanded = !expanded },
|
||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value =
|
value =
|
||||||
when (selectedSystem) {
|
when (selectedSystem) {
|
||||||
DifficultySystem.V_SCALE -> "V-Scale"
|
DifficultySystem.V_SCALE -> "V-Scale"
|
||||||
DifficultySystem.FONT -> "Font"
|
DifficultySystem.FONT -> "Font"
|
||||||
DifficultySystem.YDS -> "YDS"
|
DifficultySystem.YDS -> "YDS"
|
||||||
DifficultySystem.CUSTOM -> "Custom"
|
DifficultySystem.CUSTOM -> "Custom"
|
||||||
},
|
},
|
||||||
onValueChange = {},
|
onValueChange = {},
|
||||||
readOnly = true,
|
readOnly = true,
|
||||||
trailingIcon = {
|
trailingIcon = {
|
||||||
ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded)
|
ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded)
|
||||||
},
|
},
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.menuAnchor(
|
Modifier.menuAnchor(
|
||||||
type =
|
type =
|
||||||
ExposedDropdownMenuAnchorType
|
ExposedDropdownMenuAnchorType
|
||||||
.PrimaryNotEditable,
|
.PrimaryNotEditable,
|
||||||
enabled = true
|
enabled = true,
|
||||||
)
|
)
|
||||||
.width(120.dp),
|
.width(120.dp),
|
||||||
textStyle = MaterialTheme.typography.bodyMedium
|
textStyle = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
onDismissRequest = { expanded = false }
|
onDismissRequest = { expanded = false },
|
||||||
) {
|
) {
|
||||||
usedSystems.forEach { system ->
|
usedSystems.forEach { system ->
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
text = {
|
text = {
|
||||||
Text(
|
Text(
|
||||||
when (system) {
|
when (system) {
|
||||||
DifficultySystem.V_SCALE -> "V-Scale"
|
DifficultySystem.V_SCALE -> "V-Scale"
|
||||||
DifficultySystem.FONT -> "Font"
|
DifficultySystem.FONT -> "Font"
|
||||||
DifficultySystem.YDS -> "YDS"
|
DifficultySystem.YDS -> "YDS"
|
||||||
DifficultySystem.CUSTOM -> "Custom"
|
DifficultySystem.CUSTOM -> "Custom"
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedSystem = system
|
selectedSystem = system
|
||||||
expanded = false
|
expanded = false
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,89 +239,91 @@ fun GradeDistributionChartCard(gradeDistributionData: List<GradeDistributionData
|
|||||||
|
|
||||||
// Filter grade distribution data by selected scale and time period
|
// Filter grade distribution data by selected scale and time period
|
||||||
val filteredGradeData =
|
val filteredGradeData =
|
||||||
remember(gradeDistributionData, selectedSystem, showAllTime) {
|
remember(gradeDistributionData, selectedSystem, showAllTime) {
|
||||||
val systemFiltered =
|
val systemFiltered =
|
||||||
gradeDistributionData.filter {
|
gradeDistributionData.filter {
|
||||||
it.difficultySystem == selectedSystem
|
it.difficultySystem == selectedSystem
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showAllTime) {
|
if (showAllTime) {
|
||||||
systemFiltered
|
systemFiltered
|
||||||
} else {
|
} else {
|
||||||
// Filter for last 7 days
|
// Filter for last 7 days
|
||||||
val sevenDaysAgo = LocalDateTime.now().minusDays(7)
|
val sevenDaysAgo = LocalDateTime.now().minusDays(7)
|
||||||
systemFiltered.filter { dataPoint ->
|
systemFiltered.filter { dataPoint ->
|
||||||
try {
|
try {
|
||||||
val attemptDate =
|
val attemptDate =
|
||||||
DateFormatUtils.parseToLocalDateTime(dataPoint.date)
|
DateFormatUtils.parseToLocalDateTime(dataPoint.date)
|
||||||
attemptDate?.isAfter(sevenDaysAgo) == true
|
attemptDate?.isAfter(sevenDaysAgo) == true
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
// If date parsing fails, include the data point
|
// If date parsing fails, include the data point
|
||||||
true
|
true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (filteredGradeData.isNotEmpty()) {
|
if (filteredGradeData.isNotEmpty()) {
|
||||||
// Group by grade and sum counts
|
// Group by grade and sum counts
|
||||||
val gradeGroups =
|
val gradeGroups =
|
||||||
filteredGradeData
|
filteredGradeData
|
||||||
.groupBy { it.grade }
|
.groupBy { it.grade }
|
||||||
.mapValues { (_, dataPoints) -> dataPoints.sumOf { it.count } }
|
.mapValues { (_, dataPoints) -> dataPoints.sumOf { it.count } }
|
||||||
.map { (grade, count) ->
|
.map { (grade, count) ->
|
||||||
val firstDataPoint =
|
val firstDataPoint =
|
||||||
filteredGradeData.first { it.grade == grade }
|
filteredGradeData.first { it.grade == grade }
|
||||||
BarChartDataPoint(
|
BarChartDataPoint(
|
||||||
label = grade,
|
label = grade,
|
||||||
value = count,
|
value = count,
|
||||||
gradeNumeric = firstDataPoint.gradeNumeric
|
gradeNumeric = firstDataPoint.gradeNumeric,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
BarChart(data = gradeGroups, modifier = Modifier.fillMaxWidth().height(220.dp))
|
BarChart(data = gradeGroups, modifier = Modifier.fillMaxWidth().height(220.dp))
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Successful climbs by ${when(selectedSystem) {
|
"Successful climbs by ${when (selectedSystem) {
|
||||||
DifficultySystem.V_SCALE -> "V-grade"
|
DifficultySystem.V_SCALE -> "V-grade"
|
||||||
DifficultySystem.FONT -> "Font grade"
|
DifficultySystem.FONT -> "Font grade"
|
||||||
DifficultySystem.YDS -> "YDS grade"
|
DifficultySystem.YDS -> "YDS grade"
|
||||||
DifficultySystem.CUSTOM -> "custom grade"
|
DifficultySystem.CUSTOM -> "custom grade"
|
||||||
}}",
|
}}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxWidth().height(220.dp),
|
modifier = Modifier.fillMaxWidth().height(220.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "No data",
|
contentDescription = "No data",
|
||||||
modifier = Modifier.size(48.dp),
|
modifier = Modifier.size(48.dp),
|
||||||
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f)
|
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f),
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "No data available.",
|
text = "No data available.",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
if (showAllTime)
|
if (showAllTime) {
|
||||||
"Complete some climbs to see your grade distribution!"
|
"Complete some climbs to see your grade distribution!"
|
||||||
else "No climbs in the last 7 days",
|
} else {
|
||||||
style = MaterialTheme.typography.bodySmall,
|
"No climbs in the last 7 days"
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f)
|
},
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.7f),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -334,24 +336,24 @@ fun FavoriteGymCard(gymName: String, sessionCount: Int) {
|
|||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Favorite Gym",
|
text = "Favorite Gym",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = gymName,
|
text = gymName,
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (sessionCount > 0) {
|
if (sessionCount > 0) {
|
||||||
Text(
|
Text(
|
||||||
text = "$sessionCount sessions",
|
text = "$sessionCount sessions",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -363,39 +365,39 @@ fun RecentActivityCard(recentSessions: Int) {
|
|||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Recent Activity",
|
text = "Recent Activity",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
if (recentSessions > 0) {
|
if (recentSessions > 0) {
|
||||||
"You've had $recentSessions recent sessions"
|
"You've had $recentSessions recent sessions"
|
||||||
} else {
|
} else {
|
||||||
"No recent activity"
|
"No recent activity"
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class GradeDistributionDataPoint(
|
data class GradeDistributionDataPoint(
|
||||||
val date: String,
|
val date: String,
|
||||||
val grade: String,
|
val grade: String,
|
||||||
val gradeNumeric: Int,
|
val gradeNumeric: Int,
|
||||||
val count: Int,
|
val count: Int,
|
||||||
val climbType: ClimbType,
|
val climbType: ClimbType,
|
||||||
val difficultySystem: DifficultySystem
|
val difficultySystem: DifficultySystem,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun calculateGradeDistribution(
|
fun calculateGradeDistribution(
|
||||||
sessions: List<com.atridad.ascently.data.model.ClimbSession>,
|
sessions: List<com.atridad.ascently.data.model.ClimbSession>,
|
||||||
problems: List<com.atridad.ascently.data.model.Problem>,
|
problems: List<com.atridad.ascently.data.model.Problem>,
|
||||||
attempts: List<com.atridad.ascently.data.model.Attempt>
|
attempts: List<com.atridad.ascently.data.model.Attempt>,
|
||||||
): List<GradeDistributionDataPoint> {
|
): List<GradeDistributionDataPoint> {
|
||||||
if (sessions.isEmpty() || problems.isEmpty() || attempts.isEmpty()) {
|
if (sessions.isEmpty() || problems.isEmpty() || attempts.isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
@@ -403,9 +405,9 @@ fun calculateGradeDistribution(
|
|||||||
|
|
||||||
// Get all successful attempts
|
// Get all successful attempts
|
||||||
val successfulAttempts =
|
val successfulAttempts =
|
||||||
attempts.filter {
|
attempts.filter {
|
||||||
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
||||||
}
|
}
|
||||||
|
|
||||||
if (successfulAttempts.isEmpty()) {
|
if (successfulAttempts.isEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
@@ -426,18 +428,18 @@ fun calculateGradeDistribution(
|
|||||||
gradeDistribution[key] = existing.copy(count = existing.count + 1)
|
gradeDistribution[key] = existing.copy(count = existing.count + 1)
|
||||||
} else {
|
} else {
|
||||||
gradeDistribution[key] =
|
gradeDistribution[key] =
|
||||||
GradeDistributionDataPoint(
|
GradeDistributionDataPoint(
|
||||||
date = attempt.timestamp,
|
date = attempt.timestamp,
|
||||||
grade = problem.difficulty.grade,
|
grade = problem.difficulty.grade,
|
||||||
gradeNumeric =
|
gradeNumeric =
|
||||||
gradeToNumeric(
|
gradeToNumeric(
|
||||||
problem.difficulty.system,
|
problem.difficulty.system,
|
||||||
problem.difficulty.grade
|
problem.difficulty.grade,
|
||||||
),
|
),
|
||||||
count = 1,
|
count = 1,
|
||||||
climbType = problem.climbType,
|
climbType = problem.climbType,
|
||||||
difficultySystem = problem.difficulty.system
|
difficultySystem = problem.difficulty.system,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -22,21 +22,21 @@ fun GymsScreen(viewModel: ClimbViewModel, onNavigateToGymDetail: (String) -> Uni
|
|||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "Ascently Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Climbing Gyms",
|
text = "Climbing Gyms",
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
||||||
}
|
}
|
||||||
@@ -45,10 +45,10 @@ fun GymsScreen(viewModel: ClimbViewModel, onNavigateToGymDetail: (String) -> Uni
|
|||||||
|
|
||||||
if (gyms.isEmpty()) {
|
if (gyms.isEmpty()) {
|
||||||
EmptyStateMessage(
|
EmptyStateMessage(
|
||||||
title = "No Gyms Added",
|
title = "No Gyms Added",
|
||||||
message = "Add your favorite climbing gyms to start tracking your progress!",
|
message = "Add your favorite climbing gyms to start tracking your progress!",
|
||||||
onActionClick = {},
|
onActionClick = {},
|
||||||
actionText = ""
|
actionText = "",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
@@ -67,17 +67,17 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = gym.name,
|
text = gym.name,
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
gym.location?.let { location ->
|
gym.location?.let { location ->
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = location,
|
text = location,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,9 +86,9 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
Row {
|
Row {
|
||||||
gym.supportedClimbTypes.forEach { climbType ->
|
gym.supportedClimbTypes.forEach { climbType ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = {},
|
onClick = {},
|
||||||
label = { Text(climbType.displayName) },
|
label = { Text(climbType.displayName) },
|
||||||
modifier = Modifier.padding(end = 4.dp)
|
modifier = Modifier.padding(end = 4.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -96,10 +96,10 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
if (gym.difficultySystems.isNotEmpty()) {
|
if (gym.difficultySystems.isNotEmpty()) {
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Systems: ${gym.difficultySystems.joinToString(", ") { it.displayName }}",
|
"Systems: ${gym.difficultySystems.joinToString(", ") { it.displayName }}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +107,10 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
if (notes.isNotBlank()) {
|
if (notes.isNotBlank()) {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = notes,
|
text = notes,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
maxLines = 2
|
maxLines = 2,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
|
|
||||||
// Apply filters
|
// Apply filters
|
||||||
val filteredProblems =
|
val filteredProblems =
|
||||||
problems.filter { problem ->
|
problems.filter { problem ->
|
||||||
val climbTypeMatch = selectedClimbType?.let { it == problem.climbType } != false
|
val climbTypeMatch = selectedClimbType?.let { it == problem.climbType } != false
|
||||||
val gymMatch = selectedGym?.let { it.id == problem.gymId } != false
|
val gymMatch = selectedGym?.let { it.id == problem.gymId } != false
|
||||||
climbTypeMatch && gymMatch
|
climbTypeMatch && gymMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separate active and inactive problems
|
// Separate active and inactive problems
|
||||||
val activeProblems = filteredProblems.filter { it.isActive }
|
val activeProblems = filteredProblems.filter { it.isActive }
|
||||||
@@ -49,21 +49,21 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "Ascently Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Climbing Problems",
|
text = "Climbing Problems",
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
SyncIndicator(isSyncing = viewModel.syncService.isSyncing)
|
||||||
}
|
}
|
||||||
@@ -75,18 +75,18 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
Card(modifier = Modifier.fillMaxWidth()) {
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.padding(16.dp)) {
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = "Filters",
|
text = "Filters",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
// Climb Type Filter
|
// Climb Type Filter
|
||||||
Text(
|
Text(
|
||||||
text = "Climb Type",
|
text = "Climb Type",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -94,16 +94,16 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
item {
|
item {
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = null },
|
onClick = { selectedClimbType = null },
|
||||||
label = { Text("All Types") },
|
label = { Text("All Types") },
|
||||||
selected = selectedClimbType == null
|
selected = selectedClimbType == null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
items(ClimbType.entries) { climbType ->
|
items(ClimbType.entries) { climbType ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = climbType },
|
onClick = { selectedClimbType = climbType },
|
||||||
label = { Text(climbType.displayName) },
|
label = { Text(climbType.displayName) },
|
||||||
selected = selectedClimbType == climbType
|
selected = selectedClimbType == climbType,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,9 +112,9 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
|
|
||||||
// Gym Filter
|
// Gym Filter
|
||||||
Text(
|
Text(
|
||||||
text = "Gym",
|
text = "Gym",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -122,16 +122,16 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
item {
|
item {
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedGym = null },
|
onClick = { selectedGym = null },
|
||||||
label = { Text("All Gyms") },
|
label = { Text("All Gyms") },
|
||||||
selected = selectedGym == null
|
selected = selectedGym == null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
items(gyms) { gym ->
|
items(gyms) { gym ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedGym = gym },
|
onClick = { selectedGym = gym },
|
||||||
label = { Text(gym.name) },
|
label = { Text(gym.name) },
|
||||||
selected = selectedGym?.id == gym.id
|
selected = selectedGym?.id == gym.id,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,10 +140,10 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
if (selectedClimbType != null || selectedGym != null) {
|
if (selectedClimbType != null || selectedGym != null) {
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Showing ${filteredProblems.size} of ${problems.size} problems (${activeProblems.size} active, ${inactiveProblems.size} reset)",
|
"Showing ${filteredProblems.size} of ${problems.size} problems (${activeProblems.size} active, ${inactiveProblems.size} reset)",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,35 +154,37 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
|
|
||||||
if (filteredProblems.isEmpty()) {
|
if (filteredProblems.isEmpty()) {
|
||||||
EmptyStateMessage(
|
EmptyStateMessage(
|
||||||
title =
|
title =
|
||||||
if (problems.isEmpty()) {
|
if (problems.isEmpty()) {
|
||||||
if (gyms.isEmpty()) "No Gyms Available" else "No Problems Yet"
|
if (gyms.isEmpty()) "No Gyms Available" else "No Problems Yet"
|
||||||
} else {
|
} else {
|
||||||
"No Problems Match Filters"
|
"No Problems Match Filters"
|
||||||
},
|
},
|
||||||
message =
|
message =
|
||||||
if (problems.isEmpty()) {
|
if (problems.isEmpty()) {
|
||||||
if (gyms.isEmpty())
|
if (gyms.isEmpty()) {
|
||||||
"Add a gym first to start tracking problems and routes!"
|
"Add a gym first to start tracking problems and routes!"
|
||||||
else "Start tracking your favorite problems and routes!"
|
} else {
|
||||||
} else {
|
"Start tracking your favorite problems and routes!"
|
||||||
"Try adjusting your filters to see more problems."
|
}
|
||||||
},
|
} else {
|
||||||
onActionClick = {},
|
"Try adjusting your filters to see more problems."
|
||||||
actionText = ""
|
},
|
||||||
|
onActionClick = {},
|
||||||
|
actionText = "",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
items(sortedProblems) { problem ->
|
items(sortedProblems) { problem ->
|
||||||
ProblemCard(
|
ProblemCard(
|
||||||
problem = problem,
|
problem = problem,
|
||||||
gymName = gyms.find { it.id == problem.gymId }?.name ?: "Unknown Gym",
|
gymName = gyms.find { it.id == problem.gymId }?.name ?: "Unknown Gym",
|
||||||
attempts = attempts,
|
attempts = attempts,
|
||||||
onClick = { onNavigateToProblemDetail(problem.id) },
|
onClick = { onNavigateToProblemDetail(problem.id) },
|
||||||
onToggleActive = {
|
onToggleActive = {
|
||||||
val updatedProblem = problem.copy(isActive = !problem.isActive)
|
val updatedProblem = problem.copy(isActive = !problem.isActive)
|
||||||
viewModel.updateProblem(updatedProblem)
|
viewModel.updateProblem(updatedProblem)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
@@ -194,81 +196,86 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ProblemCard(
|
fun ProblemCard(
|
||||||
problem: Problem,
|
problem: Problem,
|
||||||
gymName: String,
|
gymName: String,
|
||||||
attempts: List<Attempt>,
|
attempts: List<Attempt>,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onToggleActive: (() -> Unit)? = null
|
onToggleActive: (() -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
val isCompleted =
|
val isCompleted =
|
||||||
attempts.any { attempt ->
|
attempts.any { attempt ->
|
||||||
attempt.problemId == problem.id &&
|
attempt.problemId == problem.id &&
|
||||||
(attempt.result == AttemptResult.SUCCESS ||
|
(
|
||||||
attempt.result == AttemptResult.FLASH)
|
attempt.result == AttemptResult.SUCCESS ||
|
||||||
}
|
attempt.result == AttemptResult.FLASH
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.Top
|
verticalAlignment = Alignment.Top,
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(
|
Text(
|
||||||
text = problem.name ?: "Unnamed Problem",
|
text = problem.name ?: "Unnamed Problem",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color =
|
color =
|
||||||
if (problem.isActive) MaterialTheme.colorScheme.onSurface
|
if (problem.isActive) {
|
||||||
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
MaterialTheme.colorScheme.onSurface
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = gymName,
|
text = gymName,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color =
|
color =
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
alpha = if (problem.isActive) 1f else 0.6f
|
alpha = if (problem.isActive) 1f else 0.6f,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
Column(horizontalAlignment = Alignment.End) {
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
if (problem.imagePaths.isNotEmpty()) {
|
if (problem.imagePaths.isNotEmpty()) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Image,
|
imageVector = Icons.Default.Image,
|
||||||
contentDescription = "Has images",
|
contentDescription = "Has images",
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(16.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCompleted) {
|
if (isCompleted) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.CheckCircle,
|
imageVector = Icons.Default.CheckCircle,
|
||||||
contentDescription = "Completed",
|
contentDescription = "Completed",
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(16.dp),
|
||||||
tint = MaterialTheme.colorScheme.tertiary
|
tint = MaterialTheme.colorScheme.tertiary,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = problem.difficulty.grade,
|
text = problem.difficulty.grade,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = problem.climbType.displayName,
|
text = problem.climbType.displayName,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,9 +283,9 @@ fun ProblemCard(
|
|||||||
problem.location?.let { location ->
|
problem.location?.let { location ->
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Location: $location",
|
text = "Location: $location",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -287,9 +294,9 @@ fun ProblemCard(
|
|||||||
Row {
|
Row {
|
||||||
problem.tags.take(3).forEach { tag ->
|
problem.tags.take(3).forEach { tag ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = {},
|
onClick = {},
|
||||||
label = { Text(tag) },
|
label = { Text(tag) },
|
||||||
modifier = Modifier.padding(end = 4.dp)
|
modifier = Modifier.padding(end = 4.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,10 +305,10 @@ fun ProblemCard(
|
|||||||
if (!problem.isActive) {
|
if (!problem.isActive) {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Reset / No Longer Set",
|
text = "Reset / No Longer Set",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.tertiary,
|
color = MaterialTheme.colorScheme.tertiary,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,19 +316,21 @@ fun ProblemCard(
|
|||||||
if (onToggleActive != null) {
|
if (onToggleActive != null) {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = onToggleActive,
|
onClick = onToggleActive,
|
||||||
colors =
|
colors =
|
||||||
ButtonDefaults.outlinedButtonColors(
|
ButtonDefaults.outlinedButtonColors(
|
||||||
contentColor =
|
contentColor =
|
||||||
if (problem.isActive)
|
if (problem.isActive) {
|
||||||
MaterialTheme.colorScheme.tertiary
|
MaterialTheme.colorScheme.tertiary
|
||||||
else MaterialTheme.colorScheme.primary
|
} else {
|
||||||
),
|
MaterialTheme.colorScheme.primary
|
||||||
modifier = Modifier.fillMaxWidth()
|
},
|
||||||
|
),
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = if (problem.isActive) "Mark as Reset" else "Mark as Active",
|
text = if (problem.isActive) "Mark as Reset" else "Mark as Active",
|
||||||
style = MaterialTheme.typography.bodySmall
|
style = MaterialTheme.typography.bodySmall,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import androidx.compose.ui.res.painterResource
|
|||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.content.edit
|
||||||
import com.atridad.ascently.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.ascently.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.ascently.data.model.SessionStatus
|
import com.atridad.ascently.data.model.SessionStatus
|
||||||
@@ -36,11 +37,10 @@ import java.time.YearMonth
|
|||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.time.format.TextStyle
|
import java.time.format.TextStyle
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import androidx.core.content.edit
|
|
||||||
|
|
||||||
enum class ViewMode {
|
enum class ViewMode {
|
||||||
LIST,
|
LIST,
|
||||||
CALENDAR
|
CALENDAR,
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -53,7 +53,7 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
val uiState by viewModel.uiState.collectAsState()
|
val uiState by viewModel.uiState.collectAsState()
|
||||||
|
|
||||||
val sharedPreferences =
|
val sharedPreferences =
|
||||||
context.getSharedPreferences("SessionsPreferences", Context.MODE_PRIVATE)
|
context.getSharedPreferences("SessionsPreferences", Context.MODE_PRIVATE)
|
||||||
val savedViewMode = sharedPreferences.getString("view_mode", "LIST")
|
val savedViewMode = sharedPreferences.getString("view_mode", "LIST")
|
||||||
var viewMode by remember {
|
var viewMode by remember {
|
||||||
mutableStateOf(if (savedViewMode == "CALENDAR") ViewMode.CALENDAR else ViewMode.LIST)
|
mutableStateOf(if (savedViewMode == "CALENDAR") ViewMode.CALENDAR else ViewMode.LIST)
|
||||||
@@ -66,38 +66,41 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
|
|
||||||
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "Ascently Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = "Climbing Sessions",
|
text = "Climbing Sessions",
|
||||||
style = MaterialTheme.typography.headlineMedium,
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f),
|
||||||
)
|
)
|
||||||
|
|
||||||
IconButton(
|
IconButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
viewMode =
|
viewMode =
|
||||||
if (viewMode == ViewMode.LIST) ViewMode.CALENDAR else ViewMode.LIST
|
if (viewMode == ViewMode.LIST) ViewMode.CALENDAR else ViewMode.LIST
|
||||||
selectedDate = null
|
selectedDate = null
|
||||||
sharedPreferences.edit { putString("view_mode", viewMode.name) }
|
sharedPreferences.edit { putString("view_mode", viewMode.name) }
|
||||||
}
|
},
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector =
|
imageVector =
|
||||||
if (viewMode == ViewMode.LIST) Icons.Default.CalendarMonth
|
if (viewMode == ViewMode.LIST) {
|
||||||
else Icons.AutoMirrored.Filled.List,
|
Icons.Default.CalendarMonth
|
||||||
contentDescription =
|
} else {
|
||||||
if (viewMode == ViewMode.LIST) "Calendar View" else "List View",
|
Icons.AutoMirrored.Filled.List
|
||||||
tint = MaterialTheme.colorScheme.primary
|
},
|
||||||
|
contentDescription =
|
||||||
|
if (viewMode == ViewMode.LIST) "Calendar View" else "List View",
|
||||||
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,10 +110,10 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
ActiveSessionBanner(
|
ActiveSessionBanner(
|
||||||
activeSession = activeSession,
|
activeSession = activeSession,
|
||||||
gym = activeSessionGym,
|
gym = activeSessionGym,
|
||||||
onSessionClick = { activeSession?.let { onNavigateToSessionDetail(it.id) } },
|
onSessionClick = { activeSession?.let { onNavigateToSessionDetail(it.id) } },
|
||||||
onEndSession = { activeSession?.let { viewModel.endSession(context, it.id) } }
|
onEndSession = { activeSession?.let { viewModel.endSession(context, it.id) } },
|
||||||
)
|
)
|
||||||
|
|
||||||
if (activeSession != null) {
|
if (activeSession != null) {
|
||||||
@@ -119,13 +122,15 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
|
|
||||||
if (completedSessions.isEmpty() && activeSession == null) {
|
if (completedSessions.isEmpty() && activeSession == null) {
|
||||||
EmptyStateMessage(
|
EmptyStateMessage(
|
||||||
title = if (gyms.isEmpty()) "No Gyms Available" else "No Sessions Yet",
|
title = if (gyms.isEmpty()) "No Gyms Available" else "No Sessions Yet",
|
||||||
message =
|
message =
|
||||||
if (gyms.isEmpty())
|
if (gyms.isEmpty()) {
|
||||||
"Add a gym first to start tracking your climbing sessions!"
|
"Add a gym first to start tracking your climbing sessions!"
|
||||||
else "Start your first climbing session!",
|
} else {
|
||||||
onActionClick = {},
|
"Start your first climbing session!"
|
||||||
actionText = ""
|
},
|
||||||
|
onActionClick = {},
|
||||||
|
actionText = "",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
when (viewMode) {
|
when (viewMode) {
|
||||||
@@ -133,10 +138,10 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
LazyColumn {
|
LazyColumn {
|
||||||
items(completedSessions) { session ->
|
items(completedSessions) { session ->
|
||||||
SessionCard(
|
SessionCard(
|
||||||
session = session,
|
session = session,
|
||||||
gymName = gyms.find { it.id == session.gymId }?.name
|
gymName = gyms.find { it.id == session.gymId }?.name
|
||||||
?: "Unknown Gym",
|
?: "Unknown Gym",
|
||||||
onClick = { onNavigateToSessionDetail(session.id) }
|
onClick = { onNavigateToSessionDetail(session.id) },
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
@@ -144,13 +149,13 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
}
|
}
|
||||||
ViewMode.CALENDAR -> {
|
ViewMode.CALENDAR -> {
|
||||||
CalendarView(
|
CalendarView(
|
||||||
sessions = completedSessions,
|
sessions = completedSessions,
|
||||||
gyms = gyms,
|
gyms = gyms,
|
||||||
selectedMonth = selectedMonth,
|
selectedMonth = selectedMonth,
|
||||||
onMonthChange = { selectedMonth = it },
|
onMonthChange = { selectedMonth = it },
|
||||||
selectedDate = selectedDate,
|
selectedDate = selectedDate,
|
||||||
onDateSelected = { selectedDate = it },
|
onDateSelected = { selectedDate = it },
|
||||||
onNavigateToSessionDetail = onNavigateToSessionDetail
|
onNavigateToSessionDetail = onNavigateToSessionDetail,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,27 +169,27 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
}
|
}
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primaryContainer
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp)
|
shape = RoundedCornerShape(12.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.CheckCircle,
|
Icons.Default.CheckCircle,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = message,
|
text = message,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -197,27 +202,27 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
}
|
}
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.errorContainer
|
containerColor = MaterialTheme.colorScheme.errorContainer,
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp)
|
shape = RoundedCornerShape(12.dp),
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Warning,
|
Icons.Default.Warning,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
tint = MaterialTheme.colorScheme.error
|
tint = MaterialTheme.colorScheme.error,
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = error,
|
text = error,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onErrorContainer
|
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,18 +235,18 @@ fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
|||||||
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = gymName,
|
text = gymName,
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = formatDate(session.date),
|
text = formatDate(session.date),
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,8 +254,8 @@ fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
|||||||
|
|
||||||
session.duration?.let { duration ->
|
session.duration?.let { duration ->
|
||||||
Text(
|
Text(
|
||||||
text = "Duration: $duration minutes",
|
text = "Duration: $duration minutes",
|
||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,10 +263,10 @@ fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
|||||||
if (notes.isNotBlank()) {
|
if (notes.isNotBlank()) {
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text = notes,
|
text = notes,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
maxLines = 2
|
maxLines = 2,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,30 +276,30 @@ fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EmptyStateMessage(
|
fun EmptyStateMessage(
|
||||||
title: String,
|
title: String,
|
||||||
message: String,
|
message: String,
|
||||||
onActionClick: () -> Unit,
|
onActionClick: () -> Unit,
|
||||||
actionText: String
|
actionText: String,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = title,
|
text = title,
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = message,
|
text = message,
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
textAlign = TextAlign.Center
|
textAlign = TextAlign.Center,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (actionText.isNotEmpty()) {
|
if (actionText.isNotEmpty()) {
|
||||||
@@ -307,64 +312,64 @@ fun EmptyStateMessage(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CalendarView(
|
fun CalendarView(
|
||||||
sessions: List<ClimbSession>,
|
sessions: List<ClimbSession>,
|
||||||
gyms: List<com.atridad.ascently.data.model.Gym>,
|
gyms: List<com.atridad.ascently.data.model.Gym>,
|
||||||
selectedMonth: YearMonth,
|
selectedMonth: YearMonth,
|
||||||
onMonthChange: (YearMonth) -> Unit,
|
onMonthChange: (YearMonth) -> Unit,
|
||||||
selectedDate: LocalDate?,
|
selectedDate: LocalDate?,
|
||||||
onDateSelected: (LocalDate?) -> Unit,
|
onDateSelected: (LocalDate?) -> Unit,
|
||||||
onNavigateToSessionDetail: (String) -> Unit
|
onNavigateToSessionDetail: (String) -> Unit,
|
||||||
) {
|
) {
|
||||||
val sessionsByDate =
|
val sessionsByDate =
|
||||||
remember(sessions) {
|
remember(sessions) {
|
||||||
sessions.groupBy {
|
sessions.groupBy {
|
||||||
try {
|
try {
|
||||||
java.time.Instant.parse(it.date)
|
java.time.Instant.parse(it.date)
|
||||||
.atZone(java.time.ZoneId.systemDefault())
|
.atZone(java.time.ZoneId.systemDefault())
|
||||||
.toLocalDate()
|
.toLocalDate()
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
LocalDate.parse(it.date, DateTimeFormatter.ISO_LOCAL_DATE)
|
LocalDate.parse(it.date, DateTimeFormatter.ISO_LOCAL_DATE)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val firstDayOfMonth = selectedMonth.atDay(1)
|
val firstDayOfMonth = selectedMonth.atDay(1)
|
||||||
val daysInMonth = selectedMonth.lengthOfMonth()
|
val daysInMonth = selectedMonth.lengthOfMonth()
|
||||||
val firstDayOfWeek = firstDayOfMonth.dayOfWeek.value % 7
|
val firstDayOfWeek = firstDayOfMonth.dayOfWeek.value % 7
|
||||||
val totalCells =
|
val totalCells =
|
||||||
((firstDayOfWeek + daysInMonth) / 7.0).let {
|
((firstDayOfWeek + daysInMonth) / 7.0).let {
|
||||||
if (it == it.toInt().toDouble()) it.toInt() * 7 else (it.toInt() + 1) * 7
|
if (it == it.toInt().toDouble()) it.toInt() * 7 else (it.toInt() + 1) * 7
|
||||||
}
|
}
|
||||||
val numRows = totalCells / 7
|
val numRows = totalCells / 7
|
||||||
|
|
||||||
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
containerColor = MaterialTheme.colorScheme.surfaceVariant,
|
||||||
)
|
),
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 12.dp),
|
Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 12.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
IconButton(onClick = { onMonthChange(selectedMonth.minusMonths(1)) }) {
|
IconButton(onClick = { onMonthChange(selectedMonth.minusMonths(1)) }) {
|
||||||
Text("‹", style = MaterialTheme.typography.headlineMedium)
|
Text("‹", style = MaterialTheme.typography.headlineMedium)
|
||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"${selectedMonth.month.getDisplayName(TextStyle.FULL, Locale.getDefault())} ${selectedMonth.year}",
|
"${selectedMonth.month.getDisplayName(TextStyle.FULL, Locale.getDefault())} ${selectedMonth.year}",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
|
|
||||||
IconButton(onClick = { onMonthChange(selectedMonth.plusMonths(1)) }) {
|
IconButton(onClick = { onMonthChange(selectedMonth.plusMonths(1)) }) {
|
||||||
@@ -375,22 +380,22 @@ fun CalendarView(
|
|||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
val today = LocalDate.now()
|
val today = LocalDate.now()
|
||||||
onMonthChange(YearMonth.from(today))
|
onMonthChange(YearMonth.from(today))
|
||||||
onDateSelected(today)
|
onDateSelected(today)
|
||||||
},
|
},
|
||||||
shape = RoundedCornerShape(50),
|
shape = RoundedCornerShape(50),
|
||||||
colors =
|
colors =
|
||||||
ButtonDefaults.buttonColors(
|
ButtonDefaults.buttonColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primary
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
),
|
),
|
||||||
contentPadding = PaddingValues(horizontal = 20.dp, vertical = 8.dp)
|
contentPadding = PaddingValues(horizontal = 20.dp, vertical = 8.dp),
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Today",
|
text = "Today",
|
||||||
style = MaterialTheme.typography.labelLarge,
|
style = MaterialTheme.typography.labelLarge,
|
||||||
fontWeight = FontWeight.SemiBold
|
fontWeight = FontWeight.SemiBold,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -401,12 +406,12 @@ fun CalendarView(
|
|||||||
Row(modifier = Modifier.fillMaxWidth()) {
|
Row(modifier = Modifier.fillMaxWidth()) {
|
||||||
listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat").forEach { day ->
|
listOf("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat").forEach { day ->
|
||||||
Text(
|
Text(
|
||||||
text = day,
|
text = day,
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
textAlign = TextAlign.Center,
|
textAlign = TextAlign.Center,
|
||||||
style = MaterialTheme.typography.labelSmall,
|
style = MaterialTheme.typography.labelSmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -428,15 +433,15 @@ fun CalendarView(
|
|||||||
val isToday = date == LocalDate.now()
|
val isToday = date == LocalDate.now()
|
||||||
|
|
||||||
CalendarDay(
|
CalendarDay(
|
||||||
day = dayNumber,
|
day = dayNumber,
|
||||||
hasSession = sessionsOnDate.isNotEmpty(),
|
hasSession = sessionsOnDate.isNotEmpty(),
|
||||||
isSelected = isSelected,
|
isSelected = isSelected,
|
||||||
isToday = isToday,
|
isToday = isToday,
|
||||||
onClick = {
|
onClick = {
|
||||||
if (sessionsOnDate.isNotEmpty()) {
|
if (sessionsOnDate.isNotEmpty()) {
|
||||||
onDateSelected(if (isSelected) null else date)
|
onDateSelected(if (isSelected) null else date)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Spacer(modifier = Modifier.aspectRatio(1f))
|
Spacer(modifier = Modifier.aspectRatio(1f))
|
||||||
@@ -453,19 +458,19 @@ fun CalendarView(
|
|||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Sessions on ${selectedDate.format(DateTimeFormatter.ofPattern("MMMM d, yyyy"))}",
|
"Sessions on ${selectedDate.format(DateTimeFormatter.ofPattern("MMMM d, yyyy"))}",
|
||||||
style = MaterialTheme.typography.titleSmall,
|
style = MaterialTheme.typography.titleSmall,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
modifier = Modifier.padding(vertical = 8.dp)
|
modifier = Modifier.padding(vertical = 8.dp),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
items(sessionsOnSelectedDate) { session ->
|
items(sessionsOnSelectedDate) { session ->
|
||||||
SessionCard(
|
SessionCard(
|
||||||
session = session,
|
session = session,
|
||||||
gymName = gyms.find { it.id == session.gymId }?.name ?: "Unknown Gym",
|
gymName = gyms.find { it.id == session.gymId }?.name ?: "Unknown Gym",
|
||||||
onClick = { onNavigateToSessionDetail(session.id) }
|
onClick = { onNavigateToSessionDetail(session.id) },
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
@@ -477,56 +482,58 @@ fun CalendarView(
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CalendarDay(
|
fun CalendarDay(
|
||||||
day: Int,
|
day: Int,
|
||||||
hasSession: Boolean,
|
hasSession: Boolean,
|
||||||
isSelected: Boolean,
|
isSelected: Boolean,
|
||||||
isToday: Boolean,
|
isToday: Boolean,
|
||||||
onClick: () -> Unit
|
onClick: () -> Unit,
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.aspectRatio(1f)
|
Modifier.aspectRatio(1f)
|
||||||
.padding(2.dp)
|
.padding(2.dp)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(
|
.background(
|
||||||
when {
|
when {
|
||||||
isSelected -> MaterialTheme.colorScheme.primaryContainer
|
isSelected -> MaterialTheme.colorScheme.primaryContainer
|
||||||
isToday -> MaterialTheme.colorScheme.secondaryContainer
|
isToday -> MaterialTheme.colorScheme.secondaryContainer
|
||||||
else -> Color.Transparent
|
else -> Color.Transparent
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
.clickable(enabled = hasSession, onClick = onClick),
|
.clickable(enabled = hasSession, onClick = onClick),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center,
|
||||||
) {
|
) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center
|
verticalArrangement = Arrangement.Center,
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = day.toString(),
|
text = day.toString(),
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color =
|
color =
|
||||||
when {
|
when {
|
||||||
isSelected -> MaterialTheme.colorScheme.onPrimaryContainer
|
isSelected -> MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
isToday -> MaterialTheme.colorScheme.onSecondaryContainer
|
isToday -> MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
!hasSession -> MaterialTheme.colorScheme.onSurfaceVariant
|
!hasSession -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
else -> MaterialTheme.colorScheme.onSurface
|
else -> MaterialTheme.colorScheme.onSurface
|
||||||
},
|
},
|
||||||
fontWeight = if (hasSession || isToday) FontWeight.Bold else FontWeight.Normal
|
fontWeight = if (hasSession || isToday) FontWeight.Bold else FontWeight.Normal,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (hasSession) {
|
if (hasSession) {
|
||||||
Box(
|
Box(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.size(6.dp)
|
Modifier.size(6.dp)
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(
|
.background(
|
||||||
if (isSelected) MaterialTheme.colorScheme.primary
|
if (isSelected) {
|
||||||
else
|
MaterialTheme.colorScheme.primary
|
||||||
MaterialTheme.colorScheme.primary.copy(
|
} else {
|
||||||
alpha = 0.7f
|
MaterialTheme.colorScheme.primary.copy(
|
||||||
)
|
alpha = 0.7f,
|
||||||
)
|
)
|
||||||
|
},
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -63,4 +63,4 @@ val ClimbNeutralVariant30 = Color(0xFF484848)
|
|||||||
val ClimbNeutralVariant50 = Color(0xFF797979)
|
val ClimbNeutralVariant50 = Color(0xFF797979)
|
||||||
val ClimbNeutralVariant60 = Color(0xFF939393)
|
val ClimbNeutralVariant60 = Color(0xFF939393)
|
||||||
val ClimbNeutralVariant80 = Color(0xFFC7C7C7)
|
val ClimbNeutralVariant80 = Color(0xFFC7C7C7)
|
||||||
val ClimbNeutralVariant90 = Color(0xFFE3E3E3)
|
val ClimbNeutralVariant90 = Color(0xFFE3E3E3)
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ object CustomIcons {
|
|||||||
defaultWidth = 24.dp,
|
defaultWidth = 24.dp,
|
||||||
defaultHeight = 24.dp,
|
defaultHeight = 24.dp,
|
||||||
viewportWidth = 24f,
|
viewportWidth = 24f,
|
||||||
viewportHeight = 24f
|
viewportHeight = 24f,
|
||||||
).path(
|
).path(
|
||||||
fill = SolidColor(color)
|
fill = SolidColor(color),
|
||||||
) {
|
) {
|
||||||
moveTo(6f, 6f)
|
moveTo(6f, 6f)
|
||||||
horizontalLineTo(18f)
|
horizontalLineTo(18f)
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ private val DarkColorScheme = darkColorScheme(
|
|||||||
surfaceContainerLow = ClimbNeutral10,
|
surfaceContainerLow = ClimbNeutral10,
|
||||||
surfaceContainer = ClimbNeutral12,
|
surfaceContainer = ClimbNeutral12,
|
||||||
surfaceContainerHigh = ClimbNeutral17,
|
surfaceContainerHigh = ClimbNeutral17,
|
||||||
surfaceContainerHighest = ClimbNeutral22
|
surfaceContainerHighest = ClimbNeutral22,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Climbing-themed light color scheme with full Material You compatibility
|
// Climbing-themed light color scheme with full Material You compatibility
|
||||||
@@ -84,7 +84,7 @@ private val LightColorScheme = lightColorScheme(
|
|||||||
surfaceContainerLow = ClimbNeutral96,
|
surfaceContainerLow = ClimbNeutral96,
|
||||||
surfaceContainer = ClimbNeutral94,
|
surfaceContainer = ClimbNeutral94,
|
||||||
surfaceContainerHigh = ClimbNeutral92,
|
surfaceContainerHigh = ClimbNeutral92,
|
||||||
surfaceContainerHighest = ClimbNeutral90
|
surfaceContainerHighest = ClimbNeutral90,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -93,7 +93,7 @@ fun AscentlyTheme(
|
|||||||
// Dynamic color is available on Android 12+ and provides full Material You theming
|
// Dynamic color is available on Android 12+ and provides full Material You theming
|
||||||
// When enabled, it adapts to the user's system wallpaper colors
|
// When enabled, it adapts to the user's system wallpaper colors
|
||||||
dynamicColor: Boolean = true,
|
dynamicColor: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val colorScheme = when {
|
val colorScheme = when {
|
||||||
dynamicColor && true -> {
|
dynamicColor && true -> {
|
||||||
@@ -103,7 +103,7 @@ fun AscentlyTheme(
|
|||||||
darkTheme -> DarkColorScheme
|
darkTheme -> DarkColorScheme
|
||||||
else -> LightColorScheme
|
else -> LightColorScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
val view = LocalView.current
|
val view = LocalView.current
|
||||||
if (!view.isInEditMode) {
|
if (!view.isInEditMode) {
|
||||||
SideEffect {
|
SideEffect {
|
||||||
@@ -116,6 +116,6 @@ fun AscentlyTheme(
|
|||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = colorScheme,
|
colorScheme = colorScheme,
|
||||||
typography = Typography,
|
typography = Typography,
|
||||||
content = content
|
content = content,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ val Typography = Typography(
|
|||||||
fontWeight = FontWeight.Normal,
|
fontWeight = FontWeight.Normal,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
lineHeight = 24.sp,
|
lineHeight = 24.sp,
|
||||||
letterSpacing = 0.5.sp
|
letterSpacing = 0.5.sp,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import com.atridad.ascently.service.SessionTrackingService
|
|||||||
import com.atridad.ascently.utils.AppLogger
|
import com.atridad.ascently.utils.AppLogger
|
||||||
import com.atridad.ascently.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
||||||
import java.io.File
|
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
class ClimbViewModel(
|
class ClimbViewModel(
|
||||||
private val repository: ClimbRepository,
|
private val repository: ClimbRepository,
|
||||||
val syncService: SyncService,
|
val syncService: SyncService,
|
||||||
private val context: Context
|
private val context: Context,
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
// Health Connect manager
|
// Health Connect manager
|
||||||
@@ -35,7 +35,7 @@ class ClimbViewModel(
|
|||||||
.stateIn(
|
.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
initialValue = emptyList()
|
initialValue = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val problems =
|
val problems =
|
||||||
@@ -44,7 +44,7 @@ class ClimbViewModel(
|
|||||||
.stateIn(
|
.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
initialValue = emptyList()
|
initialValue = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val sessions =
|
val sessions =
|
||||||
@@ -53,7 +53,7 @@ class ClimbViewModel(
|
|||||||
.stateIn(
|
.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
initialValue = emptyList()
|
initialValue = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val activeSession =
|
val activeSession =
|
||||||
@@ -62,7 +62,7 @@ class ClimbViewModel(
|
|||||||
.stateIn(
|
.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
initialValue = null
|
initialValue = null,
|
||||||
)
|
)
|
||||||
|
|
||||||
val attempts =
|
val attempts =
|
||||||
@@ -71,7 +71,7 @@ class ClimbViewModel(
|
|||||||
.stateIn(
|
.stateIn(
|
||||||
scope = viewModelScope,
|
scope = viewModelScope,
|
||||||
started = SharingStarted.WhileSubscribed(),
|
started = SharingStarted.WhileSubscribed(),
|
||||||
initialValue = emptyList()
|
initialValue = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Gym operations
|
// Gym operations
|
||||||
@@ -243,7 +243,7 @@ class ClimbViewModel(
|
|||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
error =
|
error =
|
||||||
"Notification permission is required to track your climbing session. Please enable notifications in settings."
|
"Notification permission is required to track your climbing session. Please enable notifications in settings.",
|
||||||
)
|
)
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ class ClimbViewModel(
|
|||||||
AppLogger.d("ClimbViewModel") { "Active session already exists: ${existingActive.id}" }
|
AppLogger.d("ClimbViewModel") { "Active session already exists: ${existingActive.id}" }
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
error = "There's already an active session. Please end it first."
|
error = "There's already an active session. Please end it first.",
|
||||||
)
|
)
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
@@ -281,7 +281,7 @@ class ClimbViewModel(
|
|||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
error =
|
error =
|
||||||
"Notification permission is required to manage your climbing session. Please enable notifications in settings."
|
"Notification permission is required to manage your climbing session. Please enable notifications in settings.",
|
||||||
)
|
)
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
@@ -354,20 +354,20 @@ class ClimbViewModel(
|
|||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = true,
|
isLoading = true,
|
||||||
message = "Creating ZIP file with images..."
|
message = "Creating ZIP file with images...",
|
||||||
)
|
)
|
||||||
repository.exportAllDataToZipUri(context, uri)
|
repository.exportAllDataToZipUri(context, uri)
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
message =
|
message =
|
||||||
"Export complete! Your climbing data and images have been saved."
|
"Export complete! Your climbing data and images have been saved.",
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
error = "Export failed: ${e.message}"
|
error = "Export failed: ${e.message}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,7 @@ class ClimbViewModel(
|
|||||||
|
|
||||||
if (!file.name.lowercase().endsWith(".zip")) {
|
if (!file.name.lowercase().endsWith(".zip")) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
"Only ZIP files are supported for import. Please use a ZIP file exported from Ascently."
|
"Only ZIP files are supported for import. Please use a ZIP file exported from Ascently.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,13 +389,13 @@ class ClimbViewModel(
|
|||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
message = "Data imported successfully from ${file.name}"
|
message = "Data imported successfully from ${file.name}",
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
error = "Import failed: ${e.message}"
|
error = "Import failed: ${e.message}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,7 +447,7 @@ class ClimbViewModel(
|
|||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
message = "All data has been reset successfully"
|
message = "All data has been reset successfully",
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
@@ -469,7 +469,7 @@ class ClimbViewModel(
|
|||||||
healthConnectManager.autoSyncCompletedSession(
|
healthConnectManager.autoSyncCompletedSession(
|
||||||
session,
|
session,
|
||||||
gymName,
|
gymName,
|
||||||
attemptCount
|
attemptCount,
|
||||||
)
|
)
|
||||||
|
|
||||||
result.onFailure { error ->
|
result.onFailure { error ->
|
||||||
@@ -489,5 +489,5 @@ class ClimbViewModel(
|
|||||||
data class ClimbUiState(
|
data class ClimbUiState(
|
||||||
val isLoading: Boolean = false,
|
val isLoading: Boolean = false,
|
||||||
val message: String? = null,
|
val message: String? = null,
|
||||||
val error: String? = null
|
val error: String? = null,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import com.atridad.ascently.data.repository.ClimbRepository
|
|||||||
import com.atridad.ascently.data.sync.SyncService
|
import com.atridad.ascently.data.sync.SyncService
|
||||||
|
|
||||||
class ClimbViewModelFactory(
|
class ClimbViewModelFactory(
|
||||||
private val repository: ClimbRepository,
|
private val repository: ClimbRepository,
|
||||||
private val syncService: SyncService,
|
private val syncService: SyncService,
|
||||||
private val context: Context
|
private val context: Context,
|
||||||
) : ViewModelProvider.Factory {
|
) : ViewModelProvider.Factory {
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ object AppLogger {
|
|||||||
DEBUG(Log.DEBUG),
|
DEBUG(Log.DEBUG),
|
||||||
INFO(Log.INFO),
|
INFO(Log.INFO),
|
||||||
WARN(Log.WARN),
|
WARN(Log.WARN),
|
||||||
ERROR(Log.ERROR)
|
ERROR(Log.ERROR),
|
||||||
}
|
}
|
||||||
|
|
||||||
fun d(tag: String = DEFAULT_TAG, messageProvider: () -> String) {
|
fun d(tag: String = DEFAULT_TAG, messageProvider: () -> String) {
|
||||||
@@ -34,7 +34,7 @@ object AppLogger {
|
|||||||
level: Level,
|
level: Level,
|
||||||
tag: String,
|
tag: String,
|
||||||
messageProvider: () -> String,
|
messageProvider: () -> String,
|
||||||
throwable: Throwable? = null
|
throwable: Throwable? = null,
|
||||||
) {
|
) {
|
||||||
if (!BuildConfig.DEBUG) return
|
if (!BuildConfig.DEBUG) return
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ object DateFormatUtils {
|
|||||||
|
|
||||||
// ISO 8601 formatter matching iOS date format exactly
|
// ISO 8601 formatter matching iOS date format exactly
|
||||||
private val ISO_FORMATTER =
|
private val ISO_FORMATTER =
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneOffset.UTC)
|
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneOffset.UTC)
|
||||||
|
|
||||||
/** Get current timestamp in iOS-compatible ISO 8601 format */
|
/** Get current timestamp in iOS-compatible ISO 8601 format */
|
||||||
fun nowISO8601(): String {
|
fun nowISO8601(): String {
|
||||||
@@ -22,7 +22,6 @@ object DateFormatUtils {
|
|||||||
return try {
|
return try {
|
||||||
Instant.from(ISO_FORMATTER.parse(dateString))
|
Instant.from(ISO_FORMATTER.parse(dateString))
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Instant.parse(dateString)
|
Instant.parse(dateString)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ object ImageNamingUtils {
|
|||||||
|
|
||||||
/** Generates a deterministic filename for a problem image */
|
/** Generates a deterministic filename for a problem image */
|
||||||
fun generateImageFilename(problemId: String, imageIndex: Int): String {
|
fun generateImageFilename(problemId: String, imageIndex: Int): String {
|
||||||
val input = "${problemId}_${imageIndex}"
|
val input = "${problemId}_$imageIndex"
|
||||||
val hash = createHash(input)
|
val hash = createHash(input)
|
||||||
|
|
||||||
return "problem_${hash}_${imageIndex}${IMAGE_EXTENSION}"
|
return "problem_${hash}_${imageIndex}${IMAGE_EXTENSION}"
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ object ImageUtils {
|
|||||||
context: Context,
|
context: Context,
|
||||||
imageUri: Uri,
|
imageUri: Uri,
|
||||||
originalBitmap: Bitmap,
|
originalBitmap: Bitmap,
|
||||||
outputFile: File
|
outputFile: File,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return try {
|
return try {
|
||||||
// Get EXIF data from original image
|
// Get EXIF data from original image
|
||||||
@@ -147,12 +147,16 @@ object ImageUtils {
|
|||||||
val imagesDir = getImagesDirectory(context)
|
val imagesDir = getImagesDirectory(context)
|
||||||
imagesDir.listFiles()?.mapNotNull { file ->
|
imagesDir.listFiles()?.mapNotNull { file ->
|
||||||
if (file.isFile &&
|
if (file.isFile &&
|
||||||
(file.extension == "jpg" ||
|
(
|
||||||
|
file.extension == "jpg" ||
|
||||||
file.extension == "jpeg" ||
|
file.extension == "jpeg" ||
|
||||||
file.extension == "png")
|
file.extension == "png"
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
"$IMAGES_DIR/${file.name}"
|
"$IMAGES_DIR/${file.name}"
|
||||||
} else null
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?: emptyList()
|
?: emptyList()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -187,7 +191,7 @@ object ImageUtils {
|
|||||||
context: Context,
|
context: Context,
|
||||||
tempFilename: String,
|
tempFilename: String,
|
||||||
problemId: String,
|
problemId: String,
|
||||||
imageIndex: Int
|
imageIndex: Int,
|
||||||
): String? {
|
): String? {
|
||||||
return try {
|
return try {
|
||||||
val tempFile = File(getImagesDirectory(context), tempFilename)
|
val tempFile = File(getImagesDirectory(context), tempFilename)
|
||||||
@@ -217,7 +221,7 @@ object ImageUtils {
|
|||||||
fun saveImageFromBytesWithFilename(
|
fun saveImageFromBytesWithFilename(
|
||||||
context: Context,
|
context: Context,
|
||||||
imageData: ByteArray,
|
imageData: ByteArray,
|
||||||
filename: String
|
filename: String,
|
||||||
): String? {
|
): String? {
|
||||||
return try {
|
return try {
|
||||||
val imageFile = File(getImagesDirectory(context), filename)
|
val imageFile = File(getImagesDirectory(context), filename)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class MigrationManager(private val context: Context) {
|
|||||||
"openclimb_data_state" to "ascently_data_state",
|
"openclimb_data_state" to "ascently_data_state",
|
||||||
"health_connect_prefs" to "health_connect_prefs", // Keep same name
|
"health_connect_prefs" to "health_connect_prefs", // Keep same name
|
||||||
"deleted_items" to "deleted_items", // Keep same name
|
"deleted_items" to "deleted_items", // Keep same name
|
||||||
"sync_preferences" to "sync_preferences" // Keep same name
|
"sync_preferences" to "sync_preferences", // Keep same name
|
||||||
)
|
)
|
||||||
|
|
||||||
for ((oldFileName, newFileName) in preferenceFileMigrations) {
|
for ((oldFileName, newFileName) in preferenceFileMigrations) {
|
||||||
@@ -82,7 +82,8 @@ class MigrationManager(private val context: Context) {
|
|||||||
is Float -> putFloat(key, value)
|
is Float -> putFloat(key, value)
|
||||||
is Boolean -> putBoolean(key, value)
|
is Boolean -> putBoolean(key, value)
|
||||||
is Set<*> -> {
|
is Set<*> -> {
|
||||||
@Suppress("UNCHECKED_CAST") putStringSet(key, value as Set<String>)
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
putStringSet(key, value as Set<String>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +109,7 @@ class MigrationManager(private val context: Context) {
|
|||||||
"ascently_data_state",
|
"ascently_data_state",
|
||||||
"health_connect_prefs",
|
"health_connect_prefs",
|
||||||
"deleted_items",
|
"deleted_items",
|
||||||
"sync_preferences"
|
"sync_preferences",
|
||||||
)
|
)
|
||||||
|
|
||||||
for (prefFileName in preferencesToCheck) {
|
for (prefFileName in preferencesToCheck) {
|
||||||
|
|||||||
@@ -6,24 +6,24 @@ import android.content.pm.PackageManager
|
|||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
|
||||||
object NotificationPermissionUtils {
|
object NotificationPermissionUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if notification permission is granted
|
* Check if notification permission is granted
|
||||||
*/
|
*/
|
||||||
fun isNotificationPermissionGranted(context: Context): Boolean {
|
fun isNotificationPermissionGranted(context: Context): Boolean {
|
||||||
return ContextCompat.checkSelfPermission(
|
return ContextCompat.checkSelfPermission(
|
||||||
context,
|
context,
|
||||||
Manifest.permission.POST_NOTIFICATIONS
|
Manifest.permission.POST_NOTIFICATIONS,
|
||||||
) == PackageManager.PERMISSION_GRANTED
|
) == PackageManager.PERMISSION_GRANTED
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if notification permission should be requested
|
* Check if notification permission should be requested
|
||||||
*/
|
*/
|
||||||
fun shouldRequestNotificationPermission(): Boolean {
|
fun shouldRequestNotificationPermission(): Boolean {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the notification permission string
|
* Get the notification permission string
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ object AppShortcutManager {
|
|||||||
|
|
||||||
/** Updates the app shortcuts based on current session state */
|
/** Updates the app shortcuts based on current session state */
|
||||||
fun updateShortcuts(
|
fun updateShortcuts(
|
||||||
context: Context,
|
context: Context,
|
||||||
hasActiveSession: Boolean,
|
hasActiveSession: Boolean,
|
||||||
hasGyms: Boolean,
|
hasGyms: Boolean,
|
||||||
lastUsedGym: com.atridad.ascently.data.model.Gym? = null
|
lastUsedGym: com.atridad.ascently.data.model.Gym? = null,
|
||||||
) {
|
) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
val shortcutManager = context.getSystemService(ShortcutManager::class.java)
|
val shortcutManager = context.getSystemService(ShortcutManager::class.java)
|
||||||
@@ -44,52 +44,52 @@ object AppShortcutManager {
|
|||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
private fun createStartSessionShortcut(
|
private fun createStartSessionShortcut(
|
||||||
context: Context,
|
context: Context,
|
||||||
lastUsedGym: com.atridad.ascently.data.model.Gym? = null
|
lastUsedGym: com.atridad.ascently.data.model.Gym? = null,
|
||||||
): ShortcutInfo {
|
): ShortcutInfo {
|
||||||
val startIntent =
|
val startIntent =
|
||||||
Intent(context, MainActivity::class.java).apply {
|
Intent(context, MainActivity::class.java).apply {
|
||||||
action = ACTION_START_SESSION
|
action = ACTION_START_SESSION
|
||||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
lastUsedGym?.let { gym -> putExtra("LAST_USED_GYM_ID", gym.id) }
|
lastUsedGym?.let { gym -> putExtra("LAST_USED_GYM_ID", gym.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
val shortLabel =
|
val shortLabel =
|
||||||
if (lastUsedGym != null) {
|
if (lastUsedGym != null) {
|
||||||
"Start at ${lastUsedGym.name}"
|
"Start at ${lastUsedGym.name}"
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.shortcut_start_session_short)
|
context.getString(R.string.shortcut_start_session_short)
|
||||||
}
|
}
|
||||||
|
|
||||||
val longLabel =
|
val longLabel =
|
||||||
if (lastUsedGym != null) {
|
if (lastUsedGym != null) {
|
||||||
"Start a new climbing session at ${lastUsedGym.name}"
|
"Start a new climbing session at ${lastUsedGym.name}"
|
||||||
} else {
|
} else {
|
||||||
context.getString(R.string.shortcut_start_session_long)
|
context.getString(R.string.shortcut_start_session_long)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ShortcutInfo.Builder(context, SHORTCUT_START_SESSION)
|
return ShortcutInfo.Builder(context, SHORTCUT_START_SESSION)
|
||||||
.setShortLabel(shortLabel)
|
.setShortLabel(shortLabel)
|
||||||
.setLongLabel(longLabel)
|
.setLongLabel(longLabel)
|
||||||
.setIcon(Icon.createWithResource(context, R.drawable.ic_play_arrow_24))
|
.setIcon(Icon.createWithResource(context, R.drawable.ic_play_arrow_24))
|
||||||
.setIntent(startIntent)
|
.setIntent(startIntent)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
@RequiresApi(Build.VERSION_CODES.N_MR1)
|
||||||
private fun createEndSessionShortcut(context: Context): ShortcutInfo {
|
private fun createEndSessionShortcut(context: Context): ShortcutInfo {
|
||||||
val endIntent =
|
val endIntent =
|
||||||
Intent(context, MainActivity::class.java).apply {
|
Intent(context, MainActivity::class.java).apply {
|
||||||
action = ACTION_END_SESSION
|
action = ACTION_END_SESSION
|
||||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||||
}
|
}
|
||||||
|
|
||||||
return ShortcutInfo.Builder(context, SHORTCUT_END_SESSION)
|
return ShortcutInfo.Builder(context, SHORTCUT_END_SESSION)
|
||||||
.setShortLabel(context.getString(R.string.shortcut_end_session_short))
|
.setShortLabel(context.getString(R.string.shortcut_end_session_short))
|
||||||
.setLongLabel(context.getString(R.string.shortcut_end_session_long))
|
.setLongLabel(context.getString(R.string.shortcut_end_session_long))
|
||||||
.setIcon(Icon.createWithResource(context, R.drawable.ic_stop_24))
|
.setIcon(Icon.createWithResource(context, R.drawable.ic_stop_24))
|
||||||
.setIntent(endIntent)
|
.setIntent(endIntent)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Removes all dynamic shortcuts */
|
/** Removes all dynamic shortcuts */
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.atridad.ascently.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.atridad.ascently.data.format.BackupProblem
|
import com.atridad.ascently.data.format.BackupProblem
|
||||||
import com.atridad.ascently.data.format.ClimbDataBackup
|
import com.atridad.ascently.data.format.ClimbDataBackup
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
@@ -11,8 +13,6 @@ import java.time.LocalDateTime
|
|||||||
import java.util.zip.ZipEntry
|
import java.util.zip.ZipEntry
|
||||||
import java.util.zip.ZipInputStream
|
import java.util.zip.ZipInputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import kotlinx.serialization.encodeToString
|
|
||||||
import kotlinx.serialization.json.Json
|
|
||||||
|
|
||||||
object ZipExportImportUtils {
|
object ZipExportImportUtils {
|
||||||
|
|
||||||
@@ -25,15 +25,15 @@ object ZipExportImportUtils {
|
|||||||
context: Context,
|
context: Context,
|
||||||
exportData: ClimbDataBackup,
|
exportData: ClimbDataBackup,
|
||||||
referencedImagePaths: Set<String>,
|
referencedImagePaths: Set<String>,
|
||||||
directory: File? = null
|
directory: File? = null,
|
||||||
): File {
|
): File {
|
||||||
val exportDir =
|
val exportDir =
|
||||||
directory
|
directory
|
||||||
?: File(
|
?: File(
|
||||||
context.getExternalFilesDir(
|
context.getExternalFilesDir(
|
||||||
android.os.Environment.DIRECTORY_DOCUMENTS
|
android.os.Environment.DIRECTORY_DOCUMENTS,
|
||||||
),
|
),
|
||||||
"Ascently"
|
"Ascently",
|
||||||
)
|
)
|
||||||
if (!exportDir.exists()) {
|
if (!exportDir.exists()) {
|
||||||
exportDir.mkdirs()
|
exportDir.mkdirs()
|
||||||
@@ -92,7 +92,7 @@ object ZipExportImportUtils {
|
|||||||
|
|
||||||
// Log export summary
|
// Log export summary
|
||||||
AppLogger.i("ZipExportImportUtils") {
|
AppLogger.i("ZipExportImportUtils") {
|
||||||
"Export completed: ${successfulImages}/${referencedImagePaths.size} images included"
|
"Export completed: $successfulImages/${referencedImagePaths.size} images included"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ object ZipExportImportUtils {
|
|||||||
context: Context,
|
context: Context,
|
||||||
uri: android.net.Uri,
|
uri: android.net.Uri,
|
||||||
exportData: ClimbDataBackup,
|
exportData: ClimbDataBackup,
|
||||||
referencedImagePaths: Set<String>
|
referencedImagePaths: Set<String>,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
|
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
|
||||||
@@ -164,7 +164,7 @@ object ZipExportImportUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AppLogger.i("ZipExportImportUtils") {
|
AppLogger.i("ZipExportImportUtils") {
|
||||||
"Export to URI completed: ${successfulImages}/${referencedImagePaths.size} images included"
|
"Export to URI completed: $successfulImages/${referencedImagePaths.size} images included"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,7 +176,7 @@ object ZipExportImportUtils {
|
|||||||
|
|
||||||
private fun createMetadata(
|
private fun createMetadata(
|
||||||
exportData: ClimbDataBackup,
|
exportData: ClimbDataBackup,
|
||||||
referencedImagePaths: Set<String>
|
referencedImagePaths: Set<String>,
|
||||||
): String {
|
): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
appendLine("Ascently Export Metadata")
|
appendLine("Ascently Export Metadata")
|
||||||
@@ -195,7 +195,7 @@ object ZipExportImportUtils {
|
|||||||
/** Data class to hold extraction results */
|
/** Data class to hold extraction results */
|
||||||
data class ImportResult(
|
data class ImportResult(
|
||||||
val jsonContent: String,
|
val jsonContent: String,
|
||||||
val importedImagePaths: Map<String, String> // original filename -> new relative path
|
val importedImagePaths: Map<String, String>, // original filename -> new relative path
|
||||||
)
|
)
|
||||||
|
|
||||||
/** Extracts a ZIP file and returns the JSON content and imported image paths */
|
/** Extracts a ZIP file and returns the JSON content and imported image paths */
|
||||||
@@ -235,7 +235,7 @@ object ZipExportImportUtils {
|
|||||||
File.createTempFile(
|
File.createTempFile(
|
||||||
"import_image_",
|
"import_image_",
|
||||||
"_$originalFilename",
|
"_$originalFilename",
|
||||||
context.cacheDir
|
context.cacheDir,
|
||||||
)
|
)
|
||||||
|
|
||||||
FileOutputStream(tempFile).use { output -> zipIn.copyTo(output) }
|
FileOutputStream(tempFile).use { output -> zipIn.copyTo(output) }
|
||||||
@@ -306,7 +306,7 @@ object ZipExportImportUtils {
|
|||||||
*/
|
*/
|
||||||
fun updateProblemImagePaths(
|
fun updateProblemImagePaths(
|
||||||
problems: List<BackupProblem>,
|
problems: List<BackupProblem>,
|
||||||
imagePathMapping: Map<String, String>
|
imagePathMapping: Map<String, String>,
|
||||||
): List<BackupProblem> {
|
): List<BackupProblem> {
|
||||||
return problems.map { problem ->
|
return problems.map { problem ->
|
||||||
val updatedImagePaths =
|
val updatedImagePaths =
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import com.atridad.ascently.MainActivity
|
|||||||
import com.atridad.ascently.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.ascently.data.database.AscentlyDatabase
|
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||||
import com.atridad.ascently.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import java.time.LocalDate
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.time.LocalDate
|
||||||
|
|
||||||
class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
||||||
|
|
||||||
@@ -24,9 +24,9 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
private val coroutineScope = CoroutineScope(Dispatchers.IO + job)
|
private val coroutineScope = CoroutineScope(Dispatchers.IO + job)
|
||||||
|
|
||||||
override fun onUpdate(
|
override fun onUpdate(
|
||||||
context: Context,
|
context: Context,
|
||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
appWidgetIds: IntArray
|
appWidgetIds: IntArray,
|
||||||
) {
|
) {
|
||||||
for (appWidgetId in appWidgetIds) {
|
for (appWidgetId in appWidgetIds) {
|
||||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||||
@@ -40,9 +40,9 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun updateAppWidget(
|
private fun updateAppWidget(
|
||||||
context: Context,
|
context: Context,
|
||||||
appWidgetManager: AppWidgetManager,
|
appWidgetManager: AppWidgetManager,
|
||||||
appWidgetId: Int
|
appWidgetId: Int,
|
||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
@@ -59,20 +59,20 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
|
|
||||||
// Filter for last 7 days across all gyms
|
// Filter for last 7 days across all gyms
|
||||||
val weekSessions =
|
val weekSessions =
|
||||||
sessions.filter { session ->
|
sessions.filter { session ->
|
||||||
try {
|
try {
|
||||||
val sessionDate = LocalDate.parse(session.date.substring(0, 10))
|
val sessionDate = LocalDate.parse(session.date.substring(0, 10))
|
||||||
!sessionDate.isBefore(sevenDaysAgo) && !sessionDate.isAfter(today)
|
!sessionDate.isBefore(sevenDaysAgo) && !sessionDate.isAfter(today)
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
false
|
false
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val weekSessionIds = weekSessions.map { it.id }.toSet()
|
val weekSessionIds = weekSessions.map { it.id }.toSet()
|
||||||
|
|
||||||
// Count total attempts this week
|
// Count total attempts this week
|
||||||
val totalAttempts =
|
val totalAttempts =
|
||||||
attempts.count { attempt -> weekSessionIds.contains(attempt.sessionId) }
|
attempts.count { attempt -> weekSessionIds.contains(attempt.sessionId) }
|
||||||
|
|
||||||
// Count sessions this week
|
// Count sessions this week
|
||||||
val totalSessions = weekSessions.size
|
val totalSessions = weekSessions.size
|
||||||
@@ -85,19 +85,19 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
views.setTextViewText(R.id.widget_sessions_value, totalSessions.toString())
|
views.setTextViewText(R.id.widget_sessions_value, totalSessions.toString())
|
||||||
|
|
||||||
val intent =
|
val intent =
|
||||||
Intent(context, MainActivity::class.java).apply {
|
Intent(context, MainActivity::class.java).apply {
|
||||||
flags =
|
flags =
|
||||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||||
Intent.FLAG_ACTIVITY_CLEAR_TOP
|
Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
}
|
}
|
||||||
val pendingIntent =
|
val pendingIntent =
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or
|
PendingIntent.FLAG_UPDATE_CURRENT or
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
)
|
||||||
views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
|
views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
@@ -110,13 +110,13 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
|
|
||||||
val intent = Intent(context, MainActivity::class.java)
|
val intent = Intent(context, MainActivity::class.java)
|
||||||
val pendingIntent =
|
val pendingIntent =
|
||||||
PendingIntent.getActivity(
|
PendingIntent.getActivity(
|
||||||
context,
|
context,
|
||||||
0,
|
0,
|
||||||
intent,
|
intent,
|
||||||
PendingIntent.FLAG_UPDATE_CURRENT or
|
PendingIntent.FLAG_UPDATE_CURRENT or
|
||||||
PendingIntent.FLAG_IMMUTABLE
|
PendingIntent.FLAG_IMMUTABLE,
|
||||||
)
|
)
|
||||||
views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
|
views.setOnClickPendingIntent(R.id.widget_container, pendingIntent)
|
||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
@@ -132,10 +132,10 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
|
val appWidgetIds = appWidgetManager.getAppWidgetIds(componentName)
|
||||||
|
|
||||||
val intent =
|
val intent =
|
||||||
Intent(context, ClimbStatsWidgetProvider::class.java).apply {
|
Intent(context, ClimbStatsWidgetProvider::class.java).apply {
|
||||||
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||||
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds)
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds)
|
||||||
}
|
}
|
||||||
context.sendBroadcast(intent)
|
context.sendBroadcast(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package com.atridad.ascently
|
|||||||
|
|
||||||
import com.atridad.ascently.data.format.*
|
import com.atridad.ascently.data.format.*
|
||||||
import com.atridad.ascently.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
class BusinessLogicTests {
|
class BusinessLogicTests {
|
||||||
|
|
||||||
@@ -21,11 +21,11 @@ class BusinessLogicTests {
|
|||||||
assertNull(session.duration)
|
assertNull(session.duration)
|
||||||
|
|
||||||
val completedSession =
|
val completedSession =
|
||||||
session.copy(
|
session.copy(
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
endTime = getCurrentTimestamp(),
|
endTime = getCurrentTimestamp(),
|
||||||
duration = 7200L
|
duration = 7200L,
|
||||||
)
|
)
|
||||||
assertEquals(SessionStatus.COMPLETED, completedSession.status)
|
assertEquals(SessionStatus.COMPLETED, completedSession.status)
|
||||||
assertNotNull(completedSession.endTime)
|
assertNotNull(completedSession.endTime)
|
||||||
assertNotNull(completedSession.duration)
|
assertNotNull(completedSession.duration)
|
||||||
@@ -38,12 +38,12 @@ class BusinessLogicTests {
|
|||||||
val session = ClimbSession.create(gym.id)
|
val session = ClimbSession.create(gym.id)
|
||||||
|
|
||||||
val attempt =
|
val attempt =
|
||||||
Attempt.create(
|
Attempt.create(
|
||||||
sessionId = session.id,
|
sessionId = session.id,
|
||||||
problemId = problem.id,
|
problemId = problem.id,
|
||||||
result = AttemptResult.SUCCESS,
|
result = AttemptResult.SUCCESS,
|
||||||
notes = "Clean send!"
|
notes = "Clean send!",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(session.id, attempt.sessionId)
|
assertEquals(session.id, attempt.sessionId)
|
||||||
assertEquals(problem.id, attempt.problemId)
|
assertEquals(problem.id, attempt.problemId)
|
||||||
@@ -76,12 +76,12 @@ class BusinessLogicTests {
|
|||||||
val problem2 = createTestProblem(gym.id)
|
val problem2 = createTestProblem(gym.id)
|
||||||
|
|
||||||
val attempts =
|
val attempts =
|
||||||
listOf(
|
listOf(
|
||||||
Attempt.create(session.id, problem1.id, AttemptResult.SUCCESS),
|
Attempt.create(session.id, problem1.id, AttemptResult.SUCCESS),
|
||||||
Attempt.create(session.id, problem1.id, AttemptResult.FALL),
|
Attempt.create(session.id, problem1.id, AttemptResult.FALL),
|
||||||
Attempt.create(session.id, problem2.id, AttemptResult.FLASH),
|
Attempt.create(session.id, problem2.id, AttemptResult.FLASH),
|
||||||
Attempt.create(session.id, problem2.id, AttemptResult.SUCCESS)
|
Attempt.create(session.id, problem2.id, AttemptResult.SUCCESS),
|
||||||
)
|
)
|
||||||
|
|
||||||
val sessionStats = calculateSessionStatistics(session, attempts)
|
val sessionStats = calculateSessionStatistics(session, attempts)
|
||||||
|
|
||||||
@@ -97,17 +97,17 @@ class BusinessLogicTests {
|
|||||||
val session = ClimbSession.create(gym.id)
|
val session = ClimbSession.create(gym.id)
|
||||||
|
|
||||||
val problems =
|
val problems =
|
||||||
listOf(
|
listOf(
|
||||||
createTestProblemWithGrade(gym.id, "V3"),
|
createTestProblemWithGrade(gym.id, "V3"),
|
||||||
createTestProblemWithGrade(gym.id, "V4"),
|
createTestProblemWithGrade(gym.id, "V4"),
|
||||||
createTestProblemWithGrade(gym.id, "V5"),
|
createTestProblemWithGrade(gym.id, "V5"),
|
||||||
createTestProblemWithGrade(gym.id, "V6")
|
createTestProblemWithGrade(gym.id, "V6"),
|
||||||
)
|
)
|
||||||
|
|
||||||
val attempts =
|
val attempts =
|
||||||
problems.map { problem ->
|
problems.map { problem ->
|
||||||
Attempt.create(session.id, problem.id, AttemptResult.SUCCESS)
|
Attempt.create(session.id, problem.id, AttemptResult.SUCCESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
val progression = calculateDifficultyProgression(attempts, problems)
|
val progression = calculateDifficultyProgression(attempts, problems)
|
||||||
|
|
||||||
@@ -123,17 +123,17 @@ class BusinessLogicTests {
|
|||||||
val problems = listOf(createTestProblem(gym.id), createTestProblem(gym.id))
|
val problems = listOf(createTestProblem(gym.id), createTestProblem(gym.id))
|
||||||
val session = ClimbSession.create(gym.id)
|
val session = ClimbSession.create(gym.id)
|
||||||
val attempts =
|
val attempts =
|
||||||
problems.map { problem ->
|
problems.map { problem ->
|
||||||
Attempt.create(session.id, problem.id, AttemptResult.SUCCESS)
|
Attempt.create(session.id, problem.id, AttemptResult.SUCCESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
val backup =
|
val backup =
|
||||||
createBackupData(
|
createBackupData(
|
||||||
gyms = listOf(gym),
|
gyms = listOf(gym),
|
||||||
problems = problems,
|
problems = problems,
|
||||||
sessions = listOf(session),
|
sessions = listOf(session),
|
||||||
attempts = attempts
|
attempts = attempts,
|
||||||
)
|
)
|
||||||
|
|
||||||
validateBackupIntegrity(backup)
|
validateBackupIntegrity(backup)
|
||||||
|
|
||||||
@@ -146,30 +146,30 @@ class BusinessLogicTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testClimbTypeCompatibilityRules() {
|
fun testClimbTypeCompatibilityRules() {
|
||||||
val boulderGym =
|
val boulderGym =
|
||||||
Gym(
|
Gym(
|
||||||
id = "boulder_gym",
|
id = "boulder_gym",
|
||||||
name = "Boulder Gym",
|
name = "Boulder Gym",
|
||||||
location = "Boulder City",
|
location = "Boulder City",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
||||||
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.FONT),
|
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.FONT),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = getCurrentTimestamp(),
|
createdAt = getCurrentTimestamp(),
|
||||||
updatedAt = getCurrentTimestamp()
|
updatedAt = getCurrentTimestamp(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val ropeGym =
|
val ropeGym =
|
||||||
Gym(
|
Gym(
|
||||||
id = "rope_gym",
|
id = "rope_gym",
|
||||||
name = "Rope Gym",
|
name = "Rope Gym",
|
||||||
location = "Rope City",
|
location = "Rope City",
|
||||||
supportedClimbTypes = listOf(ClimbType.ROPE),
|
supportedClimbTypes = listOf(ClimbType.ROPE),
|
||||||
difficultySystems = listOf(DifficultySystem.YDS),
|
difficultySystems = listOf(DifficultySystem.YDS),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = getCurrentTimestamp(),
|
createdAt = getCurrentTimestamp(),
|
||||||
updatedAt = getCurrentTimestamp()
|
updatedAt = getCurrentTimestamp(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Boulder gym should support boulder problems with V-Scale
|
// Boulder gym should support boulder problems with V-Scale
|
||||||
assertTrue(isCompatibleClimbType(boulderGym, ClimbType.BOULDER, DifficultySystem.V_SCALE))
|
assertTrue(isCompatibleClimbType(boulderGym, ClimbType.BOULDER, DifficultySystem.V_SCALE))
|
||||||
@@ -197,26 +197,26 @@ class BusinessLogicTests {
|
|||||||
val session = ClimbSession.create(gym.id)
|
val session = ClimbSession.create(gym.id)
|
||||||
|
|
||||||
val attempts =
|
val attempts =
|
||||||
listOf(
|
listOf(
|
||||||
createAttemptWithTimestamp(
|
createAttemptWithTimestamp(
|
||||||
session.id,
|
session.id,
|
||||||
problem.id,
|
problem.id,
|
||||||
"2024-01-01T10:00:00Z",
|
"2024-01-01T10:00:00Z",
|
||||||
AttemptResult.FALL
|
AttemptResult.FALL,
|
||||||
),
|
),
|
||||||
createAttemptWithTimestamp(
|
createAttemptWithTimestamp(
|
||||||
session.id,
|
session.id,
|
||||||
problem.id,
|
problem.id,
|
||||||
"2024-01-01T10:05:00Z",
|
"2024-01-01T10:05:00Z",
|
||||||
AttemptResult.FALL
|
AttemptResult.FALL,
|
||||||
),
|
),
|
||||||
createAttemptWithTimestamp(
|
createAttemptWithTimestamp(
|
||||||
session.id,
|
session.id,
|
||||||
problem.id,
|
problem.id,
|
||||||
"2024-01-01T10:10:00Z",
|
"2024-01-01T10:10:00Z",
|
||||||
AttemptResult.SUCCESS
|
AttemptResult.SUCCESS,
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val sequence = AttemptSequence(attempts)
|
val sequence = AttemptSequence(attempts)
|
||||||
|
|
||||||
@@ -230,32 +230,32 @@ class BusinessLogicTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testGradeConsistencyValidation() {
|
fun testGradeConsistencyValidation() {
|
||||||
val validCombinations =
|
val validCombinations =
|
||||||
listOf(
|
listOf(
|
||||||
Pair(ClimbType.BOULDER, DifficultySystem.V_SCALE),
|
Pair(ClimbType.BOULDER, DifficultySystem.V_SCALE),
|
||||||
Pair(ClimbType.BOULDER, DifficultySystem.FONT),
|
Pair(ClimbType.BOULDER, DifficultySystem.FONT),
|
||||||
Pair(ClimbType.ROPE, DifficultySystem.YDS),
|
Pair(ClimbType.ROPE, DifficultySystem.YDS),
|
||||||
Pair(ClimbType.BOULDER, DifficultySystem.CUSTOM),
|
Pair(ClimbType.BOULDER, DifficultySystem.CUSTOM),
|
||||||
Pair(ClimbType.ROPE, DifficultySystem.CUSTOM)
|
Pair(ClimbType.ROPE, DifficultySystem.CUSTOM),
|
||||||
)
|
)
|
||||||
|
|
||||||
val invalidCombinations =
|
val invalidCombinations =
|
||||||
listOf(
|
listOf(
|
||||||
Pair(ClimbType.BOULDER, DifficultySystem.YDS),
|
Pair(ClimbType.BOULDER, DifficultySystem.YDS),
|
||||||
Pair(ClimbType.ROPE, DifficultySystem.V_SCALE),
|
Pair(ClimbType.ROPE, DifficultySystem.V_SCALE),
|
||||||
Pair(ClimbType.ROPE, DifficultySystem.FONT)
|
Pair(ClimbType.ROPE, DifficultySystem.FONT),
|
||||||
)
|
)
|
||||||
|
|
||||||
validCombinations.forEach { (climbType, difficultySystem) ->
|
validCombinations.forEach { (climbType, difficultySystem) ->
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"$climbType should be compatible with $difficultySystem",
|
"$climbType should be compatible with $difficultySystem",
|
||||||
isValidGradeCombination(climbType, difficultySystem)
|
isValidGradeCombination(climbType, difficultySystem),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidCombinations.forEach { (climbType, difficultySystem) ->
|
invalidCombinations.forEach { (climbType, difficultySystem) ->
|
||||||
assertFalse(
|
assertFalse(
|
||||||
"$climbType should not be compatible with $difficultySystem",
|
"$climbType should not be compatible with $difficultySystem",
|
||||||
isValidGradeCombination(climbType, difficultySystem)
|
isValidGradeCombination(climbType, difficultySystem),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -276,11 +276,11 @@ class BusinessLogicTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testImagePathHandling() {
|
fun testImagePathHandling() {
|
||||||
val originalPaths =
|
val originalPaths =
|
||||||
listOf(
|
listOf(
|
||||||
"/storage/images/problem1.jpg",
|
"/storage/images/problem1.jpg",
|
||||||
"/data/cache/problem2.png",
|
"/data/cache/problem2.png",
|
||||||
"relative/path/problem3.jpeg"
|
"relative/path/problem3.jpeg",
|
||||||
)
|
)
|
||||||
|
|
||||||
val relativePaths = convertToRelativePaths(originalPaths)
|
val relativePaths = convertToRelativePaths(originalPaths)
|
||||||
|
|
||||||
@@ -295,76 +295,76 @@ class BusinessLogicTests {
|
|||||||
|
|
||||||
private fun createTestGym(): Gym {
|
private fun createTestGym(): Gym {
|
||||||
return Gym(
|
return Gym(
|
||||||
id = "test_gym_1",
|
id = "test_gym_1",
|
||||||
name = "Test Climbing Gym",
|
name = "Test Climbing Gym",
|
||||||
location = "Test City",
|
location = "Test City",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
||||||
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = "Test gym for unit testing",
|
notes = "Test gym for unit testing",
|
||||||
createdAt = getCurrentTimestamp(),
|
createdAt = getCurrentTimestamp(),
|
||||||
updatedAt = getCurrentTimestamp()
|
updatedAt = getCurrentTimestamp(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTestProblem(
|
private fun createTestProblem(
|
||||||
gymId: String,
|
gymId: String,
|
||||||
climbType: ClimbType = ClimbType.BOULDER
|
climbType: ClimbType = ClimbType.BOULDER,
|
||||||
): Problem {
|
): Problem {
|
||||||
val difficulty =
|
val difficulty =
|
||||||
when (climbType) {
|
when (climbType) {
|
||||||
ClimbType.BOULDER -> DifficultyGrade(DifficultySystem.V_SCALE, "V5")
|
ClimbType.BOULDER -> DifficultyGrade(DifficultySystem.V_SCALE, "V5")
|
||||||
ClimbType.ROPE -> DifficultyGrade(DifficultySystem.YDS, "5.10a")
|
ClimbType.ROPE -> DifficultyGrade(DifficultySystem.YDS, "5.10a")
|
||||||
}
|
}
|
||||||
|
|
||||||
return Problem(
|
return Problem(
|
||||||
id = "test_problem_${java.util.UUID.randomUUID()}",
|
id = "test_problem_${java.util.UUID.randomUUID()}",
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
name = "Test Problem",
|
name = "Test Problem",
|
||||||
description = "A test climbing problem",
|
description = "A test climbing problem",
|
||||||
climbType = climbType,
|
climbType = climbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
tags = listOf("test", "overhang"),
|
tags = listOf("test", "overhang"),
|
||||||
location = "Wall A",
|
location = "Wall A",
|
||||||
imagePaths = emptyList(),
|
imagePaths = emptyList(),
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = "2024-01-01",
|
dateSet = "2024-01-01",
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = getCurrentTimestamp(),
|
createdAt = getCurrentTimestamp(),
|
||||||
updatedAt = getCurrentTimestamp()
|
updatedAt = getCurrentTimestamp(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createTestProblemWithGrade(gymId: String, grade: String): Problem {
|
private fun createTestProblemWithGrade(gymId: String, grade: String): Problem {
|
||||||
return Problem(
|
return Problem(
|
||||||
id = "test_problem_${java.util.UUID.randomUUID()}",
|
id = "test_problem_${java.util.UUID.randomUUID()}",
|
||||||
gymId = gymId,
|
gymId = gymId,
|
||||||
name = "Test Problem $grade",
|
name = "Test Problem $grade",
|
||||||
description = null,
|
description = null,
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, grade),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, grade),
|
||||||
tags = emptyList(),
|
tags = emptyList(),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = emptyList(),
|
imagePaths = emptyList(),
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = getCurrentTimestamp(),
|
createdAt = getCurrentTimestamp(),
|
||||||
updatedAt = getCurrentTimestamp()
|
updatedAt = getCurrentTimestamp(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createAttemptWithTimestamp(
|
private fun createAttemptWithTimestamp(
|
||||||
sessionId: String,
|
sessionId: String,
|
||||||
problemId: String,
|
problemId: String,
|
||||||
timestamp: String,
|
timestamp: String,
|
||||||
result: AttemptResult
|
result: AttemptResult,
|
||||||
): Attempt {
|
): Attempt {
|
||||||
return Attempt.create(
|
return Attempt.create(
|
||||||
sessionId = sessionId,
|
sessionId = sessionId,
|
||||||
problemId = problemId,
|
problemId = problemId,
|
||||||
result = result,
|
result = result,
|
||||||
timestamp = timestamp
|
timestamp = timestamp,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,126 +373,126 @@ class BusinessLogicTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateSessionStatistics(
|
private fun calculateSessionStatistics(
|
||||||
session: ClimbSession,
|
session: ClimbSession,
|
||||||
attempts: List<Attempt>
|
attempts: List<Attempt>,
|
||||||
): SessionStatistics {
|
): SessionStatistics {
|
||||||
val successful =
|
val successful =
|
||||||
attempts.count {
|
attempts.count {
|
||||||
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
||||||
}
|
}
|
||||||
val uniqueProblems = attempts.map { it.problemId }.toSet().size
|
val uniqueProblems = attempts.map { it.problemId }.toSet().size
|
||||||
val successRate = (successful.toDouble() / attempts.size) * 100
|
val successRate = (successful.toDouble() / attempts.size) * 100
|
||||||
|
|
||||||
return SessionStatistics(
|
return SessionStatistics(
|
||||||
totalAttempts = attempts.size,
|
totalAttempts = attempts.size,
|
||||||
successfulAttempts = successful,
|
successfulAttempts = successful,
|
||||||
uniqueProblems = uniqueProblems,
|
uniqueProblems = uniqueProblems,
|
||||||
successRate = successRate
|
successRate = successRate,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateDifficultyProgression(
|
private fun calculateDifficultyProgression(
|
||||||
attempts: List<Attempt>,
|
attempts: List<Attempt>,
|
||||||
problems: List<Problem>
|
problems: List<Problem>,
|
||||||
): DifficultyProgression {
|
): DifficultyProgression {
|
||||||
val problemMap = problems.associateBy { it.id }
|
val problemMap = problems.associateBy { it.id }
|
||||||
val grades =
|
val grades =
|
||||||
attempts
|
attempts
|
||||||
.mapNotNull { attempt -> problemMap[attempt.problemId]?.difficulty?.grade }
|
.mapNotNull { attempt -> problemMap[attempt.problemId]?.difficulty?.grade }
|
||||||
.filter { it.startsWith("V") }
|
.filter { it.startsWith("V") }
|
||||||
|
|
||||||
val numericGrades =
|
val numericGrades =
|
||||||
grades.mapNotNull { grade ->
|
grades.mapNotNull { grade ->
|
||||||
when (grade) {
|
when (grade) {
|
||||||
"VB" -> 0
|
"VB" -> 0
|
||||||
else -> grade.removePrefix("V").toIntOrNull()
|
else -> grade.removePrefix("V").toIntOrNull()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val minGrade = "V${numericGrades.minOrNull() ?: 0}".replace("V0", "VB")
|
val minGrade = "V${numericGrades.minOrNull() ?: 0}".replace("V0", "VB")
|
||||||
val maxGrade = "V${numericGrades.maxOrNull() ?: 0}".replace("V0", "VB")
|
val maxGrade = "V${numericGrades.maxOrNull() ?: 0}".replace("V0", "VB")
|
||||||
val avgGrade = numericGrades.average()
|
val avgGrade = numericGrades.average()
|
||||||
val showsProgression =
|
val showsProgression =
|
||||||
numericGrades.size > 1 &&
|
numericGrades.size > 1 &&
|
||||||
(numericGrades.maxOrNull() ?: 0) > (numericGrades.minOrNull() ?: 0)
|
(numericGrades.maxOrNull() ?: 0) > (numericGrades.minOrNull() ?: 0)
|
||||||
|
|
||||||
return DifficultyProgression(minGrade, maxGrade, avgGrade, showsProgression)
|
return DifficultyProgression(minGrade, maxGrade, avgGrade, showsProgression)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createBackupData(
|
private fun createBackupData(
|
||||||
gyms: List<Gym>,
|
gyms: List<Gym>,
|
||||||
problems: List<Problem>,
|
problems: List<Problem>,
|
||||||
sessions: List<ClimbSession>,
|
sessions: List<ClimbSession>,
|
||||||
attempts: List<Attempt>
|
attempts: List<Attempt>,
|
||||||
): ClimbDataBackup {
|
): ClimbDataBackup {
|
||||||
return ClimbDataBackup(
|
return ClimbDataBackup(
|
||||||
exportedAt = getCurrentTimestamp(),
|
exportedAt = getCurrentTimestamp(),
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms =
|
gyms =
|
||||||
gyms.map { gym ->
|
gyms.map { gym ->
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = gym.id,
|
id = gym.id,
|
||||||
name = gym.name,
|
name = gym.name,
|
||||||
location = gym.location,
|
location = gym.location,
|
||||||
supportedClimbTypes = gym.supportedClimbTypes,
|
supportedClimbTypes = gym.supportedClimbTypes,
|
||||||
difficultySystems = gym.difficultySystems,
|
difficultySystems = gym.difficultySystems,
|
||||||
customDifficultyGrades = gym.customDifficultyGrades,
|
customDifficultyGrades = gym.customDifficultyGrades,
|
||||||
notes = gym.notes,
|
notes = gym.notes,
|
||||||
createdAt = gym.createdAt,
|
createdAt = gym.createdAt,
|
||||||
updatedAt = gym.updatedAt
|
updatedAt = gym.updatedAt,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
problems =
|
problems =
|
||||||
problems.map { problem ->
|
problems.map { problem ->
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = problem.id,
|
id = problem.id,
|
||||||
gymId = problem.gymId,
|
gymId = problem.gymId,
|
||||||
name = problem.name,
|
name = problem.name,
|
||||||
description = problem.description,
|
description = problem.description,
|
||||||
climbType = problem.climbType,
|
climbType = problem.climbType,
|
||||||
difficulty = problem.difficulty,
|
difficulty = problem.difficulty,
|
||||||
tags = problem.tags,
|
tags = problem.tags,
|
||||||
location = problem.location,
|
location = problem.location,
|
||||||
imagePaths = problem.imagePaths,
|
imagePaths = problem.imagePaths,
|
||||||
isActive = problem.isActive,
|
isActive = problem.isActive,
|
||||||
dateSet = problem.dateSet,
|
dateSet = problem.dateSet,
|
||||||
notes = problem.notes,
|
notes = problem.notes,
|
||||||
createdAt = problem.createdAt,
|
createdAt = problem.createdAt,
|
||||||
updatedAt = problem.updatedAt
|
updatedAt = problem.updatedAt,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
sessions =
|
sessions =
|
||||||
sessions.map { session ->
|
sessions.map { session ->
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = session.id,
|
id = session.id,
|
||||||
gymId = session.gymId,
|
gymId = session.gymId,
|
||||||
date = session.date,
|
date = session.date,
|
||||||
startTime = session.startTime,
|
startTime = session.startTime,
|
||||||
endTime = session.endTime,
|
endTime = session.endTime,
|
||||||
duration = session.duration,
|
duration = session.duration,
|
||||||
status = session.status,
|
status = session.status,
|
||||||
notes = session.notes,
|
notes = session.notes,
|
||||||
createdAt = session.createdAt,
|
createdAt = session.createdAt,
|
||||||
updatedAt = session.updatedAt
|
updatedAt = session.updatedAt,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
attempts =
|
attempts =
|
||||||
attempts.map { attempt ->
|
attempts.map { attempt ->
|
||||||
BackupAttempt(
|
BackupAttempt(
|
||||||
id = attempt.id,
|
id = attempt.id,
|
||||||
sessionId = attempt.sessionId,
|
sessionId = attempt.sessionId,
|
||||||
problemId = attempt.problemId,
|
problemId = attempt.problemId,
|
||||||
result = attempt.result,
|
result = attempt.result,
|
||||||
highestHold = attempt.highestHold,
|
highestHold = attempt.highestHold,
|
||||||
notes = attempt.notes,
|
notes = attempt.notes,
|
||||||
duration = attempt.duration,
|
duration = attempt.duration,
|
||||||
restTime = attempt.restTime,
|
restTime = attempt.restTime,
|
||||||
timestamp = attempt.timestamp,
|
timestamp = attempt.timestamp,
|
||||||
createdAt = attempt.createdAt,
|
createdAt = attempt.createdAt,
|
||||||
updatedAt = attempt.updatedAt,
|
updatedAt = attempt.updatedAt,
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,8 +501,8 @@ class BusinessLogicTests {
|
|||||||
val gymIds = backup.gyms.map { it.id }.toSet()
|
val gymIds = backup.gyms.map { it.id }.toSet()
|
||||||
backup.problems.forEach { problem ->
|
backup.problems.forEach { problem ->
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Problem ${problem.id} references non-existent gym ${problem.gymId}",
|
"Problem ${problem.id} references non-existent gym ${problem.gymId}",
|
||||||
gymIds.contains(problem.gymId)
|
gymIds.contains(problem.gymId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -510,8 +510,8 @@ class BusinessLogicTests {
|
|||||||
val sessionIds = backup.sessions.map { it.id }.toSet()
|
val sessionIds = backup.sessions.map { it.id }.toSet()
|
||||||
backup.attempts.forEach { attempt ->
|
backup.attempts.forEach { attempt ->
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Attempt ${attempt.id} references non-existent session ${attempt.sessionId}",
|
"Attempt ${attempt.id} references non-existent session ${attempt.sessionId}",
|
||||||
sessionIds.contains(attempt.sessionId)
|
sessionIds.contains(attempt.sessionId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -519,19 +519,19 @@ class BusinessLogicTests {
|
|||||||
val problemIds = backup.problems.map { it.id }.toSet()
|
val problemIds = backup.problems.map { it.id }.toSet()
|
||||||
backup.attempts.forEach { attempt ->
|
backup.attempts.forEach { attempt ->
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Attempt ${attempt.id} references non-existent problem ${attempt.problemId}",
|
"Attempt ${attempt.id} references non-existent problem ${attempt.problemId}",
|
||||||
problemIds.contains(attempt.problemId)
|
problemIds.contains(attempt.problemId),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isCompatibleClimbType(
|
private fun isCompatibleClimbType(
|
||||||
gym: Gym,
|
gym: Gym,
|
||||||
climbType: ClimbType,
|
climbType: ClimbType,
|
||||||
difficultySystem: DifficultySystem
|
difficultySystem: DifficultySystem,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return gym.supportedClimbTypes.contains(climbType) &&
|
return gym.supportedClimbTypes.contains(climbType) &&
|
||||||
gym.difficultySystems.contains(difficultySystem)
|
gym.difficultySystems.contains(difficultySystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun calculateSessionDuration(startTime: String, endTime: String): Long {
|
private fun calculateSessionDuration(startTime: String, endTime: String): Long {
|
||||||
@@ -541,19 +541,19 @@ class BusinessLogicTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidGradeCombination(
|
private fun isValidGradeCombination(
|
||||||
climbType: ClimbType,
|
climbType: ClimbType,
|
||||||
difficultySystem: DifficultySystem
|
difficultySystem: DifficultySystem,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
return when (climbType) {
|
return when (climbType) {
|
||||||
ClimbType.BOULDER ->
|
ClimbType.BOULDER ->
|
||||||
difficultySystem in
|
difficultySystem in
|
||||||
listOf(
|
listOf(
|
||||||
DifficultySystem.V_SCALE,
|
DifficultySystem.V_SCALE,
|
||||||
DifficultySystem.FONT,
|
DifficultySystem.FONT,
|
||||||
DifficultySystem.CUSTOM
|
DifficultySystem.CUSTOM,
|
||||||
)
|
)
|
||||||
ClimbType.ROPE ->
|
ClimbType.ROPE ->
|
||||||
difficultySystem in listOf(DifficultySystem.YDS, DifficultySystem.CUSTOM)
|
difficultySystem in listOf(DifficultySystem.YDS, DifficultySystem.CUSTOM)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,29 +568,29 @@ class BusinessLogicTests {
|
|||||||
// Data classes for testing
|
// Data classes for testing
|
||||||
|
|
||||||
data class SessionStatistics(
|
data class SessionStatistics(
|
||||||
val totalAttempts: Int,
|
val totalAttempts: Int,
|
||||||
val successfulAttempts: Int,
|
val successfulAttempts: Int,
|
||||||
val uniqueProblems: Int,
|
val uniqueProblems: Int,
|
||||||
val successRate: Double
|
val successRate: Double,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class DifficultyProgression(
|
data class DifficultyProgression(
|
||||||
val minGrade: String,
|
val minGrade: String,
|
||||||
val maxGrade: String,
|
val maxGrade: String,
|
||||||
val averageGrade: Double,
|
val averageGrade: Double,
|
||||||
val showsProgression: Boolean
|
val showsProgression: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class AttemptSequence(val attempts: List<Attempt>) {
|
data class AttemptSequence(val attempts: List<Attempt>) {
|
||||||
val totalAttempts = attempts.size
|
val totalAttempts = attempts.size
|
||||||
val failedAttempts =
|
val failedAttempts =
|
||||||
attempts.count {
|
attempts.count {
|
||||||
it.result == AttemptResult.FALL || it.result == AttemptResult.NO_PROGRESS
|
it.result == AttemptResult.FALL || it.result == AttemptResult.NO_PROGRESS
|
||||||
}
|
}
|
||||||
val successfulAttempts =
|
val successfulAttempts =
|
||||||
attempts.count {
|
attempts.count {
|
||||||
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
it.result == AttemptResult.SUCCESS || it.result == AttemptResult.FLASH
|
||||||
}
|
}
|
||||||
val finalResult = attempts.lastOrNull()?.result
|
val finalResult = attempts.lastOrNull()?.result
|
||||||
|
|
||||||
fun isValidSequence(): Boolean {
|
fun isValidSequence(): Boolean {
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ package com.atridad.ascently
|
|||||||
|
|
||||||
import com.atridad.ascently.data.format.*
|
import com.atridad.ascently.data.format.*
|
||||||
import com.atridad.ascently.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import java.time.Instant
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
class DataModelTests {
|
class DataModelTests {
|
||||||
|
|
||||||
@@ -141,17 +141,17 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testBackupGymCreationAndValidation() {
|
fun testBackupGymCreationAndValidation() {
|
||||||
val gym =
|
val gym =
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym123",
|
id = "gym123",
|
||||||
name = "Test Climbing Gym",
|
name = "Test Climbing Gym",
|
||||||
location = "Test City",
|
location = "Test City",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
||||||
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
difficultySystems = listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = "Great gym for beginners",
|
notes = "Great gym for beginners",
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("gym123", gym.id)
|
assertEquals("gym123", gym.id)
|
||||||
assertEquals("Test Climbing Gym", gym.name)
|
assertEquals("Test Climbing Gym", gym.name)
|
||||||
@@ -167,22 +167,22 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testBackupProblemCreationAndValidation() {
|
fun testBackupProblemCreationAndValidation() {
|
||||||
val problem =
|
val problem =
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem123",
|
id = "problem123",
|
||||||
gymId = "gym123",
|
gymId = "gym123",
|
||||||
name = "Test Problem",
|
name = "Test Problem",
|
||||||
description = "A challenging boulder problem",
|
description = "A challenging boulder problem",
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
||||||
tags = listOf("overhang", "crimpy"),
|
tags = listOf("overhang", "crimpy"),
|
||||||
location = "Wall A",
|
location = "Wall A",
|
||||||
imagePaths = listOf("image1.jpg", "image2.jpg"),
|
imagePaths = listOf("image1.jpg", "image2.jpg"),
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = "2024-01-01",
|
dateSet = "2024-01-01",
|
||||||
notes = "Watch the start holds",
|
notes = "Watch the start holds",
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("problem123", problem.id)
|
assertEquals("problem123", problem.id)
|
||||||
assertEquals("gym123", problem.gymId)
|
assertEquals("gym123", problem.gymId)
|
||||||
@@ -190,25 +190,25 @@ class DataModelTests {
|
|||||||
assertEquals(ClimbType.BOULDER, problem.climbType)
|
assertEquals(ClimbType.BOULDER, problem.climbType)
|
||||||
assertEquals("V5", problem.difficulty.grade)
|
assertEquals("V5", problem.difficulty.grade)
|
||||||
assertTrue(problem.isActive)
|
assertTrue(problem.isActive)
|
||||||
assertEquals(2, problem.tags.size)
|
assertEquals(2, problem.tags?.size ?: 0)
|
||||||
assertEquals(2, problem.imagePaths?.size ?: 0)
|
assertEquals(2, problem.imagePaths?.size ?: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testBackupClimbSessionCreationAndValidation() {
|
fun testBackupClimbSessionCreationAndValidation() {
|
||||||
val session =
|
val session =
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "session123",
|
id = "session123",
|
||||||
gymId = "gym123",
|
gymId = "gym123",
|
||||||
date = "2024-01-01",
|
date = "2024-01-01",
|
||||||
startTime = "2024-01-01T10:00:00Z",
|
startTime = "2024-01-01T10:00:00Z",
|
||||||
endTime = "2024-01-01T12:00:00Z",
|
endTime = "2024-01-01T12:00:00Z",
|
||||||
duration = 7200,
|
duration = 7200,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = "Great session today",
|
notes = "Great session today",
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T12:00:00Z"
|
updatedAt = "2024-01-01T12:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("session123", session.id)
|
assertEquals("session123", session.id)
|
||||||
assertEquals("gym123", session.gymId)
|
assertEquals("gym123", session.gymId)
|
||||||
@@ -220,19 +220,19 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testBackupAttemptCreationAndValidation() {
|
fun testBackupAttemptCreationAndValidation() {
|
||||||
val attempt =
|
val attempt =
|
||||||
BackupAttempt(
|
BackupAttempt(
|
||||||
id = "attempt123",
|
id = "attempt123",
|
||||||
sessionId = "session123",
|
sessionId = "session123",
|
||||||
problemId = "problem123",
|
problemId = "problem123",
|
||||||
result = AttemptResult.SUCCESS,
|
result = AttemptResult.SUCCESS,
|
||||||
highestHold = "Top",
|
highestHold = "Top",
|
||||||
notes = "Stuck it on second try",
|
notes = "Stuck it on second try",
|
||||||
duration = 300,
|
duration = 300,
|
||||||
restTime = 120,
|
restTime = 120,
|
||||||
timestamp = "2024-01-01T10:30:00Z",
|
timestamp = "2024-01-01T10:30:00Z",
|
||||||
createdAt = "2024-01-01T10:30:00Z",
|
createdAt = "2024-01-01T10:30:00Z",
|
||||||
updatedAt = "2024-01-01T10:30:00Z"
|
updatedAt = "2024-01-01T10:30:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("attempt123", attempt.id)
|
assertEquals("attempt123", attempt.id)
|
||||||
assertEquals("session123", attempt.sessionId)
|
assertEquals("session123", attempt.sessionId)
|
||||||
@@ -246,15 +246,15 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testClimbDataBackupCreationAndValidation() {
|
fun testClimbDataBackupCreationAndValidation() {
|
||||||
val backup =
|
val backup =
|
||||||
ClimbDataBackup(
|
ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T10:00:00Z",
|
exportedAt = "2024-01-01T10:00:00Z",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms = emptyList(),
|
gyms = emptyList(),
|
||||||
problems = emptyList(),
|
problems = emptyList(),
|
||||||
sessions = emptyList(),
|
sessions = emptyList(),
|
||||||
attempts = emptyList()
|
attempts = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals("2.0", backup.version)
|
assertEquals("2.0", backup.version)
|
||||||
assertEquals("2.0", backup.formatVersion)
|
assertEquals("2.0", backup.formatVersion)
|
||||||
@@ -280,18 +280,18 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testSessionDurationCalculation() {
|
fun testSessionDurationCalculation() {
|
||||||
val session =
|
val session =
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "test",
|
id = "test",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
date = "2024-01-01",
|
date = "2024-01-01",
|
||||||
startTime = "2024-01-01T10:00:00Z",
|
startTime = "2024-01-01T10:00:00Z",
|
||||||
endTime = "2024-01-01T12:00:00Z",
|
endTime = "2024-01-01T12:00:00Z",
|
||||||
duration = 7200,
|
duration = 7200,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T12:00:00Z"
|
updatedAt = "2024-01-01T12:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(7200L, session.duration)
|
assertEquals(7200L, session.duration)
|
||||||
val hours = session.duration!! / 3600
|
val hours = session.duration!! / 3600
|
||||||
@@ -301,21 +301,21 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testEmptyCollectionsHandling() {
|
fun testEmptyCollectionsHandling() {
|
||||||
val gym =
|
val gym =
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym1",
|
id = "gym1",
|
||||||
name = "Test Gym",
|
name = "Test Gym",
|
||||||
location = null,
|
location = null,
|
||||||
supportedClimbTypes = emptyList(),
|
supportedClimbTypes = emptyList(),
|
||||||
difficultySystems = emptyList(),
|
difficultySystems = emptyList(),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertTrue(gym.supportedClimbTypes.isEmpty())
|
assertTrue(gym.supportedClimbTypes?.isEmpty() ?: true)
|
||||||
assertTrue(gym.difficultySystems.isEmpty())
|
assertTrue(gym.difficultySystems?.isEmpty() ?: true)
|
||||||
assertTrue(gym.customDifficultyGrades.isEmpty())
|
assertTrue(gym.customDifficultyGrades?.isEmpty() ?: true)
|
||||||
assertNull(gym.location)
|
assertNull(gym.location)
|
||||||
assertNull(gym.notes)
|
assertNull(gym.notes)
|
||||||
}
|
}
|
||||||
@@ -323,29 +323,29 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testNullableFieldsHandling() {
|
fun testNullableFieldsHandling() {
|
||||||
val problem =
|
val problem =
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem1",
|
id = "problem1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
name = null,
|
name = null,
|
||||||
description = null,
|
description = null,
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V1"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V1"),
|
||||||
tags = emptyList(),
|
tags = emptyList(),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = null,
|
imagePaths = null,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertNull(problem.name)
|
assertNull(problem.name)
|
||||||
assertNull(problem.description)
|
assertNull(problem.description)
|
||||||
assertNull(problem.location)
|
assertNull(problem.location)
|
||||||
assertNull(problem.dateSet)
|
assertNull(problem.dateSet)
|
||||||
assertNull(problem.notes)
|
assertNull(problem.notes)
|
||||||
assertTrue(problem.tags.isEmpty())
|
assertTrue(problem.tags?.isEmpty() ?: true)
|
||||||
assertNull(problem.imagePaths)
|
assertNull(problem.imagePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -362,7 +362,7 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testBackupDataFormatValidation() {
|
fun testBackupDataFormatValidation() {
|
||||||
val testJson =
|
val testJson =
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"exportedAt": "2024-01-01T10:00:00Z",
|
"exportedAt": "2024-01-01T10:00:00Z",
|
||||||
"version": "2.0",
|
"version": "2.0",
|
||||||
@@ -372,7 +372,7 @@ class DataModelTests {
|
|||||||
"sessions": [],
|
"sessions": [],
|
||||||
"attempts": []
|
"attempts": []
|
||||||
}
|
}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
assertTrue(testJson.contains("exportedAt"))
|
assertTrue(testJson.contains("exportedAt"))
|
||||||
assertTrue(testJson.contains("version"))
|
assertTrue(testJson.contains("version"))
|
||||||
@@ -397,44 +397,44 @@ class DataModelTests {
|
|||||||
fun testClimbTypeAndDifficultySystemCompatibility() {
|
fun testClimbTypeAndDifficultySystemCompatibility() {
|
||||||
// Test that V_SCALE works with BOULDER
|
// Test that V_SCALE works with BOULDER
|
||||||
val boulderProblem =
|
val boulderProblem =
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "boulder1",
|
id = "boulder1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
name = "Boulder Problem",
|
name = "Boulder Problem",
|
||||||
description = null,
|
description = null,
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V3"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V3"),
|
||||||
tags = emptyList(),
|
tags = emptyList(),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = null,
|
imagePaths = null,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(ClimbType.BOULDER, boulderProblem.climbType)
|
assertEquals(ClimbType.BOULDER, boulderProblem.climbType)
|
||||||
assertEquals(DifficultySystem.V_SCALE, boulderProblem.difficulty.system)
|
assertEquals(DifficultySystem.V_SCALE, boulderProblem.difficulty.system)
|
||||||
|
|
||||||
// Test that YDS works with ROPE
|
// Test that YDS works with ROPE
|
||||||
val ropeProblem =
|
val ropeProblem =
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "rope1",
|
id = "rope1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
name = "Rope Problem",
|
name = "Rope Problem",
|
||||||
description = null,
|
description = null,
|
||||||
climbType = ClimbType.ROPE,
|
climbType = ClimbType.ROPE,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.YDS, "5.10a"),
|
difficulty = DifficultyGrade(DifficultySystem.YDS, "5.10a"),
|
||||||
tags = emptyList(),
|
tags = emptyList(),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = null,
|
imagePaths = null,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(ClimbType.ROPE, ropeProblem.climbType)
|
assertEquals(ClimbType.ROPE, ropeProblem.climbType)
|
||||||
assertEquals(DifficultySystem.YDS, ropeProblem.difficulty.system)
|
assertEquals(DifficultySystem.YDS, ropeProblem.difficulty.system)
|
||||||
@@ -473,12 +473,12 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testAttemptResultValidation() {
|
fun testAttemptResultValidation() {
|
||||||
val validResults =
|
val validResults =
|
||||||
listOf(
|
listOf(
|
||||||
AttemptResult.SUCCESS,
|
AttemptResult.SUCCESS,
|
||||||
AttemptResult.FALL,
|
AttemptResult.FALL,
|
||||||
AttemptResult.NO_PROGRESS,
|
AttemptResult.NO_PROGRESS,
|
||||||
AttemptResult.FLASH
|
AttemptResult.FLASH,
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(4, validResults.size)
|
assertEquals(4, validResults.size)
|
||||||
assertTrue(validResults.contains(AttemptResult.SUCCESS))
|
assertTrue(validResults.contains(AttemptResult.SUCCESS))
|
||||||
@@ -490,7 +490,7 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testSessionStatusValidation() {
|
fun testSessionStatusValidation() {
|
||||||
val validStatuses =
|
val validStatuses =
|
||||||
listOf(SessionStatus.ACTIVE, SessionStatus.COMPLETED, SessionStatus.PAUSED)
|
listOf(SessionStatus.ACTIVE, SessionStatus.COMPLETED, SessionStatus.PAUSED)
|
||||||
|
|
||||||
assertEquals(3, validStatuses.size)
|
assertEquals(3, validStatuses.size)
|
||||||
assertTrue(validStatuses.contains(SessionStatus.ACTIVE))
|
assertTrue(validStatuses.contains(SessionStatus.ACTIVE))
|
||||||
@@ -501,64 +501,64 @@ class DataModelTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testClimbDataIntegrity() {
|
fun testClimbDataIntegrity() {
|
||||||
val gym =
|
val gym =
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym1",
|
id = "gym1",
|
||||||
name = "Test Gym",
|
name = "Test Gym",
|
||||||
location = "Test City",
|
location = "Test City",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
||||||
difficultySystems = listOf(DifficultySystem.V_SCALE),
|
difficultySystems = listOf(DifficultySystem.V_SCALE),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
val problem =
|
val problem =
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem1",
|
id = "problem1",
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
name = "Test Problem",
|
name = "Test Problem",
|
||||||
description = null,
|
description = null,
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V3"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V3"),
|
||||||
tags = emptyList(),
|
tags = emptyList(),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = null,
|
imagePaths = null,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T10:00:00Z"
|
updatedAt = "2024-01-01T10:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
val session =
|
val session =
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "session1",
|
id = "session1",
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
date = "2024-01-01",
|
date = "2024-01-01",
|
||||||
startTime = "2024-01-01T10:00:00Z",
|
startTime = "2024-01-01T10:00:00Z",
|
||||||
endTime = "2024-01-01T11:00:00Z",
|
endTime = "2024-01-01T11:00:00Z",
|
||||||
duration = 3600,
|
duration = 3600,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00Z",
|
createdAt = "2024-01-01T10:00:00Z",
|
||||||
updatedAt = "2024-01-01T11:00:00Z"
|
updatedAt = "2024-01-01T11:00:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
val attempt =
|
val attempt =
|
||||||
BackupAttempt(
|
BackupAttempt(
|
||||||
id = "attempt1",
|
id = "attempt1",
|
||||||
sessionId = session.id,
|
sessionId = session.id,
|
||||||
problemId = problem.id,
|
problemId = problem.id,
|
||||||
result = AttemptResult.SUCCESS,
|
result = AttemptResult.SUCCESS,
|
||||||
highestHold = null,
|
highestHold = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
duration = 120,
|
duration = 120,
|
||||||
restTime = null,
|
restTime = null,
|
||||||
timestamp = "2024-01-01T10:30:00Z",
|
timestamp = "2024-01-01T10:30:00Z",
|
||||||
createdAt = "2024-01-01T10:30:00Z",
|
createdAt = "2024-01-01T10:30:00Z",
|
||||||
updatedAt = "2024-01-01T10:30:00Z"
|
updatedAt = "2024-01-01T10:30:00Z",
|
||||||
)
|
)
|
||||||
|
|
||||||
// Verify referential integrity
|
// Verify referential integrity
|
||||||
assertEquals(gym.id, problem.gymId)
|
assertEquals(gym.id, problem.gymId)
|
||||||
|
|||||||
@@ -11,197 +11,197 @@ class SyncMergeLogicTest {
|
|||||||
fun `test intelligent merge preserves all data`() {
|
fun `test intelligent merge preserves all data`() {
|
||||||
// Create local data
|
// Create local data
|
||||||
val localGyms =
|
val localGyms =
|
||||||
listOf(
|
listOf(
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym1",
|
id = "gym1",
|
||||||
name = "Local Gym 1",
|
name = "Local Gym 1",
|
||||||
location = "Local Location",
|
location = "Local Location",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
||||||
difficultySystems = listOf(DifficultySystem.V_SCALE),
|
difficultySystems = listOf(DifficultySystem.V_SCALE),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T10:00:00"
|
updatedAt = "2024-01-01T10:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val localProblems =
|
val localProblems =
|
||||||
listOf(
|
listOf(
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem1",
|
id = "problem1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
name = "Local Problem",
|
name = "Local Problem",
|
||||||
description = "Local description",
|
description = "Local description",
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
||||||
tags = listOf("local"),
|
tags = listOf("local"),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = listOf("local_image.jpg"),
|
imagePaths = listOf("local_image.jpg"),
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T10:00:00"
|
updatedAt = "2024-01-01T10:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val localSessions =
|
val localSessions =
|
||||||
listOf(
|
listOf(
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "session1",
|
id = "session1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
date = "2024-01-01",
|
date = "2024-01-01",
|
||||||
startTime = "2024-01-01T10:00:00",
|
startTime = "2024-01-01T10:00:00",
|
||||||
endTime = "2024-01-01T12:00:00",
|
endTime = "2024-01-01T12:00:00",
|
||||||
duration = 7200,
|
duration = 7200,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T10:00:00"
|
updatedAt = "2024-01-01T10:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val localAttempts =
|
val localAttempts =
|
||||||
listOf(
|
listOf(
|
||||||
BackupAttempt(
|
BackupAttempt(
|
||||||
id = "attempt1",
|
id = "attempt1",
|
||||||
sessionId = "session1",
|
sessionId = "session1",
|
||||||
problemId = "problem1",
|
problemId = "problem1",
|
||||||
result = AttemptResult.SUCCESS,
|
result = AttemptResult.SUCCESS,
|
||||||
highestHold = null,
|
highestHold = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
duration = 300,
|
duration = 300,
|
||||||
restTime = null,
|
restTime = null,
|
||||||
timestamp = "2024-01-01T10:30:00",
|
timestamp = "2024-01-01T10:30:00",
|
||||||
createdAt = "2024-01-01T10:30:00",
|
createdAt = "2024-01-01T10:30:00",
|
||||||
updatedAt = "2024-01-01T10:30:00"
|
updatedAt = "2024-01-01T10:30:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val localBackup =
|
val localBackup =
|
||||||
ClimbDataBackup(
|
ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T10:00:00",
|
exportedAt = "2024-01-01T10:00:00",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms = localGyms,
|
gyms = localGyms,
|
||||||
problems = localProblems,
|
problems = localProblems,
|
||||||
sessions = localSessions,
|
sessions = localSessions,
|
||||||
attempts = localAttempts
|
attempts = localAttempts,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create server data with some overlapping and some unique data
|
// Create server data with some overlapping and some unique data
|
||||||
val serverGyms =
|
val serverGyms =
|
||||||
listOf(
|
listOf(
|
||||||
// Same gym but with newer update
|
// Same gym but with newer update
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym1",
|
id = "gym1",
|
||||||
name = "Updated Gym 1",
|
name = "Updated Gym 1",
|
||||||
location = "Updated Location",
|
location = "Updated Location",
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
supportedClimbTypes = listOf(ClimbType.BOULDER, ClimbType.ROPE),
|
||||||
difficultySystems =
|
difficultySystems =
|
||||||
listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
listOf(DifficultySystem.V_SCALE, DifficultySystem.YDS),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = "Updated notes",
|
notes = "Updated notes",
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T12:00:00" // Newer update
|
updatedAt = "2024-01-01T12:00:00", // Newer update
|
||||||
),
|
),
|
||||||
// Unique server gym
|
// Unique server gym
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym2",
|
id = "gym2",
|
||||||
name = "Server Gym 2",
|
name = "Server Gym 2",
|
||||||
location = "Server Location",
|
location = "Server Location",
|
||||||
supportedClimbTypes = listOf(ClimbType.ROPE),
|
supportedClimbTypes = listOf(ClimbType.ROPE),
|
||||||
difficultySystems = listOf(DifficultySystem.YDS),
|
difficultySystems = listOf(DifficultySystem.YDS),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T11:00:00",
|
createdAt = "2024-01-01T11:00:00",
|
||||||
updatedAt = "2024-01-01T11:00:00"
|
updatedAt = "2024-01-01T11:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val serverProblems =
|
val serverProblems =
|
||||||
listOf(
|
listOf(
|
||||||
// Same problem but with newer update and different images
|
// Same problem but with newer update and different images
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem1",
|
id = "problem1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
name = "Updated Problem",
|
name = "Updated Problem",
|
||||||
description = "Updated description",
|
description = "Updated description",
|
||||||
climbType = ClimbType.BOULDER,
|
climbType = ClimbType.BOULDER,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
difficulty = DifficultyGrade(DifficultySystem.V_SCALE, "V5"),
|
||||||
tags = listOf("updated", "server"),
|
tags = listOf("updated", "server"),
|
||||||
location = "Updated location",
|
location = "Updated location",
|
||||||
imagePaths = listOf("server_image.jpg"),
|
imagePaths = listOf("server_image.jpg"),
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = "2024-01-01",
|
dateSet = "2024-01-01",
|
||||||
notes = "Updated notes",
|
notes = "Updated notes",
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T11:00:00" // Newer update
|
updatedAt = "2024-01-01T11:00:00", // Newer update
|
||||||
),
|
),
|
||||||
// Unique server problem
|
// Unique server problem
|
||||||
BackupProblem(
|
BackupProblem(
|
||||||
id = "problem2",
|
id = "problem2",
|
||||||
gymId = "gym2",
|
gymId = "gym2",
|
||||||
name = "Server Problem",
|
name = "Server Problem",
|
||||||
description = "Server description",
|
description = "Server description",
|
||||||
climbType = ClimbType.ROPE,
|
climbType = ClimbType.ROPE,
|
||||||
difficulty = DifficultyGrade(DifficultySystem.YDS, "5.10a"),
|
difficulty = DifficultyGrade(DifficultySystem.YDS, "5.10a"),
|
||||||
tags = listOf("server"),
|
tags = listOf("server"),
|
||||||
location = null,
|
location = null,
|
||||||
imagePaths = null,
|
imagePaths = null,
|
||||||
isActive = true,
|
isActive = true,
|
||||||
dateSet = null,
|
dateSet = null,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T11:00:00",
|
createdAt = "2024-01-01T11:00:00",
|
||||||
updatedAt = "2024-01-01T11:00:00"
|
updatedAt = "2024-01-01T11:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val serverSessions =
|
val serverSessions =
|
||||||
listOf(
|
listOf(
|
||||||
// Unique server session
|
// Unique server session
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "session2",
|
id = "session2",
|
||||||
gymId = "gym2",
|
gymId = "gym2",
|
||||||
date = "2024-01-02",
|
date = "2024-01-02",
|
||||||
startTime = "2024-01-02T14:00:00",
|
startTime = "2024-01-02T14:00:00",
|
||||||
endTime = "2024-01-02T16:00:00",
|
endTime = "2024-01-02T16:00:00",
|
||||||
duration = 7200,
|
duration = 7200,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = "Server session",
|
notes = "Server session",
|
||||||
createdAt = "2024-01-02T14:00:00",
|
createdAt = "2024-01-02T14:00:00",
|
||||||
updatedAt = "2024-01-02T14:00:00"
|
updatedAt = "2024-01-02T14:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val serverAttempts =
|
val serverAttempts =
|
||||||
listOf(
|
listOf(
|
||||||
// Unique server attempt
|
// Unique server attempt
|
||||||
BackupAttempt(
|
BackupAttempt(
|
||||||
id = "attempt2",
|
id = "attempt2",
|
||||||
sessionId = "session2",
|
sessionId = "session2",
|
||||||
problemId = "problem2",
|
problemId = "problem2",
|
||||||
result = AttemptResult.FALL,
|
result = AttemptResult.FALL,
|
||||||
highestHold = "Last move",
|
highestHold = "Last move",
|
||||||
notes = "Almost had it",
|
notes = "Almost had it",
|
||||||
duration = 180,
|
duration = 180,
|
||||||
restTime = 60,
|
restTime = 60,
|
||||||
timestamp = "2024-01-02T14:30:00",
|
timestamp = "2024-01-02T14:30:00",
|
||||||
createdAt = "2024-01-02T14:30:00",
|
createdAt = "2024-01-02T14:30:00",
|
||||||
updatedAt = "2024-01-02T14:30:00"
|
updatedAt = "2024-01-02T14:30:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val serverBackup =
|
val serverBackup =
|
||||||
ClimbDataBackup(
|
ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T12:00:00",
|
exportedAt = "2024-01-01T12:00:00",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms = serverGyms,
|
gyms = serverGyms,
|
||||||
problems = serverProblems,
|
problems = serverProblems,
|
||||||
sessions = serverSessions,
|
sessions = serverSessions,
|
||||||
attempts = serverAttempts
|
attempts = serverAttempts,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Simulate merge logic
|
// Simulate merge logic
|
||||||
val mergedBackup = performIntelligentMerge(localBackup, serverBackup)
|
val mergedBackup = performIntelligentMerge(localBackup, serverBackup)
|
||||||
@@ -231,12 +231,12 @@ class SyncMergeLogicTest {
|
|||||||
|
|
||||||
// Images should be merged (both local and server images preserved)
|
// Images should be merged (both local and server images preserved)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain local image",
|
"Should contain local image",
|
||||||
mergedProblem1.imagePaths!!.contains("local_image.jpg")
|
mergedProblem1.imagePaths!!.contains("local_image.jpg"),
|
||||||
)
|
)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain server image",
|
"Should contain server image",
|
||||||
mergedProblem1.imagePaths!!.contains("server_image.jpg")
|
mergedProblem1.imagePaths!!.contains("server_image.jpg"),
|
||||||
)
|
)
|
||||||
assertEquals("Should have 2 images total", 2, mergedProblem1.imagePaths!!.size)
|
assertEquals("Should have 2 images total", 2, mergedProblem1.imagePaths!!.size)
|
||||||
|
|
||||||
@@ -246,78 +246,78 @@ class SyncMergeLogicTest {
|
|||||||
|
|
||||||
// Verify all sessions are preserved
|
// Verify all sessions are preserved
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain local session",
|
"Should contain local session",
|
||||||
mergedBackup.sessions.any { it.id == "session1" }
|
mergedBackup.sessions.any { it.id == "session1" },
|
||||||
)
|
)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain server session",
|
"Should contain server session",
|
||||||
mergedBackup.sessions.any { it.id == "session2" }
|
mergedBackup.sessions.any { it.id == "session2" },
|
||||||
)
|
)
|
||||||
|
|
||||||
// Verify all attempts are preserved
|
// Verify all attempts are preserved
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain local attempt",
|
"Should contain local attempt",
|
||||||
mergedBackup.attempts.any { it.id == "attempt1" }
|
mergedBackup.attempts.any { it.id == "attempt1" },
|
||||||
)
|
)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain server attempt",
|
"Should contain server attempt",
|
||||||
mergedBackup.attempts.any { it.id == "attempt2" }
|
mergedBackup.attempts.any { it.id == "attempt2" },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test date comparison logic`() {
|
fun `test date comparison logic`() {
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"ISO instant should be newer",
|
"ISO instant should be newer",
|
||||||
isNewerThan("2024-01-01T12:00:00Z", "2024-01-01T10:00:00Z")
|
isNewerThan("2024-01-01T12:00:00Z", "2024-01-01T10:00:00Z"),
|
||||||
)
|
)
|
||||||
assertFalse(
|
assertFalse(
|
||||||
"ISO instant should be older",
|
"ISO instant should be older",
|
||||||
isNewerThan("2024-01-01T10:00:00Z", "2024-01-01T12:00:00Z")
|
isNewerThan("2024-01-01T10:00:00Z", "2024-01-01T12:00:00Z"),
|
||||||
)
|
)
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"String comparison should work as fallback",
|
"String comparison should work as fallback",
|
||||||
isNewerThan("2024-01-02T10:00:00", "2024-01-01T10:00:00")
|
isNewerThan("2024-01-02T10:00:00", "2024-01-01T10:00:00"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test empty data scenarios`() {
|
fun `test empty data scenarios`() {
|
||||||
val emptyBackup =
|
val emptyBackup =
|
||||||
ClimbDataBackup(
|
ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T10:00:00",
|
exportedAt = "2024-01-01T10:00:00",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms = emptyList(),
|
gyms = emptyList(),
|
||||||
problems = emptyList(),
|
problems = emptyList(),
|
||||||
sessions = emptyList(),
|
sessions = emptyList(),
|
||||||
attempts = emptyList()
|
attempts = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val dataBackup =
|
val dataBackup =
|
||||||
ClimbDataBackup(
|
ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T10:00:00",
|
exportedAt = "2024-01-01T10:00:00",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms =
|
gyms =
|
||||||
listOf(
|
listOf(
|
||||||
BackupGym(
|
BackupGym(
|
||||||
id = "gym1",
|
id = "gym1",
|
||||||
name = "Test Gym",
|
name = "Test Gym",
|
||||||
location = null,
|
location = null,
|
||||||
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
supportedClimbTypes = listOf(ClimbType.BOULDER),
|
||||||
difficultySystems =
|
difficultySystems =
|
||||||
listOf(DifficultySystem.V_SCALE),
|
listOf(DifficultySystem.V_SCALE),
|
||||||
customDifficultyGrades = emptyList(),
|
customDifficultyGrades = emptyList(),
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T10:00:00"
|
updatedAt = "2024-01-01T10:00:00",
|
||||||
)
|
),
|
||||||
),
|
),
|
||||||
problems = emptyList(),
|
problems = emptyList(),
|
||||||
sessions = emptyList(),
|
sessions = emptyList(),
|
||||||
attempts = emptyList()
|
attempts = emptyList(),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Test merging empty with data
|
// Test merging empty with data
|
||||||
val merged1 = performIntelligentMerge(emptyBackup, dataBackup)
|
val merged1 = performIntelligentMerge(emptyBackup, dataBackup)
|
||||||
@@ -334,8 +334,8 @@ class SyncMergeLogicTest {
|
|||||||
|
|
||||||
// Helper methods that simulate the merge logic from SyncService
|
// Helper methods that simulate the merge logic from SyncService
|
||||||
private fun performIntelligentMerge(
|
private fun performIntelligentMerge(
|
||||||
local: ClimbDataBackup,
|
local: ClimbDataBackup,
|
||||||
server: ClimbDataBackup
|
server: ClimbDataBackup,
|
||||||
): ClimbDataBackup {
|
): ClimbDataBackup {
|
||||||
val mergedGyms = mergeGyms(local.gyms, server.gyms)
|
val mergedGyms = mergeGyms(local.gyms, server.gyms)
|
||||||
val mergedProblems = mergeProblems(local.problems, server.problems)
|
val mergedProblems = mergeProblems(local.problems, server.problems)
|
||||||
@@ -343,13 +343,13 @@ class SyncMergeLogicTest {
|
|||||||
val mergedAttempts = mergeAttempts(local.attempts, server.attempts)
|
val mergedAttempts = mergeAttempts(local.attempts, server.attempts)
|
||||||
|
|
||||||
return ClimbDataBackup(
|
return ClimbDataBackup(
|
||||||
exportedAt = "2024-01-01T12:00:00",
|
exportedAt = "2024-01-01T12:00:00",
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
gyms = mergedGyms,
|
gyms = mergedGyms,
|
||||||
problems = mergedProblems,
|
problems = mergedProblems,
|
||||||
sessions = mergedSessions,
|
sessions = mergedSessions,
|
||||||
attempts = mergedAttempts
|
attempts = mergedAttempts,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -371,8 +371,8 @@ class SyncMergeLogicTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun mergeProblems(
|
private fun mergeProblems(
|
||||||
local: List<BackupProblem>,
|
local: List<BackupProblem>,
|
||||||
server: List<BackupProblem>
|
server: List<BackupProblem>,
|
||||||
): List<BackupProblem> {
|
): List<BackupProblem> {
|
||||||
val merged = mutableMapOf<String, BackupProblem>()
|
val merged = mutableMapOf<String, BackupProblem>()
|
||||||
|
|
||||||
@@ -390,7 +390,7 @@ class SyncMergeLogicTest {
|
|||||||
serverProblem.imagePaths?.let { allImagePaths.addAll(it) }
|
serverProblem.imagePaths?.let { allImagePaths.addAll(it) }
|
||||||
|
|
||||||
merged[serverProblem.id] =
|
merged[serverProblem.id] =
|
||||||
serverProblem.withUpdatedImagePaths(allImagePaths.toList())
|
serverProblem.withUpdatedImagePaths(allImagePaths.toList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -398,8 +398,8 @@ class SyncMergeLogicTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun mergeSessions(
|
private fun mergeSessions(
|
||||||
local: List<BackupClimbSession>,
|
local: List<BackupClimbSession>,
|
||||||
server: List<BackupClimbSession>
|
server: List<BackupClimbSession>,
|
||||||
): List<BackupClimbSession> {
|
): List<BackupClimbSession> {
|
||||||
val merged = mutableMapOf<String, BackupClimbSession>()
|
val merged = mutableMapOf<String, BackupClimbSession>()
|
||||||
|
|
||||||
@@ -419,8 +419,8 @@ class SyncMergeLogicTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun mergeAttempts(
|
private fun mergeAttempts(
|
||||||
local: List<BackupAttempt>,
|
local: List<BackupAttempt>,
|
||||||
server: List<BackupAttempt>
|
server: List<BackupAttempt>,
|
||||||
): List<BackupAttempt> {
|
): List<BackupAttempt> {
|
||||||
val merged = mutableMapOf<String, BackupAttempt>()
|
val merged = mutableMapOf<String, BackupAttempt>()
|
||||||
|
|
||||||
@@ -431,10 +431,10 @@ class SyncMergeLogicTest {
|
|||||||
server.forEach { serverAttempt ->
|
server.forEach { serverAttempt ->
|
||||||
val localAttempt = merged[serverAttempt.id]
|
val localAttempt = merged[serverAttempt.id]
|
||||||
if (localAttempt == null ||
|
if (localAttempt == null ||
|
||||||
isNewerThan(
|
isNewerThan(
|
||||||
serverAttempt.updatedAt ?: serverAttempt.createdAt,
|
serverAttempt.updatedAt ?: serverAttempt.createdAt,
|
||||||
localAttempt.updatedAt ?: localAttempt.createdAt
|
localAttempt.updatedAt ?: localAttempt.createdAt,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
merged[serverAttempt.id] = serverAttempt
|
merged[serverAttempt.id] = serverAttempt
|
||||||
}
|
}
|
||||||
@@ -458,32 +458,32 @@ class SyncMergeLogicTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `test active sessions excluded from sync`() {
|
fun `test active sessions excluded from sync`() {
|
||||||
val allLocalSessions =
|
val allLocalSessions =
|
||||||
listOf(
|
listOf(
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "active_session_1",
|
id = "active_session_1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
date = "2024-01-01",
|
date = "2024-01-01",
|
||||||
startTime = "2024-01-01T10:00:00",
|
startTime = "2024-01-01T10:00:00",
|
||||||
endTime = null,
|
endTime = null,
|
||||||
duration = null,
|
duration = null,
|
||||||
status = SessionStatus.ACTIVE,
|
status = SessionStatus.ACTIVE,
|
||||||
notes = null,
|
notes = null,
|
||||||
createdAt = "2024-01-01T10:00:00",
|
createdAt = "2024-01-01T10:00:00",
|
||||||
updatedAt = "2024-01-01T10:00:00"
|
updatedAt = "2024-01-01T10:00:00",
|
||||||
),
|
),
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
id = "completed_session_1",
|
id = "completed_session_1",
|
||||||
gymId = "gym1",
|
gymId = "gym1",
|
||||||
date = "2023-12-31",
|
date = "2023-12-31",
|
||||||
startTime = "2023-12-31T15:00:00",
|
startTime = "2023-12-31T15:00:00",
|
||||||
endTime = "2023-12-31T17:00:00",
|
endTime = "2023-12-31T17:00:00",
|
||||||
duration = 7200000,
|
duration = 7200000,
|
||||||
status = SessionStatus.COMPLETED,
|
status = SessionStatus.COMPLETED,
|
||||||
notes = "Previous session",
|
notes = "Previous session",
|
||||||
createdAt = "2023-12-31T15:00:00",
|
createdAt = "2023-12-31T15:00:00",
|
||||||
updatedAt = "2023-12-31T17:00:00"
|
updatedAt = "2023-12-31T17:00:00",
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
// Simulate filtering that would happen in createBackupFromRepository
|
// Simulate filtering that would happen in createBackupFromRepository
|
||||||
val sessionsForSync = allLocalSessions.filter { it.status != SessionStatus.ACTIVE }
|
val sessionsForSync = allLocalSessions.filter { it.status != SessionStatus.ACTIVE }
|
||||||
@@ -493,18 +493,18 @@ class SyncMergeLogicTest {
|
|||||||
|
|
||||||
// Active session should be excluded
|
// Active session should be excluded
|
||||||
assertFalse(
|
assertFalse(
|
||||||
"Should not contain active session in sync",
|
"Should not contain active session in sync",
|
||||||
sessionsForSync.any {
|
sessionsForSync.any {
|
||||||
it.id == "active_session_1" && it.status == SessionStatus.ACTIVE
|
it.id == "active_session_1" && it.status == SessionStatus.ACTIVE
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// Completed session should be included
|
// Completed session should be included
|
||||||
assertTrue(
|
assertTrue(
|
||||||
"Should contain completed session in sync",
|
"Should contain completed session in sync",
|
||||||
sessionsForSync.any {
|
sessionsForSync.any {
|
||||||
it.id == "completed_session_1" && it.status == SessionStatus.COMPLETED
|
it.id == "completed_session_1" && it.status == SessionStatus.COMPLETED
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.ascently
|
package com.atridad.ascently
|
||||||
|
|
||||||
|
import org.junit.Assert.*
|
||||||
|
import org.junit.Test
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import org.junit.Assert.*
|
|
||||||
import org.junit.Test
|
|
||||||
|
|
||||||
class UtilityTests {
|
class UtilityTests {
|
||||||
|
|
||||||
@@ -75,13 +75,13 @@ class UtilityTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testClimbingStatistics() {
|
fun testClimbingStatistics() {
|
||||||
val attempts =
|
val attempts =
|
||||||
listOf(
|
listOf(
|
||||||
AttemptData("SUCCESS", 120),
|
AttemptData("SUCCESS", 120),
|
||||||
AttemptData("FALL", 90),
|
AttemptData("FALL", 90),
|
||||||
AttemptData("SUCCESS", 150),
|
AttemptData("SUCCESS", 150),
|
||||||
AttemptData("FLASH", 60),
|
AttemptData("FLASH", 60),
|
||||||
AttemptData("FALL", 110)
|
AttemptData("FALL", 110),
|
||||||
)
|
)
|
||||||
|
|
||||||
val stats = calculateAttemptStatistics(attempts)
|
val stats = calculateAttemptStatistics(attempts)
|
||||||
|
|
||||||
@@ -163,23 +163,23 @@ class UtilityTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testSearchFiltering() {
|
fun testSearchFiltering() {
|
||||||
val problems =
|
val problems =
|
||||||
listOf(
|
listOf(
|
||||||
ProblemData(
|
ProblemData(
|
||||||
"id1",
|
"id1",
|
||||||
"Crimpy Problem",
|
"Crimpy Problem",
|
||||||
"BOULDER",
|
"BOULDER",
|
||||||
"V5",
|
"V5",
|
||||||
listOf("crimpy", "overhang")
|
listOf("crimpy", "overhang"),
|
||||||
),
|
),
|
||||||
ProblemData("id2", "Easy Route", "ROPE", "5.6", listOf("beginner", "slab")),
|
ProblemData("id2", "Easy Route", "ROPE", "5.6", listOf("beginner", "slab")),
|
||||||
ProblemData(
|
ProblemData(
|
||||||
"id3",
|
"id3",
|
||||||
"Hard Boulder",
|
"Hard Boulder",
|
||||||
"BOULDER",
|
"BOULDER",
|
||||||
"V10",
|
"V10",
|
||||||
listOf("powerful", "roof")
|
listOf("powerful", "roof"),
|
||||||
)
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
val boulderProblems = filterByClimbType(problems, "BOULDER")
|
val boulderProblems = filterByClimbType(problems, "BOULDER")
|
||||||
assertEquals(2, boulderProblems.size)
|
assertEquals(2, boulderProblems.size)
|
||||||
@@ -207,20 +207,20 @@ class UtilityTests {
|
|||||||
@Test
|
@Test
|
||||||
fun testBackupValidation() {
|
fun testBackupValidation() {
|
||||||
val validBackup =
|
val validBackup =
|
||||||
BackupData(
|
BackupData(
|
||||||
version = "2.0",
|
version = "2.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
exportedAt = "2024-01-01T10:00:00Z",
|
exportedAt = "2024-01-01T10:00:00Z",
|
||||||
dataCount = 5
|
dataCount = 5,
|
||||||
)
|
)
|
||||||
|
|
||||||
val invalidBackup =
|
val invalidBackup =
|
||||||
BackupData(
|
BackupData(
|
||||||
version = "1.0",
|
version = "1.0",
|
||||||
formatVersion = "2.0",
|
formatVersion = "2.0",
|
||||||
exportedAt = "invalid-date",
|
exportedAt = "invalid-date",
|
||||||
dataCount = -1
|
dataCount = -1,
|
||||||
)
|
)
|
||||||
|
|
||||||
assertTrue(isValidBackup(validBackup))
|
assertTrue(isValidBackup(validBackup))
|
||||||
assertFalse(isValidBackup(invalidBackup))
|
assertFalse(isValidBackup(invalidBackup))
|
||||||
@@ -258,10 +258,10 @@ class UtilityTests {
|
|||||||
val successRate = (successful.toDouble() / attempts.size) * 100
|
val successRate = (successful.toDouble() / attempts.size) * 100
|
||||||
|
|
||||||
return AttemptStatistics(
|
return AttemptStatistics(
|
||||||
totalAttempts = attempts.size,
|
totalAttempts = attempts.size,
|
||||||
successfulAttempts = successful,
|
successfulAttempts = successful,
|
||||||
successRate = successRate,
|
successRate = successRate,
|
||||||
averageDuration = avgDuration
|
averageDuration = avgDuration,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,8 +301,8 @@ class UtilityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun filterByClimbType(
|
private fun filterByClimbType(
|
||||||
problems: List<ProblemData>,
|
problems: List<ProblemData>,
|
||||||
climbType: String
|
climbType: String,
|
||||||
): List<ProblemData> {
|
): List<ProblemData> {
|
||||||
return problems.filter { it.climbType == climbType }
|
return problems.filter { it.climbType == climbType }
|
||||||
}
|
}
|
||||||
@@ -312,9 +312,9 @@ class UtilityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun filterByDifficultyRange(
|
private fun filterByDifficultyRange(
|
||||||
problems: List<ProblemData>,
|
problems: List<ProblemData>,
|
||||||
minGrade: String,
|
minGrade: String,
|
||||||
maxGrade: String
|
maxGrade: String,
|
||||||
): List<ProblemData> {
|
): List<ProblemData> {
|
||||||
return problems.filter { problem ->
|
return problems.filter { problem ->
|
||||||
if (problem.climbType == "BOULDER" && problem.difficulty.startsWith("V")) {
|
if (problem.climbType == "BOULDER" && problem.difficulty.startsWith("V")) {
|
||||||
@@ -329,17 +329,17 @@ class UtilityTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun mergeData(
|
private fun mergeData(
|
||||||
local: Map<String, String>,
|
local: Map<String, String>,
|
||||||
server: Map<String, String>
|
server: Map<String, String>,
|
||||||
): Map<String, String> {
|
): Map<String, String> {
|
||||||
return (local.keys + server.keys).associateWith { key -> server[key] ?: local[key]!! }
|
return (local.keys + server.keys).associateWith { key -> server[key] ?: local[key]!! }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isValidBackup(backup: BackupData): Boolean {
|
private fun isValidBackup(backup: BackupData): Boolean {
|
||||||
return backup.version == "2.0" &&
|
return backup.version == "2.0" &&
|
||||||
backup.formatVersion == "2.0" &&
|
backup.formatVersion == "2.0" &&
|
||||||
backup.exportedAt.matches(Regex("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z")) &&
|
backup.exportedAt.matches(Regex("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z")) &&
|
||||||
backup.dataCount >= 0
|
backup.dataCount >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data classes for testing
|
// Data classes for testing
|
||||||
@@ -347,24 +347,24 @@ class UtilityTests {
|
|||||||
data class AttemptData(val result: String, val duration: Int)
|
data class AttemptData(val result: String, val duration: Int)
|
||||||
|
|
||||||
data class AttemptStatistics(
|
data class AttemptStatistics(
|
||||||
val totalAttempts: Int,
|
val totalAttempts: Int,
|
||||||
val successfulAttempts: Int,
|
val successfulAttempts: Int,
|
||||||
val successRate: Double,
|
val successRate: Double,
|
||||||
val averageDuration: Double
|
val averageDuration: Double,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class ProblemData(
|
data class ProblemData(
|
||||||
val id: String,
|
val id: String,
|
||||||
val name: String,
|
val name: String,
|
||||||
val climbType: String,
|
val climbType: String,
|
||||||
val difficulty: String,
|
val difficulty: String,
|
||||||
val tags: List<String>
|
val tags: List<String>,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class BackupData(
|
data class BackupData(
|
||||||
val version: String,
|
val version: String,
|
||||||
val formatVersion: String,
|
val formatVersion: String,
|
||||||
val exportedAt: String,
|
val exportedAt: String,
|
||||||
val dataCount: Int
|
val dataCount: Int,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,6 @@ plugins {
|
|||||||
alias(libs.plugins.android.application) apply false
|
alias(libs.plugins.android.application) apply false
|
||||||
alias(libs.plugins.kotlin.android) apply false
|
alias(libs.plugins.kotlin.android) apply false
|
||||||
alias(libs.plugins.kotlin.compose) apply false
|
alias(libs.plugins.kotlin.compose) apply false
|
||||||
|
alias(libs.plugins.detekt) apply false
|
||||||
|
alias(libs.plugins.spotless) apply false
|
||||||
}
|
}
|
||||||
584
android/detekt.yml
Normal file
584
android/detekt.yml
Normal file
@@ -0,0 +1,584 @@
|
|||||||
|
build:
|
||||||
|
maxIssues: -1
|
||||||
|
excludeCorrectable: false
|
||||||
|
|
||||||
|
config:
|
||||||
|
validation: true
|
||||||
|
warningsAsErrors: false
|
||||||
|
|
||||||
|
processors:
|
||||||
|
active: true
|
||||||
|
exclude:
|
||||||
|
- 'DetektProgressListener'
|
||||||
|
|
||||||
|
console-reports:
|
||||||
|
active: true
|
||||||
|
|
||||||
|
output-reports:
|
||||||
|
active: true
|
||||||
|
exclude:
|
||||||
|
- 'TxtOutputReport'
|
||||||
|
|
||||||
|
complexity:
|
||||||
|
active: true
|
||||||
|
ComplexCondition:
|
||||||
|
active: true
|
||||||
|
threshold: 5
|
||||||
|
CyclomaticComplexMethod:
|
||||||
|
active: true
|
||||||
|
threshold: 50
|
||||||
|
ignoreSingleWhenExpression: true
|
||||||
|
ignoreSimpleWhenEntries: true
|
||||||
|
ignoreNestingFunctions: false
|
||||||
|
nestingFunctions:
|
||||||
|
- 'also'
|
||||||
|
- 'apply'
|
||||||
|
- 'let'
|
||||||
|
- 'run'
|
||||||
|
- 'with'
|
||||||
|
LabeledExpression:
|
||||||
|
active: false
|
||||||
|
LargeClass:
|
||||||
|
active: true
|
||||||
|
threshold: 800
|
||||||
|
LongMethod:
|
||||||
|
active: true
|
||||||
|
threshold: 120
|
||||||
|
ignoreAnnotated:
|
||||||
|
- 'Composable'
|
||||||
|
- 'Test'
|
||||||
|
LongParameterList:
|
||||||
|
active: true
|
||||||
|
functionThreshold: 15
|
||||||
|
constructorThreshold: 15
|
||||||
|
ignoreDefaultParameters: true
|
||||||
|
ignoreDataClasses: true
|
||||||
|
ignoreAnnotatedParameter:
|
||||||
|
- 'Composable'
|
||||||
|
MethodOverloading:
|
||||||
|
active: false
|
||||||
|
NamedArguments:
|
||||||
|
active: false
|
||||||
|
NestedBlockDepth:
|
||||||
|
active: true
|
||||||
|
threshold: 8
|
||||||
|
NestedScopeFunctions:
|
||||||
|
active: true
|
||||||
|
threshold: 2
|
||||||
|
functions:
|
||||||
|
- 'also'
|
||||||
|
- 'apply'
|
||||||
|
- 'let'
|
||||||
|
- 'run'
|
||||||
|
- 'with'
|
||||||
|
ReplaceSafeCallChainWithRun:
|
||||||
|
active: false
|
||||||
|
StringLiteralDuplication:
|
||||||
|
active: false
|
||||||
|
threshold: 4
|
||||||
|
ignoreAnnotation: true
|
||||||
|
excludeStringsWithLessThan5Characters: true
|
||||||
|
ignoreStringsRegex: '$^'
|
||||||
|
TooManyFunctions:
|
||||||
|
active: true
|
||||||
|
thresholdInFiles: 40
|
||||||
|
thresholdInClasses: 40
|
||||||
|
thresholdInInterfaces: 25
|
||||||
|
thresholdInObjects: 25
|
||||||
|
thresholdInEnums: 15
|
||||||
|
ignoreDeprecated: true
|
||||||
|
ignorePrivate: true
|
||||||
|
ignoreOverridden: true
|
||||||
|
|
||||||
|
coroutines:
|
||||||
|
active: true
|
||||||
|
GlobalCoroutineUsage:
|
||||||
|
active: true
|
||||||
|
InjectDispatcher:
|
||||||
|
active: true
|
||||||
|
dispatcherNames:
|
||||||
|
- 'IO'
|
||||||
|
- 'Default'
|
||||||
|
- 'Unconfined'
|
||||||
|
RedundantSuspendModifier:
|
||||||
|
active: true
|
||||||
|
SleepInsteadOfDelay:
|
||||||
|
active: true
|
||||||
|
SuspendFunSwallowedCancellation:
|
||||||
|
active: true
|
||||||
|
SuspendFunWithCoroutineScopeReceiver:
|
||||||
|
active: true
|
||||||
|
SuspendFunWithFlowReturnType:
|
||||||
|
active: true
|
||||||
|
|
||||||
|
empty-blocks:
|
||||||
|
active: true
|
||||||
|
EmptyCatchBlock:
|
||||||
|
active: true
|
||||||
|
allowedExceptionNameRegex: '_|(ignore|expected).*'
|
||||||
|
EmptyClassBlock:
|
||||||
|
active: true
|
||||||
|
EmptyDefaultConstructor:
|
||||||
|
active: true
|
||||||
|
EmptyDoWhileBlock:
|
||||||
|
active: true
|
||||||
|
EmptyElseBlock:
|
||||||
|
active: true
|
||||||
|
EmptyFinallyBlock:
|
||||||
|
active: true
|
||||||
|
EmptyForBlock:
|
||||||
|
active: true
|
||||||
|
EmptyFunctionBlock:
|
||||||
|
active: true
|
||||||
|
ignoreOverridden: true
|
||||||
|
EmptyIfBlock:
|
||||||
|
active: true
|
||||||
|
EmptyInitBlock:
|
||||||
|
active: true
|
||||||
|
EmptyKtFile:
|
||||||
|
active: true
|
||||||
|
EmptySecondaryConstructor:
|
||||||
|
active: true
|
||||||
|
EmptyTryBlock:
|
||||||
|
active: true
|
||||||
|
EmptyWhenBlock:
|
||||||
|
active: true
|
||||||
|
EmptyWhileBlock:
|
||||||
|
active: true
|
||||||
|
|
||||||
|
exceptions:
|
||||||
|
active: true
|
||||||
|
ExceptionRaisedInUnexpectedLocation:
|
||||||
|
active: true
|
||||||
|
methodNames:
|
||||||
|
- 'equals'
|
||||||
|
- 'finalize'
|
||||||
|
- 'hashCode'
|
||||||
|
- 'toString'
|
||||||
|
InstanceOfCheckForException:
|
||||||
|
active: true
|
||||||
|
NotImplementedDeclaration:
|
||||||
|
active: false
|
||||||
|
ObjectExtendsThrowable:
|
||||||
|
active: false
|
||||||
|
PrintStackTrace:
|
||||||
|
active: true
|
||||||
|
RethrowCaughtException:
|
||||||
|
active: true
|
||||||
|
ReturnFromFinally:
|
||||||
|
active: true
|
||||||
|
SwallowedException:
|
||||||
|
active: false
|
||||||
|
ignoredExceptionTypes:
|
||||||
|
- 'InterruptedException'
|
||||||
|
- 'MalformedURLException'
|
||||||
|
- 'NumberFormatException'
|
||||||
|
- 'ParseException'
|
||||||
|
allowedExceptionNameRegex: '_|(ignore|expected).*'
|
||||||
|
ThrowingExceptionFromFinally:
|
||||||
|
active: true
|
||||||
|
ThrowingExceptionInMain:
|
||||||
|
active: false
|
||||||
|
ThrowingExceptionsWithoutMessageOrCause:
|
||||||
|
active: true
|
||||||
|
excludes: ['**/test/**', '**/androidTest/**', '**/*.Test.kt', '**/*.Spec.kt', '**/*.Spek.kt']
|
||||||
|
exceptions:
|
||||||
|
- 'ArrayIndexOutOfBoundsException'
|
||||||
|
- 'Exception'
|
||||||
|
- 'IllegalArgumentException'
|
||||||
|
- 'IllegalMonitorStateException'
|
||||||
|
- 'IllegalStateException'
|
||||||
|
- 'IndexOutOfBoundsException'
|
||||||
|
- 'NullPointerException'
|
||||||
|
- 'RuntimeException'
|
||||||
|
- 'Throwable'
|
||||||
|
ThrowingNewInstanceOfSameException:
|
||||||
|
active: true
|
||||||
|
TooGenericExceptionCaught:
|
||||||
|
active: false
|
||||||
|
excludes: ['**/test/**', '**/androidTest/**', '**/*.Test.kt', '**/*.Spec.kt', '**/*.Spek.kt']
|
||||||
|
exceptionNames:
|
||||||
|
- 'ArrayIndexOutOfBoundsException'
|
||||||
|
- 'Error'
|
||||||
|
- 'Exception'
|
||||||
|
- 'IllegalMonitorStateException'
|
||||||
|
- 'IndexOutOfBoundsException'
|
||||||
|
- 'NullPointerException'
|
||||||
|
- 'RuntimeException'
|
||||||
|
- 'Throwable'
|
||||||
|
allowedExceptionNameRegex: '_|(ignore|expected).*'
|
||||||
|
TooGenericExceptionThrown:
|
||||||
|
active: false
|
||||||
|
exceptionNames:
|
||||||
|
- 'Error'
|
||||||
|
- 'Exception'
|
||||||
|
- 'RuntimeException'
|
||||||
|
- 'Throwable'
|
||||||
|
|
||||||
|
naming:
|
||||||
|
active: true
|
||||||
|
BooleanPropertyNaming:
|
||||||
|
active: true
|
||||||
|
allowedPattern: '^(is|has|are|should|can|will|does|did)'
|
||||||
|
ClassNaming:
|
||||||
|
active: true
|
||||||
|
classPattern: '[A-Z][a-zA-Z0-9]*'
|
||||||
|
ConstructorParameterNaming:
|
||||||
|
active: true
|
||||||
|
parameterPattern: '[a-z][A-Za-z0-9]*'
|
||||||
|
privateParameterPattern: '[a-z][A-Za-z0-9]*'
|
||||||
|
excludeClassPattern: '$^'
|
||||||
|
EnumNaming:
|
||||||
|
active: true
|
||||||
|
enumEntryPattern: '[A-Z][_a-zA-Z0-9]*'
|
||||||
|
ForbiddenClassName:
|
||||||
|
active: false
|
||||||
|
FunctionMaxLength:
|
||||||
|
active: false
|
||||||
|
FunctionMinLength:
|
||||||
|
active: false
|
||||||
|
FunctionNaming:
|
||||||
|
active: true
|
||||||
|
functionPattern: '[a-zA-Z][a-zA-Z0-9]*'
|
||||||
|
excludeClassPattern: '$^'
|
||||||
|
ignoreAnnotated:
|
||||||
|
- 'Composable'
|
||||||
|
FunctionParameterNaming:
|
||||||
|
active: true
|
||||||
|
parameterPattern: '[a-z][A-Za-z0-9]*'
|
||||||
|
excludeClassPattern: '$^'
|
||||||
|
InvalidPackageDeclaration:
|
||||||
|
active: true
|
||||||
|
rootPackage: 'com.atridad.ascently'
|
||||||
|
LambdaParameterNaming:
|
||||||
|
active: true
|
||||||
|
parameterPattern: '[a-z][A-Za-z0-9]*|_'
|
||||||
|
MatchingDeclarationName:
|
||||||
|
active: false
|
||||||
|
mustBeFirst: true
|
||||||
|
MemberNameEqualsClassName:
|
||||||
|
active: true
|
||||||
|
ignoreOverridden: true
|
||||||
|
NoNameShadowing:
|
||||||
|
active: true
|
||||||
|
NonBooleanPropertyPrefixedWithIs:
|
||||||
|
active: true
|
||||||
|
ObjectPropertyNaming:
|
||||||
|
active: false
|
||||||
|
PackageNaming:
|
||||||
|
active: true
|
||||||
|
packagePattern: '[a-z]+(\.[a-z][A-Za-z0-9]*)*'
|
||||||
|
TopLevelPropertyNaming:
|
||||||
|
active: true
|
||||||
|
constantPattern: '[A-Z][_A-Z0-9]*'
|
||||||
|
propertyPattern: '[A-Za-z][_A-Za-z0-9]*'
|
||||||
|
privatePropertyPattern: '_?[A-Za-z][A-Za-z0-9]*'
|
||||||
|
VariableMaxLength:
|
||||||
|
active: false
|
||||||
|
VariableMinLength:
|
||||||
|
active: false
|
||||||
|
VariableNaming:
|
||||||
|
active: true
|
||||||
|
variablePattern: '[a-z][A-Za-z0-9]*'
|
||||||
|
privateVariablePattern: '[_a-z][A-Za-z0-9]*'
|
||||||
|
excludeClassPattern: '$^'
|
||||||
|
|
||||||
|
performance:
|
||||||
|
active: true
|
||||||
|
ArrayPrimitive:
|
||||||
|
active: true
|
||||||
|
CouldBeSequence:
|
||||||
|
active: false
|
||||||
|
ForEachOnRange:
|
||||||
|
active: true
|
||||||
|
SpreadOperator:
|
||||||
|
active: false
|
||||||
|
UnnecessaryPartOfBinaryExpression:
|
||||||
|
active: true
|
||||||
|
UnnecessaryTemporaryInstantiation:
|
||||||
|
active: true
|
||||||
|
|
||||||
|
potential-bugs:
|
||||||
|
active: true
|
||||||
|
AvoidReferentialEquality:
|
||||||
|
active: true
|
||||||
|
CastNullableToNonNullableType:
|
||||||
|
active: true
|
||||||
|
CastToNullableType:
|
||||||
|
active: false
|
||||||
|
Deprecation:
|
||||||
|
active: false
|
||||||
|
DontDowncastCollectionTypes:
|
||||||
|
active: true
|
||||||
|
DoubleMutabilityForCollection:
|
||||||
|
active: true
|
||||||
|
ElseCaseInsteadOfExhaustiveWhen:
|
||||||
|
active: false
|
||||||
|
EqualsAlwaysReturnsTrueOrFalse:
|
||||||
|
active: true
|
||||||
|
EqualsWithHashCodeExist:
|
||||||
|
active: true
|
||||||
|
ExitOutsideMain:
|
||||||
|
active: false
|
||||||
|
ExplicitGarbageCollectionCall:
|
||||||
|
active: true
|
||||||
|
HasPlatformType:
|
||||||
|
active: true
|
||||||
|
IgnoredReturnValue:
|
||||||
|
active: true
|
||||||
|
ImplicitDefaultLocale:
|
||||||
|
active: true
|
||||||
|
ImplicitUnitReturnType:
|
||||||
|
active: true
|
||||||
|
allowExplicitReturnType: true
|
||||||
|
InvalidRange:
|
||||||
|
active: true
|
||||||
|
IteratorHasNextCallsNextMethod:
|
||||||
|
active: true
|
||||||
|
IteratorNotThrowingNoSuchElementException:
|
||||||
|
active: true
|
||||||
|
LateinitUsage:
|
||||||
|
active: false
|
||||||
|
MapGetWithNotNullAssertionOperator:
|
||||||
|
active: true
|
||||||
|
MissingPackageDeclaration:
|
||||||
|
active: true
|
||||||
|
NullCheckOnMutableProperty:
|
||||||
|
active: true
|
||||||
|
NullableToStringCall:
|
||||||
|
active: true
|
||||||
|
PropertyUsedBeforeDeclaration:
|
||||||
|
active: false
|
||||||
|
UnconditionalJumpStatementInLoop:
|
||||||
|
active: true
|
||||||
|
UnnecessaryNotNullCheck:
|
||||||
|
active: true
|
||||||
|
UnnecessaryNotNullOperator:
|
||||||
|
active: true
|
||||||
|
UnnecessarySafeCall:
|
||||||
|
active: true
|
||||||
|
UnreachableCatchBlock:
|
||||||
|
active: true
|
||||||
|
UnreachableCode:
|
||||||
|
active: true
|
||||||
|
UnsafeCallOnNullableType:
|
||||||
|
active: true
|
||||||
|
UnsafeCast:
|
||||||
|
active: true
|
||||||
|
UnusedUnaryOperator:
|
||||||
|
active: true
|
||||||
|
UselessPostfixExpression:
|
||||||
|
active: true
|
||||||
|
WrongEqualsTypeParameter:
|
||||||
|
active: true
|
||||||
|
|
||||||
|
style:
|
||||||
|
active: true
|
||||||
|
AlsoCouldBeApply:
|
||||||
|
active: false
|
||||||
|
BracesOnIfStatements:
|
||||||
|
active: false
|
||||||
|
singleLine: 'never'
|
||||||
|
multiLine: 'always'
|
||||||
|
BracesOnWhenStatements:
|
||||||
|
active: false
|
||||||
|
singleLine: 'necessary'
|
||||||
|
multiLine: 'necessary'
|
||||||
|
CanBeNonNullable:
|
||||||
|
active: true
|
||||||
|
CascadingCallWrapping:
|
||||||
|
active: false
|
||||||
|
ClassOrdering:
|
||||||
|
active: false
|
||||||
|
CollapsibleIfStatements:
|
||||||
|
active: false
|
||||||
|
DataClassContainsFunctions:
|
||||||
|
active: false
|
||||||
|
DataClassShouldBeImmutable:
|
||||||
|
active: true
|
||||||
|
DestructuringDeclarationWithTooManyEntries:
|
||||||
|
active: true
|
||||||
|
maxDestructuringEntries: 5
|
||||||
|
EqualsNullCall:
|
||||||
|
active: true
|
||||||
|
EqualsOnSignatureLine:
|
||||||
|
active: true
|
||||||
|
ExplicitCollectionElementAccessMethod:
|
||||||
|
active: true
|
||||||
|
ExplicitItLambdaParameter:
|
||||||
|
active: false
|
||||||
|
ExpressionBodySyntax:
|
||||||
|
active: false
|
||||||
|
includeLineWrapping: false
|
||||||
|
ForbiddenAnnotation:
|
||||||
|
active: false
|
||||||
|
ForbiddenComment:
|
||||||
|
active: false
|
||||||
|
ForbiddenImport:
|
||||||
|
active: false
|
||||||
|
ForbiddenMethodCall:
|
||||||
|
active: false
|
||||||
|
ForbiddenSuppress:
|
||||||
|
active: false
|
||||||
|
ForbiddenVoid:
|
||||||
|
active: true
|
||||||
|
ignoreOverridden: true
|
||||||
|
ignoreUsageInGenerics: true
|
||||||
|
FunctionOnlyReturningConstant:
|
||||||
|
active: false
|
||||||
|
ignoreOverridableFunction: true
|
||||||
|
ignoreActualFunction: true
|
||||||
|
excludedFunctions: []
|
||||||
|
LoopWithTooManyJumpStatements:
|
||||||
|
active: true
|
||||||
|
maxJumpCount: 2
|
||||||
|
MagicNumber:
|
||||||
|
active: false
|
||||||
|
MandatoryBracesLoops:
|
||||||
|
active: true
|
||||||
|
MaxChainedCallsOnSameLine:
|
||||||
|
active: true
|
||||||
|
maxChainedCalls: 5
|
||||||
|
MaxLineLength:
|
||||||
|
active: true
|
||||||
|
maxLineLength: 220
|
||||||
|
excludePackageStatements: true
|
||||||
|
excludeImportStatements: true
|
||||||
|
excludeCommentStatements: true
|
||||||
|
excludeRawStrings: true
|
||||||
|
MayBeConst:
|
||||||
|
active: true
|
||||||
|
ModifierOrder:
|
||||||
|
active: true
|
||||||
|
MultilineRawStringIndentation:
|
||||||
|
active: false
|
||||||
|
indentSize: 4
|
||||||
|
MultilineLambdaItParameter:
|
||||||
|
active: true
|
||||||
|
NestedClassesVisibility:
|
||||||
|
active: true
|
||||||
|
NewLineAtEndOfFile:
|
||||||
|
active: false
|
||||||
|
NoTabs:
|
||||||
|
active: true
|
||||||
|
NullableBooleanCheck:
|
||||||
|
active: true
|
||||||
|
ObjectLiteralToLambda:
|
||||||
|
active: true
|
||||||
|
OptionalAbstractKeyword:
|
||||||
|
active: true
|
||||||
|
OptionalUnit:
|
||||||
|
active: true
|
||||||
|
PreferToOverPairSyntax:
|
||||||
|
active: true
|
||||||
|
ProtectedMemberInFinalClass:
|
||||||
|
active: true
|
||||||
|
RedundantExplicitType:
|
||||||
|
active: true
|
||||||
|
RedundantHigherOrderMapUsage:
|
||||||
|
active: true
|
||||||
|
RedundantVisibilityModifierRule:
|
||||||
|
active: false
|
||||||
|
ReturnCount:
|
||||||
|
active: true
|
||||||
|
max: 6
|
||||||
|
excludedFunctions:
|
||||||
|
- 'equals'
|
||||||
|
excludeLabeled: true
|
||||||
|
excludeReturnFromLambda: true
|
||||||
|
excludeGuardClauses: true
|
||||||
|
SafeCast:
|
||||||
|
active: true
|
||||||
|
SerialVersionUIDInSerializableClass:
|
||||||
|
active: false
|
||||||
|
SpacingBetweenPackageAndImports:
|
||||||
|
active: true
|
||||||
|
StringShouldBeRawString:
|
||||||
|
active: false
|
||||||
|
ThrowsCount:
|
||||||
|
active: true
|
||||||
|
max: 10
|
||||||
|
excludeGuardClauses: true
|
||||||
|
TrailingWhitespace:
|
||||||
|
active: false
|
||||||
|
TrimMultilineRawString:
|
||||||
|
active: true
|
||||||
|
UnderscoresInNumericLiterals:
|
||||||
|
active: false
|
||||||
|
acceptableLength: 4
|
||||||
|
allowNonStandardGrouping: false
|
||||||
|
UnnecessaryAbstractClass:
|
||||||
|
active: true
|
||||||
|
UnnecessaryAnnotationUseSiteTarget:
|
||||||
|
active: true
|
||||||
|
UnnecessaryApply:
|
||||||
|
active: true
|
||||||
|
UnnecessaryBackticks:
|
||||||
|
active: true
|
||||||
|
UnnecessaryBracesAroundTrailingLambda:
|
||||||
|
active: true
|
||||||
|
UnnecessaryFilter:
|
||||||
|
active: true
|
||||||
|
UnnecessaryInheritance:
|
||||||
|
active: true
|
||||||
|
UnnecessaryInnerClass:
|
||||||
|
active: true
|
||||||
|
UnnecessaryLet:
|
||||||
|
active: true
|
||||||
|
UnnecessaryParentheses:
|
||||||
|
active: false
|
||||||
|
allowForUnclearPrecedence: true
|
||||||
|
UntilInsteadOfRangeTo:
|
||||||
|
active: true
|
||||||
|
UnusedImports:
|
||||||
|
active: true
|
||||||
|
UnusedParameter:
|
||||||
|
active: true
|
||||||
|
allowedNames: 'ignored|expected|_|session|startTime|endTime|xAxisFormatter'
|
||||||
|
UnusedPrivateClass:
|
||||||
|
active: true
|
||||||
|
UnusedPrivateMember:
|
||||||
|
active: true
|
||||||
|
allowedNames: '(_|ignored|expected|serialVersionUID)'
|
||||||
|
UnusedPrivateProperty:
|
||||||
|
active: true
|
||||||
|
allowedNames: '_|ignored|expected|serialVersionUID'
|
||||||
|
UseAnyOrNoneInsteadOfFind:
|
||||||
|
active: true
|
||||||
|
UseArrayLiteralsInAnnotations:
|
||||||
|
active: true
|
||||||
|
UseCheckNotNull:
|
||||||
|
active: true
|
||||||
|
UseCheckOrError:
|
||||||
|
active: true
|
||||||
|
UseDataClass:
|
||||||
|
active: false
|
||||||
|
UseEmptyCounterpart:
|
||||||
|
active: true
|
||||||
|
UseIfEmptyOrIfBlank:
|
||||||
|
active: true
|
||||||
|
UseIfInsteadOfWhen:
|
||||||
|
active: false
|
||||||
|
UseIsNullOrEmpty:
|
||||||
|
active: true
|
||||||
|
UseLet:
|
||||||
|
active: false
|
||||||
|
UseOrEmpty:
|
||||||
|
active: true
|
||||||
|
UseRequire:
|
||||||
|
active: true
|
||||||
|
UseRequireNotNull:
|
||||||
|
active: true
|
||||||
|
UseSumOfInsteadOfFlatMapSize:
|
||||||
|
active: true
|
||||||
|
UselessCallOnNotNull:
|
||||||
|
active: true
|
||||||
|
UtilityClassWithPublicConstructor:
|
||||||
|
active: true
|
||||||
|
VarCouldBeVal:
|
||||||
|
active: true
|
||||||
|
WildcardImport:
|
||||||
|
active: false
|
||||||
|
excludeImports:
|
||||||
|
- 'java.util.*'
|
||||||
|
- 'kotlinx.android.synthetic.*'
|
||||||
@@ -10,7 +10,11 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
|
|||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. For more details, visit
|
# This option should only be used with decoupled projects. For more details, visit
|
||||||
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
|
# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
|
||||||
# org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
# Enable Gradle build caching for faster incremental builds
|
||||||
|
org.gradle.caching=true
|
||||||
|
# Enable configuration caching for faster configuration phase
|
||||||
|
org.gradle.configuration-cache=true
|
||||||
# AndroidX package structure to make it clearer which packages are bundled with the
|
# AndroidX package structure to make it clearer which packages are bundled with the
|
||||||
# Android operating system, and which are packaged with your app's APK
|
# Android operating system, and which are packaged with your app's APK
|
||||||
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
# https://developer.android.com/topic/libraries/support-library/androidx-rn
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ kotlinxCoroutines = "1.10.2"
|
|||||||
coil = "2.7.0"
|
coil = "2.7.0"
|
||||||
ksp = "2.2.20-2.0.3"
|
ksp = "2.2.20-2.0.3"
|
||||||
exifinterface = "1.4.1"
|
exifinterface = "1.4.1"
|
||||||
|
healthConnect = "1.1.0-alpha07"
|
||||||
|
detekt = "1.23.7"
|
||||||
|
spotless = "6.25.0"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
@@ -69,9 +72,14 @@ mockk = { group = "io.mockk", name = "mockk", version = "1.14.6" }
|
|||||||
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
||||||
androidx-exifinterface = { group = "androidx.exifinterface", name = "exifinterface", version.ref = "exifinterface" }
|
androidx-exifinterface = { group = "androidx.exifinterface", name = "exifinterface", version.ref = "exifinterface" }
|
||||||
|
|
||||||
|
# Health Connect
|
||||||
|
health-connect = { group = "androidx.health.connect", name = "connect-client", version.ref = "healthConnect" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
||||||
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
|
||||||
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
|
||||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||||
|
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
|
||||||
|
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
|
||||||
|
|||||||
22
ios/.editorconfig
Normal file
22
ios/.editorconfig
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 4
|
||||||
|
end_of_line = lf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
|
|
||||||
|
[*.swift]
|
||||||
|
indent_size = 4
|
||||||
|
max_line_length = 140
|
||||||
|
|
||||||
|
[*.{plist,storyboard,xib,xcscheme,xcworkspacedata}]
|
||||||
|
indent_size = 2
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[Makefile]
|
||||||
|
indent_style = tab
|
||||||
68
ios/.swiftformat
Normal file
68
ios/.swiftformat
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
# SwiftFormat Configuration for Ascently iOS
|
||||||
|
# Maintains consistent formatting across the project
|
||||||
|
|
||||||
|
# File options
|
||||||
|
--exclude build,Pods,DerivedData,.build
|
||||||
|
|
||||||
|
# Format options
|
||||||
|
--swiftversion 6.0
|
||||||
|
--indent 4
|
||||||
|
--tabwidth 4
|
||||||
|
--maxwidth 140
|
||||||
|
--wraparguments before-first
|
||||||
|
--wrapparameters before-first
|
||||||
|
--wrapcollections before-first
|
||||||
|
--wrapconditions after-first
|
||||||
|
--wrapreturntype preserve
|
||||||
|
--wrapeffects preserve
|
||||||
|
--closingparen balanced
|
||||||
|
--funcattributes prev-line
|
||||||
|
--typeattributes prev-line
|
||||||
|
--varattributes preserve
|
||||||
|
--storedvarattrs same-line
|
||||||
|
--computedvarattrs preserve
|
||||||
|
--complexattributes prev-line
|
||||||
|
--typeblanklines preserve
|
||||||
|
--structthreshold 20
|
||||||
|
--enumthreshold 20
|
||||||
|
--extensionacl on-declarations
|
||||||
|
--organizetypes class,struct,enum,extension,protocol
|
||||||
|
--modifierorder acl,setteracl,override,static,final,required,convenience,lazy,dynamic
|
||||||
|
--self remove
|
||||||
|
--importgrouping alpha
|
||||||
|
--semicolons inline
|
||||||
|
--operatorfunc spaced
|
||||||
|
--nospaceoperators ..<,...
|
||||||
|
--ranges no-space
|
||||||
|
--emptybraces no-space
|
||||||
|
--trimwhitespace always
|
||||||
|
--stripunusedargs closure-only
|
||||||
|
--header ignore
|
||||||
|
--guardelse auto
|
||||||
|
--elseposition same-line
|
||||||
|
--shortoptionals always
|
||||||
|
--linebreaks lf
|
||||||
|
--xcodeindentation disabled
|
||||||
|
--fragment false
|
||||||
|
--conflictmarkers reject
|
||||||
|
--ifdef no-indent
|
||||||
|
--extensionlength 0
|
||||||
|
|
||||||
|
# Enable rules
|
||||||
|
--enable isEmpty,sortedSwitchCases,redundantInit,redundantGet,redundantObjc
|
||||||
|
--enable blankLineAfterSwitchCase,consecutiveSpaces,duplicateImports
|
||||||
|
--enable elseOnSameLine,emptyBraces,hoistAwait,hoistPatternLet,hoistTry
|
||||||
|
--enable leadingDelimiters,redundantBackticks,redundantBreak,redundantClosure
|
||||||
|
--enable redundantExtensionACL,redundantFileprivate,redundantLetError
|
||||||
|
--enable redundantNilInit,redundantParens,redundantPattern,redundantRawValues
|
||||||
|
--enable redundantReturn,redundantSelf,redundantType,redundantVoidReturnType
|
||||||
|
--enable semicolons,sortImports,spaceAroundBraces,spaceAroundBrackets
|
||||||
|
--enable spaceAroundComments,spaceAroundGenerics,spaceAroundOperators
|
||||||
|
--enable spaceAroundParens,spaceInsideBraces,spaceInsideBrackets
|
||||||
|
--enable spaceInsideComments,spaceInsideGenerics,spaceInsideParens
|
||||||
|
--enable strongOutlets,strongifiedSelf,todos,trailingClosures,trailingCommas
|
||||||
|
--enable typeSugar,unusedArguments,void,wrapArguments,wrapAttributes
|
||||||
|
--enable yodaConditions,blankLinesBetweenScopes,blankLinesAtEndOfScope
|
||||||
|
|
||||||
|
# Disable rules
|
||||||
|
--disable wrapMultilineStatementBraces
|
||||||
139
ios/.swiftlint.yml
Normal file
139
ios/.swiftlint.yml
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
excluded:
|
||||||
|
- build
|
||||||
|
- Pods
|
||||||
|
- DerivedData
|
||||||
|
- .build
|
||||||
|
- AscentlyTests
|
||||||
|
|
||||||
|
disabled_rules:
|
||||||
|
- trailing_whitespace
|
||||||
|
- todo
|
||||||
|
- nesting
|
||||||
|
- opening_brace
|
||||||
|
- multiple_closures_with_trailing_closure
|
||||||
|
- trailing_comma
|
||||||
|
- attributes
|
||||||
|
- function_parameter_count
|
||||||
|
- large_tuple
|
||||||
|
|
||||||
|
opt_in_rules:
|
||||||
|
- empty_count
|
||||||
|
- explicit_init
|
||||||
|
- closure_spacing
|
||||||
|
- overridden_super_call
|
||||||
|
- redundant_nil_coalescing
|
||||||
|
- first_where
|
||||||
|
- sorted_first_last
|
||||||
|
- contains_over_filter_count
|
||||||
|
- contains_over_filter_is_empty
|
||||||
|
- empty_string
|
||||||
|
- prefer_zero_over_explicit_init
|
||||||
|
- flatmap_over_map_reduce
|
||||||
|
- last_where
|
||||||
|
- sorted_imports
|
||||||
|
- toggle_bool
|
||||||
|
- unavailable_function
|
||||||
|
- unneeded_parentheses_in_closure_argument
|
||||||
|
- vertical_whitespace_closing_braces
|
||||||
|
- yoda_condition
|
||||||
|
- collection_alignment
|
||||||
|
- literal_expression_end_indentation
|
||||||
|
|
||||||
|
line_length:
|
||||||
|
warning: 140
|
||||||
|
error: 250
|
||||||
|
ignores_comments: true
|
||||||
|
ignores_urls: true
|
||||||
|
ignores_function_declarations: true
|
||||||
|
ignores_interpolated_strings: true
|
||||||
|
|
||||||
|
type_body_length:
|
||||||
|
warning: 600
|
||||||
|
error: 1000
|
||||||
|
|
||||||
|
file_length:
|
||||||
|
warning: 1000
|
||||||
|
error: 1500
|
||||||
|
ignore_comment_only_lines: true
|
||||||
|
|
||||||
|
function_body_length:
|
||||||
|
warning: 100
|
||||||
|
error: 200
|
||||||
|
|
||||||
|
cyclomatic_complexity:
|
||||||
|
warning: 20
|
||||||
|
error: 30
|
||||||
|
ignores_case_statements: true
|
||||||
|
|
||||||
|
identifier_name:
|
||||||
|
min_length:
|
||||||
|
warning: 2
|
||||||
|
error: 1
|
||||||
|
max_length:
|
||||||
|
warning: 50
|
||||||
|
error: 60
|
||||||
|
validates_start_with_lowercase: error
|
||||||
|
allowed_symbols:
|
||||||
|
- _
|
||||||
|
excluded:
|
||||||
|
- id
|
||||||
|
- i
|
||||||
|
- j
|
||||||
|
- x
|
||||||
|
- y
|
||||||
|
- z
|
||||||
|
- to
|
||||||
|
- at
|
||||||
|
- or
|
||||||
|
- is
|
||||||
|
- no
|
||||||
|
- go
|
||||||
|
- db
|
||||||
|
- DATA_JSON_FILENAME
|
||||||
|
- IMAGES_DIR_NAME
|
||||||
|
- METADATA_FILENAME
|
||||||
|
# ViewBuilder section functions (SwiftUI convention)
|
||||||
|
- StatusSection
|
||||||
|
- IconDisplaySection
|
||||||
|
- DebugSection
|
||||||
|
- TestingSection
|
||||||
|
- ResultsSection
|
||||||
|
- GymSelectionSection
|
||||||
|
- SessionDetailsSection
|
||||||
|
- ProblemSelectionSection
|
||||||
|
- CreateProblemSection
|
||||||
|
- AttemptDetailsSection
|
||||||
|
- BasicInfoSection
|
||||||
|
- ClimbTypesSection
|
||||||
|
- DifficultySystemsSection
|
||||||
|
- NotesSection
|
||||||
|
- ClimbTypeSection
|
||||||
|
- DifficultySection
|
||||||
|
- LocationSection
|
||||||
|
- TagsSection
|
||||||
|
- PhotosSection
|
||||||
|
- AdditionalInfoSection
|
||||||
|
|
||||||
|
type_name:
|
||||||
|
min_length:
|
||||||
|
warning: 3
|
||||||
|
error: 2
|
||||||
|
max_length:
|
||||||
|
warning: 50
|
||||||
|
error: 60
|
||||||
|
|
||||||
|
force_cast: warning
|
||||||
|
|
||||||
|
force_try: warning
|
||||||
|
|
||||||
|
large_tuple:
|
||||||
|
warning: 4
|
||||||
|
error: 6
|
||||||
|
|
||||||
|
nesting:
|
||||||
|
type_level:
|
||||||
|
warning: 3
|
||||||
|
function_level:
|
||||||
|
warning: 5
|
||||||
|
|
||||||
|
reporter: "xcode"
|
||||||
@@ -465,7 +465,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = Ascently/Ascently.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Ascently/Ascently.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 38;
|
CURRENT_PROJECT_VERSION = 39;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
DRIVERKIT_DEPLOYMENT_TARGET = 24.6;
|
DRIVERKIT_DEPLOYMENT_TARGET = 24.6;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -487,7 +487,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
||||||
MARKETING_VERSION = 2.5.1;
|
MARKETING_VERSION = 2.5.2;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@@ -513,7 +513,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = Ascently/Ascently.entitlements;
|
CODE_SIGN_ENTITLEMENTS = Ascently/Ascently.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 38;
|
CURRENT_PROJECT_VERSION = 39;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
DRIVERKIT_DEPLOYMENT_TARGET = 24.6;
|
DRIVERKIT_DEPLOYMENT_TARGET = 24.6;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
@@ -535,7 +535,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
MACOSX_DEPLOYMENT_TARGET = 15.6;
|
||||||
MARKETING_VERSION = 2.5.1;
|
MARKETING_VERSION = 2.5.2;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@@ -602,7 +602,7 @@
|
|||||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||||
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 38;
|
CURRENT_PROJECT_VERSION = 39;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
@@ -613,7 +613,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.5.1;
|
MARKETING_VERSION = 2.5.2;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently.SessionStatusLive;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently.SessionStatusLive;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
@@ -632,7 +632,7 @@
|
|||||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||||
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 38;
|
CURRENT_PROJECT_VERSION = 39;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
@@ -643,7 +643,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 2.5.1;
|
MARKETING_VERSION = 2.5.2;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently.SessionStatusLive;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.Ascently.SessionStatusLive;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
|
|||||||
Binary file not shown.
@@ -45,7 +45,7 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
.environmentObject(dataManager)
|
.environmentObject(dataManager)
|
||||||
.environmentObject(MusicService.shared)
|
.environmentObject(MusicService.shared)
|
||||||
.onChange(of: scenePhase) { oldPhase, newPhase in
|
.onChange(of: scenePhase) { _, newPhase in
|
||||||
if newPhase == .active {
|
if newPhase == .active {
|
||||||
// Add slight delay to ensure app is fully loaded
|
// Add slight delay to ensure app is fully loaded
|
||||||
Task {
|
Task {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import MusicKit
|
|
||||||
import AVFoundation
|
import AVFoundation
|
||||||
import SwiftUI
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import MusicKit
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
class MusicService: ObservableObject {
|
class MusicService: ObservableObject {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import Foundation
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import Foundation
|
||||||
|
|
||||||
class ServerSyncProvider: SyncProvider {
|
class ServerSyncProvider: SyncProvider {
|
||||||
var type: SyncProviderType { .server }
|
var type: SyncProviderType { .server }
|
||||||
@@ -235,7 +235,7 @@ class ServerSyncProvider: SyncProvider {
|
|||||||
}.map { problem -> BackupProblem in
|
}.map { problem -> BackupProblem in
|
||||||
let backupProblem = BackupProblem(from: problem)
|
let backupProblem = BackupProblem(from: problem)
|
||||||
if !problem.imagePaths.isEmpty {
|
if !problem.imagePaths.isEmpty {
|
||||||
let normalizedPaths = problem.imagePaths.enumerated().map { index, _ in
|
let normalizedPaths = problem.imagePaths.indices.map { index in
|
||||||
ImageNamingUtils.generateImageFilename(
|
ImageNamingUtils.generateImageFilename(
|
||||||
problemId: problem.id.uuidString, imageIndex: index)
|
problemId: problem.id.uuidString, imageIndex: index)
|
||||||
}
|
}
|
||||||
@@ -859,7 +859,6 @@ class ServerSyncProvider: SyncProvider {
|
|||||||
attempts: filteredAttempts,
|
attempts: filteredAttempts,
|
||||||
deletedItems: backup.deletedItems
|
deletedItems: backup.deletedItems
|
||||||
)
|
)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Filter out deleted items even when no image path mapping
|
// Filter out deleted items even when no image path mapping
|
||||||
let deletedGymIds = Set(
|
let deletedGymIds = Set(
|
||||||
@@ -930,7 +929,6 @@ class ServerSyncProvider: SyncProvider {
|
|||||||
// Update local data state to match imported data timestamp
|
// Update local data state to match imported data timestamp
|
||||||
DataStateManager.shared.setLastModified(backup.exportedAt)
|
DataStateManager.shared.setLastModified(backup.exportedAt)
|
||||||
AppLogger.info("Data state synchronized to imported timestamp: \(backup.exportedAt)", tag: logTag)
|
AppLogger.info("Data state synchronized to imported timestamp: \(backup.exportedAt)", tag: logTag)
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
throw SyncError.importFailed(error)
|
throw SyncError.importFailed(error)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -153,9 +153,7 @@ struct SyncMerger {
|
|||||||
let activeSessionIds = Set(
|
let activeSessionIds = Set(
|
||||||
local.compactMap { attempt in
|
local.compactMap { attempt in
|
||||||
return attempt.sessionId
|
return attempt.sessionId
|
||||||
}.filter { sessionId in
|
}.filter { _ in
|
||||||
// Check if this session ID belongs to an active session
|
|
||||||
// For now, we'll be conservative and not delete attempts during merge
|
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ class SyncService: ObservableObject {
|
|||||||
if let lastSync = userDefaults.object(forKey: Keys.lastSyncTime) as? Date {
|
if let lastSync = userDefaults.object(forKey: Keys.lastSyncTime) as? Date {
|
||||||
self.lastSyncTime = lastSync
|
self.lastSyncTime = lastSync
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
syncError = error.localizedDescription
|
syncError = error.localizedDescription
|
||||||
throw error
|
throw error
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ class ImageManager {
|
|||||||
|
|
||||||
saveMigrationState(initialState)
|
saveMigrationState(initialState)
|
||||||
performMigrationWithCheckpoints(files: allLegacyFiles, currentState: initialState)
|
performMigrationWithCheckpoints(files: allLegacyFiles, currentState: initialState)
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
logError("ERROR: Failed to start migration: \(error)")
|
logError("ERROR: Failed to start migration: \(error)")
|
||||||
}
|
}
|
||||||
@@ -255,7 +254,6 @@ class ImageManager {
|
|||||||
|
|
||||||
logInfo("Resuming with \(remainingFiles.count) remaining files")
|
logInfo("Resuming with \(remainingFiles.count) remaining files")
|
||||||
performMigrationWithCheckpoints(files: remainingFiles, currentState: state)
|
performMigrationWithCheckpoints(files: remainingFiles, currentState: state)
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
logError("ERROR: Failed to resume migration: \(error)")
|
logError("ERROR: Failed to resume migration: \(error)")
|
||||||
// Fallback: start fresh
|
// Fallback: start fresh
|
||||||
@@ -325,7 +323,6 @@ class ImageManager {
|
|||||||
migratedCount += 1
|
migratedCount += 1
|
||||||
|
|
||||||
logInfo("Migrated: \(fileName) (\(migratedCount)/\(currentState.totalFiles))")
|
logInfo("Migrated: \(fileName) (\(migratedCount)/\(currentState.totalFiles))")
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
failedCount += 1
|
failedCount += 1
|
||||||
logError("ERROR: Failed to migrate \(fileName): \(error)")
|
logError("ERROR: Failed to migrate \(fileName): \(error)")
|
||||||
@@ -676,7 +673,7 @@ class ImageManager {
|
|||||||
|
|
||||||
for fileName in files {
|
for fileName in files {
|
||||||
let filePath = imagesDirectory.appendingPathComponent(fileName)
|
let filePath = imagesDirectory.appendingPathComponent(fileName)
|
||||||
if let data = try? Data(contentsOf: filePath), data.count > 0 {
|
if let data = try? Data(contentsOf: filePath), !data.isEmpty {
|
||||||
// Basic validation - check if file has content and is reasonable size
|
// Basic validation - check if file has content and is reasonable size
|
||||||
if data.count > 100 { // Minimum viable image size
|
if data.count > 100 { // Minimum viable image size
|
||||||
validFiles += 1
|
validFiles += 1
|
||||||
@@ -825,7 +822,7 @@ class ImageManager {
|
|||||||
let primaryEmpty =
|
let primaryEmpty =
|
||||||
(try? fileManager.contentsOfDirectory(atPath: imagesDirectory.path).isEmpty) ?? true
|
(try? fileManager.contentsOfDirectory(atPath: imagesDirectory.path).isEmpty) ?? true
|
||||||
let backupHasFiles =
|
let backupHasFiles =
|
||||||
((try? fileManager.contentsOfDirectory(atPath: backupDirectory.path)) ?? []).count > 0
|
!((try? fileManager.contentsOfDirectory(atPath: backupDirectory.path)) ?? []).isEmpty
|
||||||
|
|
||||||
if primaryEmpty && backupHasFiles {
|
if primaryEmpty && backupHasFiles {
|
||||||
logDebug("DEBUG SAFE: Primary empty but backup exists - restoring")
|
logDebug("DEBUG SAFE: Primary empty but backup exists - restoring")
|
||||||
@@ -944,7 +941,6 @@ class ImageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logInfo("Completed migration from previous Application Support directory")
|
logInfo("Completed migration from previous Application Support directory")
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
logError("ERROR: Failed to migrate from previous Application Support: \(error)")
|
logError("ERROR: Failed to migrate from previous Application Support: \(error)")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import SwiftUI
|
|
||||||
import Combine
|
import Combine
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
class ThemeManager: ObservableObject {
|
class ThemeManager: ObservableObject {
|
||||||
@Published var accentColor: Color = .blue {
|
@Published var accentColor: Color = .blue {
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ struct ZipUtils {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
let imageData = try Data(contentsOf: imageURL)
|
let imageData = try Data(contentsOf: imageURL)
|
||||||
if imageData.count > 0 {
|
if !imageData.isEmpty {
|
||||||
let imageEntryName = "\(IMAGES_DIR_NAME)/\(imageName)"
|
let imageEntryName = "\(IMAGES_DIR_NAME)/\(imageName)"
|
||||||
try addFileToZip(
|
try addFileToZip(
|
||||||
filename: imageEntryName,
|
filename: imageEntryName,
|
||||||
|
|||||||
@@ -526,7 +526,6 @@ struct AddAttemptView: View {
|
|||||||
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProblemSelectionRow: View {
|
struct ProblemSelectionRow: View {
|
||||||
@@ -1302,7 +1301,6 @@ struct EditAttemptView: View {
|
|||||||
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ struct AddEditProblemView: View {
|
|||||||
await loadSelectedPhotos()
|
await loadSelectedPhotos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@@ -224,7 +223,6 @@ struct AddEditProblemView: View {
|
|||||||
.fill(.quaternary)
|
.fill(.quaternary)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ struct BarChartView: View {
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
VStack(alignment: .leading) {
|
VStack(alignment: .leading) {
|
||||||
// Chart area
|
// Chart area
|
||||||
HStack(alignment: .bottom, spacing: spacing / CGFloat(sortedData.count)) {
|
HStack(alignment: .bottom, spacing: spacing / CGFloat(sortedData.count)) {
|
||||||
ForEach(Array(sortedData.enumerated()), id: \.offset) { index, gradeCount in
|
ForEach(Array(sortedData.enumerated()), id: \.offset) { index, gradeCount in
|
||||||
VStack(spacing: 4) {
|
VStack(spacing: 4) {
|
||||||
|
|||||||
@@ -231,7 +231,6 @@ struct SessionDetailView: View {
|
|||||||
uniqueProblemsCompleted: completedProblems.count
|
uniqueProblemsCompleted: completedProblems.count
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionHeaderCard: View {
|
struct SessionHeaderCard: View {
|
||||||
@@ -305,7 +304,6 @@ struct SessionHeaderCard: View {
|
|||||||
formatter.dateStyle = .full
|
formatter.dateStyle = .full
|
||||||
return formatter.string(from: date)
|
return formatter.string(from: date)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionStatsCard: View {
|
struct SessionStatsCard: View {
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ struct ProblemsView: View {
|
|||||||
Button(action: {
|
Button(action: {
|
||||||
showingFilters = true
|
showingFilters = true
|
||||||
}) {
|
}) {
|
||||||
Image(systemName: (selectedClimbType != nil || selectedGym != nil) ? "line.3.horizontal.decrease.circle.fill" : "line.3.horizontal.decrease.circle")
|
let hasFilters = selectedClimbType != nil || selectedGym != nil
|
||||||
|
Image(systemName: hasFilters ? "line.3.horizontal.decrease.circle.fill" : "line.3.horizontal.decrease.circle")
|
||||||
.font(.system(size: 16, weight: .medium))
|
.font(.system(size: 16, weight: .medium))
|
||||||
.foregroundColor(themeManager.accentColor)
|
.foregroundColor(themeManager.accentColor)
|
||||||
}
|
}
|
||||||
@@ -365,7 +366,6 @@ struct FilterSection: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FilterChip: View {
|
struct FilterChip: View {
|
||||||
@@ -392,8 +392,6 @@ struct FilterChip: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct ProblemRow: View {
|
struct ProblemRow: View {
|
||||||
let problem: Problem
|
let problem: Problem
|
||||||
@EnvironmentObject var dataManager: ClimbingDataManager
|
@EnvironmentObject var dataManager: ClimbingDataManager
|
||||||
|
|||||||
@@ -256,7 +256,6 @@ struct ActiveSessionBanner: View {
|
|||||||
SessionDetailView(sessionId: session.id)
|
SessionDetailView(sessionId: session.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionRow: View {
|
struct SessionRow: View {
|
||||||
|
|||||||
@@ -251,9 +251,16 @@ struct DataManagementSection: View {
|
|||||||
dataManager.resetAllData()
|
dataManager.resetAllData()
|
||||||
}
|
}
|
||||||
} message: {
|
} message: {
|
||||||
Text(
|
Text("""
|
||||||
"Are you sure you want to reset all data? This will permanently delete:\n\n• All gyms and their information\n• All problems and their images\n• All climbing sessions\n• All attempts and progress data\n\nThis action cannot be undone. Consider exporting your data first."
|
Are you sure you want to reset all data? This will permanently delete:
|
||||||
)
|
|
||||||
|
• All gyms and their information
|
||||||
|
• All problems and their images
|
||||||
|
• All climbing sessions
|
||||||
|
• All attempts and progress data
|
||||||
|
|
||||||
|
This action cannot be undone. Consider exporting your data first.
|
||||||
|
""")
|
||||||
}
|
}
|
||||||
|
|
||||||
.alert("Delete All Images", isPresented: $showingDeleteImagesAlert) {
|
.alert("Delete All Images", isPresented: $showingDeleteImagesAlert) {
|
||||||
@@ -262,9 +269,14 @@ struct DataManagementSection: View {
|
|||||||
deleteAllImages()
|
deleteAllImages()
|
||||||
}
|
}
|
||||||
} message: {
|
} message: {
|
||||||
Text(
|
Text("""
|
||||||
"This will permanently delete ALL image files from your device.\n\nProblems will keep their references but the actual image files will be removed. This cannot be undone.\n\nConsider exporting your data first if you want to keep your images."
|
This will permanently delete ALL image files from your device.
|
||||||
)
|
|
||||||
|
Problems will keep their references but the actual image files will be removed. \
|
||||||
|
This cannot be undone.
|
||||||
|
|
||||||
|
Consider exporting your data first if you want to keep your images.
|
||||||
|
""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,7 +663,6 @@ struct SyncSection: View {
|
|||||||
.foregroundColor(.red)
|
.foregroundColor(.red)
|
||||||
.padding(.leading, 24)
|
.padding(.leading, 24)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showingSyncSettings) {
|
.sheet(isPresented: $showingSyncSettings) {
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ struct SessionStatusLiveLiveActivity: Widget {
|
|||||||
LiveActivityView(context: context)
|
LiveActivityView(context: context)
|
||||||
.activityBackgroundTint(Color.blue.opacity(0.2))
|
.activityBackgroundTint(Color.blue.opacity(0.2))
|
||||||
.activitySystemActionForegroundColor(Color.primary)
|
.activitySystemActionForegroundColor(Color.primary)
|
||||||
|
|
||||||
} dynamicIsland: { context in
|
} dynamicIsland: { context in
|
||||||
DynamicIsland {
|
DynamicIsland {
|
||||||
DynamicIslandExpandedRegion(.leading) {
|
DynamicIslandExpandedRegion(.leading) {
|
||||||
|
|||||||
Reference in New Issue
Block a user