Skip to content

Commit

Permalink
Uniformize snackbar anchorage
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Apr 4, 2022
1 parent ee79f74 commit 1e0cca4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 33 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()) {
requireActivity().showSnackbar(getString(R.string.modalCreateFileSucces, createFile.name))
showSnackbarAboveFab(getString(R.string.modalCreateFileSucces, createFile.name))
apiResponse.data?.let { file -> requireContext().openOnlyOfficeActivity(file) }
} else {
requireActivity().showSnackbar(R.string.errorFileCreate)
showSnackbarAboveFab(R.string.errorFileCreate)
}
mainViewModel.refreshActivities.value = true
dialog.dismiss()
Expand All @@ -215,7 +215,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() {
launchSync = true
}
} catch (exception: Exception) {
requireActivity().showSnackbar(R.string.errorDeviceStorage)
showSnackbarAboveFab(R.string.errorDeviceStorage)
} finally {
if (launchSync) requireContext().syncImmediately()
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() {
}
} catch (exception: Exception) {
exception.printStackTrace()
requireActivity().showSnackbar(R.string.errorDeviceStorage)
showSnackbarAboveFab(R.string.errorDeviceStorage)
}
}

Expand All @@ -260,10 +260,10 @@ class AddFileBottomSheetDialog : BottomSheetDialogFragment() {

when {
isLowMemory -> {
requireActivity().showSnackbar(R.string.uploadOutOfMemoryError)
showSnackbarAboveFab(R.string.uploadOutOfMemoryError)
}
fileName == null -> {
requireActivity().showSnackbar(R.string.anErrorHasOccurred)
showSnackbarAboveFab(R.string.anErrorHasOccurred)
}
else -> {
CoroutineScope(Dispatchers.IO).launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,7 +119,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc
} else {
getString(apiResponse.translatedError)
}
requireActivity().showSnackbar(text, mainFab)
showSnackbarAboveFab(text)
}
}
}
Expand Down Expand Up @@ -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)
showSnackbarAboveFab(R.string.fileInfoLinkCopiedToClipboard)
findNavController().popBackStack()
}, onError = { translatedError ->
requireActivity().showSnackbar(translatedError, anchorView = requireActivity().mainFab)
})
}, onError = { translatedError -> showSnackbarAboveFab(translatedError) })
}

override fun downloadFileClicked() {
Expand Down Expand Up @@ -226,7 +223,7 @@ class FileInfoActionsBottomSheetDialog : BottomSheetDialogFragment(), FileInfoAc
showFavoritesResultSnackbar()
setBackNavigationResult(REFRESH_FAVORITE_FILE, currentFile.id)
} else {
requireActivity().showSnackbar(R.string.errorAddFavorite, requireActivity().mainFab)
showSnackbarAboveFab(R.string.errorAddFavorite)
findNavController().popBackStack()
}
}
Expand Down Expand Up @@ -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)
showSnackbarAboveFab(R.string.allActivityNotFoundError)
findNavController().popBackStack()
} else {
safeNavigate(
Expand Down Expand Up @@ -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
)
}
showSnackbarAboveFab(getString(if (isFavorite) R.string.allFileAddFavoris else R.string.allFileDeleteFavoris, name), true)
}

private fun transmitActionAndPopBack(message: String, action: CancellableAction? = null) {
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/java/com/infomaniak/drive/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -429,11 +428,12 @@ fun Activity.showSnackbar(
)
}

fun Fragment.showSnackBarInvalidFileName(fileName: String, anchorView: View? = null) {
activity?.showSnackbar(
getString(R.string.snackBarInvalidFileNameError, Utils.getInvalidFileNameCharacter(fileName), fileName),
anchorView
)
fun Fragment.showSnackbarAboveFab(titleId: Int, showAboveFab: Boolean = true) {
showSnackbarAboveFab(getString(titleId), showAboveFab)
}

fun Fragment.showSnackbarAboveFab(title: String, showAboveFab: Boolean = true) {
activity?.let { it.showSnackbar(title, if (showAboveFab) it.mainFab else null) }
}

@SuppressLint("NewApi")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import com.infomaniak.drive.ui.fileList.SelectFolderActivity
import com.infomaniak.drive.utils.*
import com.infomaniak.drive.utils.MatomoUtils.trackEvent
import com.infomaniak.drive.utils.Utils.moveFileClicked
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.view_file_info_actions.view.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -216,7 +215,11 @@ class FileInfoActionsView @JvmOverloads constructor(
findNavController().currentBackStackEntry?.destination?.id == R.id.fileInfoActionsBottomSheetDialog
if (downloadError) {
availableOfflineSwitch.isChecked = false
showSnackBarInvalidFileName(currentFile.name, if (isBottomSheetFragmentView) activity?.mainFab else null)
val fileName = currentFile.name
showSnackbarAboveFab(
getString(R.string.snackBarInvalidFileNameError, Utils.getInvalidFileNameCharacter(fileName), fileName),
isBottomSheetFragmentView
)
}
if (isBottomSheetFragmentView) {
findNavController().popBackStack()
Expand Down

0 comments on commit 1e0cca4

Please sign in to comment.