diff --git a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt index 35ff8f3fcc..890635cd37 100644 --- a/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt +++ b/app/src/main/java/com/infomaniak/drive/data/cache/FileController.kt @@ -243,9 +243,9 @@ object FileController { return apiResponse } - fun updateFolderColor(file: File, color: String, realm: Realm? = null): ApiResponse { + fun updateFolderColor(file: File, color: String, userDrive: UserDrive): ApiResponse { return ApiRepository.updateFolderColor(file, color).also { - if (it.isSuccess()) updateFile(file.id, realm) { localFile -> localFile.color = color } + if (it.isSuccess()) updateFile(file.id, userDrive = userDrive) { localFile -> localFile.color = color } } } @@ -254,7 +254,7 @@ object FileController { realm: Realm? = null, userDrive: UserDrive? = null, context: Context, - onSuccess: ((fileId: Int) -> Unit)? = null + onSuccess: ((fileId: Int) -> Unit)? = null, ): ApiResponse { val apiResponse = ApiRepository.deleteFile(file) if (apiResponse.isSuccess()) { @@ -294,6 +294,7 @@ object FileController { } realm?.let(block) ?: getRealmInstance(userDrive).use(block) } catch (exception: Exception) { + exception.printStackTrace() Sentry.withScope { scope -> scope.setExtra("custom realm", "${realm != null}") Sentry.captureException(exception) diff --git a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt index 3eb485ffd0..4a8e2bb351 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt @@ -364,11 +364,8 @@ class MainViewModel( emit(FileController.renameFile(file, newName)) } - fun updateFolderColor(file: File, color: String) = liveData(Dispatchers.IO) { - val fileResult = FileResult( - isSuccess = FileController.updateFolderColor(file, color).isSuccess() - ) - emit(fileResult) + fun updateFolderColor(file: File, color: String, userDrive: UserDrive) = liveData(Dispatchers.IO) { + emit(FileResult(isSuccess = FileController.updateFolderColor(file, color, userDrive).isSuccess())) } fun manageCategory(categoryId: Int, files: List, isAdding: Boolean) = liveData(Dispatchers.IO) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/FileInfoActionsBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/FileInfoActionsBottomSheetDialog.kt index 991beef9e2..8490039009 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/FileInfoActionsBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/FileInfoActionsBottomSheetDialog.kt @@ -115,15 +115,16 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc private fun updateFolderColor(color: String) { if (isResumed) { - mainViewModel.updateFolderColor(currentFile, color).observe(viewLifecycleOwner) { fileRequest -> - findNavController().popBackStack() - val snackbarText = if (fileRequest.isSuccess) { - resources.getQuantityString(R.plurals.fileListColorFolderConfirmationSnackbar, 1) - } else { - fileRequest.errorResId?.let { getString(it) } + mainViewModel.updateFolderColor(currentFile, color, navigationArgs.userDrive) + .observe(viewLifecycleOwner) { fileRequest -> + findNavController().popBackStack() + val snackbarText = if (fileRequest.isSuccess) { + resources.getQuantityString(R.plurals.fileListColorFolderConfirmationSnackbar, 1) + } else { + fileRequest.errorResId?.let { getString(it) } + } + snackbarText?.let { text -> showSnackbar(text, showAboveFab = true) } } - snackbarText?.let { text -> showSnackbar(text, showAboveFab = true) } - } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileAdapter.kt index 590faab588..5b1620057a 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileAdapter.kt @@ -472,13 +472,20 @@ open class FileAdapter( } override fun areContentsTheSame(oldItem: File, newItem: File): Boolean { + + val areCategoriesTheSame = oldItem.categories.size == newItem.categories.size && + oldItem.categories.filterIndexed { index, fileCategory -> + newItem.categories[index]?.categoryId != fileCategory.categoryId + }.isEmpty() + return oldItem.name == newItem.name && oldItem.isFavorite == newItem.isFavorite && oldItem.isOffline == newItem.isOffline && + oldItem.color == newItem.color && oldItem.lastModifiedAt == newItem.lastModifiedAt && - oldItem.size == newItem.size + oldItem.size == newItem.size && + areCategoriesTheSame } - } companion object { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectFragment.kt index 36ccc31027..b19ab6e0a0 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectFragment.kt @@ -417,8 +417,9 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen BulkOperationType.MANAGE_CATEGORIES -> Unit BulkOperationType.COLOR_FOLDER -> { if (color != null && file.isAllowedToBeColored()) { + val userDrive = UserDrive(sharedWithMe = file.getVisibilityType() == File.VisibilityType.IS_IN_SHARED_SPACE) mediator.addSource( - updateFolderColor(file, color), + updateFolderColor(file, color, userDrive), updateMultiSelectMediator(mediator), ) } else {