diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 3fb7bcd0a..a5f7afab9 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -51,8 +51,8 @@ import mozilla.components.feature.session.SwipeRefreshFeature import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissionsFeature import mozilla.components.feature.sitepermissions.SitePermissionsRules -import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.PermissionsFeature +import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.ktx.android.view.exitImmersiveModeIfNeeded import org.mozilla.fenix.Experiments @@ -254,8 +254,14 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session promptsStyling = DownloadsFeature.PromptsStyling( gravity = Gravity.BOTTOM, shouldWidthMatchParent = true, - positiveButtonBackgroundColor = ThemeManager.resolveAttribute(R.attr.accent, context), - positiveButtonTextColor = ThemeManager.resolveAttribute(R.attr.contrastText, context), + positiveButtonBackgroundColor = ThemeManager.resolveAttribute( + R.attr.accent, + context + ), + positiveButtonTextColor = ThemeManager.resolveAttribute( + R.attr.contrastText, + context + ), positiveButtonRadius = (resources.getDimensionPixelSize(R.dimen.tab_corner_radius)).toFloat() ), onNeedToRequestPermissions = { permissions -> @@ -266,7 +272,8 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session downloadFeature.onDownloadStopped = { download, _, downloadJobStatus -> // If the download is just paused, don't show any in-app notification if (downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.COMPLETED || - downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED) { + downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED + ) { val dialog = DownloadNotificationBottomSheetDialog( context = context, didFail = downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED, @@ -275,7 +282,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session onCannotOpenFile = { FenixSnackbar.make(view, Snackbar.LENGTH_SHORT) .setText(context.getString(R.string.mozac_feature_downloads_could_not_open_file)) - .setAnchorView(browserToolbarView.view) + .setAnchorView(browserToolbarView.getSnackbarAnchor()) .show() } @@ -670,7 +677,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session view?.let { view -> FenixSnackbar.make(view, Snackbar.LENGTH_LONG) - .setAnchorView(browserToolbarView.view) + .setAnchorView(browserToolbarView.getSnackbarAnchor()) .setAction(getString(R.string.edit_bookmark_snackbar_action)) { nav( R.id.browserFragment, diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index 3f272882f..a318ad464 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -256,7 +256,7 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler { view?.let { view -> FenixSnackbar.make(view, Snackbar.LENGTH_SHORT) .setText(view.context.getString(R.string.create_collection_tab_saved)) - .setAnchorView(browserToolbarView.view) + .setAnchorView(browserToolbarView.getSnackbarAnchor()) .show() } } diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt index 05f3eaafe..36a2b72be 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarView.kt @@ -214,6 +214,14 @@ class BrowserToolbarView( } } + /** + * Returns the correct snackbar anchor for bottom or top toolbar configuration. + * A null anchor view is ignored. + * + * @see #setAnchorView(com.google.android.material.snackbar.BaseTransientBottomBar) + */ + fun getSnackbarAnchor(): View? = if (shouldUseBottomToolbar) view else null + @Suppress("UNUSED_PARAMETER") fun update(state: BrowserFragmentState) { // Intentionally leaving this as a stub for now since we don't actually want to update currently