V3 S6 : confiance (révocation, quota, appareils, conflits) + import + onboarding
Backend : token_version (000022, claim tv, 401 si révoqué, bump au password — fin limite V1), quota (000023 idempotente, colonne héritée de 000001, 413 QUOTA_EXCEEDED, GET /users/me/usage), devices (GET + DELETE révocation, EnforceDeviceExists en prod), renames concurrents transparents (baseUpdatedAt + conflicts[] non-fataux, tolérance 2 s). Tests service + handlers + migrations + auth. Mobile : pipeline conflits (DTO + SyncConflictStore + worker + dialogue), baseUpdatedAt prêt, liens 7j par défaut, écran Appareils (+ quota), import classeur unifié (scan/note/dossier), onboarding cercle Famille. Contrat docs/api-v1.md, V3.md (S6 livré).
This commit is contained in:
@@ -30,11 +30,13 @@ import com.kazier.mobile.data.remote.dto.SyncOpDto
|
||||
import com.kazier.mobile.data.remote.dto.SyncOpsRequest
|
||||
import com.kazier.mobile.data.remote.dto.SyncOpsResult
|
||||
import com.kazier.mobile.data.remote.dto.CorrectFactsDto
|
||||
import com.kazier.mobile.data.remote.dto.DeviceDto
|
||||
import com.kazier.mobile.data.remote.dto.DuplicateGroupDto
|
||||
import com.kazier.mobile.data.remote.dto.FactDto
|
||||
import com.kazier.mobile.data.remote.dto.RelationDto
|
||||
import com.kazier.mobile.data.remote.dto.RelationVerdictDto
|
||||
import com.kazier.mobile.data.remote.dto.TrashDto
|
||||
import com.kazier.mobile.data.remote.dto.UsageDto
|
||||
import com.kazier.mobile.data.remote.dto.VersionDto
|
||||
import kotlin.coroutines.cancellation.CancellationException
|
||||
import okhttp3.MultipartBody
|
||||
@@ -190,6 +192,18 @@ class ApiClient @Inject constructor(
|
||||
suspend fun listDuplicates(): List<DuplicateGroupDto> =
|
||||
unwrap({ apiService.listDuplicates() })
|
||||
|
||||
/** Devices du compte — `GET /devices`. */
|
||||
suspend fun listDevices(): List<DeviceDto> =
|
||||
unwrap({ apiService.listDevices() })
|
||||
|
||||
/** Révoque un device — `DELETE /devices/:id`. */
|
||||
suspend fun revokeDevice(deviceId: String): String =
|
||||
unwrap({ apiService.revokeDevice(deviceId) }).id
|
||||
|
||||
/** Empreinte du compte — `GET /users/me/usage`. */
|
||||
suspend fun getUsage(): UsageDto =
|
||||
unwrap({ apiService.getUsage() })
|
||||
|
||||
/** Recherche serveur paginée — `GET /files/search?q=…` (+ `meta`). */
|
||||
suspend fun searchFilesPaged(
|
||||
query: String,
|
||||
|
||||
@@ -23,11 +23,13 @@ import com.kazier.mobile.data.remote.dto.ShareLinkDto
|
||||
import com.kazier.mobile.data.remote.dto.SyncOpsRequest
|
||||
import com.kazier.mobile.data.remote.dto.SyncOpsResult
|
||||
import com.kazier.mobile.data.remote.dto.CorrectFactsDto
|
||||
import com.kazier.mobile.data.remote.dto.DeviceDto
|
||||
import com.kazier.mobile.data.remote.dto.DuplicateGroupDto
|
||||
import com.kazier.mobile.data.remote.dto.FactDto
|
||||
import com.kazier.mobile.data.remote.dto.RelationDto
|
||||
import com.kazier.mobile.data.remote.dto.RelationVerdictDto
|
||||
import com.kazier.mobile.data.remote.dto.TrashDto
|
||||
import com.kazier.mobile.data.remote.dto.UsageDto
|
||||
import com.kazier.mobile.data.remote.dto.VersionDto
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
@@ -223,6 +225,20 @@ interface ApiService {
|
||||
@GET("duplicates")
|
||||
suspend fun listDuplicates(): Response<ApiEnvelope<List<DuplicateGroupDto>>>
|
||||
|
||||
/** Devices du compte (`GET /devices`, dernier login = ce compte). */
|
||||
@GET("devices")
|
||||
suspend fun listDevices(): Response<ApiEnvelope<List<DeviceDto>>>
|
||||
|
||||
/** Révoque un device (`DELETE /devices/:id`, A1 — téléphone perdu). */
|
||||
@DELETE("devices/{id}")
|
||||
suspend fun revokeDevice(
|
||||
@Path("id") deviceId: String,
|
||||
): Response<ApiEnvelope<IdResultDto>>
|
||||
|
||||
/** Empreinte du compte (`GET /users/me/usage`, calculée serveur). */
|
||||
@GET("users/me/usage")
|
||||
suspend fun getUsage(): Response<ApiEnvelope<UsageDto>>
|
||||
|
||||
/**
|
||||
* Recherche serveur (`GET /files/search?q=…`, paginé `meta`). Non consommée
|
||||
* en V1 (recherche 100 % locale via Room) — exposée pour parité contrat.
|
||||
|
||||
@@ -191,6 +191,19 @@ data class SyncOpsRequest(
|
||||
data class SyncOpsResult(
|
||||
@Json(name = "applied") val applied: Int,
|
||||
@Json(name = "failed") val failed: SyncFailedDto? = null,
|
||||
/**
|
||||
* Renames LWW appliqués malgré une base périmée (V3 S6 A4) — non-fataux,
|
||||
* le batch continue. Absent (vieux serveur) = liste vide.
|
||||
*/
|
||||
@Json(name = "conflicts") val conflicts: List<SyncConflictDto>? = null,
|
||||
)
|
||||
|
||||
/** Rename concurrent appliqué quand même (transparence, pas de CRDT). */
|
||||
data class SyncConflictDto(
|
||||
@Json(name = "operation_id") val operationId: String,
|
||||
@Json(name = "resource_id") val resourceId: String,
|
||||
@Json(name = "serverName") val serverName: String = "",
|
||||
@Json(name = "serverUpdatedAt") val serverUpdatedAt: Long = 0L,
|
||||
)
|
||||
|
||||
/** Première erreur non-idempotente du batch (arrêt du serveur). */
|
||||
@@ -335,4 +348,25 @@ data class DuplicateGroupDto(
|
||||
@Json(name = "totalBytes") val totalBytes: Long = 0L,
|
||||
@Json(name = "reclaimableBytes") val reclaimableBytes: Long = 0L,
|
||||
@Json(name = "files") val files: List<DuplicateFileDto> = emptyList(),
|
||||
)
|
||||
|
||||
/**
|
||||
* Device du compte `GET /devices` (V3 S6 A1) — dernier login = ce compte.
|
||||
* `lastSeenAt` ms epoch (null si jamais revu depuis l'enregistrement).
|
||||
*/
|
||||
data class DeviceDto(
|
||||
@Json(name = "deviceId") val deviceId: String,
|
||||
@Json(name = "lastSeenAt") val lastSeenAt: Long? = null,
|
||||
)
|
||||
|
||||
/**
|
||||
* Empreinte du compte `GET /users/me/usage` (V3 S6 A2) — calculée serveur,
|
||||
* corbeille détaillée (octets récupérables à la purge).
|
||||
*/
|
||||
data class UsageDto(
|
||||
@Json(name = "usedBytes") val usedBytes: Long = 0L,
|
||||
@Json(name = "quotaBytes") val quotaBytes: Long = 0L,
|
||||
@Json(name = "fileCount") val fileCount: Int = 0,
|
||||
@Json(name = "trashCount") val trashCount: Int = 0,
|
||||
@Json(name = "trashedBytes") val trashedBytes: Long = 0L,
|
||||
)
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.kazier.mobile.data.repository
|
||||
|
||||
import com.kazier.mobile.data.remote.ApiClient
|
||||
import com.kazier.mobile.data.remote.dto.DeviceDto
|
||||
import com.kazier.mobile.data.remote.dto.UsageDto
|
||||
import com.kazier.mobile.domain.DeviceIdentity
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Appareils + empreinte du compte (V3 S6 A1/A2).
|
||||
*
|
||||
* - `listDevices` : devices dont le dernier login est ce compte ;
|
||||
* `isCurrent` repère ce téléphone (via `DeviceIdentity`) — le bouton
|
||||
* révoquer n'apparaît jamais dessus (pas de suicide) ;
|
||||
* - `revoke` : `DELETE /devices/:id` (téléphone perdu) — avec
|
||||
* `EnforceDeviceExists`, ses tokens deviennent 401 ;
|
||||
* - `usage` : `GET /users/me/usage` (quota + corbeille détaillée).
|
||||
*/
|
||||
@Singleton
|
||||
class DevicesRepository @Inject constructor(
|
||||
private val apiClient: ApiClient,
|
||||
private val deviceIdentity: DeviceIdentity,
|
||||
) {
|
||||
|
||||
data class DeviceUi(
|
||||
val deviceId: String,
|
||||
val lastSeenAt: Long?,
|
||||
val isCurrent: Boolean,
|
||||
)
|
||||
|
||||
suspend fun listDevices(): List<DeviceUi> {
|
||||
val current = runCatching { deviceIdentity.getOrCreate() }.getOrNull()
|
||||
return apiClient.listDevices().map { dto: DeviceDto ->
|
||||
DeviceUi(
|
||||
deviceId = dto.deviceId,
|
||||
lastSeenAt = dto.lastSeenAt,
|
||||
isCurrent = current != null && dto.deviceId == current,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun revoke(deviceId: String) {
|
||||
apiClient.revokeDevice(deviceId)
|
||||
}
|
||||
|
||||
suspend fun usage(): UsageDto = apiClient.getUsage()
|
||||
}
|
||||
+10
-4
@@ -185,19 +185,25 @@ class OutboxRepository @Inject constructor(
|
||||
)
|
||||
|
||||
/**
|
||||
* Raccourci `update_metadata` — payload `{ name }` (rename d'une ressource
|
||||
* partagée, `editor+`, docs/api-v1.md §6.1). m21 : rend le rename partagé
|
||||
* émissible — l'op n'avait aucun écrivain côté client.
|
||||
* Raccourci `update_metadata` — payload `{ name, baseUpdatedAt? }`
|
||||
* (rename d'une ressource partagée, `editor+`, docs/api-v1.md §6.1).
|
||||
* `baseUpdatedAt` (ms epoch, V3 S6 A4) = `updated_at` vu par le client :
|
||||
* périmé au-delà de 2 s de tolérance → rename appliqué quand même (LWW)
|
||||
* mais signalé en `conflicts` (« renommé ailleurs »).
|
||||
*/
|
||||
suspend fun enqueueUpdateMetadata(
|
||||
resourceId: String,
|
||||
resourceType: String,
|
||||
name: String,
|
||||
baseUpdatedAt: Long? = null,
|
||||
): String = enqueue(
|
||||
operation = PendingOperationType.UPDATE_METADATA,
|
||||
resourceId = resourceId,
|
||||
resourceType = resourceType,
|
||||
payload = mapOf("name" to name),
|
||||
payload = buildMap {
|
||||
put("name", name)
|
||||
baseUpdatedAt?.let { put("baseUpdatedAt", it) }
|
||||
},
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,4 +12,6 @@ object PrefKeys {
|
||||
const val PERMISSIONS_CACHED_AT = "permissions_cached_at"
|
||||
/** Règle de rétention locale V2-5 : `all` | `last_months:N`. */
|
||||
const val RETENTION_RULE = "retention_rule"
|
||||
/** Conflits de rename LWW (S6 A4) : JSON `[{operationId,…}]`, max 10. */
|
||||
const val SYNC_CONFLICTS = "sync_conflicts"
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.kazier.mobile.domain
|
||||
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import com.kazier.mobile.data.local.dao.UserPreferenceDao
|
||||
import com.kazier.mobile.data.local.entity.UserPreferenceEntity
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
|
||||
/**
|
||||
* Conflit de rename LWW signalé par le serveur (V3 S6 A4) : un
|
||||
* `update_metadata` appliqué malgré une `baseUpdatedAt` périmée — « renommé
|
||||
* ailleurs », nom serveur gagnant. Persisté en `user_preferences`
|
||||
* (JSON, max 10, dédupliqué par `operationId`), exposé en [StateFlow] pour
|
||||
* la « liste des sync », effaçable en un tap.
|
||||
*/
|
||||
data class SyncConflict(
|
||||
val operationId: String,
|
||||
val resourceId: String,
|
||||
val serverName: String,
|
||||
val serverUpdatedAt: Long,
|
||||
val seenAt: Long,
|
||||
)
|
||||
|
||||
@Singleton
|
||||
class SyncConflictStore @Inject constructor(
|
||||
private val userPreferenceDao: UserPreferenceDao,
|
||||
moshi: Moshi,
|
||||
) {
|
||||
|
||||
private val adapter: JsonAdapter<List<SyncConflict>> = moshi.adapter(
|
||||
Types.newParameterizedType(List::class.java, SyncConflict::class.java),
|
||||
)
|
||||
|
||||
private val _conflicts = MutableStateFlow<List<SyncConflict>>(emptyList())
|
||||
val conflicts: StateFlow<List<SyncConflict>> = _conflicts.asStateFlow()
|
||||
|
||||
suspend fun load() {
|
||||
val raw = userPreferenceDao.getValue(PrefKeys.SYNC_CONFLICTS) ?: return
|
||||
_conflicts.value = runCatching { adapter.fromJson(raw).orEmpty() }.getOrDefault(emptyList())
|
||||
}
|
||||
|
||||
suspend fun addAll(incoming: List<SyncConflict>) {
|
||||
if (incoming.isEmpty()) return
|
||||
val merged = (incoming + _conflicts.value)
|
||||
.distinctBy { it.operationId }
|
||||
.take(MAX_CONFLICTS)
|
||||
_conflicts.value = merged
|
||||
persist(merged)
|
||||
}
|
||||
|
||||
suspend fun clear() {
|
||||
_conflicts.value = emptyList()
|
||||
userPreferenceDao.delete(PrefKeys.SYNC_CONFLICTS)
|
||||
}
|
||||
|
||||
private suspend fun persist(conflicts: List<SyncConflict>) {
|
||||
userPreferenceDao.upsert(
|
||||
UserPreferenceEntity(PrefKeys.SYNC_CONFLICTS, adapter.toJson(conflicts), System.currentTimeMillis()),
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MAX_CONFLICTS = 10
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,8 @@ import com.kazier.mobile.data.local.dao.PendingOperationDao
|
||||
import com.kazier.mobile.data.local.entity.PendingOpStatus
|
||||
import com.kazier.mobile.data.local.entity.PendingOperationEntity
|
||||
import com.kazier.mobile.data.local.entity.PendingOperationType
|
||||
import com.kazier.mobile.domain.SyncConflict
|
||||
import com.kazier.mobile.domain.SyncConflictStore
|
||||
import com.kazier.mobile.data.remote.ApiClient
|
||||
import com.kazier.mobile.data.remote.ApiException
|
||||
import com.kazier.mobile.data.remote.dto.SyncOpDto
|
||||
@@ -96,6 +98,7 @@ class OutboxSyncWorker @AssistedInject constructor(
|
||||
private val fileDao: FileDao,
|
||||
private val folderDao: FolderDao,
|
||||
private val tokenProvider: TokenProvider,
|
||||
private val conflictStore: SyncConflictStore,
|
||||
moshi: Moshi,
|
||||
) : CoroutineWorker(appContext, workerParams) {
|
||||
|
||||
@@ -151,6 +154,23 @@ class OutboxSyncWorker @AssistedInject constructor(
|
||||
}
|
||||
|
||||
val now = System.currentTimeMillis()
|
||||
// Conflits de rename LWW (S6 A4) : non-fataux, persistés pour la
|
||||
// « liste des sync » (« renommé ailleurs », nom serveur gagnant).
|
||||
result.conflicts.orEmpty().takeIf { it.isNotEmpty() }?.let { batchConflicts ->
|
||||
runCatching {
|
||||
conflictStore.addAll(
|
||||
batchConflicts.map {
|
||||
SyncConflict(
|
||||
operationId = it.operationId,
|
||||
resourceId = it.resourceId,
|
||||
serverName = it.serverName,
|
||||
serverUpdatedAt = it.serverUpdatedAt,
|
||||
seenAt = now,
|
||||
)
|
||||
},
|
||||
)
|
||||
}.onFailure { e -> Timber.w(e, "outbox: conflits non persistés") }
|
||||
}
|
||||
// Garde C7 : `applied` incohérent → clamp, jamais de crash.
|
||||
val appliedCount = result.applied.coerceIn(0, pending.size)
|
||||
if (appliedCount != result.applied) {
|
||||
|
||||
@@ -12,6 +12,8 @@ import com.kazier.mobile.data.repository.FolderRepository
|
||||
import com.kazier.mobile.data.repository.SaveFolderInput
|
||||
import com.kazier.mobile.data.repository.ShareRepository
|
||||
import com.kazier.mobile.data.repository.TrashRepository
|
||||
import com.kazier.mobile.domain.SyncConflict
|
||||
import com.kazier.mobile.domain.SyncConflictStore
|
||||
import com.kazier.mobile.features.ocr.OcrAutoWorker
|
||||
import com.kazier.mobile.features.saf.FileDeleter
|
||||
import com.kazier.mobile.features.saf.FolderDeleter
|
||||
@@ -53,6 +55,7 @@ class SyncViewModel @Inject constructor(
|
||||
private val pendingOperationDao: PendingOperationDao,
|
||||
private val shareRepository: ShareRepository,
|
||||
private val trashRepository: TrashRepository,
|
||||
private val conflictStore: SyncConflictStore,
|
||||
private val fileDeleter: FileDeleter,
|
||||
private val folderDeleter: FolderDeleter,
|
||||
@ApplicationContext private val appContext: Context,
|
||||
@@ -75,6 +78,8 @@ class SyncViewModel @Inject constructor(
|
||||
val failed: Int = 0,
|
||||
/** Dernières opérations (tous statuts) — « liste des sync ». */
|
||||
val operations: List<PendingOperationEntity> = emptyList(),
|
||||
/** Renames LWW concurrents (S6 A4) — « renommé ailleurs ». */
|
||||
val conflicts: List<SyncConflict> = emptyList(),
|
||||
)
|
||||
|
||||
private val _importState = MutableStateFlow(ImportState())
|
||||
@@ -88,7 +93,8 @@ class SyncViewModel @Inject constructor(
|
||||
WorkManager.getInstance(appContext).getWorkInfosForUniqueWorkFlow(OutboxSyncWorker.NAME),
|
||||
pendingOperationDao.observePendingCount(),
|
||||
pendingOperationDao.observeRecent(RECENT_LIMIT),
|
||||
) { walking, workInfos, pending, operations ->
|
||||
conflictStore.conflicts,
|
||||
) { walking, workInfos, pending, operations, conflicts ->
|
||||
// RUNNING = drain en cours ; ENQUEUED = planifié (attente réseau/backoff).
|
||||
val draining = workInfos.any { it.state == WorkInfo.State.RUNNING || it.state == WorkInfo.State.ENQUEUED }
|
||||
SyncStatus(
|
||||
@@ -96,12 +102,22 @@ class SyncViewModel @Inject constructor(
|
||||
pending = pending,
|
||||
failed = operations.count { it.status == PendingOpStatus.FAILED },
|
||||
operations = operations,
|
||||
conflicts = conflicts,
|
||||
)
|
||||
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), SyncStatus())
|
||||
|
||||
/** Efface les conflits affichés (lus et assumés). */
|
||||
fun clearConflicts() {
|
||||
viewModelScope.launch {
|
||||
runCatching { conflictStore.clear() }
|
||||
}
|
||||
}
|
||||
|
||||
/** Démarre la boucle une seule fois (idempotent). */
|
||||
fun ensureStarted() {
|
||||
if (loopJob?.isActive == true) return
|
||||
// Conflits persistés (S6 A4) : chargés pour la « liste des sync ».
|
||||
viewModelScope.launch { runCatching { conflictStore.load() } }
|
||||
// Rétention auto V2-5 : passe quotidienne périodique (KEEP).
|
||||
RetentionWorker.enqueuePeriodic(appContext)
|
||||
loopJob = viewModelScope.launch {
|
||||
|
||||
@@ -175,6 +175,7 @@ fun HeaderStatusAction(
|
||||
SyncOperationsDialog(
|
||||
status = syncStatus,
|
||||
onDismiss = { showQueue = false },
|
||||
onClearConflicts = syncViewModel::clearConflicts,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+63
-1
@@ -27,6 +27,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.kazier.mobile.R
|
||||
import com.kazier.mobile.data.local.entity.PendingOpStatus
|
||||
import com.kazier.mobile.data.local.entity.PendingOperationEntity
|
||||
import com.kazier.mobile.domain.SyncConflict
|
||||
import com.kazier.mobile.features.sync.SyncViewModel
|
||||
import com.kazier.mobile.ui.theme.ErrorDark
|
||||
import com.kazier.mobile.ui.theme.ErrorLight
|
||||
@@ -38,12 +39,14 @@ import com.kazier.mobile.ui.theme.SyncingLight
|
||||
|
||||
/**
|
||||
* Dialogue « liste des sync » : dernières opérations de l'outbox (tous statuts),
|
||||
* avec un résumé (en attente / échouées) en tête de liste.
|
||||
* avec un résumé (en attente / échouées) en tête de liste — plus les renames
|
||||
* concurrents LWW (S6 A4, « renommé ailleurs », effaçables).
|
||||
*/
|
||||
@Composable
|
||||
internal fun SyncOperationsDialog(
|
||||
status: SyncViewModel.SyncStatus,
|
||||
onDismiss: () -> Unit,
|
||||
onClearConflicts: () -> Unit = {},
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
@@ -51,6 +54,12 @@ internal fun SyncOperationsDialog(
|
||||
text = {
|
||||
Column {
|
||||
SyncListSummary(status)
|
||||
if (status.conflicts.isNotEmpty()) {
|
||||
ConflictsSection(
|
||||
conflicts = status.conflicts,
|
||||
onClear = onClearConflicts,
|
||||
)
|
||||
}
|
||||
if (status.operations.isEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.sync_list_empty),
|
||||
@@ -158,4 +167,57 @@ private fun operationLabel(operation: String): String = when (operation) {
|
||||
"delete_resource" -> stringResource(R.string.sync_op_delete)
|
||||
"update_metadata" -> stringResource(R.string.sync_op_update)
|
||||
else -> operation
|
||||
}
|
||||
|
||||
/**
|
||||
* Renames concurrents LWW (S6 A4) : nom serveur gagnant + effacement en un
|
||||
* tap (lus et assumés). La liste est courte (max 10, persistée).
|
||||
*/
|
||||
@Composable
|
||||
private fun ConflictsSection(
|
||||
conflicts: List<SyncConflict>,
|
||||
onClear: () -> Unit,
|
||||
) {
|
||||
Column(modifier = Modifier.padding(bottom = 8.dp)) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.sync_conflicts_title, conflicts.size),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
TextButton(onClick = onClear) {
|
||||
Text(stringResource(R.string.sync_conflicts_clear))
|
||||
}
|
||||
}
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.heightIn(max = KazierDimens.DialogListMaxHeight / 2),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
items(conflicts, key = { it.operationId }) { conflict ->
|
||||
Column(modifier = Modifier.padding(vertical = 4.dp)) {
|
||||
Text(
|
||||
text = stringResource(
|
||||
R.string.sync_conflict_renamed,
|
||||
conflict.serverName,
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.Medium,
|
||||
)
|
||||
Text(
|
||||
text = android.text.format.DateUtils
|
||||
.getRelativeTimeSpanString(conflict.serverUpdatedAt).toString(),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,14 @@ import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CheckCircle
|
||||
import androidx.compose.material.icons.filled.DocumentScanner
|
||||
import androidx.compose.material.icons.filled.Group
|
||||
import androidx.compose.material.icons.filled.Sync
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SmallFloatingActionButton
|
||||
import androidx.compose.material3.Text
|
||||
@@ -60,10 +63,15 @@ fun DashboardScreen(
|
||||
) {
|
||||
val connectionStatus by connectionStatusViewModel.status.collectAsStateWithLifecycle()
|
||||
val unprocessed by viewModel.unprocessedCount.collectAsStateWithLifecycle()
|
||||
val groupCount by viewModel.groupCount.collectAsStateWithLifecycle()
|
||||
val creatingCircle by viewModel.creatingCircle.collectAsStateWithLifecycle()
|
||||
val syncStatus by syncViewModel.syncStatus.collectAsStateWithLifecycle()
|
||||
// Mode local : rien n'est poussé vers le serveur, la carte sync est inutile.
|
||||
val isLocal = connectionStatus == ServerConnectionStatus.Local
|
||||
val showSyncCard = !isLocal && (syncStatus.syncing || syncStatus.pending > 0 || syncStatus.failed > 0)
|
||||
// Onboarding foyer B5 : en ligne, aucun cercle → proposition « Famille ».
|
||||
val showFamilyCard = !isLocal &&
|
||||
connectionStatus == ServerConnectionStatus.Online && groupCount == 0
|
||||
|
||||
// Tirer-pour-actualiser = revérifier le serveur (review + file sont déjà
|
||||
// temps réel via les flows, il n'y a rien d'autre à recharger ici).
|
||||
@@ -131,6 +139,13 @@ fun DashboardScreen(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
if (showFamilyCard) {
|
||||
FamilyCircleCard(
|
||||
creating = creatingCircle,
|
||||
onCreate = { viewModel.createFamilyCircle(it) },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
if (showSyncCard) {
|
||||
SyncSummaryCard(
|
||||
status = syncStatus,
|
||||
@@ -229,3 +244,75 @@ private fun SyncSummaryCard(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Onboarding foyer B5 : aucun cercle et en ligne → proposition de créer le
|
||||
* cercle « Famille » en un tap (nom éditable, pré-rempli). Disparaît après
|
||||
* création (compteur rechargé) ou hors-ligne.
|
||||
*/
|
||||
@Composable
|
||||
private fun FamilyCircleCard(
|
||||
creating: Boolean,
|
||||
onCreate: (String) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
var name by rememberSaveable { mutableStateOf("") }
|
||||
// Pré-remplissage paresseux une fois (pas d'écrasement de la saisie).
|
||||
val defaultName = stringResource(R.string.family_default_name)
|
||||
LaunchedEffect(defaultName) {
|
||||
if (name.isBlank()) name = defaultName
|
||||
}
|
||||
KazierCard(modifier = modifier) {
|
||||
Column(
|
||||
modifier = Modifier.padding(20.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Group,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(28.dp),
|
||||
)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = stringResource(R.string.family_title),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.family_hint),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(top = 4.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = name,
|
||||
onValueChange = { name = it },
|
||||
label = { Text(stringResource(R.string.family_name)) },
|
||||
singleLine = true,
|
||||
enabled = !creating,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
Button(
|
||||
onClick = { onCreate(name.trim()) },
|
||||
enabled = !creating && name.trim().isNotEmpty(),
|
||||
) {
|
||||
if (creating) {
|
||||
CircularProgressIndicator(modifier = Modifier.size(20.dp))
|
||||
} else {
|
||||
Text(stringResource(R.string.family_create))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,61 @@ package com.kazier.mobile.ui.dashboard
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.kazier.mobile.data.remote.ApiClient
|
||||
import com.kazier.mobile.data.repository.FileRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class DashboardViewModel @Inject constructor(
|
||||
fileRepository: FileRepository,
|
||||
private val apiClient: ApiClient,
|
||||
) : ViewModel() {
|
||||
|
||||
/** Nombre de documents locaux restant à traiter (mode review). */
|
||||
val unprocessedCount: StateFlow<Int> = fileRepository.observeUnprocessedCount()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), initialValue = 0)
|
||||
|
||||
/**
|
||||
* Onboarding foyer B5 : nombre de groupes (cercles) du compte, NULL tant
|
||||
* que non chargé ou hors-ligne (best-effort — jamais bloquant, jamais
|
||||
* d'erreur visible : la carte s'affiche seulement si 0 avéré en ligne).
|
||||
*/
|
||||
private val _groupCount = MutableStateFlow<Int?>(null)
|
||||
val groupCount: StateFlow<Int?> = _groupCount.asStateFlow()
|
||||
|
||||
private val _creatingCircle = MutableStateFlow(false)
|
||||
val creatingCircle: StateFlow<Boolean> = _creatingCircle.asStateFlow()
|
||||
|
||||
init {
|
||||
refreshGroups()
|
||||
}
|
||||
|
||||
fun refreshGroups() {
|
||||
viewModelScope.launch {
|
||||
runCatching { apiClient.listGroups() }
|
||||
.onSuccess { groups -> _groupCount.update { groups.size } }
|
||||
.onFailure { e -> Timber.d("dashboard groups skipped: %s", e.message) }
|
||||
}
|
||||
}
|
||||
|
||||
/** Crée le cercle « Famille » en un tap (puis recharge le compteur). */
|
||||
fun createFamilyCircle(name: String) {
|
||||
if (_creatingCircle.value) return
|
||||
viewModelScope.launch {
|
||||
_creatingCircle.value = true
|
||||
runCatching { apiClient.createGroup(name) }
|
||||
.onSuccess { refreshGroups() }
|
||||
.onFailure { e -> Timber.w(e, "dashboard create circle failed") }
|
||||
_creatingCircle.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package com.kazier.mobile.ui.devices
|
||||
|
||||
import android.text.format.DateUtils
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.PhoneAndroid
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.kazier.mobile.R
|
||||
import com.kazier.mobile.data.repository.DevicesRepository
|
||||
import com.kazier.mobile.ui.components.formatFileSize
|
||||
|
||||
/**
|
||||
* Appareils du compte (V3 S6 A1) : ce téléphone repéré (« cet appareil »,
|
||||
* jamais révocable), les autres révocables après confirmation (téléphone
|
||||
* perdu — leurs tokens deviennent 401). Tête : quota utilisé.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun DevicesScreen(
|
||||
onBack: () -> Unit,
|
||||
viewModel: DevicesViewModel = hiltViewModel(),
|
||||
) {
|
||||
val state by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
LaunchedEffect(state.error) {
|
||||
state.error?.let {
|
||||
snackbarHostState.showSnackbar(it)
|
||||
viewModel.clearError()
|
||||
}
|
||||
}
|
||||
var pendingRevoke by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
|
||||
pendingRevoke?.let { deviceId ->
|
||||
AlertDialog(
|
||||
onDismissRequest = { pendingRevoke = null },
|
||||
title = { Text(stringResource(R.string.devices_revoke_confirm_title)) },
|
||||
text = { Text(stringResource(R.string.devices_revoke_confirm_message)) },
|
||||
confirmButton = {
|
||||
TextButton(onClick = {
|
||||
pendingRevoke = null
|
||||
viewModel.revoke(deviceId)
|
||||
}) { Text(stringResource(R.string.devices_revoke_confirm)) }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { pendingRevoke = null }) {
|
||||
Text(stringResource(R.string.delete_cancel))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text(stringResource(R.string.devices_title)) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onBack) {
|
||||
Icon(
|
||||
Icons.AutoMirrored.Filled.ArrowBack,
|
||||
contentDescription = stringResource(R.string.back),
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHostState) },
|
||||
) { padding ->
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize().padding(padding),
|
||||
contentPadding = PaddingValues(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
state.usage?.let { usage ->
|
||||
item(key = "usage") {
|
||||
UsageCard(
|
||||
usedBytes = usage.usedBytes,
|
||||
quotaBytes = usage.quotaBytes,
|
||||
fileCount = usage.fileCount,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (state.isLoading && state.devices.isEmpty()) {
|
||||
item(key = "loading") {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth().padding(32.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
CircularProgressIndicator()
|
||||
}
|
||||
}
|
||||
}
|
||||
items(state.devices, key = { it.deviceId }) { device ->
|
||||
DeviceRow(
|
||||
device = device,
|
||||
onRevoke = { pendingRevoke = device.deviceId },
|
||||
)
|
||||
}
|
||||
if (!state.isLoading && state.devices.isEmpty()) {
|
||||
item(key = "empty") {
|
||||
Text(
|
||||
text = stringResource(R.string.devices_empty),
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center,
|
||||
modifier = Modifier.fillMaxWidth().padding(32.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun UsageCard(usedBytes: Long, quotaBytes: Long, fileCount: Int) {
|
||||
val fraction = if (quotaBytes > 0) (usedBytes.toFloat() / quotaBytes).coerceIn(0f, 1f) else 0f
|
||||
Card(modifier = Modifier.fillMaxWidth()) {
|
||||
Column(modifier = Modifier.padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Text(
|
||||
text = stringResource(
|
||||
R.string.devices_usage,
|
||||
formatFileSize(usedBytes),
|
||||
formatFileSize(quotaBytes),
|
||||
fileCount,
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
fontWeight = FontWeight.Medium,
|
||||
)
|
||||
LinearProgressIndicator(
|
||||
progress = { fraction },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun DeviceRow(
|
||||
device: DevicesRepository.DeviceUi,
|
||||
onRevoke: () -> Unit,
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.PhoneAndroid,
|
||||
contentDescription = null,
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.size(28.dp),
|
||||
)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = if (device.isCurrent) {
|
||||
stringResource(R.string.devices_current)
|
||||
} else {
|
||||
stringResource(R.string.devices_other, device.deviceId.take(8))
|
||||
},
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
fontWeight = FontWeight.Medium,
|
||||
)
|
||||
device.lastSeenAt?.let { seen ->
|
||||
Text(
|
||||
text = DateUtils.getRelativeTimeSpanString(seen).toString(),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (!device.isCurrent) {
|
||||
IconButton(onClick = onRevoke) {
|
||||
Icon(
|
||||
Icons.Filled.Delete,
|
||||
contentDescription = stringResource(R.string.devices_revoke),
|
||||
tint = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.kazier.mobile.ui.devices
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.kazier.mobile.data.remote.dto.UsageDto
|
||||
import com.kazier.mobile.data.repository.DevicesRepository
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Appareils du compte + empreinte (V3 S6 A1/A2) : liste (ce téléphone
|
||||
* repéré, jamais révocable), révocation d'un device perdu (avec confirmation),
|
||||
* quota utilisé affiché en tête.
|
||||
*/
|
||||
@HiltViewModel
|
||||
class DevicesViewModel @Inject constructor(
|
||||
private val devicesRepository: DevicesRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
data class DevicesUiState(
|
||||
val isLoading: Boolean = false,
|
||||
val devices: List<DevicesRepository.DeviceUi> = emptyList(),
|
||||
val usage: UsageDto? = null,
|
||||
val error: String? = null,
|
||||
)
|
||||
|
||||
private val _uiState = MutableStateFlow(DevicesUiState())
|
||||
val uiState: StateFlow<DevicesUiState> = _uiState.asStateFlow()
|
||||
|
||||
init {
|
||||
refresh()
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
viewModelScope.launch {
|
||||
_uiState.update { it.copy(isLoading = true, error = null) }
|
||||
val devices = runCatching { devicesRepository.listDevices() }
|
||||
val usage = runCatching { devicesRepository.usage() }
|
||||
devices.onFailure { e -> Timber.d("devices list failed: %s", e.message) }
|
||||
usage.onFailure { e -> Timber.d("usage failed: %s", e.message) }
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isLoading = false,
|
||||
devices = devices.getOrDefault(emptyList()),
|
||||
usage = usage.getOrNull(),
|
||||
error = (devices.exceptionOrNull() ?: usage.exceptionOrNull())
|
||||
?.let { e -> e.message ?: e.javaClass.simpleName },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun clearError() {
|
||||
_uiState.update { it.copy(error = null) }
|
||||
}
|
||||
|
||||
/** Révoque un device perdu (jamais celui-ci — le bouton est masqué). */
|
||||
fun revoke(deviceId: String) {
|
||||
viewModelScope.launch {
|
||||
runCatching { devicesRepository.revoke(deviceId) }
|
||||
.onSuccess { refresh() }
|
||||
.onFailure { e ->
|
||||
Timber.w(e, "devices revoke failed")
|
||||
_uiState.update { it.copy(error = e.message ?: e.javaClass.simpleName) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,6 +229,23 @@ fun FolderListScreen(
|
||||
syncViewModel.importRoot(uri = uri.toString(), name = rootName)
|
||||
}
|
||||
|
||||
// B1 : « classeur » unifié — le menu + accueille aussi l'ajout d'un
|
||||
// dossier surveillé (même importRoot que l'onboarding, sans la création
|
||||
// du sous-dossier « Kazier » réservée à la racine par défaut).
|
||||
val pickWatchLauncher = rememberLauncherForActivityResult(
|
||||
ActivityResultContracts.OpenDocumentTree(),
|
||||
) { uri: Uri? ->
|
||||
if (uri == null) return@rememberLauncherForActivityResult
|
||||
runCatching {
|
||||
context.contentResolver.takePersistableUriPermission(
|
||||
uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
|
||||
)
|
||||
}.onFailure { Timber.w(it, "persistable permission absent on watch pick") }
|
||||
val rootName = uri.safDisplayName(context) ?: uri.lastPathSegment ?: folderLabel
|
||||
syncViewModel.importRoot(uri = uri.toString(), name = rootName)
|
||||
}
|
||||
|
||||
// Attend la création de la racine (importRoot la sauvegarde puis lance le
|
||||
// walk), crée le sous-dossier « Kazier » et l'enregistre comme racine.
|
||||
LaunchedEffect(pendingDefaultPick) {
|
||||
@@ -450,6 +467,14 @@ fun FolderListScreen(
|
||||
showNoteDialog = true
|
||||
},
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.create_option_watch)) },
|
||||
leadingIcon = { Icon(Icons.Filled.Folder, contentDescription = null) },
|
||||
onClick = {
|
||||
showCreateMenu = false
|
||||
pickWatchLauncher.launch(null)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.kazier.mobile.ui.settings.SettingsScreen
|
||||
import com.kazier.mobile.ui.share.OpenLinkScreen
|
||||
import com.kazier.mobile.ui.trash.TrashScreen
|
||||
import com.kazier.mobile.ui.duplicates.DuplicatesScreen
|
||||
import com.kazier.mobile.ui.devices.DevicesScreen
|
||||
import com.kazier.mobile.ui.watchedfolders.WatchedFoldersScreen
|
||||
|
||||
object Routes {
|
||||
@@ -42,6 +43,7 @@ object Routes {
|
||||
const val WATCHED_FOLDERS = "watched"
|
||||
const val TRASH = "trash"
|
||||
const val DUPLICATES = "duplicates"
|
||||
const val DEVICES = "devices"
|
||||
const val FOLDER_DETAIL = "folder/{folderResourceId}"
|
||||
const val ARG_FOLDER = "folderResourceId"
|
||||
const val DOCUMENT = "document/{documentResourceId}"
|
||||
@@ -152,6 +154,7 @@ fun NavGraph(
|
||||
onOpenWatchedFolders = onOpenWatchedFolders,
|
||||
onOpenTrash = { navController.navigate(Routes.TRASH) },
|
||||
onOpenDuplicates = { navController.navigate(Routes.DUPLICATES) },
|
||||
onOpenDevices = { navController.navigate(Routes.DEVICES) },
|
||||
authViewModel = authViewModel,
|
||||
connectionStatusViewModel = connectionStatusViewModel,
|
||||
syncViewModel = syncViewModel,
|
||||
@@ -195,6 +198,11 @@ fun NavGraph(
|
||||
onBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable(Routes.DEVICES) {
|
||||
DevicesScreen(
|
||||
onBack = { navController.popBackStack() },
|
||||
)
|
||||
}
|
||||
composable(
|
||||
route = Routes.FOLDER_DETAIL,
|
||||
arguments = listOf(
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CloudOff
|
||||
import androidx.compose.material.icons.filled.ContentCopy
|
||||
import androidx.compose.material.icons.filled.DarkMode
|
||||
import androidx.compose.material.icons.filled.PhoneAndroid
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Dns
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
@@ -73,6 +74,7 @@ fun SettingsScreen(
|
||||
onOpenWatchedFolders: () -> Unit,
|
||||
onOpenTrash: () -> Unit,
|
||||
onOpenDuplicates: () -> Unit,
|
||||
onOpenDevices: () -> Unit,
|
||||
authViewModel: AuthViewModel,
|
||||
connectionStatusViewModel: ConnectionStatusViewModel,
|
||||
syncViewModel: SyncViewModel,
|
||||
@@ -173,6 +175,14 @@ fun SettingsScreen(
|
||||
onClick = onOpenDuplicates,
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
SettingsRow(
|
||||
icon = { Icon(Icons.Filled.PhoneAndroid, contentDescription = null) },
|
||||
title = stringResource(R.string.devices_title),
|
||||
subtitle = stringResource(R.string.devices_hint),
|
||||
onClick = onOpenDevices,
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
SettingsRow(
|
||||
icon = { Icon(Icons.Filled.Dns, contentDescription = null) },
|
||||
|
||||
@@ -519,6 +519,13 @@ private fun LinksSection(
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
maxLines = 2,
|
||||
)
|
||||
link.expiresAt?.let { expiry ->
|
||||
Text(
|
||||
text = stringResource(R.string.share_link_expires, expiry),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
OutlinedButton(onClick = {
|
||||
clipboard.setText(AnnotatedString(link.url))
|
||||
Toast.makeText(context, context.getString(R.string.share_link_copied), Toast.LENGTH_SHORT).show()
|
||||
|
||||
@@ -295,23 +295,30 @@ class ShareViewModel @Inject constructor(
|
||||
|
||||
/**
|
||||
* Crée un lien public (`create_link`, token 32-hex généré localement).
|
||||
* Le lien est exposé en [ShareUiState.lastCreatedLink] pour copie.
|
||||
* Expiration par défaut 7j (V3 S6 — un lien permanent est un RIB qui
|
||||
* traîne ; révocable à tout moment). Le lien est exposé en
|
||||
* [ShareUiState.lastCreatedLink] pour copie.
|
||||
*/
|
||||
fun createLink(resourceId: String, resourceType: String, access: String) {
|
||||
viewModelScope.launch {
|
||||
_uiState.update { it.copy(actionError = null, lastCreatedLink = null) }
|
||||
val token = generateId.newResourceId()
|
||||
val expiresAt = System.currentTimeMillis() + LINK_DEFAULT_TTL_MS
|
||||
runCatching {
|
||||
outboxRepository.enqueueCreateLink(
|
||||
resourceId = resourceId,
|
||||
resourceType = resourceType,
|
||||
token = token,
|
||||
access = access,
|
||||
expiresAt = expiresAt,
|
||||
)
|
||||
}.onSuccess {
|
||||
OutboxSyncWorker.enqueue(appContext)
|
||||
val expiryLabel = java.text.DateFormat
|
||||
.getDateInstance(java.text.DateFormat.SHORT)
|
||||
.format(java.util.Date(expiresAt))
|
||||
_uiState.update {
|
||||
it.copy(lastCreatedLink = ShareLinkUi(token, access, null, ShareLinkParser.shareUrl(token)))
|
||||
it.copy(lastCreatedLink = ShareLinkUi(token, access, expiryLabel, ShareLinkParser.shareUrl(token)))
|
||||
}
|
||||
refreshPending(resourceId)
|
||||
}.onFailure { e ->
|
||||
@@ -521,6 +528,11 @@ class ShareViewModel @Inject constructor(
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Expiration par défaut des liens créés : 7 jours (V3 S6). */
|
||||
const val LINK_DEFAULT_TTL_MS = 7L * 24 * 60 * 60 * 1000
|
||||
}
|
||||
}
|
||||
|
||||
/** Quadruplet local (pas de Tuple4 stdlib en Kotlin). */
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<string name="new_folder_error">Could not create the folder.</string>
|
||||
<string name="create_option_scan">Scan a document</string>
|
||||
<string name="create_option_note">Add a note</string>
|
||||
<string name="create_option_watch">Watch a folder</string>
|
||||
<string name="create_option_title">Add</string>
|
||||
<string name="note_dialog_title">New note</string>
|
||||
<string name="note_title_label">Title</string>
|
||||
@@ -344,6 +345,7 @@
|
||||
<string name="share_link_created">Link created — copy it before closing.</string>
|
||||
<string name="share_link_copy">Copy</string>
|
||||
<string name="share_link_copied">Link copied.</string>
|
||||
<string name="share_link_expires">Expires %1$s (7 days by default).</string>
|
||||
<string name="share_link_revoke_confirm">Revoke this link? It will stop working.</string>
|
||||
<string name="share_open_link_hint">Paste a received link or token</string>
|
||||
<string name="share_open_link_button">Open</string>
|
||||
@@ -453,4 +455,25 @@
|
||||
<string name="collection_delete_title">Delete “%1$s”?</string>
|
||||
<string name="collection_delete_message">The collection disappears from this device.</string>
|
||||
<string name="collection_delete_confirm">Delete</string>
|
||||
<!-- Rename conflicts V3 S6 A4 -->
|
||||
<string name="sync_conflicts_title">Renamed elsewhere (%1$d)</string>
|
||||
<string name="sync_conflicts_clear">Clear</string>
|
||||
<string name="sync_conflict_renamed">“%1$s” (server name kept)</string>
|
||||
<!-- Devices V3 S6 A1 -->
|
||||
<string name="devices_title">Devices</string>
|
||||
<string name="devices_hint">View and revoke connected devices</string>
|
||||
<string name="devices_empty">No registered devices.</string>
|
||||
<string name="devices_current">This device</string>
|
||||
<string name="devices_other">Device %1$s…</string>
|
||||
<string name="devices_revoke">Revoke this device</string>
|
||||
<string name="devices_revoke_confirm_title">Revoke this device?</string>
|
||||
<string name="devices_revoke_confirm_message">Its sessions will be signed out and it must re-register.</string>
|
||||
<string name="devices_revoke_confirm">Revoke</string>
|
||||
<string name="devices_usage">%1$s / %2$s (%3$d files)</string>
|
||||
<!-- Family onboarding V3 S6 B5 -->
|
||||
<string name="family_title">Create your Family circle</string>
|
||||
<string name="family_hint">Share your papers with loved ones in one tap.</string>
|
||||
<string name="family_name">Circle name</string>
|
||||
<string name="family_default_name">Family</string>
|
||||
<string name="family_create">Create</string>
|
||||
</resources>
|
||||
@@ -43,6 +43,7 @@
|
||||
<string name="new_folder_error">Impossible de créer le dossier.</string>
|
||||
<string name="create_option_scan">Scanner un document</string>
|
||||
<string name="create_option_note">Ajouter une note</string>
|
||||
<string name="create_option_watch">Surveiller un dossier</string>
|
||||
<string name="create_option_title">Ajouter</string>
|
||||
<string name="note_dialog_title">Nouvelle note</string>
|
||||
<string name="note_title_label">Titre</string>
|
||||
@@ -345,6 +346,7 @@
|
||||
<string name="share_link_created">Lien créé — copiez-le avant de fermer.</string>
|
||||
<string name="share_link_copy">Copier</string>
|
||||
<string name="share_link_copied">Lien copié.</string>
|
||||
<string name="share_link_expires">Expire le %1$s (7 jours par défaut).</string>
|
||||
<string name="share_link_revoke_confirm">Révoquer ce lien ? Il ne fonctionnera plus.</string>
|
||||
<string name="share_open_link_hint">Collez un lien ou un token reçu</string>
|
||||
<string name="share_open_link_button">Ouvrir</string>
|
||||
@@ -454,4 +456,25 @@
|
||||
<string name="collection_delete_title">Supprimer « %1$s » ?</string>
|
||||
<string name="collection_delete_message">La collection disparaît de cet appareil.</string>
|
||||
<string name="collection_delete_confirm">Supprimer</string>
|
||||
<!-- Conflits rename V3 S6 A4 -->
|
||||
<string name="sync_conflicts_title">Renommés ailleurs (%1$d)</string>
|
||||
<string name="sync_conflicts_clear">Effacer</string>
|
||||
<string name="sync_conflict_renamed">« %1$s » (nom serveur conservé)</string>
|
||||
<!-- Appareils V3 S6 A1 -->
|
||||
<string name="devices_title">Appareils</string>
|
||||
<string name="devices_hint">Voir et révoquer les appareils connectés</string>
|
||||
<string name="devices_empty">Aucun appareil enregistré.</string>
|
||||
<string name="devices_current">Cet appareil</string>
|
||||
<string name="devices_other">Appareil %1$s…</string>
|
||||
<string name="devices_revoke">Révoquer cet appareil</string>
|
||||
<string name="devices_revoke_confirm_title">Révoquer cet appareil ?</string>
|
||||
<string name="devices_revoke_confirm_message">Ses sessions seront déconnectées et il devra se ré-enregistrer.</string>
|
||||
<string name="devices_revoke_confirm">Révoquer</string>
|
||||
<string name="devices_usage">%1$s / %2$s (%3$d fichiers)</string>
|
||||
<!-- Onboarding foyer V3 S6 B5 -->
|
||||
<string name="family_title">Crée ton cercle Famille</string>
|
||||
<string name="family_hint">Partage tes papiers avec tes proches en un tap.</string>
|
||||
<string name="family_name">Nom du cercle</string>
|
||||
<string name="family_default_name">Famille</string>
|
||||
<string name="family_create">Créer</string>
|
||||
</resources>
|
||||
@@ -357,6 +357,15 @@ class Auth401Test {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
@@ -231,6 +231,15 @@ class PaginationTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
@@ -159,6 +159,15 @@ class RemoteContentTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<FileDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
|
||||
@@ -365,6 +365,15 @@ class SessionReloginTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<FileDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
|
||||
@@ -198,6 +198,15 @@ class ShareManagementTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<FileDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
|
||||
@@ -292,6 +292,15 @@ class BytesUploadTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<FileDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
|
||||
+3
@@ -195,6 +195,9 @@ class FactsRepositoryTest {
|
||||
override suspend fun listRelations(fileId: String): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.RelationDto>>> = TODO()
|
||||
override suspend fun verdictRelation(fileId: String, body: com.kazier.mobile.data.remote.dto.RelationVerdictDto): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.RelationDto>>> = TODO()
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> = TODO()
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> = TODO()
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> = TODO()
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.FileDto>>> = TODO()
|
||||
override suspend fun changePassword(body: com.kazier.mobile.data.remote.dto.ChangePasswordDto): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getShareLink(token: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.ShareLinkDto>> = TODO()
|
||||
|
||||
+9
@@ -417,6 +417,15 @@ private class FolderMergeApiService : ApiService {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
+3
@@ -155,6 +155,9 @@ class LinksRepositoryTest {
|
||||
override suspend fun listFacts(fileId: String): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.FactDto>>> = TODO()
|
||||
override suspend fun correctFacts(fileId: String, body: com.kazier.mobile.data.remote.dto.CorrectFactsDto): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.FactDto>>> = TODO()
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> = TODO()
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> = TODO()
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> = TODO()
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.FileDto>>> = TODO()
|
||||
override suspend fun changePassword(body: com.kazier.mobile.data.remote.dto.ChangePasswordDto): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getShareLink(token: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.ShareLinkDto>> = TODO()
|
||||
|
||||
+9
@@ -506,6 +506,15 @@ private class MoveProtectionApiService : ApiService {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
@@ -418,6 +418,15 @@ private class OcrApiServiceFake : ApiService {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
+9
@@ -300,6 +300,15 @@ class OfflineDownloadTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): Response<ApiEnvelope<List<FileDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
|
||||
@@ -273,6 +273,15 @@ private class RefreshVsMoveApiService : ApiService {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
+9
@@ -527,6 +527,15 @@ private class FakeApiService : ApiService {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
Response.success(ApiEnvelope(data = emptyList()))
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
Response.success(ApiEnvelope())
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
Response.success(ApiEnvelope(data = com.kazier.mobile.data.remote.dto.UsageDto()))
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.kazier.mobile.domain
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Room
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
||||
import com.kazier.mobile.data.local.AppDatabase
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
/**
|
||||
* Conflits LWW (S6 A4) : persistance JSON (max 10, dédupliqués), rechargement,
|
||||
* effacement.
|
||||
*/
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(sdk = [34])
|
||||
class SyncConflictStoreTest {
|
||||
|
||||
private lateinit var db: AppDatabase
|
||||
private lateinit var store: SyncConflictStore
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
val context = ApplicationProvider.getApplicationContext<Context>()
|
||||
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
|
||||
.allowMainThreadQueries()
|
||||
.build()
|
||||
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
store = SyncConflictStore(db.userPreferenceDao(), moshi)
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
db.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun ajout_persiste_et_recharge() = runTest {
|
||||
store.addAll(
|
||||
listOf(
|
||||
SyncConflict("op1", "res1", "v3.txt", 1000L, 2000L),
|
||||
SyncConflict("op2", "res2", "w.txt", 1000L, 2000L),
|
||||
),
|
||||
)
|
||||
assertEquals(2, store.conflicts.first().size)
|
||||
|
||||
// Nouveau store sur la même DB : recharge.
|
||||
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
val reloaded = SyncConflictStore(db.userPreferenceDao(), moshi)
|
||||
reloaded.load()
|
||||
val list = reloaded.conflicts.first()
|
||||
assertEquals(2, list.size)
|
||||
assertEquals("v3.txt", list[0].serverName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dedupe_par_operation_et_plafond() = runTest {
|
||||
val many = (1..12).map { SyncConflict("op$it", "r$it", "n$it", 1L, 2L) }
|
||||
store.addAll(many)
|
||||
assertEquals(10, store.conflicts.first().size)
|
||||
|
||||
// Re-ajout du même : pas de doublon, ordre conservé (récents d'abord).
|
||||
store.addAll(listOf(SyncConflict("op1", "r1", "n1", 1L, 3L)))
|
||||
val list = store.conflicts.first()
|
||||
assertEquals(10, list.size)
|
||||
assertEquals("op1", list[0].operationId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun effacement() = runTest {
|
||||
store.addAll(listOf(SyncConflict("op1", "r1", "n", 1L, 2L)))
|
||||
store.clear()
|
||||
assertTrue(store.conflicts.first().isEmpty())
|
||||
}
|
||||
}
|
||||
@@ -164,6 +164,9 @@ class ReleaseLocalCopyTest {
|
||||
override suspend fun listRelations(fileId: String): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<List<com.kazier.mobile.data.remote.dto.RelationDto>>> = TODO()
|
||||
override suspend fun verdictRelation(fileId: String, body: com.kazier.mobile.data.remote.dto.RelationVerdictDto): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<List<com.kazier.mobile.data.remote.dto.RelationDto>>> = TODO()
|
||||
override suspend fun listDuplicates(): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> = TODO()
|
||||
override suspend fun listDevices(): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> = TODO()
|
||||
override suspend fun revokeDevice(deviceId: String): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getUsage(): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> = TODO()
|
||||
override suspend fun searchFiles(query: String, page: Int?, pageSize: Int?): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<List<com.kazier.mobile.data.remote.dto.FileDto>>> = TODO()
|
||||
override suspend fun changePassword(body: com.kazier.mobile.data.remote.dto.ChangePasswordDto): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> = TODO()
|
||||
override suspend fun getShareLink(token: String): retrofit2.Response<com.kazier.mobile.data.remote.dto.ApiEnvelope<com.kazier.mobile.data.remote.dto.ShareLinkDto>> = TODO()
|
||||
|
||||
+43
-3
@@ -27,6 +27,8 @@ import com.kazier.mobile.data.remote.ApiClient
|
||||
import com.kazier.mobile.data.remote.ApiException
|
||||
import com.kazier.mobile.data.remote.ApiService
|
||||
import com.kazier.mobile.data.remote.dto.ApiEnvelope
|
||||
import com.kazier.mobile.data.remote.dto.SyncConflictDto
|
||||
import com.kazier.mobile.domain.SyncConflictStore
|
||||
import com.kazier.mobile.data.remote.dto.AddGroupMemberDto
|
||||
import com.kazier.mobile.data.remote.dto.CreateGroupDto
|
||||
import com.kazier.mobile.data.remote.dto.GroupDto
|
||||
@@ -95,6 +97,7 @@ class OutboxSyncWorkerTest {
|
||||
private lateinit var fake: FakeApiService
|
||||
private lateinit var apiClient: ApiClient
|
||||
private lateinit var tokenProvider: TokenProvider
|
||||
private lateinit var conflictStore: SyncConflictStore
|
||||
private lateinit var worker: OutboxSyncWorker
|
||||
|
||||
@Before
|
||||
@@ -114,9 +117,10 @@ class OutboxSyncWorkerTest {
|
||||
fake = FakeApiService()
|
||||
apiClient = ApiClient(fake, moshi)
|
||||
tokenProvider = TokenProvider().apply { current = "test-token" }
|
||||
conflictStore = SyncConflictStore(db.userPreferenceDao(), moshi)
|
||||
worker = OutboxSyncWorker(
|
||||
context, workerParams(), apiClient, opsDao, fileDao, folderDao,
|
||||
tokenProvider, moshi,
|
||||
tokenProvider, conflictStore, moshi,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -252,8 +256,7 @@ class OutboxSyncWorkerTest {
|
||||
assertEquals(0, opsDao.countPending())
|
||||
}
|
||||
|
||||
// --- C7 : gardes ----------------------------------------------------------
|
||||
@Test
|
||||
// --- C7 : gardes ---------------------------------------------------------- @Test
|
||||
fun failed_inconnu_pas_de_boucle() = runTest {
|
||||
insertOp(opId(1))
|
||||
insertOp(opId(2))
|
||||
@@ -376,6 +379,34 @@ class OutboxSyncWorkerTest {
|
||||
)
|
||||
}
|
||||
|
||||
// --- S6 A4 : conflits LWW persistés, batch non bloqué ---------------------
|
||||
|
||||
@Test
|
||||
fun conflits_rename_persites_sans_bloquer() = runTest {
|
||||
insertOp(opId(1))
|
||||
val conflict = SyncConflictDto(opId(1), resId(1), "v3.txt", 1_700_000_000_1000L)
|
||||
fake.syncOpsHandler = {
|
||||
Response.success(
|
||||
ApiEnvelope(
|
||||
data = com.kazier.mobile.data.remote.dto.SyncOpsResult(
|
||||
applied = 1,
|
||||
failed = null,
|
||||
conflicts = listOf(conflict),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
val result = worker.doWork()
|
||||
|
||||
assertTrue(result is ListenableWorker.Result.Success)
|
||||
assertEquals(PendingOpStatus.SYNCED, opsDao.observeRecent(100).first().first().status)
|
||||
val stored = conflictStore.conflicts.first()
|
||||
assertEquals(1, stored.size)
|
||||
assertEquals(opId(1), stored[0].operationId)
|
||||
assertEquals("v3.txt", stored[0].serverName)
|
||||
}
|
||||
|
||||
// --- fixtures --------------------------------------------------------------
|
||||
|
||||
private suspend fun insertOp(
|
||||
@@ -522,6 +553,15 @@ class OutboxSyncWorkerTest {
|
||||
override suspend fun listDuplicates(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DuplicateGroupDto>>> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override suspend fun listDevices(): Response<ApiEnvelope<List<com.kazier.mobile.data.remote.dto.DeviceDto>>> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override suspend fun revokeDevice(deviceId: String): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.IdResultDto>> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override suspend fun getUsage(): Response<ApiEnvelope<com.kazier.mobile.data.remote.dto.UsageDto>> =
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
override suspend fun searchFiles(
|
||||
query: String,
|
||||
page: Int?,
|
||||
|
||||
@@ -215,8 +215,88 @@ class SearchFieldTest {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* S6 facettes : la saisie émetteur filtre les résultats FTS après
|
||||
* debounce (triggers posés à la main — hors migration en in-memory).
|
||||
*/
|
||||
@Test
|
||||
fun facette_emetteur_filtre_les_resultats() = runTest {
|
||||
Dispatchers.setMain(StandardTestDispatcher(testScheduler))
|
||||
try {
|
||||
val raw = db.openHelper.writableDatabase
|
||||
for (trigger in com.kazier.mobile.data.local.fts.FtsTriggers.TRIGGERS) {
|
||||
raw.execSQL(trigger)
|
||||
}
|
||||
fileRepository.saveLocalFile(
|
||||
input = SaveFileInput(
|
||||
uri = "content://tree/a",
|
||||
name = "a.pdf",
|
||||
extension = "pdf",
|
||||
size = 10,
|
||||
mimeType = "application/pdf",
|
||||
resourceId = RESOURCE_A,
|
||||
processed = true,
|
||||
),
|
||||
folderResourceId = FOLDER,
|
||||
)
|
||||
fileRepository.saveLocalFile(
|
||||
input = SaveFileInput(
|
||||
uri = "content://tree/b",
|
||||
name = "b.pdf",
|
||||
extension = "pdf",
|
||||
size = 10,
|
||||
mimeType = "application/pdf",
|
||||
resourceId = RESOURCE_B,
|
||||
processed = true,
|
||||
),
|
||||
folderResourceId = FOLDER,
|
||||
)
|
||||
db.fileDao().updateOcrText(RESOURCE_A, "facture EDF", 1L)
|
||||
db.fileDao().updateOcrText(RESOURCE_B, "facture ENGIE", 1L)
|
||||
db.factsDao().insertAll(
|
||||
listOf(
|
||||
com.kazier.mobile.data.local.entity.ResourceFact(
|
||||
resourceId = RESOURCE_A, factType = "issuer",
|
||||
valueText = "EDF", confidence = 0.9,
|
||||
origin = "auto", updatedAt = 1L,
|
||||
),
|
||||
com.kazier.mobile.data.local.entity.ResourceFact(
|
||||
resourceId = RESOURCE_B, factType = "issuer",
|
||||
valueText = "ENGIE", confidence = 0.9,
|
||||
origin = "auto", updatedAt = 1L,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val viewModel = newViewModel()
|
||||
backgroundScope.launch { viewModel.uiState.collect {} }
|
||||
viewModel.onQueryChange("facture")
|
||||
advanceTimeBy(400)
|
||||
withContext(Dispatchers.IO) {
|
||||
withTimeout(10_000) {
|
||||
viewModel.uiState.first { it.results.size == 2 }
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.onIssuerChange("edf")
|
||||
advanceTimeBy(400)
|
||||
val filtered = withContext(Dispatchers.IO) {
|
||||
withTimeout(10_000) {
|
||||
viewModel.uiState.first {
|
||||
it.results.size == 1 && it.results[0].resourceId == RESOURCE_A
|
||||
}
|
||||
}
|
||||
}
|
||||
assertEquals(1, filtered.activeFacetCount)
|
||||
} finally {
|
||||
Dispatchers.resetMain()
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val FOLDER = "f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0"
|
||||
const val RESOURCE_ID = "aabbccddeeff11223344556677889900"
|
||||
const val RESOURCE_A = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
const val RESOURCE_B = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user