Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 34fb06a673 | |||
| dc2a0b2c68 | |||
| 742f634084 |
@@ -126,7 +126,9 @@ class SyncEngine @Inject constructor(
|
||||
logEvent(pair.id, SyncEventType.FILE_DOWNLOADED, rel, null, bytes)
|
||||
FileOutcome(downloaded = 1, bytesTransferred = bytes,
|
||||
newState = buildState(pair.id, rel,
|
||||
LocalFileInfo(rel, remote!!.sizeBytes, localMtime), remoteAfterTransfer = remote))
|
||||
LocalFileInfo(rel, remote!!.sizeBytes, localMtime),
|
||||
remoteAfterTransfer = remote,
|
||||
storeLocalMtime = false))
|
||||
}
|
||||
SyncDecision.DELETE_LOCAL -> {
|
||||
accessor.delete(rel)
|
||||
@@ -203,10 +205,13 @@ class SyncEngine @Inject constructor(
|
||||
rel: String,
|
||||
local: LocalFileInfo?,
|
||||
remoteAfterTransfer: RemoteFile?,
|
||||
storeLocalMtime: Boolean = true,
|
||||
) = SyncFileStateEntity(
|
||||
syncPairId = pairId,
|
||||
relativePath = rel,
|
||||
localModifiedAt = local?.lastModifiedMs?.let { Instant.ofEpochMilli(it) },
|
||||
// When storeLocalMtime=false, leave localModifiedAt null so the SKIP reconciliation
|
||||
// pass on the next sync reads it from the walkFiles cursor (avoids SAF stale-mtime loops).
|
||||
localModifiedAt = if (storeLocalMtime) local?.lastModifiedMs?.let { Instant.ofEpochMilli(it) } else null,
|
||||
localSizeBytes = local?.sizeBytes ?: 0L,
|
||||
localHash = null,
|
||||
remoteModifiedAt = remoteAfterTransfer?.modifiedAt,
|
||||
@@ -236,12 +241,16 @@ internal fun syncDecide(
|
||||
|
||||
// Treat null known timestamps as "not yet recorded" — don't treat as changed.
|
||||
// The SKIP reconciliation pass will fill them in on the next sync.
|
||||
// Use second-precision for both sides: FAT32 has 2-second mtime resolution, WebDAV
|
||||
// RFC-1123 has 1-second resolution, so millisecond comparison causes phantom "changed"
|
||||
// detections and rewrite loops after a fresh download/upload.
|
||||
val localChanged = known == null ||
|
||||
(localExists && known.localModifiedAt != null &&
|
||||
local!!.lastModifiedMs != known.localModifiedAt.toEpochMilli())
|
||||
local!!.lastModifiedMs / 1000 != known.localModifiedAt.epochSecond)
|
||||
val remoteChanged = known == null ||
|
||||
(remoteExists && known.remoteModifiedAt != null &&
|
||||
(remote!!.etag != known.remoteEtag || remote.modifiedAt != known.remoteModifiedAt))
|
||||
(remote!!.etag != known.remoteEtag ||
|
||||
remote.modifiedAt.epochSecond != known.remoteModifiedAt.epochSecond))
|
||||
|
||||
return when {
|
||||
!localExists && !remoteExists -> SyncDecision.SKIP
|
||||
|
||||
@@ -5,6 +5,7 @@ import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.syncflow.data.db.CloudAccountDao
|
||||
import com.syncflow.data.db.SyncFileStateDao
|
||||
import com.syncflow.data.db.SyncPairDao
|
||||
import com.syncflow.data.db.entities.CloudAccountEntity
|
||||
import com.syncflow.data.db.entities.SyncPairEntity
|
||||
@@ -58,6 +59,7 @@ data class AddPairUiState(
|
||||
@HiltViewModel
|
||||
class AddPairViewModel @Inject constructor(
|
||||
private val syncPairDao: SyncPairDao,
|
||||
private val fileStateDao: SyncFileStateDao,
|
||||
private val accountDao: CloudAccountDao,
|
||||
@ApplicationContext private val context: Context,
|
||||
savedState: SavedStateHandle,
|
||||
@@ -148,7 +150,20 @@ class AddPairViewModel @Inject constructor(
|
||||
notifyOnComplete = s.notifyOnComplete, notifyOnError = s.notifyOnError,
|
||||
isEnabled = true, lastSyncAt = null, lastSyncResult = SyncStatus.IDLE, pendingConflicts = 0,
|
||||
)
|
||||
if (editPairId == null) syncPairDao.insert(entity) else syncPairDao.update(entity)
|
||||
if (editPairId == null) {
|
||||
syncPairDao.insert(entity)
|
||||
} else {
|
||||
val existing = syncPairDao.getById(editPairId)
|
||||
syncPairDao.update(entity)
|
||||
// If local or remote folder changed, old file-state records no longer
|
||||
// correspond to any real path — wipe them so the next sync starts fresh
|
||||
// instead of trying to delete/re-upload stale paths.
|
||||
if (existing != null &&
|
||||
(existing.localPath != entity.localPath || existing.remotePath != entity.remotePath)
|
||||
) {
|
||||
fileStateDao.deleteForPair(editPairId)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onSuccess {
|
||||
if (s.scheduleType == ScheduleType.ON_CHANGE) FileWatchService.start(context)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.syncflow.ui.files
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
import android.webkit.MimeTypeMap
|
||||
@@ -39,8 +40,9 @@ fun FilesScreen(
|
||||
val selectedPair by vm.selectedPair.collectAsState()
|
||||
val files by vm.files.collectAsState()
|
||||
val isDownloading by vm.isDownloading.collectAsState()
|
||||
val isSelectionMode by vm.isSelectionMode.collectAsState()
|
||||
val selectedCount by vm.selectedCount.collectAsState()
|
||||
val selectedKeys by vm.selectedKeys.collectAsState()
|
||||
val isSelectionMode = selectedKeys.isNotEmpty()
|
||||
val selectedCount = selectedKeys.size
|
||||
val context = LocalContext.current
|
||||
val snackbarHostState = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
@@ -56,15 +58,18 @@ fun FilesScreen(
|
||||
val uri = FileProvider.getUriForFile(
|
||||
context, "${context.packageName}.fileprovider", action.file
|
||||
)
|
||||
val mimeType = action.file.name.mimeType()
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(uri, action.file.name.mimeType())
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
setDataAndType(uri, mimeType)
|
||||
// ClipData is required so FLAG_GRANT_READ_URI_PERMISSION
|
||||
// propagates to whichever app the system chooser picks.
|
||||
clipData = ClipData.newRawUri("", uri)
|
||||
addFlags(
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
)
|
||||
}
|
||||
context.startActivity(
|
||||
Intent.createChooser(intent, "Open with").apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
)
|
||||
context.startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
snackbarHostState.showSnackbar("Cannot open file: ${e.message}")
|
||||
}
|
||||
@@ -77,6 +82,7 @@ fun FilesScreen(
|
||||
val intent = Intent(Intent.ACTION_SEND).apply {
|
||||
type = action.file.name.mimeType()
|
||||
putExtra(Intent.EXTRA_STREAM, uri)
|
||||
clipData = ClipData.newRawUri("", uri)
|
||||
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
context.startActivity(
|
||||
@@ -252,12 +258,11 @@ fun FilesScreen(
|
||||
}
|
||||
}
|
||||
items(dirFiles, key = { "${it.syncPairId}_${it.relativePath}" }) { file ->
|
||||
val selected = vm.isSelected(file)
|
||||
FileRow(
|
||||
file = file,
|
||||
isInSubDir = dir.isNotEmpty() && !isSelectionMode,
|
||||
isSelectionMode = isSelectionMode,
|
||||
isSelected = selected,
|
||||
isSelected = vm.fileKey(file) in selectedKeys,
|
||||
vm = vm,
|
||||
)
|
||||
HorizontalDivider(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.syncflow.ui.files
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaScannerConnection
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.syncflow.data.db.SyncFileStateDao
|
||||
@@ -60,6 +61,7 @@ class FilesViewModel @Inject constructor(
|
||||
val isDownloading: StateFlow<Boolean> = _isDownloading
|
||||
|
||||
private val _selectedKeys = MutableStateFlow<Set<String>>(emptySet())
|
||||
val selectedKeys: StateFlow<Set<String>> = _selectedKeys
|
||||
val isSelectionMode: StateFlow<Boolean> = _selectedKeys.map { it.isNotEmpty() }
|
||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), false)
|
||||
val selectedCount: StateFlow<Int> = _selectedKeys.map { it.size }
|
||||
@@ -70,6 +72,8 @@ class FilesViewModel @Inject constructor(
|
||||
fun openFile(file: SyncFileStateEntity) {
|
||||
val resolved = resolveFile(file, emitErrorIfMissing = false)
|
||||
if (resolved != null) {
|
||||
// Ensure MediaStore knows about this file so gallery apps can open it
|
||||
MediaScannerConnection.scanFile(context, arrayOf(resolved.absolutePath), null, null)
|
||||
viewModelScope.launch { _fileAction.emit(FileAction.Open(resolved)) }
|
||||
} else {
|
||||
downloadAndOpen(file)
|
||||
@@ -152,7 +156,7 @@ class FilesViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun fileKey(file: SyncFileStateEntity) = "${file.syncPairId}:${file.relativePath}"
|
||||
fun fileKey(file: SyncFileStateEntity) = "${file.syncPairId}:${file.relativePath}"
|
||||
|
||||
// ── Download-then-open/share ──────────────────────────────────────────────
|
||||
|
||||
@@ -191,6 +195,7 @@ class FilesViewModel @Inject constructor(
|
||||
cacheFile.outputStream().use { out ->
|
||||
provider.downloadFile("${pair.remotePath}/${file.relativePath}", out) { }.getOrThrow()
|
||||
}
|
||||
MediaScannerConnection.scanFile(context, arrayOf(cacheFile.absolutePath), null, null)
|
||||
cacheFile
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "Download for preview failed: ${file.relativePath}")
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<gradient
|
||||
android:type="radial"
|
||||
android:gradientRadius="80%"
|
||||
android:centerX="0.5"
|
||||
android:centerY="0.4"
|
||||
android:startColor="#1B2A3B"
|
||||
android:endColor="#06090E"/>
|
||||
</shape>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
|
||||
<!-- Dark charcoal background, matching Avast-style dark icon bg -->
|
||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
||||
android:fillColor="#1F1F2E"/>
|
||||
|
||||
<!-- Very subtle inner glow -->
|
||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
||||
android:fillAlpha="0.25">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient android:type="radial"
|
||||
android:gradientRadius="60"
|
||||
android:centerX="54" android:centerY="50"
|
||||
android:startColor="#3D3A50"
|
||||
android:endColor="#00000000"/>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
|
||||
</vector>
|
||||
|
||||
@@ -1,4 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
SyncFlow icon foreground.
|
||||
Design: three bold teardrop "speed streak" shapes in Avast color palette
|
||||
(teal, red, yellow) converging on a white cloud in the centre.
|
||||
Each teardrop has a pointed tail (far from cloud) and a wide rounded head
|
||||
(near the cloud), like motion streaks flying into the sync point.
|
||||
|
||||
Safe zone: 18-90dp band. Cloud centred at (54, 55).
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:aapt="http://schemas.android.com/aapt"
|
||||
android:width="108dp"
|
||||
@@ -6,45 +15,88 @@
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
|
||||
<!--
|
||||
Circular sync icon (AutoSync-style): two 170° arcs forming a clockwise
|
||||
rotation. Arc 1 sweeps over the bottom (right→bottom→left), Arc 2 over the
|
||||
top (left→top→right). Arrowheads at the 9-o'clock and 3-o'clock gaps.
|
||||
Circle radius 26, center (54,54).
|
||||
-->
|
||||
|
||||
<!-- Arc 1: right → bottom → left (CW, small arc 170°) -->
|
||||
<!-- SHADOW layer under teardrops for depth -->
|
||||
<path
|
||||
android:pathData="M 79.9,56.3 A 26,26 0 0,1 28.1,56.3"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeWidth="9"
|
||||
android:strokeLineCap="round">
|
||||
<aapt:attr name="android:strokeColor">
|
||||
android:pathData="M 54,28 C 42,28 30,36 32,50 C 22,55 22,70 34,72 L 74,72 C 84,72 88,62 82,55 C 86,43 76,33 66,35 C 62,30 58,28 54,28 Z"
|
||||
android:fillColor="#000000"
|
||||
android:fillAlpha="0.20"
|
||||
android:translateY="2.5"/>
|
||||
|
||||
<!-- TEAL teardrop: enters from upper-left, tail at (22,22), head near cloud top-left -->
|
||||
<!-- Teardrop shape: pointed at tail, fat elliptical head, rotated ~45 deg into centre -->
|
||||
<path
|
||||
android:pathData="M 35.5,26.5
|
||||
C 30,21 22,22 22,22
|
||||
C 22,22 27,30 32.5,35.5
|
||||
C 36,38 40,40 43,42
|
||||
C 40,39 36,32 35.5,26.5 Z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient android:type="linear"
|
||||
android:startX="79.9" android:startY="56.3"
|
||||
android:endX="28.1" android:endY="56.3"
|
||||
android:startColor="#40C4FF"
|
||||
android:endColor="#00E5FF"/>
|
||||
android:startX="22" android:startY="22"
|
||||
android:endX="43" android:endY="42"
|
||||
android:startColor="#00BFA5"
|
||||
android:endColor="#26D6C0"/>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<!-- Arrowhead at left side (175°), pointing upward -->
|
||||
<path android:pathData="M 23.9,65.7 L 28.1,56.3 L 33.9,64.8 Z" android:fillColor="#00E5FF"/>
|
||||
|
||||
<!-- Arc 2: left → top → right (CW, small arc 170°) -->
|
||||
<!-- RED teardrop: enters from upper-right, tail at (86,22), head near cloud top-right -->
|
||||
<path
|
||||
android:pathData="M 28.1,51.7 A 26,26 0 0,1 79.9,51.7"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeWidth="9"
|
||||
android:strokeLineCap="round">
|
||||
<aapt:attr name="android:strokeColor">
|
||||
android:pathData="M 72.5,26.5
|
||||
C 78,21 86,22 86,22
|
||||
C 86,22 81,30 75.5,35.5
|
||||
C 72,38 68,40 65,42
|
||||
C 68,39 72,32 72.5,26.5 Z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient android:type="linear"
|
||||
android:startX="28.1" android:startY="51.7"
|
||||
android:endX="79.9" android:endY="51.7"
|
||||
android:startColor="#00E5FF"
|
||||
android:endColor="#40C4FF"/>
|
||||
android:startX="86" android:startY="22"
|
||||
android:endX="65" android:endY="42"
|
||||
android:startColor="#E53935"
|
||||
android:endColor="#EF6558"/>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
<!-- Arrowhead at right side (355°), pointing downward -->
|
||||
<path android:pathData="M 84.1,42.3 L 79.9,51.7 L 74.1,43.2 Z" android:fillColor="#40C4FF"/>
|
||||
|
||||
<!-- YELLOW teardrop: enters from bottom-centre, tail at (54,88), head near cloud base -->
|
||||
<path
|
||||
android:pathData="M 48,75
|
||||
C 45,82 47,88 54,88
|
||||
C 61,88 63,82 60,75
|
||||
C 58,71 56,68 54,66
|
||||
C 52,68 50,71 48,75 Z">
|
||||
<aapt:attr name="android:fillColor">
|
||||
<gradient android:type="linear"
|
||||
android:startX="54" android:startY="88"
|
||||
android:endX="54" android:endY="66"
|
||||
android:startColor="#F9A825"
|
||||
android:endColor="#FFD740"/>
|
||||
</aapt:attr>
|
||||
</path>
|
||||
|
||||
<!-- CLOUD body (white, centred at 54,50) -->
|
||||
<path
|
||||
android:pathData="
|
||||
M 36,62
|
||||
A 9,9 0 0,1 36,44
|
||||
A 9,9 0 0,1 45,36
|
||||
A 12,12 0 0,1 66,37
|
||||
A 8,8 0 0,1 74,48
|
||||
A 8,8 0 0,1 68,62
|
||||
Z"
|
||||
android:fillColor="#FFFFFF"/>
|
||||
|
||||
<!-- Teal highlight on cloud top-left edge -->
|
||||
<path
|
||||
android:pathData="M 36,53 A 9,9 0 0,1 41,38"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeWidth="2"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeColor="#4000BFA5"/>
|
||||
|
||||
<!-- Red highlight on cloud top-right edge -->
|
||||
<path
|
||||
android:pathData="M 63,37 A 8,8 0 0,1 73,48"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeWidth="2"
|
||||
android:strokeLineCap="round"
|
||||
android:strokeColor="#40E53935"/>
|
||||
|
||||
</vector>
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
VERSION_NAME=1.0.25
|
||||
VERSION_CODE=26
|
||||
VERSION_NAME=1.0.28
|
||||
VERSION_CODE=29
|
||||
|
||||
Reference in New Issue
Block a user