1.03 for iOS and 1.5.0 for Android
This commit is contained in:
@@ -16,8 +16,8 @@ android {
|
|||||||
applicationId = "com.atridad.openclimb"
|
applicationId = "com.atridad.openclimb"
|
||||||
minSdk = 31
|
minSdk = 31
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 24
|
versionCode = 25
|
||||||
versionName = "1.5.0"
|
versionName = "1.5.1"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,13 @@ package com.atridad.openclimb.ui.screens
|
|||||||
import androidx.compose.foundation.BorderStroke
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyRow
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.selection.selectable
|
import androidx.compose.foundation.selection.selectable
|
||||||
import androidx.compose.foundation.selection.selectableGroup
|
import androidx.compose.foundation.selection.selectableGroup
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
@@ -56,9 +56,7 @@ fun EditAttemptDialog(
|
|||||||
Dialog(onDismissRequest = onDismiss) {
|
Dialog(onDismissRequest = onDismiss) {
|
||||||
Card(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
Card(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize().padding(24.dp),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(24.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(20.dp)
|
verticalArrangement = Arrangement.spacedBy(20.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
@@ -130,8 +128,8 @@ fun EditAttemptDialog(
|
|||||||
) {
|
) {
|
||||||
AttemptResult.entries.forEach { result ->
|
AttemptResult.entries.forEach { result ->
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier =
|
||||||
.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.selectable(
|
.selectable(
|
||||||
selected = selectedResult == result,
|
selected = selectedResult == result,
|
||||||
onClick = { selectedResult = result },
|
onClick = { selectedResult = result },
|
||||||
@@ -140,15 +138,16 @@ fun EditAttemptDialog(
|
|||||||
.padding(8.dp),
|
.padding(8.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
RadioButton(
|
RadioButton(selected = selectedResult == result, onClick = null)
|
||||||
selected = selectedResult == result,
|
|
||||||
onClick = null
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = when (result) {
|
text =
|
||||||
|
when (result) {
|
||||||
AttemptResult.NO_PROGRESS -> "No Progress"
|
AttemptResult.NO_PROGRESS -> "No Progress"
|
||||||
else -> result.name.lowercase().replaceFirstChar { it.uppercase() }
|
else ->
|
||||||
|
result.name.lowercase().replaceFirstChar {
|
||||||
|
it.uppercase()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodyMedium
|
style = MaterialTheme.typography.bodyMedium
|
||||||
)
|
)
|
||||||
@@ -200,9 +199,7 @@ fun EditAttemptDialog(
|
|||||||
},
|
},
|
||||||
enabled = selectedProblem != null,
|
enabled = selectedProblem != null,
|
||||||
modifier = Modifier.weight(1f)
|
modifier = Modifier.weight(1f)
|
||||||
) {
|
) { Text("Update") }
|
||||||
Text("Update")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,7 +253,10 @@ fun SessionDetailScreen(
|
|||||||
title = { Text("Session Details") },
|
title = { Text("Session Details") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
@@ -267,7 +267,10 @@ fun SessionDetailScreen(
|
|||||||
isGeneratingShare = true
|
isGeneratingShare = true
|
||||||
viewModel.viewModelScope.launch {
|
viewModel.viewModelScope.launch {
|
||||||
val shareFile =
|
val shareFile =
|
||||||
viewModel.generateSessionShareCard(context, sessionId)
|
viewModel.generateSessionShareCard(
|
||||||
|
context,
|
||||||
|
sessionId
|
||||||
|
)
|
||||||
isGeneratingShare = false
|
isGeneratingShare = false
|
||||||
shareFile?.let { file ->
|
shareFile?.let { file ->
|
||||||
viewModel.shareSessionCard(context, file)
|
viewModel.shareSessionCard(context, file)
|
||||||
@@ -290,16 +293,22 @@ fun SessionDetailScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show stop icon for active sessions, delete icon for completed sessions
|
// Show stop icon for active sessions, delete icon for completed
|
||||||
|
// sessions
|
||||||
if (session?.status == SessionStatus.ACTIVE) {
|
if (session?.status == SessionStatus.ACTIVE) {
|
||||||
IconButton(onClick = {
|
IconButton(
|
||||||
|
onClick = {
|
||||||
session.let { s ->
|
session.let { s ->
|
||||||
viewModel.endSession(context, s.id)
|
viewModel.endSession(context, s.id)
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
}
|
}
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = CustomIcons.Stop(MaterialTheme.colorScheme.onSurface),
|
imageVector =
|
||||||
|
CustomIcons.Stop(
|
||||||
|
MaterialTheme.colorScheme.onSurface
|
||||||
|
),
|
||||||
contentDescription = "Stop Session"
|
contentDescription = "Stop Session"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -372,8 +381,10 @@ fun SessionDetailScreen(
|
|||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
if (session?.duration != null) "Completed" else "In Progress",
|
if (session?.duration != null) "Completed"
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 6.dp),
|
else "In Progress",
|
||||||
|
modifier =
|
||||||
|
Modifier.padding(horizontal = 12.dp, vertical = 6.dp),
|
||||||
style = MaterialTheme.typography.labelMedium,
|
style = MaterialTheme.typography.labelMedium,
|
||||||
color =
|
color =
|
||||||
if (session?.duration != null)
|
if (session?.duration != null)
|
||||||
@@ -428,55 +439,6 @@ fun SessionDetailScreen(
|
|||||||
value = completedProblems.size.toString()
|
value = completedProblems.size.toString()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show grade range(s) with better layout
|
|
||||||
val grades = attemptedProblems.map { it.difficulty }
|
|
||||||
if (grades.isNotEmpty()) {
|
|
||||||
val boulderProblems = attemptedProblems.filter { it.climbType == ClimbType.BOULDER }
|
|
||||||
val ropeProblems = attemptedProblems.filter { it.climbType == ClimbType.ROPE }
|
|
||||||
|
|
||||||
val boulderRange = if (boulderProblems.isNotEmpty()) {
|
|
||||||
val boulderGrades = boulderProblems.map { it.difficulty }
|
|
||||||
val sorted = boulderGrades.sortedWith { a, b -> a.compareTo(b) }
|
|
||||||
"${sorted.first().grade} - ${sorted.last().grade}"
|
|
||||||
} else null
|
|
||||||
|
|
||||||
val ropeRange = if (ropeProblems.isNotEmpty()) {
|
|
||||||
val ropeGrades = ropeProblems.map { it.difficulty }
|
|
||||||
val sorted = ropeGrades.sortedWith { a, b -> a.compareTo(b) }
|
|
||||||
"${sorted.first().grade} - ${sorted.last().grade}"
|
|
||||||
} else null
|
|
||||||
|
|
||||||
if (boulderRange != null && ropeRange != null) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
|
||||||
) {
|
|
||||||
StatItem(label = "Boulder Range", value = boulderRange)
|
|
||||||
StatItem(label = "Rope Range", value = ropeRange)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
StatItem(
|
|
||||||
label = "Grade Range",
|
|
||||||
value = boulderRange ?: ropeRange ?: "N/A"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
StatItem(
|
|
||||||
label = "Grade Range",
|
|
||||||
value = "N/A"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,7 +480,9 @@ fun SessionDetailScreen(
|
|||||||
SessionAttemptCard(
|
SessionAttemptCard(
|
||||||
attempt = attempt,
|
attempt = attempt,
|
||||||
problem = problem,
|
problem = problem,
|
||||||
onEditAttempt = { attemptToEdit -> showEditAttemptDialog = attemptToEdit },
|
onEditAttempt = { attemptToEdit ->
|
||||||
|
showEditAttemptDialog = attemptToEdit
|
||||||
|
},
|
||||||
onDeleteAttempt = { attemptToDelete ->
|
onDeleteAttempt = { attemptToDelete ->
|
||||||
viewModel.deleteAttempt(attemptToDelete)
|
viewModel.deleteAttempt(attemptToDelete)
|
||||||
},
|
},
|
||||||
@@ -539,7 +503,8 @@ fun SessionDetailScreen(
|
|||||||
Text("Are you sure you want to delete this session?")
|
Text("Are you sure you want to delete this session?")
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "This will also delete all attempts associated with this session.",
|
text =
|
||||||
|
"This will also delete all attempts associated with this session.",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
@@ -554,9 +519,7 @@ fun SessionDetailScreen(
|
|||||||
}
|
}
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
}
|
}
|
||||||
) {
|
) { Text("Delete", color = MaterialTheme.colorScheme.error) }
|
||||||
Text("Delete", color = MaterialTheme.colorScheme.error)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
||||||
@@ -633,7 +596,10 @@ fun ProblemDetailScreen(
|
|||||||
title = { Text("Problem Details") },
|
title = { Text("Problem Details") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
@@ -832,7 +798,8 @@ fun ProblemDetailScreen(
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Start a session and track your attempts on this problem!",
|
text =
|
||||||
|
"Start a session and track your attempts on this problem!",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -858,7 +825,8 @@ fun ProblemDetailScreen(
|
|||||||
Text("Are you sure you want to delete this problem?")
|
Text("Are you sure you want to delete this problem?")
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "This will also delete all attempts associated with this problem.",
|
text =
|
||||||
|
"This will also delete all attempts associated with this problem.",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
@@ -873,9 +841,7 @@ fun ProblemDetailScreen(
|
|||||||
}
|
}
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
}
|
}
|
||||||
) {
|
) { Text("Delete", color = MaterialTheme.colorScheme.error) }
|
||||||
Text("Delete", color = MaterialTheme.colorScheme.error)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
||||||
@@ -929,7 +895,10 @@ fun GymDetailScreen(
|
|||||||
title = { Text(gym?.name ?: "Gym Details") },
|
title = { Text(gym?.name ?: "Gym Details") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
@@ -947,9 +916,7 @@ fun GymDetailScreen(
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize().padding(paddingValues),
|
modifier = Modifier.fillMaxSize().padding(paddingValues),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) { Text("Gym not found") }
|
||||||
Text("Gym not found")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier.fillMaxSize().padding(paddingValues).padding(16.dp),
|
modifier = Modifier.fillMaxSize().padding(paddingValues).padding(16.dp),
|
||||||
@@ -1025,7 +992,6 @@ fun GymDetailScreen(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
@@ -1097,10 +1063,8 @@ fun GymDetailScreen(
|
|||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
// Show recent problems (limit to 5)
|
// Show recent problems (limit to 5)
|
||||||
problems
|
problems.sortedByDescending { it.createdAt }.take(5).forEach {
|
||||||
.sortedByDescending { it.createdAt }
|
problem ->
|
||||||
.take(5)
|
|
||||||
.forEach { problem ->
|
|
||||||
val problemAttempts =
|
val problemAttempts =
|
||||||
gymAttempts.filter { it.problemId == problem.id }
|
gymAttempts.filter { it.problemId == problem.id }
|
||||||
val problemSuccessful =
|
val problemSuccessful =
|
||||||
@@ -1114,21 +1078,30 @@ fun GymDetailScreen(
|
|||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = 4.dp)
|
.padding(vertical = 4.dp)
|
||||||
.clickable { onNavigateToProblemDetail(problem.id) },
|
.clickable {
|
||||||
|
onNavigateToProblemDetail(
|
||||||
|
problem.id
|
||||||
|
)
|
||||||
|
},
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme
|
||||||
|
.surface
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
elevation =
|
||||||
|
CardDefaults.cardElevation(
|
||||||
|
defaultElevation = 4.dp
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
Text(
|
Text(
|
||||||
text = problem.name ?: "Unnamed Problem",
|
text = problem.name
|
||||||
|
?: "Unnamed Problem",
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -1142,7 +1115,9 @@ fun GymDetailScreen(
|
|||||||
Icon(
|
Icon(
|
||||||
Icons.Default.Check,
|
Icons.Default.Check,
|
||||||
contentDescription = "Completed",
|
contentDescription = "Completed",
|
||||||
tint = MaterialTheme.colorScheme.primary
|
tint =
|
||||||
|
MaterialTheme.colorScheme
|
||||||
|
.primary
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1180,25 +1155,30 @@ fun GymDetailScreen(
|
|||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
|
||||||
// Show recent sessions (limit to 3)
|
// Show recent sessions (limit to 3)
|
||||||
sessions
|
sessions.sortedByDescending { it.date }.take(3).forEach { session ->
|
||||||
.sortedByDescending { it.date }
|
|
||||||
.take(3)
|
|
||||||
.forEach { session ->
|
|
||||||
val sessionAttempts =
|
val sessionAttempts =
|
||||||
gymAttempts.filter { it.sessionId == session.id }
|
gymAttempts.filter { it.sessionId == session.id }
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier =
|
modifier =
|
||||||
Modifier
|
Modifier.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = 4.dp)
|
.padding(vertical = 4.dp)
|
||||||
.clickable { onNavigateToSessionDetail(session.id) },
|
.clickable {
|
||||||
|
onNavigateToSessionDetail(
|
||||||
|
session.id
|
||||||
|
)
|
||||||
|
},
|
||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme
|
||||||
|
.surface
|
||||||
),
|
),
|
||||||
shape = RoundedCornerShape(12.dp),
|
shape = RoundedCornerShape(12.dp),
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp)
|
elevation =
|
||||||
|
CardDefaults.cardElevation(
|
||||||
|
defaultElevation = 4.dp
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
ListItem(
|
ListItem(
|
||||||
headlineContent = {
|
headlineContent = {
|
||||||
@@ -1210,26 +1190,27 @@ fun GymDetailScreen(
|
|||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
if (
|
if (session.status ==
|
||||||
session.status ==
|
SessionStatus
|
||||||
SessionStatus.ACTIVE
|
.ACTIVE
|
||||||
)
|
)
|
||||||
"Active Session"
|
"Active Session"
|
||||||
else "Session",
|
else "Session",
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
if (
|
if (session.status == SessionStatus.ACTIVE
|
||||||
session.status == SessionStatus.ACTIVE
|
|
||||||
) {
|
) {
|
||||||
Badge(
|
Badge(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.primary
|
.primary
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
"ACTIVE",
|
"ACTIVE",
|
||||||
style =
|
style =
|
||||||
MaterialTheme.typography
|
MaterialTheme
|
||||||
|
.typography
|
||||||
.labelSmall
|
.labelSmall
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1248,7 +1229,8 @@ fun GymDetailScreen(
|
|||||||
DateTimeFormatter.ofPattern(
|
DateTimeFormatter.ofPattern(
|
||||||
"MMM dd, yyyy"
|
"MMM dd, yyyy"
|
||||||
)
|
)
|
||||||
) ?: session.date
|
)
|
||||||
|
?: session.date
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
"$formattedDate • ${sessionAttempts.size} attempts"
|
"$formattedDate • ${sessionAttempts.size} attempts"
|
||||||
@@ -1259,7 +1241,8 @@ fun GymDetailScreen(
|
|||||||
Text(
|
Text(
|
||||||
text = "${duration}min",
|
text = "${duration}min",
|
||||||
style =
|
style =
|
||||||
MaterialTheme.typography.bodySmall,
|
MaterialTheme.typography
|
||||||
|
.bodySmall,
|
||||||
color =
|
color =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme.colorScheme
|
||||||
.onSurfaceVariant
|
.onSurfaceVariant
|
||||||
@@ -1339,9 +1322,7 @@ fun GymDetailScreen(
|
|||||||
}
|
}
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
}
|
}
|
||||||
) {
|
) { Text("Delete", color = MaterialTheme.colorScheme.error) }
|
||||||
Text("Delete", color = MaterialTheme.colorScheme.error)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
||||||
@@ -1406,23 +1387,24 @@ fun AttemptHistoryCard(attempt: Attempt, session: ClimbSession, gym: Gym?) {
|
|||||||
fun AttemptResultBadge(result: AttemptResult) {
|
fun AttemptResultBadge(result: AttemptResult) {
|
||||||
val backgroundColor =
|
val backgroundColor =
|
||||||
when (result) {
|
when (result) {
|
||||||
AttemptResult.SUCCESS,
|
AttemptResult.SUCCESS, AttemptResult.FLASH ->
|
||||||
AttemptResult.FLASH -> MaterialTheme.colorScheme.primaryContainer
|
MaterialTheme.colorScheme.primaryContainer
|
||||||
AttemptResult.FALL -> MaterialTheme.colorScheme.secondaryContainer
|
AttemptResult.FALL -> MaterialTheme.colorScheme.secondaryContainer
|
||||||
else -> MaterialTheme.colorScheme.surfaceVariant
|
else -> MaterialTheme.colorScheme.surfaceVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
val textColor =
|
val textColor =
|
||||||
when (result) {
|
when (result) {
|
||||||
AttemptResult.SUCCESS,
|
AttemptResult.SUCCESS, AttemptResult.FLASH ->
|
||||||
AttemptResult.FLASH -> MaterialTheme.colorScheme.onPrimaryContainer
|
MaterialTheme.colorScheme.onPrimaryContainer
|
||||||
AttemptResult.FALL -> MaterialTheme.colorScheme.onSecondaryContainer
|
AttemptResult.FALL -> MaterialTheme.colorScheme.onSecondaryContainer
|
||||||
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
}
|
}
|
||||||
|
|
||||||
Surface(color = backgroundColor, shape = RoundedCornerShape(12.dp)) {
|
Surface(color = backgroundColor, shape = RoundedCornerShape(12.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = when (result) {
|
text =
|
||||||
|
when (result) {
|
||||||
AttemptResult.NO_PROGRESS -> "No Progress"
|
AttemptResult.NO_PROGRESS -> "No Progress"
|
||||||
else -> result.name.lowercase().replaceFirstChar { it.uppercase() }
|
else -> result.name.lowercase().replaceFirstChar { it.uppercase() }
|
||||||
},
|
},
|
||||||
@@ -1445,9 +1427,7 @@ fun SessionAttemptCard(
|
|||||||
var showDeleteDialog by remember { mutableStateOf(false) }
|
var showDeleteDialog by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth().clickable { onAttemptClick() },
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable { onAttemptClick() },
|
|
||||||
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(16.dp)) {
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
@@ -1530,9 +1510,7 @@ fun SessionAttemptCard(
|
|||||||
onDeleteAttempt(attempt)
|
onDeleteAttempt(attempt)
|
||||||
showDeleteDialog = false
|
showDeleteDialog = false
|
||||||
}
|
}
|
||||||
) {
|
) { Text("Delete", color = MaterialTheme.colorScheme.error) }
|
||||||
Text("Delete", color = MaterialTheme.colorScheme.error)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
dismissButton = {
|
dismissButton = {
|
||||||
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
TextButton(onClick = { showDeleteDialog = false }) { Text("Cancel") }
|
||||||
@@ -1578,8 +1556,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
|
|
||||||
// Auto-select climb type if there's only one available
|
// Auto-select climb type if there's only one available
|
||||||
LaunchedEffect(gym.supportedClimbTypes) {
|
LaunchedEffect(gym.supportedClimbTypes) {
|
||||||
if (
|
if (gym.supportedClimbTypes.size == 1 &&
|
||||||
gym.supportedClimbTypes.size == 1 &&
|
|
||||||
selectedClimbType != gym.supportedClimbTypes.first()
|
selectedClimbType != gym.supportedClimbTypes.first()
|
||||||
) {
|
) {
|
||||||
selectedClimbType = gym.supportedClimbTypes.first()
|
selectedClimbType = gym.supportedClimbTypes.first()
|
||||||
@@ -1598,8 +1575,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
selectedDifficultySystem !in availableSystems -> {
|
selectedDifficultySystem !in availableSystems -> {
|
||||||
selectedDifficultySystem =
|
selectedDifficultySystem =
|
||||||
availableSystems.firstOrNull()
|
availableSystems.firstOrNull()
|
||||||
?: gym.difficultySystems.firstOrNull()
|
?: gym.difficultySystems.firstOrNull() ?: DifficultySystem.CUSTOM
|
||||||
?: DifficultySystem.CUSTOM
|
|
||||||
}
|
}
|
||||||
// If there's only one available system, auto-select it
|
// If there's only one available system, auto-select it
|
||||||
availableSystems.size == 1 && selectedDifficultySystem != availableSystems.first() -> {
|
availableSystems.size == 1 && selectedDifficultySystem != availableSystems.first() -> {
|
||||||
@@ -1617,16 +1593,9 @@ fun EnhancedAddAttemptDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dialog(onDismissRequest = onDismiss) {
|
Dialog(onDismissRequest = onDismiss) {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth(0.95f).fillMaxHeight(0.9f).padding(16.dp)) {
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(0.95f)
|
|
||||||
.fillMaxHeight(0.9f)
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize().padding(24.dp),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(24.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(20.dp)
|
verticalArrangement = Arrangement.spacedBy(20.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
@@ -1655,7 +1624,8 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(
|
MaterialTheme.colorScheme
|
||||||
|
.surfaceVariant.copy(
|
||||||
alpha = 0.5f
|
alpha = 0.5f
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
@@ -1668,7 +1638,9 @@ fun EnhancedAddAttemptDialog(
|
|||||||
Text(
|
Text(
|
||||||
text = "No active problems in this gym",
|
text = "No active problems in this gym",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color =
|
||||||
|
MaterialTheme.colorScheme
|
||||||
|
.onSurfaceVariant
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -1691,46 +1663,65 @@ fun EnhancedAddAttemptDialog(
|
|||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.primaryContainer
|
.primaryContainer
|
||||||
else
|
else
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.surfaceVariant,
|
.surfaceVariant,
|
||||||
),
|
),
|
||||||
border =
|
border =
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
BorderStroke(
|
BorderStroke(
|
||||||
2.dp,
|
2.dp,
|
||||||
MaterialTheme.colorScheme.primary
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.primary
|
||||||
)
|
)
|
||||||
else null,
|
else null,
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(16.dp)) {
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
Text(
|
Text(
|
||||||
text = problem.name ?: "Unnamed Problem",
|
text = problem.name
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
?: "Unnamed Problem",
|
||||||
|
style =
|
||||||
|
MaterialTheme.typography
|
||||||
|
.bodyLarge,
|
||||||
fontWeight = FontWeight.SemiBold,
|
fontWeight = FontWeight.SemiBold,
|
||||||
color =
|
color =
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
MaterialTheme.colorScheme.onSurface
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.onSurface
|
||||||
else
|
else
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.onSurfaceVariant
|
.onSurfaceVariant
|
||||||
)
|
)
|
||||||
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.getDisplayName()}: ${problem.difficulty.grade}",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style =
|
||||||
|
MaterialTheme.typography
|
||||||
|
.bodyMedium,
|
||||||
color =
|
color =
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
MaterialTheme.colorScheme.onSurface
|
MaterialTheme
|
||||||
.copy(alpha = 0.8f)
|
.colorScheme
|
||||||
|
.onSurface.copy(
|
||||||
|
alpha = 0.8f
|
||||||
|
)
|
||||||
else
|
else
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.onSurfaceVariant
|
.onSurfaceVariant
|
||||||
.copy(alpha = 0.7f),
|
.copy(
|
||||||
|
alpha =
|
||||||
|
0.7f
|
||||||
|
),
|
||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1742,9 +1733,7 @@ fun EnhancedAddAttemptDialog(
|
|||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
onClick = { showCreateProblem = true },
|
onClick = { showCreateProblem = true },
|
||||||
modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
) {
|
) { Text("Create New Problem") }
|
||||||
Text("Create New Problem")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -1779,8 +1768,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
singleLine = true,
|
singleLine = true,
|
||||||
colors =
|
colors =
|
||||||
OutlinedTextFieldDefaults.colors(
|
OutlinedTextFieldDefaults.colors(
|
||||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
focusedBorderColor =
|
||||||
unfocusedBorderColor = MaterialTheme.colorScheme.outline
|
MaterialTheme.colorScheme.primary,
|
||||||
|
unfocusedBorderColor =
|
||||||
|
MaterialTheme.colorScheme.outline
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1806,10 +1797,12 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
FilterChipDefaults.filterChipColors(
|
FilterChipDefaults.filterChipColors(
|
||||||
selectedContainerColor =
|
selectedContainerColor =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.primaryContainer,
|
.primaryContainer,
|
||||||
selectedLabelColor =
|
selectedLabelColor =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.onPrimaryContainer
|
.onPrimaryContainer
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1846,10 +1839,12 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
FilterChipDefaults.filterChipColors(
|
FilterChipDefaults.filterChipColors(
|
||||||
selectedContainerColor =
|
selectedContainerColor =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.primaryContainer,
|
.primaryContainer,
|
||||||
selectedLabelColor =
|
selectedLabelColor =
|
||||||
MaterialTheme.colorScheme
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
.onPrimaryContainer
|
.onPrimaryContainer
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1862,36 +1857,51 @@ fun EnhancedAddAttemptDialog(
|
|||||||
value = newProblemGrade,
|
value = newProblemGrade,
|
||||||
onValueChange = { newValue ->
|
onValueChange = { newValue ->
|
||||||
// Only allow integers for custom scales
|
// Only allow integers for custom scales
|
||||||
if (newValue.isEmpty() || newValue.all { it.isDigit() }) {
|
if (newValue.isEmpty() ||
|
||||||
|
newValue.all { it.isDigit() }
|
||||||
|
) {
|
||||||
newProblemGrade = newValue
|
newProblemGrade = newValue
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label = { Text("Grade *") },
|
label = { Text("Grade *") },
|
||||||
placeholder = { Text("Enter numeric grade (e.g. 5, 10, 15)") },
|
placeholder = {
|
||||||
|
Text("Enter numeric grade (e.g. 5, 10, 15)")
|
||||||
|
},
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
colors =
|
colors =
|
||||||
OutlinedTextFieldDefaults.colors(
|
OutlinedTextFieldDefaults.colors(
|
||||||
focusedBorderColor =
|
focusedBorderColor =
|
||||||
MaterialTheme.colorScheme.primary,
|
MaterialTheme.colorScheme
|
||||||
|
.primary,
|
||||||
unfocusedBorderColor =
|
unfocusedBorderColor =
|
||||||
MaterialTheme.colorScheme.outline
|
MaterialTheme.colorScheme
|
||||||
|
.outline
|
||||||
),
|
),
|
||||||
isError = newProblemGrade.isBlank(),
|
isError = newProblemGrade.isBlank(),
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
|
keyboardOptions =
|
||||||
|
KeyboardOptions(
|
||||||
|
keyboardType = KeyboardType.Number
|
||||||
|
),
|
||||||
supportingText =
|
supportingText =
|
||||||
if (newProblemGrade.isBlank()) {
|
if (newProblemGrade.isBlank()) {
|
||||||
{
|
{
|
||||||
Text(
|
Text(
|
||||||
"Grade is required",
|
"Grade is required",
|
||||||
color = MaterialTheme.colorScheme.error
|
color =
|
||||||
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
{
|
{
|
||||||
Text(
|
Text(
|
||||||
"Custom grades must be whole numbers",
|
"Custom grades must be whole numbers",
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color =
|
||||||
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.onSurfaceVariant
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1919,14 +1929,24 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
ExposedDropdownMenuDefaults
|
ExposedDropdownMenuDefaults
|
||||||
.outlinedTextFieldColors(),
|
.outlinedTextFieldColors(),
|
||||||
modifier = Modifier.menuAnchor(androidx.compose.material3.MenuAnchorType.PrimaryNotEditable, enabled = true).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()) {
|
||||||
{
|
{
|
||||||
Text(
|
Text(
|
||||||
"Grade is required",
|
"Grade is required",
|
||||||
color = MaterialTheme.colorScheme.error
|
color =
|
||||||
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else null
|
} else null
|
||||||
@@ -1965,9 +1985,8 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
CardDefaults.cardColors(
|
CardDefaults.cardColors(
|
||||||
containerColor =
|
containerColor =
|
||||||
MaterialTheme.colorScheme.surfaceVariant.copy(
|
MaterialTheme.colorScheme.surfaceVariant
|
||||||
alpha = 0.3f
|
.copy(alpha = 0.3f)
|
||||||
)
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Column(modifier = Modifier.padding(12.dp).selectableGroup()) {
|
Column(modifier = Modifier.padding(12.dp).selectableGroup()) {
|
||||||
@@ -1977,8 +1996,12 @@ fun EnhancedAddAttemptDialog(
|
|||||||
modifier =
|
modifier =
|
||||||
Modifier.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.selectable(
|
.selectable(
|
||||||
selected = selectedResult == result,
|
selected =
|
||||||
onClick = { selectedResult = result },
|
selectedResult ==
|
||||||
|
result,
|
||||||
|
onClick = {
|
||||||
|
selectedResult = result
|
||||||
|
},
|
||||||
role = Role.RadioButton
|
role = Role.RadioButton
|
||||||
)
|
)
|
||||||
.padding(vertical = 4.dp)
|
.padding(vertical = 4.dp)
|
||||||
@@ -1989,18 +2012,22 @@ fun EnhancedAddAttemptDialog(
|
|||||||
colors =
|
colors =
|
||||||
RadioButtonDefaults.colors(
|
RadioButtonDefaults.colors(
|
||||||
selectedColor =
|
selectedColor =
|
||||||
MaterialTheme.colorScheme.primary
|
MaterialTheme
|
||||||
|
.colorScheme
|
||||||
|
.primary
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
Text(
|
Text(
|
||||||
text =
|
text =
|
||||||
result.name.lowercase().replaceFirstChar {
|
result.name.lowercase()
|
||||||
|
.replaceFirstChar {
|
||||||
it.uppercase()
|
it.uppercase()
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
fontWeight =
|
fontWeight =
|
||||||
if (selectedResult == result) FontWeight.Medium
|
if (selectedResult == result)
|
||||||
|
FontWeight.Medium
|
||||||
else FontWeight.Normal,
|
else FontWeight.Normal,
|
||||||
color = MaterialTheme.colorScheme.onSurface
|
color = MaterialTheme.colorScheme.onSurface
|
||||||
)
|
)
|
||||||
@@ -2028,8 +2055,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
singleLine = true,
|
singleLine = true,
|
||||||
colors =
|
colors =
|
||||||
OutlinedTextFieldDefaults.colors(
|
OutlinedTextFieldDefaults.colors(
|
||||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
focusedBorderColor =
|
||||||
unfocusedBorderColor = MaterialTheme.colorScheme.outline
|
MaterialTheme.colorScheme.primary,
|
||||||
|
unfocusedBorderColor =
|
||||||
|
MaterialTheme.colorScheme.outline
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -2045,8 +2074,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
maxLines = 4,
|
maxLines = 4,
|
||||||
colors =
|
colors =
|
||||||
OutlinedTextFieldDefaults.colors(
|
OutlinedTextFieldDefaults.colors(
|
||||||
focusedBorderColor = MaterialTheme.colorScheme.primary,
|
focusedBorderColor =
|
||||||
unfocusedBorderColor = MaterialTheme.colorScheme.outline
|
MaterialTheme.colorScheme.primary,
|
||||||
|
unfocusedBorderColor =
|
||||||
|
MaterialTheme.colorScheme.outline
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -2059,11 +2090,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
colors =
|
colors =
|
||||||
ButtonDefaults.outlinedButtonColors(
|
ButtonDefaults.outlinedButtonColors(
|
||||||
contentColor = MaterialTheme.colorScheme.onSurface
|
contentColor =
|
||||||
|
MaterialTheme.colorScheme.onSurface
|
||||||
)
|
)
|
||||||
) {
|
) { Text("Cancel", fontWeight = FontWeight.Medium) }
|
||||||
Text("Cancel", fontWeight = FontWeight.Medium)
|
|
||||||
}
|
|
||||||
|
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = {
|
||||||
@@ -2072,23 +2102,34 @@ fun EnhancedAddAttemptDialog(
|
|||||||
if (newProblemGrade.isNotBlank()) {
|
if (newProblemGrade.isNotBlank()) {
|
||||||
val difficulty =
|
val difficulty =
|
||||||
DifficultyGrade(
|
DifficultyGrade(
|
||||||
system = selectedDifficultySystem,
|
system =
|
||||||
|
selectedDifficultySystem,
|
||||||
grade = newProblemGrade,
|
grade = newProblemGrade,
|
||||||
numericValue =
|
numericValue =
|
||||||
when (selectedDifficultySystem) {
|
when (selectedDifficultySystem
|
||||||
DifficultySystem.V_SCALE ->
|
) {
|
||||||
|
DifficultySystem
|
||||||
|
.V_SCALE ->
|
||||||
newProblemGrade
|
newProblemGrade
|
||||||
.removePrefix("V")
|
.removePrefix(
|
||||||
.toIntOrNull() ?: 0
|
"V"
|
||||||
|
)
|
||||||
|
.toIntOrNull()
|
||||||
|
?: 0
|
||||||
else ->
|
else ->
|
||||||
newProblemGrade.hashCode() % 100
|
newProblemGrade
|
||||||
|
.hashCode() %
|
||||||
|
100
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val newProblem =
|
val newProblem =
|
||||||
Problem.create(
|
Problem.create(
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
name = newProblemName.ifBlank { null },
|
name =
|
||||||
|
newProblemName.ifBlank {
|
||||||
|
null
|
||||||
|
},
|
||||||
climbType = selectedClimbType,
|
climbType = selectedClimbType,
|
||||||
difficulty = difficulty
|
difficulty = difficulty
|
||||||
)
|
)
|
||||||
@@ -2101,7 +2142,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
sessionId = session.id,
|
sessionId = session.id,
|
||||||
problemId = newProblem.id,
|
problemId = newProblem.id,
|
||||||
result = selectedResult,
|
result = selectedResult,
|
||||||
highestHold = highestHold.ifBlank { null },
|
highestHold =
|
||||||
|
highestHold.ifBlank {
|
||||||
|
null
|
||||||
|
},
|
||||||
notes = notes.ifBlank { null }
|
notes = notes.ifBlank { null }
|
||||||
)
|
)
|
||||||
onAttemptAdded(attempt)
|
onAttemptAdded(attempt)
|
||||||
@@ -2114,7 +2158,10 @@ fun EnhancedAddAttemptDialog(
|
|||||||
sessionId = session.id,
|
sessionId = session.id,
|
||||||
problemId = problem.id,
|
problemId = problem.id,
|
||||||
result = selectedResult,
|
result = selectedResult,
|
||||||
highestHold = highestHold.ifBlank { null },
|
highestHold =
|
||||||
|
highestHold.ifBlank {
|
||||||
|
null
|
||||||
|
},
|
||||||
notes = notes.ifBlank { null }
|
notes = notes.ifBlank { null }
|
||||||
)
|
)
|
||||||
onAttemptAdded(attempt)
|
onAttemptAdded(attempt)
|
||||||
@@ -2127,15 +2174,13 @@ fun EnhancedAddAttemptDialog(
|
|||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
colors =
|
colors =
|
||||||
ButtonDefaults.buttonColors(
|
ButtonDefaults.buttonColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primary,
|
containerColor =
|
||||||
|
MaterialTheme.colorScheme.primary,
|
||||||
disabledContainerColor =
|
disabledContainerColor =
|
||||||
MaterialTheme.colorScheme.onSurface.copy(
|
MaterialTheme.colorScheme.onSurface
|
||||||
alpha = 0.12f
|
.copy(alpha = 0.12f)
|
||||||
)
|
)
|
||||||
)
|
) { Text("Add", fontWeight = FontWeight.Medium) }
|
||||||
) {
|
|
||||||
Text("Add", fontWeight = FontWeight.Medium)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,12 +324,17 @@ class ClimbViewModel(private val repository: ClimbRepository) : ViewModel() {
|
|||||||
fun exportDataToZipUri(context: Context, uri: android.net.Uri) {
|
fun exportDataToZipUri(context: Context, uri: android.net.Uri) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
try {
|
try {
|
||||||
_uiState.value = _uiState.value.copy(isLoading = true)
|
_uiState.value =
|
||||||
|
_uiState.value.copy(
|
||||||
|
isLoading = true,
|
||||||
|
message = "Creating ZIP file with images..."
|
||||||
|
)
|
||||||
repository.exportAllDataToZipUri(context, uri)
|
repository.exportAllDataToZipUri(context, uri)
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
_uiState.value.copy(
|
_uiState.value.copy(
|
||||||
isLoading = false,
|
isLoading = false,
|
||||||
message = "Data with images exported successfully"
|
message =
|
||||||
|
"Export complete! Your climbing data and images have been saved."
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_uiState.value =
|
_uiState.value =
|
||||||
|
|||||||
@@ -394,7 +394,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = OpenClimb/OpenClimb.entitlements;
|
CODE_SIGN_ENTITLEMENTS = OpenClimb/OpenClimb.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
@@ -414,7 +414,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@@ -437,7 +437,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = OpenClimb/OpenClimb.entitlements;
|
CODE_SIGN_ENTITLEMENTS = OpenClimb/OpenClimb.entitlements;
|
||||||
CODE_SIGN_IDENTITY = "Apple Development";
|
CODE_SIGN_IDENTITY = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
@@ -457,7 +457,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||||
@@ -479,7 +479,7 @@
|
|||||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||||
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
@@ -490,7 +490,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb.SessionStatusLive;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb.SessionStatusLive;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
@@ -509,7 +509,7 @@
|
|||||||
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
|
||||||
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
CODE_SIGN_ENTITLEMENTS = SessionStatusLiveExtension.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 7;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
@@ -520,7 +520,7 @@
|
|||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
"@executable_path/../../Frameworks",
|
"@executable_path/../../Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.0.2;
|
MARKETING_VERSION = 1.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb.SessionStatusLive;
|
PRODUCT_BUNDLE_IDENTIFIER = com.atridad.OpenClimb.SessionStatusLive;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SKIP_INSTALL = YES;
|
SKIP_INSTALL = YES;
|
||||||
|
|||||||
Binary file not shown.
@@ -12,7 +12,7 @@
|
|||||||
<key>SessionStatusLiveExtension.xcscheme_^#shared#^_</key>
|
<key>SessionStatusLiveExtension.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>1</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ struct ContentView: View {
|
|||||||
@StateObject private var dataManager = ClimbingDataManager()
|
@StateObject private var dataManager = ClimbingDataManager()
|
||||||
@State private var selectedTab = 0
|
@State private var selectedTab = 0
|
||||||
@Environment(\.scenePhase) private var scenePhase
|
@Environment(\.scenePhase) private var scenePhase
|
||||||
|
@State private var notificationObservers: [NSObjectProtocol] = []
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
TabView(selection: $selectedTab) {
|
TabView(selection: $selectedTab) {
|
||||||
@@ -43,10 +44,22 @@ struct ContentView: View {
|
|||||||
.tag(4)
|
.tag(4)
|
||||||
}
|
}
|
||||||
.environmentObject(dataManager)
|
.environmentObject(dataManager)
|
||||||
.onChange(of: scenePhase) {
|
.onChange(of: scenePhase) { oldPhase, newPhase in
|
||||||
if scenePhase == .active {
|
if newPhase == .active {
|
||||||
|
// Add slight delay to ensure app is fully loaded
|
||||||
|
Task {
|
||||||
|
try? await Task.sleep(nanoseconds: 200_000_000) // 0.2 seconds
|
||||||
dataManager.onAppBecomeActive()
|
dataManager.onAppBecomeActive()
|
||||||
}
|
}
|
||||||
|
} else if newPhase == .background {
|
||||||
|
dataManager.onAppEnterBackground()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.onAppear {
|
||||||
|
setupNotificationObservers()
|
||||||
|
}
|
||||||
|
.onDisappear {
|
||||||
|
removeNotificationObservers()
|
||||||
}
|
}
|
||||||
.overlay(alignment: .top) {
|
.overlay(alignment: .top) {
|
||||||
if let message = dataManager.successMessage {
|
if let message = dataManager.successMessage {
|
||||||
@@ -62,6 +75,44 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func setupNotificationObservers() {
|
||||||
|
// Listen for when the app will enter foreground
|
||||||
|
let willEnterForegroundObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: UIApplication.willEnterForegroundNotification,
|
||||||
|
object: nil,
|
||||||
|
queue: .main
|
||||||
|
) { _ in
|
||||||
|
print("📱 App will enter foreground - preparing Live Activity check")
|
||||||
|
Task {
|
||||||
|
// Small delay to ensure app is fully active
|
||||||
|
try? await Task.sleep(nanoseconds: 800_000_000) // 0.8 seconds
|
||||||
|
await dataManager.onAppBecomeActive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Listen for when the app becomes active
|
||||||
|
let didBecomeActiveObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: UIApplication.didBecomeActiveNotification,
|
||||||
|
object: nil,
|
||||||
|
queue: .main
|
||||||
|
) { _ in
|
||||||
|
print("📱 App did become active - checking Live Activity status")
|
||||||
|
Task {
|
||||||
|
try? await Task.sleep(nanoseconds: 300_000_000) // 0.3 seconds
|
||||||
|
dataManager.onAppBecomeActive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationObservers = [willEnterForegroundObserver, didBecomeActiveObserver]
|
||||||
|
}
|
||||||
|
|
||||||
|
private func removeNotificationObservers() {
|
||||||
|
for observer in notificationObservers {
|
||||||
|
NotificationCenter.default.removeObserver(observer)
|
||||||
|
}
|
||||||
|
notificationObservers.removeAll()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SuccessMessageView: View {
|
struct SuccessMessageView: View {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
@@ -522,7 +521,7 @@ class ImageManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getFullPath(from relativePath: String) -> String {
|
func getFullPath(from relativePath: String) -> String {
|
||||||
// If it's already a full path, check if it's legacy and needs migration
|
// If it's already a full path, check if it's legacy and needs migration
|
||||||
if relativePath.hasPrefix("/") {
|
if relativePath.hasPrefix("/") {
|
||||||
// If it's pointing to legacy Documents directory, redirect to new location
|
// If it's pointing to legacy Documents directory, redirect to new location
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import UniformTypeIdentifiers
|
|||||||
import WidgetKit
|
import WidgetKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if canImport(ActivityKit)
|
||||||
|
import ActivityKit
|
||||||
|
#endif
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
class ClimbingDataManager: ObservableObject {
|
class ClimbingDataManager: ObservableObject {
|
||||||
|
|
||||||
@@ -23,6 +27,7 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
private let sharedUserDefaults = UserDefaults(suiteName: "group.com.atridad.OpenClimb")
|
private let sharedUserDefaults = UserDefaults(suiteName: "group.com.atridad.OpenClimb")
|
||||||
private let encoder = JSONEncoder()
|
private let encoder = JSONEncoder()
|
||||||
private let decoder = JSONDecoder()
|
private let decoder = JSONDecoder()
|
||||||
|
private var liveActivityObserver: NSObjectProtocol?
|
||||||
|
|
||||||
private enum Keys {
|
private enum Keys {
|
||||||
static let gyms = "openclimb_gyms"
|
static let gyms = "openclimb_gyms"
|
||||||
@@ -57,6 +62,7 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
_ = ImageManager.shared
|
_ = ImageManager.shared
|
||||||
loadAllData()
|
loadAllData()
|
||||||
migrateImagePaths()
|
migrateImagePaths()
|
||||||
|
setupLiveActivityNotifications()
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
try? await Task.sleep(nanoseconds: 2_000_000_000)
|
||||||
@@ -67,6 +73,12 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
if let observer = liveActivityObserver {
|
||||||
|
NotificationCenter.default.removeObserver(observer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func loadAllData() {
|
private func loadAllData() {
|
||||||
loadGyms()
|
loadGyms()
|
||||||
loadProblems()
|
loadProblems()
|
||||||
@@ -463,6 +475,7 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
|
|
||||||
let exportData = ClimbDataExport(
|
let exportData = ClimbDataExport(
|
||||||
exportedAt: dateFormatter.string(from: Date()),
|
exportedAt: dateFormatter.string(from: Date()),
|
||||||
|
version: "1.0",
|
||||||
gyms: gyms.map { AndroidGym(from: $0) },
|
gyms: gyms.map { AndroidGym(from: $0) },
|
||||||
problems: problems.map { AndroidProblem(from: $0) },
|
problems: problems.map { AndroidProblem(from: $0) },
|
||||||
sessions: sessions.map { AndroidClimbSession(from: $0) },
|
sessions: sessions.map { AndroidClimbSession(from: $0) },
|
||||||
@@ -471,13 +484,21 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
|
|
||||||
// Collect referenced image paths
|
// Collect referenced image paths
|
||||||
let referencedImagePaths = collectReferencedImagePaths()
|
let referencedImagePaths = collectReferencedImagePaths()
|
||||||
|
print("🎯 Starting export with \(referencedImagePaths.count) images")
|
||||||
|
|
||||||
return try ZipUtils.createExportZip(
|
let zipData = try ZipUtils.createExportZip(
|
||||||
exportData: exportData,
|
exportData: exportData,
|
||||||
referencedImagePaths: referencedImagePaths
|
referencedImagePaths: referencedImagePaths
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print("✅ Export completed successfully")
|
||||||
|
successMessage = "Export completed with \(referencedImagePaths.count) images"
|
||||||
|
clearMessageAfterDelay()
|
||||||
|
return zipData
|
||||||
} catch {
|
} catch {
|
||||||
setError("Export failed: \(error.localizedDescription)")
|
let errorMessage = "Export failed: \(error.localizedDescription)"
|
||||||
|
print("❌ \(errorMessage)")
|
||||||
|
setError(errorMessage)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -565,16 +586,18 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
|
|
||||||
struct ClimbDataExport: Codable {
|
struct ClimbDataExport: Codable {
|
||||||
let exportedAt: String
|
let exportedAt: String
|
||||||
|
let version: String
|
||||||
let gyms: [AndroidGym]
|
let gyms: [AndroidGym]
|
||||||
let problems: [AndroidProblem]
|
let problems: [AndroidProblem]
|
||||||
let sessions: [AndroidClimbSession]
|
let sessions: [AndroidClimbSession]
|
||||||
let attempts: [AndroidAttempt]
|
let attempts: [AndroidAttempt]
|
||||||
|
|
||||||
init(
|
init(
|
||||||
exportedAt: String, gyms: [AndroidGym], problems: [AndroidProblem],
|
exportedAt: String, version: String = "1.0", gyms: [AndroidGym], problems: [AndroidProblem],
|
||||||
sessions: [AndroidClimbSession], attempts: [AndroidAttempt]
|
sessions: [AndroidClimbSession], attempts: [AndroidAttempt]
|
||||||
) {
|
) {
|
||||||
self.exportedAt = exportedAt
|
self.exportedAt = exportedAt
|
||||||
|
self.version = version
|
||||||
self.gyms = gyms
|
self.gyms = gyms
|
||||||
self.problems = problems
|
self.problems = problems
|
||||||
self.sessions = sessions
|
self.sessions = sessions
|
||||||
@@ -588,6 +611,7 @@ struct AndroidGym: Codable {
|
|||||||
let location: String?
|
let location: String?
|
||||||
let supportedClimbTypes: [ClimbType]
|
let supportedClimbTypes: [ClimbType]
|
||||||
let difficultySystems: [DifficultySystem]
|
let difficultySystems: [DifficultySystem]
|
||||||
|
let customDifficultyGrades: [String]
|
||||||
let notes: String?
|
let notes: String?
|
||||||
let createdAt: String
|
let createdAt: String
|
||||||
let updatedAt: String
|
let updatedAt: String
|
||||||
@@ -598,6 +622,7 @@ struct AndroidGym: Codable {
|
|||||||
self.location = gym.location
|
self.location = gym.location
|
||||||
self.supportedClimbTypes = gym.supportedClimbTypes
|
self.supportedClimbTypes = gym.supportedClimbTypes
|
||||||
self.difficultySystems = gym.difficultySystems
|
self.difficultySystems = gym.difficultySystems
|
||||||
|
self.customDifficultyGrades = gym.customDifficultyGrades
|
||||||
self.notes = gym.notes
|
self.notes = gym.notes
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
||||||
@@ -607,13 +632,15 @@ struct AndroidGym: Codable {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
id: String, name: String, location: String?, supportedClimbTypes: [ClimbType],
|
id: String, name: String, location: String?, supportedClimbTypes: [ClimbType],
|
||||||
difficultySystems: [DifficultySystem], notes: String?, createdAt: String, updatedAt: String
|
difficultySystems: [DifficultySystem], customDifficultyGrades: [String] = [],
|
||||||
|
notes: String?, createdAt: String, updatedAt: String
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.location = location
|
self.location = location
|
||||||
self.supportedClimbTypes = supportedClimbTypes
|
self.supportedClimbTypes = supportedClimbTypes
|
||||||
self.difficultySystems = difficultySystems
|
self.difficultySystems = difficultySystems
|
||||||
|
self.customDifficultyGrades = customDifficultyGrades
|
||||||
self.notes = notes
|
self.notes = notes
|
||||||
self.createdAt = createdAt
|
self.createdAt = createdAt
|
||||||
self.updatedAt = updatedAt
|
self.updatedAt = updatedAt
|
||||||
@@ -633,7 +660,7 @@ struct AndroidGym: Codable {
|
|||||||
location: location,
|
location: location,
|
||||||
supportedClimbTypes: supportedClimbTypes,
|
supportedClimbTypes: supportedClimbTypes,
|
||||||
difficultySystems: difficultySystems,
|
difficultySystems: difficultySystems,
|
||||||
customDifficultyGrades: [],
|
customDifficultyGrades: customDifficultyGrades,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
createdAt: createdDate,
|
createdAt: createdDate,
|
||||||
updatedAt: updatedDate
|
updatedAt: updatedDate
|
||||||
@@ -648,7 +675,13 @@ struct AndroidProblem: Codable {
|
|||||||
let description: String?
|
let description: String?
|
||||||
let climbType: ClimbType
|
let climbType: ClimbType
|
||||||
let difficulty: DifficultyGrade
|
let difficulty: DifficultyGrade
|
||||||
|
let setter: String?
|
||||||
|
let tags: [String]
|
||||||
|
let location: String?
|
||||||
let imagePaths: [String]?
|
let imagePaths: [String]?
|
||||||
|
let isActive: Bool
|
||||||
|
let dateSet: String?
|
||||||
|
let notes: String?
|
||||||
let createdAt: String
|
let createdAt: String
|
||||||
let updatedAt: String
|
let updatedAt: String
|
||||||
|
|
||||||
@@ -659,16 +692,26 @@ struct AndroidProblem: Codable {
|
|||||||
self.description = problem.description
|
self.description = problem.description
|
||||||
self.climbType = problem.climbType
|
self.climbType = problem.climbType
|
||||||
self.difficulty = problem.difficulty
|
self.difficulty = problem.difficulty
|
||||||
|
self.setter = problem.setter
|
||||||
|
self.tags = problem.tags
|
||||||
|
self.location = problem.location
|
||||||
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
|
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
|
||||||
|
self.isActive = problem.isActive
|
||||||
|
self.notes = problem.notes
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
||||||
|
self.dateSet = problem.dateSet != nil ? formatter.string(from: problem.dateSet!) : nil
|
||||||
self.createdAt = formatter.string(from: problem.createdAt)
|
self.createdAt = formatter.string(from: problem.createdAt)
|
||||||
self.updatedAt = formatter.string(from: problem.updatedAt)
|
self.updatedAt = formatter.string(from: problem.updatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(
|
||||||
id: String, gymId: String, name: String?, description: String?, climbType: ClimbType,
|
id: String, gymId: String, name: String?, description: String?, climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade, imagePaths: [String]?, createdAt: String, updatedAt: String
|
difficulty: DifficultyGrade, setter: String? = nil, tags: [String] = [],
|
||||||
|
location: String? = nil,
|
||||||
|
imagePaths: [String]? = nil, isActive: Bool = true, dateSet: String? = nil,
|
||||||
|
notes: String? = nil,
|
||||||
|
createdAt: String, updatedAt: String
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.gymId = gymId
|
self.gymId = gymId
|
||||||
@@ -676,7 +719,13 @@ struct AndroidProblem: Codable {
|
|||||||
self.description = description
|
self.description = description
|
||||||
self.climbType = climbType
|
self.climbType = climbType
|
||||||
self.difficulty = difficulty
|
self.difficulty = difficulty
|
||||||
|
self.setter = setter
|
||||||
|
self.tags = tags
|
||||||
|
self.location = location
|
||||||
self.imagePaths = imagePaths
|
self.imagePaths = imagePaths
|
||||||
|
self.isActive = isActive
|
||||||
|
self.dateSet = dateSet
|
||||||
|
self.notes = notes
|
||||||
self.createdAt = createdAt
|
self.createdAt = createdAt
|
||||||
self.updatedAt = updatedAt
|
self.updatedAt = updatedAt
|
||||||
}
|
}
|
||||||
@@ -697,13 +746,13 @@ struct AndroidProblem: Codable {
|
|||||||
description: description,
|
description: description,
|
||||||
climbType: climbType,
|
climbType: climbType,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
setter: nil,
|
setter: setter,
|
||||||
tags: [],
|
tags: tags,
|
||||||
location: nil,
|
location: location,
|
||||||
imagePaths: imagePaths ?? [],
|
imagePaths: imagePaths ?? [],
|
||||||
isActive: true,
|
isActive: isActive,
|
||||||
dateSet: nil,
|
dateSet: dateSet != nil ? formatter.date(from: dateSet!) : nil,
|
||||||
notes: nil,
|
notes: notes,
|
||||||
createdAt: createdDate,
|
createdAt: createdDate,
|
||||||
updatedAt: updatedDate
|
updatedAt: updatedDate
|
||||||
)
|
)
|
||||||
@@ -717,7 +766,13 @@ struct AndroidProblem: Codable {
|
|||||||
description: self.description,
|
description: self.description,
|
||||||
climbType: self.climbType,
|
climbType: self.climbType,
|
||||||
difficulty: self.difficulty,
|
difficulty: self.difficulty,
|
||||||
|
setter: self.setter,
|
||||||
|
tags: self.tags,
|
||||||
|
location: self.location,
|
||||||
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
|
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
|
||||||
|
isActive: self.isActive,
|
||||||
|
dateSet: self.dateSet,
|
||||||
|
notes: self.notes,
|
||||||
createdAt: self.createdAt,
|
createdAt: self.createdAt,
|
||||||
updatedAt: self.updatedAt
|
updatedAt: self.updatedAt
|
||||||
)
|
)
|
||||||
@@ -730,8 +785,9 @@ struct AndroidClimbSession: Codable {
|
|||||||
let date: String
|
let date: String
|
||||||
let startTime: String?
|
let startTime: String?
|
||||||
let endTime: String?
|
let endTime: String?
|
||||||
let duration: Int?
|
let duration: Int64?
|
||||||
let status: SessionStatus
|
let status: SessionStatus
|
||||||
|
let notes: String?
|
||||||
let createdAt: String
|
let createdAt: String
|
||||||
let updatedAt: String
|
let updatedAt: String
|
||||||
|
|
||||||
@@ -743,15 +799,17 @@ struct AndroidClimbSession: Codable {
|
|||||||
self.date = formatter.string(from: session.date)
|
self.date = formatter.string(from: session.date)
|
||||||
self.startTime = session.startTime != nil ? formatter.string(from: session.startTime!) : nil
|
self.startTime = session.startTime != nil ? formatter.string(from: session.startTime!) : nil
|
||||||
self.endTime = session.endTime != nil ? formatter.string(from: session.endTime!) : nil
|
self.endTime = session.endTime != nil ? formatter.string(from: session.endTime!) : nil
|
||||||
self.duration = session.duration
|
self.duration = session.duration != nil ? Int64(session.duration!) : nil
|
||||||
self.status = session.status
|
self.status = session.status
|
||||||
|
self.notes = session.notes
|
||||||
self.createdAt = formatter.string(from: session.createdAt)
|
self.createdAt = formatter.string(from: session.createdAt)
|
||||||
self.updatedAt = formatter.string(from: session.updatedAt)
|
self.updatedAt = formatter.string(from: session.updatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(
|
||||||
id: String, gymId: String, date: String, startTime: String?, endTime: String?,
|
id: String, gymId: String, date: String, startTime: String?, endTime: String?,
|
||||||
duration: Int?, status: SessionStatus, createdAt: String, updatedAt: String
|
duration: Int64?, status: SessionStatus, notes: String? = nil, createdAt: String,
|
||||||
|
updatedAt: String
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.gymId = gymId
|
self.gymId = gymId
|
||||||
@@ -760,6 +818,7 @@ struct AndroidClimbSession: Codable {
|
|||||||
self.endTime = endTime
|
self.endTime = endTime
|
||||||
self.duration = duration
|
self.duration = duration
|
||||||
self.status = status
|
self.status = status
|
||||||
|
self.notes = notes
|
||||||
self.createdAt = createdAt
|
self.createdAt = createdAt
|
||||||
self.updatedAt = updatedAt
|
self.updatedAt = updatedAt
|
||||||
}
|
}
|
||||||
@@ -783,9 +842,9 @@ struct AndroidClimbSession: Codable {
|
|||||||
date: sessionDate,
|
date: sessionDate,
|
||||||
startTime: sessionStartTime,
|
startTime: sessionStartTime,
|
||||||
endTime: sessionEndTime,
|
endTime: sessionEndTime,
|
||||||
duration: duration,
|
duration: duration != nil ? Int(duration!) : nil,
|
||||||
status: status,
|
status: status,
|
||||||
notes: nil,
|
notes: notes,
|
||||||
createdAt: createdDate,
|
createdAt: createdDate,
|
||||||
updatedAt: updatedDate
|
updatedAt: updatedDate
|
||||||
)
|
)
|
||||||
@@ -799,8 +858,8 @@ struct AndroidAttempt: Codable {
|
|||||||
let result: AttemptResult
|
let result: AttemptResult
|
||||||
let highestHold: String?
|
let highestHold: String?
|
||||||
let notes: String?
|
let notes: String?
|
||||||
let duration: Int?
|
let duration: Int64?
|
||||||
let restTime: Int?
|
let restTime: Int64?
|
||||||
let timestamp: String
|
let timestamp: String
|
||||||
let createdAt: String
|
let createdAt: String
|
||||||
|
|
||||||
@@ -811,8 +870,8 @@ struct AndroidAttempt: Codable {
|
|||||||
self.result = attempt.result
|
self.result = attempt.result
|
||||||
self.highestHold = attempt.highestHold
|
self.highestHold = attempt.highestHold
|
||||||
self.notes = attempt.notes
|
self.notes = attempt.notes
|
||||||
self.duration = attempt.duration
|
self.duration = attempt.duration != nil ? Int64(attempt.duration!) : nil
|
||||||
self.restTime = attempt.restTime
|
self.restTime = attempt.restTime != nil ? Int64(attempt.restTime!) : nil
|
||||||
let formatter = DateFormatter()
|
let formatter = DateFormatter()
|
||||||
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
|
||||||
self.timestamp = formatter.string(from: attempt.timestamp)
|
self.timestamp = formatter.string(from: attempt.timestamp)
|
||||||
@@ -821,7 +880,7 @@ struct AndroidAttempt: Codable {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
id: String, sessionId: String, problemId: String, result: AttemptResult,
|
id: String, sessionId: String, problemId: String, result: AttemptResult,
|
||||||
highestHold: String?, notes: String?, duration: Int?, restTime: Int?,
|
highestHold: String?, notes: String?, duration: Int64?, restTime: Int64?,
|
||||||
timestamp: String, createdAt: String
|
timestamp: String, createdAt: String
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
@@ -853,8 +912,8 @@ struct AndroidAttempt: Codable {
|
|||||||
result: result,
|
result: result,
|
||||||
highestHold: highestHold,
|
highestHold: highestHold,
|
||||||
notes: notes,
|
notes: notes,
|
||||||
duration: duration,
|
duration: duration != nil ? Int(duration!) : nil,
|
||||||
restTime: restTime,
|
restTime: restTime != nil ? Int(restTime!) : nil,
|
||||||
timestamp: attemptTimestamp,
|
timestamp: attemptTimestamp,
|
||||||
createdAt: createdDate
|
createdAt: createdDate
|
||||||
)
|
)
|
||||||
@@ -864,9 +923,33 @@ struct AndroidAttempt: Codable {
|
|||||||
extension ClimbingDataManager {
|
extension ClimbingDataManager {
|
||||||
private func collectReferencedImagePaths() -> Set<String> {
|
private func collectReferencedImagePaths() -> Set<String> {
|
||||||
var imagePaths = Set<String>()
|
var imagePaths = Set<String>()
|
||||||
|
print("🖼️ Starting image path collection...")
|
||||||
|
print("📊 Total problems: \(problems.count)")
|
||||||
|
|
||||||
for problem in problems {
|
for problem in problems {
|
||||||
imagePaths.formUnion(problem.imagePaths)
|
if !problem.imagePaths.isEmpty {
|
||||||
|
print(
|
||||||
|
"📸 Problem '\(problem.name ?? "Unnamed")' has \(problem.imagePaths.count) images"
|
||||||
|
)
|
||||||
|
for imagePath in problem.imagePaths {
|
||||||
|
print(" - Relative path: \(imagePath)")
|
||||||
|
let fullPath = ImageManager.shared.getFullPath(from: imagePath)
|
||||||
|
print(" - Full path: \(fullPath)")
|
||||||
|
|
||||||
|
// Check if file exists
|
||||||
|
if FileManager.default.fileExists(atPath: fullPath) {
|
||||||
|
print(" ✅ File exists")
|
||||||
|
imagePaths.insert(fullPath)
|
||||||
|
} else {
|
||||||
|
print(" ❌ File does NOT exist")
|
||||||
|
// Still add it to let ZipUtils handle the error logging
|
||||||
|
imagePaths.insert(fullPath)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print("🖼️ Collected \(imagePaths.count) total image paths for export")
|
||||||
return imagePaths
|
return imagePaths
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1046,23 +1129,111 @@ extension ClimbingDataManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func checkAndRestartLiveActivity() async {
|
private func checkAndRestartLiveActivity() async {
|
||||||
guard let activeSession = activeSession else { return }
|
guard let activeSession = activeSession else {
|
||||||
|
// No active session, make sure all Live Activities are cleaned up
|
||||||
|
await LiveActivityManager.shared.endLiveActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only restart if session is actually active
|
||||||
|
guard activeSession.status == .active else {
|
||||||
|
print(
|
||||||
|
"⚠️ Session exists but is not active (status: \(activeSession.status)), ending Live Activity"
|
||||||
|
)
|
||||||
|
await LiveActivityManager.shared.endLiveActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if let gym = gym(withId: activeSession.gymId) {
|
if let gym = gym(withId: activeSession.gymId) {
|
||||||
|
print("🔍 Checking Live Activity for active session at \(gym.name)")
|
||||||
|
|
||||||
|
// First cleanup any dismissed activities
|
||||||
|
await LiveActivityManager.shared.cleanupDismissedActivities()
|
||||||
|
|
||||||
|
// Then attempt to restart if needed
|
||||||
await LiveActivityManager.shared.restartLiveActivityIfNeeded(
|
await LiveActivityManager.shared.restartLiveActivityIfNeeded(
|
||||||
activeSession: activeSession,
|
activeSession: activeSession,
|
||||||
gymName: gym.name
|
gymName: gym.name
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Update with current session data
|
||||||
|
await updateLiveActivityData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this when app becomes active to check for Live Activity restart
|
/// Call this when app becomes active to check for Live Activity restart
|
||||||
func onAppBecomeActive() {
|
func onAppBecomeActive() {
|
||||||
|
print("📱 App became active - checking Live Activity status")
|
||||||
Task {
|
Task {
|
||||||
await checkAndRestartLiveActivity()
|
await checkAndRestartLiveActivity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Call this when app enters background to update Live Activity
|
||||||
|
func onAppEnterBackground() {
|
||||||
|
print("📱 App entering background - updating Live Activity if needed")
|
||||||
|
Task {
|
||||||
|
await updateLiveActivityData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Setup notifications for Live Activity events
|
||||||
|
private func setupLiveActivityNotifications() {
|
||||||
|
liveActivityObserver = NotificationCenter.default.addObserver(
|
||||||
|
forName: .liveActivityDismissed,
|
||||||
|
object: nil,
|
||||||
|
queue: .main
|
||||||
|
) { [weak self] _ in
|
||||||
|
print("🔔 Received Live Activity dismissed notification - attempting restart")
|
||||||
|
Task { @MainActor in
|
||||||
|
await self?.handleLiveActivityDismissed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handle Live Activity being dismissed by user
|
||||||
|
private func handleLiveActivityDismissed() async {
|
||||||
|
guard let activeSession = activeSession,
|
||||||
|
activeSession.status == .active,
|
||||||
|
let gym = gym(withId: activeSession.gymId)
|
||||||
|
else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
print("🔄 Attempting to restart dismissed Live Activity for \(gym.name)")
|
||||||
|
|
||||||
|
// Wait a bit before restarting to avoid frequency limits
|
||||||
|
try? await Task.sleep(nanoseconds: 2_000_000_000) // 2 seconds
|
||||||
|
|
||||||
|
await LiveActivityManager.shared.startLiveActivity(
|
||||||
|
for: activeSession,
|
||||||
|
gymName: gym.name
|
||||||
|
)
|
||||||
|
|
||||||
|
// Update with current data
|
||||||
|
await updateLiveActivityData()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update Live Activity with current session statistics
|
||||||
|
private func updateLiveActivityData() async {
|
||||||
|
guard let activeSession = activeSession,
|
||||||
|
activeSession.status == .active
|
||||||
|
else { return }
|
||||||
|
|
||||||
|
let elapsed = Date().timeIntervalSince(activeSession.startTime ?? activeSession.date)
|
||||||
|
let sessionAttempts = attempts.filter { $0.sessionId == activeSession.id }
|
||||||
|
let totalAttempts = sessionAttempts.count
|
||||||
|
let completedProblems = Set(
|
||||||
|
sessionAttempts.filter { $0.result.isSuccessful }.map { $0.problemId }
|
||||||
|
).count
|
||||||
|
|
||||||
|
await LiveActivityManager.shared.updateLiveActivity(
|
||||||
|
elapsed: elapsed,
|
||||||
|
totalAttempts: totalAttempts,
|
||||||
|
completedProblems: completedProblems
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Update Live Activity with current session data
|
/// Update Live Activity with current session data
|
||||||
private func updateLiveActivityForActiveSession() {
|
private func updateLiveActivityForActiveSession() {
|
||||||
guard let activeSession = activeSession,
|
guard let activeSession = activeSession,
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
import ActivityKit
|
import ActivityKit
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
extension Notification.Name {
|
||||||
|
static let liveActivityDismissed = Notification.Name("liveActivityDismissed")
|
||||||
|
}
|
||||||
|
|
||||||
@MainActor
|
@MainActor
|
||||||
final class LiveActivityManager {
|
final class LiveActivityManager {
|
||||||
static let shared = LiveActivityManager()
|
static let shared = LiveActivityManager()
|
||||||
private init() {}
|
private init() {}
|
||||||
|
|
||||||
private var currentActivity: Activity<SessionActivityAttributes>?
|
private var currentActivity: Activity<SessionActivityAttributes>?
|
||||||
|
private var healthCheckTimer: Timer?
|
||||||
|
private var lastHealthCheck: Date = Date()
|
||||||
|
|
||||||
|
deinit {
|
||||||
|
healthCheckTimer?.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if there's an active session and restart Live Activity if needed
|
/// Check if there's an active session and restart Live Activity if needed
|
||||||
func restartLiveActivityIfNeeded(activeSession: ClimbSession?, gymName: String?) async {
|
func restartLiveActivityIfNeeded(activeSession: ClimbSession?, gymName: String?) async {
|
||||||
@@ -18,13 +28,31 @@ final class LiveActivityManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we already have a running Live Activity
|
// Check if we have a tracked Live Activity that's still actually running
|
||||||
if currentActivity != nil {
|
if let currentActivity = currentActivity {
|
||||||
print("ℹ️ Live Activity already running")
|
let activities = Activity<SessionActivityAttributes>.activities
|
||||||
|
let isStillActive = activities.contains { $0.id == currentActivity.id }
|
||||||
|
|
||||||
|
if isStillActive {
|
||||||
|
print("ℹ️ Live Activity still running: \(currentActivity.id)")
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
print(
|
||||||
|
"⚠️ Tracked Live Activity \(currentActivity.id) was dismissed, clearing reference"
|
||||||
|
)
|
||||||
|
self.currentActivity = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if there are ANY active Live Activities for this session
|
||||||
|
let existingActivities = Activity<SessionActivityAttributes>.activities
|
||||||
|
if let existingActivity = existingActivities.first {
|
||||||
|
print("ℹ️ Found existing Live Activity: \(existingActivity.id), using it")
|
||||||
|
self.currentActivity = existingActivity
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
print("🔄 Restarting Live Activity for existing session")
|
print("🔄 No Live Activity found, restarting for existing session")
|
||||||
await startLiveActivity(for: activeSession, gymName: gymName)
|
await startLiveActivity(for: activeSession, gymName: gymName)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,10 +62,17 @@ final class LiveActivityManager {
|
|||||||
|
|
||||||
await endLiveActivity()
|
await endLiveActivity()
|
||||||
|
|
||||||
|
// Start health checks once we have an active session
|
||||||
|
startHealthChecks()
|
||||||
|
|
||||||
|
// Calculate elapsed time if session already started
|
||||||
|
let startTime = session.startTime ?? session.date
|
||||||
|
let elapsed = Date().timeIntervalSince(startTime)
|
||||||
|
|
||||||
let attributes = SessionActivityAttributes(
|
let attributes = SessionActivityAttributes(
|
||||||
gymName: gymName, startTime: session.startTime ?? session.date)
|
gymName: gymName, startTime: startTime)
|
||||||
let initialContentState = SessionActivityAttributes.ContentState(
|
let initialContentState = SessionActivityAttributes.ContentState(
|
||||||
elapsed: 0,
|
elapsed: elapsed,
|
||||||
totalAttempts: 0,
|
totalAttempts: 0,
|
||||||
completedProblems: 0
|
completedProblems: 0
|
||||||
)
|
)
|
||||||
@@ -59,6 +94,8 @@ final class LiveActivityManager {
|
|||||||
print("Authorization error - check Live Activity permissions in Settings")
|
print("Authorization error - check Live Activity permissions in Settings")
|
||||||
} else if error.localizedDescription.contains("content") {
|
} else if error.localizedDescription.contains("content") {
|
||||||
print("Content error - check ActivityAttributes structure")
|
print("Content error - check ActivityAttributes structure")
|
||||||
|
} else if error.localizedDescription.contains("frequencyLimited") {
|
||||||
|
print("Frequency limited - too many Live Activities started recently")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,11 +103,23 @@ final class LiveActivityManager {
|
|||||||
/// Call this to update the Live Activity with new session progress
|
/// Call this to update the Live Activity with new session progress
|
||||||
func updateLiveActivity(elapsed: TimeInterval, totalAttempts: Int, completedProblems: Int) async
|
func updateLiveActivity(elapsed: TimeInterval, totalAttempts: Int, completedProblems: Int) async
|
||||||
{
|
{
|
||||||
guard let currentActivity else {
|
guard let currentActivity = currentActivity else {
|
||||||
print("⚠️ No current activity to update")
|
print("⚠️ No current activity to update")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify the activity is still valid before updating
|
||||||
|
let activities = Activity<SessionActivityAttributes>.activities
|
||||||
|
let isStillActive = activities.contains { $0.id == currentActivity.id }
|
||||||
|
|
||||||
|
if !isStillActive {
|
||||||
|
print(
|
||||||
|
"⚠️ Tracked Live Activity \(currentActivity.id) is no longer active, clearing reference"
|
||||||
|
)
|
||||||
|
self.currentActivity = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
print(
|
print(
|
||||||
"🔄 Updating Live Activity - Attempts: \(totalAttempts), Completed: \(completedProblems)"
|
"🔄 Updating Live Activity - Attempts: \(totalAttempts), Completed: \(completedProblems)"
|
||||||
)
|
)
|
||||||
@@ -81,12 +130,21 @@ final class LiveActivityManager {
|
|||||||
completedProblems: completedProblems
|
completedProblems: completedProblems
|
||||||
)
|
)
|
||||||
|
|
||||||
|
do {
|
||||||
await currentActivity.update(.init(state: updatedContentState, staleDate: nil))
|
await currentActivity.update(.init(state: updatedContentState, staleDate: nil))
|
||||||
print("✅ Live Activity updated successfully")
|
print("✅ Live Activity updated successfully")
|
||||||
|
} catch {
|
||||||
|
print("❌ Failed to update Live Activity: \(error)")
|
||||||
|
// If update fails, the activity might have been dismissed
|
||||||
|
self.currentActivity = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call this when a ClimbSession ends to end the Live Activity
|
/// Call this when a ClimbSession ends to end the Live Activity
|
||||||
func endLiveActivity() async {
|
func endLiveActivity() async {
|
||||||
|
// Stop health checks first
|
||||||
|
stopHealthChecks()
|
||||||
|
|
||||||
// First end the tracked activity if it exists
|
// First end the tracked activity if it exists
|
||||||
if let currentActivity {
|
if let currentActivity {
|
||||||
print("🔴 Ending tracked Live Activity: \(currentActivity.id)")
|
print("🔴 Ending tracked Live Activity: \(currentActivity.id)")
|
||||||
@@ -115,18 +173,92 @@ final class LiveActivityManager {
|
|||||||
func checkLiveActivityAvailability() -> String {
|
func checkLiveActivityAvailability() -> String {
|
||||||
let authorizationInfo = ActivityAuthorizationInfo()
|
let authorizationInfo = ActivityAuthorizationInfo()
|
||||||
let status = authorizationInfo.areActivitiesEnabled
|
let status = authorizationInfo.areActivitiesEnabled
|
||||||
|
let allActivities = Activity<SessionActivityAttributes>.activities
|
||||||
|
|
||||||
let message = """
|
let message = """
|
||||||
Live Activity Status:
|
Live Activity Status:
|
||||||
• Enabled: \(status)
|
• Enabled: \(status)
|
||||||
• Authorization: \(authorizationInfo.areActivitiesEnabled ? "Granted" : "Denied/Unknown")
|
• Authorization: \(authorizationInfo.areActivitiesEnabled ? "Granted" : "Denied/Unknown")
|
||||||
• Current Activity: \(currentActivity?.id.description ?? "None")
|
• Tracked Activity: \(currentActivity?.id.description ?? "None")
|
||||||
|
• All Active Activities: \(allActivities.count)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print(message)
|
print(message)
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Force check and cleanup dismissed Live Activities
|
||||||
|
func cleanupDismissedActivities() async {
|
||||||
|
let activities = Activity<SessionActivityAttributes>.activities
|
||||||
|
|
||||||
|
if let currentActivity = currentActivity {
|
||||||
|
let isStillActive = activities.contains { $0.id == currentActivity.id }
|
||||||
|
if !isStillActive {
|
||||||
|
print("🧹 Cleaning up dismissed Live Activity: \(currentActivity.id)")
|
||||||
|
self.currentActivity = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start periodic health checks for Live Activity
|
||||||
|
func startHealthChecks() {
|
||||||
|
stopHealthChecks() // Stop any existing timer
|
||||||
|
|
||||||
|
print("🩺 Starting Live Activity health checks")
|
||||||
|
healthCheckTimer = Timer.scheduledTimer(withTimeInterval: 30.0, repeats: true) {
|
||||||
|
[weak self] _ in
|
||||||
|
Task { @MainActor in
|
||||||
|
await self?.performHealthCheck()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stop periodic health checks
|
||||||
|
func stopHealthChecks() {
|
||||||
|
healthCheckTimer?.invalidate()
|
||||||
|
healthCheckTimer = nil
|
||||||
|
print("🛑 Stopped Live Activity health checks")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Perform a health check on the current Live Activity
|
||||||
|
private func performHealthCheck() async {
|
||||||
|
guard let currentActivity = currentActivity else { return }
|
||||||
|
|
||||||
|
let now = Date()
|
||||||
|
let timeSinceLastCheck = now.timeIntervalSince(lastHealthCheck)
|
||||||
|
|
||||||
|
// Only perform health check if it's been at least 25 seconds
|
||||||
|
guard timeSinceLastCheck >= 25 else { return }
|
||||||
|
|
||||||
|
print("🩺 Performing Live Activity health check")
|
||||||
|
lastHealthCheck = now
|
||||||
|
|
||||||
|
let activities = Activity<SessionActivityAttributes>.activities
|
||||||
|
let isStillActive = activities.contains { $0.id == currentActivity.id }
|
||||||
|
|
||||||
|
if !isStillActive {
|
||||||
|
print("💔 Health check failed - Live Activity was dismissed")
|
||||||
|
self.currentActivity = nil
|
||||||
|
|
||||||
|
// Notify that we need to restart
|
||||||
|
NotificationCenter.default.post(
|
||||||
|
name: .liveActivityDismissed,
|
||||||
|
object: nil
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
print("✅ Live Activity health check passed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the current activity status for debugging
|
||||||
|
func getCurrentActivityStatus() -> String {
|
||||||
|
let activities = Activity<SessionActivityAttributes>.activities
|
||||||
|
let trackedStatus = currentActivity != nil ? "Tracked" : "None"
|
||||||
|
let actualCount = activities.count
|
||||||
|
|
||||||
|
return "Status: \(trackedStatus) | Active Count: \(actualCount)"
|
||||||
|
}
|
||||||
|
|
||||||
/// Start periodic updates for Live Activity
|
/// Start periodic updates for Live Activity
|
||||||
func startPeriodicUpdates(for session: ClimbSession, totalAttempts: Int, completedProblems: Int)
|
func startPeriodicUpdates(for session: ClimbSession, totalAttempts: Int, completedProblems: Int)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -105,9 +105,26 @@ struct ProgressChartSection: View {
|
|||||||
@EnvironmentObject var dataManager: ClimbingDataManager
|
@EnvironmentObject var dataManager: ClimbingDataManager
|
||||||
@State private var selectedSystem: DifficultySystem = .vScale
|
@State private var selectedSystem: DifficultySystem = .vScale
|
||||||
@State private var showAllTime: Bool = true
|
@State private var showAllTime: Bool = true
|
||||||
|
@State private var cachedGradeCountData: [GradeCount] = []
|
||||||
|
@State private var lastCalculationDate: Date = Date.distantPast
|
||||||
|
@State private var lastDataHash: Int = 0
|
||||||
|
|
||||||
private var gradeCountData: [GradeCount] {
|
private var gradeCountData: [GradeCount] {
|
||||||
calculateGradeCounts()
|
let currentHash =
|
||||||
|
dataManager.problems.count + dataManager.attempts.count + (showAllTime ? 1 : 0)
|
||||||
|
let now = Date()
|
||||||
|
|
||||||
|
// Recalculate only if data changed or cache is older than 30 seconds
|
||||||
|
if currentHash != lastDataHash || now.timeIntervalSince(lastCalculationDate) > 30 {
|
||||||
|
let newData = calculateGradeCounts()
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.cachedGradeCountData = newData
|
||||||
|
self.lastCalculationDate = now
|
||||||
|
self.lastDataHash = currentHash
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cachedGradeCountData.isEmpty ? calculateGradeCounts() : cachedGradeCountData
|
||||||
}
|
}
|
||||||
|
|
||||||
private var usedSystems: [DifficultySystem] {
|
private var usedSystems: [DifficultySystem] {
|
||||||
|
|||||||
@@ -15,6 +15,18 @@ struct SessionDetailView: View {
|
|||||||
dataManager.session(withId: sessionId)
|
dataManager.session(withId: sessionId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func startTimer() {
|
||||||
|
// Update every 5 seconds instead of 1 second for better performance
|
||||||
|
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { _ in
|
||||||
|
currentTime = Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopTimer() {
|
||||||
|
timer?.invalidate()
|
||||||
|
timer = nil
|
||||||
|
}
|
||||||
|
|
||||||
private var gym: Gym? {
|
private var gym: Gym? {
|
||||||
guard let session = session else { return nil }
|
guard let session = session else { return nil }
|
||||||
return dataManager.gym(withId: session.gymId)
|
return dataManager.gym(withId: session.gymId)
|
||||||
@@ -35,7 +47,7 @@ struct SessionDetailView: View {
|
|||||||
calculateSessionStats()
|
calculateSessionStats()
|
||||||
}
|
}
|
||||||
|
|
||||||
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
@State private var timer: Timer?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
@@ -57,8 +69,11 @@ struct SessionDetailView: View {
|
|||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
.onReceive(timer) { _ in
|
.onAppear {
|
||||||
currentTime = Date()
|
startTimer()
|
||||||
|
}
|
||||||
|
.onDisappear {
|
||||||
|
stopTimer()
|
||||||
}
|
}
|
||||||
.navigationTitle("Session Details")
|
.navigationTitle("Session Details")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
@@ -153,46 +168,14 @@ struct SessionDetailView: View {
|
|||||||
let uniqueProblems = Set(attempts.map { $0.problemId })
|
let uniqueProblems = Set(attempts.map { $0.problemId })
|
||||||
let completedProblems = Set(successfulAttempts.map { $0.problemId })
|
let completedProblems = Set(successfulAttempts.map { $0.problemId })
|
||||||
|
|
||||||
let attemptedProblems = uniqueProblems.compactMap { dataManager.problem(withId: $0) }
|
|
||||||
let boulderProblems = attemptedProblems.filter { $0.climbType == .boulder }
|
|
||||||
let ropeProblems = attemptedProblems.filter { $0.climbType == .rope }
|
|
||||||
|
|
||||||
let boulderRange = gradeRange(for: boulderProblems)
|
|
||||||
let ropeRange = gradeRange(for: ropeProblems)
|
|
||||||
|
|
||||||
return SessionStats(
|
return SessionStats(
|
||||||
totalAttempts: attempts.count,
|
totalAttempts: attempts.count,
|
||||||
successfulAttempts: successfulAttempts.count,
|
successfulAttempts: successfulAttempts.count,
|
||||||
uniqueProblemsAttempted: uniqueProblems.count,
|
uniqueProblemsAttempted: uniqueProblems.count,
|
||||||
uniqueProblemsCompleted: completedProblems.count,
|
uniqueProblemsCompleted: completedProblems.count
|
||||||
boulderRange: boulderRange,
|
|
||||||
ropeRange: ropeRange
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func gradeRange(for problems: [Problem]) -> String? {
|
|
||||||
guard !problems.isEmpty else { return nil }
|
|
||||||
let difficulties = problems.map { $0.difficulty }
|
|
||||||
|
|
||||||
// Group by difficulty system first
|
|
||||||
let groupedBySystem = Dictionary(grouping: difficulties) { $0.system }
|
|
||||||
|
|
||||||
// For each system, find the range
|
|
||||||
let ranges = groupedBySystem.compactMap { (system, difficulties) -> String? in
|
|
||||||
let sortedDifficulties = difficulties.sorted()
|
|
||||||
guard let min = sortedDifficulties.first, let max = sortedDifficulties.last else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if min == max {
|
|
||||||
return min.grade
|
|
||||||
} else {
|
|
||||||
return "\(min.grade) - \(max.grade)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ranges.joined(separator: ", ")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionHeaderCard: View {
|
struct SessionHeaderCard: View {
|
||||||
@@ -300,19 +283,6 @@ struct SessionStatsCard: View {
|
|||||||
StatItem(label: "Successful", value: "\(stats.successfulAttempts)")
|
StatItem(label: "Successful", value: "\(stats.successfulAttempts)")
|
||||||
StatItem(label: "Completed", value: "\(stats.uniqueProblemsCompleted)")
|
StatItem(label: "Completed", value: "\(stats.uniqueProblemsCompleted)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grade ranges
|
|
||||||
VStack(alignment: .leading, spacing: 8) {
|
|
||||||
if let boulderRange = stats.boulderRange, let ropeRange = stats.ropeRange {
|
|
||||||
HStack {
|
|
||||||
StatItem(label: "Boulder Range", value: boulderRange)
|
|
||||||
StatItem(label: "Rope Range", value: ropeRange)
|
|
||||||
}
|
|
||||||
} else if let singleRange = stats.boulderRange ?? stats.ropeRange {
|
|
||||||
StatItem(label: "Grade Range", value: singleRange)
|
|
||||||
.frame(maxWidth: .infinity, alignment: .center)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
@@ -504,8 +474,6 @@ struct SessionStats {
|
|||||||
let successfulAttempts: Int
|
let successfulAttempts: Int
|
||||||
let uniqueProblemsAttempted: Int
|
let uniqueProblemsAttempted: Int
|
||||||
let uniqueProblemsCompleted: Int
|
let uniqueProblemsCompleted: Int
|
||||||
let boulderRange: String?
|
|
||||||
let ropeRange: String?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#Preview {
|
#Preview {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ProblemsView: View {
|
struct ProblemsView: View {
|
||||||
@@ -286,7 +285,7 @@ struct ProblemRow: View {
|
|||||||
|
|
||||||
if !problem.imagePaths.isEmpty {
|
if !problem.imagePaths.isEmpty {
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
HStack(spacing: 8) {
|
LazyHStack(spacing: 8) {
|
||||||
ForEach(problem.imagePaths.prefix(3), id: \.self) { imagePath in
|
ForEach(problem.imagePaths.prefix(3), id: \.self) { imagePath in
|
||||||
ProblemImageView(imagePath: imagePath)
|
ProblemImageView(imagePath: imagePath)
|
||||||
}
|
}
|
||||||
@@ -372,6 +371,13 @@ struct ProblemImageView: View {
|
|||||||
@State private var isLoading = true
|
@State private var isLoading = true
|
||||||
@State private var hasFailed = false
|
@State private var hasFailed = false
|
||||||
|
|
||||||
|
private static var imageCache: NSCache<NSString, UIImage> = {
|
||||||
|
let cache = NSCache<NSString, UIImage>()
|
||||||
|
cache.countLimit = 100
|
||||||
|
cache.totalCostLimit = 50 * 1024 * 1024 // 50MB
|
||||||
|
return cache
|
||||||
|
}()
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if let uiImage = uiImage {
|
if let uiImage = uiImage {
|
||||||
@@ -412,10 +418,22 @@ struct ProblemImageView: View {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let cacheKey = NSString(string: imagePath)
|
||||||
|
|
||||||
|
// Check cache first
|
||||||
|
if let cachedImage = Self.imageCache.object(forKey: cacheKey) {
|
||||||
|
self.uiImage = cachedImage
|
||||||
|
self.isLoading = false
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
DispatchQueue.global(qos: .userInitiated).async {
|
DispatchQueue.global(qos: .userInitiated).async {
|
||||||
if let data = ImageManager.shared.loadImageData(fromPath: imagePath),
|
if let data = ImageManager.shared.loadImageData(fromPath: imagePath),
|
||||||
let image = UIImage(data: data)
|
let image = UIImage(data: data)
|
||||||
{
|
{
|
||||||
|
// Cache the image
|
||||||
|
Self.imageCache.setObject(image, forKey: cacheKey)
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.uiImage = image
|
self.uiImage = image
|
||||||
self.isLoading = false
|
self.isLoading = false
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ struct ActiveSessionBanner: View {
|
|||||||
@State private var currentTime = Date()
|
@State private var currentTime = Date()
|
||||||
@State private var navigateToDetail = false
|
@State private var navigateToDetail = false
|
||||||
|
|
||||||
private let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
|
@State private var timer: Timer?
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
HStack {
|
HStack {
|
||||||
@@ -162,8 +162,11 @@ struct ActiveSessionBanner: View {
|
|||||||
.fill(.green.opacity(0.1))
|
.fill(.green.opacity(0.1))
|
||||||
.stroke(.green.opacity(0.3), lineWidth: 1)
|
.stroke(.green.opacity(0.3), lineWidth: 1)
|
||||||
)
|
)
|
||||||
.onReceive(timer) { _ in
|
.onAppear {
|
||||||
currentTime = Date()
|
startTimer()
|
||||||
|
}
|
||||||
|
.onDisappear {
|
||||||
|
stopTimer()
|
||||||
}
|
}
|
||||||
.background(
|
.background(
|
||||||
NavigationLink(
|
NavigationLink(
|
||||||
@@ -190,6 +193,17 @@ struct ActiveSessionBanner: View {
|
|||||||
return String(format: "%ds", seconds)
|
return String(format: "%ds", seconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func startTimer() {
|
||||||
|
timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true) { _ in
|
||||||
|
currentTime = Date()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func stopTimer() {
|
||||||
|
timer?.invalidate()
|
||||||
|
timer = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SessionRow: View {
|
struct SessionRow: View {
|
||||||
|
|||||||
@@ -164,15 +164,37 @@ struct ExportDataView: View {
|
|||||||
let data: Data
|
let data: Data
|
||||||
@Environment(\.dismiss) private var dismiss
|
@Environment(\.dismiss) private var dismiss
|
||||||
@State private var tempFileURL: URL?
|
@State private var tempFileURL: URL?
|
||||||
|
@State private var isCreatingFile = true
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
|
VStack(spacing: 30) {
|
||||||
|
if isCreatingFile {
|
||||||
|
// Loading state - more prominent
|
||||||
VStack(spacing: 20) {
|
VStack(spacing: 20) {
|
||||||
Image(systemName: "square.and.arrow.up")
|
ProgressView()
|
||||||
.font(.system(size: 60))
|
.scaleEffect(1.5)
|
||||||
.foregroundColor(.blue)
|
.tint(.blue)
|
||||||
|
|
||||||
Text("Export Data")
|
Text("Preparing Your Export")
|
||||||
|
.font(.title2)
|
||||||
|
.fontWeight(.semibold)
|
||||||
|
|
||||||
|
Text("Creating ZIP file with your climbing data and images...")
|
||||||
|
.font(.body)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.padding(.horizontal)
|
||||||
|
}
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||||||
|
} else {
|
||||||
|
// Ready state
|
||||||
|
VStack(spacing: 20) {
|
||||||
|
Image(systemName: "checkmark.circle.fill")
|
||||||
|
.font(.system(size: 60))
|
||||||
|
.foregroundColor(.green)
|
||||||
|
|
||||||
|
Text("Export Ready!")
|
||||||
.font(.title)
|
.font(.title)
|
||||||
.fontWeight(.bold)
|
.fontWeight(.bold)
|
||||||
|
|
||||||
@@ -201,24 +223,12 @@ struct ExportDataView: View {
|
|||||||
}
|
}
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
.buttonStyle(.plain)
|
.buttonStyle(.plain)
|
||||||
} else {
|
|
||||||
Button(action: {}) {
|
|
||||||
Label("Preparing Export...", systemImage: "hourglass")
|
|
||||||
.font(.headline)
|
|
||||||
.foregroundColor(.white)
|
|
||||||
.frame(maxWidth: .infinity)
|
|
||||||
.padding()
|
|
||||||
.background(
|
|
||||||
RoundedRectangle(cornerRadius: 12)
|
|
||||||
.fill(.gray)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
.disabled(true)
|
|
||||||
.padding(.horizontal)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.padding()
|
.padding()
|
||||||
.navigationTitle("Export")
|
.navigationTitle("Export")
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
@@ -259,6 +269,9 @@ struct ExportDataView: View {
|
|||||||
).first
|
).first
|
||||||
else {
|
else {
|
||||||
print("Could not access Documents directory")
|
print("Could not access Documents directory")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isCreatingFile = false
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let fileURL = documentsURL.appendingPathComponent(filename)
|
let fileURL = documentsURL.appendingPathComponent(filename)
|
||||||
@@ -268,9 +281,13 @@ struct ExportDataView: View {
|
|||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.tempFileURL = fileURL
|
self.tempFileURL = fileURL
|
||||||
|
self.isCreatingFile = false
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print("Failed to create export file: \(error)")
|
print("Failed to create export file: \(error)")
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.isCreatingFile = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user