Skip to content

Commit 1963519

Browse files
committed
Refactor: Refine move logic and exclude 'To Edit' folders
- Corrects processed media history for file moves. The original path is no longer marked as "sorted," only the new destination path is. - Excludes all folders named "To Edit" from Session Setup lists and Duplicates scans. This prevents these CleanSweep-related folders from potentially cluttering the UI.
1 parent b6b8d81 commit 1963519

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

app/src/main/java/com/cleansweep/data/repository/DirectMediaRepositoryImpl.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ class DirectMediaRepositoryImpl @Inject constructor(
214214
val path = cursor.getString(dataColumn)
215215
// Ensure path exists and has a parent before adding
216216
if (path != null) {
217-
File(path).parent?.let { folderPaths.add(it) }
217+
File(path).parentFile?.let { parentFile ->
218+
if (parentFile.name != "To Edit") {
219+
folderPaths.add(parentFile.absolutePath)
220+
}
221+
}
218222
}
219223
}
220224
}
@@ -335,7 +339,7 @@ class DirectMediaRepositoryImpl @Inject constructor(
335339

336340
suspend fun processDirectory(directory: File, mediaStoreMap: Map<String, MediaStoreCache>) {
337341
currentCoroutineContext().ensureActive()
338-
if (!directory.exists() || !directory.isDirectory || !directory.canRead() || directory.name.startsWith('.') || !isSafeDestination(directory.absolutePath)) {
342+
if (directory.name == "To Edit" || !directory.exists() || !directory.isDirectory || !directory.canRead() || directory.name.startsWith('.') || !isSafeDestination(directory.absolutePath)) {
339343
return
340344
}
341345

@@ -529,7 +533,7 @@ class DirectMediaRepositoryImpl @Inject constructor(
529533
currentCoroutineContext().ensureActive()
530534
val directory = queue.poll() ?: continue
531535

532-
if (!directory.exists() || !directory.canRead() || directory.name.startsWith(".") || !isSafeDestination(directory.absolutePath)) {
536+
if (directory.name == "To Edit" || !directory.exists() || !directory.canRead() || directory.name.startsWith(".") || !isSafeDestination(directory.absolutePath)) {
533537
continue
534538
}
535539

@@ -1258,7 +1262,7 @@ class DirectMediaRepositoryImpl @Inject constructor(
12581262
currentCoroutineContext().ensureActive()
12591263
val directory = queue.poll() ?: continue
12601264

1261-
if (!directory.exists() || !directory.canRead() || directory.name.startsWith(".") || !isSafeDestination(directory.absolutePath)) {
1265+
if (directory.name == "To Edit" || !directory.exists() || !directory.canRead() || directory.name.startsWith(".") || !isSafeDestination(directory.absolutePath)) {
12621266
continue
12631267
}
12641268

app/src/main/java/com/cleansweep/ui/screens/swiper/SwiperViewModel.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,6 @@ class SwiperViewModel @Inject constructor(
642642
}
643643
Log.d(TAG, "applyChanges: Found ${initialChanges.size} initial pending changes.")
644644

645-
// --- VALIDATION STEP ---
646645
val validatedChanges = fileOperationsHelper.filterExistingFiles(initialChanges)
647646
val missingCount = initialChanges.size - validatedChanges.size
648647

@@ -658,7 +657,6 @@ class SwiperViewModel @Inject constructor(
658657
_uiState.update { it.copy(isApplyingChanges = false, showSummarySheet = false) }
659658
return@launch
660659
}
661-
// --- END VALIDATION ---
662660

663661
val finalChanges = synchronizeUnindexedChanges(validatedChanges)
664662
if (finalChanges == null) {
@@ -806,9 +804,21 @@ class SwiperViewModel @Inject constructor(
806804
folderUpdateEventBus.post(FolderUpdateEvent.FolderBatchUpdate(folderDeltas))
807805
}
808806

809-
val originalPaths = originalChanges.map { it.item.id }.toSet()
810-
val processedPaths = (originalPaths + moveResults.values.map { it.id }).toSet()
807+
val pathsToRemember = mutableSetOf<String>()
811808

809+
// Add original paths for non-move actions (Keep, Delete, etc.)
810+
originalChanges.forEach { change ->
811+
if (change.action !is SwiperAction.Move) {
812+
pathsToRemember.add(change.item.id)
813+
}
814+
}
815+
816+
// Add new destination paths for all moved items
817+
moveResults.values.forEach { newItem ->
818+
pathsToRemember.add(newItem.id)
819+
}
820+
821+
val processedPaths = pathsToRemember.toSet()
812822
sessionProcessedMediaIds.addAll(processedPaths)
813823

814824
if (_rememberProcessedMediaEnabled) {

0 commit comments

Comments
 (0)