Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21b7ffc7b3 | |||
| cb9fa1d3db | |||
| e59564ac07 | |||
| 0ba4fd7eb9 | |||
| 69d4257a18 | |||
| 683169e8b7 | |||
| 77d56ee6be |
@@ -58,6 +58,7 @@ enum class ConflictStrategy(val label: String) {
|
||||
enum class DeleteBehavior(val label: String, val description: String) {
|
||||
MIRROR("Mirror deletions", "Delete on target when deleted on source"),
|
||||
KEEP("Keep deleted files", "Never delete — only add/update"),
|
||||
ARCHIVE("Archive deleted", "Move files deleted from phone to _Deleted/ folder on remote"),
|
||||
}
|
||||
|
||||
enum class ScheduleType(val label: String) {
|
||||
@@ -69,5 +70,5 @@ enum class ScheduleType(val label: String) {
|
||||
}
|
||||
|
||||
enum class SyncStatus {
|
||||
IDLE, SYNCING, SUCCESS, PARTIAL, FAILED, CONFLICT,
|
||||
IDLE, SYNCING, PAUSED, SUCCESS, PARTIAL, FAILED, CONFLICT,
|
||||
}
|
||||
|
||||
@@ -156,10 +156,20 @@ class SyncEngine @Inject constructor(
|
||||
FileOutcome(deleted = 1)
|
||||
}
|
||||
SyncDecision.DELETE_REMOTE -> {
|
||||
runCatching { provider.deleteFile("${pair.remotePath}/$rel") }
|
||||
.onFailure { e -> Timber.e(e, "SyncEngine: DELETE_REMOTE failed for $rel") }
|
||||
fileStateDao.delete(pair.id, rel)
|
||||
logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "remote", 0)
|
||||
if (pair.deleteBehavior == DeleteBehavior.ARCHIVE) {
|
||||
val archivePath = "${pair.remotePath}/_Deleted/$rel"
|
||||
runCatching {
|
||||
ensureRemoteDirs(provider, "${pair.remotePath}/_Deleted", rel)
|
||||
provider.moveFile("${pair.remotePath}/$rel", archivePath).getOrThrow()
|
||||
}.onFailure { e -> Timber.e(e, "SyncEngine: ARCHIVE failed for $rel") }
|
||||
fileStateDao.delete(pair.id, rel)
|
||||
logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "archived", 0)
|
||||
} else {
|
||||
runCatching { provider.deleteFile("${pair.remotePath}/$rel") }
|
||||
.onFailure { e -> Timber.e(e, "SyncEngine: DELETE_REMOTE failed for $rel") }
|
||||
fileStateDao.delete(pair.id, rel)
|
||||
logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "remote", 0)
|
||||
}
|
||||
FileOutcome(deleted = 1)
|
||||
}
|
||||
SyncDecision.CONFLICT -> {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.syncflow.ui.addpair
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
@@ -12,6 +15,7 @@ import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
@@ -28,9 +32,20 @@ fun AddPairScreen(onDone: () -> Unit, vm: AddPairViewModel = hiltViewModel()) {
|
||||
val s by vm.state.collectAsState()
|
||||
LaunchedEffect(s.done) { if (s.done) onDone() }
|
||||
|
||||
val context = LocalContext.current
|
||||
var showRemoteBrowser by remember { mutableStateOf(false) }
|
||||
var showLocalBrowser by remember { mutableStateOf(false) }
|
||||
|
||||
val safLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
|
||||
if (uri != null) {
|
||||
context.contentResolver.takePersistableUriPermission(
|
||||
uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
|
||||
)
|
||||
vm.update { copy(localPath = uri.toString()) }
|
||||
}
|
||||
}
|
||||
|
||||
if (showLocalBrowser) {
|
||||
LocalBrowserDialog(
|
||||
initialPath = s.localPath.ifBlank { "" },
|
||||
|
||||
@@ -34,6 +34,12 @@ import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.provider.Settings
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
@@ -131,6 +137,10 @@ fun LocalBrowserDialog(
|
||||
else entries.filter { it.file.name.contains(searchQuery, ignoreCase = true) }
|
||||
|
||||
val currentFolderName = currentPath.name.ifBlank { "Internal Storage" }
|
||||
val context = LocalContext.current
|
||||
val hasAllFilesAccess = remember {
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.R || Environment.isExternalStorageManager()
|
||||
}
|
||||
|
||||
Dialog(
|
||||
onDismissRequest = onDismiss,
|
||||
@@ -192,6 +202,35 @@ fun LocalBrowserDialog(
|
||||
colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||
)
|
||||
|
||||
// ── All-files-access banner ──────────────────────────────────
|
||||
if (!hasAllFilesAccess) {
|
||||
Surface(color = MaterialTheme.colorScheme.errorContainer) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Icon(Icons.Default.Warning, null, Modifier.size(18.dp), tint = MaterialTheme.colorScheme.onErrorContainer)
|
||||
Text(
|
||||
"Grant \"All files access\" to browse and sync all folders",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onErrorContainer,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
TextButton(
|
||||
onClick = {
|
||||
val intent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||
Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION,
|
||||
Uri.fromParts("package", context.packageName, null))
|
||||
else Intent(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION)
|
||||
context.startActivity(intent)
|
||||
},
|
||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 4.dp),
|
||||
) { Text("Grant", style = MaterialTheme.typography.labelSmall) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Breadcrumbs ──────────────────────────────────────────────
|
||||
Surface(tonalElevation = 1.dp) {
|
||||
LazyRow(
|
||||
@@ -265,20 +304,20 @@ fun LocalBrowserDialog(
|
||||
// ── Select button ────────────────────────────────────────────
|
||||
Surface(tonalElevation = 4.dp, modifier = Modifier.fillMaxWidth()) {
|
||||
Column {
|
||||
Button(
|
||||
onClick = { onSelect(currentPath.absolutePath) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, top = 12.dp, end = 16.dp, bottom = 12.dp)
|
||||
.height(52.dp),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
) {
|
||||
Icon(Icons.Default.CheckCircle, null, Modifier.size(20.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text("Select \"$currentFolderName\"",
|
||||
style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
Spacer(Modifier.height(bottomInset))
|
||||
Button(
|
||||
onClick = { onSelect(currentPath.absolutePath) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, top = 12.dp, end = 16.dp, bottom = 12.dp)
|
||||
.height(52.dp),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
) {
|
||||
Icon(Icons.Default.CheckCircle, null, Modifier.size(20.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text("Select \"$currentFolderName\"",
|
||||
style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold)
|
||||
}
|
||||
Spacer(Modifier.height(bottomInset))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,9 @@ class FilesViewModel @Inject constructor(
|
||||
val pairs: StateFlow<List<SyncPairEntity>> = syncPairDao.observeAll()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
||||
|
||||
val accounts = accountRepository.observeAll()
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
||||
|
||||
private val _selectedPairId = MutableStateFlow<Long?>(null)
|
||||
|
||||
val selectedPair: StateFlow<SyncPairEntity?> = combine(_selectedPairId, pairs) { id, list ->
|
||||
@@ -158,6 +161,31 @@ class FilesViewModel @Inject constructor(
|
||||
|
||||
fun fileKey(file: SyncFileStateEntity) = "${file.syncPairId}:${file.relativePath}"
|
||||
|
||||
fun openCloudFile(accountId: Long, remotePath: String) {
|
||||
viewModelScope.launch {
|
||||
val account = accountRepository.getAccount(accountId) ?: run {
|
||||
_fileAction.emit(FileAction.Error("Account not found"))
|
||||
return@launch
|
||||
}
|
||||
val provider = providerFactory.create(account)
|
||||
val fileName = remotePath.substringAfterLast('/')
|
||||
val cacheFile = File(context.cacheDir, "syncflow_open/$fileName")
|
||||
cacheFile.parentFile?.mkdirs()
|
||||
_isDownloading.value = true
|
||||
try {
|
||||
cacheFile.outputStream().use { out ->
|
||||
provider.downloadFile(remotePath, out) { }.getOrThrow()
|
||||
}
|
||||
_fileAction.emit(FileAction.Open(cacheFile))
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Cloud open failed: $remotePath")
|
||||
_fileAction.emit(FileAction.Error("Cannot open: ${e.message}"))
|
||||
} finally {
|
||||
_isDownloading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ── Download-then-open/share ──────────────────────────────────────────────
|
||||
|
||||
private fun downloadAndOpen(file: SyncFileStateEntity) {
|
||||
|
||||
@@ -53,6 +53,7 @@ fun HomeScreen(
|
||||
onClick = { onPairClick(pair.id) },
|
||||
onSync = { vm.triggerSync(pair) },
|
||||
onToggle = { vm.toggleEnabled(pair) },
|
||||
onPause = { vm.pauseSync(pair) },
|
||||
)
|
||||
}
|
||||
item { Spacer(Modifier.height(80.dp)) }
|
||||
@@ -66,6 +67,7 @@ private fun SyncPairCard(
|
||||
onClick: () -> Unit,
|
||||
onSync: () -> Unit,
|
||||
onToggle: () -> Unit,
|
||||
onPause: () -> Unit = {},
|
||||
) {
|
||||
val accentColor = pair.lastSyncResult.accentColor
|
||||
|
||||
@@ -170,13 +172,16 @@ private fun SyncPairCard(
|
||||
animationSpec = infiniteRepeatable(tween(900, easing = LinearEasing)),
|
||||
label = "cardRotation",
|
||||
)
|
||||
FilledTonalIconButton(onClick = onSync, modifier = Modifier.size(36.dp)) {
|
||||
Icon(
|
||||
Icons.Default.Sync, "Sync now",
|
||||
modifier = Modifier.size(18.dp).graphicsLayer {
|
||||
if (pair.lastSyncResult == SyncStatus.SYNCING) rotationZ = syncRotation
|
||||
},
|
||||
)
|
||||
when (pair.lastSyncResult) {
|
||||
SyncStatus.SYNCING -> FilledTonalIconButton(onClick = onPause, modifier = Modifier.size(36.dp)) {
|
||||
Icon(Icons.Default.Pause, "Pause sync", modifier = Modifier.size(18.dp))
|
||||
}
|
||||
SyncStatus.PAUSED -> FilledTonalIconButton(onClick = onSync, modifier = Modifier.size(36.dp)) {
|
||||
Icon(Icons.Default.PlayArrow, "Resume sync", modifier = Modifier.size(18.dp))
|
||||
}
|
||||
else -> FilledTonalIconButton(onClick = onSync, modifier = Modifier.size(36.dp)) {
|
||||
Icon(Icons.Default.Sync, "Sync now", modifier = Modifier.size(18.dp).graphicsLayer { rotationZ = syncRotation * 0f })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -189,6 +194,7 @@ private fun StatusPill(status: SyncStatus) {
|
||||
val (icon, label) = when (status) {
|
||||
SyncStatus.SUCCESS -> Pair(Icons.Default.CheckCircle, "Synced")
|
||||
SyncStatus.SYNCING -> Pair(Icons.Default.Sync, "Syncing…")
|
||||
SyncStatus.PAUSED -> Pair(Icons.Default.Pause, "Paused")
|
||||
SyncStatus.FAILED -> Pair(Icons.Default.Error, "Failed")
|
||||
SyncStatus.CONFLICT -> Pair(Icons.Default.Warning, "Conflict")
|
||||
SyncStatus.PARTIAL -> Pair(Icons.Default.WarningAmber, "Partial")
|
||||
@@ -247,11 +253,12 @@ private fun EmptyState(modifier: Modifier = Modifier, onAdd: () -> Unit) {
|
||||
|
||||
private val SyncStatus.accentColor: Color
|
||||
@Composable get() = when (this) {
|
||||
SyncStatus.SUCCESS -> Color(0xFF2E7D32) // green — done, healthy
|
||||
SyncStatus.SYNCING -> Color(0xFF1565C0) // blue — in progress
|
||||
SyncStatus.FAILED -> Color(0xFFC62828) // red — error
|
||||
SyncStatus.PARTIAL -> Color(0xFFE65100) // orange — some files failed
|
||||
SyncStatus.CONFLICT -> Color(0xFFF9A825) // amber — needs resolution
|
||||
SyncStatus.SUCCESS -> Color(0xFF2E7D32)
|
||||
SyncStatus.SYNCING -> Color(0xFF1565C0)
|
||||
SyncStatus.PAUSED -> Color(0xFF6A1B9A)
|
||||
SyncStatus.FAILED -> Color(0xFFC62828)
|
||||
SyncStatus.PARTIAL -> Color(0xFFE65100)
|
||||
SyncStatus.CONFLICT -> Color(0xFFF9A825)
|
||||
SyncStatus.IDLE -> MaterialTheme.colorScheme.outline
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import androidx.work.WorkManager
|
||||
import com.syncflow.data.db.SyncPairDao
|
||||
import com.syncflow.data.db.entities.SyncPairEntity
|
||||
import com.syncflow.domain.model.ScheduleType
|
||||
import com.syncflow.domain.model.SyncStatus
|
||||
import com.syncflow.worker.FileWatchService
|
||||
import com.syncflow.worker.SyncWorker
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
@@ -32,6 +33,11 @@ class HomeViewModel @Inject constructor(
|
||||
workManager.enqueue(req)
|
||||
}
|
||||
|
||||
fun pauseSync(pair: SyncPairEntity) {
|
||||
workManager.cancelAllWorkByTag("sync_${pair.id}")
|
||||
viewModelScope.launch { syncPairDao.updateStatus(pair.id, SyncStatus.PAUSED) }
|
||||
}
|
||||
|
||||
fun toggleEnabled(pair: SyncPairEntity) {
|
||||
viewModelScope.launch {
|
||||
val nowEnabled = !pair.isEnabled
|
||||
|
||||
@@ -66,7 +66,17 @@ fun PairDetailScreen(
|
||||
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.Default.ArrowBack, "Back") } },
|
||||
actions = {
|
||||
IconButton(onClick = { pair?.let { onEdit(it.id) } }) { Icon(Icons.Default.Edit, "Edit") }
|
||||
IconButton(onClick = { vm.syncNow() }) { Icon(Icons.Default.Sync, "Sync now") }
|
||||
when (pair?.lastSyncResult) {
|
||||
SyncStatus.SYNCING -> IconButton(onClick = { vm.pauseSync() }) {
|
||||
Icon(Icons.Default.Pause, "Pause sync")
|
||||
}
|
||||
SyncStatus.PAUSED -> IconButton(onClick = { vm.syncNow() }) {
|
||||
Icon(Icons.Default.PlayArrow, "Resume sync")
|
||||
}
|
||||
else -> IconButton(onClick = { vm.syncNow() }) {
|
||||
Icon(Icons.Default.Sync, "Sync now")
|
||||
}
|
||||
}
|
||||
IconButton(onClick = { showDelete = true }) { Icon(Icons.Default.Delete, "Delete") }
|
||||
},
|
||||
)
|
||||
@@ -142,6 +152,7 @@ private fun StatusBanner(pair: SyncPairEntity) {
|
||||
val (icon, label, containerColor) = when (pair.lastSyncResult) {
|
||||
SyncStatus.SUCCESS -> Triple(Icons.Default.CheckCircle, "Synced", MaterialTheme.colorScheme.primaryContainer)
|
||||
SyncStatus.SYNCING -> Triple(Icons.Default.Sync, "Syncing…", MaterialTheme.colorScheme.secondaryContainer)
|
||||
SyncStatus.PAUSED -> Triple(Icons.Default.Pause, "Paused — tap ▶ to resume", MaterialTheme.colorScheme.surfaceVariant)
|
||||
SyncStatus.FAILED -> Triple(Icons.Default.Error, "Failed", MaterialTheme.colorScheme.errorContainer)
|
||||
SyncStatus.CONFLICT -> Triple(Icons.Default.Warning, "Conflict", MaterialTheme.colorScheme.tertiaryContainer)
|
||||
SyncStatus.PARTIAL -> Triple(Icons.Default.WarningAmber,"Partial", MaterialTheme.colorScheme.tertiaryContainer)
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.work.WorkManager
|
||||
import com.syncflow.data.db.SyncConflictDao
|
||||
import com.syncflow.data.db.SyncEventDao
|
||||
import com.syncflow.data.db.SyncPairDao
|
||||
import com.syncflow.domain.model.SyncStatus
|
||||
import com.syncflow.worker.SyncWorker
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
@@ -39,6 +40,12 @@ class PairDetailViewModel @Inject constructor(
|
||||
workManager.enqueue(SyncWorker.buildOneTimeRequest(p.id, wifiOnly = false, chargingOnly = false))
|
||||
}
|
||||
|
||||
fun pauseSync() {
|
||||
val p = pair.value ?: return
|
||||
workManager.cancelAllWorkByTag("sync_${p.id}")
|
||||
viewModelScope.launch { syncPairDao.updateStatus(p.id, SyncStatus.PAUSED) }
|
||||
}
|
||||
|
||||
fun delete() {
|
||||
viewModelScope.launch {
|
||||
pair.value?.let { syncPairDao.delete(it) }
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
VERSION_NAME=1.0.52
|
||||
VERSION_CODE=53
|
||||
VERSION_NAME=1.0.59
|
||||
VERSION_CODE=60
|
||||
|
||||
Reference in New Issue
Block a user