iOS and Android dependency updates and optimizations
This commit is contained in:
@@ -18,8 +18,8 @@ android {
|
||||
applicationId = "com.atridad.ascently"
|
||||
minSdk = 31
|
||||
targetSdk = 36
|
||||
versionCode = 49
|
||||
versionName = "2.4.1"
|
||||
versionCode = 50
|
||||
versionName = "2.5.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import androidx.health.connect.client.permission.HealthPermission
|
||||
import androidx.health.connect.client.records.ExerciseSessionRecord
|
||||
import androidx.health.connect.client.records.HeartRateRecord
|
||||
import androidx.health.connect.client.records.TotalCaloriesBurnedRecord
|
||||
|
||||
import androidx.health.connect.client.units.Energy
|
||||
import com.atridad.ascently.data.model.ClimbSession
|
||||
import com.atridad.ascently.data.model.SessionStatus
|
||||
@@ -22,6 +23,7 @@ import kotlinx.coroutines.flow.flow
|
||||
import java.time.Duration
|
||||
import java.time.Instant
|
||||
import java.time.ZoneOffset
|
||||
import androidx.core.content.edit
|
||||
|
||||
/**
|
||||
* Health Connect manager for Ascently that syncs climbing sessions to Samsung Health, Google Fit,
|
||||
@@ -197,6 +199,7 @@ class HealthConnectManager(private val context: Context) {
|
||||
exerciseType =
|
||||
ExerciseSessionRecord.EXERCISE_TYPE_STRENGTH_TRAINING,
|
||||
title = "Rock Climbing at $gymName",
|
||||
metadata = androidx.health.connect.client.records.metadata.Metadata.manualEntry(),
|
||||
)
|
||||
records.add(exerciseSession)
|
||||
} catch (e: Exception) {
|
||||
@@ -217,6 +220,7 @@ class HealthConnectManager(private val context: Context) {
|
||||
endZoneOffset =
|
||||
ZoneOffset.systemDefault().rules.getOffset(endTime),
|
||||
energy = Energy.calories(estimatedCalories),
|
||||
metadata = androidx.health.connect.client.records.metadata.Metadata.manualEntry(),
|
||||
)
|
||||
records.add(caloriesRecord)
|
||||
}
|
||||
@@ -239,9 +243,9 @@ class HealthConnectManager(private val context: Context) {
|
||||
}
|
||||
|
||||
preferences
|
||||
.edit()
|
||||
.putString("last_sync_success", DateFormatUtils.nowISO8601())
|
||||
.apply()
|
||||
.edit {
|
||||
putString("last_sync_success", DateFormatUtils.nowISO8601())
|
||||
}
|
||||
} else {
|
||||
val reason =
|
||||
when {
|
||||
@@ -326,6 +330,7 @@ class HealthConnectManager(private val context: Context) {
|
||||
endTime = endTime,
|
||||
endZoneOffset = ZoneOffset.systemDefault().rules.getOffset(endTime),
|
||||
samples = samples,
|
||||
metadata = androidx.health.connect.client.records.metadata.Metadata.manualEntry(),
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
AppLogger.e(TAG, e) { "Error creating heart rate record" }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.atridad.ascently.data.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
@@ -34,6 +35,7 @@ enum class AttemptResult {
|
||||
],
|
||||
indices = [Index(value = ["sessionId"]), Index(value = ["problemId"])],
|
||||
)
|
||||
@Immutable
|
||||
@Serializable
|
||||
data class Attempt(
|
||||
@PrimaryKey val id: String,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.atridad.ascently.data.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
@@ -27,6 +28,7 @@ enum class SessionStatus {
|
||||
],
|
||||
indices = [Index(value = ["gymId"])],
|
||||
)
|
||||
@Immutable
|
||||
@Serializable
|
||||
data class ClimbSession(
|
||||
@PrimaryKey val id: String,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.atridad.ascently.data.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
import com.atridad.ascently.utils.DateFormatUtils
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Immutable
|
||||
@Entity(tableName = "gyms")
|
||||
@Serializable
|
||||
data class Gym(
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.atridad.ascently.data.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.room.Entity
|
||||
import androidx.room.ForeignKey
|
||||
import androidx.room.Index
|
||||
@@ -7,6 +8,7 @@ import androidx.room.PrimaryKey
|
||||
import com.atridad.ascently.utils.DateFormatUtils
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Immutable
|
||||
@Entity(
|
||||
tableName = "problems",
|
||||
foreignKeys =
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.atridad.ascently.R
|
||||
import com.atridad.ascently.data.database.AscentlyDatabase
|
||||
import com.atridad.ascently.data.repository.ClimbRepository
|
||||
import com.atridad.ascently.utils.AppLogger
|
||||
import com.atridad.ascently.utils.DateFormatUtils
|
||||
import com.atridad.ascently.widget.ClimbStatsWidgetProvider
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
@@ -237,9 +238,8 @@ class SessionTrackingService : Service() {
|
||||
val startTimeMillis =
|
||||
session.startTime?.let { startTime ->
|
||||
try {
|
||||
val start = LocalDateTime.parse(startTime)
|
||||
val zoneId = ZoneId.systemDefault()
|
||||
start.atZone(zoneId).toInstant().toEpochMilli()
|
||||
DateFormatUtils.parseISO8601(startTime)?.toEpochMilli()
|
||||
?: System.currentTimeMillis()
|
||||
} catch (_: Exception) {
|
||||
System.currentTimeMillis()
|
||||
}
|
||||
@@ -263,9 +263,9 @@ class SessionTrackingService : Service() {
|
||||
val duration =
|
||||
session.startTime?.let { startTime ->
|
||||
try {
|
||||
val start = LocalDateTime.parse(startTime)
|
||||
val now = LocalDateTime.now()
|
||||
val totalSeconds = ChronoUnit.SECONDS.between(start, now)
|
||||
val start = DateFormatUtils.parseISO8601(startTime)
|
||||
val now = java.time.Instant.now()
|
||||
val totalSeconds = if (start != null) ChronoUnit.SECONDS.between(start, now) else 0L
|
||||
val hours = totalSeconds / 3600
|
||||
val minutes = (totalSeconds % 3600) / 60
|
||||
val seconds = totalSeconds % 60
|
||||
|
||||
@@ -13,8 +13,9 @@ import androidx.compose.ui.unit.dp
|
||||
import com.atridad.ascently.data.model.ClimbSession
|
||||
import com.atridad.ascently.data.model.Gym
|
||||
import com.atridad.ascently.ui.theme.CustomIcons
|
||||
import com.atridad.ascently.utils.DateFormatUtils
|
||||
import kotlinx.coroutines.delay
|
||||
import java.time.LocalDateTime
|
||||
import java.time.Instant
|
||||
import java.time.temporal.ChronoUnit
|
||||
|
||||
@Composable
|
||||
@@ -23,101 +24,112 @@ fun ActiveSessionBanner(
|
||||
gym: Gym?,
|
||||
onSessionClick: () -> Unit,
|
||||
onEndSession: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
if (activeSession != null) {
|
||||
// Add a timer that updates every second for real-time duration counting
|
||||
var currentTime by remember { mutableStateOf(LocalDateTime.now()) }
|
||||
if (activeSession == null) return
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
while (true) {
|
||||
delay(1000) // Update every second
|
||||
currentTime = LocalDateTime.now()
|
||||
}
|
||||
val sessionId = activeSession.id
|
||||
val startTimeString = activeSession.startTime
|
||||
val gymName = gym?.name ?: "Unknown Gym"
|
||||
|
||||
var elapsedSeconds by remember(sessionId) { mutableLongStateOf(0L) }
|
||||
|
||||
LaunchedEffect(sessionId, startTimeString) {
|
||||
if (startTimeString == null) return@LaunchedEffect
|
||||
|
||||
while (true) {
|
||||
elapsedSeconds = calculateElapsedSeconds(startTimeString)
|
||||
delay(1000)
|
||||
}
|
||||
}
|
||||
|
||||
Card(
|
||||
val durationText = remember(elapsedSeconds) {
|
||||
formatDuration(elapsedSeconds)
|
||||
}
|
||||
|
||||
Card(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onSessionClick() },
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
),
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { onSessionClick() },
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
||||
),
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Default.PlayArrow,
|
||||
contentDescription = "Active session",
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
text = "Active Session",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
Icon(
|
||||
Icons.Default.PlayArrow,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(16.dp),
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(
|
||||
text = gym?.name ?: "Unknown Gym",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
text = "Active Session",
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
)
|
||||
|
||||
activeSession.startTime?.let { startTime ->
|
||||
val duration = calculateDuration(startTime, currentTime)
|
||||
Text(
|
||||
text = duration,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.8f),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = onEndSession,
|
||||
colors = IconButtonDefaults.iconButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.error,
|
||||
contentColor = MaterialTheme.colorScheme.onError,
|
||||
),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = CustomIcons.Stop(MaterialTheme.colorScheme.onError),
|
||||
contentDescription = "End session",
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
|
||||
Text(
|
||||
text = gymName,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||
)
|
||||
|
||||
if (startTimeString != null) {
|
||||
Text(
|
||||
text = durationText,
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onPrimaryContainer.copy(alpha = 0.8f),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
FilledIconButton(
|
||||
onClick = onEndSession,
|
||||
colors = IconButtonDefaults.filledIconButtonColors(
|
||||
containerColor = MaterialTheme.colorScheme.error,
|
||||
contentColor = MaterialTheme.colorScheme.onError,
|
||||
),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = CustomIcons.Stop(MaterialTheme.colorScheme.onError),
|
||||
contentDescription = "End session",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun calculateDuration(startTimeString: String, currentTime: LocalDateTime): String {
|
||||
private fun calculateElapsedSeconds(startTimeString: String): Long {
|
||||
return try {
|
||||
val startTime = LocalDateTime.parse(startTimeString)
|
||||
val totalSeconds = ChronoUnit.SECONDS.between(startTime, currentTime)
|
||||
val hours = totalSeconds / 3600
|
||||
val minutes = (totalSeconds % 3600) / 60
|
||||
val seconds = totalSeconds % 60
|
||||
|
||||
when {
|
||||
hours > 0 -> "${hours}h ${minutes}m ${seconds}s"
|
||||
minutes > 0 -> "${minutes}m ${seconds}s"
|
||||
else -> "${totalSeconds}s"
|
||||
}
|
||||
val startTime = DateFormatUtils.parseISO8601(startTimeString) ?: return 0L
|
||||
val now = Instant.now()
|
||||
ChronoUnit.SECONDS.between(startTime, now).coerceAtLeast(0)
|
||||
} catch (_: Exception) {
|
||||
"Active"
|
||||
0L
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatDuration(totalSeconds: Long): String {
|
||||
val hours = totalSeconds / 3600
|
||||
val minutes = (totalSeconds % 3600) / 60
|
||||
val seconds = totalSeconds % 60
|
||||
|
||||
return when {
|
||||
hours > 0 -> "${hours}h ${minutes}m ${seconds}s"
|
||||
minutes > 0 -> "${minutes}m ${seconds}s"
|
||||
else -> "${seconds}s"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,16 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
||||
val attempts by viewModel.attempts.collectAsState()
|
||||
val gyms by viewModel.gyms.collectAsState()
|
||||
|
||||
val gradeDistributionData = remember(sessions, problems, attempts) {
|
||||
calculateGradeDistribution(sessions, problems, attempts)
|
||||
}
|
||||
|
||||
val favoriteGym = remember(sessions, gyms) {
|
||||
sessions.groupBy { it.gymId }.maxByOrNull { it.value.size }?.let { (gymId, sessionList) ->
|
||||
gyms.find { it.id == gymId }?.name to sessionList.size
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize().padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(16.dp),
|
||||
@@ -65,18 +75,11 @@ fun AnalyticsScreen(viewModel: ClimbViewModel) {
|
||||
|
||||
// Grade Distribution Chart
|
||||
item {
|
||||
val gradeDistributionData = calculateGradeDistribution(sessions, problems, attempts)
|
||||
GradeDistributionChartCard(gradeDistributionData = gradeDistributionData)
|
||||
}
|
||||
|
||||
// Favorite Gym
|
||||
item {
|
||||
val favoriteGym =
|
||||
sessions.groupBy { it.gymId }.maxByOrNull { it.value.size }?.let {
|
||||
(gymId, sessions) ->
|
||||
gyms.find { it.id == gymId }?.name to sessions.size
|
||||
}
|
||||
|
||||
FavoriteGymCard(
|
||||
gymName = favoriteGym?.first ?: "No sessions yet",
|
||||
sessionCount = favoriteGym?.second ?: 0,
|
||||
|
||||
@@ -225,26 +225,24 @@ fun SessionDetailScreen(
|
||||
var showEditAttemptDialog by remember { mutableStateOf<Attempt?>(null) }
|
||||
|
||||
// Get session details
|
||||
val session = sessions.find { it.id == sessionId }
|
||||
val gym = session?.let { s -> gyms.find { it.id == s.gymId } }
|
||||
val session = remember(sessions, sessionId) { sessions.find { it.id == sessionId } }
|
||||
val gym = remember(session, gyms) { session?.let { s -> gyms.find { it.id == s.gymId } } }
|
||||
|
||||
// Calculate stats
|
||||
val successfulAttempts =
|
||||
val successfulAttempts = remember(attempts) {
|
||||
attempts.filter { it.result in listOf(AttemptResult.SUCCESS, AttemptResult.FLASH) }
|
||||
val uniqueProblems = attempts.map { it.problemId }.distinct()
|
||||
}
|
||||
val uniqueProblems = remember(attempts) { attempts.map { it.problemId }.distinct() }
|
||||
val completedProblems = remember(successfulAttempts) { successfulAttempts.map { it.problemId }.distinct() }
|
||||
|
||||
val completedProblems = successfulAttempts.map { it.problemId }.distinct()
|
||||
|
||||
val attemptsWithProblems =
|
||||
val attemptsWithProblems = remember(attempts, problems) {
|
||||
attempts
|
||||
.mapNotNull { attempt ->
|
||||
val problem = problems.find { it.id == attempt.problemId }
|
||||
if (problem != null) attempt to problem else null
|
||||
}
|
||||
.sortedBy { attempt ->
|
||||
// Sort by timestamp (when attempt was logged)
|
||||
attempt.first.timestamp
|
||||
}
|
||||
.sortedBy { it.first.timestamp }
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -267,7 +265,7 @@ fun SessionDetailScreen(
|
||||
if (session?.status == SessionStatus.ACTIVE) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
session.let { s ->
|
||||
session?.let { s ->
|
||||
viewModel.endSession(context, s.id)
|
||||
onNavigateBack()
|
||||
}
|
||||
@@ -313,8 +311,11 @@ fun SessionDetailScreen(
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
val formattedDate = remember(session?.date) {
|
||||
DateFormatUtils.formatDateForDisplay(session?.date ?: "")
|
||||
}
|
||||
Text(
|
||||
text = formatDate(session?.date ?: ""),
|
||||
text = formattedDate,
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
@@ -503,11 +504,13 @@ fun SessionDetailScreen(
|
||||
)
|
||||
}
|
||||
|
||||
if (showAddAttemptDialog && session != null && gym != null) {
|
||||
val currentSession = session
|
||||
val currentGym = gym
|
||||
if (showAddAttemptDialog && currentSession != null && currentGym != null) {
|
||||
EnhancedAddAttemptDialog(
|
||||
session = session,
|
||||
gym = gym,
|
||||
problems = problems.filter { it.gymId == gym.id && it.isActive },
|
||||
session = currentSession,
|
||||
gym = currentGym,
|
||||
problems = problems.filter { it.gymId == currentGym.id && it.isActive },
|
||||
onDismiss = { showAddAttemptDialog = false },
|
||||
onAttemptAdded = { attempt ->
|
||||
viewModel.addAttempt(attempt)
|
||||
@@ -728,9 +731,12 @@ fun ProblemDetailScreen(
|
||||
}
|
||||
firstSuccess?.let { attempt ->
|
||||
val session = sessions.find { it.id == attempt.sessionId }
|
||||
val firstSuccessDate = remember(session?.date) {
|
||||
DateFormatUtils.formatDateForDisplay(session?.date ?: "")
|
||||
}
|
||||
Text(
|
||||
text =
|
||||
"First success: ${formatDate(session?.date ?: "")} (${attempt.result.name.lowercase().replaceFirstChar { it.uppercase() }})",
|
||||
"First success: $firstSuccessDate (${attempt.result.name.lowercase().replaceFirstChar { it.uppercase() }})",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
@@ -1309,6 +1315,10 @@ fun StatItem(label: String, value: String) {
|
||||
|
||||
@Composable
|
||||
fun AttemptHistoryCard(attempt: Attempt, session: ClimbSession, gym: Gym?) {
|
||||
val formattedDate = remember(session.date) {
|
||||
DateFormatUtils.formatDateForDisplay(session.date)
|
||||
}
|
||||
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.padding(16.dp)) {
|
||||
Row(
|
||||
@@ -1318,7 +1328,7 @@ fun AttemptHistoryCard(attempt: Attempt, session: ClimbSession, gym: Gym?) {
|
||||
) {
|
||||
Column {
|
||||
Text(
|
||||
text = formatDate(session.date),
|
||||
text = formattedDate,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
fontWeight = FontWeight.Medium,
|
||||
)
|
||||
@@ -1478,9 +1488,7 @@ fun SessionAttemptCard(
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatDate(dateString: String): String {
|
||||
return DateFormatUtils.formatDateForDisplay(dateString)
|
||||
}
|
||||
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
|
||||
@@ -52,7 +52,7 @@ fun GymsScreen(viewModel: ClimbViewModel, onNavigateToGymDetail: (String) -> Uni
|
||||
)
|
||||
} else {
|
||||
LazyColumn {
|
||||
items(gyms) { gym ->
|
||||
items(gyms, key = { it.id }) { gym ->
|
||||
GymCard(gym = gym, onClick = { onNavigateToGymDetail(gym.id) })
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
|
||||
@@ -35,17 +35,18 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
||||
var selectedGym by remember { mutableStateOf<Gym?>(null) }
|
||||
|
||||
// Apply filters
|
||||
val filteredProblems =
|
||||
val filteredProblems = remember(problems, selectedClimbType, selectedGym) {
|
||||
problems.filter { problem ->
|
||||
val climbTypeMatch = selectedClimbType?.let { it == problem.climbType } != false
|
||||
val gymMatch = selectedGym?.let { it.id == problem.gymId } != false
|
||||
climbTypeMatch && gymMatch
|
||||
}
|
||||
}
|
||||
|
||||
// Separate active and inactive problems
|
||||
val activeProblems = filteredProblems.filter { it.isActive }
|
||||
val inactiveProblems = filteredProblems.filter { !it.isActive }
|
||||
val sortedProblems = activeProblems + inactiveProblems
|
||||
val activeProblems = remember(filteredProblems) { filteredProblems.filter { it.isActive } }
|
||||
val inactiveProblems = remember(filteredProblems) { filteredProblems.filter { !it.isActive } }
|
||||
val sortedProblems = remember(activeProblems, inactiveProblems) { activeProblems + inactiveProblems }
|
||||
|
||||
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||
Row(
|
||||
@@ -175,7 +176,7 @@ fun ProblemsScreen(viewModel: ClimbViewModel, onNavigateToProblemDetail: (String
|
||||
)
|
||||
} else {
|
||||
LazyColumn {
|
||||
items(sortedProblems) { problem ->
|
||||
items(sortedProblems, key = { it.id }) { problem ->
|
||||
ProblemCard(
|
||||
problem = problem,
|
||||
gymName = gyms.find { it.id == problem.gymId }?.name ?: "Unknown Gym",
|
||||
|
||||
@@ -61,8 +61,12 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
||||
var selectedMonth by remember { mutableStateOf(YearMonth.now()) }
|
||||
var selectedDate by remember { mutableStateOf<LocalDate?>(LocalDate.now()) }
|
||||
|
||||
val completedSessions = sessions.filter { it.status == SessionStatus.COMPLETED }
|
||||
val activeSessionGym = activeSession?.let { session -> gyms.find { it.id == session.gymId } }
|
||||
val completedSessions = remember(sessions) {
|
||||
sessions.filter { it.status == SessionStatus.COMPLETED }
|
||||
}
|
||||
val activeSessionGym = remember(activeSession, gyms) {
|
||||
activeSession?.let { session -> gyms.find { it.id == session.gymId } }
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.fillMaxSize().padding(16.dp)) {
|
||||
Row(
|
||||
@@ -136,7 +140,7 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
||||
when (viewMode) {
|
||||
ViewMode.LIST -> {
|
||||
LazyColumn {
|
||||
items(completedSessions) { session ->
|
||||
items(completedSessions, key = { it.id }) { session ->
|
||||
SessionCard(
|
||||
session = session,
|
||||
gymName = gyms.find { it.id == session.gymId }?.name
|
||||
@@ -232,6 +236,10 @@ fun SessionsScreen(viewModel: ClimbViewModel, onNavigateToSessionDetail: (String
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
||||
val formattedDate = remember(session.date) {
|
||||
DateFormatUtils.formatDateForDisplay(session.date)
|
||||
}
|
||||
|
||||
Card(onClick = onClick, modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.fillMaxWidth().padding(16.dp)) {
|
||||
Row(
|
||||
@@ -244,7 +252,7 @@ fun SessionCard(session: ClimbSession, gymName: String, onClick: () -> Unit) {
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
Text(
|
||||
text = formatDate(session.date),
|
||||
text = formattedDate,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
@@ -539,7 +547,3 @@ fun CalendarDay(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun formatDate(dateString: String): String {
|
||||
return DateFormatUtils.formatDateForDisplay(dateString)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[versions]
|
||||
agp = "8.12.3"
|
||||
kotlin = "2.2.21"
|
||||
kotlin = "2.3.0"
|
||||
coreKtx = "1.17.0"
|
||||
junit = "4.13.2"
|
||||
junitVersion = "1.3.0"
|
||||
@@ -10,8 +10,8 @@ androidxTestExt = "1.3.0"
|
||||
androidxTestRunner = "1.7.0"
|
||||
androidxTestRules = "1.7.0"
|
||||
lifecycleRuntimeKtx = "2.10.0"
|
||||
activityCompose = "1.12.0"
|
||||
composeBom = "2025.11.01"
|
||||
activityCompose = "1.12.2"
|
||||
composeBom = "2025.12.01"
|
||||
room = "2.8.4"
|
||||
navigation = "2.9.6"
|
||||
viewmodel = "2.10.0"
|
||||
@@ -19,10 +19,10 @@ kotlinxSerialization = "1.9.0"
|
||||
kotlinxCoroutines = "1.10.2"
|
||||
coil = "2.7.0"
|
||||
ksp = "2.2.20-2.0.3"
|
||||
exifinterface = "1.4.1"
|
||||
healthConnect = "1.1.0-alpha07"
|
||||
detekt = "1.23.7"
|
||||
spotless = "6.25.0"
|
||||
exifinterface = "1.4.2"
|
||||
healthConnect = "1.1.0"
|
||||
detekt = "1.23.8"
|
||||
spotless = "8.1.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
|
||||
Reference in New Issue
Block a user