Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #6436: Adds snackbar for failed download (#6648)
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored Nov 22, 2019
1 parent 5cc1ea9 commit bcf80d0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {
Expand Down Expand Up @@ -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()
}
Expand All @@ -83,7 +89,6 @@ class DownloadNotificationBottomSheetDialog(

setOnShowListener {
window?.apply {
// setBackgroundDrawableResource(android.R.color.transparent)
setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
setLayout(
ViewGroup.LayoutParams.MATCH_PARENT,
Expand Down

0 comments on commit bcf80d0

Please sign in to comment.