From 28af3fa0ce280b3eecc0d5a61feabf60be334ed7 Mon Sep 17 00:00:00 2001 From: Sawyer Blatz Date: Fri, 15 Nov 2019 16:28:24 -0800 Subject: [PATCH] For #6436: Adds snackbar for failed download --- .../org/mozilla/fenix/browser/BaseBrowserFragment.kt | 11 +++++++++-- .../DownloadNotificationBottomSheetDialog.kt | 11 ++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) 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 639b6658a239..16befed0d853 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -23,7 +23,7 @@ import androidx.lifecycle.lifecycleScope import androidx.navigation.NavDirections import androidx.navigation.fragment.findNavController import com.google.android.material.snackbar.Snackbar -import kotlinx.android.synthetic.main.component_search.toolbar +import kotlinx.android.synthetic.main.component_search.* import kotlinx.android.synthetic.main.fragment_browser.* import kotlinx.android.synthetic.main.fragment_browser.view.* import kotlinx.coroutines.Dispatchers.IO @@ -268,7 +268,14 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs context = context, didFail = downloadJobStatus == AbstractFetchDownloadService.DownloadJobStatus.FAILED, download = download, - tryAgain = downloadFeature::tryAgain + tryAgain = downloadFeature::tryAgain, + onCannotOpenFile = { + FenixSnackbar.make(view, Snackbar.LENGTH_SHORT) + .setText(context.getString(R.string.mozac_feature_downloads_could_not_open_file)) + .setAnchorView(browserToolbarView.view) + .show() + } + ) dialog.show() } diff --git a/app/src/main/java/org/mozilla/fenix/downloads/DownloadNotificationBottomSheetDialog.kt b/app/src/main/java/org/mozilla/fenix/downloads/DownloadNotificationBottomSheetDialog.kt index fd98adae33ac..77e9af5ddbfb 100644 --- a/app/src/main/java/org/mozilla/fenix/downloads/DownloadNotificationBottomSheetDialog.kt +++ b/app/src/main/java/org/mozilla/fenix/downloads/DownloadNotificationBottomSheetDialog.kt @@ -24,7 +24,8 @@ class DownloadNotificationBottomSheetDialog( context: Context, private val download: DownloadState, private val didFail: Boolean, - private val tryAgain: (Long) -> Unit + private val tryAgain: (Long) -> Unit, + private val onCannotOpenFile: () -> Unit // We must pass in the BottomSheetDialog theme for the transparent window background to apply properly ) : BottomSheetDialog(context, R.style.Theme_MaterialComponents_BottomSheetDialog) { override fun onCreate(savedInstanceState: Bundle?) { @@ -64,11 +65,16 @@ class DownloadNotificationBottomSheetDialog( mozilla.components.feature.downloads.R.string.mozac_feature_downloads_button_open ) setOnClickListener { - AbstractFetchDownloadService.openFile( + val fileWasOpened = AbstractFetchDownloadService.openFile( context = context, contentType = download.contentType, filePath = download.filePath ) + + if (!fileWasOpened) { + onCannotOpenFile() + } + context.metrics.track(Event.InAppNotificationDownloadOpen) dismiss() } @@ -83,7 +89,6 @@ class DownloadNotificationBottomSheetDialog( setOnShowListener { window?.apply { - // setBackgroundDrawableResource(android.R.color.transparent) setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) setLayout( ViewGroup.LayoutParams.MATCH_PARENT,