Skip to content

Commit

Permalink
Replace requireActivity().showSnackBar
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Apr 4, 2022
1 parent 12e807e commit bc0fa47
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() {
}
} catch (exception: Exception) {
exception.printStackTrace()
showSnackbarAboveFab(R.string.errorDeviceStorage)
showSnackbar(R.string.errorDeviceStorage, true)
}
}

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ 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)
}
}

private fun whenFolderCreated(file: File) {
requireActivity().showSnackbar(R.string.createCommonFolderSucces)
showSnackbar(R.string.createCommonFolderSucces)

if (newFolderViewModel.currentPermission == SPECIFIC_USERS) {
safeNavigate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CreateDropBoxFolderFragment : CreateFolderFragment() {
navigateToFileShareDetails(file)
}
}, onError = { translatedError ->
requireActivity().showSnackbar(translatedError)
showSnackbar(translatedError)
findNavController().popBackStack(R.id.newFolderFragment, true)
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc
} else {
getString(apiResponse.translatedError)
}
showSnackbarAboveFab(text)
showSnackbar(text, true)
}
}
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DownloadProgressDialog : DialogFragment() {
downloadProgress.progress = progress
}
} ?: run {
requireActivity().showSnackbar(R.string.anErrorHasOccurred)
showSnackbar(R.string.anErrorHasOccurred)
findNavController().popBackStack()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down Expand Up @@ -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) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class SearchFragment : FileListFragment() {

fun handleApiCallFailure(apiResponse: ApiResponse<ArrayList<File>>) {
searchViewModel.visibilityMode.value = VisibilityMode.NO_RESULTS
requireActivity().showSnackbar(apiResponse.translateError())
showSnackbar(apiResponse.translateError())
}

fun getSearchResults(data: ArrayList<File>?): ArrayList<File> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -165,7 +165,7 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() {
fileComment.likesCount = fileComment.likesCount - 1
commentsAdapter.updateComment(fileComment)
} else {
requireActivity().showSnackbar(apiResponse.translatedError)
showSnackbar(apiResponse.translatedError)
}
}
} else {
Expand All @@ -179,7 +179,7 @@ class FileDetailsCommentsFragment : FileDetailsSubFragment() {
fileComment.likesCount = fileComment.likesCount + 1
commentsAdapter.updateComment(fileComment)
} else {
requireActivity().showSnackbar(apiResponse.translatedError)
showSnackbar(apiResponse.translatedError)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand All @@ -306,7 +306,7 @@ class FileDetailsInfoFragment : FileDetailsSubFragment() {
if (success) {
shareLinkContainer.update(null)
} else {
requireActivity().showSnackbar(apiResponse.translateError())
showSnackbar(apiResponse.translateError())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand All @@ -260,7 +260,7 @@ class FileShareDetailsFragment : Fragment() {
if (success) {
shareLinkContainer.update(null)
} else {
requireActivity().showSnackbar(apiResponse.translateError())
showSnackbar(apiResponse.translateError())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -276,7 +275,7 @@ abstract class MultiSelectFragment(private val matomoCategory: String) : Fragmen
)
}
} else {
requireActivity().showSnackbar(apiResponse.translateError())
showSnackbar(apiResponse.translateError())
}
closeMultiSelect()
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit bc0fa47

Please sign in to comment.