Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shared with me list not updated for colored folder #1453

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ object FileController {
return apiResponse
}

fun updateFolderColor(file: File, color: String, realm: Realm? = null): ApiResponse<Boolean> {
fun updateFolderColor(file: File, color: String, userDrive: UserDrive): ApiResponse<Boolean> {
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 }
}
}

Expand All @@ -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<CancellableAction> {
val apiResponse = ApiRepository.deleteFile(file)
if (apiResponse.isSuccess()) {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions app/src/main/java/com/infomaniak/drive/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<File>, isAdding: Boolean) = liveData(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading