New builds for iOS 1.0.3 and Android 1.5.1
This commit is contained in:
@@ -11,8 +11,7 @@ interface ProblemDao {
|
|||||||
@Query("SELECT * FROM problems ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems ORDER BY updatedAt DESC")
|
||||||
fun getAllProblems(): Flow<List<Problem>>
|
fun getAllProblems(): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE id = :id")
|
@Query("SELECT * FROM problems WHERE id = :id") suspend fun getProblemById(id: String): Problem?
|
||||||
suspend fun getProblemById(id: String): Problem?
|
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE gymId = :gymId ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE gymId = :gymId ORDER BY updatedAt DESC")
|
||||||
fun getProblemsByGym(gymId: String): Flow<List<Problem>>
|
fun getProblemsByGym(gymId: String): Flow<List<Problem>>
|
||||||
@@ -20,7 +19,9 @@ interface ProblemDao {
|
|||||||
@Query("SELECT * FROM problems WHERE climbType = :climbType ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE climbType = :climbType ORDER BY updatedAt DESC")
|
||||||
fun getProblemsByClimbType(climbType: ClimbType): Flow<List<Problem>>
|
fun getProblemsByClimbType(climbType: ClimbType): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE gymId = :gymId AND climbType = :climbType ORDER BY updatedAt DESC")
|
@Query(
|
||||||
|
"SELECT * FROM problems WHERE gymId = :gymId AND climbType = :climbType ORDER BY updatedAt DESC"
|
||||||
|
)
|
||||||
fun getProblemsByGymAndType(gymId: String, climbType: ClimbType): Flow<List<Problem>>
|
fun getProblemsByGymAndType(gymId: String, climbType: ClimbType): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT * FROM problems WHERE isActive = 1 ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE isActive = 1 ORDER BY updatedAt DESC")
|
||||||
@@ -29,20 +30,16 @@ interface ProblemDao {
|
|||||||
@Query("SELECT * FROM problems WHERE gymId = :gymId AND isActive = 1 ORDER BY updatedAt DESC")
|
@Query("SELECT * FROM problems WHERE gymId = :gymId AND isActive = 1 ORDER BY updatedAt DESC")
|
||||||
fun getActiveProblemsByGym(gymId: String): Flow<List<Problem>>
|
fun getActiveProblemsByGym(gymId: String): Flow<List<Problem>>
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertProblem(problem: Problem)
|
||||||
suspend fun insertProblem(problem: Problem)
|
|
||||||
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||||
suspend fun insertProblems(problems: List<Problem>)
|
suspend fun insertProblems(problems: List<Problem>)
|
||||||
|
|
||||||
@Update
|
@Update suspend fun updateProblem(problem: Problem)
|
||||||
suspend fun updateProblem(problem: Problem)
|
|
||||||
|
|
||||||
@Delete
|
@Delete suspend fun deleteProblem(problem: Problem)
|
||||||
suspend fun deleteProblem(problem: Problem)
|
|
||||||
|
|
||||||
@Query("DELETE FROM problems WHERE id = :id")
|
@Query("DELETE FROM problems WHERE id = :id") suspend fun deleteProblemById(id: String)
|
||||||
suspend fun deleteProblemById(id: String)
|
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM problems WHERE gymId = :gymId")
|
@Query("SELECT COUNT(*) FROM problems WHERE gymId = :gymId")
|
||||||
suspend fun getProblemsCountByGym(gymId: String): Int
|
suspend fun getProblemsCountByGym(gymId: String): Int
|
||||||
@@ -50,19 +47,18 @@ interface ProblemDao {
|
|||||||
@Query("SELECT COUNT(*) FROM problems WHERE isActive = 1")
|
@Query("SELECT COUNT(*) FROM problems WHERE isActive = 1")
|
||||||
suspend fun getActiveProblemsCount(): Int
|
suspend fun getActiveProblemsCount(): Int
|
||||||
|
|
||||||
@Query("""
|
@Query(
|
||||||
|
"""
|
||||||
SELECT * FROM problems
|
SELECT * FROM problems
|
||||||
WHERE (name LIKE '%' || :searchQuery || '%'
|
WHERE (name LIKE '%' || :searchQuery || '%'
|
||||||
OR description LIKE '%' || :searchQuery || '%'
|
OR description LIKE '%' || :searchQuery || '%'
|
||||||
OR location LIKE '%' || :searchQuery || '%'
|
OR location LIKE '%' || :searchQuery || '%')
|
||||||
OR setter LIKE '%' || :searchQuery || '%')
|
|
||||||
ORDER BY updatedAt DESC
|
ORDER BY updatedAt DESC
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
fun searchProblems(searchQuery: String): Flow<List<Problem>>
|
fun searchProblems(searchQuery: String): Flow<List<Problem>>
|
||||||
|
|
||||||
@Query("SELECT COUNT(*) FROM problems")
|
@Query("SELECT COUNT(*) FROM problems") suspend fun getProblemsCount(): Int
|
||||||
suspend fun getProblemsCount(): Int
|
|
||||||
|
|
||||||
@Query("DELETE FROM problems")
|
@Query("DELETE FROM problems") suspend fun deleteAllProblems()
|
||||||
suspend fun deleteAllProblems()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,31 +4,29 @@ import androidx.room.Entity
|
|||||||
import androidx.room.ForeignKey
|
import androidx.room.ForeignKey
|
||||||
import androidx.room.Index
|
import androidx.room.Index
|
||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
import kotlinx.serialization.Serializable
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@Entity(
|
@Entity(
|
||||||
tableName = "problems",
|
tableName = "problems",
|
||||||
foreignKeys = [
|
foreignKeys =
|
||||||
|
[
|
||||||
ForeignKey(
|
ForeignKey(
|
||||||
entity = Gym::class,
|
entity = Gym::class,
|
||||||
parentColumns = ["id"],
|
parentColumns = ["id"],
|
||||||
childColumns = ["gymId"],
|
childColumns = ["gymId"],
|
||||||
onDelete = ForeignKey.CASCADE
|
onDelete = ForeignKey.CASCADE
|
||||||
)
|
)],
|
||||||
],
|
|
||||||
indices = [Index(value = ["gymId"])]
|
indices = [Index(value = ["gymId"])]
|
||||||
)
|
)
|
||||||
@Serializable
|
@Serializable
|
||||||
data class Problem(
|
data class Problem(
|
||||||
@PrimaryKey
|
@PrimaryKey val id: String,
|
||||||
val id: String,
|
|
||||||
val gymId: String,
|
val gymId: String,
|
||||||
val name: String? = null,
|
val name: String? = null,
|
||||||
val description: String? = null,
|
val description: String? = null,
|
||||||
val climbType: ClimbType,
|
val climbType: ClimbType,
|
||||||
val difficulty: DifficultyGrade,
|
val difficulty: DifficultyGrade,
|
||||||
val setter: String? = null,
|
|
||||||
val tags: List<String> = emptyList(),
|
val tags: List<String> = emptyList(),
|
||||||
val location: String? = null,
|
val location: String? = null,
|
||||||
val imagePaths: List<String> = emptyList(),
|
val imagePaths: List<String> = emptyList(),
|
||||||
@@ -45,7 +43,6 @@ data class Problem(
|
|||||||
description: String? = null,
|
description: String? = null,
|
||||||
climbType: ClimbType,
|
climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade,
|
difficulty: DifficultyGrade,
|
||||||
setter: String? = null,
|
|
||||||
tags: List<String> = emptyList(),
|
tags: List<String> = emptyList(),
|
||||||
location: String? = null,
|
location: String? = null,
|
||||||
imagePaths: List<String> = emptyList(),
|
imagePaths: List<String> = emptyList(),
|
||||||
@@ -60,7 +57,6 @@ data class Problem(
|
|||||||
description = description,
|
description = description,
|
||||||
climbType = climbType,
|
climbType = climbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
setter = setter,
|
|
||||||
tags = tags,
|
tags = tags,
|
||||||
location = location,
|
location = location,
|
||||||
imagePaths = imagePaths,
|
imagePaths = imagePaths,
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class ClimbRepository(database: OpenClimbDatabase, private val context: Context)
|
|||||||
val exportData =
|
val exportData =
|
||||||
ClimbDataExport(
|
ClimbDataExport(
|
||||||
exportedAt = LocalDateTime.now().toString(),
|
exportedAt = LocalDateTime.now().toString(),
|
||||||
version = "1.0",
|
version = "2.0",
|
||||||
gyms = allGyms,
|
gyms = allGyms,
|
||||||
problems = allProblems,
|
problems = allProblems,
|
||||||
sessions = allSessions,
|
sessions = allSessions,
|
||||||
@@ -141,7 +141,7 @@ class ClimbRepository(database: OpenClimbDatabase, private val context: Context)
|
|||||||
val exportData =
|
val exportData =
|
||||||
ClimbDataExport(
|
ClimbDataExport(
|
||||||
exportedAt = LocalDateTime.now().toString(),
|
exportedAt = LocalDateTime.now().toString(),
|
||||||
version = "1.0",
|
version = "2.0",
|
||||||
gyms = allGyms,
|
gyms = allGyms,
|
||||||
problems = allProblems,
|
problems = allProblems,
|
||||||
sessions = allSessions,
|
sessions = allSessions,
|
||||||
@@ -343,7 +343,7 @@ class ClimbRepository(database: OpenClimbDatabase, private val context: Context)
|
|||||||
@kotlinx.serialization.Serializable
|
@kotlinx.serialization.Serializable
|
||||||
data class ClimbDataExport(
|
data class ClimbDataExport(
|
||||||
val exportedAt: String,
|
val exportedAt: String,
|
||||||
val version: String = "1.0",
|
val version: String = "2.0",
|
||||||
val gyms: List<Gym>,
|
val gyms: List<Gym>,
|
||||||
val problems: List<Problem>,
|
val problems: List<Problem>,
|
||||||
val sessions: List<ClimbSession>,
|
val sessions: List<ClimbSession>,
|
||||||
|
|||||||
@@ -12,24 +12,20 @@ import androidx.compose.material3.*
|
|||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.semantics.Role
|
import androidx.compose.ui.semantics.Role
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.openclimb.data.model.*
|
||||||
import com.atridad.openclimb.ui.components.ImagePicker
|
import com.atridad.openclimb.ui.components.ImagePicker
|
||||||
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
||||||
import kotlinx.coroutines.flow.first
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
|
import kotlinx.coroutines.flow.first
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AddEditGymScreen(
|
fun AddEditGymScreen(gymId: String?, viewModel: ClimbViewModel, onNavigateBack: () -> Unit) {
|
||||||
gymId: String?,
|
|
||||||
viewModel: ClimbViewModel,
|
|
||||||
onNavigateBack: () -> Unit
|
|
||||||
) {
|
|
||||||
var name by remember { mutableStateOf("") }
|
var name by remember { mutableStateOf("") }
|
||||||
var location by remember { mutableStateOf("") }
|
var location by remember { mutableStateOf("") }
|
||||||
var notes by remember { mutableStateOf("") }
|
var notes by remember { mutableStateOf("") }
|
||||||
@@ -39,17 +35,19 @@ fun AddEditGymScreen(
|
|||||||
val isEditing = gymId != null
|
val isEditing = gymId != null
|
||||||
|
|
||||||
// Calculate available difficulty systems based on selected climb types
|
// Calculate available difficulty systems based on selected climb types
|
||||||
val availableDifficultySystems = if (selectedClimbTypes.isEmpty()) {
|
val availableDifficultySystems =
|
||||||
|
if (selectedClimbTypes.isEmpty()) {
|
||||||
emptyList()
|
emptyList()
|
||||||
} else {
|
} else {
|
||||||
selectedClimbTypes.flatMap { climbType ->
|
selectedClimbTypes
|
||||||
DifficultySystem.getSystemsForClimbType(climbType)
|
.flatMap { climbType -> DifficultySystem.getSystemsForClimbType(climbType) }
|
||||||
}.distinct()
|
.distinct()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset selected difficulty systems when available systems change
|
// Reset selected difficulty systems when available systems change
|
||||||
LaunchedEffect(availableDifficultySystems) {
|
LaunchedEffect(availableDifficultySystems) {
|
||||||
selectedDifficultySystems = selectedDifficultySystems.filter { it in availableDifficultySystems }.toSet()
|
selectedDifficultySystems =
|
||||||
|
selectedDifficultySystems.filter { it in availableDifficultySystems }.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load existing gym data for editing
|
// Load existing gym data for editing
|
||||||
@@ -72,13 +70,23 @@ fun AddEditGymScreen(
|
|||||||
title = { Text(if (isEditing) "Edit Gym" else "Add Gym") },
|
title = { Text(if (isEditing) "Edit Gym" else "Add Gym") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
val gym = Gym.create(name, location, selectedClimbTypes.toList(), selectedDifficultySystems.toList(), notes = notes)
|
val gym =
|
||||||
|
Gym.create(
|
||||||
|
name,
|
||||||
|
location,
|
||||||
|
selectedClimbTypes.toList(),
|
||||||
|
selectedDifficultySystems.toList(),
|
||||||
|
notes = notes
|
||||||
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateGym(gym.copy(id = gymId!!))
|
viewModel.updateGym(gym.copy(id = gymId!!))
|
||||||
@@ -87,19 +95,17 @@ fun AddEditGymScreen(
|
|||||||
}
|
}
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
},
|
},
|
||||||
enabled = name.isNotBlank() && selectedClimbTypes.isNotEmpty() && selectedDifficultySystems.isNotEmpty()
|
enabled =
|
||||||
) {
|
name.isNotBlank() &&
|
||||||
Text("Save")
|
selectedClimbTypes.isNotEmpty() &&
|
||||||
}
|
selectedDifficultySystems.isNotEmpty()
|
||||||
|
) { Text("Save") }
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize().padding(paddingValues).padding(16.dp),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(paddingValues)
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
// Name field
|
// Name field
|
||||||
@@ -121,12 +127,8 @@ fun AddEditGymScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Climb Types
|
// Climb Types
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Supported Climb Types",
|
text = "Supported Climb Types",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -138,15 +140,20 @@ fun AddEditGymScreen(
|
|||||||
ClimbType.entries.forEach { climbType ->
|
ClimbType.entries.forEach { climbType ->
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier =
|
||||||
.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.selectable(
|
.selectable(
|
||||||
selected = climbType in selectedClimbTypes,
|
selected = climbType in selectedClimbTypes,
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedClimbTypes = if (climbType in selectedClimbTypes) {
|
selectedClimbTypes =
|
||||||
selectedClimbTypes - climbType
|
if (climbType in
|
||||||
|
selectedClimbTypes
|
||||||
|
) {
|
||||||
|
selectedClimbTypes -
|
||||||
|
climbType
|
||||||
} else {
|
} else {
|
||||||
selectedClimbTypes + climbType
|
selectedClimbTypes +
|
||||||
|
climbType
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
role = Role.Checkbox
|
role = Role.Checkbox
|
||||||
@@ -164,12 +171,8 @@ fun AddEditGymScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Difficulty Systems
|
// Difficulty Systems
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Difficulty Systems",
|
text = "Difficulty Systems",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -180,7 +183,8 @@ fun AddEditGymScreen(
|
|||||||
|
|
||||||
if (selectedClimbTypes.isEmpty()) {
|
if (selectedClimbTypes.isEmpty()) {
|
||||||
Text(
|
Text(
|
||||||
text = "Select climb types first to see available difficulty systems",
|
text =
|
||||||
|
"Select climb types first to see available difficulty systems",
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
modifier = Modifier.padding(vertical = 8.dp)
|
modifier = Modifier.padding(vertical = 8.dp)
|
||||||
@@ -189,15 +193,22 @@ fun AddEditGymScreen(
|
|||||||
availableDifficultySystems.forEach { system ->
|
availableDifficultySystems.forEach { system ->
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier =
|
||||||
.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.selectable(
|
.selectable(
|
||||||
selected = system in selectedDifficultySystems,
|
selected =
|
||||||
|
system in
|
||||||
|
selectedDifficultySystems,
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedDifficultySystems = if (system in selectedDifficultySystems) {
|
selectedDifficultySystems =
|
||||||
selectedDifficultySystems - system
|
if (system in
|
||||||
|
selectedDifficultySystems
|
||||||
|
) {
|
||||||
|
selectedDifficultySystems -
|
||||||
|
system
|
||||||
} else {
|
} else {
|
||||||
selectedDifficultySystems + system
|
selectedDifficultySystems +
|
||||||
|
system
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
role = Role.Checkbox
|
role = Role.Checkbox
|
||||||
@@ -239,13 +250,15 @@ fun AddEditProblemScreen(
|
|||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
|
|
||||||
// Problem form state
|
// Problem form state
|
||||||
var selectedGym by remember { mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } }) }
|
var selectedGym by remember {
|
||||||
|
mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } })
|
||||||
|
}
|
||||||
var problemName by remember { mutableStateOf("") }
|
var problemName by remember { mutableStateOf("") }
|
||||||
var description by remember { mutableStateOf("") }
|
var description by remember { mutableStateOf("") }
|
||||||
var selectedClimbType by remember { mutableStateOf(ClimbType.BOULDER) }
|
var selectedClimbType by remember { mutableStateOf(ClimbType.BOULDER) }
|
||||||
var selectedDifficultySystem by remember { mutableStateOf(DifficultySystem.V_SCALE) }
|
var selectedDifficultySystem by remember { mutableStateOf(DifficultySystem.V_SCALE) }
|
||||||
var difficultyGrade by remember { mutableStateOf("") }
|
var difficultyGrade by remember { mutableStateOf("") }
|
||||||
var setter by remember { mutableStateOf("") }
|
|
||||||
var location by remember { mutableStateOf("") }
|
var location by remember { mutableStateOf("") }
|
||||||
var tags by remember { mutableStateOf("") }
|
var tags by remember { mutableStateOf("") }
|
||||||
var notes by remember { mutableStateOf("") }
|
var notes by remember { mutableStateOf("") }
|
||||||
@@ -262,7 +275,7 @@ fun AddEditProblemScreen(
|
|||||||
selectedClimbType = p.climbType
|
selectedClimbType = p.climbType
|
||||||
selectedDifficultySystem = p.difficulty.system
|
selectedDifficultySystem = p.difficulty.system
|
||||||
difficultyGrade = p.difficulty.grade
|
difficultyGrade = p.difficulty.grade
|
||||||
setter = p.setter ?: ""
|
|
||||||
location = p.location ?: ""
|
location = p.location ?: ""
|
||||||
tags = p.tags.joinToString(", ")
|
tags = p.tags.joinToString(", ")
|
||||||
notes = p.notes ?: ""
|
notes = p.notes ?: ""
|
||||||
@@ -280,7 +293,8 @@ fun AddEditProblemScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val availableClimbTypes = selectedGym?.supportedClimbTypes ?: ClimbType.entries.toList()
|
val availableClimbTypes = selectedGym?.supportedClimbTypes ?: ClimbType.entries.toList()
|
||||||
val availableDifficultySystems = DifficultySystem.getSystemsForClimbType(selectedClimbType).filter { system ->
|
val availableDifficultySystems =
|
||||||
|
DifficultySystem.getSystemsForClimbType(selectedClimbType).filter { system ->
|
||||||
selectedGym?.difficultySystems?.contains(system) != false
|
selectedGym?.difficultySystems?.contains(system) != false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,10 +310,12 @@ fun AddEditProblemScreen(
|
|||||||
when {
|
when {
|
||||||
// If current system is not compatible, select the first available one
|
// If current system is not compatible, select the first available one
|
||||||
selectedDifficultySystem !in availableDifficultySystems -> {
|
selectedDifficultySystem !in availableDifficultySystems -> {
|
||||||
selectedDifficultySystem = availableDifficultySystems.firstOrNull() ?: DifficultySystem.CUSTOM
|
selectedDifficultySystem =
|
||||||
|
availableDifficultySystems.firstOrNull() ?: DifficultySystem.CUSTOM
|
||||||
}
|
}
|
||||||
// If there's only one available system and nothing is selected, auto-select it
|
// If there's only one available system and nothing is selected, auto-select it
|
||||||
availableDifficultySystems.size == 1 && selectedDifficultySystem != availableDifficultySystems.first() -> {
|
availableDifficultySystems.size == 1 &&
|
||||||
|
selectedDifficultySystem != availableDifficultySystems.first() -> {
|
||||||
selectedDifficultySystem = availableDifficultySystems.first()
|
selectedDifficultySystem = availableDifficultySystems.first()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,37 +335,60 @@ fun AddEditProblemScreen(
|
|||||||
title = { Text(if (isEditing) "Edit Problem" else "Add Problem") },
|
title = { Text(if (isEditing) "Edit Problem" else "Add Problem") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = {
|
onClick = {
|
||||||
selectedGym?.let { gym ->
|
selectedGym?.let { gym ->
|
||||||
val difficulty = DifficultyGrade(
|
val difficulty =
|
||||||
|
DifficultyGrade(
|
||||||
system = selectedDifficultySystem,
|
system = selectedDifficultySystem,
|
||||||
grade = difficultyGrade,
|
grade = difficultyGrade,
|
||||||
numericValue = when (selectedDifficultySystem) {
|
numericValue =
|
||||||
DifficultySystem.V_SCALE -> difficultyGrade.removePrefix("V").toIntOrNull() ?: 0
|
when (selectedDifficultySystem
|
||||||
else -> difficultyGrade.hashCode() % 100 // Simple mapping for other systems
|
) {
|
||||||
|
DifficultySystem.V_SCALE ->
|
||||||
|
difficultyGrade
|
||||||
|
.removePrefix(
|
||||||
|
"V"
|
||||||
|
)
|
||||||
|
.toIntOrNull()
|
||||||
|
?: 0
|
||||||
|
else ->
|
||||||
|
difficultyGrade
|
||||||
|
.hashCode() %
|
||||||
|
100 // Simple mapping for other systems
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
val problem = Problem.create(
|
val problem =
|
||||||
|
Problem.create(
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
name = problemName.ifBlank { null },
|
name = problemName.ifBlank { null },
|
||||||
description = description.ifBlank { null },
|
description =
|
||||||
|
description.ifBlank { null },
|
||||||
climbType = selectedClimbType,
|
climbType = selectedClimbType,
|
||||||
difficulty = difficulty,
|
difficulty = difficulty,
|
||||||
setter = setter.ifBlank { null },
|
tags =
|
||||||
tags = tags.split(",").map { it.trim() }.filter { it.isNotBlank() },
|
tags.split(",")
|
||||||
|
.map { it.trim() }
|
||||||
|
.filter {
|
||||||
|
it.isNotBlank()
|
||||||
|
},
|
||||||
location = location.ifBlank { null },
|
location = location.ifBlank { null },
|
||||||
imagePaths = imagePaths,
|
imagePaths = imagePaths,
|
||||||
notes = notes.ifBlank { null }
|
notes = notes.ifBlank { null }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
viewModel.updateProblem(problem.copy(id = problemId!!))
|
viewModel.updateProblem(
|
||||||
|
problem.copy(id = problemId!!)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
viewModel.addProblem(problem)
|
viewModel.addProblem(problem)
|
||||||
}
|
}
|
||||||
@@ -357,28 +396,19 @@ fun AddEditProblemScreen(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = selectedGym != null && difficultyGrade.isNotBlank()
|
enabled = selectedGym != null && difficultyGrade.isNotBlank()
|
||||||
) {
|
) { Text("Save") }
|
||||||
Text("Save")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize().padding(paddingValues).padding(16.dp),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(paddingValues)
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
// Gym Selection
|
// Gym Selection
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Select Gym",
|
text = "Select Gym",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -394,9 +424,7 @@ fun AddEditProblemScreen(
|
|||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LazyRow(
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
items(gyms) { gym ->
|
items(gyms) { gym ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedGym = gym },
|
onClick = { selectedGym = gym },
|
||||||
@@ -412,12 +440,8 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
// Basic Problem Info
|
// Basic Problem Info
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Problem Details",
|
text = "Problem Details",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -448,14 +472,6 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
OutlinedTextField(
|
|
||||||
value = setter,
|
|
||||||
onValueChange = { setter = it },
|
|
||||||
label = { Text("Route Setter (Optional)") },
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
singleLine = true
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
@@ -473,12 +489,8 @@ fun AddEditProblemScreen(
|
|||||||
// Climb Type
|
// Climb Type
|
||||||
if (selectedGym != null) {
|
if (selectedGym != null) {
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Climb Type",
|
text = "Climb Type",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -487,9 +499,7 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Row(
|
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
availableClimbTypes.forEach { climbType ->
|
availableClimbTypes.forEach { climbType ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = climbType },
|
onClick = { selectedClimbType = climbType },
|
||||||
@@ -506,12 +516,8 @@ fun AddEditProblemScreen(
|
|||||||
// Difficulty
|
// Difficulty
|
||||||
if (selectedGym != null) {
|
if (selectedGym != null) {
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Difficulty",
|
text = "Difficulty",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -526,9 +532,7 @@ fun AddEditProblemScreen(
|
|||||||
fontWeight = FontWeight.Medium
|
fontWeight = FontWeight.Medium
|
||||||
)
|
)
|
||||||
|
|
||||||
LazyRow(
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
items(availableDifficultySystems) { system ->
|
items(availableDifficultySystems) { system ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedDifficultySystem = system },
|
onClick = { selectedDifficultySystem = system },
|
||||||
@@ -545,16 +549,22 @@ fun AddEditProblemScreen(
|
|||||||
value = difficultyGrade,
|
value = difficultyGrade,
|
||||||
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() }
|
||||||
|
) {
|
||||||
difficultyGrade = newValue
|
difficultyGrade = newValue
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
label = { Text("Grade *") },
|
label = { Text("Grade *") },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
placeholder = { Text("Enter numeric grade (e.g. 5, 10, 15)") },
|
placeholder = {
|
||||||
supportingText = { Text("Custom grades must be whole numbers") },
|
Text("Enter numeric grade (e.g. 5, 10, 15)")
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
|
},
|
||||||
|
supportingText = {
|
||||||
|
Text("Custom grades must be whole numbers")
|
||||||
|
},
|
||||||
|
keyboardOptions =
|
||||||
|
KeyboardOptions(keyboardType = KeyboardType.Number)
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
@@ -567,13 +577,24 @@ fun AddEditProblemScreen(
|
|||||||
) {
|
) {
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = difficultyGrade,
|
value = difficultyGrade,
|
||||||
onValueChange = { },
|
onValueChange = {},
|
||||||
readOnly = true,
|
readOnly = true,
|
||||||
label = { Text("Grade *") },
|
label = { Text("Grade *") },
|
||||||
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(expanded = expanded) },
|
trailingIcon = {
|
||||||
colors = ExposedDropdownMenuDefaults.outlinedTextFieldColors(),
|
ExposedDropdownMenuDefaults.TrailingIcon(
|
||||||
modifier = Modifier
|
expanded = expanded
|
||||||
.menuAnchor(androidx.compose.material3.MenuAnchorType.PrimaryNotEditable, enabled = true)
|
)
|
||||||
|
},
|
||||||
|
colors =
|
||||||
|
ExposedDropdownMenuDefaults
|
||||||
|
.outlinedTextFieldColors(),
|
||||||
|
modifier =
|
||||||
|
Modifier.menuAnchor(
|
||||||
|
androidx.compose.material3
|
||||||
|
.MenuAnchorType
|
||||||
|
.PrimaryNotEditable,
|
||||||
|
enabled = true
|
||||||
|
)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
)
|
)
|
||||||
ExposedDropdownMenu(
|
ExposedDropdownMenu(
|
||||||
@@ -599,12 +620,8 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
// Images Section
|
// Images Section
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Photos",
|
text = "Photos",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -623,12 +640,8 @@ fun AddEditProblemScreen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Additional Info",
|
text = "Additional Info",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -661,18 +674,15 @@ fun AddEditProblemScreen(
|
|||||||
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
modifier = Modifier
|
modifier =
|
||||||
.fillMaxWidth()
|
Modifier.fillMaxWidth()
|
||||||
.selectable(
|
.selectable(
|
||||||
selected = isActive,
|
selected = isActive,
|
||||||
onClick = { isActive = !isActive },
|
onClick = { isActive = !isActive },
|
||||||
role = Role.Checkbox
|
role = Role.Checkbox
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
Checkbox(
|
Checkbox(checked = isActive, onCheckedChange = null)
|
||||||
checked = isActive,
|
|
||||||
onCheckedChange = null
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Problem is currently active",
|
text = "Problem is currently active",
|
||||||
@@ -699,7 +709,9 @@ fun AddEditSessionScreen(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
// Session form state
|
// Session form state
|
||||||
var selectedGym by remember { mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } }) }
|
var selectedGym by remember {
|
||||||
|
mutableStateOf<Gym?>(gymId?.let { id -> gyms.find { it.id == id } })
|
||||||
|
}
|
||||||
var sessionDate by remember { mutableStateOf(LocalDateTime.now().toLocalDate().toString()) }
|
var sessionDate by remember { mutableStateOf(LocalDateTime.now().toLocalDate().toString()) }
|
||||||
var duration by remember { mutableStateOf("") }
|
var duration by remember { mutableStateOf("") }
|
||||||
var sessionNotes by remember { mutableStateOf("") }
|
var sessionNotes by remember { mutableStateOf("") }
|
||||||
@@ -729,7 +741,10 @@ fun AddEditSessionScreen(
|
|||||||
title = { Text(if (isEditing) "Edit Session" else "Add Session") },
|
title = { Text(if (isEditing) "Edit Session" else "Add Session") },
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = onNavigateBack) {
|
IconButton(onClick = onNavigateBack) {
|
||||||
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
|
Icon(
|
||||||
|
Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
@@ -737,40 +752,41 @@ fun AddEditSessionScreen(
|
|||||||
onClick = {
|
onClick = {
|
||||||
selectedGym?.let { gym ->
|
selectedGym?.let { gym ->
|
||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
val session = ClimbSession.create(
|
val session =
|
||||||
|
ClimbSession.create(
|
||||||
gymId = gym.id,
|
gymId = gym.id,
|
||||||
notes = sessionNotes.ifBlank { null }
|
notes =
|
||||||
|
sessionNotes.ifBlank {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
)
|
||||||
|
viewModel.updateSession(
|
||||||
|
session.copy(id = sessionId!!)
|
||||||
)
|
)
|
||||||
viewModel.updateSession(session.copy(id = sessionId!!))
|
|
||||||
} else {
|
} else {
|
||||||
viewModel.startSession(context, gym.id, sessionNotes.ifBlank { null })
|
viewModel.startSession(
|
||||||
|
context,
|
||||||
|
gym.id,
|
||||||
|
sessionNotes.ifBlank { null }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
onNavigateBack()
|
onNavigateBack()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
enabled = selectedGym != null
|
enabled = selectedGym != null
|
||||||
) {
|
) { Text("Save") }
|
||||||
Text("Save")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxSize().padding(paddingValues).padding(16.dp),
|
||||||
.fillMaxSize()
|
|
||||||
.padding(paddingValues)
|
|
||||||
.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(16.dp)
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
// Gym Selection
|
// Gym Selection
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Select Gym",
|
text = "Select Gym",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -786,9 +802,7 @@ fun AddEditSessionScreen(
|
|||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.error
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LazyRow(
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
items(gyms) { gym ->
|
items(gyms) { gym ->
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedGym = gym },
|
onClick = { selectedGym = gym },
|
||||||
@@ -804,12 +818,8 @@ fun AddEditSessionScreen(
|
|||||||
|
|
||||||
// Session Details
|
// Session Details
|
||||||
item {
|
item {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Session Details",
|
text = "Session Details",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -834,7 +844,8 @@ fun AddEditSessionScreen(
|
|||||||
label = { Text("Duration (minutes)") },
|
label = { Text("Duration (minutes)") },
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number)
|
keyboardOptions =
|
||||||
|
KeyboardOptions(keyboardType = KeyboardType.Number)
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -852,6 +863,3 @@ fun AddEditSessionScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -693,15 +693,6 @@ fun ProblemDetailScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
problem?.setter?.let { setter ->
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
Text(
|
|
||||||
text = "Set by: $setter",
|
|
||||||
style = MaterialTheme.typography.bodySmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (problem?.tags?.isNotEmpty() == true) {
|
if (problem?.tags?.isNotEmpty() == true) {
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
|
|||||||
@@ -21,10 +21,7 @@ import com.atridad.openclimb.ui.viewmodel.ClimbViewModel
|
|||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ProblemsScreen(
|
fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String) -> Unit) {
|
||||||
viewModel: ClimbViewModel,
|
|
||||||
onNavigateToProblemDetail: (String) -> Unit
|
|
||||||
) {
|
|
||||||
val problems by viewModel.problems.collectAsState()
|
val problems by viewModel.problems.collectAsState()
|
||||||
val gyms by viewModel.gyms.collectAsState()
|
val gyms by viewModel.gyms.collectAsState()
|
||||||
var showImageViewer by remember { mutableStateOf(false) }
|
var showImageViewer by remember { mutableStateOf(false) }
|
||||||
@@ -36,17 +33,19 @@ fun ProblemsScreen(
|
|||||||
var selectedGym by remember { mutableStateOf<Gym?>(null) }
|
var selectedGym by remember { mutableStateOf<Gym?>(null) }
|
||||||
|
|
||||||
// Apply filters
|
// Apply filters
|
||||||
val filteredProblems = problems.filter { problem ->
|
val filteredProblems =
|
||||||
|
problems.filter { problem ->
|
||||||
val climbTypeMatch = selectedClimbType?.let { it == problem.climbType } != false
|
val climbTypeMatch = selectedClimbType?.let { it == problem.climbType } != false
|
||||||
val gymMatch = selectedGym?.let { it.id == problem.gymId } != false
|
val gymMatch = selectedGym?.let { it.id == problem.gymId } != false
|
||||||
climbTypeMatch && gymMatch
|
climbTypeMatch && gymMatch
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
// Separate active and inactive problems
|
||||||
modifier = Modifier
|
val activeProblems = filteredProblems.filter { it.isActive }
|
||||||
.fillMaxSize()
|
val inactiveProblems = filteredProblems.filter { !it.isActive }
|
||||||
.padding(16.dp)
|
val sortedProblems = activeProblems + inactiveProblems
|
||||||
) {
|
|
||||||
|
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
@@ -69,12 +68,8 @@ fun ProblemsScreen(
|
|||||||
|
|
||||||
// Filters Section
|
// Filters Section
|
||||||
if (problems.isNotEmpty()) {
|
if (problems.isNotEmpty()) {
|
||||||
Card(
|
Card(modifier = Modifier.fillMaxWidth()) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
Column(modifier = Modifier.padding(16.dp)) {
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "Filters",
|
text = "Filters",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
@@ -92,9 +87,7 @@ fun ProblemsScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
LazyRow(
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
item {
|
item {
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedClimbType = null },
|
onClick = { selectedClimbType = null },
|
||||||
@@ -122,9 +115,7 @@ fun ProblemsScreen(
|
|||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
LazyRow(
|
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
item {
|
item {
|
||||||
FilterChip(
|
FilterChip(
|
||||||
onClick = { selectedGym = null },
|
onClick = { selectedGym = null },
|
||||||
@@ -145,7 +136,8 @@ fun ProblemsScreen(
|
|||||||
if (selectedClimbType != null || selectedGym != null) {
|
if (selectedClimbType != null || selectedGym != null) {
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Showing ${filteredProblems.size} of ${problems.size} problems",
|
text =
|
||||||
|
"Showing ${filteredProblems.size} of ${problems.size} problems (${activeProblems.size} active, ${inactiveProblems.size} reset)",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color = MaterialTheme.colorScheme.onSurfaceVariant
|
||||||
)
|
)
|
||||||
@@ -158,22 +150,26 @@ fun ProblemsScreen(
|
|||||||
|
|
||||||
if (filteredProblems.isEmpty()) {
|
if (filteredProblems.isEmpty()) {
|
||||||
EmptyStateMessage(
|
EmptyStateMessage(
|
||||||
title = if (problems.isEmpty()) {
|
title =
|
||||||
|
if (problems.isEmpty()) {
|
||||||
if (gyms.isEmpty()) "No Gyms Available" else "No Problems Yet"
|
if (gyms.isEmpty()) "No Gyms Available" else "No Problems Yet"
|
||||||
} else {
|
} else {
|
||||||
"No Problems Match Filters"
|
"No Problems Match Filters"
|
||||||
},
|
},
|
||||||
message = if (problems.isEmpty()) {
|
message =
|
||||||
if (gyms.isEmpty()) "Add a gym first to start tracking problems and routes!" else "Start tracking your favorite problems and routes!"
|
if (problems.isEmpty()) {
|
||||||
|
if (gyms.isEmpty())
|
||||||
|
"Add a gym first to start tracking problems and routes!"
|
||||||
|
else "Start tracking your favorite problems and routes!"
|
||||||
} else {
|
} else {
|
||||||
"Try adjusting your filters to see more problems."
|
"Try adjusting your filters to see more problems."
|
||||||
},
|
},
|
||||||
onActionClick = { },
|
onActionClick = {},
|
||||||
actionText = ""
|
actionText = ""
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
items(filteredProblems) { problem ->
|
items(sortedProblems) { problem ->
|
||||||
ProblemCard(
|
ProblemCard(
|
||||||
problem = problem,
|
problem = problem,
|
||||||
gymName = gyms.find { it.id == problem.gymId }?.name ?: "Unknown Gym",
|
gymName = gyms.find { it.id == problem.gymId }?.name ?: "Unknown Gym",
|
||||||
@@ -182,6 +178,10 @@ fun ProblemsScreen(
|
|||||||
selectedImagePaths = imagePaths
|
selectedImagePaths = imagePaths
|
||||||
selectedImageIndex = index
|
selectedImageIndex = index
|
||||||
showImageViewer = true
|
showImageViewer = true
|
||||||
|
},
|
||||||
|
onToggleActive = {
|
||||||
|
val updatedProblem = problem.copy(isActive = !problem.isActive)
|
||||||
|
viewModel.updateProblem(updatedProblem)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
@@ -206,17 +206,11 @@ fun ProblemCard(
|
|||||||
problem: Problem,
|
problem: Problem,
|
||||||
gymName: String,
|
gymName: String,
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onImageClick: ((List<String>, Int) -> Unit)? = null
|
onImageClick: ((List<String>, Int) -> Unit)? = null,
|
||||||
|
onToggleActive: (() -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
Card(
|
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
||||||
onClick = onClick,
|
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
@@ -226,13 +220,19 @@ fun ProblemCard(
|
|||||||
Text(
|
Text(
|
||||||
text = problem.name ?: "Unnamed Problem",
|
text = problem.name ?: "Unnamed Problem",
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold,
|
||||||
|
color =
|
||||||
|
if (problem.isActive) MaterialTheme.colorScheme.onSurface
|
||||||
|
else MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = gymName,
|
text = gymName,
|
||||||
style = MaterialTheme.typography.bodyMedium,
|
style = MaterialTheme.typography.bodyMedium,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant
|
color =
|
||||||
|
MaterialTheme.colorScheme.onSurfaceVariant.copy(
|
||||||
|
alpha = if (problem.isActive) 1f else 0.6f
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,7 +266,7 @@ fun ProblemCard(
|
|||||||
Row {
|
Row {
|
||||||
problem.tags.take(3).forEach { tag ->
|
problem.tags.take(3).forEach { tag ->
|
||||||
AssistChip(
|
AssistChip(
|
||||||
onClick = { },
|
onClick = {},
|
||||||
label = { Text(tag) },
|
label = { Text(tag) },
|
||||||
modifier = Modifier.padding(end = 4.dp)
|
modifier = Modifier.padding(end = 4.dp)
|
||||||
)
|
)
|
||||||
@@ -280,20 +280,40 @@ fun ProblemCard(
|
|||||||
ImageDisplay(
|
ImageDisplay(
|
||||||
imagePaths = problem.imagePaths.take(3), // Show max 3 images in list
|
imagePaths = problem.imagePaths.take(3), // Show max 3 images in list
|
||||||
imageSize = 60,
|
imageSize = 60,
|
||||||
onImageClick = { index ->
|
onImageClick = { index -> onImageClick?.invoke(problem.imagePaths, index) }
|
||||||
onImageClick?.invoke(problem.imagePaths, index)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!problem.isActive) {
|
if (!problem.isActive) {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "Inactive",
|
text = "Reset / No Longer Set",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.error
|
color = MaterialTheme.colorScheme.tertiary,
|
||||||
|
fontWeight = FontWeight.Medium
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Toggle active button
|
||||||
|
if (onToggleActive != null) {
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
OutlinedButton(
|
||||||
|
onClick = onToggleActive,
|
||||||
|
colors =
|
||||||
|
ButtonDefaults.outlinedButtonColors(
|
||||||
|
contentColor =
|
||||||
|
if (problem.isActive)
|
||||||
|
MaterialTheme.colorScheme.tertiary
|
||||||
|
else MaterialTheme.colorScheme.primary
|
||||||
|
),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = if (problem.isActive) "Mark as Reset" else "Mark as Active",
|
||||||
|
style = MaterialTheme.typography.bodySmall
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@ import android.content.Intent
|
|||||||
import android.graphics.*
|
import android.graphics.*
|
||||||
import android.graphics.drawable.GradientDrawable
|
import android.graphics.drawable.GradientDrawable
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.core.graphics.createBitmap
|
||||||
|
import androidx.core.graphics.toColorInt
|
||||||
import com.atridad.openclimb.data.model.*
|
import com.atridad.openclimb.data.model.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
import androidx.core.graphics.createBitmap
|
|
||||||
import androidx.core.graphics.toColorInt
|
|
||||||
|
|
||||||
object SessionShareUtils {
|
object SessionShareUtils {
|
||||||
|
|
||||||
@@ -33,10 +33,7 @@ object SessionShareUtils {
|
|||||||
attempts: List<Attempt>,
|
attempts: List<Attempt>,
|
||||||
problems: List<Problem>
|
problems: List<Problem>
|
||||||
): SessionStats {
|
): SessionStats {
|
||||||
val successfulResults = listOf(
|
val successfulResults = listOf(AttemptResult.SUCCESS, AttemptResult.FLASH)
|
||||||
AttemptResult.SUCCESS,
|
|
||||||
AttemptResult.FLASH
|
|
||||||
)
|
|
||||||
|
|
||||||
val successfulAttempts = attempts.filter { it.result in successfulResults }
|
val successfulAttempts = attempts.filter { it.result in successfulResults }
|
||||||
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
||||||
@@ -52,8 +49,10 @@ object SessionShareUtils {
|
|||||||
val ropeAverage = calculateAverageGrade(ropeProblems, "Rope")
|
val ropeAverage = calculateAverageGrade(ropeProblems, "Rope")
|
||||||
|
|
||||||
// Combine averages for display
|
// Combine averages for display
|
||||||
val averageGrade = when {
|
val averageGrade =
|
||||||
boulderAverage != null && ropeAverage != null -> "$boulderAverage / $ropeAverage"
|
when {
|
||||||
|
boulderAverage != null && ropeAverage != null ->
|
||||||
|
"$boulderAverage / $ropeAverage"
|
||||||
boulderAverage != null -> boulderAverage
|
boulderAverage != null -> boulderAverage
|
||||||
ropeAverage != null -> ropeAverage
|
ropeAverage != null -> ropeAverage
|
||||||
else -> null
|
else -> null
|
||||||
@@ -65,7 +64,8 @@ object SessionShareUtils {
|
|||||||
val completedRope = completedProblems.filter { it.climbType == ClimbType.ROPE }
|
val completedRope = completedProblems.filter { it.climbType == ClimbType.ROPE }
|
||||||
val topBoulder = highestGradeForProblems(completedBoulder)
|
val topBoulder = highestGradeForProblems(completedBoulder)
|
||||||
val topRope = highestGradeForProblems(completedRope)
|
val topRope = highestGradeForProblems(completedRope)
|
||||||
val topGrade = when {
|
val topGrade =
|
||||||
|
when {
|
||||||
topBoulder != null && topRope != null -> "$topBoulder / $topRope"
|
topBoulder != null && topRope != null -> "$topBoulder / $topRope"
|
||||||
topBoulder != null -> topBoulder
|
topBoulder != null -> topBoulder
|
||||||
topRope != null -> topRope
|
topRope != null -> topRope
|
||||||
@@ -73,14 +73,17 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val duration = if (session.duration != null) "${session.duration}m" else "Unknown"
|
val duration = if (session.duration != null) "${session.duration}m" else "Unknown"
|
||||||
val topResult = attempts.maxByOrNull {
|
val topResult =
|
||||||
|
attempts
|
||||||
|
.maxByOrNull {
|
||||||
when (it.result) {
|
when (it.result) {
|
||||||
AttemptResult.FLASH -> 3
|
AttemptResult.FLASH -> 3
|
||||||
AttemptResult.SUCCESS -> 2
|
AttemptResult.SUCCESS -> 2
|
||||||
AttemptResult.FALL -> 1
|
AttemptResult.FALL -> 1
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
}?.result
|
}
|
||||||
|
?.result
|
||||||
|
|
||||||
return SessionStats(
|
return SessionStats(
|
||||||
totalAttempts = attempts.size,
|
totalAttempts = attempts.size,
|
||||||
@@ -109,7 +112,8 @@ object SessionShareUtils {
|
|||||||
problemsBySystem.forEach { (system, systemProblems) ->
|
problemsBySystem.forEach { (system, systemProblems) ->
|
||||||
when (system) {
|
when (system) {
|
||||||
DifficultySystem.V_SCALE -> {
|
DifficultySystem.V_SCALE -> {
|
||||||
val gradeValues = systemProblems.mapNotNull { problem ->
|
val gradeValues =
|
||||||
|
systemProblems.mapNotNull { problem ->
|
||||||
when {
|
when {
|
||||||
problem.difficulty.grade == "VB" -> 0
|
problem.difficulty.grade == "VB" -> 0
|
||||||
else -> problem.difficulty.grade.removePrefix("V").toIntOrNull()
|
else -> problem.difficulty.grade.removePrefix("V").toIntOrNull()
|
||||||
@@ -121,8 +125,10 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DifficultySystem.FONT -> {
|
DifficultySystem.FONT -> {
|
||||||
val gradeValues = systemProblems.mapNotNull { problem ->
|
val gradeValues =
|
||||||
// Extract numeric part from Font grades (e.g., "6A" -> 6, "7C+" -> 7)
|
systemProblems.mapNotNull { problem ->
|
||||||
|
// Extract numeric part from Font grades (e.g., "6A" -> 6, "7C+" ->
|
||||||
|
// 7)
|
||||||
problem.difficulty.grade.filter { it.isDigit() }.toIntOrNull()
|
problem.difficulty.grade.filter { it.isDigit() }.toIntOrNull()
|
||||||
}
|
}
|
||||||
if (gradeValues.isNotEmpty()) {
|
if (gradeValues.isNotEmpty()) {
|
||||||
@@ -131,7 +137,8 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DifficultySystem.YDS -> {
|
DifficultySystem.YDS -> {
|
||||||
val gradeValues = systemProblems.mapNotNull { problem ->
|
val gradeValues =
|
||||||
|
systemProblems.mapNotNull { problem ->
|
||||||
// Extract numeric part from YDS grades (e.g., "5.10a" -> 5.10)
|
// Extract numeric part from YDS grades (e.g., "5.10a" -> 5.10)
|
||||||
val grade = problem.difficulty.grade
|
val grade = problem.difficulty.grade
|
||||||
if (grade.startsWith("5.")) {
|
if (grade.startsWith("5.")) {
|
||||||
@@ -145,8 +152,12 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
DifficultySystem.CUSTOM -> {
|
DifficultySystem.CUSTOM -> {
|
||||||
// For custom systems, try to extract numeric values
|
// For custom systems, try to extract numeric values
|
||||||
val gradeValues = systemProblems.mapNotNull { problem ->
|
val gradeValues =
|
||||||
problem.difficulty.grade.filter { it.isDigit() || it == '.' || it == '-' }.toDoubleOrNull()
|
systemProblems.mapNotNull { problem ->
|
||||||
|
problem.difficulty
|
||||||
|
.grade
|
||||||
|
.filter { it.isDigit() || it == '.' || it == '-' }
|
||||||
|
.toDoubleOrNull()
|
||||||
}
|
}
|
||||||
if (gradeValues.isNotEmpty()) {
|
if (gradeValues.isNotEmpty()) {
|
||||||
val avg = gradeValues.average()
|
val avg = gradeValues.average()
|
||||||
@@ -178,18 +189,17 @@ object SessionShareUtils {
|
|||||||
val bitmap = createBitmap(width, height)
|
val bitmap = createBitmap(width, height)
|
||||||
val canvas = Canvas(bitmap)
|
val canvas = Canvas(bitmap)
|
||||||
|
|
||||||
val gradientDrawable = GradientDrawable(
|
val gradientDrawable =
|
||||||
|
GradientDrawable(
|
||||||
GradientDrawable.Orientation.TOP_BOTTOM,
|
GradientDrawable.Orientation.TOP_BOTTOM,
|
||||||
intArrayOf(
|
intArrayOf("#667eea".toColorInt(), "#764ba2".toColorInt())
|
||||||
"#667eea".toColorInt(),
|
|
||||||
"#764ba2".toColorInt()
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
gradientDrawable.setBounds(0, 0, width, height)
|
gradientDrawable.setBounds(0, 0, width, height)
|
||||||
gradientDrawable.draw(canvas)
|
gradientDrawable.draw(canvas)
|
||||||
|
|
||||||
// Setup paint objects
|
// Setup paint objects
|
||||||
val titlePaint = Paint().apply {
|
val titlePaint =
|
||||||
|
Paint().apply {
|
||||||
color = Color.WHITE
|
color = Color.WHITE
|
||||||
textSize = 72f
|
textSize = 72f
|
||||||
typeface = Typeface.DEFAULT_BOLD
|
typeface = Typeface.DEFAULT_BOLD
|
||||||
@@ -197,7 +207,8 @@ object SessionShareUtils {
|
|||||||
textAlign = Paint.Align.CENTER
|
textAlign = Paint.Align.CENTER
|
||||||
}
|
}
|
||||||
|
|
||||||
val subtitlePaint = Paint().apply {
|
val subtitlePaint =
|
||||||
|
Paint().apply {
|
||||||
color = "#E8E8E8".toColorInt()
|
color = "#E8E8E8".toColorInt()
|
||||||
textSize = 48f
|
textSize = 48f
|
||||||
typeface = Typeface.DEFAULT
|
typeface = Typeface.DEFAULT
|
||||||
@@ -205,7 +216,8 @@ object SessionShareUtils {
|
|||||||
textAlign = Paint.Align.CENTER
|
textAlign = Paint.Align.CENTER
|
||||||
}
|
}
|
||||||
|
|
||||||
val statLabelPaint = Paint().apply {
|
val statLabelPaint =
|
||||||
|
Paint().apply {
|
||||||
color = "#B8B8B8".toColorInt()
|
color = "#B8B8B8".toColorInt()
|
||||||
textSize = 36f
|
textSize = 36f
|
||||||
typeface = Typeface.DEFAULT
|
typeface = Typeface.DEFAULT
|
||||||
@@ -213,7 +225,8 @@ object SessionShareUtils {
|
|||||||
textAlign = Paint.Align.CENTER
|
textAlign = Paint.Align.CENTER
|
||||||
}
|
}
|
||||||
|
|
||||||
val statValuePaint = Paint().apply {
|
val statValuePaint =
|
||||||
|
Paint().apply {
|
||||||
color = Color.WHITE
|
color = Color.WHITE
|
||||||
textSize = 64f
|
textSize = 64f
|
||||||
typeface = Typeface.DEFAULT_BOLD
|
typeface = Typeface.DEFAULT_BOLD
|
||||||
@@ -221,7 +234,8 @@ object SessionShareUtils {
|
|||||||
textAlign = Paint.Align.CENTER
|
textAlign = Paint.Align.CENTER
|
||||||
}
|
}
|
||||||
|
|
||||||
val cardPaint = Paint().apply {
|
val cardPaint =
|
||||||
|
Paint().apply {
|
||||||
color = "#40FFFFFF".toColorInt()
|
color = "#40FFFFFF".toColorInt()
|
||||||
isAntiAlias = true
|
isAntiAlias = true
|
||||||
}
|
}
|
||||||
@@ -252,43 +266,116 @@ object SessionShareUtils {
|
|||||||
|
|
||||||
// Left column stats
|
// Left column stats
|
||||||
var leftY = statsStartY
|
var leftY = statsStartY
|
||||||
drawStatItemFitting(canvas, columnWidth / 2f, leftY, "Attempts", stats.totalAttempts.toString(), statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
columnWidth / 2f,
|
||||||
|
leftY,
|
||||||
|
"Attempts",
|
||||||
|
stats.totalAttempts.toString(),
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
leftY += 120f
|
leftY += 120f
|
||||||
drawStatItemFitting(canvas, columnWidth / 2f, leftY, "Problems", stats.uniqueProblemsAttempted.toString(), statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
columnWidth / 2f,
|
||||||
|
leftY,
|
||||||
|
"Problems",
|
||||||
|
stats.uniqueProblemsAttempted.toString(),
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
leftY += 120f
|
leftY += 120f
|
||||||
drawStatItemFitting(canvas, columnWidth / 2f, leftY, "Duration", stats.sessionDuration, statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
columnWidth / 2f,
|
||||||
|
leftY,
|
||||||
|
"Duration",
|
||||||
|
stats.sessionDuration,
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
|
|
||||||
// Right column stats
|
// Right column stats
|
||||||
var rightY = statsStartY
|
var rightY = statsStartY
|
||||||
drawStatItemFitting(canvas, width - columnWidth / 2f, rightY, "Successful", stats.successfulAttempts.toString(), statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
rightY += 120f
|
canvas,
|
||||||
drawStatItemFitting(canvas, width - columnWidth / 2f, rightY, "Completed", stats.uniqueProblemsCompleted.toString(), statLabelPaint, statValuePaint, columnMaxTextWidth)
|
width - columnWidth / 2f,
|
||||||
|
rightY,
|
||||||
|
"Completed",
|
||||||
|
stats.uniqueProblemsCompleted.toString(),
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
rightY += 120f
|
rightY += 120f
|
||||||
|
|
||||||
var rightYAfter = rightY
|
var rightYAfter = rightY
|
||||||
stats.topGrade?.let { grade ->
|
stats.topGrade?.let { grade ->
|
||||||
drawStatItemFitting(canvas, width - columnWidth / 2f, rightY, "Top Grade", grade, statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
width - columnWidth / 2f,
|
||||||
|
rightY,
|
||||||
|
"Top Grade",
|
||||||
|
grade,
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
rightYAfter += 120f
|
rightYAfter += 120f
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grade range(s)
|
// Grade range(s)
|
||||||
val boulderRange = gradeRangeForProblems(stats.problems.filter { it.climbType == ClimbType.BOULDER })
|
val boulderRange =
|
||||||
val ropeRange = gradeRangeForProblems(stats.problems.filter { it.climbType == ClimbType.ROPE })
|
gradeRangeForProblems(
|
||||||
|
stats.problems.filter { it.climbType == ClimbType.BOULDER }
|
||||||
|
)
|
||||||
|
val ropeRange =
|
||||||
|
gradeRangeForProblems(stats.problems.filter { it.climbType == ClimbType.ROPE })
|
||||||
val rangesY = kotlin.math.max(leftY, rightYAfter) + 120f
|
val rangesY = kotlin.math.max(leftY, rightYAfter) + 120f
|
||||||
if (boulderRange != null && ropeRange != null) {
|
if (boulderRange != null && ropeRange != null) {
|
||||||
// Two evenly spaced items
|
// Two evenly spaced items
|
||||||
drawStatItemFitting(canvas, columnWidth / 2f, rangesY, "Boulder Range", boulderRange, statLabelPaint, statValuePaint, columnMaxTextWidth)
|
drawStatItemFitting(
|
||||||
drawStatItemFitting(canvas, width - columnWidth / 2f, rangesY, "Rope Range", ropeRange, statLabelPaint, statValuePaint, columnMaxTextWidth)
|
canvas,
|
||||||
|
columnWidth / 2f,
|
||||||
|
rangesY,
|
||||||
|
"Boulder Range",
|
||||||
|
boulderRange,
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
width - columnWidth / 2f,
|
||||||
|
rangesY,
|
||||||
|
"Rope Range",
|
||||||
|
ropeRange,
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
columnMaxTextWidth
|
||||||
|
)
|
||||||
} else if (boulderRange != null || ropeRange != null) {
|
} else if (boulderRange != null || ropeRange != null) {
|
||||||
// Single centered item
|
// Single centered item
|
||||||
val singleRange = boulderRange ?: ropeRange ?: ""
|
val singleRange = boulderRange ?: ropeRange ?: ""
|
||||||
drawStatItemFitting(canvas, width / 2f, rangesY, "Grade Range", singleRange, statLabelPaint, statValuePaint, width - 200f)
|
drawStatItemFitting(
|
||||||
|
canvas,
|
||||||
|
width / 2f,
|
||||||
|
rangesY,
|
||||||
|
"Grade Range",
|
||||||
|
singleRange,
|
||||||
|
statLabelPaint,
|
||||||
|
statValuePaint,
|
||||||
|
width - 200f
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// App branding
|
// App branding
|
||||||
val brandingPaint = Paint().apply {
|
val brandingPaint =
|
||||||
|
Paint().apply {
|
||||||
color = "#80FFFFFF".toColorInt()
|
color = "#80FFFFFF".toColorInt()
|
||||||
textSize = 32f
|
textSize = 32f
|
||||||
typeface = Typeface.DEFAULT
|
typeface = Typeface.DEFAULT
|
||||||
@@ -334,7 +421,8 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a stat item while fitting the value text to a max width by reducing text size if needed.
|
* Draws a stat item while fitting the value text to a max width by reducing text size if
|
||||||
|
* needed.
|
||||||
*/
|
*/
|
||||||
private fun drawStatItemFitting(
|
private fun drawStatItemFitting(
|
||||||
canvas: Canvas,
|
canvas: Canvas,
|
||||||
@@ -368,8 +456,6 @@ object SessionShareUtils {
|
|||||||
return "${sorted.first().grade} - ${sorted.last().grade}"
|
return "${sorted.first().grade} - ${sorted.last().grade}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private fun formatSessionDate(dateString: String): String {
|
private fun formatSessionDate(dateString: String): String {
|
||||||
return try {
|
return try {
|
||||||
val formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME
|
val formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME
|
||||||
@@ -383,17 +469,22 @@ object SessionShareUtils {
|
|||||||
|
|
||||||
fun shareSessionCard(context: Context, imageFile: File) {
|
fun shareSessionCard(context: Context, imageFile: File) {
|
||||||
try {
|
try {
|
||||||
val uri = FileProvider.getUriForFile(
|
val uri =
|
||||||
|
FileProvider.getUriForFile(
|
||||||
context,
|
context,
|
||||||
"${context.packageName}.fileprovider",
|
"${context.packageName}.fileprovider",
|
||||||
imageFile
|
imageFile
|
||||||
)
|
)
|
||||||
|
|
||||||
val shareIntent = Intent().apply {
|
val shareIntent =
|
||||||
|
Intent().apply {
|
||||||
action = Intent.ACTION_SEND
|
action = Intent.ACTION_SEND
|
||||||
type = "image/png"
|
type = "image/png"
|
||||||
putExtra(Intent.EXTRA_STREAM, uri)
|
putExtra(Intent.EXTRA_STREAM, uri)
|
||||||
putExtra(Intent.EXTRA_TEXT, "Check out my climbing session! 🧗♀️ #OpenClimb")
|
putExtra(
|
||||||
|
Intent.EXTRA_TEXT,
|
||||||
|
"Check out my climbing session! 🧗♀️ #OpenClimb"
|
||||||
|
)
|
||||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,16 +497,18 @@ object SessionShareUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the highest grade string among the given problems, respecting their difficulty system.
|
* Returns the highest grade string among the given problems, respecting their difficulty
|
||||||
|
* system.
|
||||||
*/
|
*/
|
||||||
private fun highestGradeForProblems(problems: List<Problem>): String? {
|
private fun highestGradeForProblems(problems: List<Problem>): String? {
|
||||||
if (problems.isEmpty()) return null
|
if (problems.isEmpty()) return null
|
||||||
return problems.maxByOrNull { p -> gradeRank(p.difficulty.system, p.difficulty.grade) }?.difficulty?.grade
|
return problems
|
||||||
|
.maxByOrNull { p -> gradeRank(p.difficulty.system, p.difficulty.grade) }
|
||||||
|
?.difficulty
|
||||||
|
?.grade
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Produces a comparable numeric rank for grades across supported systems. */
|
||||||
* Produces a comparable numeric rank for grades across supported systems.
|
|
||||||
*/
|
|
||||||
private fun gradeRank(system: DifficultySystem, grade: String): Double {
|
private fun gradeRank(system: DifficultySystem, grade: String): Double {
|
||||||
return when (system) {
|
return when (system) {
|
||||||
DifficultySystem.V_SCALE -> {
|
DifficultySystem.V_SCALE -> {
|
||||||
@@ -424,7 +517,8 @@ object SessionShareUtils {
|
|||||||
DifficultySystem.FONT -> {
|
DifficultySystem.FONT -> {
|
||||||
val list = DifficultySystem.FONT.getAvailableGrades()
|
val list = DifficultySystem.FONT.getAvailableGrades()
|
||||||
val idx = list.indexOf(grade.uppercase())
|
val idx = list.indexOf(grade.uppercase())
|
||||||
if (idx >= 0) idx.toDouble() else grade.filter { it.isDigit() }.toDoubleOrNull() ?: -1.0
|
if (idx >= 0) idx.toDouble()
|
||||||
|
else grade.filter { it.isDigit() }.toDoubleOrNull() ?: -1.0
|
||||||
}
|
}
|
||||||
DifficultySystem.YDS -> {
|
DifficultySystem.YDS -> {
|
||||||
// Parse 5.X with optional letter a-d
|
// Parse 5.X with optional letter a-d
|
||||||
@@ -434,7 +528,8 @@ object SessionShareUtils {
|
|||||||
val numberPart = tail.takeWhile { it.isDigit() || it == '.' }
|
val numberPart = tail.takeWhile { it.isDigit() || it == '.' }
|
||||||
val letterPart = tail.drop(numberPart.length).firstOrNull()
|
val letterPart = tail.drop(numberPart.length).firstOrNull()
|
||||||
val base = numberPart.toDoubleOrNull() ?: return -1.0
|
val base = numberPart.toDoubleOrNull() ?: return -1.0
|
||||||
val letterWeight = when (letterPart) {
|
val letterWeight =
|
||||||
|
when (letterPart) {
|
||||||
'a' -> 0.0
|
'a' -> 0.0
|
||||||
'b' -> 0.1
|
'b' -> 0.1
|
||||||
'c' -> 0.2
|
'c' -> 0.2
|
||||||
|
|||||||
@@ -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 = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
@@ -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 = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
ENABLE_PREVIEWS = YES;
|
ENABLE_PREVIEWS = YES;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
@@ -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 = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
@@ -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 = 8;
|
CURRENT_PROJECT_VERSION = 9;
|
||||||
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
DEVELOPMENT_TEAM = 4BC9Y2LL4B;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
INFOPLIST_FILE = SessionStatusLive/Info.plist;
|
||||||
|
|||||||
Binary file not shown.
@@ -7,7 +7,7 @@
|
|||||||
<key>OpenClimb.xcscheme_^#shared#^_</key>
|
<key>OpenClimb.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>orderHint</key>
|
<key>orderHint</key>
|
||||||
<integer>0</integer>
|
<integer>1</integer>
|
||||||
</dict>
|
</dict>
|
||||||
<key>SessionStatusLiveExtension.xcscheme_^#shared#^_</key>
|
<key>SessionStatusLiveExtension.xcscheme_^#shared#^_</key>
|
||||||
<dict>
|
<dict>
|
||||||
@@ -15,5 +15,18 @@
|
|||||||
<integer>0</integer>
|
<integer>0</integer>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
|
<key>SuppressBuildableAutocreation</key>
|
||||||
|
<dict>
|
||||||
|
<key>D24C19672E75002A0045894C</key>
|
||||||
|
<dict>
|
||||||
|
<key>primary</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
<key>D2FE948A2E78FEE0008CDB25</key>
|
||||||
|
<dict>
|
||||||
|
<key>primary</key>
|
||||||
|
<true/>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
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 tags: [String]
|
||||||
let location: String?
|
let location: String?
|
||||||
let imagePaths: [String]
|
let imagePaths: [String]
|
||||||
@@ -272,7 +272,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
gymId: UUID, name: String? = nil, description: String? = nil, climbType: ClimbType,
|
gymId: UUID, name: String? = nil, description: String? = nil, climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade, setter: String? = nil, tags: [String] = [],
|
difficulty: DifficultyGrade, tags: [String] = [],
|
||||||
location: String? = nil, imagePaths: [String] = [], dateSet: Date? = nil,
|
location: String? = nil, imagePaths: [String] = [], dateSet: Date? = nil,
|
||||||
notes: String? = nil
|
notes: String? = nil
|
||||||
) {
|
) {
|
||||||
@@ -282,7 +282,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
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.tags = tags
|
||||||
self.location = location
|
self.location = location
|
||||||
self.imagePaths = imagePaths
|
self.imagePaths = imagePaths
|
||||||
@@ -296,7 +296,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
|
|
||||||
func updated(
|
func updated(
|
||||||
name: String? = nil, description: String? = nil, climbType: ClimbType? = nil,
|
name: String? = nil, description: String? = nil, climbType: ClimbType? = nil,
|
||||||
difficulty: DifficultyGrade? = nil, setter: String? = nil, tags: [String]? = nil,
|
difficulty: DifficultyGrade? = nil, tags: [String]? = nil,
|
||||||
location: String? = nil, imagePaths: [String]? = nil, isActive: Bool? = nil,
|
location: String? = nil, imagePaths: [String]? = nil, isActive: Bool? = nil,
|
||||||
dateSet: Date? = nil, notes: String? = nil
|
dateSet: Date? = nil, notes: String? = nil
|
||||||
) -> Problem {
|
) -> Problem {
|
||||||
@@ -307,7 +307,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
description: description ?? self.description,
|
description: description ?? self.description,
|
||||||
climbType: climbType ?? self.climbType,
|
climbType: climbType ?? self.climbType,
|
||||||
difficulty: difficulty ?? self.difficulty,
|
difficulty: difficulty ?? self.difficulty,
|
||||||
setter: setter ?? self.setter,
|
|
||||||
tags: tags ?? self.tags,
|
tags: tags ?? self.tags,
|
||||||
location: location ?? self.location,
|
location: location ?? self.location,
|
||||||
imagePaths: imagePaths ?? self.imagePaths,
|
imagePaths: imagePaths ?? self.imagePaths,
|
||||||
@@ -321,7 +321,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
|
|
||||||
private init(
|
private init(
|
||||||
id: UUID, gymId: UUID, name: String?, description: String?, climbType: ClimbType,
|
id: UUID, gymId: UUID, name: String?, description: String?, climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade, setter: String?, tags: [String], location: String?,
|
difficulty: DifficultyGrade, tags: [String], location: String?,
|
||||||
imagePaths: [String], isActive: Bool, dateSet: Date?, notes: String?, createdAt: Date,
|
imagePaths: [String], isActive: Bool, dateSet: Date?, notes: String?, createdAt: Date,
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
) {
|
) {
|
||||||
@@ -331,7 +331,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
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.tags = tags
|
||||||
self.location = location
|
self.location = location
|
||||||
self.imagePaths = imagePaths
|
self.imagePaths = imagePaths
|
||||||
@@ -344,7 +344,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
|
|
||||||
static func fromImport(
|
static func fromImport(
|
||||||
id: UUID, gymId: UUID, name: String?, description: String?, climbType: ClimbType,
|
id: UUID, gymId: UUID, name: String?, description: String?, climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade, setter: String?, tags: [String], location: String?,
|
difficulty: DifficultyGrade, tags: [String], location: String?,
|
||||||
imagePaths: [String], isActive: Bool, dateSet: Date?, notes: String?, createdAt: Date,
|
imagePaths: [String], isActive: Bool, dateSet: Date?, notes: String?, createdAt: Date,
|
||||||
updatedAt: Date
|
updatedAt: Date
|
||||||
) -> Problem {
|
) -> Problem {
|
||||||
@@ -355,7 +355,7 @@ struct Problem: Identifiable, Codable, Hashable {
|
|||||||
description: description,
|
description: description,
|
||||||
climbType: climbType,
|
climbType: climbType,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
setter: setter,
|
|
||||||
tags: tags,
|
tags: tags,
|
||||||
location: location,
|
location: location,
|
||||||
imagePaths: imagePaths,
|
imagePaths: imagePaths,
|
||||||
|
|||||||
@@ -475,7 +475,7 @@ class ClimbingDataManager: ObservableObject {
|
|||||||
|
|
||||||
let exportData = ClimbDataExport(
|
let exportData = ClimbDataExport(
|
||||||
exportedAt: dateFormatter.string(from: Date()),
|
exportedAt: dateFormatter.string(from: Date()),
|
||||||
version: "1.0",
|
version: "2.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) },
|
||||||
@@ -593,7 +593,7 @@ struct ClimbDataExport: Codable {
|
|||||||
let attempts: [AndroidAttempt]
|
let attempts: [AndroidAttempt]
|
||||||
|
|
||||||
init(
|
init(
|
||||||
exportedAt: String, version: String = "1.0", gyms: [AndroidGym], problems: [AndroidProblem],
|
exportedAt: String, version: String = "2.0", gyms: [AndroidGym], problems: [AndroidProblem],
|
||||||
sessions: [AndroidClimbSession], attempts: [AndroidAttempt]
|
sessions: [AndroidClimbSession], attempts: [AndroidAttempt]
|
||||||
) {
|
) {
|
||||||
self.exportedAt = exportedAt
|
self.exportedAt = exportedAt
|
||||||
@@ -675,7 +675,6 @@ 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 tags: [String]
|
||||||
let location: String?
|
let location: String?
|
||||||
let imagePaths: [String]?
|
let imagePaths: [String]?
|
||||||
@@ -692,7 +691,6 @@ 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.tags = problem.tags
|
||||||
self.location = problem.location
|
self.location = problem.location
|
||||||
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
|
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
|
||||||
@@ -707,7 +705,7 @@ struct AndroidProblem: Codable {
|
|||||||
|
|
||||||
init(
|
init(
|
||||||
id: String, gymId: String, name: String?, description: String?, climbType: ClimbType,
|
id: String, gymId: String, name: String?, description: String?, climbType: ClimbType,
|
||||||
difficulty: DifficultyGrade, setter: String? = nil, tags: [String] = [],
|
difficulty: DifficultyGrade, tags: [String] = [],
|
||||||
location: String? = nil,
|
location: String? = nil,
|
||||||
imagePaths: [String]? = nil, isActive: Bool = true, dateSet: String? = nil,
|
imagePaths: [String]? = nil, isActive: Bool = true, dateSet: String? = nil,
|
||||||
notes: String? = nil,
|
notes: String? = nil,
|
||||||
@@ -719,7 +717,6 @@ 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.tags = tags
|
||||||
self.location = location
|
self.location = location
|
||||||
self.imagePaths = imagePaths
|
self.imagePaths = imagePaths
|
||||||
@@ -746,7 +743,6 @@ struct AndroidProblem: Codable {
|
|||||||
description: description,
|
description: description,
|
||||||
climbType: climbType,
|
climbType: climbType,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
setter: setter,
|
|
||||||
tags: tags,
|
tags: tags,
|
||||||
location: location,
|
location: location,
|
||||||
imagePaths: imagePaths ?? [],
|
imagePaths: imagePaths ?? [],
|
||||||
@@ -766,7 +762,6 @@ 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,
|
tags: self.tags,
|
||||||
location: self.location,
|
location: self.location,
|
||||||
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
|
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
|
||||||
@@ -1331,7 +1326,6 @@ extension ClimbingDataManager {
|
|||||||
description: "Technical overhang with small holds",
|
description: "Technical overhang with small holds",
|
||||||
climbType: .boulder,
|
climbType: .boulder,
|
||||||
difficulty: DifficultyGrade(system: .vScale, grade: "V4"),
|
difficulty: DifficultyGrade(system: .vScale, grade: "V4"),
|
||||||
setter: "John Doe",
|
|
||||||
tags: ["technical", "overhang"],
|
tags: ["technical", "overhang"],
|
||||||
location: "Cave area"
|
location: "Cave area"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -635,12 +635,6 @@ struct ProblemExpandedView: View {
|
|||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let setter = problem.setter, !setter.isEmpty {
|
|
||||||
Label(setter, systemImage: "person")
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let description = problem.description, !description.isEmpty {
|
if let description = problem.description, !description.isEmpty {
|
||||||
Text(description)
|
Text(description)
|
||||||
.font(.body)
|
.font(.body)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ struct AddEditProblemView: View {
|
|||||||
@State private var selectedClimbType: ClimbType = .boulder
|
@State private var selectedClimbType: ClimbType = .boulder
|
||||||
@State private var selectedDifficultySystem: DifficultySystem = .vScale
|
@State private var selectedDifficultySystem: DifficultySystem = .vScale
|
||||||
@State private var difficultyGrade = ""
|
@State private var difficultyGrade = ""
|
||||||
@State private var setter = ""
|
|
||||||
@State private var location = ""
|
@State private var location = ""
|
||||||
@State private var tags = ""
|
@State private var tags = ""
|
||||||
@State private var notes = ""
|
@State private var notes = ""
|
||||||
@@ -63,7 +62,7 @@ struct AddEditProblemView: View {
|
|||||||
PhotosSection()
|
PhotosSection()
|
||||||
ClimbTypeSection()
|
ClimbTypeSection()
|
||||||
DifficultySection()
|
DifficultySection()
|
||||||
LocationAndSetterSection()
|
LocationSection()
|
||||||
TagsSection()
|
TagsSection()
|
||||||
AdditionalInfoSection()
|
AdditionalInfoSection()
|
||||||
}
|
}
|
||||||
@@ -158,7 +157,6 @@ struct AddEditProblemView: View {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
TextField("Route Setter (Optional)", text: $setter)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,7 +279,7 @@ struct AddEditProblemView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func LocationAndSetterSection() -> some View {
|
private func LocationSection() -> some View {
|
||||||
Section("Location & Details") {
|
Section("Location & Details") {
|
||||||
TextField(
|
TextField(
|
||||||
"Location (Optional)", text: $location, prompt: Text("e.g., 'Cave area', 'Wall 3'"))
|
"Location (Optional)", text: $location, prompt: Text("e.g., 'Cave area', 'Wall 3'"))
|
||||||
@@ -334,13 +332,14 @@ struct AddEditProblemView: View {
|
|||||||
HStack(spacing: 12) {
|
HStack(spacing: 12) {
|
||||||
ForEach(imageData.indices, id: \.self) { index in
|
ForEach(imageData.indices, id: \.self) { index in
|
||||||
if let uiImage = UIImage(data: imageData[index]) {
|
if let uiImage = UIImage(data: imageData[index]) {
|
||||||
|
ZStack(alignment: .topTrailing) {
|
||||||
Image(uiImage: uiImage)
|
Image(uiImage: uiImage)
|
||||||
.resizable()
|
.resizable()
|
||||||
.aspectRatio(contentMode: .fill)
|
.aspectRatio(contentMode: .fill)
|
||||||
.frame(width: 80, height: 80)
|
.frame(width: 80, height: 80)
|
||||||
.clipped()
|
.clipped()
|
||||||
.cornerRadius(8)
|
.cornerRadius(8)
|
||||||
.overlay(alignment: .topTrailing) {
|
|
||||||
Button(action: {
|
Button(action: {
|
||||||
imageData.remove(at: index)
|
imageData.remove(at: index)
|
||||||
if index < imagePaths.count {
|
if index < imagePaths.count {
|
||||||
@@ -350,9 +349,11 @@ struct AddEditProblemView: View {
|
|||||||
Image(systemName: "xmark.circle.fill")
|
Image(systemName: "xmark.circle.fill")
|
||||||
.foregroundColor(.red)
|
.foregroundColor(.red)
|
||||||
.background(Circle().fill(.white))
|
.background(Circle().fill(.white))
|
||||||
|
.font(.system(size: 18))
|
||||||
}
|
}
|
||||||
.offset(x: 8, y: -8)
|
.offset(x: 4, y: -4)
|
||||||
}
|
}
|
||||||
|
.frame(width: 88, height: 88) // Extra space for button
|
||||||
} else {
|
} else {
|
||||||
RoundedRectangle(cornerRadius: 8)
|
RoundedRectangle(cornerRadius: 8)
|
||||||
.fill(.gray.opacity(0.3))
|
.fill(.gray.opacity(0.3))
|
||||||
@@ -365,6 +366,7 @@ struct AddEditProblemView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, 1)
|
.padding(.horizontal, 1)
|
||||||
|
.padding(.vertical, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,7 +412,7 @@ struct AddEditProblemView: View {
|
|||||||
selectedClimbType = problem.climbType
|
selectedClimbType = problem.climbType
|
||||||
selectedDifficultySystem = problem.difficulty.system
|
selectedDifficultySystem = problem.difficulty.system
|
||||||
difficultyGrade = problem.difficulty.grade
|
difficultyGrade = problem.difficulty.grade
|
||||||
setter = problem.setter ?? ""
|
|
||||||
location = problem.location ?? ""
|
location = problem.location ?? ""
|
||||||
tags = problem.tags.joined(separator: ", ")
|
tags = problem.tags.joined(separator: ", ")
|
||||||
notes = problem.notes ?? ""
|
notes = problem.notes ?? ""
|
||||||
@@ -420,7 +422,7 @@ struct AddEditProblemView: View {
|
|||||||
// Load image data for preview
|
// Load image data for preview
|
||||||
imageData = []
|
imageData = []
|
||||||
for imagePath in problem.imagePaths {
|
for imagePath in problem.imagePaths {
|
||||||
if let data = try? Data(contentsOf: URL(fileURLWithPath: imagePath)) {
|
if let data = ImageManager.shared.loadImageData(fromPath: imagePath) {
|
||||||
imageData.append(data)
|
imageData.append(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -479,7 +481,7 @@ struct AddEditProblemView: View {
|
|||||||
|
|
||||||
let trimmedName = name.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedName = name.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedDescription = description.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedDescription = description.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedSetter = setter.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
||||||
let trimmedLocation = location.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedLocation = location.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedNotes = notes.trimmingCharacters(in: .whitespacesAndNewlines)
|
let trimmedNotes = notes.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
let trimmedTags = tags.split(separator: ",").map {
|
let trimmedTags = tags.split(separator: ",").map {
|
||||||
@@ -494,7 +496,7 @@ struct AddEditProblemView: View {
|
|||||||
description: trimmedDescription.isEmpty ? nil : trimmedDescription,
|
description: trimmedDescription.isEmpty ? nil : trimmedDescription,
|
||||||
climbType: selectedClimbType,
|
climbType: selectedClimbType,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
setter: trimmedSetter.isEmpty ? nil : trimmedSetter,
|
|
||||||
tags: trimmedTags,
|
tags: trimmedTags,
|
||||||
location: trimmedLocation.isEmpty ? nil : trimmedLocation,
|
location: trimmedLocation.isEmpty ? nil : trimmedLocation,
|
||||||
imagePaths: imagePaths,
|
imagePaths: imagePaths,
|
||||||
@@ -510,7 +512,7 @@ struct AddEditProblemView: View {
|
|||||||
description: trimmedDescription.isEmpty ? nil : trimmedDescription,
|
description: trimmedDescription.isEmpty ? nil : trimmedDescription,
|
||||||
climbType: selectedClimbType,
|
climbType: selectedClimbType,
|
||||||
difficulty: difficulty,
|
difficulty: difficulty,
|
||||||
setter: trimmedSetter.isEmpty ? nil : trimmedSetter,
|
|
||||||
tags: trimmedTags,
|
tags: trimmedTags,
|
||||||
location: trimmedLocation.isEmpty ? nil : trimmedLocation,
|
location: trimmedLocation.isEmpty ? nil : trimmedLocation,
|
||||||
imagePaths: imagePaths,
|
imagePaths: imagePaths,
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct GymDetailView: View {
|
struct GymDetailView: View {
|
||||||
@@ -60,8 +59,10 @@ struct GymDetailView: View {
|
|||||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||||
if gym != nil {
|
if gym != nil {
|
||||||
Menu {
|
Menu {
|
||||||
Button("Edit Gym") {
|
Button {
|
||||||
// Navigate to edit view
|
// Navigate to edit view
|
||||||
|
} label: {
|
||||||
|
Label("Edit Gym", systemImage: "pencil")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ProblemDetailView: View {
|
struct ProblemDetailView: View {
|
||||||
@@ -64,8 +63,10 @@ struct ProblemDetailView: View {
|
|||||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||||
if problem != nil {
|
if problem != nil {
|
||||||
Menu {
|
Menu {
|
||||||
Button("Edit Problem") {
|
Button {
|
||||||
showingEditProblem = true
|
showingEditProblem = true
|
||||||
|
} label: {
|
||||||
|
Label("Edit Problem", systemImage: "pencil")
|
||||||
}
|
}
|
||||||
|
|
||||||
Button(role: .destructive) {
|
Button(role: .destructive) {
|
||||||
@@ -167,12 +168,6 @@ struct ProblemHeaderCard: View {
|
|||||||
.font(.body)
|
.font(.body)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let setter = problem.setter, !setter.isEmpty {
|
|
||||||
Text("Set by: \(setter)")
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundColor(.secondary)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !problem.tags.isEmpty {
|
if !problem.tags.isEmpty {
|
||||||
ScrollView(.horizontal, showsIndicators: false) {
|
ScrollView(.horizontal, showsIndicators: false) {
|
||||||
HStack(spacing: 8) {
|
HStack(spacing: 8) {
|
||||||
|
|||||||
@@ -280,7 +280,6 @@ struct SessionStatsCard: View {
|
|||||||
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 2), spacing: 16) {
|
LazyVGrid(columns: Array(repeating: GridItem(.flexible()), count: 2), spacing: 16) {
|
||||||
StatItem(label: "Total Attempts", value: "\(stats.totalAttempts)")
|
StatItem(label: "Total Attempts", value: "\(stats.totalAttempts)")
|
||||||
StatItem(label: "Problems", value: "\(stats.uniqueProblemsAttempted)")
|
StatItem(label: "Problems", value: "\(stats.uniqueProblemsAttempted)")
|
||||||
StatItem(label: "Successful", value: "\(stats.successfulAttempts)")
|
|
||||||
StatItem(label: "Completed", value: "\(stats.uniqueProblemsCompleted)")
|
StatItem(label: "Completed", value: "\(stats.uniqueProblemsCompleted)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct GymsView: View {
|
struct GymsView: View {
|
||||||
@@ -49,7 +48,10 @@ struct GymsList: View {
|
|||||||
Button {
|
Button {
|
||||||
gymToEdit = gym
|
gymToEdit = gym
|
||||||
} label: {
|
} label: {
|
||||||
Label("Edit", systemImage: "pencil")
|
HStack {
|
||||||
|
Image(systemName: "pencil")
|
||||||
|
Text("Edit")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.tint(.blue)
|
.tint(.blue)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ struct ProblemsView: View {
|
|||||||
// Apply search filter
|
// Apply search filter
|
||||||
if !searchText.isEmpty {
|
if !searchText.isEmpty {
|
||||||
filtered = filtered.filter { problem in
|
filtered = filtered.filter { problem in
|
||||||
(problem.name?.localizedCaseInsensitiveContains(searchText) ?? false)
|
return problem.name?.localizedCaseInsensitiveContains(searchText) ?? false
|
||||||
|| (problem.description?.localizedCaseInsensitiveContains(searchText) ?? false)
|
|| (problem.description?.localizedCaseInsensitiveContains(searchText) ?? false)
|
||||||
|| (problem.location?.localizedCaseInsensitiveContains(searchText) ?? false)
|
|| (problem.location?.localizedCaseInsensitiveContains(searchText) ?? false)
|
||||||
|| (problem.setter?.localizedCaseInsensitiveContains(searchText) ?? false)
|
|
||||||
|| problem.tags.contains { $0.localizedCaseInsensitiveContains(searchText) }
|
|| problem.tags.contains { $0.localizedCaseInsensitiveContains(searchText) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -31,7 +30,11 @@ struct ProblemsView: View {
|
|||||||
filtered = filtered.filter { $0.gymId == gym.id }
|
filtered = filtered.filter { $0.gymId == gym.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered.sorted { $0.updatedAt > $1.updatedAt }
|
// Separate active and inactive problems
|
||||||
|
let active = filtered.filter { $0.isActive }.sorted { $0.updatedAt > $1.updatedAt }
|
||||||
|
let inactive = filtered.filter { !$0.isActive }.sorted { $0.updatedAt > $1.updatedAt }
|
||||||
|
|
||||||
|
return active + inactive
|
||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
@@ -195,10 +198,23 @@ struct ProblemsList: View {
|
|||||||
Label("Delete", systemImage: "trash")
|
Label("Delete", systemImage: "trash")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Button {
|
||||||
|
let updatedProblem = problem.updated(isActive: !problem.isActive)
|
||||||
|
dataManager.updateProblem(updatedProblem)
|
||||||
|
} label: {
|
||||||
|
Label(
|
||||||
|
problem.isActive ? "Mark as Reset" : "Mark as Active",
|
||||||
|
systemImage: problem.isActive ? "xmark.circle" : "checkmark.circle")
|
||||||
|
}
|
||||||
|
.tint(.orange)
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
problemToEdit = problem
|
problemToEdit = problem
|
||||||
} label: {
|
} label: {
|
||||||
Label("Edit", systemImage: "pencil")
|
HStack {
|
||||||
|
Image(systemName: "pencil")
|
||||||
|
Text("Edit")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.tint(.blue)
|
.tint(.blue)
|
||||||
}
|
}
|
||||||
@@ -239,6 +255,7 @@ struct ProblemRow: View {
|
|||||||
Text(problem.name ?? "Unnamed Problem")
|
Text(problem.name ?? "Unnamed Problem")
|
||||||
.font(.headline)
|
.font(.headline)
|
||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
|
.foregroundColor(problem.isActive ? .primary : .secondary)
|
||||||
|
|
||||||
Text(gym?.name ?? "Unknown Gym")
|
Text(gym?.name ?? "Unknown Gym")
|
||||||
.font(.subheadline)
|
.font(.subheadline)
|
||||||
@@ -295,9 +312,9 @@ struct ProblemRow: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !problem.isActive {
|
if !problem.isActive {
|
||||||
Text("Inactive")
|
Text("Reset / No Longer Set")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundColor(.red)
|
.foregroundColor(.orange)
|
||||||
.fontWeight(.medium)
|
.fontWeight(.medium)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user