Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
8b9901383a
|
|||
|
cf2adeef7a
|
|||
|
a7481135b4
|
|||
|
748a23e1c0
|
8
.idea/deploymentTargetSelector.xml
generated
8
.idea/deploymentTargetSelector.xml
generated
@@ -4,6 +4,14 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
<DropdownSelection timestamp="2025-08-27T22:55:36.064836Z">
|
||||||
|
<Target type="DEFAULT_BOOT">
|
||||||
|
<handle>
|
||||||
|
<DeviceId pluginId="LocalEmulator" identifier="path=/Users/atridad/.android/avd/Pixel_9a.avd" />
|
||||||
|
</handle>
|
||||||
|
</Target>
|
||||||
|
</DropdownSelection>
|
||||||
|
<DialogSelection />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.android.application)
|
alias(libs.plugins.android.application)
|
||||||
alias(libs.plugins.kotlin.android)
|
alias(libs.plugins.kotlin.android)
|
||||||
@@ -12,10 +14,10 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.atridad.openclimb"
|
applicationId = "com.atridad.openclimb"
|
||||||
minSdk = 33
|
minSdk = 34
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 15
|
versionCode = 18
|
||||||
versionName = "1.1.0"
|
versionName = "1.2.0"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -33,9 +35,6 @@ android {
|
|||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "17"
|
|
||||||
}
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
toolchain {
|
toolchain {
|
||||||
@@ -48,6 +47,12 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
compilerOptions {
|
||||||
|
jvmTarget.set(JvmTarget.JVM_17)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Core Android libraries
|
// Core Android libraries
|
||||||
implementation(libs.androidx.core.ktx)
|
implementation(libs.androidx.core.ktx)
|
||||||
@@ -64,6 +69,7 @@ dependencies {
|
|||||||
// Room Database
|
// Room Database
|
||||||
implementation(libs.androidx.room.runtime)
|
implementation(libs.androidx.room.runtime)
|
||||||
implementation(libs.androidx.room.ktx)
|
implementation(libs.androidx.room.ktx)
|
||||||
|
|
||||||
ksp(libs.androidx.room.compiler)
|
ksp(libs.androidx.room.compiler)
|
||||||
|
|
||||||
// Navigation
|
// Navigation
|
||||||
@@ -81,6 +87,8 @@ dependencies {
|
|||||||
// Image Loading
|
// Image Loading
|
||||||
implementation(libs.coil.compose)
|
implementation(libs.coil.compose)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Testing
|
// Testing
|
||||||
testImplementation(libs.junit)
|
testImplementation(libs.junit)
|
||||||
testImplementation(libs.mockk)
|
testImplementation(libs.mockk)
|
||||||
|
|||||||
@@ -8,11 +8,13 @@
|
|||||||
android:maxSdkVersion="28" />
|
android:maxSdkVersion="28" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
|
||||||
|
<!-- Hardware features -->
|
||||||
|
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||||
|
|
||||||
<!-- Permissions for notifications and foreground service -->
|
<!-- Permissions for notifications and foreground service -->
|
||||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -52,7 +54,8 @@
|
|||||||
android:name=".service.SessionTrackingService"
|
android:name=".service.SessionTrackingService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
android:foregroundServiceType="specialUse">
|
android:foregroundServiceType="specialUse"
|
||||||
|
android:description="@string/session_tracking_service_description">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="android.app.foreground_service_type"
|
android:name="android.app.foreground_service_type"
|
||||||
android:value="specialUse" />
|
android:value="specialUse" />
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.app.Service
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.IBinder
|
import android.os.IBinder
|
||||||
import android.os.PowerManager
|
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
import com.atridad.openclimb.MainActivity
|
import com.atridad.openclimb.MainActivity
|
||||||
import com.atridad.openclimb.R
|
import com.atridad.openclimb.R
|
||||||
@@ -17,13 +16,13 @@ import kotlinx.coroutines.*
|
|||||||
import kotlinx.coroutines.flow.firstOrNull
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.temporal.ChronoUnit
|
import java.time.temporal.ChronoUnit
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
class SessionTrackingService : Service() {
|
class SessionTrackingService : Service() {
|
||||||
|
|
||||||
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
private val serviceScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
private var notificationJob: Job? = null
|
private var notificationJob: Job? = null
|
||||||
private var monitoringJob: Job? = null
|
private var monitoringJob: Job? = null
|
||||||
private var wakeLock: PowerManager.WakeLock? = null
|
|
||||||
|
|
||||||
private lateinit var repository: ClimbRepository
|
private lateinit var repository: ClimbRepository
|
||||||
private lateinit var notificationManager: NotificationManager
|
private lateinit var notificationManager: NotificationManager
|
||||||
@@ -58,7 +57,6 @@ class SessionTrackingService : Service() {
|
|||||||
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
|
||||||
|
|
||||||
createNotificationChannel()
|
createNotificationChannel()
|
||||||
acquireWakeLock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
||||||
@@ -87,59 +85,51 @@ class SessionTrackingService : Service() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Return START_STICKY to restart service if it gets killed
|
|
||||||
return START_STICKY
|
return START_REDELIVER_INTENT
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTaskRemoved(rootIntent: Intent?) {
|
override fun onTaskRemoved(rootIntent: Intent?) {
|
||||||
super.onTaskRemoved(rootIntent)
|
super.onTaskRemoved(rootIntent)
|
||||||
// If the app is removed from recent tasks, ensure the service keeps running
|
|
||||||
// This helps maintain the notification even if the user swipes away the app
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLowMemory() {
|
|
||||||
super.onLowMemory()
|
|
||||||
// Don't stop the service on low memory, just log it
|
|
||||||
// The notification is important for user experience
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBind(intent: Intent?): IBinder? = null
|
override fun onBind(intent: Intent?): IBinder? = null
|
||||||
|
|
||||||
private fun startSessionTracking(sessionId: String) {
|
private fun startSessionTracking(sessionId: String) {
|
||||||
// Cancel any existing jobs
|
|
||||||
notificationJob?.cancel()
|
notificationJob?.cancel()
|
||||||
monitoringJob?.cancel()
|
monitoringJob?.cancel()
|
||||||
|
|
||||||
// Start the main notification update job
|
try {
|
||||||
|
createAndShowNotification(sessionId)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
|
||||||
notificationJob = serviceScope.launch {
|
notificationJob = serviceScope.launch {
|
||||||
try {
|
try {
|
||||||
// Initial notification update
|
if (!isNotificationActive()) {
|
||||||
updateNotification(sessionId)
|
delay(1000L)
|
||||||
|
createAndShowNotification(sessionId)
|
||||||
|
}
|
||||||
|
|
||||||
// Update every 2 seconds for better performance
|
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(2000L)
|
delay(5000L)
|
||||||
updateNotification(sessionId)
|
updateNotification(sessionId)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// Log error and continue
|
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the monitoring job that ensures notification stays active
|
|
||||||
monitoringJob = serviceScope.launch {
|
monitoringJob = serviceScope.launch {
|
||||||
try {
|
try {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
delay(5000L) // Check every 5 seconds
|
delay(10000L)
|
||||||
|
|
||||||
// Verify the notification is still active
|
|
||||||
if (!isNotificationActive()) {
|
if (!isNotificationActive()) {
|
||||||
// Notification was dismissed, recreate it
|
|
||||||
updateNotification(sessionId)
|
updateNotification(sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify the session is still active
|
|
||||||
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.openclimb.data.model.SessionStatus.ACTIVE) {
|
||||||
stopSessionTracking()
|
stopSessionTracking()
|
||||||
@@ -155,7 +145,6 @@ class SessionTrackingService : Service() {
|
|||||||
private fun stopSessionTracking() {
|
private fun stopSessionTracking() {
|
||||||
notificationJob?.cancel()
|
notificationJob?.cancel()
|
||||||
monitoringJob?.cancel()
|
monitoringJob?.cancel()
|
||||||
releaseWakeLock()
|
|
||||||
stopForeground(STOP_FOREGROUND_REMOVE)
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
stopSelf()
|
stopSelf()
|
||||||
}
|
}
|
||||||
@@ -171,14 +160,37 @@ class SessionTrackingService : Service() {
|
|||||||
|
|
||||||
private suspend fun updateNotification(sessionId: String) {
|
private suspend fun updateNotification(sessionId: String) {
|
||||||
try {
|
try {
|
||||||
val session = repository.getSessionById(sessionId)
|
createAndShowNotification(sessionId)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
|
||||||
|
try {
|
||||||
|
delay(10000L)
|
||||||
|
createAndShowNotification(sessionId)
|
||||||
|
} catch (retryException: Exception) {
|
||||||
|
retryException.printStackTrace()
|
||||||
|
stopSessionTracking()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createAndShowNotification(sessionId: String) {
|
||||||
|
try {
|
||||||
|
val session = runBlocking {
|
||||||
|
repository.getSessionById(sessionId)
|
||||||
|
}
|
||||||
if (session == null || session.status != com.atridad.openclimb.data.model.SessionStatus.ACTIVE) {
|
if (session == null || session.status != com.atridad.openclimb.data.model.SessionStatus.ACTIVE) {
|
||||||
stopSessionTracking()
|
stopSessionTracking()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val gym = repository.getGymById(session.gymId)
|
val gym = runBlocking {
|
||||||
val attempts = repository.getAttemptsBySession(sessionId).firstOrNull() ?: emptyList()
|
repository.getGymById(session.gymId)
|
||||||
|
}
|
||||||
|
|
||||||
|
val attempts = runBlocking {
|
||||||
|
repository.getAttemptsBySession(sessionId).firstOrNull() ?: emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
val duration = session.startTime?.let { startTime ->
|
val duration = session.startTime?.let { startTime ->
|
||||||
try {
|
try {
|
||||||
@@ -205,7 +217,7 @@ class SessionTrackingService : Service() {
|
|||||||
.setSmallIcon(R.drawable.ic_mountains)
|
.setSmallIcon(R.drawable.ic_mountains)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setAutoCancel(false)
|
.setAutoCancel(false)
|
||||||
.setPriority(NotificationCompat.PRIORITY_LOW)
|
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||||
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
||||||
.setContentIntent(createOpenAppIntent())
|
.setContentIntent(createOpenAppIntent())
|
||||||
@@ -221,24 +233,13 @@ class SessionTrackingService : Service() {
|
|||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
// Always start foreground to ensure service stays alive
|
|
||||||
startForeground(NOTIFICATION_ID, notification)
|
startForeground(NOTIFICATION_ID, notification)
|
||||||
|
|
||||||
// Also notify separately to ensure it's visible
|
|
||||||
notificationManager.notify(NOTIFICATION_ID, notification)
|
notificationManager.notify(NOTIFICATION_ID, notification)
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
// Don't stop the service on notification errors, just log them
|
throw e
|
||||||
// Try to restart the notification after a delay
|
|
||||||
try {
|
|
||||||
delay(5000L)
|
|
||||||
updateNotification(sessionId)
|
|
||||||
} catch (retryException: Exception) {
|
|
||||||
retryException.printStackTrace()
|
|
||||||
// If retry fails, stop the service to prevent infinite loops
|
|
||||||
stopSessionTracking()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,50 +270,23 @@ class SessionTrackingService : Service() {
|
|||||||
val channel = NotificationChannel(
|
val channel = NotificationChannel(
|
||||||
CHANNEL_ID,
|
CHANNEL_ID,
|
||||||
"Session Tracking",
|
"Session Tracking",
|
||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationManager.IMPORTANCE_DEFAULT
|
||||||
).apply {
|
).apply {
|
||||||
description = "Shows active climbing session information"
|
description = "Shows active climbing session information"
|
||||||
setShowBadge(false)
|
setShowBadge(false)
|
||||||
lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
|
lockscreenVisibility = NotificationCompat.VISIBILITY_PUBLIC
|
||||||
enableLights(false)
|
enableLights(false)
|
||||||
enableVibration(false)
|
enableVibration(false)
|
||||||
|
setSound(null, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManager.createNotificationChannel(channel)
|
notificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun acquireWakeLock() {
|
|
||||||
try {
|
|
||||||
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
|
|
||||||
wakeLock = powerManager.newWakeLock(
|
|
||||||
PowerManager.PARTIAL_WAKE_LOCK,
|
|
||||||
"OpenClimb:SessionTrackingWakeLock"
|
|
||||||
).apply {
|
|
||||||
acquire(10*60*1000L) // 10 minutes timeout
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun releaseWakeLock() {
|
|
||||||
try {
|
|
||||||
wakeLock?.let {
|
|
||||||
if (it.isHeld) {
|
|
||||||
it.release()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wakeLock = null
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
notificationJob?.cancel()
|
notificationJob?.cancel()
|
||||||
monitoringJob?.cancel()
|
monitoringJob?.cancel()
|
||||||
releaseWakeLock()
|
|
||||||
serviceScope.cancel()
|
serviceScope.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,297 @@
|
|||||||
|
package com.atridad.openclimb.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.Canvas
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.graphics.*
|
||||||
|
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||||
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.text.TextMeasurer
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
|
import androidx.compose.ui.text.drawText
|
||||||
|
import androidx.compose.ui.text.rememberTextMeasurer
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data point for the line chart
|
||||||
|
*/
|
||||||
|
data class ChartDataPoint(
|
||||||
|
val x: Float,
|
||||||
|
val y: Float,
|
||||||
|
val label: String? = null
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Configuration for chart styling
|
||||||
|
*/
|
||||||
|
data class ChartStyle(
|
||||||
|
val lineColor: Color = Color(0xFF6366F1),
|
||||||
|
val fillColor: Color = Color(0x336366F1),
|
||||||
|
val lineWidth: Float = 3f,
|
||||||
|
val gridColor: Color = Color(0xFFE5E7EB),
|
||||||
|
val textColor: Color = Color(0xFF374151),
|
||||||
|
val backgroundColor: Color = Color.White
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom Line Chart with area fill below the line
|
||||||
|
*/
|
||||||
|
@Composable
|
||||||
|
fun LineChart(
|
||||||
|
data: List<ChartDataPoint>,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
style: ChartStyle = ChartStyle(),
|
||||||
|
showGrid: Boolean = true,
|
||||||
|
xAxisFormatter: (Float) -> String = { it.toString() },
|
||||||
|
yAxisFormatter: (Float) -> String = { it.toString() }
|
||||||
|
) {
|
||||||
|
val textMeasurer = rememberTextMeasurer()
|
||||||
|
val density = LocalDensity.current
|
||||||
|
|
||||||
|
Box(modifier = modifier) {
|
||||||
|
Canvas(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
if (data.isEmpty()) return@Canvas
|
||||||
|
|
||||||
|
val padding = with(density) { 32.dp.toPx() }
|
||||||
|
val chartWidth = size.width - padding * 2
|
||||||
|
val chartHeight = size.height - padding * 2
|
||||||
|
|
||||||
|
// Calculate data bounds
|
||||||
|
val dataMinY = data.minOf { it.y }
|
||||||
|
val dataMaxY = data.maxOf { it.y }
|
||||||
|
|
||||||
|
// Add some padding to Y-axis (10% above and below the data range)
|
||||||
|
val yPadding = if (dataMaxY == dataMinY) 1f else (dataMaxY - dataMinY) * 0.1f
|
||||||
|
val minY = dataMinY - yPadding
|
||||||
|
val maxY = dataMaxY + yPadding
|
||||||
|
|
||||||
|
val minX = data.minOf { it.x }
|
||||||
|
val maxX = data.maxOf { it.x }
|
||||||
|
|
||||||
|
val xRange = if (maxX - minX == 0f) 1f else maxX - minX // Minimum range of 1 for single points
|
||||||
|
val yRange = maxY - minY
|
||||||
|
|
||||||
|
// Ensure we have valid ranges
|
||||||
|
if (yRange == 0f) return@Canvas
|
||||||
|
|
||||||
|
// Convert data points to screen coordinates
|
||||||
|
val screenPoints = data.map { point ->
|
||||||
|
val x = padding + (point.x - minX) / xRange * chartWidth
|
||||||
|
val y = padding + chartHeight - (point.y - minY) / yRange * chartHeight
|
||||||
|
Offset(x, y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw background
|
||||||
|
drawRect(
|
||||||
|
color = style.backgroundColor,
|
||||||
|
topLeft = Offset(padding, padding),
|
||||||
|
size = androidx.compose.ui.geometry.Size(chartWidth, chartHeight)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Draw grid
|
||||||
|
if (showGrid) {
|
||||||
|
drawGrid(
|
||||||
|
padding = padding,
|
||||||
|
chartWidth = chartWidth,
|
||||||
|
chartHeight = chartHeight,
|
||||||
|
gridColor = style.gridColor,
|
||||||
|
minX = minX,
|
||||||
|
maxX = maxX,
|
||||||
|
minY = minY,
|
||||||
|
maxY = maxY,
|
||||||
|
textMeasurer = textMeasurer,
|
||||||
|
textColor = style.textColor,
|
||||||
|
xAxisFormatter = xAxisFormatter,
|
||||||
|
yAxisFormatter = yAxisFormatter,
|
||||||
|
actualDataPoints = data
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw area fill
|
||||||
|
if (screenPoints.size > 1) {
|
||||||
|
drawAreaFill(
|
||||||
|
points = screenPoints,
|
||||||
|
padding = padding,
|
||||||
|
chartHeight = chartHeight,
|
||||||
|
fillColor = style.fillColor
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw line
|
||||||
|
if (screenPoints.size > 1) {
|
||||||
|
drawLine(
|
||||||
|
points = screenPoints,
|
||||||
|
lineColor = style.lineColor,
|
||||||
|
lineWidth = style.lineWidth
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw data points
|
||||||
|
screenPoints.forEach { point ->
|
||||||
|
drawCircle(
|
||||||
|
color = style.lineColor,
|
||||||
|
radius = style.lineWidth * 1.5f,
|
||||||
|
center = point
|
||||||
|
)
|
||||||
|
drawCircle(
|
||||||
|
color = style.backgroundColor,
|
||||||
|
radius = style.lineWidth * 0.8f,
|
||||||
|
center = point
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun DrawScope.drawGrid(
|
||||||
|
padding: Float,
|
||||||
|
chartWidth: Float,
|
||||||
|
chartHeight: Float,
|
||||||
|
gridColor: Color,
|
||||||
|
minX: Float,
|
||||||
|
maxX: Float,
|
||||||
|
minY: Float,
|
||||||
|
maxY: Float,
|
||||||
|
textMeasurer: TextMeasurer,
|
||||||
|
textColor: Color,
|
||||||
|
xAxisFormatter: (Float) -> String,
|
||||||
|
yAxisFormatter: (Float) -> String,
|
||||||
|
actualDataPoints: List<ChartDataPoint>
|
||||||
|
) {
|
||||||
|
val textStyle = TextStyle(
|
||||||
|
color = textColor,
|
||||||
|
fontSize = 10.sp
|
||||||
|
)
|
||||||
|
|
||||||
|
// Draw vertical grid lines (X-axis) - only at integer values for sessions
|
||||||
|
val xRange = maxX - minX
|
||||||
|
if (xRange > 0) {
|
||||||
|
val startX = kotlin.math.ceil(minX).toInt()
|
||||||
|
val endX = kotlin.math.floor(maxX).toInt()
|
||||||
|
|
||||||
|
for (sessionNum in startX..endX) {
|
||||||
|
val x = padding + (sessionNum.toFloat() - minX) / xRange * chartWidth
|
||||||
|
|
||||||
|
// Draw grid line
|
||||||
|
drawLine(
|
||||||
|
color = gridColor,
|
||||||
|
start = Offset(x, padding),
|
||||||
|
end = Offset(x, padding + chartHeight),
|
||||||
|
strokeWidth = 1.dp.toPx()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Draw label
|
||||||
|
val text = xAxisFormatter(sessionNum.toFloat())
|
||||||
|
val textSize = textMeasurer.measure(text, textStyle)
|
||||||
|
drawText(
|
||||||
|
textMeasurer = textMeasurer,
|
||||||
|
text = text,
|
||||||
|
style = textStyle,
|
||||||
|
topLeft = Offset(
|
||||||
|
x - textSize.size.width / 2f,
|
||||||
|
padding + chartHeight + 8.dp.toPx()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw horizontal grid lines (Y-axis) - only at actual data point values
|
||||||
|
val yRange = maxY - minY
|
||||||
|
if (yRange > 0) {
|
||||||
|
// Get unique Y values from actual data points
|
||||||
|
val actualYValues = actualDataPoints.map { kotlin.math.round(it.y).toInt() }.toSet()
|
||||||
|
|
||||||
|
actualYValues.forEach { gradeValue ->
|
||||||
|
val y = padding + chartHeight - (gradeValue.toFloat() - minY) / yRange * chartHeight
|
||||||
|
|
||||||
|
// Only draw if within chart bounds
|
||||||
|
if (y >= padding && y <= padding + chartHeight) {
|
||||||
|
// Draw grid line
|
||||||
|
drawLine(
|
||||||
|
color = gridColor,
|
||||||
|
start = Offset(padding, y),
|
||||||
|
end = Offset(padding + chartWidth, y),
|
||||||
|
strokeWidth = 1.dp.toPx()
|
||||||
|
)
|
||||||
|
|
||||||
|
// Draw label
|
||||||
|
val text = yAxisFormatter(gradeValue.toFloat())
|
||||||
|
val textSize = textMeasurer.measure(text, textStyle)
|
||||||
|
drawText(
|
||||||
|
textMeasurer = textMeasurer,
|
||||||
|
text = text,
|
||||||
|
style = textStyle,
|
||||||
|
topLeft = Offset(
|
||||||
|
padding - textSize.size.width - 8.dp.toPx(),
|
||||||
|
y - textSize.size.height / 2f
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun DrawScope.drawAreaFill(
|
||||||
|
points: List<Offset>,
|
||||||
|
padding: Float,
|
||||||
|
chartHeight: Float,
|
||||||
|
fillColor: Color
|
||||||
|
) {
|
||||||
|
val bottomY = padding + chartHeight // This represents the bottom of the chart area
|
||||||
|
|
||||||
|
val path = Path().apply {
|
||||||
|
// Start from bottom-left (at chart bottom level)
|
||||||
|
moveTo(points.first().x, bottomY)
|
||||||
|
|
||||||
|
// Draw to first point
|
||||||
|
lineTo(points.first().x, points.first().y)
|
||||||
|
|
||||||
|
// Draw line through all points
|
||||||
|
for (i in 1 until points.size) {
|
||||||
|
lineTo(points[i].x, points[i].y)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the path by going to bottom-right (at chart bottom level) and back to start
|
||||||
|
lineTo(points.last().x, bottomY)
|
||||||
|
lineTo(points.first().x, bottomY)
|
||||||
|
close()
|
||||||
|
}
|
||||||
|
|
||||||
|
drawPath(
|
||||||
|
path = path,
|
||||||
|
color = fillColor
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun DrawScope.drawLine(
|
||||||
|
points: List<Offset>,
|
||||||
|
lineColor: Color,
|
||||||
|
lineWidth: Float
|
||||||
|
) {
|
||||||
|
val path = Path().apply {
|
||||||
|
moveTo(points.first().x, points.first().y)
|
||||||
|
for (i in 1 until points.size) {
|
||||||
|
lineTo(points[i].x, points[i].y)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drawPath(
|
||||||
|
path = path,
|
||||||
|
color = lineColor,
|
||||||
|
style = Stroke(
|
||||||
|
width = lineWidth,
|
||||||
|
cap = StrokeCap.Round,
|
||||||
|
join = StrokeJoin.Round
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -16,6 +16,7 @@ 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 androidx.compose.ui.platform.LocalContext
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.openclimb.data.model.*
|
||||||
import com.atridad.openclimb.ui.components.ImagePicker
|
import com.atridad.openclimb.ui.components.ImagePicker
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
||||||
@@ -80,7 +81,7 @@ fun AddEditGymScreen(
|
|||||||
val gym = Gym.create(name, location, selectedClimbTypes.toList(), selectedDifficultySystems.toList(), notes = notes)
|
val gym = Gym.create(name, location, selectedClimbTypes.toList(), selectedDifficultySystems.toList(), notes = notes)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateGym(gym.copy(id = gymId))
|
viewModel.updateGym(gym.copy(id = gymId!!))
|
||||||
} else {
|
} else {
|
||||||
viewModel.addGym(gym)
|
viewModel.addGym(gym)
|
||||||
}
|
}
|
||||||
@@ -348,7 +349,7 @@ fun AddEditProblemScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateProblem(problem.copy(id = problemId))
|
viewModel.updateProblem(problem.copy(id = problemId!!))
|
||||||
} else {
|
} else {
|
||||||
viewModel.addProblem(problem)
|
viewModel.addProblem(problem)
|
||||||
}
|
}
|
||||||
@@ -565,7 +566,7 @@ fun AddEditProblemScreen(
|
|||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||||
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(),
|
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.menuAnchor()
|
.menuAnchor(androidx.compose.material3.MenuAnchorType.PrimaryNotEditable, enabled = true)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
@@ -688,6 +689,7 @@ fun AddEditSessionScreen(
|
|||||||
) {
|
) {
|
||||||
val isEditing = sessionId != null
|
val isEditing = sessionId != null
|
||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
// Session form state
|
// Session form state
|
||||||
var selectedGym by remember { mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } }) }
|
var selectedGym by remember { mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } }) }
|
||||||
@@ -727,15 +729,14 @@ fun AddEditSessionScreen(
|
|||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedGym?.let { gym ->
|
selectedGym?.let { gym ->
|
||||||
|
if (isEditing) {
|
||||||
val session = ClimbSession.create(
|
val session = ClimbSession.create(
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
notes = sessionNotes.ifBlank { null }
|
notes = sessionNotes.ifBlank { null }
|
||||||
)
|
)
|
||||||
|
viewModel.updateSession(session.copy(id = sessionId!!))
|
||||||
if (isEditing) {
|
|
||||||
viewModel.updateSession(session.copy(id = sessionId))
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.addSession(session)
|
viewModel.startSession(context, gym.id, sessionNotes.ifBlank { null })
|
||||||
}
|
}
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ 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.openclimb.R
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
||||||
|
import com.atridad.openclimb.data.model.ClimbType
|
||||||
|
import com.atridad.openclimb.data.model.DifficultySystem
|
||||||
|
import com.atridad.openclimb.ui.components.ChartDataPoint
|
||||||
|
import com.atridad.openclimb.ui.components.LineChart
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AnalyticsScreen(
|
fun AnalyticsScreen(
|
||||||
@@ -57,20 +61,10 @@ fun AnalyticsScreen(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success Rate
|
// Progress Chart
|
||||||
item {
|
item {
|
||||||
val successfulAttempts = attempts.count {
|
val progressData = calculateProgressOverTime(sessions, problems, attempts)
|
||||||
it.result.name in listOf("SUCCESS", "FLASH", "REDPOINT", "ONSIGHT")
|
ProgressChartCard(progressData = progressData, problems = problems)
|
||||||
}
|
|
||||||
val successRate = if (attempts.isNotEmpty()) {
|
|
||||||
(successfulAttempts.toDouble() / attempts.size * 100).toInt()
|
|
||||||
} else 0
|
|
||||||
|
|
||||||
SuccessRateCard(
|
|
||||||
successRate = successRate,
|
|
||||||
successfulAttempts = successfulAttempts,
|
|
||||||
totalAttempts = attempts.size
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Favorite Gym
|
// Favorite Gym
|
||||||
@@ -132,14 +126,24 @@ fun OverallStatsCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SuccessRateCard(
|
fun ProgressChartCard(
|
||||||
successRate: Int,
|
progressData: List<ProgressDataPoint>,
|
||||||
successfulAttempts: Int,
|
problems: List<com.atridad.openclimb.data.model.Problem>,
|
||||||
totalAttempts: Int
|
|
||||||
) {
|
) {
|
||||||
|
// Find all grading systems that have been used
|
||||||
|
val usedSystems = remember(problems) {
|
||||||
|
problems.map { it.difficulty.system }.distinct().filter { system ->
|
||||||
|
problems.any { it.difficulty.system == system }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var selectedSystem by remember {
|
||||||
|
mutableStateOf(usedSystems.firstOrNull() ?: DifficultySystem.V_SCALE)
|
||||||
|
}
|
||||||
|
var expanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
@@ -148,37 +152,119 @@ fun SuccessRateCard(
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
|
||||||
text = "Success Rate",
|
|
||||||
style = MaterialTheme.typography.titleMedium,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "$successRate%",
|
text = "Progress Over Time",
|
||||||
style = MaterialTheme.typography.displaySmall,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = MaterialTheme.colorScheme.primary
|
modifier = Modifier.weight(1f)
|
||||||
)
|
)
|
||||||
|
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
// Scale selector dropdown
|
||||||
Text(
|
if (usedSystems.size > 1) {
|
||||||
text = "$successfulAttempts successful",
|
ExposedDropdownMenuBox(
|
||||||
style = MaterialTheme.typography.bodyMedium
|
expanded = expanded,
|
||||||
|
onExpandedChange = { expanded = !expanded }
|
||||||
|
) {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = when (selectedSystem) {
|
||||||
|
DifficultySystem.V_SCALE -> "V-Scale"
|
||||||
|
DifficultySystem.FONT -> "Font"
|
||||||
|
DifficultySystem.YDS -> "YDS"
|
||||||
|
DifficultySystem.CUSTOM -> "Custom"
|
||||||
|
},
|
||||||
|
onValueChange = {},
|
||||||
|
readOnly = true,
|
||||||
|
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
||||||
|
modifier = Modifier
|
||||||
|
.menuAnchor(type = MenuAnchorType.PrimaryNotEditable, enabled = true)
|
||||||
|
.width(120.dp),
|
||||||
|
textStyle = MaterialTheme.typography.bodyMedium
|
||||||
)
|
)
|
||||||
|
ExposedDropdownMenu(
|
||||||
|
expanded = expanded,
|
||||||
|
onDismissRequest = { expanded = false }
|
||||||
|
) {
|
||||||
|
usedSystems.forEach { system ->
|
||||||
|
DropdownMenuItem(
|
||||||
|
text = {
|
||||||
|
Text(when (system) {
|
||||||
|
DifficultySystem.V_SCALE -> "V-Scale"
|
||||||
|
DifficultySystem.FONT -> "Font"
|
||||||
|
DifficultySystem.YDS -> "YDS"
|
||||||
|
DifficultySystem.CUSTOM -> "Custom"
|
||||||
|
})
|
||||||
|
},
|
||||||
|
onClick = {
|
||||||
|
selectedSystem = system
|
||||||
|
expanded = false
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
|
// Filter progress data by selected scale
|
||||||
|
val filteredProgressData = remember(progressData, selectedSystem) {
|
||||||
|
progressData.filter { it.difficultySystem == selectedSystem }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filteredProgressData.isNotEmpty()) {
|
||||||
|
val chartData = remember(filteredProgressData) {
|
||||||
|
// Convert progress data to chart data points ordered by session
|
||||||
|
filteredProgressData
|
||||||
|
.sortedBy { it.date }
|
||||||
|
.mapIndexed { index, p ->
|
||||||
|
ChartDataPoint(
|
||||||
|
x = (index + 1).toFloat(),
|
||||||
|
y = p.maxGradeNumeric.toFloat(),
|
||||||
|
label = "Session ${index + 1}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LineChart(
|
||||||
|
data = chartData,
|
||||||
|
modifier = Modifier.fillMaxWidth().height(220.dp),
|
||||||
|
xAxisFormatter = { value ->
|
||||||
|
"S${value.toInt()}" // S1, S2, S3, etc.
|
||||||
|
},
|
||||||
|
yAxisFormatter = { value ->
|
||||||
|
numericToGrade(selectedSystem, value.toInt())
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "out of $totalAttempts attempts",
|
text = "X: session number, Y: max ${when(selectedSystem) {
|
||||||
|
DifficultySystem.V_SCALE -> "V-grade"
|
||||||
|
DifficultySystem.FONT -> "Font grade"
|
||||||
|
DifficultySystem.YDS -> "YDS grade"
|
||||||
|
DifficultySystem.CUSTOM -> "custom grade"
|
||||||
|
}} achieved",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
} else {
|
||||||
|
Text(
|
||||||
|
text = "No progress data available for ${when(selectedSystem) {
|
||||||
|
DifficultySystem.V_SCALE -> "V-Scale"
|
||||||
|
DifficultySystem.FONT -> "Font"
|
||||||
|
DifficultySystem.YDS -> "YDS"
|
||||||
|
DifficultySystem.CUSTOM -> "Custom"
|
||||||
|
}} system",
|
||||||
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,3 +339,204 @@ fun RecentActivityCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class ProgressDataPoint(
|
||||||
|
val date: String,
|
||||||
|
val maxGrade: String,
|
||||||
|
val maxGradeNumeric: Int,
|
||||||
|
val climbType: ClimbType,
|
||||||
|
val difficultySystem: DifficultySystem
|
||||||
|
)
|
||||||
|
|
||||||
|
fun calculateProgressOverTime(
|
||||||
|
sessions: List<com.atridad.openclimb.data.model.ClimbSession>,
|
||||||
|
problems: List<com.atridad.openclimb.data.model.Problem>,
|
||||||
|
attempts: List<com.atridad.openclimb.data.model.Attempt>
|
||||||
|
): List<ProgressDataPoint> {
|
||||||
|
if (sessions.isEmpty() || problems.isEmpty() || attempts.isEmpty()) {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
val sessionProgress = sessions.mapNotNull { session ->
|
||||||
|
val sessionAttempts = attempts.filter { it.sessionId == session.id }
|
||||||
|
if (sessionAttempts.isEmpty()) return@mapNotNull null
|
||||||
|
val attemptedProblemIds = sessionAttempts.map { it.problemId }.distinct()
|
||||||
|
val attemptedProblems = problems.filter { it.id in attemptedProblemIds }
|
||||||
|
if (attemptedProblems.isEmpty()) return@mapNotNull null
|
||||||
|
val highestGradeProblem = attemptedProblems.maxByOrNull { problem ->
|
||||||
|
gradeToNumeric(problem.difficulty.system, problem.difficulty.grade)
|
||||||
|
}
|
||||||
|
if (highestGradeProblem != null) {
|
||||||
|
ProgressDataPoint(
|
||||||
|
date = session.date,
|
||||||
|
maxGrade = highestGradeProblem.difficulty.grade,
|
||||||
|
maxGradeNumeric = gradeToNumeric(highestGradeProblem.difficulty.system, highestGradeProblem.difficulty.grade),
|
||||||
|
climbType = highestGradeProblem.climbType,
|
||||||
|
difficultySystem = highestGradeProblem.difficulty.system
|
||||||
|
)
|
||||||
|
} else null
|
||||||
|
}
|
||||||
|
return sessionProgress.sortedBy { it.date }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun gradeToNumeric(system: DifficultySystem, grade: String): Int {
|
||||||
|
return when (system) {
|
||||||
|
DifficultySystem.V_SCALE -> {
|
||||||
|
when (grade) {
|
||||||
|
"VB" -> 0
|
||||||
|
else -> grade.removePrefix("V").toIntOrNull() ?: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.FONT -> {
|
||||||
|
when (grade) {
|
||||||
|
"3" -> 3
|
||||||
|
"4A" -> 4
|
||||||
|
"4B" -> 5
|
||||||
|
"4C" -> 6
|
||||||
|
"5A" -> 7
|
||||||
|
"5B" -> 8
|
||||||
|
"5C" -> 9
|
||||||
|
"6A" -> 10
|
||||||
|
"6A+" -> 11
|
||||||
|
"6B" -> 12
|
||||||
|
"6B+" -> 13
|
||||||
|
"6C" -> 14
|
||||||
|
"6C+" -> 15
|
||||||
|
"7A" -> 16
|
||||||
|
"7A+" -> 17
|
||||||
|
"7B" -> 18
|
||||||
|
"7B+" -> 19
|
||||||
|
"7C" -> 20
|
||||||
|
"7C+" -> 21
|
||||||
|
"8A" -> 22
|
||||||
|
"8A+" -> 23
|
||||||
|
"8B" -> 24
|
||||||
|
"8B+" -> 25
|
||||||
|
"8C" -> 26
|
||||||
|
"8C+" -> 27
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.YDS -> {
|
||||||
|
when (grade) {
|
||||||
|
"5.0" -> 50
|
||||||
|
"5.1" -> 51
|
||||||
|
"5.2" -> 52
|
||||||
|
"5.3" -> 53
|
||||||
|
"5.4" -> 54
|
||||||
|
"5.5" -> 55
|
||||||
|
"5.6" -> 56
|
||||||
|
"5.7" -> 57
|
||||||
|
"5.8" -> 58
|
||||||
|
"5.9" -> 59
|
||||||
|
"5.10a" -> 60
|
||||||
|
"5.10b" -> 61
|
||||||
|
"5.10c" -> 62
|
||||||
|
"5.10d" -> 63
|
||||||
|
"5.11a" -> 64
|
||||||
|
"5.11b" -> 65
|
||||||
|
"5.11c" -> 66
|
||||||
|
"5.11d" -> 67
|
||||||
|
"5.12a" -> 68
|
||||||
|
"5.12b" -> 69
|
||||||
|
"5.12c" -> 70
|
||||||
|
"5.12d" -> 71
|
||||||
|
"5.13a" -> 72
|
||||||
|
"5.13b" -> 73
|
||||||
|
"5.13c" -> 74
|
||||||
|
"5.13d" -> 75
|
||||||
|
"5.14a" -> 76
|
||||||
|
"5.14b" -> 77
|
||||||
|
"5.14c" -> 78
|
||||||
|
"5.14d" -> 79
|
||||||
|
"5.15a" -> 80
|
||||||
|
"5.15b" -> 81
|
||||||
|
"5.15c" -> 82
|
||||||
|
"5.15d" -> 83
|
||||||
|
else -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.CUSTOM -> 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun numericToGrade(system: DifficultySystem, numeric: Int): String {
|
||||||
|
return when (system) {
|
||||||
|
DifficultySystem.V_SCALE -> {
|
||||||
|
when (numeric) {
|
||||||
|
0 -> "VB"
|
||||||
|
else -> "V$numeric"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.FONT -> {
|
||||||
|
when (numeric) {
|
||||||
|
3 -> "3"
|
||||||
|
4 -> "4A"
|
||||||
|
5 -> "4B"
|
||||||
|
6 -> "4C"
|
||||||
|
7 -> "5A"
|
||||||
|
8 -> "5B"
|
||||||
|
9 -> "5C"
|
||||||
|
10 -> "6A"
|
||||||
|
11 -> "6A+"
|
||||||
|
12 -> "6B"
|
||||||
|
13 -> "6B+"
|
||||||
|
14 -> "6C"
|
||||||
|
15 -> "6C+"
|
||||||
|
16 -> "7A"
|
||||||
|
17 -> "7A+"
|
||||||
|
18 -> "7B"
|
||||||
|
19 -> "7B+"
|
||||||
|
20 -> "7C"
|
||||||
|
21 -> "7C+"
|
||||||
|
22 -> "8A"
|
||||||
|
23 -> "8A+"
|
||||||
|
24 -> "8B"
|
||||||
|
25 -> "8B+"
|
||||||
|
26 -> "8C"
|
||||||
|
27 -> "8C+"
|
||||||
|
else -> numeric.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.YDS -> {
|
||||||
|
when (numeric) {
|
||||||
|
50 -> "5.0"
|
||||||
|
51 -> "5.1"
|
||||||
|
52 -> "5.2"
|
||||||
|
53 -> "5.3"
|
||||||
|
54 -> "5.4"
|
||||||
|
55 -> "5.5"
|
||||||
|
56 -> "5.6"
|
||||||
|
57 -> "5.7"
|
||||||
|
58 -> "5.8"
|
||||||
|
59 -> "5.9"
|
||||||
|
60 -> "5.10a"
|
||||||
|
61 -> "5.10b"
|
||||||
|
62 -> "5.10c"
|
||||||
|
63 -> "5.10d"
|
||||||
|
64 -> "5.11a"
|
||||||
|
65 -> "5.11b"
|
||||||
|
66 -> "5.11c"
|
||||||
|
67 -> "5.11d"
|
||||||
|
68 -> "5.12a"
|
||||||
|
69 -> "5.12b"
|
||||||
|
70 -> "5.12c"
|
||||||
|
71 -> "5.12d"
|
||||||
|
72 -> "5.13a"
|
||||||
|
73 -> "5.13b"
|
||||||
|
74 -> "5.13c"
|
||||||
|
75 -> "5.13d"
|
||||||
|
76 -> "5.14a"
|
||||||
|
77 -> "5.14b"
|
||||||
|
78 -> "5.14c"
|
||||||
|
79 -> "5.14d"
|
||||||
|
80 -> "5.15a"
|
||||||
|
81 -> "5.15b"
|
||||||
|
82 -> "5.15c"
|
||||||
|
83 -> "5.15d"
|
||||||
|
else -> numeric.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DifficultySystem.CUSTOM -> numeric.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -426,11 +426,6 @@ fun SessionDetailScreen(
|
|||||||
label = "Completed",
|
label = "Completed",
|
||||||
value = completedProblems.size.toString()
|
value = completedProblems.size.toString()
|
||||||
)
|
)
|
||||||
StatItem(
|
|
||||||
label = "Success Rate",
|
|
||||||
value = "${((successfulAttempts.size.toDouble() / attempts.size) * 100).toInt()}%"
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show grade range(s) with better layout
|
// Show grade range(s) with better layout
|
||||||
@@ -622,10 +617,6 @@ fun ProblemDetailScreen(
|
|||||||
// Calculate stats
|
// Calculate stats
|
||||||
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 successRate =
|
|
||||||
if (attempts.isNotEmpty()) {
|
|
||||||
(successfulAttempts.size.toDouble() / attempts.size * 100).toInt()
|
|
||||||
} else 0
|
|
||||||
|
|
||||||
val attemptsWithSessions =
|
val attemptsWithSessions =
|
||||||
attempts
|
attempts
|
||||||
@@ -793,7 +784,6 @@ fun ProblemDetailScreen(
|
|||||||
label = "Successful",
|
label = "Successful",
|
||||||
value = successfulAttempts.size.toString()
|
value = successfulAttempts.size.toString()
|
||||||
)
|
)
|
||||||
StatItem(label = "Success Rate", value = "$successRate%")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
@@ -929,10 +919,7 @@ fun GymDetailScreen(
|
|||||||
val successfulAttempts =
|
val successfulAttempts =
|
||||||
gymAttempts.filter { it.result in listOf(AttemptResult.SUCCESS, AttemptResult.FLASH) }
|
gymAttempts.filter { it.result in listOf(AttemptResult.SUCCESS, AttemptResult.FLASH) }
|
||||||
|
|
||||||
val successRate =
|
|
||||||
if (gymAttempts.isNotEmpty()) {
|
|
||||||
(successfulAttempts.size.toDouble() / gymAttempts.size * 100).toInt()
|
|
||||||
} else 0
|
|
||||||
|
|
||||||
val uniqueProblemsClimbed = gymAttempts.map { it.problemId }.toSet().size
|
val uniqueProblemsClimbed = gymAttempts.map { it.problemId }.toSet().size
|
||||||
val totalSessions = sessions.size
|
val totalSessions = sessions.size
|
||||||
@@ -1042,19 +1029,7 @@ fun GymDetailScreen(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
||||||
Text(
|
|
||||||
text = "$successRate%",
|
|
||||||
style = MaterialTheme.typography.headlineSmall,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = MaterialTheme.colorScheme.primary
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "Success Rate",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
@@ -2001,7 +1976,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
ExposedDropdownMenuDefaults
|
ExposedDropdownMenuDefaults
|
||||||
.outlinedTextFieldColors(),
|
.outlinedTextFieldColors(),
|
||||||
modifier = Modifier.menuAnchor().fillMaxWidth(),
|
modifier = Modifier.menuAnchor(androidx.compose.material3.MenuAnchorType.PrimaryNotEditable, enabled = true).fillMaxWidth(),
|
||||||
isError = newProblemGrade.isBlank(),
|
isError = newProblemGrade.isBlank(),
|
||||||
supportingText =
|
supportingText =
|
||||||
if (newProblemGrade.isBlank()) {
|
if (newProblemGrade.isBlank()) {
|
||||||
|
|||||||
@@ -285,11 +285,7 @@ object SessionShareUtils {
|
|||||||
drawStatItemFitting(canvas, width / 2f, rangesY, "Grade Range", singleRange, statLabelPaint, statValuePaint, width - 200f)
|
drawStatItemFitting(canvas, width / 2f, rangesY, "Grade Range", singleRange, statLabelPaint, statValuePaint, width - 200f)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Success rate arc
|
|
||||||
val successRate = if (stats.totalAttempts > 0) {
|
|
||||||
(stats.successfulAttempts.toFloat() / stats.totalAttempts) * 100f
|
|
||||||
} else 0f
|
|
||||||
drawSuccessRateArc(canvas, width / 2f, height - 300f, successRate, statLabelPaint, statValuePaint)
|
|
||||||
|
|
||||||
// App branding
|
// App branding
|
||||||
val brandingPaint = Paint().apply {
|
val brandingPaint = Paint().apply {
|
||||||
@@ -372,52 +368,7 @@ object SessionShareUtils {
|
|||||||
return "${sorted.first().grade} - ${sorted.last().grade}"
|
return "${sorted.first().grade} - ${sorted.last().grade}"
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun drawSuccessRateArc(
|
|
||||||
canvas: Canvas,
|
|
||||||
centerX: Float,
|
|
||||||
centerY: Float,
|
|
||||||
successRate: Float,
|
|
||||||
labelPaint: Paint,
|
|
||||||
valuePaint: Paint
|
|
||||||
) {
|
|
||||||
val radius = 70f
|
|
||||||
val strokeWidth = 14f
|
|
||||||
|
|
||||||
// Background arc
|
|
||||||
val bgPaint = Paint().apply {
|
|
||||||
color = "#30FFFFFF".toColorInt()
|
|
||||||
style = Paint.Style.STROKE
|
|
||||||
this.strokeWidth = strokeWidth
|
|
||||||
isAntiAlias = true
|
|
||||||
strokeCap = Paint.Cap.ROUND
|
|
||||||
}
|
|
||||||
|
|
||||||
// Success arc
|
|
||||||
val successPaint = Paint().apply {
|
|
||||||
color = "#4CAF50".toColorInt()
|
|
||||||
style = Paint.Style.STROKE
|
|
||||||
this.strokeWidth = strokeWidth
|
|
||||||
isAntiAlias = true
|
|
||||||
strokeCap = Paint.Cap.ROUND
|
|
||||||
}
|
|
||||||
|
|
||||||
val rect = RectF(centerX - radius, centerY - radius, centerX + radius, centerY + radius)
|
|
||||||
|
|
||||||
// Draw background arc (full circle)
|
|
||||||
canvas.drawArc(rect, -90f, 360f, false, bgPaint)
|
|
||||||
|
|
||||||
// Draw success arc
|
|
||||||
val sweepAngle = (successRate / 100f) * 360f
|
|
||||||
canvas.drawArc(rect, -90f, sweepAngle, false, successPaint)
|
|
||||||
|
|
||||||
// Draw percentage text
|
|
||||||
val percentText = "${successRate.roundToInt()}%"
|
|
||||||
canvas.drawText(percentText, centerX, centerY + 8f, valuePaint)
|
|
||||||
|
|
||||||
// Draw label below the arc (outside the ring) for better readability
|
|
||||||
val belowLabelPaint = Paint(labelPaint)
|
|
||||||
canvas.drawText("Success Rate", centerX, centerY + radius + 36f, belowLabelPaint)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun formatSessionDate(dateString: String): String {
|
private fun formatSessionDate(dateString: String): String {
|
||||||
return try {
|
return try {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">OpenClimb</string>
|
<string name="app_name">OpenClimb</string>
|
||||||
|
<string name="session_tracking_service_description">Tracks active climbing sessions and displays session information in the notification area</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
[versions]
|
[versions]
|
||||||
agp = "8.12.1"
|
agp = "8.12.1"
|
||||||
kotlin = "2.0.21"
|
kotlin = "2.2.10"
|
||||||
coreKtx = "1.15.0"
|
coreKtx = "1.17.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
junitVersion = "1.3.0"
|
junitVersion = "1.3.0"
|
||||||
espressoCore = "3.7.0"
|
espressoCore = "3.7.0"
|
||||||
androidxTestCore = "1.6.0"
|
androidxTestCore = "1.7.0"
|
||||||
androidxTestExt = "1.2.0"
|
androidxTestExt = "1.3.0"
|
||||||
androidxTestRunner = "1.6.0"
|
androidxTestRunner = "1.7.0"
|
||||||
androidxTestRules = "1.6.0"
|
androidxTestRules = "1.7.0"
|
||||||
lifecycleRuntimeKtx = "2.9.2"
|
lifecycleRuntimeKtx = "2.9.3"
|
||||||
activityCompose = "1.10.1"
|
activityCompose = "1.10.1"
|
||||||
composeBom = "2024.09.00"
|
composeBom = "2025.08.01"
|
||||||
room = "2.6.1"
|
room = "2.7.2"
|
||||||
navigation = "2.8.4"
|
navigation = "2.9.3"
|
||||||
viewmodel = "2.9.2"
|
viewmodel = "2.9.3"
|
||||||
kotlinxSerialization = "1.7.1"
|
kotlinxSerialization = "1.9.0"
|
||||||
kotlinxCoroutines = "1.9.0"
|
kotlinxCoroutines = "1.10.2"
|
||||||
coil = "2.7.0"
|
coil = "2.7.0"
|
||||||
ksp = "2.0.21-1.0.25"
|
ksp = "2.2.10-2.0.2"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||||
@@ -64,8 +64,7 @@ mockk = { group = "io.mockk", name = "mockk", version = "1.13.8" }
|
|||||||
# Image Loading
|
# Image Loading
|
||||||
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
coil-compose = { group = "io.coil-kt", name = "coil-compose", version.ref = "coil" }
|
||||||
|
|
||||||
# Charts - MPAndroidChart for now, will be replaced with Vico when stable
|
|
||||||
mpandroidchart = { group = "com.github.PhilJay", name = "MPAndroidChart", version = "v3.1.0" }
|
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||||
|
|||||||
Reference in New Issue
Block a user