From bc0fa47f5d90516ae2d379c895f1068065ad5f7e Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Mon, 4 Apr 2022 12:01:29 +0200 Subject: [PATCH] Replace requireActivity().showSnackBar --- .../ui/addFiles/AddFileBottomSheetDialog.kt | 12 +++---- .../ui/addFiles/CreateCommonFolderFragment.kt | 4 +-- .../addFiles/CreateDropBoxFolderFragment.kt | 2 +- .../drive/ui/addFiles/CreateFolderFragment.kt | 2 +- .../addFiles/CreatePrivateFolderFragment.kt | 3 +- .../FileInfoActionsBottomSheetDialog.kt | 12 +++---- .../NotSupportedExtensionBottomSheetDialog.kt | 2 +- .../TrashedFileActionsBottomSheetDialog.kt | 8 ++--- .../ui/fileList/ConvertToDropBoxFragment.kt | 2 +- .../ui/fileList/DownloadProgressDialog.kt | 2 +- .../drive/ui/fileList/FileListFragment.kt | 9 ++--- .../ui/fileList/ManageDropboxFragment.kt | 6 ++-- .../drive/ui/fileList/SearchFragment.kt | 2 +- .../FileDetailsCommentsFragment.kt | 10 +++--- .../fileDetails/FileDetailsInfoFragment.kt | 4 +-- .../fileShare/FileShareDetailsFragment.kt | 4 +-- .../FileShareLinkSettingsFragment.kt | 2 +- .../MultiSelectActionsBottomSheetDialog.kt | 2 +- .../multiSelect/MultiSelectFragment.kt | 5 ++- .../fileList/preview/PreviewSliderFragment.kt | 36 ++++++++----------- .../drive/ui/home/HomeActivitiesFragment.kt | 10 ++---- .../infomaniak/drive/ui/menu/TrashFragment.kt | 2 +- .../com/infomaniak/drive/utils/Extensions.kt | 18 +++++++--- .../drive/views/FileInfoActionsView.kt | 2 +- 24 files changed, 76 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/com/infomaniak/drive/ui/addFiles/AddFileBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/addFiles/AddFileBottomSheetDialog.kt index a13c0c4761..e748ebb7cf 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/addFiles/AddFileBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/addFiles/AddFileBottomSheetDialog.kt @@ -186,10 +186,10 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() { mainViewModel.createOffice(currentFolderFile.driveId, currentFolderFile.id, createFile) .observe(viewLifecycleOwner) { apiResponse -> if (apiResponse.isSuccess()) { - showSnackbarAboveFab(getString(R.string.modalCreateFileSucces, createFile.name)) + showSnackbar(getString(R.string.modalCreateFileSucces, createFile.name), true) apiResponse.data?.let { file -> requireContext().openOnlyOfficeActivity(file) } } else { - showSnackbarAboveFab(R.string.errorFileCreate) + showSnackbar(R.string.errorFileCreate, true) } mainViewModel.refreshActivities.value = true dialog.dismiss() @@ -215,7 +215,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() { launchSync = true } } catch (exception: Exception) { - showSnackbarAboveFab(R.string.errorDeviceStorage) + showSnackbar(R.string.errorDeviceStorage, true) } finally { if (launchSync) requireContext().syncImmediately() } @@ -244,7 +244,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() { } } catch (exception: Exception) { exception.printStackTrace() - showSnackbarAboveFab(R.string.errorDeviceStorage) + showSnackbar(R.string.errorDeviceStorage, true) } } @@ -260,10 +260,10 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() { when { isLowMemory -> { - showSnackbarAboveFab(R.string.uploadOutOfMemoryError) + showSnackbar(R.string.uploadOutOfMemoryError, true) } fileName == null -> { - showSnackbarAboveFab(R.string.anErrorHasOccurred) + showSnackbar(R.string.anErrorHasOccurred, true) } else -> { CoroutineScope(Dispatchers.IO).launch { diff --git a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateCommonFolderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateCommonFolderFragment.kt index d79c41d145..b36927b710 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateCommonFolderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateCommonFolderFragment.kt @@ -80,7 +80,7 @@ class CreateCommonFolderFragment : CreateFolderFragment() { if (apiResponse.error?.code == ErrorCode.DESTINATION_ALREADY_EXISTS.code) { folderNameValueLayout.error = getString(apiResponse.translateError()) } - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } createFolderButton.hideProgress(R.string.createFolderTitle) @@ -88,7 +88,7 @@ class CreateCommonFolderFragment : CreateFolderFragment() { } private fun whenFolderCreated(file: File) { - requireActivity().showSnackbar(R.string.createCommonFolderSucces) + showSnackbar(R.string.createCommonFolderSucces) if (newFolderViewModel.currentPermission == SPECIFIC_USERS) { safeNavigate( diff --git a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateDropBoxFolderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateDropBoxFolderFragment.kt index 59950c1c56..2cc0d962a3 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateDropBoxFolderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateDropBoxFolderFragment.kt @@ -79,7 +79,7 @@ class CreateDropBoxFolderFragment : CreateFolderFragment() { navigateToFileShareDetails(file) } }, onError = { translatedError -> - requireActivity().showSnackbar(translatedError) + showSnackbar(translatedError) findNavController().popBackStack(R.id.newFolderFragment, true) }) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateFolderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateFolderFragment.kt index 5499348196..490fd0a286 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateFolderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreateFolderFragment.kt @@ -128,7 +128,7 @@ open class CreateFolderFragment : Fragment() { if (apiResponse.formatError() == ErrorCode.DESTINATION_ALREADY_EXISTS) { folderNameValueLayout.error = getString(apiResponse.translateError()) } - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } createFolderButton.hideProgress(R.string.createFolderTitle) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreatePrivateFolderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreatePrivateFolderFragment.kt index a6e21a7c1c..667e4f29ad 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreatePrivateFolderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/addFiles/CreatePrivateFolderFragment.kt @@ -26,7 +26,6 @@ import com.infomaniak.drive.data.models.Permission import com.infomaniak.drive.utils.MatomoUtils.trackNewElementEvent import com.infomaniak.drive.utils.safeNavigate import com.infomaniak.drive.utils.showSnackbar -import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_create_folder.* class CreatePrivateFolderFragment : CreateFolderFragment() { @@ -54,7 +53,7 @@ class CreatePrivateFolderFragment : CreateFolderFragment() { createFolder(newFolderViewModel.currentPermission == ONLY_ME) { file, redirectToShareDetails -> file?.let { saveNewFolder(file) - requireActivity().showSnackbar(R.string.createPrivateFolderSucces, anchorView = requireActivity().mainFab) + showSnackbar(R.string.createPrivateFolderSucces, true) if (redirectToShareDetails) { safeNavigate( CreatePrivateFolderFragmentDirections.actionCreatePrivateFolderFragmentToFileShareDetailsFragment( 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 dd58f24acb..4ff5b495a1 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 @@ -119,7 +119,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc } else { getString(apiResponse.translatedError) } - showSnackbarAboveFab(text) + showSnackbar(text, true) } } } @@ -188,9 +188,9 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc override fun copyPublicLink() { super.copyPublicLink() fileInfoActionsView.createPublicCopyLink(onSuccess = { - showSnackbarAboveFab(R.string.fileInfoLinkCopiedToClipboard) + showSnackbar(R.string.fileInfoLinkCopiedToClipboard, true) findNavController().popBackStack() - }, onError = { translatedError -> showSnackbarAboveFab(translatedError) }) + }, onError = { translatedError -> showSnackbar(translatedError, true) }) } override fun downloadFileClicked() { @@ -223,7 +223,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc showFavoritesResultSnackbar() setBackNavigationResult(REFRESH_FAVORITE_FILE, currentFile.id) } else { - showSnackbarAboveFab(R.string.errorAddFavorite) + showSnackbar(R.string.errorAddFavorite, true) findNavController().popBackStack() } } @@ -318,7 +318,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc override fun openWithClicked() { super.openWithClicked() if (requireContext().openWithIntent(currentFile).resolveActivity(requireContext().packageManager) == null) { - showSnackbarAboveFab(R.string.allActivityNotFoundError) + showSnackbar(R.string.allActivityNotFoundError, true) findNavController().popBackStack() } else { safeNavigate( @@ -364,7 +364,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc } private fun File.showFavoritesResultSnackbar() { - showSnackbarAboveFab(getString(if (isFavorite) R.string.allFileAddFavoris else R.string.allFileDeleteFavoris, name)) + showSnackbar(getString(if (isFavorite) R.string.allFileAddFavoris else R.string.allFileDeleteFavoris, name), true) } private fun transmitActionAndPopBack(message: String, action: CancellableAction? = null) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/NotSupportedExtensionBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/NotSupportedExtensionBottomSheetDialog.kt index 81b84e9b99..007e1fff40 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/NotSupportedExtensionBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/NotSupportedExtensionBottomSheetDialog.kt @@ -61,7 +61,7 @@ class NotSupportedExtensionBottomSheetDialog : InformationBottomSheetDialog() { ApiResponse.Status.SUCCESS -> apiResponse.data?.let { newFile -> requireContext().openOnlyOfficeActivity(newFile) } - else -> requireActivity().showSnackbar(apiResponse.translateError()) + else -> showSnackbar(apiResponse.translateError()) } dismiss() } diff --git a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/TrashedFileActionsBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/TrashedFileActionsBottomSheetDialog.kt index f92b0a047a..7e5ba9955b 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/TrashedFileActionsBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/bottomSheetDialogs/TrashedFileActionsBottomSheetDialog.kt @@ -92,10 +92,10 @@ class TrashedFileActionsBottomSheetDialog : BottomSheetDialogFragment() { dialog.dismiss() if (apiResponse.data == true) { val title = resources.getQuantityString(R.plurals.snackbarDeleteConfirmation, 1, currentTrashedFile.name) - requireActivity().showSnackbar(title) + showSnackbar(title) dismissAndRemoveFileFromList() } else { - requireActivity().showSnackbar(R.string.errorDelete) + showSnackbar(R.string.errorDelete) findNavController().popBackStack() } } @@ -112,13 +112,13 @@ class TrashedFileActionsBottomSheetDialog : BottomSheetDialogFragment() { if (!originalPlace && folderName != null) add(folderName) } - requireActivity().showSnackbar(resources.getQuantityString(title, 1, *args.toTypedArray())) + showSnackbar(resources.getQuantityString(title, 1, *args.toTypedArray())) dismissAndRemoveFileFromList() } else { val title = if (apiResponse.formatError() == ErrorCode.AN_ERROR_HAS_OCCURRED) R.string.errorRestore else apiResponse.translateError() - requireActivity().showSnackbar(title) + showSnackbar(title) findNavController().popBackStack() } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/ConvertToDropBoxFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/ConvertToDropBoxFragment.kt index 8762c717a1..0994ca6053 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/ConvertToDropBoxFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/ConvertToDropBoxFragment.kt @@ -67,7 +67,7 @@ class ConvertToDropBoxFragment : ManageDropboxFragment() { mainViewModel.createDropBoxSuccess.value = apiResponse.data findNavController().popBackStack() } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } saveButton.hideProgress(R.string.buttonSave) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/DownloadProgressDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/DownloadProgressDialog.kt index 6cd2cae9a2..881b2c8f47 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/DownloadProgressDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/DownloadProgressDialog.kt @@ -81,7 +81,7 @@ class DownloadProgressDialog : DialogFragment() { downloadProgress.progress = progress } } ?: run { - requireActivity().showSnackbar(R.string.anErrorHasOccurred) + showSnackbar(R.string.anErrorHasOccurred) findNavController().popBackStack() } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt index 0341fe046c..f723ac909a 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/FileListFragment.kt @@ -68,7 +68,6 @@ import com.infomaniak.lib.core.utils.hideProgress import com.infomaniak.lib.core.utils.initProgress import com.infomaniak.lib.core.utils.setPagination import com.infomaniak.lib.core.utils.showProgress -import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_file_list.* import kotlinx.coroutines.* @@ -278,12 +277,8 @@ open class FileListFragment : MultiSelectFragment(MATOMO_CATEGORY), SwipeRefresh } }) else null - requireActivity().showSnackbar( - title, - anchorView = requireActivity().mainFab, - onActionClicked = onCancelActionClicked - ) - } ?: run { requireActivity().showSnackbar(title, anchorView = requireActivity().mainFab) } + showSnackbar(title, showAboveFab = true, onActionClicked = onCancelActionClicked) + } ?: run { showSnackbar(title, showAboveFab = true) } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/ManageDropboxFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/ManageDropboxFragment.kt index 2ce6a0ec22..57eb097cb7 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/ManageDropboxFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/ManageDropboxFragment.kt @@ -94,7 +94,7 @@ open class ManageDropboxFragment : Fragment() { if (apiResponse?.isSuccess() == true) { apiResponse.data?.let { updateUi(file, it) } } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } } } @@ -165,7 +165,7 @@ open class ManageDropboxFragment : Fragment() { if (apiResponse.isSuccess()) { findNavController().popBackStack() } else { - requireActivity().showSnackbar(R.string.errorDelete) + showSnackbar(R.string.errorDelete) } hideProgress(R.string.buttonDisableDropBox) } @@ -190,7 +190,7 @@ open class ManageDropboxFragment : Fragment() { if (apiResponse.isSuccess()) { findNavController().popBackStack() } else { - requireActivity().showSnackbar(R.string.errorModification) + showSnackbar(R.string.errorModification) } hideProgress(R.string.buttonSave) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/SearchFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/SearchFragment.kt index d81d9b0265..f5e9d87a3a 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/SearchFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/SearchFragment.kt @@ -237,7 +237,7 @@ class SearchFragment : FileListFragment() { fun handleApiCallFailure(apiResponse: ApiResponse>) { searchViewModel.visibilityMode.value = VisibilityMode.NO_RESULTS - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } fun getSearchResults(data: ArrayList?): ArrayList { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsCommentsFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsCommentsFragment.kt index 49403af5bd..cba36211e4 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsCommentsFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsCommentsFragment.kt @@ -80,10 +80,10 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() { if (apiResponse.isSuccess()) { apiResponse?.data?.let { comment -> commentsAdapter.addComment(comment) - requireActivity().showSnackbar(R.string.fileDetailsCommentsConfirmationSnackbar) + showSnackbar(R.string.fileDetailsCommentsConfirmationSnackbar) } } else { - requireActivity().showSnackbar(R.string.errorAddComment) + showSnackbar(R.string.errorAddComment) } dialog.dismiss() noCommentsLayout.toggleVisibility(commentsAdapter.itemCount == 0, showRefreshButton = false) @@ -147,7 +147,7 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() { commentsAdapter.deleteComment(comment) noCommentsLayout.toggleVisibility(commentsAdapter.itemCount == 0, showRefreshButton = false) } else { - requireActivity().showSnackbar(R.string.errorDelete) + showSnackbar(R.string.errorDelete) } } } @@ -165,7 +165,7 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() { fileComment.likesCount = fileComment.likesCount - 1 commentsAdapter.updateComment(fileComment) } else { - requireActivity().showSnackbar(apiResponse.translatedError) + showSnackbar(apiResponse.translatedError) } } } else { @@ -179,7 +179,7 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() { fileComment.likesCount = fileComment.likesCount + 1 commentsAdapter.updateComment(fileComment) } else { - requireActivity().showSnackbar(apiResponse.translatedError) + showSnackbar(apiResponse.translatedError) } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt index ee63c527ea..af5cf91df4 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsInfoFragment.kt @@ -295,7 +295,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() { if (apiResponse.isSuccess()) { shareLinkContainer.update(apiResponse.data) } else { - requireActivity().showSnackbar(getString(R.string.errorShareLink)) + showSnackbar(getString(R.string.errorShareLink)) } } } @@ -306,7 +306,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() { if (success) { shareLinkContainer.update(null) } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareDetailsFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareDetailsFragment.kt index 4ef84587ed..9738182b20 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareDetailsFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareDetailsFragment.kt @@ -249,7 +249,7 @@ class FileShareDetailsFragment : Fragment() { if (apiResponse.isSuccess()) { shareLinkContainer.update(apiResponse.data) } else { - requireActivity().showSnackbar(getString(R.string.errorShareLink)) + showSnackbar(getString(R.string.errorShareLink)) } } } @@ -260,7 +260,7 @@ class FileShareDetailsFragment : Fragment() { if (success) { shareLinkContainer.update(null) } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareLinkSettingsFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareLinkSettingsFragment.kt index 97bae9c20d..56fccd86bb 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareLinkSettingsFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/FileShareLinkSettingsFragment.kt @@ -159,7 +159,7 @@ class FileShareLinkSettingsFragment : Fragment() { if (apiResponse.data == true) { findNavController().popBackStack() } else { - requireActivity().showSnackbar(R.string.errorModification) + showSnackbar(R.string.errorModification) } saveButton?.hideProgress(R.string.buttonSave) } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectActionsBottomSheetDialog.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectActionsBottomSheetDialog.kt index a5538432d0..cd183045c2 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectActionsBottomSheetDialog.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/multiSelect/MultiSelectActionsBottomSheetDialog.kt @@ -170,7 +170,7 @@ abstract class MultiSelectActionsBottomSheetDialog(private val matomoCategory: S requireContext().startDownloadFile(downloadURL, ARCHIVE_FILE_NAME) } } else { - requireActivity().showSnackbar(apiResponse.translatedError) + showSnackbar(apiResponse.translatedError) } onActionSelected() } 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 4760f5e072..316b1ffd7b 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 @@ -57,7 +57,6 @@ import com.infomaniak.drive.utils.BulkOperationsUtils.launchBulkOperationWorker import com.infomaniak.drive.utils.MatomoUtils.trackEvent import com.infomaniak.drive.utils.NotificationUtils.showGeneralNotification import com.infomaniak.drive.utils.Utils.moveFileClicked -import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -276,7 +275,7 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen ) } } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } closeMultiSelect() } @@ -420,7 +419,7 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen } else { resources.getQuantityString(type.successMessage, success, success, destinationFolder?.name + "/") } - requireActivity().showSnackbar(title, anchorView = requireActivity().mainFab) + showSnackbar(title, true) closeMultiSelect() onAllIndividualActionsFinished(type) diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt index 9b61adf36f..2675598e28 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewSliderFragment.kt @@ -327,10 +327,10 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene override fun copyPublicLink() { bottomSheetFileInfos.createPublicCopyLink(onSuccess = { file -> previewSliderAdapter.updateFile(currentFile.id) { it.shareLink = file?.shareLink } - requireActivity().showSnackbar(title = R.string.fileInfoLinkCopiedToClipboard) + showSnackbar(titleId = R.string.fileInfoLinkCopiedToClipboard) toggleBottomSheet(true) }, onError = { translatedError -> - requireActivity().showSnackbar(title = translatedError) + showSnackbar(title = translatedError) toggleBottomSheet(true) }) } @@ -344,7 +344,7 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene showFavoritesResultSnackbar() bottomSheetFileInfos.refreshBottomSheetUi(this) } else { - requireActivity().showSnackbar(R.string.errorDelete) + showSnackbar(R.string.errorDelete) } toggleBottomSheet(true) } @@ -367,7 +367,7 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene private fun File.showFavoritesResultSnackbar() { val id = if (isFavorite) R.string.allFileAddFavoris else R.string.allFileDeleteFavoris - requireActivity().showSnackbar(getString(id, name)) + showSnackbar(getString(id, name)) } override fun removeOfflineFile(offlineLocalPath: java.io.File, cacheFile: java.io.File) { @@ -392,9 +392,9 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene toggleBottomSheet(true) } mainViewModel.currentPreviewFileList.remove(currentFile.id) - requireActivity().showSnackbar(R.string.snackbarLeaveShareConfirmation) + showSnackbar(R.string.snackbarLeaveShareConfirmation) } else { - requireActivity().showSnackbar(apiResponse.translatedError) + showSnackbar(apiResponse.translatedError) } } } @@ -422,11 +422,11 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene apiResponse.data?.let { file -> mainViewModel.currentPreviewFileList[file.id] = file previewSliderAdapter.addFile(file) - requireActivity().showSnackbar(getString(R.string.allFileDuplicate, currentFile.name)) + showSnackbar(getString(R.string.allFileDuplicate, currentFile.name)) toggleBottomSheet(true) } } else { - requireActivity().showSnackbar(getString(R.string.errorDuplicate)) + showSnackbar(getString(R.string.errorDuplicate)) toggleBottomSheet(true) } onApiResponse() @@ -437,11 +437,11 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene bottomSheetFileInfos.onRenameFile(mainViewModel, newName, onSuccess = { toggleBottomSheet(true) - requireActivity().showSnackbar(getString(R.string.allFileRename, currentFile.name)) + showSnackbar(getString(R.string.allFileRename, currentFile.name)) onApiResponse() }, onError = { translatedError -> toggleBottomSheet(true) - requireActivity().showSnackbar(translatedError) + showSnackbar(translatedError) onApiResponse() }) } @@ -461,10 +461,10 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene 1, currentFile.name ) - requireActivity().showSnackbar(title) + showSnackbar(title) mainViewModel.deleteFileFromHome.value = true } else { - requireActivity().showSnackbar(getString(R.string.errorDelete)) + showSnackbar(getString(R.string.errorDelete)) } } } @@ -473,7 +473,7 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene super.openWithClicked() val packageManager = requireContext().packageManager if (requireContext().openWithIntent(currentFile, userDrive).resolveActivity(packageManager) == null) { - requireActivity().showSnackbar(R.string.allActivityNotFoundError) + showSnackbar(R.string.allActivityNotFoundError) } else { safeNavigate( PreviewSliderFragmentDirections.actionPreviewSliderFragmentToDownloadProgressDialog( @@ -490,15 +490,9 @@ class PreviewSliderFragment : Fragment(), FileInfoActionsView.OnItemClickListene .observe(viewLifecycleOwner) { apiResponse -> if (apiResponse.isSuccess()) { mainViewModel.refreshActivities.value = true - requireActivity().showSnackbar( - getString( - R.string.allFileMove, - currentFile.name, - destinationFolder.name - ) - ) + showSnackbar(getString(R.string.allFileMove, currentFile.name, destinationFolder.name)) } else { - requireActivity().showSnackbar(R.string.errorMove) + showSnackbar(R.string.errorMove) } } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/home/HomeActivitiesFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/home/HomeActivitiesFragment.kt index 42443a1300..65fa4a1894 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/home/HomeActivitiesFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/home/HomeActivitiesFragment.kt @@ -30,10 +30,7 @@ import androidx.recyclerview.widget.RecyclerView import com.infomaniak.drive.R import com.infomaniak.drive.data.api.ApiRepository import com.infomaniak.drive.ui.MainViewModel -import com.infomaniak.drive.utils.AccountUtils -import com.infomaniak.drive.utils.Utils -import com.infomaniak.drive.utils.safeNavigate -import com.infomaniak.drive.utils.showSnackbar +import com.infomaniak.drive.utils.* import com.infomaniak.lib.core.utils.setPagination import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_home_tabs.* @@ -93,10 +90,7 @@ class HomeActivitiesFragment : Fragment() { } onFileClicked = { currentFile, validPreviewFiles -> if (currentFile.isTrashed()) { - requireActivity().showSnackbar( - getString(R.string.errorPreviewTrash), - anchorView = requireActivity().mainFab - ) + showSnackbar(getString(R.string.errorPreviewTrash), showAboveFab = true) } else Utils.displayFile(mainViewModel, findNavController(), currentFile, validPreviewFiles) } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt index 3cb0eb828b..df67e67986 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/menu/TrashFragment.kt @@ -116,7 +116,7 @@ class TrashFragment : FileSubTypeListFragment() { Utils.showSnackbar(requireView(), R.string.snackbarEmptyTrashConfirmation) onRefresh() } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } } } diff --git a/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt b/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt index 827de66935..71ad761765 100644 --- a/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt +++ b/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt @@ -428,12 +428,22 @@ fun Activity.showSnackbar( ) } -fun Fragment.showSnackbarAboveFab(titleId: Int, showAboveFab: Boolean = true) { - showSnackbarAboveFab(getString(titleId), showAboveFab) +fun Fragment.showSnackbar( + titleId: Int, + showAboveFab: Boolean = false, + actionButtonTitle: Int = R.string.buttonCancel, + onActionClicked: (() -> Unit)? = null +) { + showSnackbar(getString(titleId), showAboveFab, actionButtonTitle, onActionClicked) } -fun Fragment.showSnackbarAboveFab(title: String, showAboveFab: Boolean = true) { - activity?.let { it.showSnackbar(title, if (showAboveFab) it.mainFab else null) } +fun Fragment.showSnackbar( + title: String, + showAboveFab: Boolean = false, + actionButtonTitle: Int = R.string.buttonCancel, + onActionClicked: (() -> Unit)? = null +) { + activity?.let { it.showSnackbar(title, if (showAboveFab) it.mainFab else null, actionButtonTitle, onActionClicked) } } @SuppressLint("NewApi") diff --git a/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt b/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt index 2ef8351566..5b9a34a07a 100644 --- a/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt +++ b/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt @@ -216,7 +216,7 @@ class FileInfoActionsView @JvmOverloads constructor( if (downloadError) { availableOfflineSwitch.isChecked = false val fileName = currentFile.name - showSnackbarAboveFab( + showSnackbar( getString(R.string.snackBarInvalidFileNameError, Utils.getInvalidFileNameCharacter(fileName), fileName), isBottomSheetFragmentView )