Compare commits
17 Commits
ANDROID_1.
...
ANDROID_2.
| Author | SHA1 | Date | |
|---|---|---|---|
| 8529f76c22 | |||
|
879aae0721
|
|||
|
6fc86558b2
|
|||
|
23de8a6fc6
|
|||
|
01d85a4add
|
|||
|
ef1cf3583a
|
|||
|
3c7290f7e7
|
|||
|
5a49b9f0b2
|
|||
| 7601e7bb03 | |||
| 082cb79630 | |||
| 79b87a088d | |||
| 1a8f41ecde | |||
|
175dad8342
|
|||
|
4559d5e2f2
|
|||
|
d57149d29c
|
|||
|
d5cf14d466
|
|||
|
09b4055985
|
38
.github/workflows/deploy_docs.yml
vendored
Normal file
38
.github/workflows/deploy_docs.yml
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
name: Ascently - Docs Deploy
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
paths: ["docs/**"]
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
paths: ["docs/**"]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Container Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ secrets.REPO_HOST }}
|
||||||
|
username: ${{ github.repository_owner }}
|
||||||
|
password: ${{ secrets.DEPLOY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: docker/build-push-action@v6
|
||||||
|
with:
|
||||||
|
context: ./docs
|
||||||
|
platforms: linux/amd64
|
||||||
|
push: true
|
||||||
|
tags: |
|
||||||
|
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/ascently-docs:${{ github.sha }}
|
||||||
|
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/ascently-docs:latest
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
name: OpenClimb Docker Deploy
|
name: Ascently - Sync Deploy
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
packages: write
|
packages: write
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v2
|
uses: docker/setup-buildx-action@v2
|
||||||
@@ -27,12 +27,12 @@ jobs:
|
|||||||
password: ${{ secrets.DEPLOY_TOKEN }}
|
password: ${{ secrets.DEPLOY_TOKEN }}
|
||||||
|
|
||||||
- name: Build and push sync-server
|
- name: Build and push sync-server
|
||||||
uses: docker/build-push-action@v4
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: ./sync
|
context: ./sync
|
||||||
file: ./sync/Dockerfile
|
file: ./sync/Dockerfile
|
||||||
platforms: linux/amd64
|
platforms: linux/amd64
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/openclimb-sync:${{ github.sha }}
|
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/ascently-sync:${{ github.sha }}
|
||||||
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/openclimb-sync:latest
|
${{ secrets.REPO_HOST }}/${{ github.repository_owner }}/ascently-sync:latest
|
||||||
21
PRIVACY.md
21
PRIVACY.md
@@ -1,21 +0,0 @@
|
|||||||
# Privacy Policy
|
|
||||||
|
|
||||||
**Last updated: September 29, 2025**
|
|
||||||
|
|
||||||
This Privacy Policy describes our policies and procedures regarding the collection, use, and disclosure of your information when you use my software.
|
|
||||||
|
|
||||||
## No Data Collection
|
|
||||||
|
|
||||||
I do not collect any personal information, analytics, or data of any kind. This software is designed to be self-hosted or run entirely offline.
|
|
||||||
|
|
||||||
All data generated by or used with this software remains on your local machine or self-hosted environment under your control. I have no access to it.
|
|
||||||
|
|
||||||
## No Tracking or Analytics
|
|
||||||
|
|
||||||
This software does not use cookies, tracking pixels, or any other analytics or tracking mechanisms. Your usage of the software is completely private.
|
|
||||||
|
|
||||||
## Contact Us
|
|
||||||
|
|
||||||
If you have any questions about this Privacy Policy, you can contact me:
|
|
||||||
|
|
||||||
* **By email:** me@atri.dad
|
|
||||||
40
README.md
40
README.md
@@ -1,42 +1,12 @@
|
|||||||
# OpenClimb
|
# Ascently
|
||||||
|
|
||||||
This is a FOSS app meant to help climbers track their sessions, routes/problems, and overall progress. This app is offline-only and requires no special permissions to run. Its built using Jetpack Compose with Material You support on Android and SwiftUI on iOS.
|
_Formerly OpenClimb_
|
||||||
|
|
||||||
## Download
|
Ascently is an **offline-first FOSS** app designed to help climbers track their sessions, routes/problems, and overall progress. There is an optional self-hosted sync server and integrations with Apple Health and Health Connect. There are no analytics or tracking baked into any part of this project. I am committed to maintaining a transparent and open-source solution for climbers, ensuring that you have full control over your data and privacy.
|
||||||
|
|
||||||
For Android do one of the following:
|
## Documentation
|
||||||
|
|
||||||
1. Download the latest APK from the Releases page
|
Documentation can be found at [https://ascently.atri.dad](https://ascently.atri.dad)!
|
||||||
2. [<img src="https://github.com/ImranR98/Obtainium/blob/main/assets/graphics/badge_obtainium.png?raw=true" alt="Obtainium" height="41">](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22com.atridad.openclimb%22%2C%22url%22%3A%22https%3A%2F%2Fgit.atri.dad%2Fatridad%2FOpenClimb%2Freleases%22%2C%22author%22%3A%22git.atri.dad%22%2C%22name%22%3A%22OpenClimb%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22intermediateLink%5C%22%3A%5B%5D%2C%5C%22customLinkFilterRegex%5C%22%3A%5C%22%5C%22%2C%5C%22filterByLinkText%5C%22%3Afalse%2C%5C%22skipSort%5C%22%3Afalse%2C%5C%22reverseSort%5C%22%3Afalse%2C%5C%22sortByLastLinkSegment%5C%22%3Afalse%2C%5C%22versionExtractWholePage%5C%22%3Afalse%2C%5C%22requestHeader%5C%22%3A%5B%7B%5C%22requestHeader%5C%22%3A%5C%22User-Agent%3A%20Mozilla%2F5.0%20(Linux%3B%20Android%2010%3B%20K)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F114.0.0.0%20Mobile%20Safari%2F537.36%5C%22%7D%5D%2C%5C%22defaultPseudoVersioningMethod%5C%22%3A%5C%22partialAPKHash%5C%22%2C%5C%22trackOnly%5C%22%3Afalse%2C%5C%22versionExtractionRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22matchGroupToUse%5C%22%3A%5C%22%5C%22%2C%5C%22versionDetection%5C%22%3Afalse%2C%5C%22useVersionCodeAsOSVersion%5C%22%3Afalse%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22invertAPKFilter%5C%22%3Afalse%2C%5C%22autoApkFilterByArch%5C%22%3Atrue%2C%5C%22appName%5C%22%3A%5C%22OpenClimb%5C%22%2C%5C%22appAuthor%5C%22%3A%5C%22%5C%22%2C%5C%22shizukuPretendToBeGooglePlay%5C%22%3Afalse%2C%5C%22allowInsecure%5C%22%3Afalse%2C%5C%22exemptFromBackgroundUpdates%5C%22%3Afalse%2C%5C%22skipUpdateNotifications%5C%22%3Afalse%2C%5C%22about%5C%22%3A%5C%22%5C%22%2C%5C%22refreshBeforeDownload%5C%22%3Afalse%7D%22%2C%22overrideSource%22%3Anull%7D)
|
|
||||||
|
|
||||||
For iOS:
|
|
||||||
|
|
||||||
Download from the AppStore [here](https://apps.apple.com/ca/app/openclimb/id6752592783)!
|
|
||||||
For development builds, sign up for the TestFlight [here](https://testflight.apple.com/join/88RtxV4J)!
|
|
||||||
|
|
||||||
## Self-Hosted Sync Server
|
|
||||||
|
|
||||||
You can run your own sync server to keep your data in sync across devices. The server is lightweight and easy to set up using Docker.
|
|
||||||
|
|
||||||
### Quick Start with Docker Compose
|
|
||||||
|
|
||||||
1. Create a `.env` file with your configuration:
|
|
||||||
```
|
|
||||||
IMAGE=git.atri.dad/atridad/openclimb-sync:latest
|
|
||||||
APP_PORT=8080
|
|
||||||
AUTH_TOKEN=your-secure-auth-token-here
|
|
||||||
DATA_FILE=/data/openclimb.json
|
|
||||||
IMAGES_DIR=/data/images
|
|
||||||
ROOT_DIR=./openclimb-data
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Use the provided `docker-compose.yml` in the `sync/` directory:
|
|
||||||
```bash
|
|
||||||
cd sync/
|
|
||||||
docker-compose up -d
|
|
||||||
```
|
|
||||||
|
|
||||||
The server will be available at `http://localhost:8080`. Configure your clients with your server URL and auth token to start syncing.
|
|
||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# OpenClimb for Android
|
# Ascently for Android
|
||||||
|
|
||||||
This is the native Android app for OpenClimb, built with Kotlin and Jetpack Compose.
|
This is the native Android app for Ascently, built with Kotlin and Jetpack Compose.
|
||||||
|
|
||||||
## Project Structure
|
## Project Structure
|
||||||
|
|
||||||
This is a standard Android Gradle project. The main code lives in `app/src/main/java/com/atridad/openclimb/`.
|
This is a standard Android Gradle project. The main code lives in `app/src/main/java/com/atridad/ascently/`.
|
||||||
|
|
||||||
- `data/`: Handles all the app's data.
|
- `data/`: Handles all the app's data.
|
||||||
- `database/`: Room database setup (DAOs, entities).
|
- `database/`: Room database setup (DAOs, entities).
|
||||||
@@ -18,5 +18,3 @@ This is a standard Android Gradle project. The main code lives in `app/src/main/
|
|||||||
- `navigation/`: Navigation graph and routes using Jetpack Navigation.
|
- `navigation/`: Navigation graph and routes using Jetpack Navigation.
|
||||||
- `service/`: Background service for tracking climbing sessions.
|
- `service/`: Background service for tracking climbing sessions.
|
||||||
- `utils/`: Helpers for things like date formatting and image handling.
|
- `utils/`: Helpers for things like date formatting and image handling.
|
||||||
|
|
||||||
The app is built to be offline-first. All data is stored locally on your device and works without an internet connection.
|
|
||||||
@@ -9,15 +9,15 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.atridad.openclimb"
|
namespace = "com.atridad.ascently"
|
||||||
compileSdk = 36
|
compileSdk = 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.atridad.openclimb"
|
applicationId = "com.atridad.ascently"
|
||||||
minSdk = 31
|
minSdk = 31
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 39
|
versionCode = 42
|
||||||
versionName = "1.9.2"
|
versionName = "2.1.0"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "com.atridad.openclimb"
|
namespace = "com.atridad.ascently"
|
||||||
compileSdk = 36
|
compileSdk = 36
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.atridad.openclimb"
|
applicationId = "com.atridad.ascently"
|
||||||
minSdk = 31
|
minSdk = 31
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 27
|
versionCode = 27
|
||||||
|
|||||||
@@ -50,13 +50,13 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.OpenClimb"
|
android:theme="@style/Theme.Ascently"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@style/Theme.OpenClimb.Splash">
|
android:theme="@style/Theme.Ascently.Splash">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb
|
package com.atridad.ascently
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -9,8 +9,9 @@ import androidx.compose.foundation.layout.fillMaxSize
|
|||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import com.atridad.openclimb.ui.OpenClimbApp
|
import com.atridad.ascently.ui.AscentlyApp
|
||||||
import com.atridad.openclimb.ui.theme.OpenClimbTheme
|
import com.atridad.ascently.ui.theme.AscentlyTheme
|
||||||
|
import com.atridad.ascently.utils.MigrationManager
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private var shortcutAction by mutableStateOf<String?>(null)
|
private var shortcutAction by mutableStateOf<String?>(null)
|
||||||
@@ -23,16 +24,19 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setTheme(R.style.Theme_OpenClimb)
|
setTheme(R.style.Theme_Ascently)
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
|
// Perform migration from OpenClimb to Ascently if needed
|
||||||
|
MigrationManager(this).migrateIfNeeded()
|
||||||
|
|
||||||
shortcutAction = intent?.action
|
shortcutAction = intent?.action
|
||||||
lastUsedGymId = intent?.getStringExtra("LAST_USED_GYM_ID")
|
lastUsedGymId = intent?.getStringExtra("LAST_USED_GYM_ID")
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
OpenClimbTheme {
|
AscentlyTheme {
|
||||||
Surface(modifier = Modifier.fillMaxSize()) {
|
Surface(modifier = Modifier.fillMaxSize()) {
|
||||||
OpenClimbApp(
|
AscentlyApp(
|
||||||
shortcutAction = shortcutAction,
|
shortcutAction = shortcutAction,
|
||||||
lastUsedGymId = lastUsedGymId,
|
lastUsedGymId = lastUsedGymId,
|
||||||
onShortcutActionProcessed = { clearShortcutAction() }
|
onShortcutActionProcessed = { clearShortcutAction() }
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.atridad.openclimb.data.database
|
package com.atridad.ascently.data.database
|
||||||
|
|
||||||
import androidx.room.TypeConverter
|
import androidx.room.TypeConverter
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import kotlinx.serialization.encodeToString
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.data.database
|
package com.atridad.ascently.data.database
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
@@ -7,8 +7,8 @@ import androidx.room.RoomDatabase
|
|||||||
import androidx.room.TypeConverters
|
import androidx.room.TypeConverters
|
||||||
import androidx.room.migration.Migration
|
import androidx.room.migration.Migration
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||||
import com.atridad.openclimb.data.database.dao.*
|
import com.atridad.ascently.data.database.dao.*
|
||||||
import com.atridad.openclimb.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],
|
||||||
@@ -16,7 +16,7 @@ import com.atridad.openclimb.data.model.*
|
|||||||
exportSchema = false
|
exportSchema = false
|
||||||
)
|
)
|
||||||
@TypeConverters(Converters::class)
|
@TypeConverters(Converters::class)
|
||||||
abstract class OpenClimbDatabase : RoomDatabase() {
|
abstract class AscentlyDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun gymDao(): GymDao
|
abstract fun gymDao(): GymDao
|
||||||
abstract fun problemDao(): ProblemDao
|
abstract fun problemDao(): ProblemDao
|
||||||
@@ -24,12 +24,12 @@ abstract class OpenClimbDatabase : RoomDatabase() {
|
|||||||
abstract fun attemptDao(): AttemptDao
|
abstract fun attemptDao(): AttemptDao
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@Volatile private var INSTANCE: OpenClimbDatabase? = 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(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
val cursor = database.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()) {
|
||||||
@@ -39,21 +39,21 @@ abstract class OpenClimbDatabase : RoomDatabase() {
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
if (!existingColumns.contains("startTime")) {
|
if (!existingColumns.contains("startTime")) {
|
||||||
database.execSQL("ALTER TABLE climb_sessions ADD COLUMN startTime TEXT")
|
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN startTime TEXT")
|
||||||
}
|
}
|
||||||
if (!existingColumns.contains("endTime")) {
|
if (!existingColumns.contains("endTime")) {
|
||||||
database.execSQL("ALTER TABLE climb_sessions ADD COLUMN endTime TEXT")
|
db.execSQL("ALTER TABLE climb_sessions ADD COLUMN endTime TEXT")
|
||||||
}
|
}
|
||||||
if (!existingColumns.contains("status")) {
|
if (!existingColumns.contains("status")) {
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"ALTER TABLE climb_sessions ADD COLUMN status TEXT NOT NULL DEFAULT 'COMPLETED'"
|
"ALTER TABLE climb_sessions ADD COLUMN status TEXT NOT NULL DEFAULT 'COMPLETED'"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"UPDATE climb_sessions SET startTime = createdAt WHERE startTime IS NULL"
|
"UPDATE climb_sessions SET startTime = createdAt WHERE startTime IS NULL"
|
||||||
)
|
)
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"UPDATE climb_sessions SET status = 'COMPLETED' WHERE status IS NULL OR status = ''"
|
"UPDATE climb_sessions SET status = 'COMPLETED' WHERE status IS NULL OR status = ''"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -61,9 +61,9 @@ abstract class OpenClimbDatabase : RoomDatabase() {
|
|||||||
|
|
||||||
val MIGRATION_5_6 =
|
val MIGRATION_5_6 =
|
||||||
object : Migration(5, 6) {
|
object : Migration(5, 6) {
|
||||||
override fun migrate(database: SupportSQLiteDatabase) {
|
override fun migrate(db: SupportSQLiteDatabase) {
|
||||||
// Add updatedAt column to attempts table
|
// Add updatedAt column to attempts table
|
||||||
val cursor = database.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()) {
|
||||||
@@ -73,29 +73,29 @@ abstract class OpenClimbDatabase : RoomDatabase() {
|
|||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
if (!existingColumns.contains("updatedAt")) {
|
if (!existingColumns.contains("updatedAt")) {
|
||||||
database.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
|
||||||
database.execSQL(
|
db.execSQL(
|
||||||
"UPDATE attempts SET updatedAt = createdAt WHERE updatedAt = ''"
|
"UPDATE attempts SET updatedAt = createdAt WHERE updatedAt = ''"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDatabase(context: Context): OpenClimbDatabase {
|
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,
|
||||||
OpenClimbDatabase::class.java,
|
AscentlyDatabase::class.java,
|
||||||
"openclimb_database"
|
"ascently_database"
|
||||||
)
|
)
|
||||||
.addMigrations(MIGRATION_4_5, MIGRATION_5_6)
|
.addMigrations(MIGRATION_4_5, MIGRATION_5_6)
|
||||||
.enableMultiInstanceInvalidation()
|
.enableMultiInstanceInvalidation()
|
||||||
.fallbackToDestructiveMigration()
|
.fallbackToDestructiveMigration(false)
|
||||||
.build()
|
.build()
|
||||||
INSTANCE = instance
|
INSTANCE = instance
|
||||||
instance
|
instance
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.data.database.dao
|
package com.atridad.ascently.data.database.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.atridad.openclimb.data.model.Attempt
|
import com.atridad.ascently.data.model.Attempt
|
||||||
import com.atridad.openclimb.data.model.AttemptResult
|
import com.atridad.ascently.data.model.AttemptResult
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.data.database.dao
|
package com.atridad.ascently.data.database.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.atridad.openclimb.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.openclimb.data.model.SessionStatus
|
import com.atridad.ascently.data.model.SessionStatus
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.data.database.dao
|
package com.atridad.ascently.data.database.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.atridad.openclimb.data.model.ClimbType
|
import com.atridad.ascently.data.model.ClimbType
|
||||||
import com.atridad.openclimb.data.model.Gym
|
import com.atridad.ascently.data.model.Gym
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.data.database.dao
|
package com.atridad.ascently.data.database.dao
|
||||||
|
|
||||||
import androidx.room.*
|
import androidx.room.*
|
||||||
import com.atridad.openclimb.data.model.ClimbType
|
import com.atridad.ascently.data.model.ClimbType
|
||||||
import com.atridad.openclimb.data.model.Problem
|
import com.atridad.ascently.data.model.Problem
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.atridad.openclimb.data.format
|
package com.atridad.ascently.data.format
|
||||||
|
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
// Root structure for OpenClimb backup data
|
// Root structure for Ascently backup data
|
||||||
@Serializable
|
@Serializable
|
||||||
data class ClimbDataBackup(
|
data class ClimbDataBackup(
|
||||||
val exportedAt: String,
|
val exportedAt: String,
|
||||||
@@ -32,13 +32,12 @@ data class BackupGym(
|
|||||||
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> = emptyList(),
|
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 {
|
||||||
/** Create BackupGym from native Android Gym model */
|
|
||||||
fun fromGym(gym: Gym): BackupGym {
|
fun fromGym(gym: Gym): BackupGym {
|
||||||
return BackupGym(
|
return BackupGym(
|
||||||
id = gym.id,
|
id = gym.id,
|
||||||
@@ -46,7 +45,7 @@ data class BackupGym(
|
|||||||
location = gym.location,
|
location = gym.location,
|
||||||
supportedClimbTypes = gym.supportedClimbTypes,
|
supportedClimbTypes = gym.supportedClimbTypes,
|
||||||
difficultySystems = gym.difficultySystems,
|
difficultySystems = gym.difficultySystems,
|
||||||
customDifficultyGrades = gym.customDifficultyGrades,
|
customDifficultyGrades = gym.customDifficultyGrades.ifEmpty { null },
|
||||||
notes = gym.notes,
|
notes = gym.notes,
|
||||||
createdAt = gym.createdAt,
|
createdAt = gym.createdAt,
|
||||||
updatedAt = gym.updatedAt
|
updatedAt = gym.updatedAt
|
||||||
@@ -54,7 +53,6 @@ data class BackupGym(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert to native Android Gym model */
|
|
||||||
fun toGym(): Gym {
|
fun toGym(): Gym {
|
||||||
return Gym(
|
return Gym(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -62,7 +60,7 @@ data class BackupGym(
|
|||||||
location = location,
|
location = location,
|
||||||
supportedClimbTypes = supportedClimbTypes,
|
supportedClimbTypes = supportedClimbTypes,
|
||||||
difficultySystems = difficultySystems,
|
difficultySystems = difficultySystems,
|
||||||
customDifficultyGrades = customDifficultyGrades,
|
customDifficultyGrades = customDifficultyGrades ?: emptyList(),
|
||||||
notes = notes,
|
notes = notes,
|
||||||
createdAt = createdAt,
|
createdAt = createdAt,
|
||||||
updatedAt = updatedAt
|
updatedAt = updatedAt
|
||||||
@@ -79,7 +77,7 @@ data class BackupProblem(
|
|||||||
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>? = 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,
|
||||||
@@ -89,7 +87,6 @@ data class BackupProblem(
|
|||||||
val updatedAt: String
|
val updatedAt: String
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
/** Create BackupProblem from native Android Problem model */
|
|
||||||
fun fromProblem(problem: Problem): BackupProblem {
|
fun fromProblem(problem: Problem): BackupProblem {
|
||||||
return BackupProblem(
|
return BackupProblem(
|
||||||
id = problem.id,
|
id = problem.id,
|
||||||
@@ -112,7 +109,6 @@ data class BackupProblem(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert to native Android Problem model */
|
|
||||||
fun toProblem(): Problem {
|
fun toProblem(): Problem {
|
||||||
return Problem(
|
return Problem(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -121,7 +117,7 @@ data class BackupProblem(
|
|||||||
description = description,
|
description = description,
|
||||||
climbType = climbType,
|
climbType = climbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
tags = tags,
|
tags = tags ?: emptyList(),
|
||||||
location = location,
|
location = location,
|
||||||
imagePaths = imagePaths ?: emptyList(),
|
imagePaths = imagePaths ?: emptyList(),
|
||||||
isActive = isActive,
|
isActive = isActive,
|
||||||
@@ -132,7 +128,6 @@ data class BackupProblem(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create a copy with updated image paths for import processing */
|
|
||||||
fun withUpdatedImagePaths(newImagePaths: List<String>): BackupProblem {
|
fun withUpdatedImagePaths(newImagePaths: List<String>): BackupProblem {
|
||||||
return copy(imagePaths = newImagePaths.ifEmpty { null })
|
return copy(imagePaths = newImagePaths.ifEmpty { null })
|
||||||
}
|
}
|
||||||
@@ -153,7 +148,6 @@ data class BackupClimbSession(
|
|||||||
val updatedAt: String
|
val updatedAt: String
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
/** Create BackupClimbSession from native Android ClimbSession model */
|
|
||||||
fun fromClimbSession(session: ClimbSession): BackupClimbSession {
|
fun fromClimbSession(session: ClimbSession): BackupClimbSession {
|
||||||
return BackupClimbSession(
|
return BackupClimbSession(
|
||||||
id = session.id,
|
id = session.id,
|
||||||
@@ -170,7 +164,6 @@ data class BackupClimbSession(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert to native Android ClimbSession model */
|
|
||||||
fun toClimbSession(): ClimbSession {
|
fun toClimbSession(): ClimbSession {
|
||||||
return ClimbSession(
|
return ClimbSession(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -203,7 +196,6 @@ data class BackupAttempt(
|
|||||||
val updatedAt: String? = null
|
val updatedAt: String? = null
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
/** Create BackupAttempt from native Android Attempt model */
|
|
||||||
fun fromAttempt(attempt: Attempt): BackupAttempt {
|
fun fromAttempt(attempt: Attempt): BackupAttempt {
|
||||||
return BackupAttempt(
|
return BackupAttempt(
|
||||||
id = attempt.id,
|
id = attempt.id,
|
||||||
@@ -221,7 +213,6 @@ data class BackupAttempt(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Convert to native Android Attempt model */
|
|
||||||
fun toAttempt(): Attempt {
|
fun toAttempt(): Attempt {
|
||||||
return Attempt(
|
return Attempt(
|
||||||
id = id,
|
id = id,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.data.health
|
package com.atridad.ascently.data.health
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -12,9 +12,9 @@ import androidx.health.connect.client.records.ExerciseSessionRecord
|
|||||||
import androidx.health.connect.client.records.HeartRateRecord
|
import androidx.health.connect.client.records.HeartRateRecord
|
||||||
import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
||||||
import androidx.health.connect.client.units.Energy
|
import androidx.health.connect.client.units.Energy
|
||||||
import com.atridad.openclimb.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.openclimb.data.model.SessionStatus
|
import com.atridad.ascently.data.model.SessionStatus
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneOffset
|
import java.time.ZoneOffset
|
||||||
@@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.asStateFlow
|
|||||||
import kotlinx.coroutines.flow.flow
|
import kotlinx.coroutines.flow.flow
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Health Connect manager for OpenClimb that syncs climbing sessions to Samsung Health, Google Fit,
|
* Health Connect manager for Ascently that syncs climbing sessions to Samsung Health, Google Fit,
|
||||||
* and other health apps.
|
* and other health apps.
|
||||||
*/
|
*/
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
@@ -40,7 +40,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
|
|
||||||
val isEnabled: Flow<Boolean> = _isEnabled.asStateFlow()
|
val isEnabled: Flow<Boolean> = _isEnabled.asStateFlow()
|
||||||
val hasPermissions: Flow<Boolean> = _hasPermissions.asStateFlow()
|
val hasPermissions: Flow<Boolean> = _hasPermissions.asStateFlow()
|
||||||
val autoSyncEnabled: Flow<Boolean> = _autoSync.asStateFlow()
|
|
||||||
val isCompatible: Flow<Boolean> = _isCompatible.asStateFlow()
|
val isCompatible: Flow<Boolean> = _isCompatible.asStateFlow()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@@ -67,7 +66,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if Health Connect is available on this device */
|
|
||||||
fun isHealthConnectAvailable(): Flow<Boolean> = flow {
|
fun isHealthConnectAvailable(): Flow<Boolean> = flow {
|
||||||
try {
|
try {
|
||||||
if (!_isCompatible.value) {
|
if (!_isCompatible.value) {
|
||||||
@@ -83,29 +81,30 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enable or disable Health Connect integration */
|
suspend fun setEnabled(enabled: Boolean) {
|
||||||
fun setEnabled(enabled: Boolean) {
|
|
||||||
preferences.edit().putBoolean("enabled", enabled).apply()
|
preferences.edit().putBoolean("enabled", enabled).apply()
|
||||||
_isEnabled.value = enabled
|
_isEnabled.value = enabled
|
||||||
|
|
||||||
if (!enabled) {
|
if (enabled && _isCompatible.value) {
|
||||||
|
// Automatically request permissions when enabling
|
||||||
|
try {
|
||||||
|
val alreadyHasPermissions = hasAllPermissions()
|
||||||
|
if (!alreadyHasPermissions) {
|
||||||
|
Log.d(TAG, "Health Connect enabled - permissions will be requested by UI")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Error checking permissions when enabling Health Connect", e)
|
||||||
|
}
|
||||||
|
} else if (!enabled) {
|
||||||
setPermissionsGranted(false)
|
setPermissionsGranted(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the permissions granted state */
|
|
||||||
fun setPermissionsGranted(granted: Boolean) {
|
fun setPermissionsGranted(granted: Boolean) {
|
||||||
preferences.edit().putBoolean("permissions", granted).apply()
|
preferences.edit().putBoolean("permissions", granted).apply()
|
||||||
_hasPermissions.value = granted
|
_hasPermissions.value = granted
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Enable or disable auto-sync */
|
|
||||||
fun setAutoSyncEnabled(enabled: Boolean) {
|
|
||||||
preferences.edit().putBoolean("auto_sync", enabled).apply()
|
|
||||||
_autoSync.value = enabled
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if all required permissions are granted */
|
|
||||||
suspend fun hasAllPermissions(): Boolean {
|
suspend fun hasAllPermissions(): Boolean {
|
||||||
return try {
|
return try {
|
||||||
if (!_isCompatible.value || healthConnectClient == null) {
|
if (!_isCompatible.value || healthConnectClient == null) {
|
||||||
@@ -126,7 +125,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Check if Health Connect is ready for use */
|
|
||||||
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)
|
||||||
@@ -142,88 +140,30 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get permission request contract */
|
|
||||||
fun getPermissionRequestContract(): ActivityResultContract<Set<String>, Set<String>> {
|
fun getPermissionRequestContract(): ActivityResultContract<Set<String>, Set<String>> {
|
||||||
return PermissionController.createRequestPermissionResultContract()
|
return PermissionController.createRequestPermissionResultContract()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test Health Connect functionality */
|
|
||||||
fun testHealthConnectSync(): String {
|
|
||||||
val results = mutableListOf<String>()
|
|
||||||
|
|
||||||
results.add("=== Health Connect Debug Test ===")
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Check availability synchronously
|
|
||||||
val packageManager = context.packageManager
|
|
||||||
val healthConnectPackages =
|
|
||||||
listOf(
|
|
||||||
"com.google.android.apps.healthdata",
|
|
||||||
"com.android.health.connect",
|
|
||||||
"androidx.health.connect"
|
|
||||||
)
|
|
||||||
|
|
||||||
val available =
|
|
||||||
healthConnectPackages.any { packageName ->
|
|
||||||
try {
|
|
||||||
packageManager.getPackageInfo(packageName, 0)
|
|
||||||
true
|
|
||||||
} catch (e: Exception) {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
results.add("Available: $available")
|
|
||||||
|
|
||||||
// Check enabled state
|
|
||||||
results.add("Enabled in settings: ${_isEnabled.value}")
|
|
||||||
|
|
||||||
// Check permissions (simplified)
|
|
||||||
val hasPerms = _hasPermissions.value
|
|
||||||
results.add("Has permissions: $hasPerms")
|
|
||||||
|
|
||||||
// Check compatibility
|
|
||||||
results.add("API Compatible: ${_isCompatible.value}")
|
|
||||||
|
|
||||||
val ready = _isEnabled.value && _isCompatible.value && available && hasPerms
|
|
||||||
results.add("Ready to sync: $ready")
|
|
||||||
|
|
||||||
if (ready) {
|
|
||||||
results.add("Health Connect is connected!")
|
|
||||||
} else {
|
|
||||||
results.add("❌ Health Connect not ready")
|
|
||||||
if (!available) results.add("- Health Connect not available on device")
|
|
||||||
if (!_isEnabled.value) results.add("- Not enabled in OpenClimb settings")
|
|
||||||
if (!hasPerms) results.add("- Permissions not granted")
|
|
||||||
if (!_isCompatible.value) results.add("- API compatibility issues")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
results.add("Test failed with error: ${e.message}")
|
|
||||||
Log.e(TAG, "Health Connect test failed", e)
|
|
||||||
}
|
|
||||||
|
|
||||||
return results.joinToString("\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get required permissions as strings */
|
|
||||||
fun getRequiredPermissions(): Set<String> {
|
fun getRequiredPermissions(): Set<String> {
|
||||||
return try {
|
return try {
|
||||||
REQUIRED_PERMISSIONS.map { it.toString() }.toSet()
|
REQUIRED_PERMISSIONS.map { it }.toSet()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "Error getting required permissions", e)
|
Log.e(TAG, "Error getting required permissions", e)
|
||||||
emptySet()
|
emptySet()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sync a completed climbing session to Health Connect */
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
suspend fun syncClimbingSession(
|
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()) {
|
if (!isReady() || !_autoSync.value) {
|
||||||
return Result.failure(IllegalStateException("Health Connect not ready"))
|
return Result.failure(
|
||||||
|
IllegalStateException("Health Connect not ready or auto-sync disabled")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (session.status != SessionStatus.COMPLETED) {
|
if (session.status != SessionStatus.COMPLETED) {
|
||||||
@@ -320,18 +260,18 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Auto-sync a session if enabled */
|
suspend fun autoSyncCompletedSession(
|
||||||
suspend fun autoSyncSession(
|
|
||||||
session: ClimbSession,
|
session: ClimbSession,
|
||||||
gymName: String,
|
gymName: String,
|
||||||
attemptCount: Int = 0
|
attemptCount: Int = 0
|
||||||
): Result<Unit> {
|
): Result<Unit> {
|
||||||
return if (_autoSync.value && isReady()) {
|
return if (_autoSync.value && isReady() && session.status == SessionStatus.COMPLETED) {
|
||||||
Log.d(TAG, "Auto-syncing session '${session.id}' to Health Connect...")
|
Log.d(TAG, "Auto-syncing completed session '${session.id}' to Health Connect...")
|
||||||
syncClimbingSession(session, gymName, attemptCount)
|
syncCompletedSession(session, gymName, attemptCount)
|
||||||
} else {
|
} else {
|
||||||
val reason =
|
val reason =
|
||||||
when {
|
when {
|
||||||
|
session.status != SessionStatus.COMPLETED -> "session not completed"
|
||||||
!_autoSync.value -> "auto-sync disabled"
|
!_autoSync.value -> "auto-sync disabled"
|
||||||
!isReady() -> "Health Connect not ready"
|
!isReady() -> "Health Connect not ready"
|
||||||
else -> "unknown reason"
|
else -> "unknown reason"
|
||||||
@@ -341,7 +281,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Estimate calories burned during climbing */
|
|
||||||
private fun estimateCaloriesForClimbing(durationMinutes: Long, attemptCount: Int): Double {
|
private fun estimateCaloriesForClimbing(durationMinutes: Long, attemptCount: Int): Double {
|
||||||
val baseCaloriesPerMinute = 8.0
|
val baseCaloriesPerMinute = 8.0
|
||||||
val intensityMultiplier =
|
val intensityMultiplier =
|
||||||
@@ -353,7 +292,6 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
return durationMinutes * baseCaloriesPerMinute * intensityMultiplier
|
return durationMinutes * baseCaloriesPerMinute * intensityMultiplier
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create heart rate data */
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
private fun createHeartRateRecord(
|
private fun createHeartRateRecord(
|
||||||
startTime: Instant,
|
startTime: Instant,
|
||||||
@@ -395,32 +333,7 @@ class HealthConnectManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reset all preferences */
|
|
||||||
fun reset() {
|
|
||||||
preferences.edit().clear().apply()
|
|
||||||
_isEnabled.value = false
|
|
||||||
_hasPermissions.value = false
|
|
||||||
_autoSync.value = true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if ready for use */
|
|
||||||
fun isReadySync(): Boolean {
|
fun isReadySync(): Boolean {
|
||||||
return _isEnabled.value && _hasPermissions.value
|
return _isEnabled.value && _hasPermissions.value
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get last successful sync timestamp */
|
|
||||||
fun getLastSyncSuccess(): String? {
|
|
||||||
return preferences.getString("last_sync_success", null)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get detailed status */
|
|
||||||
fun getDetailedStatus(): Map<String, String> {
|
|
||||||
return mapOf(
|
|
||||||
"enabled" to _isEnabled.value.toString(),
|
|
||||||
"hasPermissions" to _hasPermissions.value.toString(),
|
|
||||||
"autoSync" to _autoSync.value.toString(),
|
|
||||||
"compatible" to _isCompatible.value.toString(),
|
|
||||||
"lastSyncSuccess" to (getLastSyncSuccess() ?: "never")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.openclimb.data.model
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -12,7 +12,7 @@ enum class AttemptResult {
|
|||||||
SUCCESS,
|
SUCCESS,
|
||||||
FALL,
|
FALL,
|
||||||
NO_PROGRESS,
|
NO_PROGRESS,
|
||||||
FLASH,
|
FLASH
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
@@ -74,5 +74,4 @@ data class Attempt(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.openclimb.data.model
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
enum class ClimbType {
|
||||||
|
ROPE,
|
||||||
|
BOULDER;
|
||||||
|
|
||||||
|
val displayName: String
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
ROPE -> "Rope"
|
||||||
|
BOULDER -> "Bouldering"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,263 @@
|
|||||||
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
enum class DifficultySystem {
|
||||||
|
// Bouldering
|
||||||
|
V_SCALE,
|
||||||
|
FONT,
|
||||||
|
|
||||||
|
// Rope
|
||||||
|
YDS,
|
||||||
|
CUSTOM;
|
||||||
|
|
||||||
|
val displayName: String
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
V_SCALE -> "V Scale"
|
||||||
|
FONT -> "Font Scale"
|
||||||
|
YDS -> "YDS (Yosemite)"
|
||||||
|
CUSTOM -> "Custom"
|
||||||
|
}
|
||||||
|
|
||||||
|
val isBoulderingSystem: Boolean
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
V_SCALE, FONT -> true
|
||||||
|
YDS -> false
|
||||||
|
CUSTOM -> true
|
||||||
|
}
|
||||||
|
|
||||||
|
val isRopeSystem: Boolean
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
YDS -> true
|
||||||
|
V_SCALE, FONT -> false
|
||||||
|
CUSTOM -> true
|
||||||
|
}
|
||||||
|
|
||||||
|
val availableGrades: List<String>
|
||||||
|
get() =
|
||||||
|
when (this) {
|
||||||
|
V_SCALE ->
|
||||||
|
listOf(
|
||||||
|
"VB",
|
||||||
|
"V0",
|
||||||
|
"V1",
|
||||||
|
"V2",
|
||||||
|
"V3",
|
||||||
|
"V4",
|
||||||
|
"V5",
|
||||||
|
"V6",
|
||||||
|
"V7",
|
||||||
|
"V8",
|
||||||
|
"V9",
|
||||||
|
"V10",
|
||||||
|
"V11",
|
||||||
|
"V12",
|
||||||
|
"V13",
|
||||||
|
"V14",
|
||||||
|
"V15",
|
||||||
|
"V16",
|
||||||
|
"V17"
|
||||||
|
)
|
||||||
|
FONT ->
|
||||||
|
listOf(
|
||||||
|
"3",
|
||||||
|
"4A",
|
||||||
|
"4B",
|
||||||
|
"4C",
|
||||||
|
"5A",
|
||||||
|
"5B",
|
||||||
|
"5C",
|
||||||
|
"6A",
|
||||||
|
"6A+",
|
||||||
|
"6B",
|
||||||
|
"6B+",
|
||||||
|
"6C",
|
||||||
|
"6C+",
|
||||||
|
"7A",
|
||||||
|
"7A+",
|
||||||
|
"7B",
|
||||||
|
"7B+",
|
||||||
|
"7C",
|
||||||
|
"7C+",
|
||||||
|
"8A",
|
||||||
|
"8A+",
|
||||||
|
"8B",
|
||||||
|
"8B+",
|
||||||
|
"8C",
|
||||||
|
"8C+"
|
||||||
|
)
|
||||||
|
YDS ->
|
||||||
|
listOf(
|
||||||
|
"5.0",
|
||||||
|
"5.1",
|
||||||
|
"5.2",
|
||||||
|
"5.3",
|
||||||
|
"5.4",
|
||||||
|
"5.5",
|
||||||
|
"5.6",
|
||||||
|
"5.7",
|
||||||
|
"5.8",
|
||||||
|
"5.9",
|
||||||
|
"5.10a",
|
||||||
|
"5.10b",
|
||||||
|
"5.10c",
|
||||||
|
"5.10d",
|
||||||
|
"5.11a",
|
||||||
|
"5.11b",
|
||||||
|
"5.11c",
|
||||||
|
"5.11d",
|
||||||
|
"5.12a",
|
||||||
|
"5.12b",
|
||||||
|
"5.12c",
|
||||||
|
"5.12d",
|
||||||
|
"5.13a",
|
||||||
|
"5.13b",
|
||||||
|
"5.13c",
|
||||||
|
"5.13d",
|
||||||
|
"5.14a",
|
||||||
|
"5.14b",
|
||||||
|
"5.14c",
|
||||||
|
"5.14d",
|
||||||
|
"5.15a",
|
||||||
|
"5.15b",
|
||||||
|
"5.15c",
|
||||||
|
"5.15d"
|
||||||
|
)
|
||||||
|
CUSTOM -> emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun systemsForClimbType(climbType: ClimbType): List<DifficultySystem> =
|
||||||
|
when (climbType) {
|
||||||
|
ClimbType.BOULDER -> entries.filter { it.isBoulderingSystem }
|
||||||
|
ClimbType.ROPE -> entries.filter { it.isRopeSystem }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class DifficultyGrade(val system: DifficultySystem, val grade: String, val numericValue: Int) {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
system: DifficultySystem,
|
||||||
|
grade: String
|
||||||
|
) : this(system = system, grade = grade, numericValue = calculateNumericValue(system, grade))
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private fun calculateNumericValue(system: DifficultySystem, grade: String): Int {
|
||||||
|
return when (system) {
|
||||||
|
DifficultySystem.V_SCALE -> {
|
||||||
|
if (grade == "VB") 0 else grade.removePrefix("V").toIntOrNull() ?: 0
|
||||||
|
}
|
||||||
|
DifficultySystem.FONT -> {
|
||||||
|
val fontMapping: Map<String, Int> =
|
||||||
|
mapOf(
|
||||||
|
"3" to 3,
|
||||||
|
"4A" to 4,
|
||||||
|
"4B" to 5,
|
||||||
|
"4C" to 6,
|
||||||
|
"5A" to 7,
|
||||||
|
"5B" to 8,
|
||||||
|
"5C" to 9,
|
||||||
|
"6A" to 10,
|
||||||
|
"6A+" to 11,
|
||||||
|
"6B" to 12,
|
||||||
|
"6B+" to 13,
|
||||||
|
"6C" to 14,
|
||||||
|
"6C+" to 15,
|
||||||
|
"7A" to 16,
|
||||||
|
"7A+" to 17,
|
||||||
|
"7B" to 18,
|
||||||
|
"7B+" to 19,
|
||||||
|
"7C" to 20,
|
||||||
|
"7C+" to 21,
|
||||||
|
"8A" to 22,
|
||||||
|
"8A+" to 23,
|
||||||
|
"8B" to 24,
|
||||||
|
"8B+" to 25,
|
||||||
|
"8C" to 26,
|
||||||
|
"8C+" to 27
|
||||||
|
)
|
||||||
|
fontMapping[grade] ?: 0
|
||||||
|
}
|
||||||
|
DifficultySystem.YDS -> {
|
||||||
|
val ydsMapping: Map<String, Int> =
|
||||||
|
mapOf(
|
||||||
|
"5.0" to 50,
|
||||||
|
"5.1" to 51,
|
||||||
|
"5.2" to 52,
|
||||||
|
"5.3" to 53,
|
||||||
|
"5.4" to 54,
|
||||||
|
"5.5" to 55,
|
||||||
|
"5.6" to 56,
|
||||||
|
"5.7" to 57,
|
||||||
|
"5.8" to 58,
|
||||||
|
"5.9" to 59,
|
||||||
|
"5.10a" to 60,
|
||||||
|
"5.10b" to 61,
|
||||||
|
"5.10c" to 62,
|
||||||
|
"5.10d" to 63,
|
||||||
|
"5.11a" to 64,
|
||||||
|
"5.11b" to 65,
|
||||||
|
"5.11c" to 66,
|
||||||
|
"5.11d" to 67,
|
||||||
|
"5.12a" to 68,
|
||||||
|
"5.12b" to 69,
|
||||||
|
"5.12c" to 70,
|
||||||
|
"5.12d" to 71,
|
||||||
|
"5.13a" to 72,
|
||||||
|
"5.13b" to 73,
|
||||||
|
"5.13c" to 74,
|
||||||
|
"5.13d" to 75,
|
||||||
|
"5.14a" to 76,
|
||||||
|
"5.14b" to 77,
|
||||||
|
"5.14c" to 78,
|
||||||
|
"5.14d" to 79,
|
||||||
|
"5.15a" to 80,
|
||||||
|
"5.15b" to 81,
|
||||||
|
"5.15c" to 82,
|
||||||
|
"5.15d" to 83
|
||||||
|
)
|
||||||
|
ydsMapping[grade] ?: 0
|
||||||
|
}
|
||||||
|
DifficultySystem.CUSTOM -> grade.toIntOrNull() ?: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Compare this grade with another grade of the same system Returns negative if this grade is
|
||||||
|
* easier, positive if harder, 0 if equal
|
||||||
|
*/
|
||||||
|
fun compareTo(other: DifficultyGrade): Int {
|
||||||
|
if (system != other.system) return 0
|
||||||
|
|
||||||
|
return when (system) {
|
||||||
|
DifficultySystem.V_SCALE -> compareVScaleGrades(grade, other.grade)
|
||||||
|
DifficultySystem.FONT -> compareFontGrades(grade, other.grade)
|
||||||
|
DifficultySystem.YDS -> compareYDSGrades(grade, other.grade)
|
||||||
|
DifficultySystem.CUSTOM -> grade.compareTo(other.grade)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun compareVScaleGrades(grade1: String, grade2: String): Int {
|
||||||
|
if (grade1 == "VB" && grade2 != "VB") return -1
|
||||||
|
if (grade2 == "VB" && grade1 != "VB") return 1
|
||||||
|
if (grade1 == "VB") return 0
|
||||||
|
|
||||||
|
val num1 = grade1.removePrefix("V").toIntOrNull() ?: 0
|
||||||
|
val num2 = grade2.removePrefix("V").toIntOrNull() ?: 0
|
||||||
|
return num1.compareTo(num2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun compareFontGrades(grade1: String, grade2: String): Int {
|
||||||
|
return grade1.compareTo(grade2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun compareYDSGrades(grade1: String, grade2: String): Int {
|
||||||
|
return grade1.compareTo(grade2)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.data.model
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Entity(tableName = "gyms")
|
@Entity(tableName = "gyms")
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.openclimb.data.model
|
package com.atridad.ascently.data.model
|
||||||
|
|
||||||
import androidx.room.Entity
|
import androidx.room.Entity
|
||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
@@ -1,25 +1,25 @@
|
|||||||
package com.atridad.openclimb.data.repository
|
package com.atridad.ascently.data.repository
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.atridad.openclimb.data.database.OpenClimbDatabase
|
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||||
import com.atridad.openclimb.data.format.BackupAttempt
|
import com.atridad.ascently.data.format.BackupAttempt
|
||||||
import com.atridad.openclimb.data.format.BackupClimbSession
|
import com.atridad.ascently.data.format.BackupClimbSession
|
||||||
import com.atridad.openclimb.data.format.BackupGym
|
import com.atridad.ascently.data.format.BackupGym
|
||||||
import com.atridad.openclimb.data.format.BackupProblem
|
import com.atridad.ascently.data.format.BackupProblem
|
||||||
import com.atridad.openclimb.data.format.ClimbDataBackup
|
import com.atridad.ascently.data.format.ClimbDataBackup
|
||||||
import com.atridad.openclimb.data.format.DeletedItem
|
import com.atridad.ascently.data.format.DeletedItem
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import com.atridad.openclimb.data.state.DataStateManager
|
import com.atridad.ascently.data.state.DataStateManager
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import com.atridad.openclimb.utils.ZipExportImportUtils
|
import com.atridad.ascently.utils.ZipExportImportUtils
|
||||||
import java.io.File
|
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
|
||||||
|
|
||||||
class ClimbRepository(database: OpenClimbDatabase, private val context: Context) {
|
class ClimbRepository(database: AscentlyDatabase, private val context: Context) {
|
||||||
private val gymDao = database.gymDao()
|
private val gymDao = database.gymDao()
|
||||||
private val problemDao = database.problemDao()
|
private val problemDao = database.problemDao()
|
||||||
private val sessionDao = database.climbSessionDao()
|
private val sessionDao = database.climbSessionDao()
|
||||||
@@ -157,7 +157,7 @@ class ClimbRepository(database: OpenClimbDatabase, private val context: Context)
|
|||||||
.filter { imagePath ->
|
.filter { imagePath ->
|
||||||
try {
|
try {
|
||||||
val imageFile =
|
val imageFile =
|
||||||
com.atridad.openclimb.utils.ImageUtils.getImageFile(
|
com.atridad.ascently.utils.ImageUtils.getImageFile(
|
||||||
context,
|
context,
|
||||||
imagePath
|
imagePath
|
||||||
)
|
)
|
||||||
@@ -251,23 +251,15 @@ class ClimbRepository(database: OpenClimbDatabase, private val context: Context)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the callback for auto-sync functionality. This should be called by the SyncService to
|
|
||||||
* register itself for auto-sync triggers.
|
|
||||||
*/
|
|
||||||
fun setAutoSyncCallback(callback: (() -> Unit)?) {
|
fun setAutoSyncCallback(callback: (() -> Unit)?) {
|
||||||
autoSyncCallback = callback
|
autoSyncCallback = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Triggers auto-sync if enabled. This is called after any data modification to keep data
|
|
||||||
* synchronized across devices automatically.
|
|
||||||
*/
|
|
||||||
private fun triggerAutoSync() {
|
private fun triggerAutoSync() {
|
||||||
autoSyncCallback?.invoke()
|
autoSyncCallback?.invoke()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun trackDeletion(itemId: String, itemType: String) {
|
fun trackDeletion(itemId: String, itemType: String) {
|
||||||
val currentDeletions = getDeletedItems().toMutableList()
|
val currentDeletions = getDeletedItems().toMutableList()
|
||||||
val newDeletion =
|
val newDeletion =
|
||||||
DeletedItem(id = itemId, type = itemType, deletedAt = DateFormatUtils.nowISO8601())
|
DeletedItem(id = itemId, type = itemType, deletedAt = DateFormatUtils.nowISO8601())
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.openclimb.data.state
|
package com.atridad.ascently.data.state
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the overall data state timestamp for sync purposes. This tracks when any data in the
|
* Manages the overall data state timestamp for sync purposes. This tracks when any data in the
|
||||||
@@ -14,7 +14,7 @@ class DataStateManager(context: Context) {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "DataStateManager"
|
private const val TAG = "DataStateManager"
|
||||||
private const val PREFS_NAME = "openclimb_data_state"
|
private const val PREFS_NAME = "ascently_data_state"
|
||||||
private const val KEY_LAST_MODIFIED = "last_modified_timestamp"
|
private const val KEY_LAST_MODIFIED = "last_modified_timestamp"
|
||||||
private const val KEY_INITIALIZED = "state_initialized"
|
private const val KEY_INITIALIZED = "state_initialized"
|
||||||
}
|
}
|
||||||
@@ -58,5 +58,4 @@ class DataStateManager(context: Context) {
|
|||||||
private fun markAsInitialized() {
|
private fun markAsInitialized() {
|
||||||
prefs.edit { putBoolean(KEY_INITIALIZED, true) }
|
prefs.edit { putBoolean(KEY_INITIALIZED, true) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.atridad.ascently.data.sync
|
||||||
|
|
||||||
|
import com.atridad.ascently.data.format.BackupAttempt
|
||||||
|
import com.atridad.ascently.data.format.BackupClimbSession
|
||||||
|
import com.atridad.ascently.data.format.BackupGym
|
||||||
|
import com.atridad.ascently.data.format.BackupProblem
|
||||||
|
import com.atridad.ascently.data.format.DeletedItem
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
/** Request structure for delta sync - sends only changes since last sync */
|
||||||
|
@Serializable
|
||||||
|
data class DeltaSyncRequest(
|
||||||
|
val lastSyncTime: String,
|
||||||
|
val gyms: List<BackupGym>,
|
||||||
|
val problems: List<BackupProblem>,
|
||||||
|
val sessions: List<BackupClimbSession>,
|
||||||
|
val attempts: List<BackupAttempt>,
|
||||||
|
val deletedItems: List<DeletedItem>
|
||||||
|
)
|
||||||
|
|
||||||
|
/** Response structure for delta sync - receives only changes from server */
|
||||||
|
@Serializable
|
||||||
|
data class DeltaSyncResponse(
|
||||||
|
val serverTime: String,
|
||||||
|
val gyms: List<BackupGym>,
|
||||||
|
val problems: List<BackupProblem>,
|
||||||
|
val sessions: List<BackupClimbSession>,
|
||||||
|
val attempts: List<BackupAttempt>,
|
||||||
|
val deletedItems: List<DeletedItem>
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.data.sync
|
package com.atridad.ascently.data.sync
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
@@ -7,18 +7,21 @@ import android.net.NetworkCapabilities
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.annotation.RequiresPermission
|
import androidx.annotation.RequiresPermission
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.atridad.openclimb.data.format.BackupAttempt
|
import com.atridad.ascently.data.format.BackupAttempt
|
||||||
import com.atridad.openclimb.data.format.BackupClimbSession
|
import com.atridad.ascently.data.format.BackupClimbSession
|
||||||
import com.atridad.openclimb.data.format.BackupGym
|
import com.atridad.ascently.data.format.BackupGym
|
||||||
import com.atridad.openclimb.data.format.BackupProblem
|
import com.atridad.ascently.data.format.BackupProblem
|
||||||
import com.atridad.openclimb.data.format.ClimbDataBackup
|
import com.atridad.ascently.data.format.ClimbDataBackup
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import com.atridad.openclimb.data.state.DataStateManager
|
import com.atridad.ascently.data.state.DataStateManager
|
||||||
import com.atridad.openclimb.utils.DateFormatUtils
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import com.atridad.openclimb.utils.ImageNamingUtils
|
import com.atridad.ascently.utils.ImageNamingUtils
|
||||||
import com.atridad.openclimb.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -63,6 +66,7 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
prettyPrint = true
|
prettyPrint = true
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
explicitNulls = false
|
explicitNulls = false
|
||||||
|
coerceInputValues = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// State
|
// State
|
||||||
@@ -130,17 +134,6 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
sharedPreferences.edit { putBoolean(Keys.IS_CONNECTED, false) }
|
sharedPreferences.edit { putBoolean(Keys.IS_CONNECTED, false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Legacy accessor expected by some UI code (kept for compatibility)
|
|
||||||
@Deprecated(
|
|
||||||
message = "Use serverUrl (kebab case) instead",
|
|
||||||
replaceWith = ReplaceWith("serverUrl")
|
|
||||||
)
|
|
||||||
var serverURL: String
|
|
||||||
get() = serverUrl
|
|
||||||
set(value) {
|
|
||||||
serverUrl = value
|
|
||||||
}
|
|
||||||
|
|
||||||
var authToken: String
|
var authToken: String
|
||||||
get() = sharedPreferences.getString(Keys.AUTH_TOKEN, "") ?: ""
|
get() = sharedPreferences.getString(Keys.AUTH_TOKEN, "") ?: ""
|
||||||
set(value) {
|
set(value) {
|
||||||
@@ -206,6 +199,12 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
serverBackup.sessions.isNotEmpty() ||
|
serverBackup.sessions.isNotEmpty() ||
|
||||||
serverBackup.attempts.isNotEmpty()
|
serverBackup.attempts.isNotEmpty()
|
||||||
|
|
||||||
|
// If both client and server have been synced before, use delta sync
|
||||||
|
val lastSyncTimeStr = sharedPreferences.getString(Keys.LAST_SYNC_TIME, null)
|
||||||
|
if (hasLocalData && hasServerData && lastSyncTimeStr != null) {
|
||||||
|
Log.d(TAG, "Using delta sync for incremental updates")
|
||||||
|
performDeltaSync(lastSyncTimeStr)
|
||||||
|
} else {
|
||||||
when {
|
when {
|
||||||
!hasLocalData && hasServerData -> {
|
!hasLocalData && hasServerData -> {
|
||||||
Log.d(TAG, "No local data found, performing full restore from server")
|
Log.d(TAG, "No local data found, performing full restore from server")
|
||||||
@@ -228,6 +227,7 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
Log.d(TAG, "No data to sync")
|
Log.d(TAG, "No data to sync")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val now = DateFormatUtils.nowISO8601()
|
val now = DateFormatUtils.nowISO8601()
|
||||||
_lastSyncTime.value = now
|
_lastSyncTime.value = now
|
||||||
@@ -241,6 +241,265 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private suspend fun performDeltaSync(lastSyncTimeStr: String) {
|
||||||
|
Log.d(TAG, "Starting delta sync with lastSyncTime=$lastSyncTimeStr")
|
||||||
|
|
||||||
|
// Parse last sync time to filter modified items
|
||||||
|
val lastSyncDate = parseISO8601(lastSyncTimeStr) ?: Date(0)
|
||||||
|
|
||||||
|
// Collect items modified since last sync
|
||||||
|
val allGyms = repository.getAllGyms().first()
|
||||||
|
val modifiedGyms =
|
||||||
|
allGyms
|
||||||
|
.filter { gym -> parseISO8601(gym.updatedAt)?.after(lastSyncDate) == true }
|
||||||
|
.map { BackupGym.fromGym(it) }
|
||||||
|
|
||||||
|
val allProblems = repository.getAllProblems().first()
|
||||||
|
val modifiedProblems =
|
||||||
|
allProblems
|
||||||
|
.filter { problem ->
|
||||||
|
parseISO8601(problem.updatedAt)?.after(lastSyncDate) == true
|
||||||
|
}
|
||||||
|
.map { problem ->
|
||||||
|
val backupProblem = BackupProblem.fromProblem(problem)
|
||||||
|
val normalizedImagePaths =
|
||||||
|
problem.imagePaths.mapIndexed { index, _ ->
|
||||||
|
ImageNamingUtils.generateImageFilename(problem.id, index)
|
||||||
|
}
|
||||||
|
if (normalizedImagePaths.isNotEmpty()) {
|
||||||
|
backupProblem.copy(imagePaths = normalizedImagePaths)
|
||||||
|
} else {
|
||||||
|
backupProblem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val allSessions = repository.getAllSessions().first()
|
||||||
|
val modifiedSessions =
|
||||||
|
allSessions
|
||||||
|
.filter { session ->
|
||||||
|
parseISO8601(session.updatedAt)?.after(lastSyncDate) == true
|
||||||
|
}
|
||||||
|
.map { BackupClimbSession.fromClimbSession(it) }
|
||||||
|
|
||||||
|
val allAttempts = repository.getAllAttempts().first()
|
||||||
|
val modifiedAttempts =
|
||||||
|
allAttempts
|
||||||
|
.filter { attempt ->
|
||||||
|
parseISO8601(attempt.createdAt)?.after(lastSyncDate) == true
|
||||||
|
}
|
||||||
|
.map { BackupAttempt.fromAttempt(it) }
|
||||||
|
|
||||||
|
val allDeletions = repository.getDeletedItems()
|
||||||
|
val modifiedDeletions =
|
||||||
|
allDeletions.filter { item ->
|
||||||
|
parseISO8601(item.deletedAt)?.after(lastSyncDate) == true
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"Delta sync sending: gyms=${modifiedGyms.size}, problems=${modifiedProblems.size}, sessions=${modifiedSessions.size}, attempts=${modifiedAttempts.size}, deletions=${modifiedDeletions.size}"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Create delta request
|
||||||
|
val deltaRequest =
|
||||||
|
DeltaSyncRequest(
|
||||||
|
lastSyncTime = lastSyncTimeStr,
|
||||||
|
gyms = modifiedGyms,
|
||||||
|
problems = modifiedProblems,
|
||||||
|
sessions = modifiedSessions,
|
||||||
|
attempts = modifiedAttempts,
|
||||||
|
deletedItems = modifiedDeletions
|
||||||
|
)
|
||||||
|
|
||||||
|
val requestBody =
|
||||||
|
json.encodeToString(DeltaSyncRequest.serializer(), deltaRequest)
|
||||||
|
.toRequestBody("application/json".toMediaType())
|
||||||
|
|
||||||
|
val request =
|
||||||
|
Request.Builder()
|
||||||
|
.url("$serverUrl/sync/delta")
|
||||||
|
.header("Authorization", "Bearer $authToken")
|
||||||
|
.post(requestBody)
|
||||||
|
.build()
|
||||||
|
|
||||||
|
val deltaResponse =
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
|
httpClient.newCall(request).execute().use { response ->
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
val body = response.body?.string()
|
||||||
|
if (!body.isNullOrEmpty()) {
|
||||||
|
json.decodeFromString(DeltaSyncResponse.serializer(), body)
|
||||||
|
} else {
|
||||||
|
throw SyncException.InvalidResponse("Empty response body")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
handleHttpError(response.code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: IOException) {
|
||||||
|
throw SyncException.NetworkError(e.message ?: "Network error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.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}"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Apply server changes to local data
|
||||||
|
applyDeltaResponse(deltaResponse)
|
||||||
|
|
||||||
|
// Sync only modified problem images
|
||||||
|
syncModifiedImages(modifiedProblems)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseISO8601(dateString: String): Date? {
|
||||||
|
return try {
|
||||||
|
val format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
||||||
|
format.parse(dateString)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun applyDeltaResponse(response: DeltaSyncResponse) {
|
||||||
|
// Temporarily disable auto-sync to prevent recursive sync triggers
|
||||||
|
repository.setAutoSyncCallback(null)
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Download images for new/modified problems from server
|
||||||
|
val imagePathMapping = mutableMapOf<String, String>()
|
||||||
|
for (problem in response.problems) {
|
||||||
|
problem.imagePaths?.forEach { imagePath ->
|
||||||
|
val serverFilename = imagePath.substringAfterLast('/')
|
||||||
|
try {
|
||||||
|
val localImagePath = downloadImage(serverFilename)
|
||||||
|
if (localImagePath != null) {
|
||||||
|
imagePathMapping[imagePath] = localImagePath
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "Failed to download image $imagePath: ${e.message}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge gyms - check if exists and compare timestamps
|
||||||
|
val existingGyms = repository.getAllGyms().first()
|
||||||
|
for (backupGym in response.gyms) {
|
||||||
|
val existing = existingGyms.find { it.id == backupGym.id }
|
||||||
|
if (existing == null || backupGym.updatedAt >= existing.updatedAt) {
|
||||||
|
val gym = backupGym.toGym()
|
||||||
|
if (existing != null) {
|
||||||
|
repository.updateGym(gym)
|
||||||
|
} else {
|
||||||
|
repository.insertGym(gym)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge problems
|
||||||
|
val existingProblems = repository.getAllProblems().first()
|
||||||
|
for (backupProblem in response.problems) {
|
||||||
|
val updatedImagePaths =
|
||||||
|
backupProblem.imagePaths?.map { oldPath ->
|
||||||
|
imagePathMapping[oldPath] ?: oldPath
|
||||||
|
}
|
||||||
|
val problemToMerge = backupProblem.copy(imagePaths = updatedImagePaths)
|
||||||
|
val problem = problemToMerge.toProblem()
|
||||||
|
|
||||||
|
val existing = existingProblems.find { it.id == backupProblem.id }
|
||||||
|
if (existing == null || backupProblem.updatedAt >= existing.updatedAt) {
|
||||||
|
if (existing != null) {
|
||||||
|
repository.updateProblem(problem)
|
||||||
|
} else {
|
||||||
|
repository.insertProblem(problem)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge sessions
|
||||||
|
val existingSessions = repository.getAllSessions().first()
|
||||||
|
for (backupSession in response.sessions) {
|
||||||
|
val session = backupSession.toClimbSession()
|
||||||
|
val existing = existingSessions.find { it.id == backupSession.id }
|
||||||
|
if (existing == null || backupSession.updatedAt >= existing.updatedAt) {
|
||||||
|
if (existing != null) {
|
||||||
|
repository.updateSession(session)
|
||||||
|
} else {
|
||||||
|
repository.insertSession(session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Merge attempts
|
||||||
|
val existingAttempts = repository.getAllAttempts().first()
|
||||||
|
for (backupAttempt in response.attempts) {
|
||||||
|
val attempt = backupAttempt.toAttempt()
|
||||||
|
val existing = existingAttempts.find { it.id == backupAttempt.id }
|
||||||
|
if (existing == null || backupAttempt.createdAt >= existing.createdAt) {
|
||||||
|
if (existing != null) {
|
||||||
|
repository.updateAttempt(attempt)
|
||||||
|
} else {
|
||||||
|
repository.insertAttempt(attempt)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply deletions
|
||||||
|
applyDeletions(response.deletedItems)
|
||||||
|
|
||||||
|
// Update deletion records
|
||||||
|
val allDeletions = repository.getDeletedItems() + response.deletedItems
|
||||||
|
repository.clearDeletedItems()
|
||||||
|
allDeletions.distinctBy { "${it.type}:${it.id}" }.forEach {
|
||||||
|
repository.trackDeletion(it.id, it.type)
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// Re-enable auto-sync
|
||||||
|
repository.setAutoSyncCallback { serviceScope.launch { triggerAutoSync() } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun applyDeletions(
|
||||||
|
deletions: List<com.atridad.ascently.data.format.DeletedItem>
|
||||||
|
) {
|
||||||
|
val existingGyms = repository.getAllGyms().first()
|
||||||
|
val existingProblems = repository.getAllProblems().first()
|
||||||
|
val existingSessions = repository.getAllSessions().first()
|
||||||
|
val existingAttempts = repository.getAllAttempts().first()
|
||||||
|
|
||||||
|
for (item in deletions) {
|
||||||
|
when (item.type) {
|
||||||
|
"gym" -> {
|
||||||
|
existingGyms.find { it.id == item.id }?.let { repository.deleteGym(it) }
|
||||||
|
}
|
||||||
|
"problem" -> {
|
||||||
|
existingProblems.find { it.id == item.id }?.let { repository.deleteProblem(it) }
|
||||||
|
}
|
||||||
|
"session" -> {
|
||||||
|
existingSessions.find { it.id == item.id }?.let { repository.deleteSession(it) }
|
||||||
|
}
|
||||||
|
"attempt" -> {
|
||||||
|
existingAttempts.find { it.id == item.id }?.let { repository.deleteAttempt(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun syncModifiedImages(modifiedProblems: List<BackupProblem>) {
|
||||||
|
if (modifiedProblems.isEmpty()) return
|
||||||
|
|
||||||
|
Log.d(TAG, "Syncing images for ${modifiedProblems.size} modified problems")
|
||||||
|
|
||||||
|
for (backupProblem in modifiedProblems) {
|
||||||
|
backupProblem.imagePaths?.forEach { imagePath ->
|
||||||
|
val filename = imagePath.substringAfterLast('/')
|
||||||
|
uploadImage(imagePath, filename)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun downloadData(): ClimbDataBackup {
|
private suspend fun downloadData(): ClimbDataBackup {
|
||||||
val request =
|
val request =
|
||||||
Request.Builder()
|
Request.Builder()
|
||||||
@@ -277,8 +536,7 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
|
|
||||||
private suspend fun uploadData(backup: ClimbDataBackup) {
|
private suspend fun uploadData(backup: ClimbDataBackup) {
|
||||||
val requestBody =
|
val requestBody =
|
||||||
json.encodeToString(ClimbDataBackup.serializer(), backup)
|
json.encodeToString(backup).toRequestBody("application/json".toMediaType())
|
||||||
.toRequestBody("application/json".toMediaType())
|
|
||||||
|
|
||||||
val request =
|
val request =
|
||||||
Request.Builder()
|
Request.Builder()
|
||||||
@@ -440,9 +698,7 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
backup.problems.map { backupProblem ->
|
backup.problems.map { backupProblem ->
|
||||||
val imagePaths = backupProblem.imagePaths
|
val imagePaths = backupProblem.imagePaths
|
||||||
val updatedImagePaths =
|
val updatedImagePaths =
|
||||||
imagePaths?.map { oldPath ->
|
imagePaths?.map { oldPath -> imagePathMapping[oldPath] ?: oldPath }
|
||||||
imagePathMapping[oldPath] ?: oldPath
|
|
||||||
}
|
|
||||||
backupProblem.copy(imagePaths = updatedImagePaths).toProblem()
|
backupProblem.copy(imagePaths = updatedImagePaths).toProblem()
|
||||||
}
|
}
|
||||||
val sessions = backup.sessions.map { it.toClimbSession() }
|
val sessions = backup.sessions.map { it.toClimbSession() }
|
||||||
@@ -544,26 +800,16 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
|||||||
|
|
||||||
sealed class SyncException(message: String) : IOException(message), Serializable {
|
sealed class SyncException(message: String) : IOException(message), Serializable {
|
||||||
object NotConfigured :
|
object NotConfigured :
|
||||||
SyncException("Sync is not configured. Please set server URL and auth token.") {
|
SyncException("Sync is not configured. Please set server URL and auth token.")
|
||||||
@JvmStatic private fun readResolve(): Any = NotConfigured
|
|
||||||
}
|
|
||||||
|
|
||||||
object NotConnected : SyncException("Not connected to server. Please test connection first.") {
|
object NotConnected : SyncException("Not connected to server. Please test connection first.")
|
||||||
@JvmStatic private fun readResolve(): Any = NotConnected
|
|
||||||
}
|
|
||||||
|
|
||||||
object Unauthorized : SyncException("Unauthorized. Please check your auth token.") {
|
object Unauthorized : SyncException("Unauthorized. Please check your auth token.")
|
||||||
@JvmStatic private fun readResolve(): Any = Unauthorized
|
|
||||||
}
|
|
||||||
|
|
||||||
object ImageNotFound : SyncException("Image not found on server") {
|
object ImageNotFound : SyncException("Image not found on server")
|
||||||
@JvmStatic private fun readResolve(): Any = ImageNotFound
|
|
||||||
}
|
|
||||||
|
|
||||||
data class ServerError(val code: Int) : SyncException("Server error: HTTP $code")
|
data class ServerError(val code: Int) : SyncException("Server error: HTTP $code")
|
||||||
data class InvalidResponse(val details: String) :
|
data class InvalidResponse(val details: String) :
|
||||||
SyncException("Invalid server response: $details")
|
SyncException("Invalid server response: $details")
|
||||||
data class DecodingError(val details: String) :
|
|
||||||
SyncException("Failed to decode server response: $details")
|
|
||||||
data class NetworkError(val details: String) : SyncException("Network error: $details")
|
data class NetworkError(val details: String) : SyncException("Network error: $details")
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.navigation
|
package com.atridad.ascently.navigation
|
||||||
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.navigation
|
package com.atridad.ascently.navigation
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.service
|
package com.atridad.ascently.service
|
||||||
|
|
||||||
import android.app.NotificationChannel
|
import android.app.NotificationChannel
|
||||||
import android.app.NotificationManager
|
import android.app.NotificationManager
|
||||||
@@ -8,10 +8,10 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.atridad.openclimb.MainActivity
|
import com.atridad.ascently.MainActivity
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.database.OpenClimbDatabase
|
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
@@ -52,7 +52,7 @@ class SessionTrackingService : Service() {
|
|||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
|
|
||||||
val database = OpenClimbDatabase.getDatabase(this)
|
val database = AscentlyDatabase.getDatabase(this)
|
||||||
repository = ClimbRepository(database, this)
|
repository = ClimbRepository(database, this)
|
||||||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
@@ -75,8 +75,8 @@ class SessionTrackingService : Service() {
|
|||||||
sessionId != null -> repository.getSessionById(sessionId)
|
sessionId != null -> repository.getSessionById(sessionId)
|
||||||
else -> repository.getActiveSession()
|
else -> repository.getActiveSession()
|
||||||
}
|
}
|
||||||
if (targetSession != null && targetSession.status == com.atridad.openclimb.data.model.SessionStatus.ACTIVE) {
|
if (targetSession != null && targetSession.status == com.atridad.ascently.data.model.SessionStatus.ACTIVE) {
|
||||||
val completed = with(com.atridad.openclimb.data.model.ClimbSession) { targetSession.complete() }
|
val completed = with(com.atridad.ascently.data.model.ClimbSession) { targetSession.complete() }
|
||||||
repository.updateSession(completed)
|
repository.updateSession(completed)
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -127,7 +127,7 @@ class SessionTrackingService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val session = repository.getSessionById(sessionId)
|
val session = repository.getSessionById(sessionId)
|
||||||
if (session == null || session.status != com.atridad.openclimb.data.model.SessionStatus.ACTIVE) {
|
if (session == null || session.status != com.atridad.ascently.data.model.SessionStatus.ACTIVE) {
|
||||||
stopSessionTracking()
|
stopSessionTracking()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ class SessionTrackingService : Service() {
|
|||||||
val session = runBlocking {
|
val session = runBlocking {
|
||||||
repository.getSessionById(sessionId)
|
repository.getSessionById(sessionId)
|
||||||
}
|
}
|
||||||
if (session == null || session.status != com.atridad.openclimb.data.model.SessionStatus.ACTIVE) {
|
if (session == null || session.status != com.atridad.ascently.data.model.SessionStatus.ACTIVE) {
|
||||||
stopSessionTracking()
|
stopSessionTracking()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui
|
package com.atridad.ascently.ui
|
||||||
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
@@ -17,21 +17,21 @@ import androidx.navigation.compose.composable
|
|||||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import androidx.navigation.toRoute
|
import androidx.navigation.toRoute
|
||||||
import com.atridad.openclimb.data.database.OpenClimbDatabase
|
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import com.atridad.openclimb.data.sync.SyncService
|
import com.atridad.ascently.data.sync.SyncService
|
||||||
import com.atridad.openclimb.navigation.Screen
|
import com.atridad.ascently.navigation.Screen
|
||||||
import com.atridad.openclimb.navigation.bottomNavigationItems
|
import com.atridad.ascently.navigation.bottomNavigationItems
|
||||||
import com.atridad.openclimb.ui.components.NotificationPermissionDialog
|
import com.atridad.ascently.ui.components.NotificationPermissionDialog
|
||||||
import com.atridad.openclimb.ui.screens.*
|
import com.atridad.ascently.ui.screens.*
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModelFactory
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModelFactory
|
||||||
import com.atridad.openclimb.utils.AppShortcutManager
|
import com.atridad.ascently.utils.AppShortcutManager
|
||||||
import com.atridad.openclimb.utils.NotificationPermissionUtils
|
import com.atridad.ascently.utils.NotificationPermissionUtils
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun OpenClimbApp(
|
fun AscentlyApp(
|
||||||
shortcutAction: String? = null,
|
shortcutAction: String? = null,
|
||||||
lastUsedGymId: String? = null,
|
lastUsedGymId: String? = null,
|
||||||
onShortcutActionProcessed: () -> Unit = {}
|
onShortcutActionProcessed: () -> Unit = {}
|
||||||
@@ -39,9 +39,9 @@ fun OpenClimbApp(
|
|||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
var lastUsedGym by remember { mutableStateOf<com.atridad.openclimb.data.model.Gym?>(null) }
|
var lastUsedGym by remember { mutableStateOf<com.atridad.ascently.data.model.Gym?>(null) }
|
||||||
|
|
||||||
val database = remember { OpenClimbDatabase.getDatabase(context) }
|
val database = remember { AscentlyDatabase.getDatabase(context) }
|
||||||
val repository = remember { ClimbRepository(database, context) }
|
val repository = remember { ClimbRepository(database, context) }
|
||||||
val syncService = remember { SyncService(context, repository) }
|
val syncService = remember { SyncService(context, repository) }
|
||||||
val viewModel: ClimbViewModel =
|
val viewModel: ClimbViewModel =
|
||||||
@@ -115,7 +115,7 @@ fun OpenClimbApp(
|
|||||||
LaunchedEffect(shortcutAction, activeSession, gyms, lastUsedGym) {
|
LaunchedEffect(shortcutAction, activeSession, gyms, lastUsedGym) {
|
||||||
if (shortcutAction == AppShortcutManager.ACTION_START_SESSION && gyms.isNotEmpty()) {
|
if (shortcutAction == AppShortcutManager.ACTION_START_SESSION && gyms.isNotEmpty()) {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"OpenClimbApp",
|
"AscentlyApp",
|
||||||
"Processing shortcut action: activeSession=$activeSession, gyms.size=${gyms.size}, lastUsedGymId=$lastUsedGymId, lastUsedGym=${lastUsedGym?.name}"
|
"Processing shortcut action: activeSession=$activeSession, gyms.size=${gyms.size}, lastUsedGymId=$lastUsedGymId, lastUsedGym=${lastUsedGym?.name}"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -125,12 +125,12 @@ fun OpenClimbApp(
|
|||||||
context
|
context
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
android.util.Log.d("OpenClimbApp", "Showing notification permission dialog")
|
android.util.Log.d("AscentlyApp", "Showing notification permission dialog")
|
||||||
showNotificationPermissionDialog = true
|
showNotificationPermissionDialog = true
|
||||||
} else {
|
} else {
|
||||||
if (gyms.size == 1) {
|
if (gyms.size == 1) {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"OpenClimbApp",
|
"AscentlyApp",
|
||||||
"Starting session with single gym: ${gyms.first().name}"
|
"Starting session with single gym: ${gyms.first().name}"
|
||||||
)
|
)
|
||||||
viewModel.startSession(context, gyms.first().id)
|
viewModel.startSession(context, gyms.first().id)
|
||||||
@@ -141,13 +141,13 @@ fun OpenClimbApp(
|
|||||||
|
|
||||||
if (targetGym != null) {
|
if (targetGym != null) {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"OpenClimbApp",
|
"AscentlyApp",
|
||||||
"Starting session with target gym: ${targetGym.name}"
|
"Starting session with target gym: ${targetGym.name}"
|
||||||
)
|
)
|
||||||
viewModel.startSession(context, targetGym.id)
|
viewModel.startSession(context, targetGym.id)
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"OpenClimbApp",
|
"AscentlyApp",
|
||||||
"No target gym found, navigating to selection"
|
"No target gym found, navigating to selection"
|
||||||
)
|
)
|
||||||
navController.navigate(Screen.AddEditSession())
|
navController.navigate(Screen.AddEditSession())
|
||||||
@@ -156,7 +156,7 @@ fun OpenClimbApp(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
android.util.Log.d(
|
android.util.Log.d(
|
||||||
"OpenClimbApp",
|
"AscentlyApp",
|
||||||
"Active session already exists: ${activeSession?.id}"
|
"Active session already exists: ${activeSession?.id}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ fun OpenClimbApp(
|
|||||||
var fabConfig by remember { mutableStateOf<FabConfig?>(null) }
|
var fabConfig by remember { mutableStateOf<FabConfig?>(null) }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = { OpenClimbBottomNavigation(navController = navController) },
|
bottomBar = { AscentlyBottomNavigation(navController = navController) },
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
fabConfig?.let { config ->
|
fabConfig?.let { config ->
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
@@ -363,7 +363,7 @@ fun OpenClimbApp(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OpenClimbBottomNavigation(navController: NavHostController) {
|
fun AscentlyBottomNavigation(navController: NavHostController) {
|
||||||
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
||||||
val currentRoute = navBackStackEntry?.destination?.route
|
val currentRoute = navBackStackEntry?.destination?.route
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@@ -10,9 +10,9 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.openclimb.data.model.Gym
|
import com.atridad.ascently.data.model.Gym
|
||||||
import com.atridad.openclimb.ui.theme.CustomIcons
|
import com.atridad.ascently.ui.theme.CustomIcons
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.temporal.ChronoUnit
|
import java.time.temporal.ChronoUnit
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
|
import androidx.activity.compose.BackHandler
|
||||||
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.layout.systemBarsPadding
|
||||||
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.layout.ContentScale
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
@Composable
|
||||||
|
fun FullscreenImageViewer(imagePaths: List<String>, initialIndex: Int = 0, onDismiss: () -> Unit) {
|
||||||
|
val pagerState = rememberPagerState(initialPage = initialIndex, pageCount = { imagePaths.size })
|
||||||
|
val thumbnailListState = rememberLazyListState()
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
// Handle back button press
|
||||||
|
BackHandler { onDismiss() }
|
||||||
|
|
||||||
|
// Auto-scroll thumbnail list to center current image
|
||||||
|
LaunchedEffect(pagerState.currentPage) {
|
||||||
|
if (imagePaths.size > 1) {
|
||||||
|
thumbnailListState.animateScrollToItem(
|
||||||
|
index = pagerState.currentPage,
|
||||||
|
scrollOffset = -200
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
properties =
|
||||||
|
DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = true)
|
||||||
|
) {
|
||||||
|
Box(modifier = Modifier.fillMaxSize().background(Color.Black).systemBarsPadding()) {
|
||||||
|
// Main image pager
|
||||||
|
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
|
||||||
|
OrientationAwareImage(
|
||||||
|
imagePath = imagePaths[page],
|
||||||
|
contentDescription = "Full screen image",
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentScale = ContentScale.Fit
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Top bar with back button and counter
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxWidth().align(Alignment.TopStart),
|
||||||
|
color = Color.Black.copy(alpha = 0.6f)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxWidth().padding(horizontal = 4.dp, vertical = 8.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
// Back button
|
||||||
|
IconButton(onClick = onDismiss) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Close",
|
||||||
|
tint = Color.White
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
// Image counter
|
||||||
|
if (imagePaths.size > 1) {
|
||||||
|
Text(
|
||||||
|
text = "${pagerState.currentPage + 1} / ${imagePaths.size}",
|
||||||
|
color = Color.White,
|
||||||
|
style = MaterialTheme.typography.bodyMedium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thumbnail strip at bottom (if multiple images)
|
||||||
|
if (imagePaths.size > 1) {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxWidth().align(Alignment.BottomCenter),
|
||||||
|
color = Color.Black.copy(alpha = 0.6f)
|
||||||
|
) {
|
||||||
|
LazyRow(
|
||||||
|
state = thumbnailListState,
|
||||||
|
modifier = Modifier.padding(vertical = 12.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
|
contentPadding = PaddingValues(horizontal = 16.dp)
|
||||||
|
) {
|
||||||
|
itemsIndexed(imagePaths) { index, imagePath ->
|
||||||
|
val isSelected = index == pagerState.currentPage
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.size(48.dp)
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.clickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
pagerState.animateScrollToPage(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
OrientationAwareImage(
|
||||||
|
imagePath = imagePath,
|
||||||
|
contentDescription = "Thumbnail ${index + 1}",
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
|
||||||
|
// Selection indicator
|
||||||
|
if (isSelected) {
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxSize()
|
||||||
|
.background(
|
||||||
|
Color.White.copy(alpha = 0.3f),
|
||||||
|
RoundedCornerShape(8.dp)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier =
|
||||||
|
Modifier.fillMaxSize()
|
||||||
|
.background(
|
||||||
|
Color.Transparent,
|
||||||
|
RoundedCornerShape(8.dp)
|
||||||
|
)
|
||||||
|
.clip(RoundedCornerShape(8.dp))
|
||||||
|
.background(
|
||||||
|
Color.White.copy(alpha = 0.2f)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
@@ -20,7 +20,7 @@ fun ImageDisplay(
|
|||||||
imageSize: Int = 120,
|
imageSize: Int = 120,
|
||||||
onImageClick: ((Int) -> Unit)? = null
|
onImageClick: ((Int) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
LocalContext.current
|
||||||
|
|
||||||
if (imagePaths.isNotEmpty()) {
|
if (imagePaths.isNotEmpty()) {
|
||||||
LazyRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(modifier = modifier, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
@@ -25,7 +25,7 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
import com.atridad.openclimb.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -255,7 +255,7 @@ private fun createImageFile(context: android.content.Context): File {
|
|||||||
@Composable
|
@Composable
|
||||||
private fun ImageItem(imagePath: String, onRemove: () -> Unit, modifier: Modifier = Modifier) {
|
private fun ImageItem(imagePath: String, onRemove: () -> Unit, modifier: Modifier = Modifier) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val imageFile = ImageUtils.getImageFile(context, imagePath)
|
ImageUtils.getImageFile(context, imagePath)
|
||||||
|
|
||||||
Box(modifier = modifier.size(80.dp)) {
|
Box(modifier = modifier.size(80.dp)) {
|
||||||
OrientationAwareImage(
|
OrientationAwareImage(
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Notifications
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.Dialog
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun NotificationPermissionDialog(onDismiss: () -> Unit, onRequestPermission: () -> Unit) {
|
||||||
|
Dialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
properties = DialogProperties(dismissOnBackPress = false, dismissOnClickOutside = false)
|
||||||
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
||||||
|
shape = MaterialTheme.shapes.medium
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.padding(24.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Notifications,
|
||||||
|
contentDescription = "Notifications",
|
||||||
|
modifier = Modifier.size(48.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.primary
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Enable Notifications",
|
||||||
|
style = MaterialTheme.typography.headlineSmall,
|
||||||
|
fontWeight = MaterialTheme.typography.headlineSmall.fontWeight,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
|
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.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||||
|
) {
|
||||||
|
TextButton(onClick = onDismiss, modifier = Modifier.weight(1f)) {
|
||||||
|
Text("Not Now")
|
||||||
|
}
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
onRequestPermission()
|
||||||
|
onDismiss()
|
||||||
|
},
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
|
) { Text("Enable") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.graphics.Matrix
|
import android.graphics.Matrix
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.asImageBitmap
|
import androidx.compose.ui.graphics.asImageBitmap
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
import com.atridad.openclimb.utils.ImageUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
@@ -20,8 +23,8 @@ import kotlinx.coroutines.withContext
|
|||||||
@Composable
|
@Composable
|
||||||
fun OrientationAwareImage(
|
fun OrientationAwareImage(
|
||||||
imagePath: String,
|
imagePath: String,
|
||||||
contentDescription: String? = null,
|
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
contentDescription: String? = null,
|
||||||
contentScale: ContentScale = ContentScale.Fit
|
contentScale: ContentScale = ContentScale.Fit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -42,7 +45,7 @@ fun OrientationAwareImage(
|
|||||||
?: return@withContext null
|
?: return@withContext null
|
||||||
val correctedBitmap = correctImageOrientation(imageFile, originalBitmap)
|
val correctedBitmap = correctImageOrientation(imageFile, originalBitmap)
|
||||||
correctedBitmap.asImageBitmap()
|
correctedBitmap.asImageBitmap()
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,7 @@ fun OrientationAwareImage(
|
|||||||
|
|
||||||
Box(modifier = modifier) {
|
Box(modifier = modifier) {
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
CircularProgressIndicator(modifier = Modifier.fillMaxSize())
|
CircularProgressIndicator(modifier = Modifier.size(32.dp).align(Alignment.Center))
|
||||||
} else {
|
} else {
|
||||||
imageBitmap?.let { bitmap ->
|
imageBitmap?.let { bitmap ->
|
||||||
Image(
|
Image(
|
||||||
@@ -113,15 +116,7 @@ private fun correctImageOrientation(
|
|||||||
needsTransform = true
|
needsTransform = true
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
if (orientation == ExifInterface.ORIENTATION_UNDEFINED || orientation == 0) {
|
// Default case - no transformation needed
|
||||||
if (imageFile.name.startsWith("problem_") &&
|
|
||||||
imageFile.name.contains("_") &&
|
|
||||||
imageFile.name.endsWith(".jpg")
|
|
||||||
) {
|
|
||||||
matrix.postRotate(90f)
|
|
||||||
needsTransform = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +138,7 @@ private fun correctImageOrientation(
|
|||||||
}
|
}
|
||||||
rotatedBitmap
|
rotatedBitmap
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
bitmap
|
bitmap
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
package com.atridad.ascently.ui.components
|
||||||
|
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
@@ -0,0 +1,297 @@
|
|||||||
|
package com.atridad.ascently.ui.health
|
||||||
|
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.*
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import com.atridad.ascently.data.health.HealthConnectManager
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun HealthConnectCard(modifier: Modifier = Modifier) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val healthConnectManager = remember { HealthConnectManager(context) }
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
// State tracking
|
||||||
|
var isHealthConnectAvailable by remember { mutableStateOf(false) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var errorMessage by remember { mutableStateOf<String?>(null) }
|
||||||
|
|
||||||
|
// Collect flows
|
||||||
|
val isEnabled by healthConnectManager.isEnabled.collectAsState(initial = false)
|
||||||
|
val hasPermissions by healthConnectManager.hasPermissions.collectAsState(initial = false)
|
||||||
|
|
||||||
|
val isCompatible by healthConnectManager.isCompatible.collectAsState(initial = true)
|
||||||
|
|
||||||
|
// Permission launcher
|
||||||
|
val permissionLauncher =
|
||||||
|
rememberLauncherForActivityResult(
|
||||||
|
contract = healthConnectManager.getPermissionRequestContract()
|
||||||
|
) { _ ->
|
||||||
|
coroutineScope.launch {
|
||||||
|
val allGranted = healthConnectManager.hasAllPermissions()
|
||||||
|
if (!allGranted) {
|
||||||
|
errorMessage =
|
||||||
|
"Some Health Connect permissions were not granted. Please grant all permissions to enable syncing."
|
||||||
|
} else {
|
||||||
|
errorMessage = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check Health Connect availability on first load
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
coroutineScope.launch {
|
||||||
|
try {
|
||||||
|
healthConnectManager.isHealthConnectAvailable().collect { available ->
|
||||||
|
isHealthConnectAvailable = available
|
||||||
|
isLoading = false
|
||||||
|
|
||||||
|
if (!available && isCompatible) {
|
||||||
|
errorMessage = "Health Connect is not available on this device"
|
||||||
|
} else if (!isCompatible) {
|
||||||
|
errorMessage =
|
||||||
|
"Health Connect API compatibility issue. Please update your device or the app."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
isLoading = false
|
||||||
|
errorMessage = "Error checking Health Connect availability: ${e.message}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Card(
|
||||||
|
modifier = modifier.fillMaxWidth(),
|
||||||
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
colors =
|
||||||
|
CardDefaults.cardColors(
|
||||||
|
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
|
) {
|
||||||
|
// Header with icon and title
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.HealthAndSafety,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(32.dp),
|
||||||
|
tint =
|
||||||
|
if (isHealthConnectAvailable && isEnabled && hasPermissions) {
|
||||||
|
MaterialTheme.colorScheme.primary
|
||||||
|
} else {
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
|
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
text = "Health Connect",
|
||||||
|
style = MaterialTheme.typography.titleMedium,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text =
|
||||||
|
when {
|
||||||
|
isLoading -> "Checking availability..."
|
||||||
|
!isCompatible -> "API Issue"
|
||||||
|
!isHealthConnectAvailable -> "Not available"
|
||||||
|
isEnabled && hasPermissions -> "Connected"
|
||||||
|
isEnabled && !hasPermissions -> "Needs permissions"
|
||||||
|
else -> "Disabled"
|
||||||
|
},
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color =
|
||||||
|
when {
|
||||||
|
isLoading ->
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
|
alpha = 0.7f
|
||||||
|
)
|
||||||
|
|
||||||
|
!isCompatible -> MaterialTheme.colorScheme.error
|
||||||
|
!isHealthConnectAvailable -> MaterialTheme.colorScheme.error
|
||||||
|
isEnabled && hasPermissions ->
|
||||||
|
MaterialTheme.colorScheme.primary
|
||||||
|
|
||||||
|
isEnabled && !hasPermissions ->
|
||||||
|
MaterialTheme.colorScheme.tertiary
|
||||||
|
|
||||||
|
else ->
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
|
alpha = 0.7f
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Main toggle switch
|
||||||
|
Switch(
|
||||||
|
checked = isEnabled,
|
||||||
|
onCheckedChange = { enabled ->
|
||||||
|
coroutineScope.launch {
|
||||||
|
if (enabled && isHealthConnectAvailable) {
|
||||||
|
healthConnectManager.setEnabled(true)
|
||||||
|
try {
|
||||||
|
val permissionSet =
|
||||||
|
healthConnectManager.getRequiredPermissions()
|
||||||
|
if (permissionSet.isNotEmpty()) {
|
||||||
|
permissionLauncher.launch(permissionSet)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
errorMessage = "Error requesting permissions: ${e.message}"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
healthConnectManager.setEnabled(false)
|
||||||
|
errorMessage = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = isHealthConnectAvailable && !isLoading && isCompatible
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isEnabled) {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Climbing sessions will be automatically added to Health Connect when completed.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!hasPermissions) {
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
Card(
|
||||||
|
shape = RoundedCornerShape(12.dp),
|
||||||
|
colors =
|
||||||
|
CardDefaults.cardColors(
|
||||||
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme.errorContainer.copy(
|
||||||
|
alpha = 0.3f
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(20.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = "Permissions needed",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text =
|
||||||
|
"Grant Health Connect permissions to sync your climbing sessions",
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color =
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
|
alpha = 0.8f
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = {
|
||||||
|
coroutineScope.launch {
|
||||||
|
try {
|
||||||
|
val permissionSet =
|
||||||
|
healthConnectManager
|
||||||
|
.getRequiredPermissions()
|
||||||
|
if (permissionSet.isNotEmpty()) {
|
||||||
|
permissionLauncher.launch(permissionSet)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
errorMessage =
|
||||||
|
"Error requesting permissions: ${e.message}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) { Text("Grant Permissions") }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
Text(
|
||||||
|
text =
|
||||||
|
"Sync your climbing sessions to Samsung Health, Google Fit, and other fitness apps through Health Connect.",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
textAlign = TextAlign.Center,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.8f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
errorMessage?.let { error ->
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
|
Card(
|
||||||
|
shape = RoundedCornerShape(8.dp),
|
||||||
|
colors =
|
||||||
|
CardDefaults.cardColors(
|
||||||
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme.errorContainer.copy(
|
||||||
|
alpha = 0.5f
|
||||||
|
)
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(12.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Default.Warning,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(16.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
|
Text(
|
||||||
|
text = error,
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onErrorContainer
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
@@ -17,9 +17,9 @@ import androidx.compose.ui.semantics.Role
|
|||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import com.atridad.openclimb.ui.components.ImagePicker
|
import com.atridad.ascently.ui.components.ImagePicker
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack:
|
|||||||
emptyList()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
selectedClimbTypes
|
selectedClimbTypes
|
||||||
.flatMap { climbType -> DifficultySystem.getSystemsForClimbType(climbType) }
|
.flatMap { climbType -> DifficultySystem.systemsForClimbType(climbType) }
|
||||||
.distinct()
|
.distinct()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateGym(gym.copy(id = gymId!!))
|
viewModel.updateGym(gym.copy(id = gymId))
|
||||||
} else {
|
} else {
|
||||||
viewModel.addGym(gym)
|
viewModel.addGym(gym)
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack:
|
|||||||
onCheckedChange = null
|
onCheckedChange = null
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(climbType.getDisplayName())
|
Text(climbType.displayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack:
|
|||||||
onCheckedChange = null
|
onCheckedChange = null
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(system.getDisplayName())
|
Text(system.displayName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,6 @@ fun AddEditProblemScreen(
|
|||||||
) {
|
) {
|
||||||
val isEditing = problemId != null
|
val isEditing = problemId != null
|
||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
// Problem form state
|
// Problem form state
|
||||||
var selectedGym by remember {
|
var selectedGym by remember {
|
||||||
@@ -295,7 +294,7 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
val availableClimbTypes = selectedGym?.supportedClimbTypes ?: ClimbType.entries.toList()
|
val availableClimbTypes = selectedGym?.supportedClimbTypes ?: ClimbType.entries.toList()
|
||||||
val availableDifficultySystems =
|
val availableDifficultySystems =
|
||||||
DifficultySystem.getSystemsForClimbType(selectedClimbType).filter { system ->
|
DifficultySystem.systemsForClimbType(selectedClimbType).filter { system ->
|
||||||
selectedGym?.difficultySystems?.contains(system) != false
|
selectedGym?.difficultySystems?.contains(system) != false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -324,7 +323,7 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
// Reset grade when difficulty system changes (unless it's a valid grade for the new system)
|
// Reset grade when difficulty system changes (unless it's a valid grade for the new system)
|
||||||
LaunchedEffect(selectedDifficultySystem) {
|
LaunchedEffect(selectedDifficultySystem) {
|
||||||
val availableGrades = selectedDifficultySystem.getAvailableGrades()
|
val availableGrades = selectedDifficultySystem.availableGrades
|
||||||
if (availableGrades.isNotEmpty() && difficultyGrade !in availableGrades) {
|
if (availableGrades.isNotEmpty() && difficultyGrade !in availableGrades) {
|
||||||
difficultyGrade = ""
|
difficultyGrade = ""
|
||||||
}
|
}
|
||||||
@@ -387,12 +386,11 @@ fun AddEditProblemScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateProblem(
|
problemId.let { id ->
|
||||||
problem.copy(id = problemId),
|
viewModel.updateProblem(problem.copy(id = id))
|
||||||
context
|
}
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.addProblem(problem, context)
|
viewModel.addProblem(problem)
|
||||||
}
|
}
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
}
|
}
|
||||||
@@ -505,7 +503,7 @@ fun AddEditProblemScreen(
|
|||||||
availableClimbTypes.forEach { climbType ->
|
availableClimbTypes.forEach { climbType ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = climbType },
|
onClick = { selectedClimbType = climbType },
|
||||||
label = { Text(climbType.getDisplayName()) },
|
label = { Text(climbType.displayName) },
|
||||||
selected = selectedClimbType == climbType
|
selected = selectedClimbType == climbType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -538,7 +536,7 @@ fun AddEditProblemScreen(
|
|||||||
items(availableDifficultySystems) { system ->
|
items(availableDifficultySystems) { system ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedDifficultySystem = system },
|
onClick = { selectedDifficultySystem = system },
|
||||||
label = { Text(system.getDisplayName()) },
|
label = { Text(system.displayName) },
|
||||||
selected = selectedDifficultySystem == system
|
selected = selectedDifficultySystem == system
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -570,7 +568,7 @@ fun AddEditProblemScreen(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
val availableGrades = selectedDifficultySystem.getAvailableGrades()
|
val availableGrades = selectedDifficultySystem.availableGrades
|
||||||
|
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
@@ -592,8 +590,7 @@ fun AddEditProblemScreen(
|
|||||||
.outlinedTextFieldColors(),
|
.outlinedTextFieldColors(),
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.menuAnchor(
|
Modifier.menuAnchor(
|
||||||
androidx.compose.material3
|
ExposedDropdownMenuAnchorType
|
||||||
.MenuAnchorType
|
|
||||||
.PrimaryNotEditable,
|
.PrimaryNotEditable,
|
||||||
enabled = true
|
enabled = true
|
||||||
)
|
)
|
||||||
@@ -765,9 +762,9 @@ fun AddEditSessionScreen(
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
viewModel.updateSession(
|
sessionId.let { id ->
|
||||||
session.copy(id = sessionId!!)
|
viewModel.updateSession(session.copy(id = id))
|
||||||
)
|
}
|
||||||
} else {
|
} else {
|
||||||
viewModel.startSession(
|
viewModel.startSession(
|
||||||
context,
|
context,
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
@@ -9,16 +9,16 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.model.AttemptResult
|
import com.atridad.ascently.data.model.AttemptResult
|
||||||
import com.atridad.openclimb.data.model.ClimbType
|
import com.atridad.ascently.data.model.ClimbType
|
||||||
import com.atridad.openclimb.data.model.DifficultySystem
|
import com.atridad.ascently.data.model.DifficultySystem
|
||||||
import com.atridad.openclimb.ui.components.BarChart
|
import com.atridad.ascently.ui.components.BarChart
|
||||||
import com.atridad.openclimb.ui.components.BarChartDataPoint
|
import com.atridad.ascently.ui.components.BarChartDataPoint
|
||||||
import com.atridad.openclimb.ui.components.SyncIndicator
|
import com.atridad.ascently.ui.components.SyncIndicator
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
||||||
@@ -39,7 +39,7 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
|||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -200,7 +200,9 @@ fun GradeDistributionChartCard(gradeDistributionData: List<GradeDistributionData
|
|||||||
},
|
},
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.menuAnchor(
|
Modifier.menuAnchor(
|
||||||
type = ExposedDropdownMenuAnchorType.PrimaryNotEditable,
|
type =
|
||||||
|
ExposedDropdownMenuAnchorType
|
||||||
|
.PrimaryNotEditable,
|
||||||
enabled = true
|
enabled = true
|
||||||
)
|
)
|
||||||
.width(120.dp),
|
.width(120.dp),
|
||||||
@@ -251,11 +253,8 @@ fun GradeDistributionChartCard(gradeDistributionData: List<GradeDistributionData
|
|||||||
systemFiltered.filter { dataPoint ->
|
systemFiltered.filter { dataPoint ->
|
||||||
try {
|
try {
|
||||||
val attemptDate =
|
val attemptDate =
|
||||||
LocalDateTime.parse(
|
DateFormatUtils.parseToLocalDateTime(dataPoint.date)
|
||||||
dataPoint.date,
|
attemptDate?.isAfter(sevenDaysAgo) == true
|
||||||
DateTimeFormatter.ISO_LOCAL_DATE_TIME
|
|
||||||
)
|
|
||||||
attemptDate.isAfter(sevenDaysAgo)
|
|
||||||
} catch (_: Exception) {
|
} catch (_: Exception) {
|
||||||
// If date parsing fails, include the data point
|
// If date parsing fails, include the data point
|
||||||
true
|
true
|
||||||
@@ -394,9 +393,9 @@ data class GradeDistributionDataPoint(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun calculateGradeDistribution(
|
fun calculateGradeDistribution(
|
||||||
sessions: List<com.atridad.openclimb.data.model.ClimbSession>,
|
sessions: List<com.atridad.ascently.data.model.ClimbSession>,
|
||||||
problems: List<com.atridad.openclimb.data.model.Problem>,
|
problems: List<com.atridad.ascently.data.model.Problem>,
|
||||||
attempts: List<com.atridad.openclimb.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()
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
@@ -16,10 +16,8 @@ import androidx.compose.material.icons.filled.Add
|
|||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
import androidx.compose.material.icons.filled.Delete
|
import androidx.compose.material.icons.filled.Delete
|
||||||
import androidx.compose.material.icons.filled.Edit
|
import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material.icons.filled.HealthAndSafety
|
|
||||||
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
import androidx.compose.material.icons.filled.KeyboardArrowDown
|
||||||
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
import androidx.compose.material.icons.filled.KeyboardArrowUp
|
||||||
import androidx.compose.material.icons.filled.Share
|
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@@ -30,16 +28,13 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.lifecycle.viewModelScope
|
import com.atridad.ascently.data.model.*
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.ui.components.FullscreenImageViewer
|
||||||
import com.atridad.openclimb.ui.components.FullscreenImageViewer
|
import com.atridad.ascently.ui.components.ImageDisplaySection
|
||||||
import com.atridad.openclimb.ui.components.ImageDisplaySection
|
import com.atridad.ascently.ui.theme.CustomIcons
|
||||||
import com.atridad.openclimb.ui.theme.CustomIcons
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import kotlinx.coroutines.flow.first
|
import kotlinx.coroutines.flow.first
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -221,7 +216,6 @@ fun SessionDetailScreen(
|
|||||||
val problems by viewModel.problems.collectAsState()
|
val problems by viewModel.problems.collectAsState()
|
||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
|
|
||||||
var isGeneratingShare by remember { mutableStateOf(false) }
|
|
||||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
var showAddAttemptDialog by remember { mutableStateOf(false) }
|
var showAddAttemptDialog by remember { mutableStateOf(false) }
|
||||||
var showEditAttemptDialog by remember { mutableStateOf<Attempt?>(null) }
|
var showEditAttemptDialog by remember { mutableStateOf<Attempt?>(null) }
|
||||||
@@ -234,7 +228,7 @@ fun SessionDetailScreen(
|
|||||||
val successfulAttempts =
|
val successfulAttempts =
|
||||||
attempts.filter { it.result in listOf(AttemptResult.SUCCESS, AttemptResult.FLASH) }
|
attempts.filter { it.result in listOf(AttemptResult.SUCCESS, AttemptResult.FLASH) }
|
||||||
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
||||||
val attemptedProblems = problems.filter { it.id in uniqueProblems }
|
|
||||||
val completedProblems = successfulAttempts.map { it.problemId }.distinct()
|
val completedProblems = successfulAttempts.map { it.problemId }.distinct()
|
||||||
|
|
||||||
val attemptsWithProblems =
|
val attemptsWithProblems =
|
||||||
@@ -261,64 +255,8 @@ fun SessionDetailScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
if (session?.duration != null) {
|
// No manual actions needed - Health Connect syncs automatically when
|
||||||
val healthConnectManager = viewModel.getHealthConnectManager()
|
// sessions complete
|
||||||
val isHealthConnectEnabled by
|
|
||||||
healthConnectManager.isEnabled.collectAsState(
|
|
||||||
initial = false
|
|
||||||
)
|
|
||||||
val hasPermissions by
|
|
||||||
healthConnectManager.hasPermissions.collectAsState(
|
|
||||||
initial = false
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isHealthConnectEnabled && hasPermissions) {
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
viewModel.manualSyncToHealthConnect(sessionId)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.HealthAndSafety,
|
|
||||||
contentDescription = "Sync to Health Connect",
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Share button
|
|
||||||
if (session?.duration != null) { // Only show for completed sessions
|
|
||||||
IconButton(
|
|
||||||
onClick = {
|
|
||||||
isGeneratingShare = true
|
|
||||||
viewModel.viewModelScope.launch {
|
|
||||||
val shareFile =
|
|
||||||
viewModel.generateSessionShareCard(
|
|
||||||
context,
|
|
||||||
sessionId
|
|
||||||
)
|
|
||||||
isGeneratingShare = false
|
|
||||||
shareFile?.let { file ->
|
|
||||||
viewModel.shareSessionCard(context, file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = !isGeneratingShare
|
|
||||||
) {
|
|
||||||
if (isGeneratingShare) {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(20.dp),
|
|
||||||
strokeWidth = 2.dp
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Share,
|
|
||||||
contentDescription = "Share Session"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show stop icon for active sessions, delete icon for completed
|
// Show stop icon for active sessions, delete icon for completed
|
||||||
// sessions
|
// sessions
|
||||||
@@ -564,7 +502,7 @@ fun SessionDetailScreen(
|
|||||||
viewModel.addAttempt(attempt)
|
viewModel.addAttempt(attempt)
|
||||||
showAddAttemptDialog = false
|
showAddAttemptDialog = false
|
||||||
},
|
},
|
||||||
onProblemCreated = { problem -> viewModel.addProblem(problem, context) }
|
onProblemCreated = { problem -> viewModel.addProblem(problem) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -590,7 +528,7 @@ fun ProblemDetailScreen(
|
|||||||
onNavigateBack: () -> Unit,
|
onNavigateBack: () -> Unit,
|
||||||
onNavigateToEdit: (String) -> Unit
|
onNavigateToEdit: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
|
||||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
var showImageViewer by remember { mutableStateOf(false) }
|
var showImageViewer by remember { mutableStateOf(false) }
|
||||||
var selectedImageIndex by remember { mutableIntStateOf(0) }
|
var selectedImageIndex by remember { mutableIntStateOf(0) }
|
||||||
@@ -665,7 +603,7 @@ fun ProblemDetailScreen(
|
|||||||
problem?.let { p ->
|
problem?.let { p ->
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"${p.difficulty.system.getDisplayName()}: ${p.difficulty.grade}",
|
"${p.difficulty.system.displayName}: ${p.difficulty.grade}",
|
||||||
style = MaterialTheme.typography.titleLarge,
|
style = MaterialTheme.typography.titleLarge,
|
||||||
color = MaterialTheme.colorScheme.primary,
|
color = MaterialTheme.colorScheme.primary,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
@@ -674,7 +612,7 @@ fun ProblemDetailScreen(
|
|||||||
|
|
||||||
problem?.let { p ->
|
problem?.let { p ->
|
||||||
Text(
|
Text(
|
||||||
text = p.climbType.getDisplayName(),
|
text = p.climbType.displayName,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -854,7 +792,7 @@ fun ProblemDetailScreen(
|
|||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
problem?.let { p ->
|
problem?.let { p ->
|
||||||
viewModel.deleteProblem(p, context)
|
viewModel.deleteProblem(p)
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
}
|
}
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
@@ -1236,19 +1174,10 @@ fun GymDetailScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
val dateTime =
|
|
||||||
try {
|
|
||||||
LocalDateTime.parse(session.date)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
val formattedDate =
|
val formattedDate =
|
||||||
dateTime?.format(
|
DateFormatUtils.formatDateForDisplay(
|
||||||
DateTimeFormatter.ofPattern(
|
session.date
|
||||||
"MMM dd, yyyy"
|
|
||||||
)
|
)
|
||||||
)
|
|
||||||
?: session.date
|
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"$formattedDate • ${sessionAttempts.size} attempts"
|
"$formattedDate • ${sessionAttempts.size} attempts"
|
||||||
@@ -1463,7 +1392,7 @@ fun SessionAttemptCard(
|
|||||||
|
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"${problem.difficulty.system.getDisplayName()}: ${problem.difficulty.grade}",
|
"${problem.difficulty.system.displayName}: ${problem.difficulty.grade}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.primary
|
color = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -1538,14 +1467,7 @@ fun SessionAttemptCard(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun formatDate(dateString: String): String {
|
private fun formatDate(dateString: String): String {
|
||||||
return try {
|
return DateFormatUtils.formatDateForDisplay(dateString)
|
||||||
val formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME
|
|
||||||
val date = LocalDateTime.parse(dateString, formatter)
|
|
||||||
val displayFormatter = DateTimeFormatter.ofPattern("MMM dd, yyyy")
|
|
||||||
date.format(displayFormatter)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
dateString.take(10) // Fallback to just the date part
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@@ -1584,7 +1506,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
// Auto-select difficulty system if there's only one available for the selected climb type
|
// Auto-select difficulty system if there's only one available for the selected climb type
|
||||||
LaunchedEffect(selectedClimbType, gym.difficultySystems) {
|
LaunchedEffect(selectedClimbType, gym.difficultySystems) {
|
||||||
val availableSystems =
|
val availableSystems =
|
||||||
DifficultySystem.getSystemsForClimbType(selectedClimbType).filter { system ->
|
DifficultySystem.systemsForClimbType(selectedClimbType).filter { system ->
|
||||||
gym.difficultySystems.contains(system)
|
gym.difficultySystems.contains(system)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1604,7 +1526,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
|
|
||||||
// Reset grade when difficulty system changes
|
// Reset grade when difficulty system changes
|
||||||
LaunchedEffect(selectedDifficultySystem) {
|
LaunchedEffect(selectedDifficultySystem) {
|
||||||
val availableGrades = selectedDifficultySystem.getAvailableGrades()
|
val availableGrades = selectedDifficultySystem.availableGrades
|
||||||
if (availableGrades.isNotEmpty() && newProblemGrade !in availableGrades) {
|
if (availableGrades.isNotEmpty() && newProblemGrade !in availableGrades) {
|
||||||
newProblemGrade = ""
|
newProblemGrade = ""
|
||||||
}
|
}
|
||||||
@@ -1721,7 +1643,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"${problem.difficulty.system.getDisplayName()}: ${problem.difficulty.grade}",
|
"${problem.difficulty.system.displayName}: ${problem.difficulty.grade}",
|
||||||
style =
|
style =
|
||||||
MaterialTheme.typography
|
MaterialTheme.typography
|
||||||
.bodyMedium,
|
.bodyMedium,
|
||||||
@@ -1730,7 +1652,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
MaterialTheme
|
MaterialTheme
|
||||||
.colorScheme
|
.colorScheme
|
||||||
.onSurface.copy(
|
.onSurface.copy(
|
||||||
alpha = 0.8f
|
alpha = 0.9f
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
MaterialTheme
|
MaterialTheme
|
||||||
@@ -1807,7 +1729,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
onClick = { selectedClimbType = climbType },
|
onClick = { selectedClimbType = climbType },
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
climbType.getDisplayName(),
|
climbType.displayName,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -1838,7 +1760,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
)
|
)
|
||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
val availableSystems =
|
val availableSystems =
|
||||||
DifficultySystem.getSystemsForClimbType(
|
DifficultySystem.systemsForClimbType(
|
||||||
selectedClimbType
|
selectedClimbType
|
||||||
)
|
)
|
||||||
.filter { system ->
|
.filter { system ->
|
||||||
@@ -1849,7 +1771,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
onClick = { selectedDifficultySystem = system },
|
onClick = { selectedDifficultySystem = system },
|
||||||
label = {
|
label = {
|
||||||
Text(
|
Text(
|
||||||
system.getDisplayName(),
|
system.displayName,
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -1926,8 +1848,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
val availableGrades =
|
val availableGrades = selectedDifficultySystem.availableGrades
|
||||||
selectedDifficultySystem.getAvailableGrades()
|
|
||||||
|
|
||||||
ExposedDropdownMenuBox(
|
ExposedDropdownMenuBox(
|
||||||
expanded = expanded,
|
expanded = expanded,
|
||||||
@@ -1949,8 +1870,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
.outlinedTextFieldColors(),
|
.outlinedTextFieldColors(),
|
||||||
modifier =
|
modifier =
|
||||||
Modifier.menuAnchor(
|
Modifier.menuAnchor(
|
||||||
androidx.compose.material3
|
ExposedDropdownMenuAnchorType
|
||||||
.MenuAnchorType
|
|
||||||
.PrimaryNotEditable,
|
.PrimaryNotEditable,
|
||||||
enabled = true
|
enabled = true
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
@@ -10,10 +10,10 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.model.Gym
|
import com.atridad.ascently.data.model.Gym
|
||||||
import com.atridad.openclimb.ui.components.SyncIndicator
|
import com.atridad.ascently.ui.components.SyncIndicator
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -28,7 +28,7 @@ fun GymsScreen(viewModel: ClimbViewModel, onNavigateToGymDetail: (String) -> Uni
|
|||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -87,7 +87,7 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
gym.supportedClimbTypes.forEach { climbType ->
|
gym.supportedClimbTypes.forEach { climbType ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = {},
|
onClick = {},
|
||||||
label = { Text(climbType.getDisplayName()) },
|
label = { Text(climbType.displayName) },
|
||||||
modifier = Modifier.padding(end = 4.dp)
|
modifier = Modifier.padding(end = 4.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ fun GymCard(gym: Gym, onClick: () -> Unit) {
|
|||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
"Systems: ${gym.difficultySystems.joinToString(", ") { it.getDisplayName() }}",
|
"Systems: ${gym.difficultySystems.joinToString(", ") { it.displayName }}",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
@@ -11,18 +11,17 @@ import androidx.compose.material3.*
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.model.Attempt
|
import com.atridad.ascently.data.model.Attempt
|
||||||
import com.atridad.openclimb.data.model.AttemptResult
|
import com.atridad.ascently.data.model.AttemptResult
|
||||||
import com.atridad.openclimb.data.model.ClimbType
|
import com.atridad.ascently.data.model.ClimbType
|
||||||
import com.atridad.openclimb.data.model.Gym
|
import com.atridad.ascently.data.model.Gym
|
||||||
import com.atridad.openclimb.data.model.Problem
|
import com.atridad.ascently.data.model.Problem
|
||||||
import com.atridad.openclimb.ui.components.SyncIndicator
|
import com.atridad.ascently.ui.components.SyncIndicator
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -30,7 +29,6 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
val problems by viewModel.problems.collectAsState()
|
val problems by viewModel.problems.collectAsState()
|
||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
val attempts by viewModel.attempts.collectAsState()
|
val attempts by viewModel.attempts.collectAsState()
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
// Filter state
|
// Filter state
|
||||||
var selectedClimbType by remember { mutableStateOf<ClimbType?>(null) }
|
var selectedClimbType by remember { mutableStateOf<ClimbType?>(null) }
|
||||||
@@ -57,7 +55,7 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -104,7 +102,7 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
items(ClimbType.entries) { climbType ->
|
items(ClimbType.entries) { climbType ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = climbType },
|
onClick = { selectedClimbType = climbType },
|
||||||
label = { Text(climbType.getDisplayName()) },
|
label = { Text(climbType.displayName) },
|
||||||
selected = selectedClimbType == climbType
|
selected = selectedClimbType == climbType
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -183,7 +181,7 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
|||||||
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, context)
|
viewModel.updateProblem(updatedProblem)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -268,7 +266,7 @@ fun ProblemCard(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = problem.climbType.getDisplayName(),
|
text = problem.climbType.displayName,
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
@@ -16,14 +16,13 @@ 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 com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.model.ClimbSession
|
import com.atridad.ascently.data.model.ClimbSession
|
||||||
import com.atridad.openclimb.data.model.SessionStatus
|
import com.atridad.ascently.data.model.SessionStatus
|
||||||
import com.atridad.openclimb.ui.components.ActiveSessionBanner
|
import com.atridad.ascently.ui.components.ActiveSessionBanner
|
||||||
import com.atridad.openclimb.ui.components.SyncIndicator
|
import com.atridad.ascently.ui.components.SyncIndicator
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
import java.time.LocalDateTime
|
import com.atridad.ascently.utils.DateFormatUtils
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -46,7 +45,7 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
|||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -247,10 +246,5 @@ fun EmptyStateMessage(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun formatDate(dateString: String): String {
|
private fun formatDate(dateString: String): String {
|
||||||
return try {
|
return DateFormatUtils.formatDateForDisplay(dateString)
|
||||||
val date = LocalDateTime.parse(dateString.split("T")[0] + "T00:00:00")
|
|
||||||
date.format(DateTimeFormatter.ofPattern("MMM dd, yyyy"))
|
|
||||||
} catch (_: Exception) {
|
|
||||||
dateString
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.screens
|
package com.atridad.ascently.ui.screens
|
||||||
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
@@ -15,10 +15,10 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.ui.components.SyncIndicator
|
import com.atridad.ascently.ui.components.SyncIndicator
|
||||||
import com.atridad.openclimb.ui.health.HealthConnectCard
|
import com.atridad.ascently.ui.health.HealthConnectCard
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.ascently.ui.viewmodel.ClimbViewModel
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -50,15 +50,15 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
var isDeletingImages by remember { mutableStateOf(false) }
|
var isDeletingImages by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
// Sync configuration state
|
// Sync configuration state
|
||||||
var serverUrl by remember { mutableStateOf(syncService.serverURL) }
|
var serverUrl by remember { mutableStateOf(syncService.serverUrl) }
|
||||||
var authToken by remember { mutableStateOf(syncService.authToken) }
|
var authToken by remember { mutableStateOf(syncService.authToken) }
|
||||||
|
|
||||||
val packageInfo = remember { context.packageManager.getPackageInfo(context.packageName, 0) }
|
val packageInfo = remember { context.packageManager.getPackageInfo(context.packageName, 0) }
|
||||||
val appVersion = packageInfo.versionName
|
val appVersion = packageInfo.versionName
|
||||||
|
|
||||||
// Update local state when sync service configuration changes
|
// Update local state when sync service configuration changes
|
||||||
LaunchedEffect(syncService.serverURL, syncService.authToken) {
|
LaunchedEffect(syncService.serverUrl, syncService.authToken) {
|
||||||
serverUrl = syncService.serverURL
|
serverUrl = syncService.serverUrl
|
||||||
authToken = syncService.authToken
|
authToken = syncService.authToken
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
// Only allow ZIP files
|
// Only allow ZIP files
|
||||||
if (!fileName.lowercase().endsWith(".zip")) {
|
if (!fileName.lowercase().endsWith(".zip")) {
|
||||||
viewModel.setError(
|
viewModel.setError(
|
||||||
"Only ZIP files are supported for import. Please use a ZIP file exported from OpenClimb."
|
"Only ZIP files are supported for import. Please use a ZIP file exported from Ascently."
|
||||||
)
|
)
|
||||||
return@let
|
return@let
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.ic_mountains),
|
painter = painterResource(id = R.drawable.ic_mountains),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(32.dp),
|
modifier = Modifier.size(32.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
@@ -183,7 +183,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
},
|
},
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
Column {
|
Column {
|
||||||
Text("Server: ${syncService.serverURL}")
|
Text("Server: ${syncService.serverUrl}")
|
||||||
lastSyncTime?.let { time ->
|
lastSyncTime?.let { time ->
|
||||||
Text(
|
Text(
|
||||||
"Last sync: ${
|
"Last sync: ${
|
||||||
@@ -336,7 +336,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = { Text("Setup Sync") },
|
headlineContent = { Text("Setup Sync") },
|
||||||
supportingContent = {
|
supportingContent = {
|
||||||
Text("Connect to your OpenClimb sync server")
|
Text("Connect to your Ascently sync server")
|
||||||
},
|
},
|
||||||
leadingContent = {
|
leadingContent = {
|
||||||
Icon(Icons.Default.CloudSync, contentDescription = null)
|
Icon(Icons.Default.CloudSync, contentDescription = null)
|
||||||
@@ -421,7 +421,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
val defaultFileName =
|
val defaultFileName =
|
||||||
"openclimb_export_${
|
"ascently_export_${
|
||||||
java.time.LocalDateTime.now()
|
java.time.LocalDateTime.now()
|
||||||
.toString()
|
.toString()
|
||||||
.replace(":", "-")
|
.replace(":", "-")
|
||||||
@@ -604,11 +604,11 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
painterResource(
|
painterResource(
|
||||||
id = R.drawable.ic_mountains
|
id = R.drawable.ic_mountains
|
||||||
),
|
),
|
||||||
contentDescription = "OpenClimb Logo",
|
contentDescription = "Ascently Logo",
|
||||||
modifier = Modifier.size(24.dp),
|
modifier = Modifier.size(24.dp),
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint = MaterialTheme.colorScheme.primary
|
||||||
)
|
)
|
||||||
Text("OpenClimb")
|
Text("Ascently")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
supportingContent = { Text("Track your climbing progress") },
|
supportingContent = { Text("Track your climbing progress") },
|
||||||
@@ -863,7 +863,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
syncService.serverURL = serverUrl.trim()
|
syncService.serverUrl = serverUrl.trim()
|
||||||
syncService.authToken = authToken.trim()
|
syncService.authToken = authToken.trim()
|
||||||
viewModel.testSyncConnection()
|
viewModel.testSyncConnection()
|
||||||
while (syncService.isTesting.value) {
|
while (syncService.isTesting.value) {
|
||||||
@@ -905,7 +905,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
onClick = {
|
onClick = {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
syncService.serverURL = serverUrl.trim()
|
syncService.serverUrl = serverUrl.trim()
|
||||||
syncService.authToken = authToken.trim()
|
syncService.authToken = authToken.trim()
|
||||||
viewModel.testSyncConnection()
|
viewModel.testSyncConnection()
|
||||||
while (syncService.isTesting.value) {
|
while (syncService.isTesting.value) {
|
||||||
@@ -932,7 +932,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
serverUrl = syncService.serverURL
|
serverUrl = syncService.serverUrl
|
||||||
authToken = syncService.authToken
|
authToken = syncService.authToken
|
||||||
showSyncConfigDialog = false
|
showSyncConfigDialog = false
|
||||||
}
|
}
|
||||||
@@ -981,7 +981,7 @@ fun SettingsScreen(viewModel: ClimbViewModel) {
|
|||||||
isDeletingImages = true
|
isDeletingImages = true
|
||||||
showDeleteImagesDialog = false
|
showDeleteImagesDialog = false
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
viewModel.deleteAllImages(context)
|
viewModel.deleteAllImages()
|
||||||
isDeletingImages = false
|
isDeletingImages = false
|
||||||
viewModel.setMessage("All images deleted successfully!")
|
viewModel.setMessage("All images deleted successfully!")
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.theme
|
package com.atridad.ascently.ui.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.theme
|
package com.atridad.ascently.ui.theme
|
||||||
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.theme
|
package com.atridad.ascently.ui.theme
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
@@ -88,7 +88,7 @@ private val LightColorScheme = lightColorScheme(
|
|||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun OpenClimbTheme(
|
fun AscentlyTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
// 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
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.ui.theme
|
package com.atridad.ascently.ui.theme
|
||||||
|
|
||||||
import androidx.compose.material3.Typography
|
import androidx.compose.material3.Typography
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
@@ -1,22 +1,18 @@
|
|||||||
package com.atridad.openclimb.ui.viewmodel
|
package com.atridad.ascently.ui.viewmodel
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.atridad.openclimb.data.health.HealthConnectManager
|
import com.atridad.ascently.data.health.HealthConnectManager
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import com.atridad.openclimb.data.sync.SyncService
|
import com.atridad.ascently.data.sync.SyncService
|
||||||
import com.atridad.openclimb.service.SessionTrackingService
|
import com.atridad.ascently.service.SessionTrackingService
|
||||||
import com.atridad.openclimb.utils.ImageNamingUtils
|
import com.atridad.ascently.utils.ImageUtils
|
||||||
import com.atridad.openclimb.utils.ImageUtils
|
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
||||||
import com.atridad.openclimb.utils.SessionShareUtils
|
|
||||||
import com.atridad.openclimb.widget.ClimbStatsWidgetProvider
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
|
|
||||||
class ClimbViewModel(
|
class ClimbViewModel(
|
||||||
private val repository: ClimbRepository,
|
private val repository: ClimbRepository,
|
||||||
@@ -78,64 +74,57 @@ class ClimbViewModel(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Gym operations
|
// Gym operations
|
||||||
fun addGym(gym: Gym) {
|
fun addGym(gym: Gym, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch { repository.insertGym(gym) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addGym(gym: Gym, context: Context) {
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.insertGym(gym)
|
repository.insertGym(gym)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateGym(gym: Gym) {
|
|
||||||
viewModelScope.launch { repository.updateGym(gym) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateGym(gym: Gym, context: Context) {
|
fun updateGym(gym: Gym, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.updateGym(gym)
|
repository.updateGym(gym)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteGym(gym: Gym) {
|
|
||||||
viewModelScope.launch { repository.deleteGym(gym) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteGym(gym: Gym, context: Context) {
|
fun deleteGym(gym: Gym, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.deleteGym(gym)
|
repository.deleteGym(gym)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getGymById(id: String): Flow<Gym?> = flow { emit(repository.getGymById(id)) }
|
fun getGymById(id: String): Flow<Gym?> = flow { emit(repository.getGymById(id)) }
|
||||||
|
|
||||||
// Problem operations
|
// Problem operations
|
||||||
fun addProblem(problem: Problem, context: Context) {
|
fun addProblem(problem: Problem, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val finalProblem = renameTemporaryImages(problem, context)
|
val finalProblem = renameTemporaryImages(problem)
|
||||||
repository.insertProblem(finalProblem)
|
repository.insertProblem(finalProblem)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
// Auto-sync now happens automatically via repository callback
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun renameTemporaryImages(problem: Problem, context: Context? = null): Problem {
|
private fun renameTemporaryImages(problem: Problem): Problem {
|
||||||
if (problem.imagePaths.isEmpty()) {
|
if (problem.imagePaths.isEmpty()) {
|
||||||
return problem
|
return problem
|
||||||
}
|
}
|
||||||
|
|
||||||
val appContext = context ?: return problem
|
|
||||||
val finalImagePaths = mutableListOf<String>()
|
val finalImagePaths = mutableListOf<String>()
|
||||||
|
|
||||||
problem.imagePaths.forEachIndexed { index, tempPath ->
|
problem.imagePaths.forEachIndexed { index, tempPath ->
|
||||||
if (tempPath.startsWith("temp_")) {
|
if (tempPath.startsWith("temp_")) {
|
||||||
val deterministicName = ImageNamingUtils.generateImageFilename(problem.id, index)
|
|
||||||
val finalPath =
|
val finalPath =
|
||||||
ImageUtils.renameTemporaryImage(appContext, tempPath, problem.id, index)
|
ImageUtils.renameTemporaryImage(context, tempPath, problem.id, index)
|
||||||
finalImagePaths.add(finalPath ?: tempPath)
|
finalImagePaths.add(finalPath ?: tempPath)
|
||||||
} else {
|
} else {
|
||||||
finalImagePaths.add(tempPath)
|
finalImagePaths.add(tempPath)
|
||||||
@@ -145,34 +134,34 @@ class ClimbViewModel(
|
|||||||
return problem.copy(imagePaths = finalImagePaths)
|
return problem.copy(imagePaths = finalImagePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateProblem(problem: Problem, context: Context) {
|
fun updateProblem(problem: Problem, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val finalProblem = renameTemporaryImages(problem, context)
|
val finalProblem = renameTemporaryImages(problem)
|
||||||
repository.updateProblem(finalProblem)
|
repository.updateProblem(finalProblem)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun deleteProblem(problem: Problem, context: Context) {
|
fun deleteProblem(problem: Problem, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// Delete associated images
|
|
||||||
problem.imagePaths.forEach { imagePath -> ImageUtils.deleteImage(context, imagePath) }
|
problem.imagePaths.forEach { imagePath -> ImageUtils.deleteImage(context, imagePath) }
|
||||||
|
|
||||||
repository.deleteProblem(problem)
|
repository.deleteProblem(problem)
|
||||||
|
cleanupOrphanedImages()
|
||||||
cleanupOrphanedImages(context)
|
if (updateWidgets) {
|
||||||
|
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private suspend fun cleanupOrphanedImages(context: Context) {
|
private suspend fun cleanupOrphanedImages() {
|
||||||
val allProblems = repository.getAllProblems().first()
|
val allProblems = repository.getAllProblems().first()
|
||||||
val referencedImagePaths = allProblems.flatMap { it.imagePaths }.toSet()
|
val referencedImagePaths = allProblems.flatMap { it.imagePaths }.toSet()
|
||||||
ImageUtils.cleanupOrphanedImages(context, referencedImagePaths)
|
ImageUtils.cleanupOrphanedImages(context, referencedImagePaths)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAllImages(context: Context) {
|
fun deleteAllImages() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val imagesDir = ImageUtils.getImagesDirectory(context)
|
val imagesDir = ImageUtils.getImagesDirectory(context)
|
||||||
var deletedCount = 0
|
var deletedCount = 0
|
||||||
@@ -212,38 +201,24 @@ class ClimbViewModel(
|
|||||||
fun getProblemsByGym(gymId: String): Flow<List<Problem>> = repository.getProblemsByGym(gymId)
|
fun getProblemsByGym(gymId: String): Flow<List<Problem>> = repository.getProblemsByGym(gymId)
|
||||||
|
|
||||||
// Session operations
|
// Session operations
|
||||||
fun addSession(session: ClimbSession) {
|
|
||||||
viewModelScope.launch { repository.insertSession(session) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addSession(session: ClimbSession, context: Context) {
|
fun updateSession(session: ClimbSession, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
|
||||||
repository.insertSession(session)
|
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateSession(session: ClimbSession) {
|
|
||||||
viewModelScope.launch { repository.updateSession(session) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun updateSession(session: ClimbSession, context: Context) {
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.updateSession(session)
|
repository.updateSession(session)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteSession(session: ClimbSession) {
|
|
||||||
viewModelScope.launch { repository.deleteSession(session) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteSession(session: ClimbSession, context: Context) {
|
fun deleteSession(session: ClimbSession, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.deleteSession(session)
|
repository.deleteSession(session)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getSessionById(id: String): Flow<ClimbSession?> = flow {
|
fun getSessionById(id: String): Flow<ClimbSession?> = flow {
|
||||||
emit(repository.getSessionById(id))
|
emit(repository.getSessionById(id))
|
||||||
@@ -260,7 +235,7 @@ class ClimbViewModel(
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
android.util.Log.d("ClimbViewModel", "startSession called with gymId: $gymId")
|
android.util.Log.d("ClimbViewModel", "startSession called with gymId: $gymId")
|
||||||
|
|
||||||
if (!com.atridad.openclimb.utils.NotificationPermissionUtils
|
if (!com.atridad.ascently.utils.NotificationPermissionUtils
|
||||||
.isNotificationPermissionGranted(context)
|
.isNotificationPermissionGranted(context)
|
||||||
) {
|
) {
|
||||||
android.util.Log.d("ClimbViewModel", "Notification permission not granted")
|
android.util.Log.d("ClimbViewModel", "Notification permission not granted")
|
||||||
@@ -305,7 +280,7 @@ class ClimbViewModel(
|
|||||||
|
|
||||||
fun endSession(context: Context, sessionId: String) {
|
fun endSession(context: Context, sessionId: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
if (!com.atridad.openclimb.utils.NotificationPermissionUtils
|
if (!com.atridad.ascently.utils.NotificationPermissionUtils
|
||||||
.isNotificationPermissionGranted(context)
|
.isNotificationPermissionGranted(context)
|
||||||
) {
|
) {
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
@@ -345,38 +320,32 @@ class ClimbViewModel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Attempt operations
|
// Attempt operations
|
||||||
fun addAttempt(attempt: Attempt) {
|
fun addAttempt(attempt: Attempt, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch { repository.insertAttempt(attempt) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addAttempt(attempt: Attempt, context: Context) {
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.insertAttempt(attempt)
|
repository.insertAttempt(attempt)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAttempt(attempt: Attempt) {
|
|
||||||
viewModelScope.launch { repository.deleteAttempt(attempt) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteAttempt(attempt: Attempt, context: Context) {
|
fun deleteAttempt(attempt: Attempt, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.deleteAttempt(attempt)
|
repository.deleteAttempt(attempt)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAttempt(attempt: Attempt) {
|
|
||||||
viewModelScope.launch { repository.updateAttempt(attempt) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateAttempt(attempt: Attempt, context: Context) {
|
fun updateAttempt(attempt: Attempt, updateWidgets: Boolean = true) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
repository.updateAttempt(attempt)
|
repository.updateAttempt(attempt)
|
||||||
|
if (updateWidgets) {
|
||||||
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
ClimbStatsWidgetProvider.updateAllWidgets(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun getAttemptsBySession(sessionId: String): Flow<List<Attempt>> =
|
fun getAttemptsBySession(sessionId: String): Flow<List<Attempt>> =
|
||||||
repository.getAttemptsBySession(sessionId)
|
repository.getAttemptsBySession(sessionId)
|
||||||
@@ -416,7 +385,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 OpenClimb."
|
"Only ZIP files are supported for import. Please use a ZIP file exported from Ascently."
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -499,106 +468,27 @@ class ClimbViewModel(
|
|||||||
val attempts = repository.getAttemptsBySession(session.id).first()
|
val attempts = repository.getAttemptsBySession(session.id).first()
|
||||||
val attemptCount = attempts.size
|
val attemptCount = attempts.size
|
||||||
|
|
||||||
val result = healthConnectManager.autoSyncSession(session, gymName, attemptCount)
|
|
||||||
|
|
||||||
result
|
|
||||||
.onSuccess {
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(
|
|
||||||
message =
|
|
||||||
"Session synced to Health Connect successfully!"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.onFailure { error ->
|
|
||||||
if (healthConnectManager.isReadySync()) {
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(
|
|
||||||
error =
|
|
||||||
"Failed to sync to Health Connect: ${error.message}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (healthConnectManager.isReadySync()) {
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(error = "Health Connect sync error: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun manualSyncToHealthConnect(sessionId: String) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
val session = repository.getSessionById(sessionId)
|
|
||||||
if (session == null) {
|
|
||||||
_uiState.value = _uiState.value.copy(error = "Session not found")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
if (session.status != SessionStatus.COMPLETED) {
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(error = "Only completed sessions can be synced")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
val gym = repository.getGymById(session.gymId)
|
|
||||||
val gymName = gym?.name ?: "Unknown Gym"
|
|
||||||
val attempts = repository.getAttemptsBySession(session.id).first()
|
|
||||||
val attemptCount = attempts.size
|
|
||||||
|
|
||||||
val result =
|
val result =
|
||||||
healthConnectManager.syncClimbingSession(session, gymName, attemptCount)
|
healthConnectManager.autoSyncCompletedSession(
|
||||||
|
session,
|
||||||
|
gymName,
|
||||||
|
attemptCount
|
||||||
|
)
|
||||||
|
|
||||||
result
|
result.onFailure { error ->
|
||||||
.onSuccess {
|
if (healthConnectManager.isReadySync()) {
|
||||||
_uiState.value =
|
android.util.Log.w(
|
||||||
_uiState.value.copy(
|
"ClimbViewModel",
|
||||||
message =
|
"Health Connect sync failed: ${error.message}"
|
||||||
"Session synced to Health Connect successfully!"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.onFailure { error ->
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(
|
|
||||||
error =
|
|
||||||
"Failed to sync to Health Connect: ${error.message}"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value =
|
if (healthConnectManager.isReadySync()) {
|
||||||
_uiState.value.copy(error = "Health Connect sync error: ${e.message}")
|
android.util.Log.w("ClimbViewModel", "Health Connect sync error: ${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHealthConnectManager(): HealthConnectManager = healthConnectManager
|
|
||||||
|
|
||||||
// Share operations
|
|
||||||
suspend fun generateSessionShareCard(context: Context, sessionId: String): File? =
|
|
||||||
withContext(Dispatchers.IO) {
|
|
||||||
try {
|
|
||||||
val session = repository.getSessionById(sessionId) ?: return@withContext null
|
|
||||||
val attempts = repository.getAttemptsBySession(sessionId).first()
|
|
||||||
val problems =
|
|
||||||
repository.getAllProblems().first().filter { problem ->
|
|
||||||
attempts.any { it.problemId == problem.id }
|
|
||||||
}
|
|
||||||
val gym = repository.getGymById(session.gymId) ?: return@withContext null
|
|
||||||
|
|
||||||
val stats = SessionShareUtils.calculateSessionStats(session, attempts, problems)
|
|
||||||
SessionShareUtils.generateShareCard(context, session, gym, stats)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
_uiState.value =
|
|
||||||
_uiState.value.copy(
|
|
||||||
error = "Failed to generate share card: ${e.message}"
|
|
||||||
)
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shareSessionCard(context: Context, imageFile: File) {
|
|
||||||
SessionShareUtils.shareSessionCard(context, imageFile)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.atridad.openclimb.ui.viewmodel
|
package com.atridad.ascently.ui.viewmodel
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import com.atridad.openclimb.data.sync.SyncService
|
import com.atridad.ascently.data.sync.SyncService
|
||||||
|
|
||||||
class ClimbViewModelFactory(
|
class ClimbViewModelFactory(
|
||||||
private val repository: ClimbRepository,
|
private val repository: ClimbRepository,
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
object DateFormatUtils {
|
||||||
|
|
||||||
|
// ISO 8601 formatter matching iOS date format exactly
|
||||||
|
private val ISO_FORMATTER =
|
||||||
|
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneOffset.UTC)
|
||||||
|
|
||||||
|
/** Get current timestamp in iOS-compatible ISO 8601 format */
|
||||||
|
fun nowISO8601(): String {
|
||||||
|
return ISO_FORMATTER.format(Instant.now())
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Parse an iOS-compatible ISO 8601 date string back to Instant */
|
||||||
|
fun parseISO8601(dateString: String): Instant? {
|
||||||
|
return try {
|
||||||
|
Instant.from(ISO_FORMATTER.parse(dateString))
|
||||||
|
} catch (_: Exception) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Instant.parse(dateString)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a UTC ISO 8601 date string for display in local timezone This fixes the timezone
|
||||||
|
* display issue where UTC dates were shown as local dates
|
||||||
|
*/
|
||||||
|
fun formatDateForDisplay(dateString: String): String {
|
||||||
|
val pattern = "MMM dd, yyyy"
|
||||||
|
return try {
|
||||||
|
val instant = parseISO8601(dateString)
|
||||||
|
if (instant != null) {
|
||||||
|
val localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault())
|
||||||
|
localDateTime.format(DateTimeFormatter.ofPattern(pattern))
|
||||||
|
} else {
|
||||||
|
// Fallback for malformed dates
|
||||||
|
dateString.take(10)
|
||||||
|
}
|
||||||
|
} catch (_: Exception) {
|
||||||
|
dateString.take(10)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Parse a UTC ISO 8601 date string to LocalDateTime in system timezone */
|
||||||
|
fun parseToLocalDateTime(dateString: String): LocalDateTime? {
|
||||||
|
return try {
|
||||||
|
val instant = parseISO8601(dateString)
|
||||||
|
instant?.let { LocalDateTime.ofInstant(it, ZoneId.systemDefault()) }
|
||||||
|
} catch (_: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
|
import java.security.MessageDigest
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility for creating consistent image filenames across iOS and Android platforms. Uses
|
||||||
|
* deterministic naming based on problem ID and timestamp to ensure sync compatibility.
|
||||||
|
*/
|
||||||
|
object ImageNamingUtils {
|
||||||
|
|
||||||
|
private const val IMAGE_EXTENSION = ".jpg"
|
||||||
|
private const val HASH_LENGTH = 12 // First 12 chars of SHA-256
|
||||||
|
|
||||||
|
/** Generates a deterministic filename for a problem image */
|
||||||
|
fun generateImageFilename(problemId: String, imageIndex: Int): String {
|
||||||
|
val input = "${problemId}_${imageIndex}"
|
||||||
|
val hash = createHash(input)
|
||||||
|
|
||||||
|
return "problem_${hash}_${imageIndex}${IMAGE_EXTENSION}"
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Legacy method for backward compatibility */
|
||||||
|
@Suppress("UNUSED_PARAMETER")
|
||||||
|
fun generateImageFilename(problemId: String, timestamp: String, imageIndex: Int): String {
|
||||||
|
return generateImageFilename(problemId, imageIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a deterministic hash from input string */
|
||||||
|
private fun createHash(input: String): String {
|
||||||
|
val digest = MessageDigest.getInstance("SHA-256")
|
||||||
|
val hashBytes = digest.digest(input.toByteArray(Charsets.UTF_8))
|
||||||
|
val hashHex = hashBytes.joinToString("") { "%02x".format(it) }
|
||||||
|
return hashHex.take(HASH_LENGTH)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates a mapping of existing server filenames to canonical filenames */
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package com.atridad.openclimb.utils
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
|
import android.graphics.ImageDecoder
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.provider.MediaStore
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.core.graphics.scale
|
import androidx.core.graphics.scale
|
||||||
import androidx.exifinterface.media.ExifInterface
|
import androidx.exifinterface.media.ExifInterface
|
||||||
@@ -78,101 +78,6 @@ object ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves an image from a URI with compression */
|
|
||||||
fun saveImageFromUri(
|
|
||||||
context: Context,
|
|
||||||
imageUri: Uri,
|
|
||||||
problemId: String? = null,
|
|
||||||
imageIndex: Int? = null
|
|
||||||
): String? {
|
|
||||||
return try {
|
|
||||||
|
|
||||||
val originalBitmap =
|
|
||||||
context.contentResolver.openInputStream(imageUri)?.use { input ->
|
|
||||||
BitmapFactory.decodeStream(input)
|
|
||||||
}
|
|
||||||
?: return null
|
|
||||||
|
|
||||||
// Always require deterministic naming
|
|
||||||
require(problemId != null && imageIndex != null) {
|
|
||||||
"Problem ID and image index are required for deterministic image naming"
|
|
||||||
}
|
|
||||||
|
|
||||||
val filename = ImageNamingUtils.generateImageFilename(problemId, imageIndex)
|
|
||||||
val imageFile = File(getImagesDirectory(context), filename)
|
|
||||||
|
|
||||||
val success = saveImageWithExif(context, imageUri, originalBitmap, imageFile)
|
|
||||||
originalBitmap.recycle()
|
|
||||||
|
|
||||||
if (!success) return null
|
|
||||||
|
|
||||||
"$IMAGES_DIR/$filename"
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Corrects image orientation based on EXIF data */
|
|
||||||
private fun correctImageOrientation(context: Context, imageUri: Uri, bitmap: Bitmap): Bitmap {
|
|
||||||
return try {
|
|
||||||
val inputStream = context.contentResolver.openInputStream(imageUri)
|
|
||||||
inputStream?.use { input ->
|
|
||||||
val exif = androidx.exifinterface.media.ExifInterface(input)
|
|
||||||
val orientation =
|
|
||||||
exif.getAttributeInt(
|
|
||||||
androidx.exifinterface.media.ExifInterface.TAG_ORIENTATION,
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_NORMAL
|
|
||||||
)
|
|
||||||
|
|
||||||
val matrix = android.graphics.Matrix()
|
|
||||||
when (orientation) {
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_ROTATE_90 -> {
|
|
||||||
matrix.postRotate(90f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_ROTATE_180 -> {
|
|
||||||
matrix.postRotate(180f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_ROTATE_270 -> {
|
|
||||||
matrix.postRotate(270f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> {
|
|
||||||
matrix.postScale(-1f, 1f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
|
|
||||||
matrix.postScale(1f, -1f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_TRANSPOSE -> {
|
|
||||||
matrix.postRotate(90f)
|
|
||||||
matrix.postScale(-1f, 1f)
|
|
||||||
}
|
|
||||||
androidx.exifinterface.media.ExifInterface.ORIENTATION_TRANSVERSE -> {
|
|
||||||
matrix.postRotate(-90f)
|
|
||||||
matrix.postScale(-1f, 1f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (matrix.isIdentity) {
|
|
||||||
bitmap
|
|
||||||
} else {
|
|
||||||
android.graphics.Bitmap.createBitmap(
|
|
||||||
bitmap,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
bitmap.width,
|
|
||||||
bitmap.height,
|
|
||||||
matrix,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?: bitmap
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
bitmap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Compresses and resizes an image bitmap */
|
/** Compresses and resizes an image bitmap */
|
||||||
@SuppressLint("UseKtx")
|
@SuppressLint("UseKtx")
|
||||||
private fun compressImage(original: Bitmap): Bitmap {
|
private fun compressImage(original: Bitmap): Bitmap {
|
||||||
@@ -260,9 +165,8 @@ object ImageUtils {
|
|||||||
/** Temporarily saves an image during selection process */
|
/** Temporarily saves an image during selection process */
|
||||||
fun saveTemporaryImageFromUri(context: Context, imageUri: Uri): String? {
|
fun saveTemporaryImageFromUri(context: Context, imageUri: Uri): String? {
|
||||||
return try {
|
return try {
|
||||||
val originalBitmap =
|
val source = ImageDecoder.createSource(context.contentResolver, imageUri)
|
||||||
MediaStore.Images.Media.getBitmap(context.contentResolver, imageUri)
|
val originalBitmap = ImageDecoder.decodeBitmap(source)
|
||||||
?: return null
|
|
||||||
|
|
||||||
val tempFilename = "temp_${UUID.randomUUID()}.jpg"
|
val tempFilename = "temp_${UUID.randomUUID()}.jpg"
|
||||||
val imageFile = File(getImagesDirectory(context), tempFilename)
|
val imageFile = File(getImagesDirectory(context), tempFilename)
|
||||||
@@ -313,34 +217,6 @@ object ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Saves an image from byte array to app's private storage */
|
|
||||||
fun saveImageFromBytes(context: Context, imageData: ByteArray): String? {
|
|
||||||
return try {
|
|
||||||
val bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.size) ?: return null
|
|
||||||
|
|
||||||
val compressedBitmap = compressImage(bitmap)
|
|
||||||
|
|
||||||
// Generate unique filename
|
|
||||||
val filename = "${UUID.randomUUID()}.jpg"
|
|
||||||
val imageFile = File(getImagesDirectory(context), filename)
|
|
||||||
|
|
||||||
// Save compressed image
|
|
||||||
FileOutputStream(imageFile).use { output ->
|
|
||||||
compressedBitmap.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up bitmaps
|
|
||||||
bitmap.recycle()
|
|
||||||
compressedBitmap.recycle()
|
|
||||||
|
|
||||||
// Return relative path
|
|
||||||
"$IMAGES_DIR/$filename"
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Saves image data with a specific filename */
|
/** Saves image data with a specific filename */
|
||||||
fun saveImageFromBytesWithFilename(
|
fun saveImageFromBytesWithFilename(
|
||||||
context: Context,
|
context: Context,
|
||||||
@@ -391,52 +267,6 @@ object ImageUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Migrates existing images to use consistent naming convention */
|
|
||||||
fun migrateImageNaming(
|
|
||||||
context: Context,
|
|
||||||
problemId: String,
|
|
||||||
currentImagePaths: List<String>
|
|
||||||
): Map<String, String> {
|
|
||||||
val migrationMap = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
currentImagePaths.forEachIndexed { index, oldPath ->
|
|
||||||
val oldFilename = oldPath.substringAfterLast('/')
|
|
||||||
val newFilename = ImageNamingUtils.migrateFilename(oldFilename, problemId, index)
|
|
||||||
|
|
||||||
if (oldFilename != newFilename) {
|
|
||||||
try {
|
|
||||||
val oldFile = getImageFile(context, oldPath)
|
|
||||||
val newFile = File(getImagesDirectory(context), newFilename)
|
|
||||||
|
|
||||||
if (oldFile.exists() && oldFile.renameTo(newFile)) {
|
|
||||||
val newPath = "$IMAGES_DIR/$newFilename"
|
|
||||||
migrationMap[oldPath] = newPath
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
// Log error but continue with other images
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return migrationMap
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Batch migrates all images in the system to use consistent naming */
|
|
||||||
fun batchMigrateAllImages(
|
|
||||||
context: Context,
|
|
||||||
problemImageMap: Map<String, List<String>>
|
|
||||||
): Map<String, String> {
|
|
||||||
val allMigrations = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
problemImageMap.forEach { (problemId, imagePaths) ->
|
|
||||||
val migrations = migrateImageNaming(context, problemId, imagePaths)
|
|
||||||
allMigrations.putAll(migrations)
|
|
||||||
}
|
|
||||||
|
|
||||||
return allMigrations
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Cleans up orphaned images that are not referenced by any problems */
|
/** Cleans up orphaned images that are not referenced by any problems */
|
||||||
fun cleanupOrphanedImages(context: Context, referencedPaths: Set<String>) {
|
fun cleanupOrphanedImages(context: Context, referencedPaths: Set<String>) {
|
||||||
try {
|
try {
|
||||||
@@ -0,0 +1,171 @@
|
|||||||
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.content.SharedPreferences
|
||||||
|
import android.util.Log
|
||||||
|
import androidx.core.content.edit
|
||||||
|
|
||||||
|
class MigrationManager(private val context: Context) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "MigrationManager"
|
||||||
|
private const val MIGRATION_PREFS = "ascently_migration_state"
|
||||||
|
private const val MIGRATION_COMPLETED_KEY = "openclimb_to_ascently_completed"
|
||||||
|
}
|
||||||
|
|
||||||
|
private val migrationPrefs: SharedPreferences =
|
||||||
|
context.getSharedPreferences(MIGRATION_PREFS, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform migration from OpenClimb to Ascently if needed This should be called early in app
|
||||||
|
* startup
|
||||||
|
*/
|
||||||
|
fun migrateIfNeeded() {
|
||||||
|
if (migrationPrefs.getBoolean(MIGRATION_COMPLETED_KEY, false)) {
|
||||||
|
Log.d(TAG, "Migration already completed, skipping")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.i(TAG, "🔄 Starting migration from OpenClimb to Ascently...")
|
||||||
|
var migrationCount = 0
|
||||||
|
|
||||||
|
// Migrate SharedPreferences
|
||||||
|
migrationCount += migrateSharedPreferences()
|
||||||
|
|
||||||
|
// Mark migration as completed
|
||||||
|
migrationPrefs.edit { putBoolean(MIGRATION_COMPLETED_KEY, true) }
|
||||||
|
|
||||||
|
if (migrationCount > 0) {
|
||||||
|
Log.i(
|
||||||
|
TAG,
|
||||||
|
"🎉 Migration completed! Migrated $migrationCount items from OpenClimb to Ascently"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Log.i(TAG, "ℹ️ No OpenClimb data found to migrate")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Migrate SharedPreferences from OpenClimb naming to Ascently naming */
|
||||||
|
private fun migrateSharedPreferences(): Int {
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
// Define preference file migrations
|
||||||
|
val preferenceFileMigrations =
|
||||||
|
listOf(
|
||||||
|
"openclimb_data_state" to "ascently_data_state",
|
||||||
|
"health_connect_prefs" to "health_connect_prefs", // Keep same name
|
||||||
|
"deleted_items" to "deleted_items", // Keep same name
|
||||||
|
"sync_preferences" to "sync_preferences" // Keep same name
|
||||||
|
)
|
||||||
|
|
||||||
|
for ((oldFileName, newFileName) in preferenceFileMigrations) {
|
||||||
|
if (oldFileName != newFileName) {
|
||||||
|
count += migratePreferenceFile(oldFileName, newFileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Migrate specific keys within preference files
|
||||||
|
count += migratePreferenceKeys()
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Migrate an entire SharedPreferences file */
|
||||||
|
private fun migratePreferenceFile(oldFileName: String, newFileName: String): Int {
|
||||||
|
val oldPrefs = context.getSharedPreferences(oldFileName, Context.MODE_PRIVATE)
|
||||||
|
val newPrefs = context.getSharedPreferences(newFileName, Context.MODE_PRIVATE)
|
||||||
|
|
||||||
|
// If old prefs exist and new prefs are empty, migrate
|
||||||
|
if (oldPrefs.all.isNotEmpty() && newPrefs.all.isEmpty()) {
|
||||||
|
newPrefs.edit {
|
||||||
|
oldPrefs.all.forEach { (key, value) ->
|
||||||
|
when (value) {
|
||||||
|
is String -> putString(key, value)
|
||||||
|
is Int -> putInt(key, value)
|
||||||
|
is Long -> putLong(key, value)
|
||||||
|
is Float -> putFloat(key, value)
|
||||||
|
is Boolean -> putBoolean(key, value)
|
||||||
|
is Set<*> -> {
|
||||||
|
@Suppress("UNCHECKED_CAST") putStringSet(key, value as Set<String>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear old preferences
|
||||||
|
oldPrefs.edit { clear() }
|
||||||
|
|
||||||
|
Log.d(
|
||||||
|
TAG,
|
||||||
|
"✅ Migrated preference file: $oldFileName → $newFileName (${oldPrefs.all.size} keys)"
|
||||||
|
)
|
||||||
|
return oldPrefs.all.size
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Migrate specific keys within preference files that might contain openclimb references */
|
||||||
|
private fun migratePreferenceKeys(): Int {
|
||||||
|
var count = 0
|
||||||
|
|
||||||
|
// Check for any openclimb-prefixed keys across all preference files
|
||||||
|
val preferencesToCheck =
|
||||||
|
listOf(
|
||||||
|
"ascently_data_state",
|
||||||
|
"health_connect_prefs",
|
||||||
|
"deleted_items",
|
||||||
|
"sync_preferences"
|
||||||
|
)
|
||||||
|
|
||||||
|
for (prefFileName in preferencesToCheck) {
|
||||||
|
val prefs = context.getSharedPreferences(prefFileName, Context.MODE_PRIVATE)
|
||||||
|
val keysToMigrate = mutableListOf<Pair<String, String>>()
|
||||||
|
|
||||||
|
// Find keys that start with openclimb_ and should be ascently_
|
||||||
|
prefs.all.keys.forEach { key ->
|
||||||
|
if (key.startsWith("openclimb_")) {
|
||||||
|
val newKey = key.replace("openclimb_", "ascently_")
|
||||||
|
keysToMigrate.add(key to newKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the key migrations
|
||||||
|
if (keysToMigrate.isNotEmpty()) {
|
||||||
|
prefs.edit {
|
||||||
|
keysToMigrate.forEach { (oldKey, newKey) ->
|
||||||
|
val value = prefs.all[oldKey]
|
||||||
|
when (value) {
|
||||||
|
is String -> putString(newKey, value)
|
||||||
|
is Int -> putInt(newKey, value)
|
||||||
|
is Long -> putLong(newKey, value)
|
||||||
|
is Float -> putFloat(newKey, value)
|
||||||
|
is Boolean -> putBoolean(newKey, value)
|
||||||
|
is Set<*> -> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
putStringSet(newKey, value as Set<String>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remove(oldKey)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "✅ Migrated ${keysToMigrate.size} keys in $prefFileName")
|
||||||
|
count += keysToMigrate.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Check if migration has been completed */
|
||||||
|
fun isMigrationCompleted(): Boolean {
|
||||||
|
return migrationPrefs.getBoolean(MIGRATION_COMPLETED_KEY, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reset migration state (for testing purposes) */
|
||||||
|
fun resetMigrationState() {
|
||||||
|
migrationPrefs.edit { putBoolean(MIGRATION_COMPLETED_KEY, false) }
|
||||||
|
Log.d(TAG, "Migration state reset")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.utils
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.utils
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
@@ -7,23 +7,23 @@ import android.content.pm.ShortcutManager
|
|||||||
import android.graphics.drawable.Icon
|
import android.graphics.drawable.Icon
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import com.atridad.openclimb.MainActivity
|
import com.atridad.ascently.MainActivity
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
|
|
||||||
object AppShortcutManager {
|
object AppShortcutManager {
|
||||||
|
|
||||||
const val SHORTCUT_START_SESSION = "start_session"
|
const val SHORTCUT_START_SESSION = "start_session"
|
||||||
const val SHORTCUT_END_SESSION = "end_session"
|
const val SHORTCUT_END_SESSION = "end_session"
|
||||||
|
|
||||||
const val ACTION_START_SESSION = "com.atridad.openclimb.action.START_SESSION"
|
const val ACTION_START_SESSION = "com.atridad.ascently.action.START_SESSION"
|
||||||
const val ACTION_END_SESSION = "com.atridad.openclimb.action.END_SESSION"
|
const val ACTION_END_SESSION = "com.atridad.ascently.action.END_SESSION"
|
||||||
|
|
||||||
/** 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.openclimb.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)
|
||||||
@@ -45,7 +45,7 @@ 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.openclimb.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 {
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package com.atridad.openclimb.utils
|
package com.atridad.ascently.utils
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.atridad.openclimb.data.format.BackupProblem
|
import com.atridad.ascently.data.format.BackupProblem
|
||||||
import com.atridad.openclimb.data.format.ClimbDataBackup
|
import com.atridad.ascently.data.format.ClimbDataBackup
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
@@ -33,14 +33,14 @@ object ZipExportImportUtils {
|
|||||||
context.getExternalFilesDir(
|
context.getExternalFilesDir(
|
||||||
android.os.Environment.DIRECTORY_DOCUMENTS
|
android.os.Environment.DIRECTORY_DOCUMENTS
|
||||||
),
|
),
|
||||||
"OpenClimb"
|
"Ascently"
|
||||||
)
|
)
|
||||||
if (!exportDir.exists()) {
|
if (!exportDir.exists()) {
|
||||||
exportDir.mkdirs()
|
exportDir.mkdirs()
|
||||||
}
|
}
|
||||||
|
|
||||||
val timestamp = LocalDateTime.now().toString().replace(":", "-").replace(".", "-")
|
val timestamp = LocalDateTime.now().toString().replace(":", "-").replace(".", "-")
|
||||||
val zipFile = File(exportDir, "openclimb_export_$timestamp.zip")
|
val zipFile = File(exportDir, "ascently_export_$timestamp.zip")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ZipOutputStream(FileOutputStream(zipFile)).use { zipOut ->
|
ZipOutputStream(FileOutputStream(zipFile)).use { zipOut ->
|
||||||
@@ -182,8 +182,8 @@ object ZipExportImportUtils {
|
|||||||
referencedImagePaths: Set<String>
|
referencedImagePaths: Set<String>
|
||||||
): String {
|
): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
appendLine("OpenClimb Export Metadata")
|
appendLine("Ascently Export Metadata")
|
||||||
appendLine("=======================")
|
appendLine("========================")
|
||||||
appendLine("Export Date: ${exportData.exportedAt}")
|
appendLine("Export Date: ${exportData.exportedAt}")
|
||||||
appendLine("Version: ${exportData.version}")
|
appendLine("Version: ${exportData.version}")
|
||||||
appendLine("Gyms: ${exportData.gyms.size}")
|
appendLine("Gyms: ${exportData.gyms.size}")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb.widget
|
package com.atridad.ascently.widget
|
||||||
|
|
||||||
import android.app.PendingIntent
|
import android.app.PendingIntent
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
@@ -7,10 +7,10 @@ import android.content.ComponentName
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.atridad.openclimb.MainActivity
|
import com.atridad.ascently.MainActivity
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.ascently.R
|
||||||
import com.atridad.openclimb.data.database.OpenClimbDatabase
|
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||||
import com.atridad.openclimb.data.repository.ClimbRepository
|
import com.atridad.ascently.data.repository.ClimbRepository
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
@@ -45,7 +45,7 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
try {
|
try {
|
||||||
val database = OpenClimbDatabase.getDatabase(context)
|
val database = AscentlyDatabase.getDatabase(context)
|
||||||
val repository = ClimbRepository(database, context)
|
val repository = ClimbRepository(database, context)
|
||||||
|
|
||||||
// Fetch stats data
|
// Fetch stats data
|
||||||
@@ -53,7 +53,6 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
val problems = repository.getAllProblems().first()
|
val problems = repository.getAllProblems().first()
|
||||||
val attempts = repository.getAllAttempts().first()
|
val attempts = repository.getAllAttempts().first()
|
||||||
val gyms = repository.getAllGyms().first()
|
val gyms = repository.getAllGyms().first()
|
||||||
val activeSession = repository.getActiveSession()
|
|
||||||
|
|
||||||
// Calculate stats
|
// Calculate stats
|
||||||
val completedSessions = sessions.filter { it.endTime != null }
|
val completedSessions = sessions.filter { it.endTime != null }
|
||||||
@@ -65,10 +64,10 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
attempts.any { attempt ->
|
attempts.any { attempt ->
|
||||||
attempt.problemId == problem.id &&
|
attempt.problemId == problem.id &&
|
||||||
(attempt.result ==
|
(attempt.result ==
|
||||||
com.atridad.openclimb.data.model
|
com.atridad.ascently.data.model
|
||||||
.AttemptResult.SUCCESS ||
|
.AttemptResult.SUCCESS ||
|
||||||
attempt.result ==
|
attempt.result ==
|
||||||
com.atridad.openclimb.data.model
|
com.atridad.ascently.data.model
|
||||||
.AttemptResult.FLASH)
|
.AttemptResult.FLASH)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +107,7 @@ class ClimbStatsWidgetProvider : AppWidgetProvider() {
|
|||||||
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (_: Exception) {
|
||||||
launch(Dispatchers.Main) {
|
launch(Dispatchers.Main) {
|
||||||
val views = RemoteViews(context.packageName, R.layout.widget_climb_stats)
|
val views = RemoteViews(context.packageName, R.layout.widget_climb_stats)
|
||||||
views.setTextViewText(R.id.widget_total_sessions, "0")
|
views.setTextViewText(R.id.widget_total_sessions, "0")
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package com.atridad.openclimb.data.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
enum class ClimbType {
|
|
||||||
ROPE,
|
|
||||||
BOULDER;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the display name
|
|
||||||
*/
|
|
||||||
fun getDisplayName(): String = when (this) {
|
|
||||||
ROPE -> "Rope"
|
|
||||||
BOULDER -> "Bouldering"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
package com.atridad.openclimb.data.model
|
|
||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
enum class DifficultySystem {
|
|
||||||
// Bouldering
|
|
||||||
V_SCALE,
|
|
||||||
FONT,
|
|
||||||
|
|
||||||
// Rope
|
|
||||||
YDS,
|
|
||||||
CUSTOM;
|
|
||||||
|
|
||||||
/** Get the display name for the UI */
|
|
||||||
fun getDisplayName(): String =
|
|
||||||
when (this) {
|
|
||||||
V_SCALE -> "V Scale"
|
|
||||||
FONT -> "Font Scale"
|
|
||||||
YDS -> "YDS (Yosemite)"
|
|
||||||
CUSTOM -> "Custom"
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if this system is for bouldering */
|
|
||||||
fun isBoulderingSystem(): Boolean =
|
|
||||||
when (this) {
|
|
||||||
V_SCALE, FONT -> true
|
|
||||||
YDS -> false
|
|
||||||
CUSTOM -> true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Check if this system is for rope climbing */
|
|
||||||
fun isRopeSystem(): Boolean =
|
|
||||||
when (this) {
|
|
||||||
YDS -> true
|
|
||||||
V_SCALE, FONT -> false
|
|
||||||
CUSTOM -> true
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Get available grades for this system */
|
|
||||||
fun getAvailableGrades(): List<String> =
|
|
||||||
when (this) {
|
|
||||||
V_SCALE ->
|
|
||||||
listOf(
|
|
||||||
"VB",
|
|
||||||
"V0",
|
|
||||||
"V1",
|
|
||||||
"V2",
|
|
||||||
"V3",
|
|
||||||
"V4",
|
|
||||||
"V5",
|
|
||||||
"V6",
|
|
||||||
"V7",
|
|
||||||
"V8",
|
|
||||||
"V9",
|
|
||||||
"V10",
|
|
||||||
"V11",
|
|
||||||
"V12",
|
|
||||||
"V13",
|
|
||||||
"V14",
|
|
||||||
"V15",
|
|
||||||
"V16",
|
|
||||||
"V17"
|
|
||||||
)
|
|
||||||
FONT ->
|
|
||||||
listOf(
|
|
||||||
"3",
|
|
||||||
"4A",
|
|
||||||
"4B",
|
|
||||||
"4C",
|
|
||||||
"5A",
|
|
||||||
"5B",
|
|
||||||
"5C",
|
|
||||||
"6A",
|
|
||||||
"6A+",
|
|
||||||
"6B",
|
|
||||||
"6B+",
|
|
||||||
"6C",
|
|
||||||
"6C+",
|
|
||||||
"7A",
|
|
||||||
"7A+",
|
|
||||||
"7B",
|
|
||||||
"7B+",
|
|
||||||
"7C",
|
|
||||||
"7C+",
|
|
||||||
"8A",
|
|
||||||
"8A+",
|
|
||||||
"8B",
|
|
||||||
"8B+",
|
|
||||||
"8C",
|
|
||||||
"8C+"
|
|
||||||
)
|
|
||||||
YDS ->
|
|
||||||
listOf(
|
|
||||||
"5.0",
|
|
||||||
"5.1",
|
|
||||||
"5.2",
|
|
||||||
"5.3",
|
|
||||||
"5.4",
|
|
||||||
"5.5",
|
|
||||||
"5.6",
|
|
||||||
"5.7",
|
|
||||||
"5.8",
|
|
||||||
"5.9",
|
|
||||||
"5.10a",
|
|
||||||
"5.10b",
|
|
||||||
"5.10c",
|
|
||||||
"5.10d",
|
|
||||||
"5.11a",
|
|
||||||
"5.11b",
|
|
||||||
"5.11c",
|
|
||||||
"5.11d",
|
|
||||||
"5.12a",
|
|
||||||
"5.12b",
|
|
||||||
"5.12c",
|
|
||||||
"5.12d",
|
|
||||||
"5.13a",
|
|
||||||
"5.13b",
|
|
||||||
"5.13c",
|
|
||||||
"5.13d",
|
|
||||||
"5.14a",
|
|
||||||
"5.14b",
|
|
||||||
"5.14c",
|
|
||||||
"5.14d",
|
|
||||||
"5.15a",
|
|
||||||
"5.15b",
|
|
||||||
"5.15c",
|
|
||||||
"5.15d"
|
|
||||||
)
|
|
||||||
CUSTOM -> emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
/** Get all difficulty systems based on type */
|
|
||||||
fun getSystemsForClimbType(climbType: ClimbType): List<DifficultySystem> =
|
|
||||||
when (climbType) {
|
|
||||||
ClimbType.BOULDER -> entries.filter { it.isBoulderingSystem() }
|
|
||||||
ClimbType.ROPE -> entries.filter { it.isRopeSystem() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Serializable
|
|
||||||
data class DifficultyGrade(val system: DifficultySystem, val grade: String, val numericValue: Int) {
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
system: DifficultySystem,
|
|
||||||
grade: String
|
|
||||||
) : this(system = system, grade = grade, numericValue = calculateNumericValue(system, grade))
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private fun calculateNumericValue(system: DifficultySystem, grade: String): Int {
|
|
||||||
return when (system) {
|
|
||||||
DifficultySystem.V_SCALE -> {
|
|
||||||
if (grade == "VB") 0 else grade.removePrefix("V").toIntOrNull() ?: 0
|
|
||||||
}
|
|
||||||
DifficultySystem.YDS -> {
|
|
||||||
when {
|
|
||||||
grade.startsWith("5.10") ->
|
|
||||||
10 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
grade.startsWith("5.11") ->
|
|
||||||
14 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
grade.startsWith("5.12") ->
|
|
||||||
18 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
grade.startsWith("5.13") ->
|
|
||||||
22 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
grade.startsWith("5.14") ->
|
|
||||||
26 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
grade.startsWith("5.15") ->
|
|
||||||
30 + (grade.getOrNull(4)?.toString()?.hashCode()?.rem(4) ?: 0)
|
|
||||||
else -> grade.removePrefix("5.").toIntOrNull() ?: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DifficultySystem.FONT -> {
|
|
||||||
when {
|
|
||||||
grade.startsWith("6A") -> 6
|
|
||||||
grade.startsWith("6B") -> 7
|
|
||||||
grade.startsWith("6C") -> 8
|
|
||||||
grade.startsWith("7A") -> 9
|
|
||||||
grade.startsWith("7B") -> 10
|
|
||||||
grade.startsWith("7C") -> 11
|
|
||||||
grade.startsWith("8A") -> 12
|
|
||||||
grade.startsWith("8B") -> 13
|
|
||||||
grade.startsWith("8C") -> 14
|
|
||||||
else -> grade.toIntOrNull() ?: 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DifficultySystem.CUSTOM -> grade.hashCode().rem(100)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Compare this grade with another grade of the same system Returns negative if this grade is
|
|
||||||
* easier, positive if harder, 0 if equal
|
|
||||||
*/
|
|
||||||
fun compareTo(other: DifficultyGrade): Int {
|
|
||||||
if (system != other.system) return 0
|
|
||||||
|
|
||||||
return when (system) {
|
|
||||||
DifficultySystem.V_SCALE -> compareVScaleGrades(grade, other.grade)
|
|
||||||
DifficultySystem.FONT -> compareFontGrades(grade, other.grade)
|
|
||||||
DifficultySystem.YDS -> compareYDSGrades(grade, other.grade)
|
|
||||||
DifficultySystem.CUSTOM -> grade.compareTo(other.grade)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun compareVScaleGrades(grade1: String, grade2: String): Int {
|
|
||||||
if (grade1 == "VB" && grade2 != "VB") return -1
|
|
||||||
if (grade2 == "VB" && grade1 != "VB") return 1
|
|
||||||
if (grade1 == "VB") return 0
|
|
||||||
|
|
||||||
val num1 = grade1.removePrefix("V").toIntOrNull() ?: 0
|
|
||||||
val num2 = grade2.removePrefix("V").toIntOrNull() ?: 0
|
|
||||||
return num1.compareTo(num2)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun compareFontGrades(grade1: String, grade2: String): Int {
|
|
||||||
return grade1.compareTo(grade2)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun compareYDSGrades(grade1: String, grade2: String): Int {
|
|
||||||
return grade1.compareTo(grade2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,137 +0,0 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
|
||||||
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Close
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
|
||||||
@Composable
|
|
||||||
fun FullscreenImageViewer(imagePaths: List<String>, initialIndex: Int = 0, onDismiss: () -> Unit) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
val pagerState = rememberPagerState(initialPage = initialIndex, pageCount = { imagePaths.size })
|
|
||||||
val thumbnailListState = rememberLazyListState()
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
// Auto-scroll thumbnail list to center current image
|
|
||||||
LaunchedEffect(pagerState.currentPage) {
|
|
||||||
thumbnailListState.animateScrollToItem(index = pagerState.currentPage, scrollOffset = -200)
|
|
||||||
}
|
|
||||||
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
properties =
|
|
||||||
DialogProperties(
|
|
||||||
usePlatformDefaultWidth = false,
|
|
||||||
decorFitsSystemWindows = false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Box(modifier = Modifier.fillMaxSize().background(Color.Black)) {
|
|
||||||
// Main image pager
|
|
||||||
HorizontalPager(state = pagerState, modifier = Modifier.fillMaxSize()) { page ->
|
|
||||||
OrientationAwareImage(
|
|
||||||
imagePath = imagePaths[page],
|
|
||||||
contentDescription = "Full screen image",
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentScale = ContentScale.Fit
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close button
|
|
||||||
IconButton(
|
|
||||||
onClick = onDismiss,
|
|
||||||
modifier =
|
|
||||||
Modifier.align(Alignment.TopEnd)
|
|
||||||
.padding(16.dp)
|
|
||||||
.background(Color.Black.copy(alpha = 0.5f), CircleShape)
|
|
||||||
) { Icon(Icons.Default.Close, contentDescription = "Close", tint = Color.White) }
|
|
||||||
|
|
||||||
// Image counter
|
|
||||||
if (imagePaths.size > 1) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier.align(Alignment.TopCenter).padding(16.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor = Color.Black.copy(alpha = 0.7f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "${pagerState.currentPage + 1} / ${imagePaths.size}",
|
|
||||||
color = Color.White,
|
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Thumbnail strip (if multiple images)
|
|
||||||
if (imagePaths.size > 1) {
|
|
||||||
Card(
|
|
||||||
modifier =
|
|
||||||
Modifier.align(Alignment.BottomCenter)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor = Color.Black.copy(alpha = 0.7f)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
LazyRow(
|
|
||||||
state = thumbnailListState,
|
|
||||||
modifier = Modifier.padding(8.dp),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
|
||||||
contentPadding = PaddingValues(horizontal = 8.dp)
|
|
||||||
) {
|
|
||||||
itemsIndexed(imagePaths) { index, imagePath ->
|
|
||||||
val isSelected = index == pagerState.currentPage
|
|
||||||
|
|
||||||
OrientationAwareImage(
|
|
||||||
imagePath = imagePath,
|
|
||||||
contentDescription = "Thumbnail ${index + 1}",
|
|
||||||
modifier =
|
|
||||||
Modifier.size(60.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
.clickable {
|
|
||||||
coroutineScope.launch {
|
|
||||||
pagerState.animateScrollToPage(index)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.then(
|
|
||||||
if (isSelected) {
|
|
||||||
Modifier.background(
|
|
||||||
Color.White.copy(
|
|
||||||
alpha = 0.3f
|
|
||||||
),
|
|
||||||
RoundedCornerShape(8.dp)
|
|
||||||
)
|
|
||||||
} else Modifier
|
|
||||||
),
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
package com.atridad.openclimb.ui.components
|
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Notifications
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun NotificationPermissionDialog(
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onRequestPermission: () -> Unit
|
|
||||||
) {
|
|
||||||
Dialog(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
properties = DialogProperties(
|
|
||||||
dismissOnBackPress = false,
|
|
||||||
dismissOnClickOutside = false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Card(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp),
|
|
||||||
shape = MaterialTheme.shapes.medium
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(24.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Notifications,
|
|
||||||
contentDescription = "Notifications",
|
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = "Enable Notifications",
|
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
|
||||||
fontWeight = MaterialTheme.typography.headlineSmall.fontWeight,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = "OpenClimb 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,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
TextButton(
|
|
||||||
onClick = onDismiss,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Text("Not Now")
|
|
||||||
}
|
|
||||||
|
|
||||||
Button(
|
|
||||||
onClick = {
|
|
||||||
onRequestPermission()
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Text("Enable")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,440 +0,0 @@
|
|||||||
package com.atridad.openclimb.ui.health
|
|
||||||
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.*
|
|
||||||
import androidx.compose.material3.*
|
|
||||||
import androidx.compose.runtime.*
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import com.atridad.openclimb.data.health.HealthConnectManager
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun HealthConnectCard(modifier: Modifier = Modifier) {
|
|
||||||
val context = LocalContext.current
|
|
||||||
val healthConnectManager = remember { HealthConnectManager(context) }
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
// State tracking
|
|
||||||
var isHealthConnectAvailable by remember { mutableStateOf(false) }
|
|
||||||
var isLoading by remember { mutableStateOf(true) }
|
|
||||||
var errorMessage by remember { mutableStateOf<String?>(null) }
|
|
||||||
|
|
||||||
// Collect flows
|
|
||||||
val isEnabled by healthConnectManager.isEnabled.collectAsState(initial = false)
|
|
||||||
val hasPermissions by healthConnectManager.hasPermissions.collectAsState(initial = false)
|
|
||||||
val autoSyncEnabled by healthConnectManager.autoSyncEnabled.collectAsState(initial = true)
|
|
||||||
val isCompatible by healthConnectManager.isCompatible.collectAsState(initial = true)
|
|
||||||
|
|
||||||
// Permission launcher
|
|
||||||
val permissionLauncher =
|
|
||||||
rememberLauncherForActivityResult(
|
|
||||||
contract = healthConnectManager.getPermissionRequestContract()
|
|
||||||
) { grantedPermissions ->
|
|
||||||
coroutineScope.launch {
|
|
||||||
val allGranted = healthConnectManager.hasAllPermissions()
|
|
||||||
if (!allGranted) {
|
|
||||||
errorMessage =
|
|
||||||
"Some Health Connect permissions were not granted. Please grant all permissions to enable syncing."
|
|
||||||
} else {
|
|
||||||
errorMessage = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check Health Connect availability on first load
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
coroutineScope.launch {
|
|
||||||
try {
|
|
||||||
healthConnectManager.isHealthConnectAvailable().collect { available ->
|
|
||||||
isHealthConnectAvailable = available
|
|
||||||
isLoading = false
|
|
||||||
|
|
||||||
if (!available && isCompatible) {
|
|
||||||
errorMessage = "Health Connect is not available on this device"
|
|
||||||
} else if (!isCompatible) {
|
|
||||||
errorMessage =
|
|
||||||
"Health Connect API compatibility issue. Please update your device or the app."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
isLoading = false
|
|
||||||
errorMessage = "Error checking Health Connect availability: ${e.message}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Card(
|
|
||||||
modifier = modifier.fillMaxWidth(),
|
|
||||||
shape = RoundedCornerShape(16.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor = MaterialTheme.colorScheme.surfaceVariant
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(20.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
// Header with icon and title
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.HealthAndSafety,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(32.dp),
|
|
||||||
tint =
|
|
||||||
if (isHealthConnectAvailable && isEnabled && hasPermissions) {
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
text = "Health Connect",
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text =
|
|
||||||
when {
|
|
||||||
isLoading -> "Checking availability..."
|
|
||||||
!isCompatible -> "API Issue"
|
|
||||||
!isHealthConnectAvailable -> "Not available"
|
|
||||||
isEnabled && hasPermissions -> "Connected"
|
|
||||||
isEnabled && !hasPermissions -> "Needs permissions"
|
|
||||||
else -> "Disabled"
|
|
||||||
},
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color =
|
|
||||||
when {
|
|
||||||
isLoading ->
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
|
||||||
alpha = 0.7f
|
|
||||||
)
|
|
||||||
!isCompatible -> MaterialTheme.colorScheme.error
|
|
||||||
!isHealthConnectAvailable -> MaterialTheme.colorScheme.error
|
|
||||||
isEnabled && hasPermissions ->
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
isEnabled && !hasPermissions ->
|
|
||||||
MaterialTheme.colorScheme.tertiary
|
|
||||||
else ->
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
|
||||||
alpha = 0.7f
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main toggle switch
|
|
||||||
Switch(
|
|
||||||
checked = isEnabled,
|
|
||||||
onCheckedChange = { enabled ->
|
|
||||||
if (enabled && isHealthConnectAvailable) {
|
|
||||||
healthConnectManager.setEnabled(true)
|
|
||||||
coroutineScope.launch {
|
|
||||||
try {
|
|
||||||
val permissionSet =
|
|
||||||
healthConnectManager.getRequiredPermissions()
|
|
||||||
if (permissionSet.isNotEmpty()) {
|
|
||||||
permissionLauncher.launch(permissionSet)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
errorMessage = "Error requesting permissions: ${e.message}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
healthConnectManager.setEnabled(false)
|
|
||||||
errorMessage = null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = isHealthConnectAvailable && !isLoading && isCompatible
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEnabled) {
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor =
|
|
||||||
if (hasPermissions) {
|
|
||||||
MaterialTheme.colorScheme.primaryContainer.copy(
|
|
||||||
alpha = 0.3f
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.errorContainer.copy(
|
|
||||||
alpha = 0.3f
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Icon(
|
|
||||||
imageVector =
|
|
||||||
if (hasPermissions) Icons.Default.CheckCircle
|
|
||||||
else Icons.Default.Warning,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(20.dp),
|
|
||||||
tint =
|
|
||||||
if (hasPermissions) {
|
|
||||||
MaterialTheme.colorScheme.primary
|
|
||||||
} else {
|
|
||||||
MaterialTheme.colorScheme.error
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text =
|
|
||||||
if (hasPermissions) "Ready to sync"
|
|
||||||
else "Permissions needed",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasPermissions) {
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text =
|
|
||||||
"Grant Health Connect permissions to sync your climbing sessions",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color =
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
|
||||||
alpha = 0.8f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
try {
|
|
||||||
val permissionSet =
|
|
||||||
healthConnectManager
|
|
||||||
.getRequiredPermissions()
|
|
||||||
if (permissionSet.isNotEmpty()) {
|
|
||||||
permissionLauncher.launch(permissionSet)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
errorMessage =
|
|
||||||
"Error requesting permissions: ${e.message}"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) { Text("Grant Permissions") }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasPermissions) {
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(12.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor =
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(
|
|
||||||
alpha = 0.3f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
|
||||||
Text(
|
|
||||||
text = "Auto-sync sessions",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "Automatically sync completed climbing sessions",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color =
|
|
||||||
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
|
||||||
alpha = 0.7f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Switch(
|
|
||||||
checked = autoSyncEnabled,
|
|
||||||
onCheckedChange = { enabled ->
|
|
||||||
healthConnectManager.setAutoSyncEnabled(enabled)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
Text(
|
|
||||||
text =
|
|
||||||
"Sync your climbing sessions to Samsung Health, Google Fit, and other fitness apps through Health Connect.",
|
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.8f)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
errorMessage?.let { error ->
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor =
|
|
||||||
MaterialTheme.colorScheme.errorContainer.copy(
|
|
||||||
alpha = 0.5f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Warning,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.error
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = error,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onErrorContainer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isEnabled) {
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
var testResult by remember { mutableStateOf<String?>(null) }
|
|
||||||
var isTestRunning by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = {
|
|
||||||
isTestRunning = true
|
|
||||||
coroutineScope.launch {
|
|
||||||
try {
|
|
||||||
testResult = healthConnectManager.testHealthConnectSync()
|
|
||||||
} catch (e: Exception) {
|
|
||||||
testResult = "Test failed: ${e.message}"
|
|
||||||
} finally {
|
|
||||||
isTestRunning = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
enabled = !isTestRunning,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
if (isTestRunning) {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
strokeWidth = 2.dp
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
}
|
|
||||||
Text(if (isTestRunning) "Testing..." else "Test Connection")
|
|
||||||
}
|
|
||||||
testResult?.let { result ->
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
Card(
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor =
|
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(
|
|
||||||
alpha = 0.5f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.fillMaxWidth().padding(12.dp)) {
|
|
||||||
Text(
|
|
||||||
text = "Debug Results:",
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
|
||||||
Text(
|
|
||||||
text = result,
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
fontFamily = androidx.compose.ui.text.font.FontFamily.Monospace
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun HealthConnectStatusBanner(isConnected: Boolean, modifier: Modifier = Modifier) {
|
|
||||||
if (isConnected) {
|
|
||||||
Card(
|
|
||||||
modifier = modifier.fillMaxWidth(),
|
|
||||||
shape = RoundedCornerShape(8.dp),
|
|
||||||
colors =
|
|
||||||
CardDefaults.cardColors(
|
|
||||||
containerColor =
|
|
||||||
MaterialTheme.colorScheme.primaryContainer.copy(
|
|
||||||
alpha = 0.5f
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth().padding(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.CloudDone,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
tint = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = "Health Connect active - sessions will sync automatically",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onPrimaryContainer
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package com.atridad.openclimb.utils
|
|
||||||
|
|
||||||
import java.time.Instant
|
|
||||||
import java.time.ZoneOffset
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
|
|
||||||
object DateFormatUtils {
|
|
||||||
|
|
||||||
// ISO 8601 formatter matching iOS date format exactly
|
|
||||||
private val ISO_FORMATTER =
|
|
||||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSX").withZone(ZoneOffset.UTC)
|
|
||||||
|
|
||||||
/** Get current timestamp in iOS-compatible ISO 8601 format */
|
|
||||||
fun nowISO8601(): String {
|
|
||||||
return ISO_FORMATTER.format(Instant.now())
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Format an Instant to iOS-compatible ISO 8601 format */
|
|
||||||
fun formatISO8601(instant: Instant): String {
|
|
||||||
return ISO_FORMATTER.format(instant)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Parse an iOS-compatible ISO 8601 date string back to Instant */
|
|
||||||
fun parseISO8601(dateString: String): Instant? {
|
|
||||||
return try {
|
|
||||||
Instant.from(ISO_FORMATTER.parse(dateString))
|
|
||||||
} catch (e: Exception) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Instant.parse(dateString)
|
|
||||||
} catch (e2: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Validate that a date string matches the expected iOS format */
|
|
||||||
fun isValidISO8601(dateString: String): Boolean {
|
|
||||||
return parseISO8601(dateString) != null
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Convert milliseconds timestamp to iOS-compatible ISO 8601 format */
|
|
||||||
fun millisToISO8601(millis: Long): String {
|
|
||||||
return ISO_FORMATTER.format(Instant.ofEpochMilli(millis))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
package com.atridad.openclimb.utils
|
|
||||||
|
|
||||||
import java.security.MessageDigest
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility for creating consistent image filenames across iOS and Android platforms. Uses
|
|
||||||
* deterministic naming based on problem ID and timestamp to ensure sync compatibility.
|
|
||||||
*/
|
|
||||||
object ImageNamingUtils {
|
|
||||||
|
|
||||||
private const val IMAGE_EXTENSION = ".jpg"
|
|
||||||
private const val HASH_LENGTH = 12 // First 12 chars of SHA-256
|
|
||||||
|
|
||||||
/** Generates a deterministic filename for a problem image */
|
|
||||||
fun generateImageFilename(problemId: String, imageIndex: Int): String {
|
|
||||||
val input = "${problemId}_${imageIndex}"
|
|
||||||
val hash = createHash(input)
|
|
||||||
|
|
||||||
return "problem_${hash}_${imageIndex}${IMAGE_EXTENSION}"
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Legacy method for backward compatibility */
|
|
||||||
fun generateImageFilename(problemId: String, timestamp: String, imageIndex: Int): String {
|
|
||||||
return generateImageFilename(problemId, imageIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Extracts problem ID from an image filename */
|
|
||||||
fun extractProblemIdFromFilename(filename: String): String? {
|
|
||||||
if (!filename.startsWith("problem_") || !filename.endsWith(IMAGE_EXTENSION)) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format: problem_{hash}_{index}.jpg
|
|
||||||
val nameWithoutExtension = filename.substring(0, filename.length - IMAGE_EXTENSION.length)
|
|
||||||
val parts = nameWithoutExtension.split("_")
|
|
||||||
|
|
||||||
if (parts.size != 3 || parts[0] != "problem") {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
return parts[1]
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Validates if a filename follows our naming convention */
|
|
||||||
fun isValidImageFilename(filename: String): Boolean {
|
|
||||||
if (!filename.startsWith("problem_") || !filename.endsWith(IMAGE_EXTENSION)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
val nameWithoutExtension = filename.substring(0, filename.length - IMAGE_EXTENSION.length)
|
|
||||||
val parts = nameWithoutExtension.split("_")
|
|
||||||
|
|
||||||
return parts.size == 3 &&
|
|
||||||
parts[0] == "problem" &&
|
|
||||||
parts[1].length == HASH_LENGTH &&
|
|
||||||
parts[2].toIntOrNull() != null
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Migrates an existing filename to our naming convention */
|
|
||||||
fun migrateFilename(oldFilename: String, problemId: String, imageIndex: Int): String {
|
|
||||||
if (isValidImageFilename(oldFilename)) {
|
|
||||||
return oldFilename
|
|
||||||
}
|
|
||||||
|
|
||||||
return generateImageFilename(problemId, imageIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a deterministic hash from input string */
|
|
||||||
private fun createHash(input: String): String {
|
|
||||||
val digest = MessageDigest.getInstance("SHA-256")
|
|
||||||
val hashBytes = digest.digest(input.toByteArray(Charsets.UTF_8))
|
|
||||||
val hashHex = hashBytes.joinToString("") { "%02x".format(it) }
|
|
||||||
return hashHex.take(HASH_LENGTH)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Batch renames images for a problem to use our naming convention */
|
|
||||||
fun batchRenameForProblem(
|
|
||||||
problemId: String,
|
|
||||||
existingFilenames: List<String>
|
|
||||||
): Map<String, String> {
|
|
||||||
val renameMap = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
existingFilenames.forEachIndexed { index, oldFilename ->
|
|
||||||
val newFilename = generateImageFilename(problemId, index)
|
|
||||||
if (newFilename != oldFilename) {
|
|
||||||
renameMap[oldFilename] = newFilename
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return renameMap
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Generates the canonical filename for a problem image */
|
|
||||||
fun getCanonicalImageFilename(problemId: String, imageIndex: Int): String {
|
|
||||||
return generateImageFilename(problemId, imageIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Creates a mapping of existing server filenames to canonical filenames */
|
|
||||||
fun createServerMigrationMap(
|
|
||||||
problemId: String,
|
|
||||||
serverImageFilenames: List<String>,
|
|
||||||
localImageCount: Int
|
|
||||||
): Map<String, String> {
|
|
||||||
val migrationMap = mutableMapOf<String, String>()
|
|
||||||
|
|
||||||
for (imageIndex in 0 until localImageCount) {
|
|
||||||
val canonicalName = getCanonicalImageFilename(problemId, imageIndex)
|
|
||||||
|
|
||||||
if (serverImageFilenames.contains(canonicalName)) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
for (serverFilename in serverImageFilenames) {
|
|
||||||
if (isValidImageFilename(serverFilename) &&
|
|
||||||
!migrationMap.values.contains(serverFilename)
|
|
||||||
) {
|
|
||||||
migrationMap[serverFilename] = canonicalName
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return migrationMap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,543 +0,0 @@
|
|||||||
package com.atridad.openclimb.utils
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
|
||||||
import android.graphics.*
|
|
||||||
import android.graphics.drawable.GradientDrawable
|
|
||||||
import androidx.core.content.FileProvider
|
|
||||||
import androidx.core.graphics.createBitmap
|
|
||||||
import androidx.core.graphics.toColorInt
|
|
||||||
import com.atridad.openclimb.data.model.*
|
|
||||||
import java.io.File
|
|
||||||
import java.io.FileOutputStream
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.format.DateTimeFormatter
|
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
object SessionShareUtils {
|
|
||||||
|
|
||||||
data class SessionStats(
|
|
||||||
val totalAttempts: Int,
|
|
||||||
val successfulAttempts: Int,
|
|
||||||
val problems: List<Problem>,
|
|
||||||
val uniqueProblemsAttempted: Int,
|
|
||||||
val uniqueProblemsCompleted: Int,
|
|
||||||
val averageGrade: String?,
|
|
||||||
val sessionDuration: String,
|
|
||||||
val topResult: AttemptResult?,
|
|
||||||
val topGrade: String?
|
|
||||||
)
|
|
||||||
|
|
||||||
fun calculateSessionStats(
|
|
||||||
session: ClimbSession,
|
|
||||||
attempts: List<Attempt>,
|
|
||||||
problems: List<Problem>
|
|
||||||
): SessionStats {
|
|
||||||
val successfulResults = listOf(AttemptResult.SUCCESS, AttemptResult.FLASH)
|
|
||||||
|
|
||||||
val successfulAttempts = attempts.filter { it.result in successfulResults }
|
|
||||||
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
|
||||||
val uniqueCompletedProblems = successfulAttempts.map { it.problemId }.distinct()
|
|
||||||
|
|
||||||
val attemptedProblems = problems.filter { it.id in uniqueProblems }
|
|
||||||
|
|
||||||
// Calculate separate averages for different climbing types and difficulty systems
|
|
||||||
val boulderProblems = attemptedProblems.filter { it.climbType == ClimbType.BOULDER }
|
|
||||||
val ropeProblems = attemptedProblems.filter { it.climbType == ClimbType.ROPE }
|
|
||||||
|
|
||||||
val boulderAverage = calculateAverageGrade(boulderProblems, "Boulder")
|
|
||||||
val ropeAverage = calculateAverageGrade(ropeProblems, "Rope")
|
|
||||||
|
|
||||||
// Combine averages for display
|
|
||||||
val averageGrade =
|
|
||||||
when {
|
|
||||||
boulderAverage != null && ropeAverage != null ->
|
|
||||||
"$boulderAverage / $ropeAverage"
|
|
||||||
boulderAverage != null -> boulderAverage
|
|
||||||
ropeAverage != null -> ropeAverage
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine highest achieved grade (only from completed problems: SUCCESS or FLASH)
|
|
||||||
val completedProblems = problems.filter { it.id in uniqueCompletedProblems }
|
|
||||||
val completedBoulder = completedProblems.filter { it.climbType == ClimbType.BOULDER }
|
|
||||||
val completedRope = completedProblems.filter { it.climbType == ClimbType.ROPE }
|
|
||||||
val topBoulder = highestGradeForProblems(completedBoulder)
|
|
||||||
val topRope = highestGradeForProblems(completedRope)
|
|
||||||
val topGrade =
|
|
||||||
when {
|
|
||||||
topBoulder != null && topRope != null -> "$topBoulder / $topRope"
|
|
||||||
topBoulder != null -> topBoulder
|
|
||||||
topRope != null -> topRope
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
val duration = if (session.duration != null) "${session.duration}m" else "Unknown"
|
|
||||||
val topResult =
|
|
||||||
attempts
|
|
||||||
.maxByOrNull {
|
|
||||||
when (it.result) {
|
|
||||||
AttemptResult.FLASH -> 3
|
|
||||||
AttemptResult.SUCCESS -> 2
|
|
||||||
AttemptResult.FALL -> 1
|
|
||||||
else -> 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?.result
|
|
||||||
|
|
||||||
return SessionStats(
|
|
||||||
totalAttempts = attempts.size,
|
|
||||||
successfulAttempts = successfulAttempts.size,
|
|
||||||
problems = attemptedProblems,
|
|
||||||
uniqueProblemsAttempted = uniqueProblems.size,
|
|
||||||
uniqueProblemsCompleted = uniqueCompletedProblems.size,
|
|
||||||
averageGrade = averageGrade,
|
|
||||||
sessionDuration = duration,
|
|
||||||
topResult = topResult,
|
|
||||||
topGrade = topGrade
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calculate average grade for a specific set of problems, respecting their difficulty systems
|
|
||||||
*/
|
|
||||||
private fun calculateAverageGrade(problems: List<Problem>, climbingType: String): String? {
|
|
||||||
if (problems.isEmpty()) return null
|
|
||||||
|
|
||||||
// Group problems by difficulty system
|
|
||||||
val problemsBySystem = problems.groupBy { it.difficulty.system }
|
|
||||||
|
|
||||||
val averages = mutableListOf<String>()
|
|
||||||
|
|
||||||
problemsBySystem.forEach { (system, systemProblems) ->
|
|
||||||
when (system) {
|
|
||||||
DifficultySystem.V_SCALE -> {
|
|
||||||
val gradeValues =
|
|
||||||
systemProblems.mapNotNull { problem ->
|
|
||||||
when {
|
|
||||||
problem.difficulty.grade == "VB" -> 0
|
|
||||||
else -> problem.difficulty.grade.removePrefix("V").toIntOrNull()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (gradeValues.isNotEmpty()) {
|
|
||||||
val avg = gradeValues.average().roundToInt()
|
|
||||||
averages.add(if (avg == 0) "VB" else "V$avg")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DifficultySystem.FONT -> {
|
|
||||||
val gradeValues =
|
|
||||||
systemProblems.mapNotNull { problem ->
|
|
||||||
// Extract numeric part from Font grades (e.g., "6A" -> 6, "7C+" ->
|
|
||||||
// 7)
|
|
||||||
problem.difficulty.grade.filter { it.isDigit() }.toIntOrNull()
|
|
||||||
}
|
|
||||||
if (gradeValues.isNotEmpty()) {
|
|
||||||
val avg = gradeValues.average().roundToInt()
|
|
||||||
averages.add("$avg")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DifficultySystem.YDS -> {
|
|
||||||
val gradeValues =
|
|
||||||
systemProblems.mapNotNull { problem ->
|
|
||||||
// Extract numeric part from YDS grades (e.g., "5.10a" -> 5.10)
|
|
||||||
val grade = problem.difficulty.grade
|
|
||||||
if (grade.startsWith("5.")) {
|
|
||||||
grade.substring(2).toDoubleOrNull()
|
|
||||||
} else null
|
|
||||||
}
|
|
||||||
if (gradeValues.isNotEmpty()) {
|
|
||||||
val avg = gradeValues.average()
|
|
||||||
averages.add("5.${String.format("%.1f", avg)}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
DifficultySystem.CUSTOM -> {
|
|
||||||
// For custom systems, try to extract numeric values
|
|
||||||
val gradeValues =
|
|
||||||
systemProblems.mapNotNull { problem ->
|
|
||||||
problem.difficulty
|
|
||||||
.grade
|
|
||||||
.filter { it.isDigit() || it == '.' || it == '-' }
|
|
||||||
.toDoubleOrNull()
|
|
||||||
}
|
|
||||||
if (gradeValues.isNotEmpty()) {
|
|
||||||
val avg = gradeValues.average()
|
|
||||||
averages.add(String.format("%.1f", avg))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return if (averages.isNotEmpty()) {
|
|
||||||
if (averages.size == 1) {
|
|
||||||
averages.first()
|
|
||||||
} else {
|
|
||||||
averages.joinToString(" / ")
|
|
||||||
}
|
|
||||||
} else null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun generateShareCard(
|
|
||||||
context: Context,
|
|
||||||
session: ClimbSession,
|
|
||||||
gym: Gym,
|
|
||||||
stats: SessionStats
|
|
||||||
): File? {
|
|
||||||
return try {
|
|
||||||
val width = 1242 // 3:4 aspect at higher resolution for better fit
|
|
||||||
val height = 1656
|
|
||||||
|
|
||||||
val bitmap = createBitmap(width, height)
|
|
||||||
val canvas = Canvas(bitmap)
|
|
||||||
|
|
||||||
val gradientDrawable =
|
|
||||||
GradientDrawable(
|
|
||||||
GradientDrawable.Orientation.TOP_BOTTOM,
|
|
||||||
intArrayOf("#667eea".toColorInt(), "#764ba2".toColorInt())
|
|
||||||
)
|
|
||||||
gradientDrawable.setBounds(0, 0, width, height)
|
|
||||||
gradientDrawable.draw(canvas)
|
|
||||||
|
|
||||||
// Setup paint objects
|
|
||||||
val titlePaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = Color.WHITE
|
|
||||||
textSize = 72f
|
|
||||||
typeface = Typeface.DEFAULT_BOLD
|
|
||||||
isAntiAlias = true
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
val subtitlePaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = "#E8E8E8".toColorInt()
|
|
||||||
textSize = 48f
|
|
||||||
typeface = Typeface.DEFAULT
|
|
||||||
isAntiAlias = true
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
val statLabelPaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = "#B8B8B8".toColorInt()
|
|
||||||
textSize = 36f
|
|
||||||
typeface = Typeface.DEFAULT
|
|
||||||
isAntiAlias = true
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
val statValuePaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = Color.WHITE
|
|
||||||
textSize = 64f
|
|
||||||
typeface = Typeface.DEFAULT_BOLD
|
|
||||||
isAntiAlias = true
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
|
|
||||||
val cardPaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = "#40FFFFFF".toColorInt()
|
|
||||||
isAntiAlias = true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw main card background
|
|
||||||
val cardRect = RectF(60f, 200f, width - 60f, height - 120f)
|
|
||||||
canvas.drawRoundRect(cardRect, 40f, 40f, cardPaint)
|
|
||||||
|
|
||||||
// Draw content
|
|
||||||
var yPosition = 300f
|
|
||||||
|
|
||||||
// Title
|
|
||||||
canvas.drawText("Climbing Session", width / 2f, yPosition, titlePaint)
|
|
||||||
yPosition += 80f
|
|
||||||
|
|
||||||
// Gym and date
|
|
||||||
canvas.drawText(gym.name, width / 2f, yPosition, subtitlePaint)
|
|
||||||
yPosition += 60f
|
|
||||||
|
|
||||||
val dateText = formatSessionDate(session.date)
|
|
||||||
canvas.drawText(dateText, width / 2f, yPosition, subtitlePaint)
|
|
||||||
yPosition += 120f
|
|
||||||
|
|
||||||
// Stats grid
|
|
||||||
val statsStartY = yPosition
|
|
||||||
val columnWidth = width / 2f
|
|
||||||
val columnMaxTextWidth = columnWidth - 120f
|
|
||||||
|
|
||||||
// Left column stats
|
|
||||||
var leftY = statsStartY
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
columnWidth / 2f,
|
|
||||||
leftY,
|
|
||||||
"Attempts",
|
|
||||||
stats.totalAttempts.toString(),
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
leftY += 120f
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
columnWidth / 2f,
|
|
||||||
leftY,
|
|
||||||
"Problems",
|
|
||||||
stats.uniqueProblemsAttempted.toString(),
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
leftY += 120f
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
columnWidth / 2f,
|
|
||||||
leftY,
|
|
||||||
"Duration",
|
|
||||||
stats.sessionDuration,
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
|
|
||||||
// Right column stats
|
|
||||||
var rightY = statsStartY
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
width - columnWidth / 2f,
|
|
||||||
rightY,
|
|
||||||
"Completed",
|
|
||||||
stats.uniqueProblemsCompleted.toString(),
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
rightY += 120f
|
|
||||||
|
|
||||||
var rightYAfter = rightY
|
|
||||||
stats.topGrade?.let { grade ->
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
width - columnWidth / 2f,
|
|
||||||
rightY,
|
|
||||||
"Top Grade",
|
|
||||||
grade,
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
rightYAfter += 120f
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grade range(s)
|
|
||||||
val boulderRange =
|
|
||||||
gradeRangeForProblems(
|
|
||||||
stats.problems.filter { it.climbType == ClimbType.BOULDER }
|
|
||||||
)
|
|
||||||
val ropeRange =
|
|
||||||
gradeRangeForProblems(stats.problems.filter { it.climbType == ClimbType.ROPE })
|
|
||||||
val rangesY = kotlin.math.max(leftY, rightYAfter) + 120f
|
|
||||||
if (boulderRange != null && ropeRange != null) {
|
|
||||||
// Two evenly spaced items
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
columnWidth / 2f,
|
|
||||||
rangesY,
|
|
||||||
"Boulder Range",
|
|
||||||
boulderRange,
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
width - columnWidth / 2f,
|
|
||||||
rangesY,
|
|
||||||
"Rope Range",
|
|
||||||
ropeRange,
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
columnMaxTextWidth
|
|
||||||
)
|
|
||||||
} else if (boulderRange != null || ropeRange != null) {
|
|
||||||
// Single centered item
|
|
||||||
val singleRange = boulderRange ?: ropeRange ?: ""
|
|
||||||
drawStatItemFitting(
|
|
||||||
canvas,
|
|
||||||
width / 2f,
|
|
||||||
rangesY,
|
|
||||||
"Grade Range",
|
|
||||||
singleRange,
|
|
||||||
statLabelPaint,
|
|
||||||
statValuePaint,
|
|
||||||
width - 200f
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// App branding
|
|
||||||
val brandingPaint =
|
|
||||||
Paint().apply {
|
|
||||||
color = "#80FFFFFF".toColorInt()
|
|
||||||
textSize = 32f
|
|
||||||
typeface = Typeface.DEFAULT
|
|
||||||
isAntiAlias = true
|
|
||||||
textAlign = Paint.Align.CENTER
|
|
||||||
}
|
|
||||||
canvas.drawText("OpenClimb", width / 2f, height - 40f, brandingPaint)
|
|
||||||
|
|
||||||
// Save to file
|
|
||||||
val shareDir = File(context.cacheDir, "shares")
|
|
||||||
if (!shareDir.exists()) {
|
|
||||||
shareDir.mkdirs()
|
|
||||||
}
|
|
||||||
|
|
||||||
val filename = "session_${session.id}_${System.currentTimeMillis()}.png"
|
|
||||||
val file = File(shareDir, filename)
|
|
||||||
|
|
||||||
val outputStream = FileOutputStream(file)
|
|
||||||
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream)
|
|
||||||
outputStream.flush()
|
|
||||||
outputStream.close()
|
|
||||||
|
|
||||||
bitmap.recycle()
|
|
||||||
|
|
||||||
file
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun drawStatItem(
|
|
||||||
canvas: Canvas,
|
|
||||||
x: Float,
|
|
||||||
y: Float,
|
|
||||||
label: String,
|
|
||||||
value: String,
|
|
||||||
labelPaint: Paint,
|
|
||||||
valuePaint: Paint
|
|
||||||
) {
|
|
||||||
canvas.drawText(value, x, y, valuePaint)
|
|
||||||
canvas.drawText(label, x, y + 50f, labelPaint)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws a stat item while fitting the value text to a max width by reducing text size if
|
|
||||||
* needed.
|
|
||||||
*/
|
|
||||||
private fun drawStatItemFitting(
|
|
||||||
canvas: Canvas,
|
|
||||||
x: Float,
|
|
||||||
y: Float,
|
|
||||||
label: String,
|
|
||||||
value: String,
|
|
||||||
labelPaint: Paint,
|
|
||||||
valuePaint: Paint,
|
|
||||||
maxTextWidth: Float
|
|
||||||
) {
|
|
||||||
val tempPaint = Paint(valuePaint)
|
|
||||||
var textSize = tempPaint.textSize
|
|
||||||
var textWidth = tempPaint.measureText(value)
|
|
||||||
while (textWidth > maxTextWidth && textSize > 36f) {
|
|
||||||
textSize -= 2f
|
|
||||||
tempPaint.textSize = textSize
|
|
||||||
textWidth = tempPaint.measureText(value)
|
|
||||||
}
|
|
||||||
canvas.drawText(value, x, y, tempPaint)
|
|
||||||
canvas.drawText(label, x, y + 50f, labelPaint)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a range string like "X - Y" for the given problems, based on their difficulty grades.
|
|
||||||
*/
|
|
||||||
private fun gradeRangeForProblems(problems: List<Problem>): String? {
|
|
||||||
if (problems.isEmpty()) return null
|
|
||||||
val grades = problems.map { it.difficulty }
|
|
||||||
val sorted = grades.sortedWith { a, b -> a.compareTo(b) }
|
|
||||||
return "${sorted.first().grade} - ${sorted.last().grade}"
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatSessionDate(dateString: String): String {
|
|
||||||
return try {
|
|
||||||
val formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME
|
|
||||||
val date = LocalDateTime.parse(dateString, formatter)
|
|
||||||
val displayFormatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy")
|
|
||||||
date.format(displayFormatter)
|
|
||||||
} catch (_: Exception) {
|
|
||||||
dateString.take(10)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun shareSessionCard(context: Context, imageFile: File) {
|
|
||||||
try {
|
|
||||||
val uri =
|
|
||||||
FileProvider.getUriForFile(
|
|
||||||
context,
|
|
||||||
"${context.packageName}.fileprovider",
|
|
||||||
imageFile
|
|
||||||
)
|
|
||||||
|
|
||||||
val shareIntent =
|
|
||||||
Intent().apply {
|
|
||||||
action = Intent.ACTION_SEND
|
|
||||||
type = "image/png"
|
|
||||||
putExtra(Intent.EXTRA_STREAM, uri)
|
|
||||||
putExtra(Intent.EXTRA_TEXT, "Check out my climbing session! #OpenClimb")
|
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
|
||||||
}
|
|
||||||
|
|
||||||
val chooser = Intent.createChooser(shareIntent, "Share Session")
|
|
||||||
chooser.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
|
||||||
context.startActivity(chooser)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the highest grade string among the given problems, respecting their difficulty
|
|
||||||
* system.
|
|
||||||
*/
|
|
||||||
private fun highestGradeForProblems(problems: List<Problem>): String? {
|
|
||||||
if (problems.isEmpty()) return null
|
|
||||||
return problems
|
|
||||||
.maxByOrNull { p -> gradeRank(p.difficulty.system, p.difficulty.grade) }
|
|
||||||
?.difficulty
|
|
||||||
?.grade
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Produces a comparable numeric rank for grades across supported systems. */
|
|
||||||
private fun gradeRank(system: DifficultySystem, grade: String): Double {
|
|
||||||
return when (system) {
|
|
||||||
DifficultySystem.V_SCALE -> {
|
|
||||||
if (grade == "VB") 0.0 else grade.removePrefix("V").toDoubleOrNull() ?: -1.0
|
|
||||||
}
|
|
||||||
DifficultySystem.FONT -> {
|
|
||||||
val list = DifficultySystem.FONT.getAvailableGrades()
|
|
||||||
val idx = list.indexOf(grade.uppercase())
|
|
||||||
if (idx >= 0) idx.toDouble()
|
|
||||||
else grade.filter { it.isDigit() }.toDoubleOrNull() ?: -1.0
|
|
||||||
}
|
|
||||||
DifficultySystem.YDS -> {
|
|
||||||
// Parse 5.X with optional letter a-d
|
|
||||||
val s = grade.lowercase()
|
|
||||||
if (!s.startsWith("5.")) return -1.0
|
|
||||||
val tail = s.removePrefix("5.")
|
|
||||||
val numberPart = tail.takeWhile { it.isDigit() || it == '.' }
|
|
||||||
val letterPart = tail.drop(numberPart.length).firstOrNull()
|
|
||||||
val base = numberPart.toDoubleOrNull() ?: return -1.0
|
|
||||||
val letterWeight =
|
|
||||||
when (letterPart) {
|
|
||||||
'a' -> 0.0
|
|
||||||
'b' -> 0.1
|
|
||||||
'c' -> 0.2
|
|
||||||
'd' -> 0.3
|
|
||||||
else -> 0.0
|
|
||||||
}
|
|
||||||
base + letterWeight
|
|
||||||
}
|
|
||||||
DifficultySystem.CUSTOM -> {
|
|
||||||
grade.filter { it.isDigit() || it == '.' || it == '-' }.toDoubleOrNull() ?: -1.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:text="OpenClimb"
|
android:text="Ascently"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:textColor="@color/widget_text_primary" />
|
android:textColor="@color/widget_text_primary" />
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">OpenClimb</string>
|
<string name="app_name">Ascently</string>
|
||||||
<string name="session_tracking_service_description">Tracks active climbing sessions and displays session information in the notification area</string>
|
<string name="session_tracking_service_description">Tracks active climbing sessions and displays session information in the notification area</string>
|
||||||
|
|
||||||
<!-- App Shortcuts -->
|
<!-- App Shortcuts -->
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<style name="Theme.OpenClimb" parent="android:Theme.Material.Light.NoActionBar" />
|
<style name="Theme.Ascently" parent="android:Theme.Material.Light.NoActionBar" />
|
||||||
|
|
||||||
<style name="Theme.OpenClimb.Splash" parent="Theme.OpenClimb">
|
<style name="Theme.Ascently.Splash" parent="Theme.Ascently">
|
||||||
<item name="android:windowSplashScreenBackground">@color/splash_background</item>
|
<item name="android:windowSplashScreenBackground">@color/splash_background</item>
|
||||||
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_mountains</item>
|
<item name="android:windowSplashScreenAnimatedIcon">@drawable/ic_mountains</item>
|
||||||
<item name="android:windowSplashScreenAnimationDuration">200</item>
|
<item name="android:windowSplashScreenAnimationDuration">200</item>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.atridad.openclimb
|
package com.atridad.ascently
|
||||||
|
|
||||||
import com.atridad.openclimb.data.format.*
|
import com.atridad.ascently.data.format.*
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.atridad.openclimb
|
package com.atridad.ascently
|
||||||
|
|
||||||
import com.atridad.openclimb.data.format.*
|
import com.atridad.ascently.data.format.*
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
@@ -18,8 +18,8 @@ class DataModelTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testClimbTypeDisplayNames() {
|
fun testClimbTypeDisplayNames() {
|
||||||
assertEquals("Rope", ClimbType.ROPE.getDisplayName())
|
assertEquals("Rope", ClimbType.ROPE.displayName)
|
||||||
assertEquals("Bouldering", ClimbType.BOULDER.getDisplayName())
|
assertEquals("Bouldering", ClimbType.BOULDER.displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -34,58 +34,58 @@ class DataModelTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDifficultySystemDisplayNames() {
|
fun testDifficultySystemDisplayNames() {
|
||||||
assertEquals("V Scale", DifficultySystem.V_SCALE.getDisplayName())
|
assertEquals("V Scale", DifficultySystem.V_SCALE.displayName)
|
||||||
assertEquals("YDS (Yosemite)", DifficultySystem.YDS.getDisplayName())
|
assertEquals("YDS (Yosemite)", DifficultySystem.YDS.displayName)
|
||||||
assertEquals("Font Scale", DifficultySystem.FONT.getDisplayName())
|
assertEquals("Font Scale", DifficultySystem.FONT.displayName)
|
||||||
assertEquals("Custom", DifficultySystem.CUSTOM.getDisplayName())
|
assertEquals("Custom", DifficultySystem.CUSTOM.displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDifficultySystemClimbTypeCompatibility() {
|
fun testDifficultySystemClimbTypeCompatibility() {
|
||||||
// Test bouldering systems
|
// Test bouldering systems
|
||||||
assertTrue(DifficultySystem.V_SCALE.isBoulderingSystem())
|
assertTrue(DifficultySystem.V_SCALE.isBoulderingSystem)
|
||||||
assertTrue(DifficultySystem.FONT.isBoulderingSystem())
|
assertTrue(DifficultySystem.FONT.isBoulderingSystem)
|
||||||
assertFalse(DifficultySystem.YDS.isBoulderingSystem())
|
assertFalse(DifficultySystem.YDS.isBoulderingSystem)
|
||||||
assertTrue(DifficultySystem.CUSTOM.isBoulderingSystem())
|
assertTrue(DifficultySystem.CUSTOM.isBoulderingSystem)
|
||||||
|
|
||||||
// Test rope systems
|
// Test rope systems
|
||||||
assertTrue(DifficultySystem.YDS.isRopeSystem())
|
assertTrue(DifficultySystem.YDS.isRopeSystem)
|
||||||
assertFalse(DifficultySystem.V_SCALE.isRopeSystem())
|
assertFalse(DifficultySystem.V_SCALE.isRopeSystem)
|
||||||
assertFalse(DifficultySystem.FONT.isRopeSystem())
|
assertFalse(DifficultySystem.FONT.isRopeSystem)
|
||||||
assertTrue(DifficultySystem.CUSTOM.isRopeSystem())
|
assertTrue(DifficultySystem.CUSTOM.isRopeSystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDifficultySystemAvailableGrades() {
|
fun testDifficultySystemAvailableGrades() {
|
||||||
val vScaleGrades = DifficultySystem.V_SCALE.getAvailableGrades()
|
val vScaleGrades = DifficultySystem.V_SCALE.availableGrades
|
||||||
assertTrue(vScaleGrades.contains("VB"))
|
assertTrue(vScaleGrades.contains("VB"))
|
||||||
assertTrue(vScaleGrades.contains("V0"))
|
assertTrue(vScaleGrades.contains("V0"))
|
||||||
assertTrue(vScaleGrades.contains("V17"))
|
assertTrue(vScaleGrades.contains("V17"))
|
||||||
assertEquals("VB", vScaleGrades.first())
|
assertEquals("VB", vScaleGrades.first())
|
||||||
|
|
||||||
val ydsGrades = DifficultySystem.YDS.getAvailableGrades()
|
val ydsGrades = DifficultySystem.YDS.availableGrades
|
||||||
assertTrue(ydsGrades.contains("5.0"))
|
assertTrue(ydsGrades.contains("5.0"))
|
||||||
assertTrue(ydsGrades.contains("5.15d"))
|
assertTrue(ydsGrades.contains("5.15d"))
|
||||||
assertTrue(ydsGrades.contains("5.10a"))
|
assertTrue(ydsGrades.contains("5.10a"))
|
||||||
|
|
||||||
val fontGrades = DifficultySystem.FONT.getAvailableGrades()
|
val fontGrades = DifficultySystem.FONT.availableGrades
|
||||||
assertTrue(fontGrades.contains("3"))
|
assertTrue(fontGrades.contains("3"))
|
||||||
assertTrue(fontGrades.contains("8C+"))
|
assertTrue(fontGrades.contains("8C+"))
|
||||||
assertTrue(fontGrades.contains("6A"))
|
assertTrue(fontGrades.contains("6A"))
|
||||||
|
|
||||||
val customGrades = DifficultySystem.CUSTOM.getAvailableGrades()
|
val customGrades = DifficultySystem.CUSTOM.availableGrades
|
||||||
assertTrue(customGrades.isEmpty())
|
assertTrue(customGrades.isEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testDifficultySystemsForClimbType() {
|
fun testDifficultySystemsForClimbType() {
|
||||||
val boulderSystems = DifficultySystem.getSystemsForClimbType(ClimbType.BOULDER)
|
val boulderSystems = DifficultySystem.systemsForClimbType(ClimbType.BOULDER)
|
||||||
assertTrue(boulderSystems.contains(DifficultySystem.V_SCALE))
|
assertTrue(boulderSystems.contains(DifficultySystem.V_SCALE))
|
||||||
assertTrue(boulderSystems.contains(DifficultySystem.FONT))
|
assertTrue(boulderSystems.contains(DifficultySystem.FONT))
|
||||||
assertTrue(boulderSystems.contains(DifficultySystem.CUSTOM))
|
assertTrue(boulderSystems.contains(DifficultySystem.CUSTOM))
|
||||||
assertFalse(boulderSystems.contains(DifficultySystem.YDS))
|
assertFalse(boulderSystems.contains(DifficultySystem.YDS))
|
||||||
|
|
||||||
val ropeSystems = DifficultySystem.getSystemsForClimbType(ClimbType.ROPE)
|
val ropeSystems = DifficultySystem.systemsForClimbType(ClimbType.ROPE)
|
||||||
assertTrue(ropeSystems.contains(DifficultySystem.YDS))
|
assertTrue(ropeSystems.contains(DifficultySystem.YDS))
|
||||||
assertTrue(ropeSystems.contains(DifficultySystem.CUSTOM))
|
assertTrue(ropeSystems.contains(DifficultySystem.CUSTOM))
|
||||||
assertFalse(ropeSystems.contains(DifficultySystem.V_SCALE))
|
assertFalse(ropeSystems.contains(DifficultySystem.V_SCALE))
|
||||||
@@ -387,7 +387,7 @@ class DataModelTests {
|
|||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
assertTrue(currentTime > 0)
|
assertTrue(currentTime > 0)
|
||||||
|
|
||||||
val timeString = java.time.Instant.ofEpochMilli(currentTime).toString()
|
val timeString = Instant.ofEpochMilli(currentTime).toString()
|
||||||
assertTrue(timeString.isNotEmpty())
|
assertTrue(timeString.isNotEmpty())
|
||||||
assertTrue(timeString.contains("T"))
|
assertTrue(timeString.contains("T"))
|
||||||
assertTrue(timeString.endsWith("Z"))
|
assertTrue(timeString.endsWith("Z"))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.atridad.openclimb
|
package com.atridad.ascently
|
||||||
|
|
||||||
import com.atridad.openclimb.data.format.*
|
import com.atridad.ascently.data.format.*
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.ascently.data.model.*
|
||||||
import org.junit.Assert.*
|
import org.junit.Assert.*
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
|
|
||||||
@@ -457,10 +457,6 @@ class SyncMergeLogicTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test active sessions excluded from sync`() {
|
fun `test active sessions excluded from sync`() {
|
||||||
// Test scenario: Active sessions should not be included in sync data
|
|
||||||
// This tests the new behavior where active sessions are excluded from sync
|
|
||||||
// until they are completed
|
|
||||||
|
|
||||||
val allLocalSessions =
|
val allLocalSessions =
|
||||||
listOf(
|
listOf(
|
||||||
BackupClimbSession(
|
BackupClimbSession(
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.atridad.openclimb
|
package com.atridad.ascently
|
||||||
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ pluginManagement {
|
|||||||
gradlePluginPortal()
|
gradlePluginPortal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencyResolutionManagement {
|
dependencyResolutionManagement {
|
||||||
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
|
||||||
repositories {
|
repositories {
|
||||||
@@ -20,5 +21,6 @@ dependencyResolutionManagement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rootProject.name = "OpenClimb"
|
rootProject.name = "Ascently"
|
||||||
|
|
||||||
include(":app")
|
include(":app")
|
||||||
|
|||||||
79
docs/.dockerignore
Normal file
79
docs/.dockerignore
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
# Node modules
|
||||||
|
node_modules
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
# Environment files
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
# Build output
|
||||||
|
dist
|
||||||
|
.astro
|
||||||
|
|
||||||
|
# IDE files
|
||||||
|
.vscode
|
||||||
|
.idea
|
||||||
|
*.swp
|
||||||
|
*.swo
|
||||||
|
|
||||||
|
# OS files
|
||||||
|
.DS_Store
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Git
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
Dockerfile
|
||||||
|
docker-compose.yml
|
||||||
|
.dockerignore
|
||||||
|
|
||||||
|
# Documentation
|
||||||
|
README.md
|
||||||
|
*.md
|
||||||
|
|
||||||
|
# Cache directories
|
||||||
|
.cache
|
||||||
|
.parcel-cache
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
*.lcov
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Dependency directories
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# Temporary folders
|
||||||
|
tmp/
|
||||||
|
temp/
|
||||||
21
docs/.gitignore
vendored
Normal file
21
docs/.gitignore
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# build output
|
||||||
|
dist/
|
||||||
|
# generated types
|
||||||
|
.astro/
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# logs
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
|
||||||
|
|
||||||
|
# environment variables
|
||||||
|
.env
|
||||||
|
.env.production
|
||||||
|
|
||||||
|
# macOS-specific files
|
||||||
|
.DS_Store
|
||||||
80
docs/Dockerfile
Normal file
80
docs/Dockerfile
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
FROM node:24-alpine AS base
|
||||||
|
|
||||||
|
# Install system dependencies
|
||||||
|
RUN apk add --no-cache \
|
||||||
|
python3 \
|
||||||
|
make \
|
||||||
|
g++ \
|
||||||
|
libc6-compat \
|
||||||
|
vips-dev \
|
||||||
|
curl
|
||||||
|
|
||||||
|
# Install pnpm globally
|
||||||
|
RUN npm install -g pnpm
|
||||||
|
|
||||||
|
# Configure pnpm
|
||||||
|
RUN pnpm config set store-dir /.pnpm-store
|
||||||
|
RUN pnpm config set network-timeout 300000
|
||||||
|
RUN pnpm config set fetch-retries 10
|
||||||
|
RUN pnpm config set fetch-retry-factor 2
|
||||||
|
|
||||||
|
FROM base AS deps
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
|
||||||
|
# Install dependencies with retry logic
|
||||||
|
RUN --mount=type=cache,id=pnpm,target=/.pnpm-store \
|
||||||
|
pnpm install --frozen-lockfile || \
|
||||||
|
(sleep 5 && pnpm install --frozen-lockfile) || \
|
||||||
|
(sleep 10 && pnpm install --frozen-lockfile --no-frozen-lockfile)
|
||||||
|
|
||||||
|
FROM base AS build-deps
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy package files
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
|
||||||
|
# Install all dependencies including dev dependencies
|
||||||
|
RUN --mount=type=cache,id=pnpm,target=/.pnpm-store \
|
||||||
|
pnpm install --frozen-lockfile || \
|
||||||
|
(sleep 5 && pnpm install --frozen-lockfile) || \
|
||||||
|
(sleep 10 && pnpm install --frozen-lockfile --no-frozen-lockfile)
|
||||||
|
|
||||||
|
FROM build-deps AS builder
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# Build the application
|
||||||
|
RUN pnpm run build
|
||||||
|
|
||||||
|
FROM node:20-alpine AS runtime
|
||||||
|
|
||||||
|
# Install pnpm for runtime
|
||||||
|
RUN npm install -g pnpm
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy built application
|
||||||
|
COPY --from=builder /app/dist ./dist
|
||||||
|
|
||||||
|
# Copy production dependencies
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy package.json for any runtime needs
|
||||||
|
COPY package.json ./
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
|
ENV HOST=0.0.0.0 \
|
||||||
|
PORT=4321 \
|
||||||
|
NODE_ENV=production
|
||||||
|
|
||||||
|
# Expose port
|
||||||
|
EXPOSE 4321
|
||||||
|
|
||||||
|
# Start the application
|
||||||
|
CMD ["node", "./dist/server/entry.mjs"]
|
||||||
12
docs/README.md
Normal file
12
docs/README.md
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
# Ascently Documentation
|
||||||
|
|
||||||
|
Documentation site for Ascently.
|
||||||
|
|
||||||
|
This was built with [Astro Starlight](https://starlight.astro.build/).
|
||||||
|
|
||||||
|
### Setup
|
||||||
|
```bash
|
||||||
|
cd Ascently/docs
|
||||||
|
pnpm install
|
||||||
|
pnpm run dev
|
||||||
|
```
|
||||||
58
docs/astro.config.mjs
Normal file
58
docs/astro.config.mjs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
// @ts-check
|
||||||
|
import { defineConfig } from "astro/config";
|
||||||
|
import starlight from "@astrojs/starlight";
|
||||||
|
|
||||||
|
import node from "@astrojs/node";
|
||||||
|
|
||||||
|
// https://astro.build/config
|
||||||
|
export default defineConfig({
|
||||||
|
site: "https://docs.ascently.app",
|
||||||
|
|
||||||
|
integrations: [
|
||||||
|
starlight({
|
||||||
|
title: "Ascently",
|
||||||
|
description:
|
||||||
|
"An offline-first FOSS climb tracking app with an optional sync server.",
|
||||||
|
logo: {
|
||||||
|
light: "./src/assets/logo.svg",
|
||||||
|
dark: "./src/assets/logo-dark.svg",
|
||||||
|
},
|
||||||
|
favicon: "/favicon.png",
|
||||||
|
social: [
|
||||||
|
{
|
||||||
|
icon: "seti:git",
|
||||||
|
label: "Gitea",
|
||||||
|
href: "https://git.atri.dad/atridad/Ascently",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
icon: "email",
|
||||||
|
label: "Contact",
|
||||||
|
href: "mailto:me@atri.dad",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
sidebar: [
|
||||||
|
{
|
||||||
|
label: "Download",
|
||||||
|
link: "/download/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Self-Hosted Sync",
|
||||||
|
items: [
|
||||||
|
{ label: "Overview", slug: "sync/overview" },
|
||||||
|
{ label: "Quick Start", slug: "sync/quick-start" },
|
||||||
|
{ label: "API Reference", slug: "sync/api-reference" },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "Privacy",
|
||||||
|
link: "/privacy/",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
customCss: ["./src/styles/custom.css"],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
|
||||||
|
adapter: node({
|
||||||
|
mode: "standalone",
|
||||||
|
}),
|
||||||
|
});
|
||||||
8
docs/docker-compose.yml
Normal file
8
docs/docker-compose.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
services:
|
||||||
|
app:
|
||||||
|
image: ${IMAGE}
|
||||||
|
ports:
|
||||||
|
- "${APP_PORT}:4321"
|
||||||
|
environment:
|
||||||
|
NODE_ENV: production
|
||||||
|
restart: unless-stopped
|
||||||
33
docs/package.json
Normal file
33
docs/package.json
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "ascently-docs",
|
||||||
|
"type": "module",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Documentation site for Ascently - FOSS climbing tracking app",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://git.atri.dad/atridad/Ascently.git",
|
||||||
|
"directory": "docs"
|
||||||
|
},
|
||||||
|
"author": "atridad <me@atri.dad>",
|
||||||
|
"license": "MIT",
|
||||||
|
"keywords": [
|
||||||
|
"climbing",
|
||||||
|
"tracking",
|
||||||
|
"documentation",
|
||||||
|
"astro",
|
||||||
|
"starlight"
|
||||||
|
],
|
||||||
|
"scripts": {
|
||||||
|
"dev": "astro dev",
|
||||||
|
"start": "astro dev",
|
||||||
|
"build": "astro build",
|
||||||
|
"preview": "astro preview",
|
||||||
|
"astro": "astro"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@astrojs/node": "^9.5.0",
|
||||||
|
"@astrojs/starlight": "^0.36.1",
|
||||||
|
"astro": "^5.14.5",
|
||||||
|
"sharp": "^0.34.4"
|
||||||
|
}
|
||||||
|
}
|
||||||
4172
docs/pnpm-lock.yaml
generated
Normal file
4172
docs/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load Diff
BIN
docs/public/favicon.ico
Normal file
BIN
docs/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
BIN
docs/public/favicon.png
Normal file
BIN
docs/public/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 731 B |
BIN
docs/src/assets/houston.webp
Normal file
BIN
docs/src/assets/houston.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
15
docs/src/assets/logo-dark.svg
Normal file
15
docs/src/assets/logo-dark.svg
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<!-- Left mountain (amber/yellow) -->
|
||||||
|
<polygon points="6,24 12,8 18,24"
|
||||||
|
fill="#FFC107"
|
||||||
|
stroke="#FFFFFF"
|
||||||
|
stroke-width="1"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
|
||||||
|
<!-- Right mountain (red) -->
|
||||||
|
<polygon points="14,24 22,4 30,24"
|
||||||
|
fill="#F44336"
|
||||||
|
stroke="#FFFFFF"
|
||||||
|
stroke-width="1"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 475 B |
15
docs/src/assets/logo-highres.svg
Normal file
15
docs/src/assets/logo-highres.svg
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<svg width="256" height="256" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<!-- Left mountain (amber/yellow) -->
|
||||||
|
<polygon points="48,192 96,64 144,192"
|
||||||
|
fill="#FFC107"
|
||||||
|
stroke="#1C1C1C"
|
||||||
|
stroke-width="4"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
|
||||||
|
<!-- Right mountain (red) -->
|
||||||
|
<polygon points="112,192 176,32 240,192"
|
||||||
|
fill="#F44336"
|
||||||
|
stroke="#1C1C1C"
|
||||||
|
stroke-width="4"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 490 B |
15
docs/src/assets/logo.svg
Normal file
15
docs/src/assets/logo.svg
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<svg width="32" height="32" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<!-- Left mountain (amber/yellow) -->
|
||||||
|
<polygon points="6,24 12,8 18,24"
|
||||||
|
fill="#FFC107"
|
||||||
|
stroke="#1C1C1C"
|
||||||
|
stroke-width="1"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
|
||||||
|
<!-- Right mountain (red) -->
|
||||||
|
<polygon points="14,24 22,4 30,24"
|
||||||
|
fill="#F44336"
|
||||||
|
stroke="#1C1C1C"
|
||||||
|
stroke-width="1"
|
||||||
|
stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 475 B |
7
docs/src/content.config.ts
Normal file
7
docs/src/content.config.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import { defineCollection } from 'astro:content';
|
||||||
|
import { docsLoader } from '@astrojs/starlight/loaders';
|
||||||
|
import { docsSchema } from '@astrojs/starlight/schema';
|
||||||
|
|
||||||
|
export const collections = {
|
||||||
|
docs: defineCollection({ loader: docsLoader(), schema: docsSchema() }),
|
||||||
|
};
|
||||||
26
docs/src/content/docs/download.md
Normal file
26
docs/src/content/docs/download.md
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
title: Download
|
||||||
|
description: Get Ascently on your Android or iOS device
|
||||||
|
---
|
||||||
|
|
||||||
|
## Android
|
||||||
|
|
||||||
|
### Option 1: Direct APK Download
|
||||||
|
Download the latest APK from the [Releases page](https://git.atri.dad/atridad/Ascently/releases).
|
||||||
|
|
||||||
|
### Option 2: Obtainium
|
||||||
|
Use Obtainium for automatic updates:
|
||||||
|
|
||||||
|
[<img src="https://github.com/ImranR98/Obtainium/blob/main/assets/graphics/badge_obtainium.png?raw=true" alt="Obtainium" height="41">](https://apps.obtainium.imranr.dev/redirect?r=obtainium://app/%7B%22id%22%3A%22com.atridad.ascently%22%2C%22url%22%3A%22https%3A%2F%2Fgit.atri.dad%2Fatridad%2FAscently%2Freleases%22%2C%22author%22%3A%22git.atri.dad%22%2C%22name%22%3A%22Ascently%22%2C%22preferredApkIndex%22%3A0%2C%22additionalSettings%22%3A%22%7B%5C%22intermediateLink%5C%22%3A%5B%5D%2C%5C%22customLinkFilterRegex%5C%22%3A%5C%22%5C%22%2C%5C%22filterByLinkText%5C%22%3Afalse%2C%5C%22skipSort%5C%22%3Afalse%2C%5C%22reverseSort%5C%22%3Afalse%2C%5C%22sortByLastLinkSegment%5C%22%3Afalse%2C%5C%22versionExtractWholePage%5C%22%3Afalse%2C%5C%22requestHeader%5C%22%3A%5B%7B%5C%22requestHeader%5C%22%3A%5C%22User-Agent%3A%20Mozilla%2F5.0%20(Linux%3B%20Android%2010%3B%20K)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F114.0.0.0%20Mobile%20Safari%2F537.36%5C%22%7D%5D%2C%5C%22defaultPseudoVersioningMethod%5C%22%3A%5C%22partialAPKHash%5C%22%2C%5C%22trackOnly%5C%22%3Afalse%2C%5C%22versionExtractionRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22matchGroupToUse%5C%22%3A%5C%22%5C%22%2C%5C%22versionDetection%5C%22%3Afalse%2C%5C%22useVersionCodeAsOSVersion%5C%22%3Afalse%2C%5C%22apkFilterRegEx%5C%22%3A%5C%22%5C%22%2C%5C%22invertAPKFilter%5C%22%3Afalse%2C%5C%22autoApkFilterByArch%5C%22%3Atrue%2C%5C%22appName%5C%22%3A%5C%22Ascently%5C%22%2C%5C%22appAuthor%5C%22%3A%5C%22%5C%22%2C%5C%22shizukuPretendToBeGooglePlay%5C%22%3Afalse%2C%5C%22allowInsecure%5C%22%3Afalse%2C%5C%22exemptFromBackgroundUpdates%5C%22%3Afalse%2C%5C%22skipUpdateNotifications%5C%22%3Afalse%2C%5C%22about%5C%22%3A%5C%22%5C%22%2C%5C%22refreshBeforeDownload%5C%22%3Afalse%7D%22%2C%22overrideSource%22%3Anull%7D)
|
||||||
|
|
||||||
|
## iOS
|
||||||
|
|
||||||
|
### App Store
|
||||||
|
Download from the app store [here](https://apps.apple.com/ca/app/ascently/id6753959144)
|
||||||
|
|
||||||
|
### TestFlight Beta
|
||||||
|
Join the TestFlight beta [here](https://testflight.apple.com/join/E2DYRGH8)
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- **Android 12+** or **iOS 17+**
|
||||||
47
docs/src/content/docs/index.mdx
Normal file
47
docs/src/content/docs/index.mdx
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
title: Ascently
|
||||||
|
description: An offline-first FOSS climb tracking app with an optional sync server.
|
||||||
|
template: splash
|
||||||
|
hero:
|
||||||
|
tagline: Track your climbing sessions, routes, and progress.
|
||||||
|
image:
|
||||||
|
file: ../../assets/logo-highres.svg
|
||||||
|
alt: "Ascently app icon"
|
||||||
|
actions:
|
||||||
|
- text: Download
|
||||||
|
link: /download/
|
||||||
|
icon: right-arrow
|
||||||
|
- text: Docs
|
||||||
|
link: /sync/overview/
|
||||||
|
icon: right-arrow
|
||||||
|
variant: minimal
|
||||||
|
---
|
||||||
|
|
||||||
|
import { Card, CardGrid } from '@astrojs/starlight/components';
|
||||||
|
|
||||||
|
## About Ascently
|
||||||
|
|
||||||
|
_Formerly OpenClimb_
|
||||||
|
|
||||||
|
Ascently is an **offline-first FOSS** app designed to help climbers track their sessions, routes/problems, and overall progress. There is an optional self-hosted sync server and integrations with Apple Health and Health Connect. There are no analytics or tracking baked into any part of this project. I am committed to maintaining a transparent and open-source solution for climbers, ensuring that you have full control over your data and privacy.
|
||||||
|
|
||||||
|
<CardGrid stagger>
|
||||||
|
<Card title="Offline-First" icon="laptop">
|
||||||
|
Your data stays on your device. No internet connection required to track your climbing sessions.
|
||||||
|
</Card>
|
||||||
|
<Card title="Cross-Platform" icon="rocket">
|
||||||
|
Built using Jetpack Compose with Material You support on Android and SwiftUI on iOS.
|
||||||
|
</Card>
|
||||||
|
<Card title="Health Integration" icon="heart">
|
||||||
|
Integrates with Apple Health and Health Connect to track your fitness data.
|
||||||
|
</Card>
|
||||||
|
<Card title="Optional Sync" icon="cloud-download">
|
||||||
|
Run your own lightweight sync server to keep data synchronized across devices.
|
||||||
|
</Card>
|
||||||
|
</CardGrid>
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
*Built with ❤️ by Atridad Lahiji*
|
||||||
|
|
||||||
|
*Contact: me@atri.dad*
|
||||||
43
docs/src/content/docs/privacy.md
Normal file
43
docs/src/content/docs/privacy.md
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
---
|
||||||
|
title: Privacy Policy
|
||||||
|
description: Ascently's Privacy Policy
|
||||||
|
---
|
||||||
|
|
||||||
|
**Last updated: September 29, 2025**
|
||||||
|
|
||||||
|
This Privacy Policy describes our policies and procedures regarding the collection, use, and disclosure of your information when you use my software.
|
||||||
|
|
||||||
|
## No Data Collection
|
||||||
|
|
||||||
|
I do not collect any personal information, analytics, or data of any kind. This software is designed to be self-hosted or run entirely offline.
|
||||||
|
|
||||||
|
All data generated by or used with this software remains on your local machine or self-hosted environment under your control. I have no access to it.
|
||||||
|
|
||||||
|
## Optional Sync Server
|
||||||
|
|
||||||
|
You may optionally configure a sync server to synchronize your data across multiple devices. When using a sync server:
|
||||||
|
|
||||||
|
- Your data is transmitted only to the server you specify
|
||||||
|
- You are responsible for the server's security and privacy practices
|
||||||
|
- I have no access to or control over your chosen sync server
|
||||||
|
- All data remains encrypted during transmission
|
||||||
|
|
||||||
|
## Optional Health Data Integration
|
||||||
|
|
||||||
|
You may optionally integrate with Apple Health or Android Health Connect to import health and fitness data. When enabled:
|
||||||
|
|
||||||
|
- Health data is accessed only on your local device
|
||||||
|
- No health data is transmitted to me, but Apple or Google may receive data according to their respective privacy policies
|
||||||
|
- You control which health metrics are imported
|
||||||
|
- You can revoke access at any time through your device's health app settings
|
||||||
|
- Please refer to Apple's Privacy Policy or Google's Privacy Policy for information about their data practices
|
||||||
|
|
||||||
|
## No Tracking or Analytics
|
||||||
|
|
||||||
|
This software does not use cookies, tracking pixels, or any other analytics or tracking mechanisms. Your usage of the software is completely private.
|
||||||
|
|
||||||
|
## Contact Us
|
||||||
|
|
||||||
|
If you have any questions about this Privacy Policy, you can contact me:
|
||||||
|
|
||||||
|
* **By email:** me@atri.dad
|
||||||
152
docs/src/content/docs/sync/api-reference.md
Normal file
152
docs/src/content/docs/sync/api-reference.md
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
---
|
||||||
|
title: API Reference
|
||||||
|
description: Complete API documentation for the Ascently sync server
|
||||||
|
---
|
||||||
|
|
||||||
|
Complete reference for all sync server endpoints.
|
||||||
|
|
||||||
|
## Authentication
|
||||||
|
|
||||||
|
All endpoints require a bearer token in the `Authorization` header:
|
||||||
|
|
||||||
|
```
|
||||||
|
Authorization: Bearer your-auth-token
|
||||||
|
```
|
||||||
|
|
||||||
|
Unauthorized requests return `401 Unauthorized`.
|
||||||
|
|
||||||
|
## Endpoints
|
||||||
|
|
||||||
|
### Health Check
|
||||||
|
|
||||||
|
**`GET /health`**
|
||||||
|
|
||||||
|
Check if the server is running.
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": "ok",
|
||||||
|
"version": "2.0.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Full Sync - Download
|
||||||
|
|
||||||
|
**`GET /sync`**
|
||||||
|
|
||||||
|
Download the entire dataset from the server.
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"exportedAt": "2024-01-15T10:30:00.000Z",
|
||||||
|
"version": "2.0",
|
||||||
|
"formatVersion": "2.0",
|
||||||
|
"gyms": [...],
|
||||||
|
"problems": [...],
|
||||||
|
"sessions": [...],
|
||||||
|
"attempts": [...],
|
||||||
|
"deletedItems": [...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns `200 OK` with the backup data, or `404 Not Found` if no data exists.
|
||||||
|
|
||||||
|
### Full Sync - Upload
|
||||||
|
|
||||||
|
**`POST /sync`**
|
||||||
|
|
||||||
|
Upload your entire dataset to the server. This overwrites all server data.
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"exportedAt": "2024-01-15T10:30:00.000Z",
|
||||||
|
"version": "2.0",
|
||||||
|
"formatVersion": "2.0",
|
||||||
|
"gyms": [...],
|
||||||
|
"problems": [...],
|
||||||
|
"sessions": [...],
|
||||||
|
"attempts": [...],
|
||||||
|
"deletedItems": [...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```
|
||||||
|
200 OK
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delta Sync
|
||||||
|
|
||||||
|
**`POST /sync/delta`**
|
||||||
|
|
||||||
|
Sync only changed data since your last sync. Much faster than full sync.
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"lastSyncTime": "2024-01-15T10:00:00.000Z",
|
||||||
|
"gyms": [...],
|
||||||
|
"problems": [...],
|
||||||
|
"sessions": [...],
|
||||||
|
"attempts": [...],
|
||||||
|
"deletedItems": [...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Include only items modified after `lastSyncTime`. The server merges your changes with its data using last-write-wins based on `updatedAt` timestamps.
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"serverTime": "2024-01-15T10:30:00.000Z",
|
||||||
|
"gyms": [...],
|
||||||
|
"problems": [...],
|
||||||
|
"sessions": [...],
|
||||||
|
"attempts": [...],
|
||||||
|
"deletedItems": [...]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Returns only server items modified after your `lastSyncTime`. Save `serverTime` as your new `lastSyncTime` for the next delta sync.
|
||||||
|
|
||||||
|
### Image Upload
|
||||||
|
|
||||||
|
**`POST /images/upload?filename={name}`**
|
||||||
|
|
||||||
|
Upload an image file.
|
||||||
|
|
||||||
|
**Query Parameters:**
|
||||||
|
- `filename`: Image filename (e.g., `problem_abc123_0.jpg`)
|
||||||
|
|
||||||
|
**Request Body:**
|
||||||
|
Binary image data (JPEG, PNG, GIF, or WebP)
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
```
|
||||||
|
200 OK
|
||||||
|
```
|
||||||
|
|
||||||
|
### Image Download
|
||||||
|
|
||||||
|
**`GET /images/download?filename={name}`**
|
||||||
|
|
||||||
|
Download an image file.
|
||||||
|
|
||||||
|
**Query Parameters:**
|
||||||
|
- `filename`: Image filename
|
||||||
|
|
||||||
|
**Response:**
|
||||||
|
Binary image data with appropriate `Content-Type` header.
|
||||||
|
|
||||||
|
Returns `404 Not Found` if the image doesn't exist.
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- All timestamps are ISO 8601 format with milliseconds
|
||||||
|
- Active sessions (status `active`) are excluded from sync
|
||||||
|
- Images are stored separately and referenced by filename
|
||||||
|
- The server stores everything in a single `ascently.json` file
|
||||||
|
- No versioning or history - last write wins
|
||||||
51
docs/src/content/docs/sync/overview.md
Normal file
51
docs/src/content/docs/sync/overview.md
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
---
|
||||||
|
title: Self-Hosted Sync Overview
|
||||||
|
description: Learn about Ascently's optional sync server for cross-device data synchronization
|
||||||
|
---
|
||||||
|
|
||||||
|
Run your own sync server to keep your data in sync across devices. The server is lightweight and easy to set up with Docker.
|
||||||
|
|
||||||
|
## How It Works
|
||||||
|
|
||||||
|
The server stores your data in a single `ascently.json` file and images in a directory. It's simple: last write wins. Authentication is a static bearer token you set.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- **Delta sync**: Only syncs changed data
|
||||||
|
- **Image sync**: Automatically syncs problem images
|
||||||
|
- **Conflict resolution**: Last-write-wins based on timestamps
|
||||||
|
- **Cross-platform**: Works with iOS and Android clients
|
||||||
|
- **Privacy**: Your data, your server, no analytics
|
||||||
|
|
||||||
|
## API Endpoints
|
||||||
|
|
||||||
|
- `GET /health` - Health check
|
||||||
|
- `GET /sync` - Download full dataset
|
||||||
|
- `POST /sync` - Upload full dataset
|
||||||
|
- `POST /sync/delta` - Sync only changes (recommended)
|
||||||
|
- `POST /images/upload?filename={name}` - Upload image
|
||||||
|
- `GET /images/download?filename={name}` - Download image
|
||||||
|
|
||||||
|
All endpoints require `Authorization: Bearer <your-token>` header.
|
||||||
|
|
||||||
|
See the [API Reference](/sync/api-reference/) for complete documentation.
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
Check out the [Quick Start guide](/sync/quick-start/) to get your server running with Docker Compose.
|
||||||
|
|
||||||
|
You'll need:
|
||||||
|
- Docker and Docker Compose
|
||||||
|
- A secure authentication token
|
||||||
|
- A place to store your data
|
||||||
|
|
||||||
|
The server will be available at `http://localhost:8080` by default. Configure your Ascently apps with your server URL and auth token to start syncing.
|
||||||
|
|
||||||
|
## How Sync Works
|
||||||
|
|
||||||
|
1. **First sync**: Client uploads or downloads full dataset
|
||||||
|
2. **Subsequent syncs**: Client uses delta sync to only transfer changed data
|
||||||
|
3. **Conflicts**: Resolved automatically using timestamps (newer wins)
|
||||||
|
4. **Images**: Synced automatically with problem data
|
||||||
|
|
||||||
|
Active sessions are excluded from sync until completed.
|
||||||
169
docs/src/content/docs/sync/quick-start.md
Normal file
169
docs/src/content/docs/sync/quick-start.md
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
---
|
||||||
|
title: Quick Start
|
||||||
|
description: Get your Ascently sync server running with Docker Compose
|
||||||
|
---
|
||||||
|
|
||||||
|
Get your sync server running in minutes with Docker Compose.
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
|
||||||
|
- Docker and Docker Compose installed
|
||||||
|
- A server or computer to host the sync service
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
1. Create a `docker-compose.yml` file:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
ascently-sync:
|
||||||
|
image: git.atri.dad/atridad/ascently-sync:latest
|
||||||
|
ports:
|
||||||
|
- "8080:8080"
|
||||||
|
environment:
|
||||||
|
- AUTH_TOKEN=${AUTH_TOKEN}
|
||||||
|
- DATA_FILE=/data/ascently.json
|
||||||
|
- IMAGES_DIR=/data/images
|
||||||
|
volumes:
|
||||||
|
- ./ascently-data:/data
|
||||||
|
restart: unless-stopped
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Create a `.env` file in the same directory:
|
||||||
|
|
||||||
|
```env
|
||||||
|
AUTH_TOKEN=your-super-secret-token-here
|
||||||
|
```
|
||||||
|
|
||||||
|
Replace `your-super-secret-token-here` with a secure random token (see below).
|
||||||
|
|
||||||
|
3. Start the server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
The server will be available at `http://localhost:8080`.
|
||||||
|
|
||||||
|
## Generate a Secure Token
|
||||||
|
|
||||||
|
Use this command to generate a secure authentication token:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
openssl rand -base64 32
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy the output and paste it into your `.env` file as the `AUTH_TOKEN`.
|
||||||
|
|
||||||
|
Keep this token secret and don't commit it to version control.
|
||||||
|
|
||||||
|
## Configure Your Apps
|
||||||
|
|
||||||
|
Open Ascently on your iOS or Android device:
|
||||||
|
|
||||||
|
1. Go to **Settings**
|
||||||
|
2. Scroll to **Sync Configuration**
|
||||||
|
3. Enter your **Server URL**: `http://your-server-ip:8080`
|
||||||
|
4. Enter your **Auth Token**: (the token from your `.env` file)
|
||||||
|
5. Tap **Test Connection** to verify it works
|
||||||
|
6. Enable **Auto Sync**
|
||||||
|
7. Tap **Sync Now** to perform your first sync
|
||||||
|
|
||||||
|
Repeat this on all your devices to keep them in sync.
|
||||||
|
|
||||||
|
## Verify It's Working
|
||||||
|
|
||||||
|
Check the server logs:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose logs -f ascently-sync
|
||||||
|
```
|
||||||
|
|
||||||
|
You should see logs like:
|
||||||
|
|
||||||
|
```
|
||||||
|
Delta sync from 192.168.1.100: lastSyncTime=2024-01-15T10:00:00.000Z, gyms=1, problems=5, sessions=2, attempts=10, deletedItems=0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Remote Access
|
||||||
|
|
||||||
|
To access your server remotely:
|
||||||
|
|
||||||
|
### Option 1: Port Forwarding
|
||||||
|
|
||||||
|
1. Forward port 8080 on your router to your server
|
||||||
|
2. Find your public IP address
|
||||||
|
3. Use `http://your-public-ip:8080` as the server URL
|
||||||
|
|
||||||
|
### Option 2: Domain Name (Recommended)
|
||||||
|
|
||||||
|
1. Get a domain name and point it to your server
|
||||||
|
2. Set up a reverse proxy (nginx, Caddy, Traefik)
|
||||||
|
3. Enable HTTPS with Let's Encrypt
|
||||||
|
4. Use `https://sync.yourdomain.com` as the server URL
|
||||||
|
|
||||||
|
Example nginx config with HTTPS:
|
||||||
|
|
||||||
|
```nginx
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name sync.yourdomain.com;
|
||||||
|
|
||||||
|
ssl_certificate /etc/letsencrypt/live/sync.yourdomain.com/fullchain.pem;
|
||||||
|
ssl_certificate_key /etc/letsencrypt/live/sync.yourdomain.com/privkey.pem;
|
||||||
|
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:8080;
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Updating
|
||||||
|
|
||||||
|
Pull the latest image and restart:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
|
Your data is stored in `./ascently-data` and persists across updates.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Connection Failed
|
||||||
|
|
||||||
|
- Check the server is running: `docker-compose ps`
|
||||||
|
- Verify the auth token matches on server and client
|
||||||
|
- Check firewall settings and port forwarding
|
||||||
|
- Test locally first with `http://localhost:8080`
|
||||||
|
|
||||||
|
### Sync Errors
|
||||||
|
|
||||||
|
- Check server logs: `docker-compose logs ascently-sync`
|
||||||
|
- Verify your device has internet connection
|
||||||
|
- Try disabling and re-enabling sync
|
||||||
|
- Perform a manual sync from Settings
|
||||||
|
|
||||||
|
### Data Location
|
||||||
|
|
||||||
|
All data is stored in `./ascently-data/`:
|
||||||
|
|
||||||
|
```
|
||||||
|
ascently-data/
|
||||||
|
├── ascently.json # Your climb data
|
||||||
|
└── images/ # Problem images
|
||||||
|
```
|
||||||
|
|
||||||
|
You can back this up or move it to another server.
|
||||||
|
|
||||||
|
## Next Steps
|
||||||
|
|
||||||
|
- Read the [API Reference](/sync/api-reference/) for advanced usage
|
||||||
|
- Set up automated backups of your `ascently-data` directory
|
||||||
|
- Configure HTTPS for secure remote access
|
||||||
|
- Monitor server logs for sync activity
|
||||||
13
docs/src/styles/custom.css
Normal file
13
docs/src/styles/custom.css
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
:root {
|
||||||
|
--sl-color-accent: hsl(4, 90%, 58%);
|
||||||
|
--sl-color-accent-low: hsl(4, 90%, 96%);
|
||||||
|
--sl-color-accent-high: hsl(4, 90%, 30%);
|
||||||
|
--climbing-amber: hsl(45, 100%, 50%);
|
||||||
|
--climbing-red: hsl(4, 90%, 58%);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-theme="dark"] {
|
||||||
|
--sl-color-accent: hsl(45, 100%, 50%);
|
||||||
|
--sl-color-accent-low: hsl(45, 100%, 10%);
|
||||||
|
--sl-color-accent-high: hsl(45, 100%, 70%);
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user