Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0ba4fd7eb9 | |||
| 69d4257a18 |
@@ -34,17 +34,6 @@ class SyncEngine @Inject constructor(
|
||||
@ApplicationContext private val context: Context,
|
||||
) {
|
||||
suspend fun sync(pair: SyncPair, provider: CloudProvider): SyncResult {
|
||||
if (!pair.localPath.startsWith("content://") &&
|
||||
pair.syncDirection != SyncDirection.UPLOAD_ONLY) {
|
||||
val canonical = runCatching { File(pair.localPath).canonicalPath }.getOrElse { pair.localPath }
|
||||
if (canonical == "/storage/emulated/0") {
|
||||
val msg = "Local folder is the storage root — Android blocks writes here. Use Upload Only direction, or select a subfolder."
|
||||
syncPairDao.updateSyncResult(pair.id, Instant.now(), SyncStatus.FAILED, 0)
|
||||
logEvent(pair.id, SyncEventType.SYNC_FAILED, null, msg, 0)
|
||||
return SyncResult(failedFiles = 1, error = Exception(msg))
|
||||
}
|
||||
}
|
||||
|
||||
syncPairDao.updateStatus(pair.id, SyncStatus.SYNCING)
|
||||
logEvent(pair.id, SyncEventType.SYNC_STARTED, null, null, 0)
|
||||
|
||||
|
||||
@@ -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 { "" },
|
||||
@@ -105,17 +120,26 @@ fun AddPairScreen(onDone: () -> Unit, vm: AddPairViewModel = hiltViewModel()) {
|
||||
|
||||
Spacer(Modifier.height(4.dp))
|
||||
|
||||
// Local folder
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
OutlinedTextField(
|
||||
value = uriToDisplay(s.localPath), onValueChange = {},
|
||||
label = { Text("Local folder") },
|
||||
leadingIcon = { Icon(Icons.Default.PhoneAndroid, null) },
|
||||
trailingIcon = { Icon(Icons.Default.FolderOpen, null) },
|
||||
readOnly = true, singleLine = true, modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = { Text("Tap to choose folder…") },
|
||||
)
|
||||
Box(modifier = Modifier.matchParentSize().clickable { showLocalBrowser = true })
|
||||
// Local folder — tap opens Android system picker (SAF), same as Autosync
|
||||
Column {
|
||||
Box(modifier = Modifier.fillMaxWidth()) {
|
||||
OutlinedTextField(
|
||||
value = uriToDisplay(s.localPath), onValueChange = {},
|
||||
label = { Text("Local folder") },
|
||||
leadingIcon = { Icon(Icons.Default.PhoneAndroid, null) },
|
||||
trailingIcon = { Icon(Icons.Default.FolderOpen, null) },
|
||||
readOnly = true, singleLine = true, modifier = Modifier.fillMaxWidth(),
|
||||
placeholder = { Text("Tap to choose folder…") },
|
||||
)
|
||||
Box(modifier = Modifier.matchParentSize().clickable { safLauncher.launch(null) })
|
||||
}
|
||||
TextButton(
|
||||
onClick = { showLocalBrowser = true },
|
||||
modifier = Modifier.align(Alignment.End),
|
||||
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 0.dp),
|
||||
) {
|
||||
Text("Browse manually", style = MaterialTheme.typography.labelSmall)
|
||||
}
|
||||
}
|
||||
|
||||
// Remote folder
|
||||
|
||||
@@ -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(
|
||||
@@ -263,23 +302,13 @@ fun LocalBrowserDialog(
|
||||
}
|
||||
|
||||
// ── Select button ────────────────────────────────────────────
|
||||
val isStorageRoot = currentPath.absolutePath == STORAGE_ROOT.absolutePath
|
||||
Surface(tonalElevation = 4.dp, modifier = Modifier.fillMaxWidth()) {
|
||||
Column {
|
||||
if (isStorageRoot) {
|
||||
Text(
|
||||
"Android blocks writes to the storage root — please open a subfolder first",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 8.dp),
|
||||
)
|
||||
}
|
||||
Button(
|
||||
onClick = { onSelect(currentPath.absolutePath) },
|
||||
enabled = !isStorageRoot,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(start = 16.dp, top = 4.dp, end = 16.dp, bottom = 12.dp)
|
||||
.padding(start = 16.dp, top = 12.dp, end = 16.dp, bottom = 12.dp)
|
||||
.height(52.dp),
|
||||
shape = RoundedCornerShape(14.dp),
|
||||
) {
|
||||
|
||||
+2
-2
@@ -1,2 +1,2 @@
|
||||
VERSION_NAME=1.0.54
|
||||
VERSION_CODE=55
|
||||
VERSION_NAME=1.0.56
|
||||
VERSION_CODE=57
|
||||
|
||||
Reference in New Issue
Block a user