mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-15 18:12:54 +00:00
[fenix] For issue https://github.com/mozilla-mobile/fenix/issues/10428 Improve download dialog error message.
This commit is contained in:
parent
46e1424b11
commit
25b2805f87
@ -474,13 +474,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
didFail = downloadJobStatus == DownloadState.Status.FAILED,
|
||||
tryAgain = downloadFeature::tryAgain,
|
||||
onCannotOpenFile = {
|
||||
FenixSnackbar.make(
|
||||
view = view.browserLayout,
|
||||
duration = Snackbar.LENGTH_SHORT,
|
||||
isDisplayedWithBrowserToolbar = true
|
||||
)
|
||||
.setText(context.getString(R.string.mozac_feature_downloads_could_not_open_file))
|
||||
.show()
|
||||
showCannotOpenFileError(view.browserLayout, context, it)
|
||||
},
|
||||
view = view.viewDynamicDownloadDialog,
|
||||
toolbarHeight = toolbarHeight,
|
||||
@ -783,16 +777,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
}
|
||||
}
|
||||
|
||||
val onCannotOpenFile = {
|
||||
FenixSnackbar.make(
|
||||
view = view.browserLayout,
|
||||
duration = Snackbar.LENGTH_SHORT,
|
||||
isDisplayedWithBrowserToolbar = true
|
||||
)
|
||||
.setText(context.getString(R.string.mozac_feature_downloads_could_not_open_file))
|
||||
.show()
|
||||
}
|
||||
|
||||
val onDismiss: () -> Unit =
|
||||
{ sharedViewModel.downloadDialogState.remove(sessionId) }
|
||||
|
||||
@ -802,7 +786,9 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
metrics = requireComponents.analytics.metrics,
|
||||
didFail = savedDownloadState.second,
|
||||
tryAgain = onTryAgain,
|
||||
onCannotOpenFile = onCannotOpenFile,
|
||||
onCannotOpenFile = {
|
||||
showCannotOpenFileError(view.browserLayout, context, it)
|
||||
},
|
||||
view = view.viewDynamicDownloadDialog,
|
||||
toolbarHeight = toolbarHeight,
|
||||
onDismiss = onDismiss
|
||||
@ -1280,6 +1266,19 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
||||
)
|
||||
}
|
||||
|
||||
private fun showCannotOpenFileError(
|
||||
view: View,
|
||||
context: Context,
|
||||
downloadState: DownloadState
|
||||
) {
|
||||
FenixSnackbar.make(
|
||||
view = view,
|
||||
duration = Snackbar.LENGTH_SHORT,
|
||||
isDisplayedWithBrowserToolbar = true
|
||||
).setText(DynamicDownloadDialog.getCannotOpenFileErrorMessage(context, downloadState))
|
||||
.show()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_CUSTOM_TAB_SESSION_ID = "custom_tab_session_id"
|
||||
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
||||
|
@ -4,8 +4,10 @@
|
||||
|
||||
package org.mozilla.fenix.downloads
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.webkit.MimeTypeMap
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
import kotlinx.android.extensions.LayoutContainer
|
||||
import kotlinx.android.synthetic.main.download_dialog_layout.view.*
|
||||
@ -30,7 +32,7 @@ class DynamicDownloadDialog(
|
||||
private val metrics: MetricController,
|
||||
private val didFail: Boolean,
|
||||
private val tryAgain: (String) -> Unit,
|
||||
private val onCannotOpenFile: () -> Unit,
|
||||
private val onCannotOpenFile: (DownloadState) -> Unit,
|
||||
private val view: View,
|
||||
private val toolbarHeight: Int,
|
||||
private val onDismiss: () -> Unit
|
||||
@ -110,7 +112,7 @@ class DynamicDownloadDialog(
|
||||
)
|
||||
|
||||
if (!fileWasOpened) {
|
||||
onCannotOpenFile()
|
||||
onCannotOpenFile(downloadState)
|
||||
}
|
||||
|
||||
context.metrics.track(Event.InAppNotificationDownloadOpen)
|
||||
@ -138,4 +140,15 @@ class DynamicDownloadDialog(
|
||||
view.visibility = View.GONE
|
||||
onDismiss()
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun getCannotOpenFileErrorMessage(context: Context, download: DownloadState): String {
|
||||
val fileExt = MimeTypeMap.getFileExtensionFromUrl(
|
||||
download.filePath
|
||||
)
|
||||
return context.getString(
|
||||
R.string.mozac_feature_downloads_open_not_supported1, fileExt
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.downloads
|
||||
|
||||
import android.webkit.MimeTypeMap
|
||||
import mozilla.components.browser.state.state.content.DownloadState
|
||||
import mozilla.components.support.test.robolectric.testContext
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.downloads.DynamicDownloadDialog.Companion.getCannotOpenFileErrorMessage
|
||||
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
|
||||
import org.robolectric.Shadows.shadowOf
|
||||
|
||||
@RunWith(FenixRobolectricTestRunner::class)
|
||||
class DynamicDownloadDialogTest {
|
||||
|
||||
@Test
|
||||
fun `WHEN calling getCannotOpenFileErrorMessage THEN should return the error message for the download file type`() {
|
||||
val download = DownloadState(url = "", fileName = "image.gif")
|
||||
|
||||
shadowOf(MimeTypeMap.getSingleton()).apply {
|
||||
addExtensionMimeTypMapping(".gif", "image/gif")
|
||||
}
|
||||
|
||||
val expected = testContext.getString(
|
||||
R.string.mozac_feature_downloads_open_not_supported1, "gif"
|
||||
)
|
||||
|
||||
val result = getCannotOpenFileErrorMessage(testContext, download)
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user