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 504aff40a1..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()) { - requireActivity().showSnackbar(getString(R.string.modalCreateFileSucces, createFile.name)) + showSnackbar(getString(R.string.modalCreateFileSucces, createFile.name), true) apiResponse.data?.let { file -> requireContext().openOnlyOfficeActivity(file) } } else { - requireActivity().showSnackbar(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) { - requireActivity().showSnackbar(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() - requireActivity().showSnackbar(R.string.errorDeviceStorage) + showSnackbar(R.string.errorDeviceStorage, true) } } @@ -260,10 +260,10 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() { when { isLowMemory -> { - requireActivity().showSnackbar(R.string.uploadOutOfMemoryError) + showSnackbar(R.string.uploadOutOfMemoryError, true) } fileName == null -> { - requireActivity().showSnackbar(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 0c915f4d14..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 @@ -48,7 +48,6 @@ import com.infomaniak.drive.utils.Utils.openWith import com.infomaniak.drive.utils.Utils.openWithIntent import com.infomaniak.drive.views.FileInfoActionsView import com.infomaniak.lib.core.models.ApiResponse -import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_bottom_sheet_file_info_actions.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -120,7 +119,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc } else { getString(apiResponse.translatedError) } - requireActivity().showSnackbar(text, mainFab) + showSnackbar(text, true) } } } @@ -189,11 +188,9 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc override fun copyPublicLink() { super.copyPublicLink() fileInfoActionsView.createPublicCopyLink(onSuccess = { - requireActivity().showSnackbar(title = R.string.fileInfoLinkCopiedToClipboard, anchorView = requireActivity().mainFab) + showSnackbar(R.string.fileInfoLinkCopiedToClipboard, true) findNavController().popBackStack() - }, onError = { translatedError -> - requireActivity().showSnackbar(translatedError, anchorView = requireActivity().mainFab) - }) + }, onError = { translatedError -> showSnackbar(translatedError, true) }) } override fun downloadFileClicked() { @@ -226,7 +223,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc showFavoritesResultSnackbar() setBackNavigationResult(REFRESH_FAVORITE_FILE, currentFile.id) } else { - requireActivity().showSnackbar(R.string.errorAddFavorite, requireActivity().mainFab) + showSnackbar(R.string.errorAddFavorite, true) findNavController().popBackStack() } } @@ -321,7 +318,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc override fun openWithClicked() { super.openWithClicked() if (requireContext().openWithIntent(currentFile).resolveActivity(requireContext().packageManager) == null) { - requireActivity().showSnackbar(R.string.allActivityNotFoundError) + showSnackbar(R.string.allActivityNotFoundError, true) findNavController().popBackStack() } else { safeNavigate( @@ -367,17 +364,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc } private fun File.showFavoritesResultSnackbar() { - if (isFavorite) { - requireActivity().showSnackbar( - getString(R.string.allFileAddFavoris, name), - anchorView = requireActivity().mainFab - ) - } else { - requireActivity().showSnackbar( - getString(R.string.allFileDeleteFavoris, name), - anchorView = requireActivity().mainFab - ) - } + 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 963c8ec163..9f993cae1a 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 @@ -67,7 +67,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.* @@ -279,12 +278,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, true, onActionClicked = onCancelActionClicked) + } ?: run { showSnackbar(title, 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..8b4c8eef4c 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(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..61aa84a178 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(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 72b12a284d..443e1973ed 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 @@ -171,7 +171,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 cbdd1ebc76..33f545cd07 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 @@ -297,7 +296,7 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen ) } } else { - requireActivity().showSnackbar(apiResponse.translateError()) + showSnackbar(apiResponse.translateError()) } closeMultiSelect() } @@ -441,7 +440,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..0f46c14b22 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(R.string.fileInfoLinkCopiedToClipboard) toggleBottomSheet(true) }, onError = { translatedError -> - requireActivity().showSnackbar(title = translatedError) + showSnackbar(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(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(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..84a5ea2bf2 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(R.string.errorPreviewTrash, 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 5681df0bbb..3058ed9369 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 bebcc53e4b..71ad761765 100644 --- a/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt +++ b/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt @@ -93,7 +93,6 @@ import com.infomaniak.lib.core.networking.HttpUtils import com.infomaniak.lib.core.utils.UtilsUi.generateInitialsAvatarDrawable import com.infomaniak.lib.core.utils.UtilsUi.getBackgroundColorBasedOnId import com.infomaniak.lib.core.utils.UtilsUi.getInitials -import com.infomaniak.lib.core.utils.toDp import io.realm.RealmList import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.item_file.view.* @@ -429,13 +428,22 @@ fun Activity.showSnackbar( ) } -fun Fragment.showSnackBarInvalidFileName(fileName: String) { - activity?.let { - it.showSnackbar( - getString(R.string.snackBarInvalidFileNameError, Utils.getInvalidFileNameCharacter(fileName), fileName), - it.mainFab - ) - } +fun Fragment.showSnackbar( + titleId: Int, + showAboveFab: Boolean = false, + actionButtonTitle: Int = R.string.buttonCancel, + onActionClicked: (() -> Unit)? = null +) { + showSnackbar(getString(titleId), showAboveFab, actionButtonTitle, onActionClicked) +} + +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 0251e892ed..5b9a34a07a 100644 --- a/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt +++ b/app/src/main/java/com/infomaniak/drive/views/FileInfoActionsView.kt @@ -211,11 +211,19 @@ class FileInfoActionsView @JvmOverloads constructor( availableOfflineSwitch.setOnClickListener { view -> val downloadError = !onItemClickListener.availableOfflineSwitched(this, (view as SwitchMaterial).isChecked) with(ownerFragment) { + val isBottomSheetFragmentView = + findNavController().currentBackStackEntry?.destination?.id == R.id.fileInfoActionsBottomSheetDialog if (downloadError) { availableOfflineSwitch.isChecked = false - showSnackBarInvalidFileName(currentFile.name) + val fileName = currentFile.name + showSnackbar( + getString(R.string.snackBarInvalidFileNameError, Utils.getInvalidFileNameCharacter(fileName), fileName), + isBottomSheetFragmentView + ) + } + if (isBottomSheetFragmentView) { + findNavController().popBackStack() } - findNavController().popBackStack() } } availableOffline.setOnClickListener { availableOfflineSwitch.performClick() }