Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21b7ffc7b3 | |||
| cb9fa1d3db | |||
| e59564ac07 | |||
| 0ba4fd7eb9 | |||
| 69d4257a18 | |||
| 683169e8b7 | |||
| 77d56ee6be | |||
| 99193af2c5 | |||
| 3c008ec8df | |||
| c869f84a9d | |||
| c3be23417d | |||
| ae10ed0c82 |
@@ -13,6 +13,8 @@ import okhttp3.*
|
|||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import okio.BufferedSink
|
||||||
|
import okio.source
|
||||||
import org.xmlpull.v1.XmlPullParser
|
import org.xmlpull.v1.XmlPullParser
|
||||||
import org.xmlpull.v1.XmlPullParserFactory
|
import org.xmlpull.v1.XmlPullParserFactory
|
||||||
import java.io.InputStream
|
import java.io.InputStream
|
||||||
@@ -84,13 +86,18 @@ open class WebDavProvider(protected val account: CloudAccount) : CloudProvider {
|
|||||||
onProgress: (Long) -> Unit,
|
onProgress: (Long) -> Unit,
|
||||||
): Result<RemoteFile> = runCatching {
|
): Result<RemoteFile> = runCatching {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val bytes = localStream.readBytes()
|
val body = object : RequestBody() {
|
||||||
val body = bytes.toRequestBody("application/octet-stream".toMediaType())
|
override fun contentType() = "application/octet-stream".toMediaType()
|
||||||
|
override fun contentLength() = sizeBytes
|
||||||
|
override fun writeTo(sink: BufferedSink) {
|
||||||
|
localStream.source().use { source -> sink.writeAll(source) }
|
||||||
|
}
|
||||||
|
}
|
||||||
val req = Request.Builder().url(url(remotePath)).put(body).build()
|
val req = Request.Builder().url(url(remotePath)).put(body).build()
|
||||||
client.newCall(req).execute().use { resp ->
|
client.newCall(req).execute().use { resp ->
|
||||||
if (!resp.isSuccessful) throw Exception("Upload HTTP ${resp.code}")
|
if (!resp.isSuccessful) throw Exception("Upload HTTP ${resp.code}")
|
||||||
}
|
}
|
||||||
onProgress(bytes.size.toLong())
|
onProgress(sizeBytes)
|
||||||
getFileMetadata(remotePath).getOrThrow()
|
getFileMetadata(remotePath).getOrThrow()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ enum class ConflictStrategy(val label: String) {
|
|||||||
enum class DeleteBehavior(val label: String, val description: String) {
|
enum class DeleteBehavior(val label: String, val description: String) {
|
||||||
MIRROR("Mirror deletions", "Delete on target when deleted on source"),
|
MIRROR("Mirror deletions", "Delete on target when deleted on source"),
|
||||||
KEEP("Keep deleted files", "Never delete — only add/update"),
|
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) {
|
enum class ScheduleType(val label: String) {
|
||||||
@@ -69,5 +70,5 @@ enum class ScheduleType(val label: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum class SyncStatus {
|
enum class SyncStatus {
|
||||||
IDLE, SYNCING, SUCCESS, PARTIAL, FAILED, CONFLICT,
|
IDLE, SYNCING, PAUSED, SUCCESS, PARTIAL, FAILED, CONFLICT,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,11 +107,10 @@ class SyncEngine @Inject constructor(
|
|||||||
|
|
||||||
when (decision) {
|
when (decision) {
|
||||||
SyncDecision.UPLOAD -> {
|
SyncDecision.UPLOAD -> {
|
||||||
var uploadedRemoteFile: RemoteFile? = null
|
|
||||||
val bytes = runCatching {
|
val bytes = runCatching {
|
||||||
ensureRemoteDirs(provider, pair.remotePath, rel)
|
ensureRemoteDirs(provider, pair.remotePath, rel)
|
||||||
accessor.openInputStream(rel)?.use { stream ->
|
accessor.openInputStream(rel)?.use { stream ->
|
||||||
uploadedRemoteFile = provider.uploadFile(stream, "${pair.remotePath}/$rel", local!!.sizeBytes) { }.getOrThrow()
|
provider.uploadFile(stream, "${pair.remotePath}/$rel", local!!.sizeBytes) { }.getOrThrow()
|
||||||
}
|
}
|
||||||
local!!.sizeBytes
|
local!!.sizeBytes
|
||||||
}.getOrElse { e ->
|
}.getOrElse { e ->
|
||||||
@@ -120,8 +119,12 @@ class SyncEngine @Inject constructor(
|
|||||||
return@withPermit FileOutcome(failed = 1)
|
return@withPermit FileOutcome(failed = 1)
|
||||||
}
|
}
|
||||||
logEvent(pair.id, SyncEventType.FILE_UPLOADED, rel, null, bytes)
|
logEvent(pair.id, SyncEventType.FILE_UPLOADED, rel, null, bytes)
|
||||||
|
// Don't store remote metadata from upload response — the server (Nextcloud etc.)
|
||||||
|
// may change mtime/etag during post-upload processing. Leaving remoteModifiedAt
|
||||||
|
// null forces the SKIP reconciliation on the next sync to fill it in from the
|
||||||
|
// directory listing, which is the same source all future syncs will use.
|
||||||
FileOutcome(uploaded = 1, bytesTransferred = bytes,
|
FileOutcome(uploaded = 1, bytesTransferred = bytes,
|
||||||
newState = buildState(pair.id, rel, local!!, remoteAfterTransfer = uploadedRemoteFile))
|
newState = buildState(pair.id, rel, local!!, remoteAfterTransfer = null))
|
||||||
}
|
}
|
||||||
SyncDecision.DOWNLOAD -> {
|
SyncDecision.DOWNLOAD -> {
|
||||||
val bytes = runCatching {
|
val bytes = runCatching {
|
||||||
@@ -153,10 +156,20 @@ class SyncEngine @Inject constructor(
|
|||||||
FileOutcome(deleted = 1)
|
FileOutcome(deleted = 1)
|
||||||
}
|
}
|
||||||
SyncDecision.DELETE_REMOTE -> {
|
SyncDecision.DELETE_REMOTE -> {
|
||||||
runCatching { provider.deleteFile("${pair.remotePath}/$rel") }
|
if (pair.deleteBehavior == DeleteBehavior.ARCHIVE) {
|
||||||
.onFailure { e -> Timber.e(e, "SyncEngine: DELETE_REMOTE failed for $rel") }
|
val archivePath = "${pair.remotePath}/_Deleted/$rel"
|
||||||
fileStateDao.delete(pair.id, rel)
|
runCatching {
|
||||||
logEvent(pair.id, SyncEventType.FILE_DELETED, rel, "remote", 0)
|
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)
|
FileOutcome(deleted = 1)
|
||||||
}
|
}
|
||||||
SyncDecision.CONFLICT -> {
|
SyncDecision.CONFLICT -> {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package com.syncflow.ui.addpair
|
package com.syncflow.ui.addpair
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
|
||||||
import androidx.activity.compose.rememberLauncherForActivityResult
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
@@ -22,6 +22,7 @@ import androidx.compose.ui.text.input.KeyboardType
|
|||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.syncflow.domain.model.*
|
import com.syncflow.domain.model.*
|
||||||
|
import com.syncflow.ui.browser.LocalBrowserDialog
|
||||||
import com.syncflow.ui.browser.RemoteBrowserDialog
|
import com.syncflow.ui.browser.RemoteBrowserDialog
|
||||||
import java.time.DayOfWeek
|
import java.time.DayOfWeek
|
||||||
|
|
||||||
@@ -33,17 +34,29 @@ fun AddPairScreen(onDone: () -> Unit, vm: AddPairViewModel = hiltViewModel()) {
|
|||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
var showRemoteBrowser by remember { mutableStateOf(false) }
|
var showRemoteBrowser by remember { mutableStateOf(false) }
|
||||||
|
var showLocalBrowser by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
val dirPicker = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri: Uri? ->
|
val safLauncher = rememberLauncherForActivityResult(ActivityResultContracts.OpenDocumentTree()) { uri ->
|
||||||
uri?.let {
|
if (uri != null) {
|
||||||
context.contentResolver.takePersistableUriPermission(
|
context.contentResolver.takePersistableUriPermission(
|
||||||
it,
|
uri,
|
||||||
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
|
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION,
|
||||||
)
|
)
|
||||||
vm.update { copy(localPath = it.toString()) }
|
vm.update { copy(localPath = uri.toString()) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (showLocalBrowser) {
|
||||||
|
LocalBrowserDialog(
|
||||||
|
initialPath = s.localPath.ifBlank { "" },
|
||||||
|
onSelect = { path ->
|
||||||
|
vm.update { copy(localPath = path) }
|
||||||
|
showLocalBrowser = false
|
||||||
|
},
|
||||||
|
onDismiss = { showLocalBrowser = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (showRemoteBrowser && s.selectedAccountId != -1L) {
|
if (showRemoteBrowser && s.selectedAccountId != -1L) {
|
||||||
RemoteBrowserDialog(
|
RemoteBrowserDialog(
|
||||||
accountId = s.selectedAccountId,
|
accountId = s.selectedAccountId,
|
||||||
@@ -108,18 +121,17 @@ fun AddPairScreen(onDone: () -> Unit, vm: AddPairViewModel = hiltViewModel()) {
|
|||||||
Spacer(Modifier.height(4.dp))
|
Spacer(Modifier.height(4.dp))
|
||||||
|
|
||||||
// Local folder
|
// Local folder
|
||||||
OutlinedTextField(
|
Box(modifier = Modifier.fillMaxWidth()) {
|
||||||
value = uriToDisplay(s.localPath), onValueChange = {},
|
OutlinedTextField(
|
||||||
label = { Text("Local folder") },
|
value = uriToDisplay(s.localPath), onValueChange = {},
|
||||||
leadingIcon = { Icon(Icons.Default.PhoneAndroid, null) },
|
label = { Text("Local folder") },
|
||||||
trailingIcon = {
|
leadingIcon = { Icon(Icons.Default.PhoneAndroid, null) },
|
||||||
IconButton(onClick = { dirPicker.launch(null) }) {
|
trailingIcon = { Icon(Icons.Default.FolderOpen, null) },
|
||||||
Icon(Icons.Default.FolderOpen, "Browse")
|
readOnly = true, singleLine = true, modifier = Modifier.fillMaxWidth(),
|
||||||
}
|
placeholder = { Text("Tap to choose folder…") },
|
||||||
},
|
)
|
||||||
readOnly = true, singleLine = true, modifier = Modifier.fillMaxWidth(),
|
Box(modifier = Modifier.matchParentSize().clickable { showLocalBrowser = true })
|
||||||
placeholder = { Text("Tap to choose folder…") },
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// Remote folder
|
// Remote folder
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
|
|||||||
@@ -0,0 +1,391 @@
|
|||||||
|
package com.syncflow.ui.browser
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
|
import androidx.compose.material.icons.filled.*
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.graphics.vector.ImageVector
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
|
import androidx.compose.ui.unit.Dp
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
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
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
private data class LocalEntry(val file: File, val childCount: Int)
|
||||||
|
|
||||||
|
private val STORAGE_ROOT = File("/storage/emulated/0")
|
||||||
|
|
||||||
|
private data class Shortcut(val label: String, val icon: ImageVector, val path: String)
|
||||||
|
private val SHORTCUTS = listOf(
|
||||||
|
Shortcut("Camera", Icons.Default.PhotoCamera, "/storage/emulated/0/DCIM/Camera"),
|
||||||
|
Shortcut("Downloads", Icons.Default.Download, "/storage/emulated/0/Download"),
|
||||||
|
Shortcut("Documents", Icons.Default.Description, "/storage/emulated/0/Documents"),
|
||||||
|
Shortcut("Pictures", Icons.Default.Image, "/storage/emulated/0/Pictures"),
|
||||||
|
Shortcut("Music", Icons.Default.MusicNote, "/storage/emulated/0/Music"),
|
||||||
|
Shortcut("Videos", Icons.Default.Videocam, "/storage/emulated/0/Movies"),
|
||||||
|
)
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun LocalBrowserDialog(
|
||||||
|
initialPath: String = STORAGE_ROOT.absolutePath,
|
||||||
|
onSelect: (path: String) -> Unit,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
) {
|
||||||
|
var currentPath by remember { mutableStateOf(File(initialPath.ifBlank { STORAGE_ROOT.absolutePath }).let { if (it.isDirectory) it else STORAGE_ROOT }) }
|
||||||
|
var pathStack by remember { mutableStateOf(listOf(currentPath)) }
|
||||||
|
var entries by remember { mutableStateOf<List<LocalEntry>>(emptyList()) }
|
||||||
|
var isLoading by remember { mutableStateOf(true) }
|
||||||
|
var searchQuery by remember { mutableStateOf("") }
|
||||||
|
var searchActive by remember { mutableStateOf(false) }
|
||||||
|
val breadcrumbState = rememberLazyListState()
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
fun loadDir(dir: File) {
|
||||||
|
isLoading = true
|
||||||
|
entries = emptyList()
|
||||||
|
scope.launch {
|
||||||
|
val result = withContext(Dispatchers.IO) {
|
||||||
|
dir.listFiles()
|
||||||
|
?.filter { it.isDirectory && !it.name.startsWith(".") }
|
||||||
|
?.sortedBy { it.name.lowercase() }
|
||||||
|
?.map { f -> LocalEntry(f, f.listFiles()?.count { it.isDirectory } ?: 0) }
|
||||||
|
?: emptyList()
|
||||||
|
}
|
||||||
|
entries = result
|
||||||
|
isLoading = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun navigateTo(dir: File) {
|
||||||
|
currentPath = dir
|
||||||
|
pathStack = pathStack + dir
|
||||||
|
searchQuery = ""
|
||||||
|
searchActive = false
|
||||||
|
loadDir(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun navigateUp(): Boolean {
|
||||||
|
if (pathStack.size <= 1) return false
|
||||||
|
val newStack = pathStack.dropLast(1)
|
||||||
|
pathStack = newStack
|
||||||
|
currentPath = newStack.last()
|
||||||
|
searchQuery = ""
|
||||||
|
searchActive = false
|
||||||
|
loadDir(currentPath)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
fun navigateToBreadcrumb(dir: File) {
|
||||||
|
val idx = pathStack.indexOfLast { it.absolutePath == dir.absolutePath }
|
||||||
|
pathStack = if (idx >= 0) pathStack.take(idx + 1) else listOf(dir)
|
||||||
|
currentPath = dir
|
||||||
|
searchQuery = ""
|
||||||
|
searchActive = false
|
||||||
|
loadDir(dir)
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) { loadDir(currentPath) }
|
||||||
|
|
||||||
|
// Build breadcrumb segments relative to storage root
|
||||||
|
val relParts = currentPath.absolutePath
|
||||||
|
.removePrefix(STORAGE_ROOT.absolutePath)
|
||||||
|
.trimStart('/')
|
||||||
|
.split('/')
|
||||||
|
.filter { it.isNotEmpty() }
|
||||||
|
|
||||||
|
// Auto-scroll breadcrumbs to end
|
||||||
|
LaunchedEffect(currentPath) {
|
||||||
|
scope.launch { breadcrumbState.animateScrollToItem(maxOf(0, relParts.size)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
val filtered = if (searchQuery.isBlank()) entries
|
||||||
|
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,
|
||||||
|
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
|
||||||
|
) {
|
||||||
|
val view = LocalView.current
|
||||||
|
val density = LocalDensity.current
|
||||||
|
var topInset by remember { mutableStateOf(0.dp) }
|
||||||
|
var bottomInset by remember { mutableStateOf(56.dp) }
|
||||||
|
DisposableEffect(view) {
|
||||||
|
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
|
||||||
|
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
|
with(density) {
|
||||||
|
topInset = bars.top.toDp()
|
||||||
|
bottomInset = maxOf(bars.bottom.toDp(), 56.dp)
|
||||||
|
}
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
ViewCompat.requestApplyInsets(view)
|
||||||
|
onDispose { ViewCompat.setOnApplyWindowInsetsListener(view, null) }
|
||||||
|
}
|
||||||
|
|
||||||
|
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surface) {
|
||||||
|
Column(modifier = Modifier.fillMaxSize().padding(top = topInset)) {
|
||||||
|
|
||||||
|
// ── Top bar ──────────────────────────────────────────────────
|
||||||
|
TopAppBar(
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { if (!navigateUp()) onDismiss() }) {
|
||||||
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
if (searchActive) {
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
||||||
|
OutlinedTextField(
|
||||||
|
value = searchQuery,
|
||||||
|
onValueChange = { searchQuery = it },
|
||||||
|
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester),
|
||||||
|
placeholder = { Text("Search folders…") },
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||||
|
keyboardActions = KeyboardActions(onSearch = {}),
|
||||||
|
colors = OutlinedTextFieldDefaults.colors(
|
||||||
|
focusedBorderColor = Color.Transparent,
|
||||||
|
unfocusedBorderColor = Color.Transparent,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Text("Choose Local Folder", style = MaterialTheme.typography.titleMedium)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions = {
|
||||||
|
IconButton(onClick = { searchActive = !searchActive; if (!searchActive) searchQuery = "" }) {
|
||||||
|
Icon(if (searchActive) Icons.Default.Close else Icons.Default.Search, "Search")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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(
|
||||||
|
state = breadcrumbState,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 6.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
) {
|
||||||
|
item {
|
||||||
|
BreadcrumbChip(label = "📱 Storage", isLast = relParts.isEmpty(),
|
||||||
|
onClick = { navigateToBreadcrumb(STORAGE_ROOT) })
|
||||||
|
}
|
||||||
|
itemsIndexed(relParts) { idx, part ->
|
||||||
|
Icon(Icons.Default.ChevronRight, null, Modifier.size(14.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
val partPath = STORAGE_ROOT.absolutePath + "/" + relParts.take(idx + 1).joinToString("/")
|
||||||
|
BreadcrumbChip(label = part, isLast = idx == relParts.lastIndex,
|
||||||
|
onClick = { navigateToBreadcrumb(File(partPath)) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HorizontalDivider()
|
||||||
|
|
||||||
|
// ── Content ──────────────────────────────────────────────────
|
||||||
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
|
when {
|
||||||
|
isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
else -> LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
|
if (currentPath.absolutePath == STORAGE_ROOT.absolutePath && searchQuery.isBlank()) {
|
||||||
|
item {
|
||||||
|
Text("Quick access", style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(start = 20.dp, top = 14.dp, bottom = 6.dp))
|
||||||
|
LazyRow(contentPadding = PaddingValues(horizontal = 16.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||||
|
modifier = Modifier.padding(bottom = 8.dp)) {
|
||||||
|
items(SHORTCUTS.filter { File(it.path).isDirectory }) { sc ->
|
||||||
|
ShortcutChip(sc, onClick = { navigateTo(File(sc.path)) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
HorizontalDivider(modifier = Modifier.padding(vertical = 6.dp))
|
||||||
|
Text("All folders", style = MaterialTheme.typography.labelSmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
modifier = Modifier.padding(start = 20.dp, top = 4.dp, bottom = 4.dp))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filtered.isEmpty()) {
|
||||||
|
item {
|
||||||
|
Box(Modifier.fillParentMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
|
Column(horizontalAlignment = Alignment.CenterHorizontally) {
|
||||||
|
Icon(Icons.Default.FolderOpen, null, Modifier.size(56.dp),
|
||||||
|
tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f))
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Text(if (searchQuery.isBlank()) "No subfolders" else "No results for \"$searchQuery\"",
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
items(filtered, key = { it.file.absolutePath }) { entry ->
|
||||||
|
LocalFolderItem(entry = entry, onClick = { navigateTo(entry.file) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
item { Spacer(Modifier.height(8.dp)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── 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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun BreadcrumbChip(label: String, isLast: Boolean, onClick: () -> Unit) {
|
||||||
|
if (isLast) {
|
||||||
|
Surface(shape = RoundedCornerShape(8.dp), color = MaterialTheme.colorScheme.primaryContainer) {
|
||||||
|
Text(label, modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp),
|
||||||
|
style = MaterialTheme.typography.labelMedium, fontWeight = FontWeight.SemiBold,
|
||||||
|
color = MaterialTheme.colorScheme.onPrimaryContainer, maxLines = 1)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TextButton(onClick = onClick, contentPadding = PaddingValues(horizontal = 8.dp, vertical = 2.dp)) {
|
||||||
|
Text(label, style = MaterialTheme.typography.labelMedium, color = MaterialTheme.colorScheme.primary, maxLines = 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ShortcutChip(sc: Shortcut, onClick: () -> Unit) {
|
||||||
|
Surface(
|
||||||
|
onClick = onClick,
|
||||||
|
shape = RoundedCornerShape(14.dp),
|
||||||
|
color = MaterialTheme.colorScheme.secondaryContainer,
|
||||||
|
modifier = Modifier.height(72.dp).width(80.dp),
|
||||||
|
) {
|
||||||
|
Column(
|
||||||
|
modifier = Modifier.fillMaxSize().padding(8.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
Icon(sc.icon, null, Modifier.size(24.dp), tint = MaterialTheme.colorScheme.onSecondaryContainer)
|
||||||
|
Spacer(Modifier.height(4.dp))
|
||||||
|
Text(sc.label, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSecondaryContainer, maxLines = 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun LocalFolderItem(entry: LocalEntry, onClick: () -> Unit) {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable(onClick = onClick)
|
||||||
|
.padding(horizontal = 16.dp, vertical = 10.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(46.dp)
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
.background(Color(0xFF1B5E20).copy(alpha = 0.12f)),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.Folder, null, Modifier.size(26.dp), tint = Color(0xFF2E7D32))
|
||||||
|
}
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(entry.file.name, style = MaterialTheme.typography.bodyLarge, maxLines = 1, overflow = TextOverflow.Ellipsis, fontWeight = FontWeight.Medium)
|
||||||
|
if (entry.childCount > 0) {
|
||||||
|
Text("${entry.childCount} subfolder${if (entry.childCount == 1) "" else "s"}", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Icon(Icons.Default.ChevronRight, null, Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f))
|
||||||
|
}
|
||||||
|
HorizontalDivider(modifier = Modifier.padding(start = 76.dp), thickness = 0.5.dp)
|
||||||
|
}
|
||||||
@@ -1,22 +1,40 @@
|
|||||||
package com.syncflow.ui.browser
|
package com.syncflow.ui.browser
|
||||||
|
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyRow
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material.icons.filled.*
|
import androidx.compose.material.icons.filled.*
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.platform.LocalDensity
|
||||||
|
import androidx.compose.ui.platform.LocalView
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.window.Dialog
|
import androidx.compose.ui.window.Dialog
|
||||||
import androidx.compose.ui.window.DialogProperties
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import androidx.core.view.ViewCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.syncflow.domain.model.RemoteFile
|
import com.syncflow.domain.model.RemoteFile
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -30,79 +48,205 @@ fun RemoteBrowserDialog(
|
|||||||
LaunchedEffect(accountId, initialPath) { vm.init(accountId, initialPath) }
|
LaunchedEffect(accountId, initialPath) { vm.init(accountId, initialPath) }
|
||||||
|
|
||||||
val state by vm.state.collectAsState()
|
val state by vm.state.collectAsState()
|
||||||
|
var searchQuery by remember { mutableStateOf("") }
|
||||||
|
var searchActive by remember { mutableStateOf(false) }
|
||||||
|
var showNewFolderDialog by remember { mutableStateOf(false) }
|
||||||
|
val breadcrumbState = rememberLazyListState()
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
|
||||||
|
// Auto-scroll breadcrumbs to end when path changes
|
||||||
|
val segments = state.currentPath.trimEnd('/').split('/').filter { it.isNotEmpty() }
|
||||||
|
LaunchedEffect(state.currentPath) {
|
||||||
|
scope.launch { breadcrumbState.animateScrollToItem(maxOf(0, segments.size)) }
|
||||||
|
searchQuery = ""
|
||||||
|
searchActive = false
|
||||||
|
}
|
||||||
|
|
||||||
|
val filtered = if (searchQuery.isBlank()) state.entries
|
||||||
|
else state.entries.filter { it.name.contains(searchQuery, ignoreCase = true) }
|
||||||
|
|
||||||
|
val currentFolderName = state.currentPath.trimEnd('/').substringAfterLast('/').ifBlank { "Root" }
|
||||||
|
|
||||||
|
if (showNewFolderDialog) {
|
||||||
|
NewFolderDialog(
|
||||||
|
onConfirm = { name ->
|
||||||
|
vm.createFolder(name)
|
||||||
|
showNewFolderDialog = false
|
||||||
|
},
|
||||||
|
onDismiss = { showNewFolderDialog = false },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Dialog(
|
Dialog(
|
||||||
onDismissRequest = onDismiss,
|
onDismissRequest = onDismiss,
|
||||||
properties = DialogProperties(usePlatformDefaultWidth = false),
|
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false),
|
||||||
) {
|
) {
|
||||||
Surface(
|
val view = LocalView.current
|
||||||
modifier = Modifier
|
val density = LocalDensity.current
|
||||||
.fillMaxWidth(0.95f)
|
var topInset by remember { mutableStateOf(0.dp) }
|
||||||
.fillMaxHeight(0.85f),
|
var bottomInset by remember { mutableStateOf(56.dp) }
|
||||||
shape = MaterialTheme.shapes.extraLarge,
|
DisposableEffect(view) {
|
||||||
tonalElevation = 6.dp,
|
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
|
||||||
) {
|
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
|
||||||
Column {
|
with(density) {
|
||||||
// Title bar
|
topInset = bars.top.toDp()
|
||||||
|
bottomInset = maxOf(bars.bottom.toDp(), 56.dp)
|
||||||
|
}
|
||||||
|
insets
|
||||||
|
}
|
||||||
|
ViewCompat.requestApplyInsets(view)
|
||||||
|
onDispose { ViewCompat.setOnApplyWindowInsetsListener(view, null) }
|
||||||
|
}
|
||||||
|
|
||||||
|
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.surface) {
|
||||||
|
Column(modifier = Modifier.fillMaxSize().padding(top = topInset)) {
|
||||||
|
|
||||||
|
// ── Top bar ──────────────────────────────────────────────────
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
|
||||||
Column {
|
|
||||||
Text("Choose remote folder", style = MaterialTheme.typography.titleMedium)
|
|
||||||
Text(
|
|
||||||
state.currentPath,
|
|
||||||
style = MaterialTheme.typography.labelSmall,
|
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(onClick = { if (!vm.navigateUp()) onDismiss() }) {
|
IconButton(onClick = { if (!vm.navigateUp()) onDismiss() }) {
|
||||||
Icon(Icons.Default.ArrowBack, null)
|
Icon(Icons.AutoMirrored.Filled.ArrowBack, null)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
if (searchActive) {
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
||||||
|
OutlinedTextField(
|
||||||
|
value = searchQuery,
|
||||||
|
onValueChange = { searchQuery = it },
|
||||||
|
modifier = Modifier.fillMaxWidth().focusRequester(focusRequester),
|
||||||
|
placeholder = { Text("Search in folder…") },
|
||||||
|
singleLine = true,
|
||||||
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||||
|
keyboardActions = KeyboardActions(onSearch = {}),
|
||||||
|
colors = OutlinedTextFieldDefaults.colors(
|
||||||
|
focusedBorderColor = Color.Transparent,
|
||||||
|
unfocusedBorderColor = Color.Transparent,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Text("Choose Folder", style = MaterialTheme.typography.titleMedium)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
// Select current folder
|
IconButton(onClick = { searchActive = !searchActive; if (!searchActive) searchQuery = "" }) {
|
||||||
TextButton(onClick = { onSelect(state.currentPath) }) {
|
Icon(if (searchActive) Icons.Default.Close else Icons.Default.Search, "Search")
|
||||||
Text("Select here")
|
}
|
||||||
|
IconButton(onClick = { showNewFolderDialog = true }) {
|
||||||
|
Icon(Icons.Default.CreateNewFolder, "New Folder")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surfaceContainerHigh),
|
colors = TopAppBarDefaults.topAppBarColors(containerColor = MaterialTheme.colorScheme.surface),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ── Breadcrumbs ──────────────────────────────────────────────
|
||||||
|
Surface(tonalElevation = 1.dp) {
|
||||||
|
LazyRow(
|
||||||
|
state = breadcrumbState,
|
||||||
|
modifier = Modifier.fillMaxWidth().padding(horizontal = 8.dp, vertical = 6.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(2.dp),
|
||||||
|
) {
|
||||||
|
item {
|
||||||
|
BreadcrumbChip(
|
||||||
|
label = "⌂",
|
||||||
|
isLast = segments.isEmpty(),
|
||||||
|
onClick = { vm.navigateToBreadcrumb("/") },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
itemsIndexed(segments) { idx, seg ->
|
||||||
|
Icon(Icons.Default.ChevronRight, null, Modifier.size(14.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
val segPath = "/" + segments.take(idx + 1).joinToString("/")
|
||||||
|
BreadcrumbChip(
|
||||||
|
label = seg,
|
||||||
|
isLast = idx == segments.lastIndex,
|
||||||
|
onClick = { vm.navigateToBreadcrumb(segPath) },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
HorizontalDivider()
|
HorizontalDivider()
|
||||||
|
|
||||||
when {
|
// ── Content ──────────────────────────────────────────────────
|
||||||
state.isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
CircularProgressIndicator()
|
when {
|
||||||
}
|
state.isLoading -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||||
state.error != null -> Box(Modifier.fillMaxSize().padding(24.dp), contentAlignment = Alignment.Center) {
|
CircularProgressIndicator()
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
}
|
||||||
Icon(Icons.Default.ErrorOutline, null, Modifier.size(48.dp), tint = MaterialTheme.colorScheme.error)
|
|
||||||
Text(state.error!!, color = MaterialTheme.colorScheme.error)
|
state.error != null -> Column(
|
||||||
FilledTonalButton(onClick = { vm.retry() }) { Text("Retry") }
|
modifier = Modifier.fillMaxSize().padding(32.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.CloudOff, null, Modifier.size(56.dp), tint = MaterialTheme.colorScheme.error)
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Text(state.error!!, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodyMedium)
|
||||||
|
Spacer(Modifier.height(16.dp))
|
||||||
|
FilledTonalButton(onClick = vm::retry) {
|
||||||
|
Icon(Icons.Default.Refresh, null, Modifier.size(18.dp))
|
||||||
|
Spacer(Modifier.width(6.dp))
|
||||||
|
Text("Retry")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered.isEmpty() && searchQuery.isBlank() -> Column(
|
||||||
|
modifier = Modifier.fillMaxSize().padding(32.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.FolderOpen, null, Modifier.size(56.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f))
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Text("This folder is empty", style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
Text("You can still select it", style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.6f))
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered.isEmpty() -> Column(
|
||||||
|
modifier = Modifier.fillMaxSize().padding(32.dp),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center,
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.SearchOff, null, Modifier.size(56.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.4f))
|
||||||
|
Spacer(Modifier.height(12.dp))
|
||||||
|
Text("No results for \"$searchQuery\"", style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> LazyColumn(modifier = Modifier.fillMaxSize()) {
|
||||||
|
items(filtered, key = { it.path }) { entry ->
|
||||||
|
FolderItem(
|
||||||
|
file = entry,
|
||||||
|
onClick = {
|
||||||
|
if (entry.isDirectory) vm.navigateTo(entry.path)
|
||||||
|
else onSelect(entry.path.substringBeforeLast('/').ifBlank { "/" })
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
item { Spacer(Modifier.height(8.dp)) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.entries.isEmpty() -> Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
}
|
||||||
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
|
||||||
Icon(Icons.Default.FolderOff, null, Modifier.size(48.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
// ── Select button ────────────────────────────────────────────
|
||||||
Text("Empty folder", color = MaterialTheme.colorScheme.onSurfaceVariant)
|
Surface(tonalElevation = 4.dp, modifier = Modifier.fillMaxWidth()) {
|
||||||
TextButton(onClick = { onSelect(state.currentPath) }) { Text("Select this folder anyway") }
|
Column {
|
||||||
}
|
Button(
|
||||||
}
|
onClick = { onSelect(state.currentPath) },
|
||||||
else -> LazyColumn(modifier = Modifier.fillMaxSize()) {
|
modifier = Modifier
|
||||||
items(state.entries, key = { it.path }) { entry ->
|
.fillMaxWidth()
|
||||||
BrowserEntry(
|
.padding(start = 16.dp, top = 12.dp, end = 16.dp, bottom = 12.dp)
|
||||||
file = entry,
|
.height(52.dp),
|
||||||
onClick = {
|
shape = RoundedCornerShape(14.dp),
|
||||||
if (entry.isDirectory) vm.navigateTo(entry.path)
|
) {
|
||||||
else onSelect(entry.path.substringBeforeLast('/').ifBlank { "/" })
|
Icon(Icons.Default.CheckCircle, null, Modifier.size(20.dp))
|
||||||
},
|
Spacer(Modifier.width(8.dp))
|
||||||
onSelectFolder = if (entry.isDirectory) ({ onSelect(entry.path) }) else null,
|
Text(
|
||||||
|
"Select \"$currentFolderName\"",
|
||||||
|
style = MaterialTheme.typography.titleSmall,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
)
|
)
|
||||||
HorizontalDivider(modifier = Modifier.padding(start = 56.dp))
|
|
||||||
}
|
}
|
||||||
|
Spacer(Modifier.height(bottomInset))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,44 +255,119 @@ fun RemoteBrowserDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
private fun BrowserEntry(
|
private fun BreadcrumbChip(label: String, isLast: Boolean, onClick: () -> Unit) {
|
||||||
file: RemoteFile,
|
if (isLast) {
|
||||||
onClick: () -> Unit,
|
Surface(
|
||||||
onSelectFolder: (() -> Unit)?,
|
shape = RoundedCornerShape(8.dp),
|
||||||
) {
|
color = MaterialTheme.colorScheme.primaryContainer,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
modifier = Modifier.padding(horizontal = 10.dp, vertical = 4.dp),
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
fontWeight = FontWeight.SemiBold,
|
||||||
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
TextButton(
|
||||||
|
onClick = onClick,
|
||||||
|
contentPadding = PaddingValues(horizontal = 8.dp, vertical = 2.dp),
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
label,
|
||||||
|
style = MaterialTheme.typography.labelMedium,
|
||||||
|
color = MaterialTheme.colorScheme.primary,
|
||||||
|
maxLines = 1,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun FolderItem(file: RemoteFile, onClick: () -> Unit) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable(onClick = onClick)
|
.clickable(onClick = onClick)
|
||||||
.padding(horizontal = 16.dp, vertical = 10.dp),
|
.padding(horizontal = 16.dp, vertical = 10.dp),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||||
) {
|
) {
|
||||||
Icon(
|
// Colored icon badge
|
||||||
imageVector = if (file.isDirectory) Icons.Default.Folder else Icons.Default.InsertDriveFile,
|
Box(
|
||||||
contentDescription = null,
|
modifier = Modifier
|
||||||
modifier = Modifier.size(24.dp),
|
.size(46.dp)
|
||||||
tint = if (file.isDirectory) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurfaceVariant,
|
.clip(RoundedCornerShape(12.dp))
|
||||||
)
|
.background(
|
||||||
Spacer(Modifier.width(14.dp))
|
if (file.isDirectory) Color(0xFF1B5E20).copy(alpha = 0.12f)
|
||||||
|
else Color(0xFF0D47A1).copy(alpha = 0.10f)
|
||||||
|
),
|
||||||
|
contentAlignment = Alignment.Center,
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
imageVector = if (file.isDirectory) Icons.Default.Folder else Icons.Default.InsertDriveFile,
|
||||||
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(26.dp),
|
||||||
|
tint = if (file.isDirectory) Color(0xFF2E7D32) else Color(0xFF1565C0),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(file.name, style = MaterialTheme.typography.bodyMedium, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
Text(
|
||||||
|
file.name,
|
||||||
|
style = MaterialTheme.typography.bodyLarge,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis,
|
||||||
|
fontWeight = if (file.isDirectory) FontWeight.Medium else FontWeight.Normal,
|
||||||
|
)
|
||||||
if (!file.isDirectory) {
|
if (!file.isDirectory) {
|
||||||
Text(file.sizeBytes.formatBytes(), style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
Text(
|
||||||
|
file.sizeBytes.formatBytes(),
|
||||||
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (onSelectFolder != null) {
|
|
||||||
IconButton(onClick = onSelectFolder, modifier = Modifier.size(36.dp)) {
|
if (file.isDirectory) {
|
||||||
Icon(Icons.Default.CheckCircleOutline, "Select this folder", Modifier.size(20.dp), tint = MaterialTheme.colorScheme.primary)
|
Icon(Icons.Default.ChevronRight, null, Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f))
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Icon(Icons.Default.ChevronRight, null, Modifier.size(20.dp), tint = MaterialTheme.colorScheme.onSurfaceVariant)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
HorizontalDivider(modifier = Modifier.padding(start = 76.dp), thickness = 0.5.dp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun NewFolderDialog(onConfirm: (String) -> Unit, onDismiss: () -> Unit) {
|
||||||
|
var name by remember { mutableStateOf("") }
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
icon = { Icon(Icons.Default.CreateNewFolder, null) },
|
||||||
|
title = { Text("New Folder") },
|
||||||
|
text = {
|
||||||
|
OutlinedTextField(
|
||||||
|
value = name,
|
||||||
|
onValueChange = { name = it },
|
||||||
|
label = { Text("Folder name") },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
|
||||||
|
keyboardActions = KeyboardActions(onDone = { if (name.isNotBlank()) onConfirm(name.trim()) }),
|
||||||
|
)
|
||||||
|
},
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = { if (name.isNotBlank()) onConfirm(name.trim()) }, enabled = name.isNotBlank()) {
|
||||||
|
Text("Create")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Long.formatBytes(): String = when {
|
private fun Long.formatBytes(): String = when {
|
||||||
this < 1024 -> "${this}B"
|
this < 1024 -> "${this} B"
|
||||||
this < 1_048_576 -> "${"%.1f".format(this / 1024.0)}KB"
|
this < 1_048_576 -> "${"%.1f".format(this / 1024.0)} KB"
|
||||||
this < 1_073_741_824 -> "${"%.1f".format(this / 1_048_576.0)}MB"
|
this < 1_073_741_824 -> "${"%.1f".format(this / 1_048_576.0)} MB"
|
||||||
else -> "${"%.1f".format(this / 1_073_741_824.0)}GB"
|
else -> "${"%.1f".format(this / 1_073_741_824.0)} GB"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,27 @@ class RemoteBrowserViewModel @Inject constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun navigateToBreadcrumb(path: String) {
|
||||||
|
val stack = _state.value.pathStack
|
||||||
|
val idx = stack.lastIndexOf(path)
|
||||||
|
val newStack = if (idx >= 0) stack.take(idx + 1) else listOf(path)
|
||||||
|
loadJob?.cancel()
|
||||||
|
_state.update { it.copy(currentPath = path, pathStack = newStack, isLoading = true, entries = emptyList(), error = null) }
|
||||||
|
loadJob = loadPath(_state.value.accountId, path)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createFolder(name: String) {
|
||||||
|
val s = _state.value
|
||||||
|
val newPath = if (s.currentPath.trimEnd('/') == "") "/$name" else "${s.currentPath.trimEnd('/')}/$name"
|
||||||
|
viewModelScope.launch {
|
||||||
|
val account = accountRepository.getAccount(s.accountId) ?: return@launch
|
||||||
|
val provider = runCatching { providerFactory.create(account) }.getOrElse { return@launch }
|
||||||
|
provider.createDirectory(newPath)
|
||||||
|
.onSuccess { retry() }
|
||||||
|
.onFailure { e -> _state.update { it.copy(error = "Could not create folder: ${e.message}") } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun retry() {
|
fun retry() {
|
||||||
val s = _state.value
|
val s = _state.value
|
||||||
if (s.accountId == -1L) return
|
if (s.accountId == -1L) return
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ class FilesViewModel @Inject constructor(
|
|||||||
val pairs: StateFlow<List<SyncPairEntity>> = syncPairDao.observeAll()
|
val pairs: StateFlow<List<SyncPairEntity>> = syncPairDao.observeAll()
|
||||||
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
||||||
|
|
||||||
|
val accounts = accountRepository.observeAll()
|
||||||
|
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
|
||||||
|
|
||||||
private val _selectedPairId = MutableStateFlow<Long?>(null)
|
private val _selectedPairId = MutableStateFlow<Long?>(null)
|
||||||
|
|
||||||
val selectedPair: StateFlow<SyncPairEntity?> = combine(_selectedPairId, pairs) { id, list ->
|
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 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 ──────────────────────────────────────────────
|
// ── Download-then-open/share ──────────────────────────────────────────────
|
||||||
|
|
||||||
private fun downloadAndOpen(file: SyncFileStateEntity) {
|
private fun downloadAndOpen(file: SyncFileStateEntity) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ fun HomeScreen(
|
|||||||
onClick = { onPairClick(pair.id) },
|
onClick = { onPairClick(pair.id) },
|
||||||
onSync = { vm.triggerSync(pair) },
|
onSync = { vm.triggerSync(pair) },
|
||||||
onToggle = { vm.toggleEnabled(pair) },
|
onToggle = { vm.toggleEnabled(pair) },
|
||||||
|
onPause = { vm.pauseSync(pair) },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
item { Spacer(Modifier.height(80.dp)) }
|
item { Spacer(Modifier.height(80.dp)) }
|
||||||
@@ -66,6 +67,7 @@ private fun SyncPairCard(
|
|||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onSync: () -> Unit,
|
onSync: () -> Unit,
|
||||||
onToggle: () -> Unit,
|
onToggle: () -> Unit,
|
||||||
|
onPause: () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
val accentColor = pair.lastSyncResult.accentColor
|
val accentColor = pair.lastSyncResult.accentColor
|
||||||
|
|
||||||
@@ -170,13 +172,16 @@ private fun SyncPairCard(
|
|||||||
animationSpec = infiniteRepeatable(tween(900, easing = LinearEasing)),
|
animationSpec = infiniteRepeatable(tween(900, easing = LinearEasing)),
|
||||||
label = "cardRotation",
|
label = "cardRotation",
|
||||||
)
|
)
|
||||||
FilledTonalIconButton(onClick = onSync, modifier = Modifier.size(36.dp)) {
|
when (pair.lastSyncResult) {
|
||||||
Icon(
|
SyncStatus.SYNCING -> FilledTonalIconButton(onClick = onPause, modifier = Modifier.size(36.dp)) {
|
||||||
Icons.Default.Sync, "Sync now",
|
Icon(Icons.Default.Pause, "Pause sync", modifier = Modifier.size(18.dp))
|
||||||
modifier = Modifier.size(18.dp).graphicsLayer {
|
}
|
||||||
if (pair.lastSyncResult == SyncStatus.SYNCING) rotationZ = syncRotation
|
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) {
|
val (icon, label) = when (status) {
|
||||||
SyncStatus.SUCCESS -> Pair(Icons.Default.CheckCircle, "Synced")
|
SyncStatus.SUCCESS -> Pair(Icons.Default.CheckCircle, "Synced")
|
||||||
SyncStatus.SYNCING -> Pair(Icons.Default.Sync, "Syncing…")
|
SyncStatus.SYNCING -> Pair(Icons.Default.Sync, "Syncing…")
|
||||||
|
SyncStatus.PAUSED -> Pair(Icons.Default.Pause, "Paused")
|
||||||
SyncStatus.FAILED -> Pair(Icons.Default.Error, "Failed")
|
SyncStatus.FAILED -> Pair(Icons.Default.Error, "Failed")
|
||||||
SyncStatus.CONFLICT -> Pair(Icons.Default.Warning, "Conflict")
|
SyncStatus.CONFLICT -> Pair(Icons.Default.Warning, "Conflict")
|
||||||
SyncStatus.PARTIAL -> Pair(Icons.Default.WarningAmber, "Partial")
|
SyncStatus.PARTIAL -> Pair(Icons.Default.WarningAmber, "Partial")
|
||||||
@@ -247,12 +253,13 @@ private fun EmptyState(modifier: Modifier = Modifier, onAdd: () -> Unit) {
|
|||||||
|
|
||||||
private val SyncStatus.accentColor: Color
|
private val SyncStatus.accentColor: Color
|
||||||
@Composable get() = when (this) {
|
@Composable get() = when (this) {
|
||||||
SyncStatus.SUCCESS -> MaterialTheme.colorScheme.primary
|
SyncStatus.SUCCESS -> Color(0xFF2E7D32)
|
||||||
SyncStatus.SYNCING -> MaterialTheme.colorScheme.secondary
|
SyncStatus.SYNCING -> Color(0xFF1565C0)
|
||||||
SyncStatus.FAILED -> MaterialTheme.colorScheme.error
|
SyncStatus.PAUSED -> Color(0xFF6A1B9A)
|
||||||
SyncStatus.CONFLICT,
|
SyncStatus.FAILED -> Color(0xFFC62828)
|
||||||
SyncStatus.PARTIAL -> MaterialTheme.colorScheme.tertiary
|
SyncStatus.PARTIAL -> Color(0xFFE65100)
|
||||||
SyncStatus.IDLE -> MaterialTheme.colorScheme.outline
|
SyncStatus.CONFLICT -> Color(0xFFF9A825)
|
||||||
|
SyncStatus.IDLE -> MaterialTheme.colorScheme.outline
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun String.toDisplayPath(): String {
|
private fun String.toDisplayPath(): String {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import androidx.work.WorkManager
|
|||||||
import com.syncflow.data.db.SyncPairDao
|
import com.syncflow.data.db.SyncPairDao
|
||||||
import com.syncflow.data.db.entities.SyncPairEntity
|
import com.syncflow.data.db.entities.SyncPairEntity
|
||||||
import com.syncflow.domain.model.ScheduleType
|
import com.syncflow.domain.model.ScheduleType
|
||||||
|
import com.syncflow.domain.model.SyncStatus
|
||||||
import com.syncflow.worker.FileWatchService
|
import com.syncflow.worker.FileWatchService
|
||||||
import com.syncflow.worker.SyncWorker
|
import com.syncflow.worker.SyncWorker
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
@@ -32,6 +33,11 @@ class HomeViewModel @Inject constructor(
|
|||||||
workManager.enqueue(req)
|
workManager.enqueue(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun pauseSync(pair: SyncPairEntity) {
|
||||||
|
workManager.cancelAllWorkByTag("sync_${pair.id}")
|
||||||
|
viewModelScope.launch { syncPairDao.updateStatus(pair.id, SyncStatus.PAUSED) }
|
||||||
|
}
|
||||||
|
|
||||||
fun toggleEnabled(pair: SyncPairEntity) {
|
fun toggleEnabled(pair: SyncPairEntity) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val nowEnabled = !pair.isEnabled
|
val nowEnabled = !pair.isEnabled
|
||||||
|
|||||||
@@ -66,7 +66,17 @@ fun PairDetailScreen(
|
|||||||
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.Default.ArrowBack, "Back") } },
|
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.Default.ArrowBack, "Back") } },
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(onClick = { pair?.let { onEdit(it.id) } }) { Icon(Icons.Default.Edit, "Edit") }
|
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") }
|
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) {
|
val (icon, label, containerColor) = when (pair.lastSyncResult) {
|
||||||
SyncStatus.SUCCESS -> Triple(Icons.Default.CheckCircle, "Synced", MaterialTheme.colorScheme.primaryContainer)
|
SyncStatus.SUCCESS -> Triple(Icons.Default.CheckCircle, "Synced", MaterialTheme.colorScheme.primaryContainer)
|
||||||
SyncStatus.SYNCING -> Triple(Icons.Default.Sync, "Syncing…", MaterialTheme.colorScheme.secondaryContainer)
|
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.FAILED -> Triple(Icons.Default.Error, "Failed", MaterialTheme.colorScheme.errorContainer)
|
||||||
SyncStatus.CONFLICT -> Triple(Icons.Default.Warning, "Conflict", MaterialTheme.colorScheme.tertiaryContainer)
|
SyncStatus.CONFLICT -> Triple(Icons.Default.Warning, "Conflict", MaterialTheme.colorScheme.tertiaryContainer)
|
||||||
SyncStatus.PARTIAL -> Triple(Icons.Default.WarningAmber,"Partial", 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.SyncConflictDao
|
||||||
import com.syncflow.data.db.SyncEventDao
|
import com.syncflow.data.db.SyncEventDao
|
||||||
import com.syncflow.data.db.SyncPairDao
|
import com.syncflow.data.db.SyncPairDao
|
||||||
|
import com.syncflow.domain.model.SyncStatus
|
||||||
import com.syncflow.worker.SyncWorker
|
import com.syncflow.worker.SyncWorker
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import kotlinx.coroutines.flow.SharingStarted
|
import kotlinx.coroutines.flow.SharingStarted
|
||||||
@@ -39,6 +40,12 @@ class PairDetailViewModel @Inject constructor(
|
|||||||
workManager.enqueue(SyncWorker.buildOneTimeRequest(p.id, wifiOnly = false, chargingOnly = false))
|
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() {
|
fun delete() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
pair.value?.let { syncPairDao.delete(it) }
|
pair.value?.let { syncPairDao.delete(it) }
|
||||||
|
|||||||
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 188 KiB |
@@ -1,12 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="108dp"
|
|
||||||
android:height="108dp"
|
|
||||||
android:viewportWidth="108"
|
|
||||||
android:viewportHeight="108">
|
|
||||||
|
|
||||||
<!-- Pure black background -->
|
|
||||||
<path android:pathData="M0,0 H108 V108 H0 Z"
|
|
||||||
android:fillColor="#000000"/>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="108dp"
|
|
||||||
android:height="108dp"
|
|
||||||
android:viewportWidth="108"
|
|
||||||
android:viewportHeight="108">
|
|
||||||
|
|
||||||
<!--
|
|
||||||
Four thick arcs arranged as an interlocked pinwheel.
|
|
||||||
Each arc sweeps ~210 degrees, rounded caps, radius 18 from center (54,54).
|
|
||||||
Draw order creates natural over/under at the four crossing points:
|
|
||||||
blue under green, green under red, red under orange, orange under blue (re-draw blue tip).
|
|
||||||
|
|
||||||
Arc endpoints computed at radius 18, sweep 210 deg clockwise:
|
|
||||||
start angle end angle start point end point
|
|
||||||
270 (top) 120 (54, 36) (45, 70)
|
|
||||||
0 (right) 210 (72, 54) (39, 45)
|
|
||||||
90 (bot) 300 (54, 72) (63, 38)
|
|
||||||
180 (left) 390=30 (36, 54) (69, 63)
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Blue — starts at top, sweeps clockwise to lower-left -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#2979FF"
|
|
||||||
android:strokeWidth="8.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:strokeLineCap="round"
|
|
||||||
android:pathData="M 54,36 A 18,18 0 1,1 45,70"/>
|
|
||||||
|
|
||||||
<!-- Green — starts at bottom, sweeps clockwise to upper-right -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#00C853"
|
|
||||||
android:strokeWidth="8.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:strokeLineCap="round"
|
|
||||||
android:pathData="M 54,72 A 18,18 0 1,1 63,38"/>
|
|
||||||
|
|
||||||
<!-- Red — starts at right, sweeps clockwise to lower-left -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#E53935"
|
|
||||||
android:strokeWidth="8.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:strokeLineCap="round"
|
|
||||||
android:pathData="M 72,54 A 18,18 0 1,1 39,45"/>
|
|
||||||
|
|
||||||
<!-- Orange — starts at left, sweeps clockwise to upper-right -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#FF6D00"
|
|
||||||
android:strokeWidth="8.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:strokeLineCap="round"
|
|
||||||
android:pathData="M 36,54 A 18,18 0 1,1 69,63"/>
|
|
||||||
|
|
||||||
<!-- Re-draw blue start cap on top so it goes OVER orange end -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#2979FF"
|
|
||||||
android:strokeWidth="8.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:strokeLineCap="round"
|
|
||||||
android:pathData="M 54,36 A 18,18 0 0,1 62,37.5"/>
|
|
||||||
|
|
||||||
<!-- White sync circle at center -->
|
|
||||||
<path
|
|
||||||
android:fillColor="#000000"
|
|
||||||
android:pathData="M 45,54 A 9,9 0 1,0 63,54 A 9,9 0 1,0 45,54 Z"/>
|
|
||||||
|
|
||||||
<!-- Sync ring -->
|
|
||||||
<path
|
|
||||||
android:strokeColor="#FFFFFF"
|
|
||||||
android:strokeWidth="2.5"
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M 46.5,54 A 7.5,7.5 0 1,0 61.5,54 A 7.5,7.5 0 1,0 46.5,54 Z"/>
|
|
||||||
|
|
||||||
<!-- Top arrow head (pointing up) -->
|
|
||||||
<path
|
|
||||||
android:fillColor="#FFFFFF"
|
|
||||||
android:pathData="M 54,46.5 L 57,50.5 L 51,50.5 Z"/>
|
|
||||||
|
|
||||||
<!-- Bottom arrow head (pointing down) -->
|
|
||||||
<path
|
|
||||||
android:fillColor="#FFFFFF"
|
|
||||||
android:pathData="M 54,61.5 L 51,57.5 L 57,57.5 Z"/>
|
|
||||||
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
After Width: | Height: | Size: 14 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 12 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 6.5 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 20 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 52 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 44 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 88 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
|
After Width: | Height: | Size: 75 KiB |
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
|
|
||||||
</adaptive-icon>
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="ic_launcher_background">#2196F3</color>
|
<color name="ic_launcher_background">#050E05</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
VERSION_NAME=1.0.37
|
VERSION_NAME=1.0.59
|
||||||
VERSION_CODE=38
|
VERSION_CODE=60
|
||||||
|
|||||||