1.6.0 for Android and 1.1.0 for iOS - Finalizing Export and Import

formats :)
This commit is contained in:
2025-09-28 02:37:03 -06:00
parent dcc3f9cc9d
commit 036becb5be
15 changed files with 1259 additions and 562 deletions

View File

@@ -100,7 +100,7 @@ struct ContentView: View {
print("📱 App did become active - checking Live Activity status")
Task {
try? await Task.sleep(nanoseconds: 300_000_000) // 0.3 seconds
dataManager.onAppBecomeActive()
await dataManager.onAppBecomeActive()
}
}

View File

@@ -0,0 +1,452 @@
//
// BackupFormat.swift
// OpenClimb
//
// Created by OpenClimb Team on 2024-12-19.
// Copyright © 2024 OpenClimb. All rights reserved.
//
import Foundation
// MARK: - Backup Format Specification v2.0
// Platform-neutral backup format for cross-platform compatibility
// This format ensures portability between iOS and Android while maintaining
// platform-specific implementations
/// Root structure for OpenClimb backup data
struct ClimbDataBackup: Codable {
let exportedAt: String
let version: String
let formatVersion: String
let gyms: [BackupGym]
let problems: [BackupProblem]
let sessions: [BackupClimbSession]
let attempts: [BackupAttempt]
init(
exportedAt: String,
version: String = "2.0",
formatVersion: String = "2.0",
gyms: [BackupGym],
problems: [BackupProblem],
sessions: [BackupClimbSession],
attempts: [BackupAttempt]
) {
self.exportedAt = exportedAt
self.version = version
self.formatVersion = formatVersion
self.gyms = gyms
self.problems = problems
self.sessions = sessions
self.attempts = attempts
}
}
/// Platform-neutral gym representation for backup/restore
struct BackupGym: Codable {
let id: String
let name: String
let location: String?
let supportedClimbTypes: [ClimbType]
let difficultySystems: [DifficultySystem]
let customDifficultyGrades: [String]
let notes: String?
let createdAt: String // ISO 8601 format
let updatedAt: String // ISO 8601 format
/// Initialize from native iOS Gym model
init(from gym: Gym) {
self.id = gym.id.uuidString
self.name = gym.name
self.location = gym.location
self.supportedClimbTypes = gym.supportedClimbTypes
self.difficultySystems = gym.difficultySystems
self.customDifficultyGrades = gym.customDifficultyGrades
self.notes = gym.notes
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
self.createdAt = formatter.string(from: gym.createdAt)
self.updatedAt = formatter.string(from: gym.updatedAt)
}
/// Initialize with explicit parameters for import
init(
id: String,
name: String,
location: String?,
supportedClimbTypes: [ClimbType],
difficultySystems: [DifficultySystem],
customDifficultyGrades: [String] = [],
notes: String?,
createdAt: String,
updatedAt: String
) {
self.id = id
self.name = name
self.location = location
self.supportedClimbTypes = supportedClimbTypes
self.difficultySystems = difficultySystems
self.customDifficultyGrades = customDifficultyGrades
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
/// Convert to native iOS Gym model
func toGym() throws -> Gym {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
guard let uuid = UUID(uuidString: id),
let createdDate = formatter.date(from: createdAt),
let updatedDate = formatter.date(from: updatedAt)
else {
throw BackupError.invalidDateFormat
}
return Gym.fromImport(
id: uuid,
name: name,
location: location,
supportedClimbTypes: supportedClimbTypes,
difficultySystems: difficultySystems,
customDifficultyGrades: customDifficultyGrades,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
}
/// Platform-neutral problem representation for backup/restore
struct BackupProblem: Codable {
let id: String
let gymId: String
let name: String?
let description: String?
let climbType: ClimbType
let difficulty: DifficultyGrade
let tags: [String]
let location: String?
let imagePaths: [String]?
let isActive: Bool
let dateSet: String? // ISO 8601 format
let notes: String?
let createdAt: String // ISO 8601 format
let updatedAt: String // ISO 8601 format
/// Initialize from native iOS Problem model
init(from problem: Problem) {
self.id = problem.id.uuidString
self.gymId = problem.gymId.uuidString
self.name = problem.name
self.description = problem.description
self.climbType = problem.climbType
self.difficulty = problem.difficulty
self.tags = problem.tags
self.location = problem.location
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
self.isActive = problem.isActive
self.notes = problem.notes
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
self.dateSet = problem.dateSet.map { formatter.string(from: $0) }
self.createdAt = formatter.string(from: problem.createdAt)
self.updatedAt = formatter.string(from: problem.updatedAt)
}
/// Initialize with explicit parameters for import
init(
id: String,
gymId: String,
name: String?,
description: String?,
climbType: ClimbType,
difficulty: DifficultyGrade,
tags: [String] = [],
location: String?,
imagePaths: [String]?,
isActive: Bool,
dateSet: String?,
notes: String?,
createdAt: String,
updatedAt: String
) {
self.id = id
self.gymId = gymId
self.name = name
self.description = description
self.climbType = climbType
self.difficulty = difficulty
self.tags = tags
self.location = location
self.imagePaths = imagePaths
self.isActive = isActive
self.dateSet = dateSet
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
/// Convert to native iOS Problem model
func toProblem() throws -> Problem {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
guard let uuid = UUID(uuidString: id),
let gymUuid = UUID(uuidString: gymId),
let createdDate = formatter.date(from: createdAt),
let updatedDate = formatter.date(from: updatedAt)
else {
throw BackupError.invalidDateFormat
}
let dateSetDate = dateSet.flatMap { formatter.date(from: $0) }
return Problem.fromImport(
id: uuid,
gymId: gymUuid,
name: name,
description: description,
climbType: climbType,
difficulty: difficulty,
tags: tags,
location: location,
imagePaths: imagePaths ?? [],
isActive: isActive,
dateSet: dateSetDate,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
/// Create a copy with updated image paths for import processing
func withUpdatedImagePaths(_ newImagePaths: [String]) -> BackupProblem {
return BackupProblem(
id: self.id,
gymId: self.gymId,
name: self.name,
description: self.description,
climbType: self.climbType,
difficulty: self.difficulty,
tags: self.tags,
location: self.location,
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
isActive: self.isActive,
dateSet: self.dateSet,
notes: self.notes,
createdAt: self.createdAt,
updatedAt: self.updatedAt
)
}
}
/// Platform-neutral climb session representation for backup/restore
struct BackupClimbSession: Codable {
let id: String
let gymId: String
let date: String // ISO 8601 format
let startTime: String? // ISO 8601 format
let endTime: String? // ISO 8601 format
let duration: Int64? // Duration in seconds
let status: SessionStatus
let notes: String?
let createdAt: String // ISO 8601 format
let updatedAt: String // ISO 8601 format
/// Initialize from native iOS ClimbSession model
init(from session: ClimbSession) {
self.id = session.id.uuidString
self.gymId = session.gymId.uuidString
self.status = session.status
self.notes = session.notes
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
self.date = formatter.string(from: session.date)
self.startTime = session.startTime.map { formatter.string(from: $0) }
self.endTime = session.endTime.map { formatter.string(from: $0) }
self.duration = session.duration.map { Int64($0) }
self.createdAt = formatter.string(from: session.createdAt)
self.updatedAt = formatter.string(from: session.updatedAt)
}
/// Initialize with explicit parameters for import
init(
id: String,
gymId: String,
date: String,
startTime: String?,
endTime: String?,
duration: Int64?,
status: SessionStatus,
notes: String?,
createdAt: String,
updatedAt: String
) {
self.id = id
self.gymId = gymId
self.date = date
self.startTime = startTime
self.endTime = endTime
self.duration = duration
self.status = status
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
/// Convert to native iOS ClimbSession model
func toClimbSession() throws -> ClimbSession {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
guard let uuid = UUID(uuidString: id),
let gymUuid = UUID(uuidString: gymId),
let dateValue = formatter.date(from: date),
let createdDate = formatter.date(from: createdAt),
let updatedDate = formatter.date(from: updatedAt)
else {
throw BackupError.invalidDateFormat
}
let startTimeValue = startTime.flatMap { formatter.date(from: $0) }
let endTimeValue = endTime.flatMap { formatter.date(from: $0) }
let durationValue = duration.map { Int($0) }
return ClimbSession.fromImport(
id: uuid,
gymId: gymUuid,
date: dateValue,
startTime: startTimeValue,
endTime: endTimeValue,
duration: durationValue,
status: status,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
}
/// Platform-neutral attempt representation for backup/restore
struct BackupAttempt: Codable {
let id: String
let sessionId: String
let problemId: String
let result: AttemptResult
let highestHold: String?
let notes: String?
let duration: Int64? // Duration in seconds
let restTime: Int64? // Rest time in seconds
let timestamp: String // ISO 8601 format
let createdAt: String // ISO 8601 format
/// Initialize from native iOS Attempt model
init(from attempt: Attempt) {
self.id = attempt.id.uuidString
self.sessionId = attempt.sessionId.uuidString
self.problemId = attempt.problemId.uuidString
self.result = attempt.result
self.highestHold = attempt.highestHold
self.notes = attempt.notes
self.duration = attempt.duration.map { Int64($0) }
self.restTime = attempt.restTime.map { Int64($0) }
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
self.timestamp = formatter.string(from: attempt.timestamp)
self.createdAt = formatter.string(from: attempt.createdAt)
}
/// Initialize with explicit parameters for import
init(
id: String,
sessionId: String,
problemId: String,
result: AttemptResult,
highestHold: String?,
notes: String?,
duration: Int64?,
restTime: Int64?,
timestamp: String,
createdAt: String
) {
self.id = id
self.sessionId = sessionId
self.problemId = problemId
self.result = result
self.highestHold = highestHold
self.notes = notes
self.duration = duration
self.restTime = restTime
self.timestamp = timestamp
self.createdAt = createdAt
}
/// Convert to native iOS Attempt model
func toAttempt() throws -> Attempt {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
guard let uuid = UUID(uuidString: id),
let sessionUuid = UUID(uuidString: sessionId),
let problemUuid = UUID(uuidString: problemId),
let timestampDate = formatter.date(from: timestamp),
let createdDate = formatter.date(from: createdAt)
else {
throw BackupError.invalidDateFormat
}
let durationValue = duration.map { Int($0) }
let restTimeValue = restTime.map { Int($0) }
return Attempt.fromImport(
id: uuid,
sessionId: sessionUuid,
problemId: problemUuid,
result: result,
highestHold: highestHold,
notes: notes,
duration: durationValue,
restTime: restTimeValue,
timestamp: timestampDate,
createdAt: createdDate
)
}
}
// MARK: - Backup Format Errors
enum BackupError: LocalizedError {
case invalidDateFormat
case invalidUUID
case missingRequiredField(String)
case unsupportedFormatVersion(String)
var errorDescription: String? {
switch self {
case .invalidDateFormat:
return "Invalid date format in backup data"
case .invalidUUID:
return "Invalid UUID format in backup data"
case .missingRequiredField(let field):
return "Missing required field: \(field)"
case .unsupportedFormatVersion(let version):
return "Unsupported backup format version: \(version)"
}
}
}
// MARK: - Extensions
// MARK: - Helper Extensions for Optional Mapping
extension Optional {
func map<T>(_ transform: (Wrapped) -> T) -> T? {
return self.flatMap { .some(transform($0)) }
}
}

View File

@@ -1,4 +1,3 @@
import Compression
import Foundation
import zlib
@@ -10,7 +9,7 @@ struct ZipUtils {
private static let METADATA_FILENAME = "metadata.txt"
static func createExportZip(
exportData: ClimbDataExport,
exportData: ClimbDataBackup,
referencedImagePaths: Set<String>
) throws -> Data {
@@ -196,7 +195,7 @@ struct ZipUtils {
}
private static func createMetadata(
exportData: ClimbDataExport,
exportData: ClimbDataBackup,
referencedImagePaths: Set<String>
) -> String {
return """

View File

@@ -473,13 +473,14 @@ class ClimbingDataManager: ObservableObject {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
let exportData = ClimbDataExport(
let exportData = ClimbDataBackup(
exportedAt: dateFormatter.string(from: Date()),
version: "2.0",
gyms: gyms.map { AndroidGym(from: $0) },
problems: problems.map { AndroidProblem(from: $0) },
sessions: sessions.map { AndroidClimbSession(from: $0) },
attempts: attempts.map { AndroidAttempt(from: $0) }
formatVersion: "2.0",
gyms: gyms.map { BackupGym(from: $0) },
problems: problems.map { BackupProblem(from: $0) },
sessions: sessions.map { BackupClimbSession(from: $0) },
attempts: attempts.map { BackupAttempt(from: $0) }
)
// Collect referenced image paths
@@ -529,7 +530,7 @@ class ClimbingDataManager: ObservableObject {
print("Raw JSON content preview:")
print(String(decoding: importResult.jsonData.prefix(500), as: UTF8.self) + "...")
let importData = try decoder.decode(ClimbDataExport.self, from: importResult.jsonData)
let importData = try decoder.decode(ClimbDataBackup.self, from: importResult.jsonData)
print("Successfully decoded import data:")
print("- Gyms: \(importData.gyms.count)")
@@ -546,10 +547,10 @@ class ClimbingDataManager: ObservableObject {
imagePathMapping: importResult.imagePathMapping
)
self.gyms = importData.gyms.map { $0.toGym() }
self.problems = updatedProblems.map { $0.toProblem() }
self.sessions = importData.sessions.map { $0.toClimbSession() }
self.attempts = importData.attempts.map { $0.toAttempt() }
self.gyms = try importData.gyms.map { try $0.toGym() }
self.problems = try updatedProblems.map { try $0.toProblem() }
self.sessions = try importData.sessions.map { try $0.toClimbSession() }
self.attempts = try importData.attempts.map { try $0.toAttempt() }
saveGyms()
saveProblems()
@@ -584,337 +585,6 @@ class ClimbingDataManager: ObservableObject {
}
}
struct ClimbDataExport: Codable {
let exportedAt: String
let version: String
let gyms: [AndroidGym]
let problems: [AndroidProblem]
let sessions: [AndroidClimbSession]
let attempts: [AndroidAttempt]
init(
exportedAt: String, version: String = "2.0", gyms: [AndroidGym], problems: [AndroidProblem],
sessions: [AndroidClimbSession], attempts: [AndroidAttempt]
) {
self.exportedAt = exportedAt
self.version = version
self.gyms = gyms
self.problems = problems
self.sessions = sessions
self.attempts = attempts
}
}
struct AndroidGym: Codable {
let id: String
let name: String
let location: String?
let supportedClimbTypes: [ClimbType]
let difficultySystems: [DifficultySystem]
let customDifficultyGrades: [String]
let notes: String?
let createdAt: String
let updatedAt: String
init(from gym: Gym) {
self.id = gym.id.uuidString
self.name = gym.name
self.location = gym.location
self.supportedClimbTypes = gym.supportedClimbTypes
self.difficultySystems = gym.difficultySystems
self.customDifficultyGrades = gym.customDifficultyGrades
self.notes = gym.notes
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
self.createdAt = formatter.string(from: gym.createdAt)
self.updatedAt = formatter.string(from: gym.updatedAt)
}
init(
id: String, name: String, location: String?, supportedClimbTypes: [ClimbType],
difficultySystems: [DifficultySystem], customDifficultyGrades: [String] = [],
notes: String?, createdAt: String, updatedAt: String
) {
self.id = id
self.name = name
self.location = location
self.supportedClimbTypes = supportedClimbTypes
self.difficultySystems = difficultySystems
self.customDifficultyGrades = customDifficultyGrades
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
func toGym() -> Gym {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
let gymId = UUID(uuidString: id) ?? UUID()
let createdDate = formatter.date(from: createdAt) ?? Date()
let updatedDate = formatter.date(from: updatedAt) ?? Date()
return Gym.fromImport(
id: gymId,
name: name,
location: location,
supportedClimbTypes: supportedClimbTypes,
difficultySystems: difficultySystems,
customDifficultyGrades: customDifficultyGrades,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
}
struct AndroidProblem: Codable {
let id: String
let gymId: String
let name: String?
let description: String?
let climbType: ClimbType
let difficulty: DifficultyGrade
let tags: [String]
let location: String?
let imagePaths: [String]?
let isActive: Bool
let dateSet: String?
let notes: String?
let createdAt: String
let updatedAt: String
init(from problem: Problem) {
self.id = problem.id.uuidString
self.gymId = problem.gymId.uuidString
self.name = problem.name
self.description = problem.description
self.climbType = problem.climbType
self.difficulty = problem.difficulty
self.tags = problem.tags
self.location = problem.location
self.imagePaths = problem.imagePaths.isEmpty ? nil : problem.imagePaths
self.isActive = problem.isActive
self.notes = problem.notes
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
self.dateSet = problem.dateSet != nil ? formatter.string(from: problem.dateSet!) : nil
self.createdAt = formatter.string(from: problem.createdAt)
self.updatedAt = formatter.string(from: problem.updatedAt)
}
init(
id: String, gymId: String, name: String?, description: String?, climbType: ClimbType,
difficulty: DifficultyGrade, tags: [String] = [],
location: String? = nil,
imagePaths: [String]? = nil, isActive: Bool = true, dateSet: String? = nil,
notes: String? = nil,
createdAt: String, updatedAt: String
) {
self.id = id
self.gymId = gymId
self.name = name
self.description = description
self.climbType = climbType
self.difficulty = difficulty
self.tags = tags
self.location = location
self.imagePaths = imagePaths
self.isActive = isActive
self.dateSet = dateSet
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
func toProblem() -> Problem {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
let problemId = UUID(uuidString: id) ?? UUID()
let preservedGymId = UUID(uuidString: gymId) ?? UUID()
let createdDate = formatter.date(from: createdAt) ?? Date()
let updatedDate = formatter.date(from: updatedAt) ?? Date()
return Problem.fromImport(
id: problemId,
gymId: preservedGymId,
name: name,
description: description,
climbType: climbType,
difficulty: difficulty,
tags: tags,
location: location,
imagePaths: imagePaths ?? [],
isActive: isActive,
dateSet: dateSet != nil ? formatter.date(from: dateSet!) : nil,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
func withUpdatedImagePaths(_ newImagePaths: [String]) -> AndroidProblem {
return AndroidProblem(
id: self.id,
gymId: self.gymId,
name: self.name,
description: self.description,
climbType: self.climbType,
difficulty: self.difficulty,
tags: self.tags,
location: self.location,
imagePaths: newImagePaths.isEmpty ? nil : newImagePaths,
isActive: self.isActive,
dateSet: self.dateSet,
notes: self.notes,
createdAt: self.createdAt,
updatedAt: self.updatedAt
)
}
}
struct AndroidClimbSession: Codable {
let id: String
let gymId: String
let date: String
let startTime: String?
let endTime: String?
let duration: Int64?
let status: SessionStatus
let notes: String?
let createdAt: String
let updatedAt: String
init(from session: ClimbSession) {
self.id = session.id.uuidString
self.gymId = session.gymId.uuidString
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
self.date = formatter.string(from: session.date)
self.startTime = session.startTime != nil ? formatter.string(from: session.startTime!) : nil
self.endTime = session.endTime != nil ? formatter.string(from: session.endTime!) : nil
self.duration = session.duration != nil ? Int64(session.duration!) : nil
self.status = session.status
self.notes = session.notes
self.createdAt = formatter.string(from: session.createdAt)
self.updatedAt = formatter.string(from: session.updatedAt)
}
init(
id: String, gymId: String, date: String, startTime: String?, endTime: String?,
duration: Int64?, status: SessionStatus, notes: String? = nil, createdAt: String,
updatedAt: String
) {
self.id = id
self.gymId = gymId
self.date = date
self.startTime = startTime
self.endTime = endTime
self.duration = duration
self.status = status
self.notes = notes
self.createdAt = createdAt
self.updatedAt = updatedAt
}
func toClimbSession() -> ClimbSession {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
// Preserve original IDs and dates
let sessionId = UUID(uuidString: id) ?? UUID()
let preservedGymId = UUID(uuidString: gymId) ?? UUID()
let sessionDate = formatter.date(from: date) ?? Date()
let sessionStartTime = startTime != nil ? formatter.date(from: startTime!) : nil
let sessionEndTime = endTime != nil ? formatter.date(from: endTime!) : nil
let createdDate = formatter.date(from: createdAt) ?? Date()
let updatedDate = formatter.date(from: updatedAt) ?? Date()
return ClimbSession.fromImport(
id: sessionId,
gymId: preservedGymId,
date: sessionDate,
startTime: sessionStartTime,
endTime: sessionEndTime,
duration: duration != nil ? Int(duration!) : nil,
status: status,
notes: notes,
createdAt: createdDate,
updatedAt: updatedDate
)
}
}
struct AndroidAttempt: Codable {
let id: String
let sessionId: String
let problemId: String
let result: AttemptResult
let highestHold: String?
let notes: String?
let duration: Int64?
let restTime: Int64?
let timestamp: String
let createdAt: String
init(from attempt: Attempt) {
self.id = attempt.id.uuidString
self.sessionId = attempt.sessionId.uuidString
self.problemId = attempt.problemId.uuidString
self.result = attempt.result
self.highestHold = attempt.highestHold
self.notes = attempt.notes
self.duration = attempt.duration != nil ? Int64(attempt.duration!) : nil
self.restTime = attempt.restTime != nil ? Int64(attempt.restTime!) : nil
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
self.timestamp = formatter.string(from: attempt.timestamp)
self.createdAt = formatter.string(from: attempt.createdAt)
}
init(
id: String, sessionId: String, problemId: String, result: AttemptResult,
highestHold: String?, notes: String?, duration: Int64?, restTime: Int64?,
timestamp: String, createdAt: String
) {
self.id = id
self.sessionId = sessionId
self.problemId = problemId
self.result = result
self.highestHold = highestHold
self.notes = notes
self.duration = duration
self.restTime = restTime
self.timestamp = timestamp
self.createdAt = createdAt
}
func toAttempt() -> Attempt {
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
let attemptId = UUID(uuidString: id) ?? UUID()
let preservedSessionId = UUID(uuidString: sessionId) ?? UUID()
let preservedProblemId = UUID(uuidString: problemId) ?? UUID()
let attemptTimestamp = formatter.date(from: timestamp) ?? Date()
let createdDate = formatter.date(from: createdAt) ?? Date()
return Attempt.fromImport(
id: attemptId,
sessionId: preservedSessionId,
problemId: preservedProblemId,
result: result,
highestHold: highestHold,
notes: notes,
duration: duration != nil ? Int(duration!) : nil,
restTime: restTime != nil ? Int(restTime!) : nil,
timestamp: attemptTimestamp,
createdAt: createdDate
)
}
}
extension ClimbingDataManager {
private func collectReferencedImagePaths() -> Set<String> {
var imagePaths = Set<String>()
@@ -949,9 +619,9 @@ extension ClimbingDataManager {
}
private func updateProblemImagePaths(
problems: [AndroidProblem],
problems: [BackupProblem],
imagePathMapping: [String: String]
) -> [AndroidProblem] {
) -> [BackupProblem] {
return problems.map { problem in
let updatedImagePaths = (problem.imagePaths ?? []).compactMap { oldPath in
let fileName = URL(fileURLWithPath: oldPath).lastPathComponent
@@ -1298,7 +968,7 @@ extension ClimbingDataManager {
saveAttempts()
}
private func validateImportData(_ importData: ClimbDataExport) throws {
private func validateImportData(_ importData: ClimbDataBackup) throws {
if importData.gyms.isEmpty {
throw NSError(
domain: "ImportError", code: 1,

View File

@@ -130,14 +130,8 @@ final class LiveActivityManager {
completedProblems: completedProblems
)
do {
await currentActivity.update(.init(state: updatedContentState, staleDate: nil))
print("✅ Live Activity updated successfully")
} catch {
print("❌ Failed to update Live Activity: \(error)")
// If update fails, the activity might have been dismissed
self.currentActivity = nil
}
await currentActivity.update(.init(state: updatedContentState, staleDate: nil))
print("✅ Live Activity updated successfully")
}
/// Call this when a ClimbSession ends to end the Live Activity

View File

@@ -168,15 +168,9 @@ struct ActiveSessionBanner: View {
.onDisappear {
stopTimer()
}
.background(
NavigationLink(
destination: SessionDetailView(sessionId: session.id),
isActive: $navigateToDetail
) {
EmptyView()
}
.hidden()
)
.navigationDestination(isPresented: $navigateToDetail) {
SessionDetailView(sessionId: session.id)
}
}
private func formatDuration(from start: Date, to end: Date) -> String {