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: Show a snackbar when a conflict error occurs #1529

Merged
merged 2 commits into from
Feb 25, 2025
Merged
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 @@ -29,6 +29,7 @@ import androidx.navigation.navGraphViewModels
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.infomaniak.drive.MatomoDrive.trackTrashEvent
import com.infomaniak.drive.R
import com.infomaniak.drive.data.api.ErrorCode
import com.infomaniak.drive.data.models.File
import com.infomaniak.drive.databinding.FragmentBottomSheetTrashedFileActionsBinding
import com.infomaniak.drive.ui.MainViewModel
Expand Down Expand Up @@ -113,6 +114,12 @@ class TrashedFileActionsBottomSheetDialog : BottomSheetDialogFragment() {
}
}

private fun getErrorMessage(fileResult: FileResult) = when (fileResult.errorCode) {
ApiErrorCode.AN_ERROR_HAS_OCCURRED -> R.string.errorRestore
ErrorCode.CONFLICT_ERROR -> R.string.errorConflict
else -> fileResult.errorResId
}

private fun restoreResult(fileResult: FileResult, originalPlace: Boolean, folderName: String? = null) {
if (fileResult.isSuccess) {
val title = if (originalPlace) R.plurals.trashedFileRestoreFileToOriginalPlaceSuccess
Expand All @@ -125,8 +132,7 @@ class TrashedFileActionsBottomSheetDialog : BottomSheetDialogFragment() {
showSnackbar(resources.getQuantityString(title, 1, *args.toTypedArray()))
dismissAndRemoveFileFromList()
} else {
val snackbarText = if (fileResult.errorCode == ApiErrorCode.AN_ERROR_HAS_OCCURRED) R.string.errorRestore
else fileResult.errorResId
val snackbarText = getErrorMessage(fileResult)

snackbarText?.let { text -> showSnackbar(text) }
findNavController().popBackStack()
Expand Down
Loading