Skip to content

Commit

Permalink
Merge pull request #3231 from owncloud/new_arch/rename
Browse files Browse the repository at this point in the history
[New arch] Rename
  • Loading branch information
abelgardep authored May 24, 2021
2 parents c52e22a + 6bb587e commit 917eeaa
Show file tree
Hide file tree
Showing 28 changed files with 499 additions and 596 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,131 +625,6 @@ class FileDataStorageManager : KoinComponent {
// return updatedCount > 0
}

/**
* Updates database and file system for a file or folder that was moved to a different location.
*
* TODO explore better (faster) implementations
* TODO throw exceptions up !
*/
fun moveLocalFile(file: OCFile?, targetPath: String, targetParentPath: String) {
// FIXME: 13/10/2020 : New_arch: Move file

// if (file != null && file.fileExists() && ROOT_PATH != file.fileName) {
//
// val targetParent = getFileByPath(targetParentPath)
// ?: throw IllegalStateException(
// "Parent folder of the target path does not exist!!"
// )
//
// /// 1. get all the descendants of the moved element in a single QUERY
// val c: Cursor? =
// try {
// performQuery(
// uri = CONTENT_URI,
// projection = null,
// selection = "$FILE_ACCOUNT_OWNER=? AND $FILE_PATH LIKE ? ",
// selectionArgs = arrayOf(account.name, "${file.remotePath}%"),
// sortOrder = "$FILE_PATH ASC "
// )
// } catch (e: RemoteException) {
// Timber.e(e)
// null
// }
//
// val originalPathsToTriggerMediaScan = ArrayList<String>()
// val newPathsToTriggerMediaScan = ArrayList<String>()
// val defaultSavePath = FileStorageUtils.getSavePath(account.name)
//
// /// 2. prepare a batch of update operations to change all the descendants
// if (c != null) {
// val operations = ArrayList<ContentProviderOperation>(c.count)
// if (c.moveToFirst()) {
// val lengthOfOldPath = file.remotePath.length
// val lengthOfOldStoragePath = defaultSavePath.length + lengthOfOldPath
// do {
// val cv = ContentValues() // keep construction in the loop
// val child = createFileInstance(c)
// cv.put(FILE_PATH, targetPath + child!!.remotePath.substring(lengthOfOldPath))
// if (child.storagePath != null && child.storagePath.startsWith(defaultSavePath)) {
// // update link to downloaded content - but local move is not done here!
// val targetLocalPath = defaultSavePath + targetPath +
// child.storagePath.substring(lengthOfOldStoragePath)
//
// cv.put(FILE_STORAGE_PATH, targetLocalPath)
//
// originalPathsToTriggerMediaScan.add(child.storagePath)
// newPathsToTriggerMediaScan.add(targetLocalPath)
//
// }
// if (targetParent.availableOfflineStatus != NOT_AVAILABLE_OFFLINE) {
// // moving to an available offline subfolder
// cv.put(FILE_KEEP_IN_SYNC, AVAILABLE_OFFLINE_PARENT.value)
// } else {
// // moving to a not available offline subfolder - with care
// if (file.availableOfflineStatus == AVAILABLE_OFFLINE_PARENT) {
// cv.put(FILE_KEEP_IN_SYNC, NOT_AVAILABLE_OFFLINE.value)
// }
// }
//
// if (child.remotePath == file.remotePath) {
// cv.put(FILE_PARENT, targetParent.fileId)
// }
// operations.add(
// ContentProviderOperation.newUpdate(CONTENT_URI).withValues(cv).withSelection(
// "$_ID=?",
// arrayOf(child.fileId.toString())
// )
// .build()
// )
//
// } while (c.moveToNext())
// }
// c.close()
//
// /// 3. apply updates in batch
// try {
// if (contentResolver != null) {
// contentResolver!!.applyBatch(MainApp.authority, operations)
//
// } else {
// contentProviderClient!!.applyBatch(operations)
// }
//
// } catch (e: Exception) {
// Timber.e(e, "Fail to update ${file.fileId} and descendants in database")
// }
//
// }
//
// /// 4. move in local file system
// val originalLocalPath = FileStorageUtils.getDefaultSavePathFor(account.name, file)
// val targetLocalPath = defaultSavePath + targetPath
// val localFile = File(originalLocalPath)
// var renamed = false
// if (localFile.exists()) {
// val targetFile = File(targetLocalPath)
// val targetFolder = targetFile.parentFile
// if (targetFolder != null && !targetFolder.exists()) {
// targetFolder.mkdirs()
// }
// renamed = localFile.renameTo(targetFile)
// }
//
// if (renamed) {
// var it = originalPathsToTriggerMediaScan.iterator()
// while (it.hasNext()) {
// // Notify MediaScanner about removed file
// deleteFileInMediaScan(it.next())
// }
// it = newPathsToTriggerMediaScan.iterator()
// while (it.hasNext()) {
// // Notify MediaScanner about new file/folder
// triggerMediaScan(it.next())
// }
// }
// }
}

fun copyLocalFile(originalFile: OCFile?, targetPath: String, targetFileRemoteId: String) {
// FIXME: 13/10/2020 : New_arch: Copy file

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.owncloud.android.domain.files.usecases.GetFolderImagesUseCase
import com.owncloud.android.domain.files.usecases.MoveFileUseCase
import com.owncloud.android.domain.files.usecases.RefreshFolderFromServerAsyncUseCase
import com.owncloud.android.domain.files.usecases.RemoveFileUseCase
import com.owncloud.android.domain.files.usecases.RenameFileUseCase
import com.owncloud.android.domain.files.usecases.SaveFileOrFolderUseCase
import com.owncloud.android.domain.server.usecases.GetServerInfoAsyncUseCase
import com.owncloud.android.domain.sharing.sharees.GetShareesAsyncUseCase
Expand Down Expand Up @@ -85,6 +86,7 @@ val useCaseModule = module {
factory { MoveFileUseCase(get()) }
factory { RefreshFolderFromServerAsyncUseCase(get()) }
factory { RemoveFileUseCase(get()) }
factory { RenameFileUseCase(get()) }
factory { SaveFileOrFolderUseCase(get()) }

// Sharing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ val viewModelModule = module {

viewModel { PreviewImageViewModel(get(), get(), get()) }
viewModel { FileDetailsViewModel(get(), get(), get(), get(), get()) }
viewModel { FileOperationViewModel(get(), get(), get(), get()) }
viewModel { FileOperationViewModel(get(), get(), get(), get(), get()) }
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ import com.owncloud.android.domain.files.model.OCFile
sealed class FileOperation {
data class MoveOperation(val listOfFilesToMove: List<OCFile>, val targetFolder: OCFile) : FileOperation()
data class RemoveOperation(val listOfFilesToRemove: List<OCFile>, val removeOnlyLocalCopy: Boolean) : FileOperation()
data class RenameOperation(val ocFileToRename: OCFile, val newName: String) : FileOperation()
}
Loading

0 comments on commit 917eeaa

Please sign in to comment.