Skip to content

Commit 4c1bce2

Browse files
committed
allow user to delete normal files together with auto upload folders
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent 97cca77 commit 4c1bce2

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

app/src/main/java/com/nextcloud/client/jobs/upload/FileUploadHelper.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,31 @@ class FileUploadHelper {
639639
}
640640
}
641641

642-
suspend fun getAutoUploadFolder(files: List<OCFile>, accountName: String): List<SyncedFolderEntity> =
643-
files.mapNotNull { file ->
644-
getAutoUploadFolderEntity(file, accountName)
642+
/**
643+
* Splits a list of files into:
644+
* 1. Files that have an auto-upload folder configured.
645+
* 2. Files that don't.
646+
*/
647+
suspend fun splitFilesByAutoUpload(
648+
files: List<OCFile>,
649+
accountName: String
650+
): Pair<List<SyncedFolderEntity>, List<OCFile>> {
651+
652+
val autoUploadFolders = mutableListOf<SyncedFolderEntity>()
653+
val nonAutoUploadFiles = mutableListOf<OCFile>()
654+
655+
for (file in files) {
656+
val entity = getAutoUploadFolderEntity(file, accountName)
657+
if (entity != null) {
658+
autoUploadFolders.add(entity)
659+
} else {
660+
nonAutoUploadFiles.add(file)
661+
}
645662
}
646663

664+
return autoUploadFolders to nonAutoUploadFiles
665+
}
666+
647667
suspend fun getAutoUploadFolderEntity(file: ServerFileInterface, accountName: String): SyncedFolderEntity? {
648668
val dao = uploadsStorageManager.syncedFolderDao
649669
val normalizedRemotePath = file.remotePath.trimEnd()

app/src/main/java/com/owncloud/android/ui/dialog/RemoveFilesDialogFragment.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,19 @@ class RemoveFilesDialogFragment :
112112
val listener = getTypedActivity(OnFilesRemovedListener::class.java)
113113

114114
lifecycleScope.launch(Dispatchers.IO) {
115-
val autoUploadEntities =
116-
FileUploadHelper.instance().getAutoUploadFolder(files, userAccountManager.user.accountName)
115+
val (autoUploadEntities, filesToRemove) =
116+
FileUploadHelper.instance().splitFilesByAutoUpload(files, userAccountManager.user.accountName)
117117
withContext(Dispatchers.Main) {
118118
if (autoUploadEntities.isNotEmpty()) {
119119
listener?.onAutoUploadFolderRemoved(
120120
entities = autoUploadEntities,
121121
filesToRemove = files,
122122
onlyLocalCopy = onlyLocalCopy
123123
)
124-
return@withContext
125124
}
126125

127126
val fileActivity = getTypedActivity(FileActivity::class.java)
128-
fileActivity?.removeFiles(offlineFiles, files, onlyLocalCopy, listener)
127+
fileActivity?.removeFiles(offlineFiles, filesToRemove, onlyLocalCopy, listener)
129128
finishActionMode()
130129
}
131130
}

0 commit comments

Comments
 (0)