From 5f336076d9d22978e183b1346c7943494caefd00 Mon Sep 17 00:00:00 2001 From: iorgamgabriel Date: Wed, 4 Oct 2023 12:50:15 +0300 Subject: [PATCH] Bug 1854385 - When accessing files from downloads that cannot be opened, a snack bar with an error message should appear. --- .../library/downloads/DownloadFragment.kt | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt index c924b13250..2fcac34ab1 100644 --- a/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/library/downloads/DownloadFragment.kt @@ -16,6 +16,7 @@ import android.view.ViewGroup import androidx.annotation.VisibleForTesting import androidx.core.view.MenuProvider import androidx.lifecycle.Lifecycle +import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.MainScope @@ -28,8 +29,10 @@ import mozilla.components.support.base.feature.UserInteractionHandler import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.R import org.mozilla.fenix.browser.browsingmode.BrowsingMode +import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.databinding.FragmentDownloadsBinding +import org.mozilla.fenix.downloads.DynamicDownloadDialog import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.filterNotExistsOnDisk import org.mozilla.fenix.ext.getRootView @@ -216,17 +219,33 @@ class DownloadFragment : LibraryPageFragment(), UserInteractionHan } else { 0L } - AbstractFetchDownloadService.openFile( + val downloadState = DownloadState( + id = item.id, + url = item.url, + fileName = item.fileName, + contentType = item.contentType, + status = item.status, + contentLength = contentLength, + ) + + val canOpenFile = AbstractFetchDownloadService.openFile( applicationContext = it.applicationContext, - download = DownloadState( - id = item.id, - url = item.url, - fileName = item.fileName, - contentType = item.contentType, - status = item.status, - contentLength = contentLength, - ), + download = downloadState, ) + + if (!canOpenFile) { + FenixSnackbar.make( + view = binding.root, + duration = Snackbar.LENGTH_SHORT, + isDisplayedWithBrowserToolbar = true, + ).setText( + DynamicDownloadDialog.getCannotOpenFileErrorMessage( + it, + downloadState, + ), + ) + .show() + } } }