Sync bug fixes across the board!
All checks were successful
Ascently - Sync Deploy / build-and-push (push) Successful in 2m15s
All checks were successful
Ascently - Sync Deploy / build-and-push (push) Successful in 2m15s
This commit is contained in:
@@ -18,8 +18,8 @@ android {
|
||||
applicationId = "com.atridad.ascently"
|
||||
minSdk = 31
|
||||
targetSdk = 36
|
||||
versionCode = 50
|
||||
versionName = "2.5.0"
|
||||
versionCode = 51
|
||||
versionName = "2.5.1"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ data class ClimbDataBackup(
|
||||
val problems: List<BackupProblem>,
|
||||
val sessions: List<BackupClimbSession>,
|
||||
val attempts: List<BackupAttempt>,
|
||||
val deletedItems: List<DeletedItem> = emptyList(),
|
||||
)
|
||||
|
||||
@Serializable
|
||||
@@ -34,6 +33,7 @@ data class BackupGym(
|
||||
@kotlinx.serialization.SerialName("customDifficultyGrades")
|
||||
val customDifficultyGrades: List<String>? = null,
|
||||
val notes: String? = null,
|
||||
val isDeleted: Boolean = false,
|
||||
val createdAt: String,
|
||||
val updatedAt: String,
|
||||
) {
|
||||
@@ -47,10 +47,26 @@ data class BackupGym(
|
||||
difficultySystems = gym.difficultySystems,
|
||||
customDifficultyGrades = gym.customDifficultyGrades.ifEmpty { null },
|
||||
notes = gym.notes,
|
||||
isDeleted = false,
|
||||
createdAt = gym.createdAt,
|
||||
updatedAt = gym.updatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
fun createTombstone(id: String, deletedAt: String): BackupGym {
|
||||
return BackupGym(
|
||||
id = id,
|
||||
name = "DELETED",
|
||||
location = null,
|
||||
supportedClimbTypes = emptyList(),
|
||||
difficultySystems = emptyList(),
|
||||
customDifficultyGrades = null,
|
||||
notes = null,
|
||||
isDeleted = true,
|
||||
createdAt = deletedAt,
|
||||
updatedAt = deletedAt,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toGym(): Gym {
|
||||
@@ -83,6 +99,7 @@ data class BackupProblem(
|
||||
val isActive: Boolean = true,
|
||||
val dateSet: String? = null,
|
||||
val notes: String? = null,
|
||||
val isDeleted: Boolean = false,
|
||||
val createdAt: String,
|
||||
val updatedAt: String,
|
||||
) {
|
||||
@@ -106,10 +123,31 @@ data class BackupProblem(
|
||||
isActive = problem.isActive,
|
||||
dateSet = problem.dateSet,
|
||||
notes = problem.notes,
|
||||
isDeleted = false,
|
||||
createdAt = problem.createdAt,
|
||||
updatedAt = problem.updatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
fun createTombstone(id: String, deletedAt: String): BackupProblem {
|
||||
return BackupProblem(
|
||||
id = id,
|
||||
gymId = "00000000-0000-0000-0000-000000000000",
|
||||
name = "DELETED",
|
||||
description = null,
|
||||
climbType = ClimbType.values().first(),
|
||||
difficulty = DifficultyGrade(DifficultySystem.values().first(), "0"),
|
||||
tags = null,
|
||||
location = null,
|
||||
imagePaths = null,
|
||||
isActive = false,
|
||||
dateSet = null,
|
||||
notes = null,
|
||||
isDeleted = true,
|
||||
createdAt = deletedAt,
|
||||
updatedAt = deletedAt,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toProblem(): Problem {
|
||||
@@ -147,6 +185,7 @@ data class BackupClimbSession(
|
||||
val duration: Long? = null,
|
||||
val status: SessionStatus,
|
||||
val notes: String? = null,
|
||||
val isDeleted: Boolean = false,
|
||||
val createdAt: String,
|
||||
val updatedAt: String,
|
||||
) {
|
||||
@@ -161,10 +200,27 @@ data class BackupClimbSession(
|
||||
duration = session.duration,
|
||||
status = session.status,
|
||||
notes = session.notes,
|
||||
isDeleted = false,
|
||||
createdAt = session.createdAt,
|
||||
updatedAt = session.updatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
fun createTombstone(id: String, deletedAt: String): BackupClimbSession {
|
||||
return BackupClimbSession(
|
||||
id = id,
|
||||
gymId = "00000000-0000-0000-0000-000000000000",
|
||||
date = deletedAt,
|
||||
startTime = null,
|
||||
endTime = null,
|
||||
duration = null,
|
||||
status = SessionStatus.values().first(),
|
||||
notes = null,
|
||||
isDeleted = true,
|
||||
createdAt = deletedAt,
|
||||
updatedAt = deletedAt,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toClimbSession(): ClimbSession {
|
||||
@@ -195,6 +251,7 @@ data class BackupAttempt(
|
||||
val duration: Long? = null,
|
||||
val restTime: Long? = null,
|
||||
val timestamp: String,
|
||||
val isDeleted: Boolean = false,
|
||||
val createdAt: String,
|
||||
val updatedAt: String? = null,
|
||||
) {
|
||||
@@ -210,10 +267,28 @@ data class BackupAttempt(
|
||||
duration = attempt.duration,
|
||||
restTime = attempt.restTime,
|
||||
timestamp = attempt.timestamp,
|
||||
isDeleted = false,
|
||||
createdAt = attempt.createdAt,
|
||||
updatedAt = attempt.updatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
fun createTombstone(id: String, deletedAt: String): BackupAttempt {
|
||||
return BackupAttempt(
|
||||
id = id,
|
||||
sessionId = "00000000-0000-0000-0000-000000000000",
|
||||
problemId = "00000000-0000-0000-0000-000000000000",
|
||||
result = AttemptResult.values().first(),
|
||||
highestHold = null,
|
||||
notes = null,
|
||||
duration = null,
|
||||
restTime = null,
|
||||
timestamp = deletedAt,
|
||||
isDeleted = true,
|
||||
createdAt = deletedAt,
|
||||
updatedAt = deletedAt,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun toAttempt(): Attempt {
|
||||
|
||||
@@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.io.File
|
||||
import java.time.Instant
|
||||
|
||||
class ClimbRepository(database: AscentlyDatabase, private val context: Context) {
|
||||
private val gymDao = database.gymDao()
|
||||
@@ -38,6 +39,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
|
||||
// Gym operations
|
||||
fun getAllGyms(): Flow<List<Gym>> = gymDao.getAllGyms()
|
||||
suspend fun getAllGymsSync(): List<Gym> = gymDao.getAllGyms().first()
|
||||
suspend fun getGymById(id: String): Gym? = gymDao.getGymById(id)
|
||||
suspend fun insertGym(gym: Gym) {
|
||||
gymDao.insertGym(gym)
|
||||
@@ -60,6 +62,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
|
||||
// Problem operations
|
||||
fun getAllProblems(): Flow<List<Problem>> = problemDao.getAllProblems()
|
||||
suspend fun getAllProblemsSync(): List<Problem> = problemDao.getAllProblems().first()
|
||||
suspend fun getProblemById(id: String): Problem? = problemDao.getProblemById(id)
|
||||
fun getProblemsByGym(gymId: String): Flow<List<Problem>> = problemDao.getProblemsByGym(gymId)
|
||||
suspend fun insertProblem(problem: Problem) {
|
||||
@@ -80,6 +83,7 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
|
||||
// Session operations
|
||||
fun getAllSessions(): Flow<List<ClimbSession>> = sessionDao.getAllSessions()
|
||||
suspend fun getAllSessionsSync(): List<ClimbSession> = sessionDao.getAllSessions().first()
|
||||
suspend fun getSessionById(id: String): ClimbSession? = sessionDao.getSessionById(id)
|
||||
fun getSessionsByGym(gymId: String): Flow<List<ClimbSession>> =
|
||||
sessionDao.getSessionsByGym(gymId)
|
||||
@@ -122,6 +126,8 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
|
||||
// Attempt operations
|
||||
fun getAllAttempts(): Flow<List<Attempt>> = attemptDao.getAllAttempts()
|
||||
suspend fun getAllAttemptsSync(): List<Attempt> = attemptDao.getAllAttempts().first()
|
||||
suspend fun getAttemptById(id: String): Attempt? = attemptDao.getAttemptById(id)
|
||||
fun getAttemptsBySession(sessionId: String): Flow<List<Attempt>> =
|
||||
attemptDao.getAttemptsBySession(sessionId)
|
||||
|
||||
@@ -273,10 +279,9 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
}
|
||||
|
||||
fun trackDeletion(itemId: String, itemType: String) {
|
||||
val currentDeletions = getDeletedItems().toMutableList()
|
||||
cleanupOldDeletions()
|
||||
val newDeletion =
|
||||
DeletedItem(id = itemId, type = itemType, deletedAt = DateFormatUtils.nowISO8601())
|
||||
currentDeletions.add(newDeletion)
|
||||
|
||||
val json = json.encodeToString(newDeletion)
|
||||
deletionPreferences.edit { putString("deleted_$itemId", json) }
|
||||
@@ -304,6 +309,27 @@ class ClimbRepository(database: AscentlyDatabase, private val context: Context)
|
||||
deletionPreferences.edit { clear() }
|
||||
}
|
||||
|
||||
private fun cleanupOldDeletions() {
|
||||
val allPrefs = deletionPreferences.all
|
||||
val cutoff = Instant.now().minusSeconds(90L * 24 * 60 * 60)
|
||||
|
||||
deletionPreferences.edit {
|
||||
for ((key, value) in allPrefs) {
|
||||
if (key.startsWith("deleted_") && value is String) {
|
||||
try {
|
||||
val deletion = json.decodeFromString<DeletedItem>(value)
|
||||
val deletedAt = Instant.parse(deletion.deletedAt)
|
||||
if (deletedAt.isBefore(cutoff)) {
|
||||
remove(key)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun validateDataIntegrity(
|
||||
gyms: List<Gym>,
|
||||
problems: List<Problem>,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,6 @@ import com.atridad.ascently.data.format.BackupAttempt
|
||||
import com.atridad.ascently.data.format.BackupClimbSession
|
||||
import com.atridad.ascently.data.format.BackupGym
|
||||
import com.atridad.ascently.data.format.BackupProblem
|
||||
import com.atridad.ascently.data.format.DeletedItem
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/** Request structure for delta sync - sends only changes since last sync */
|
||||
@@ -15,16 +14,15 @@ data class DeltaSyncRequest(
|
||||
val problems: List<BackupProblem>,
|
||||
val sessions: List<BackupClimbSession>,
|
||||
val attempts: List<BackupAttempt>,
|
||||
val deletedItems: List<DeletedItem>,
|
||||
)
|
||||
|
||||
/** Response structure for delta sync - receives only changes from server */
|
||||
@Serializable
|
||||
data class DeltaSyncResponse(
|
||||
val serverTime: String,
|
||||
val requestFullSync: Boolean = false,
|
||||
val gyms: List<BackupGym>,
|
||||
val problems: List<BackupProblem>,
|
||||
val sessions: List<BackupClimbSession>,
|
||||
val attempts: List<BackupAttempt>,
|
||||
val deletedItems: List<DeletedItem>,
|
||||
)
|
||||
|
||||
@@ -18,4 +18,6 @@ sealed class SyncException(message: String) : IOException(message), Serializable
|
||||
SyncException("Invalid server response: $details")
|
||||
|
||||
data class NetworkError(val details: String) : SyncException("Network error: $details")
|
||||
|
||||
data class General(val details: String) : SyncException(details)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import androidx.core.content.edit
|
||||
import com.atridad.ascently.data.repository.ClimbRepository
|
||||
import com.atridad.ascently.data.state.DataStateManager
|
||||
import com.atridad.ascently.utils.AppLogger
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@@ -27,7 +28,7 @@ class SyncService(private val context: Context, private val repository: ClimbRep
|
||||
}
|
||||
|
||||
// Currently we only support one provider, but this allows for future expansion
|
||||
private val provider: SyncProvider = AscentlySyncProvider(context, repository)
|
||||
private val provider: SyncProvider = AscentlySyncProvider(context, repository, DataStateManager(context))
|
||||
|
||||
// State
|
||||
private val _isSyncing = MutableStateFlow(false)
|
||||
|
||||
Reference in New Issue
Block a user