diff --git a/packages/flutter_mozilla_components/android/build.gradle b/packages/flutter_mozilla_components/android/build.gradle index 6eaf72f5..1fc1cf79 100644 --- a/packages/flutter_mozilla_components/android/build.gradle +++ b/packages/flutter_mozilla_components/android/build.gradle @@ -3,7 +3,7 @@ version = "1.0-SNAPSHOT" buildscript { ext.kotlin_version = "2.3.10" - ext.mozillaComponentsVersion = '149.0' + ext.mozillaComponentsVersion = '150.0' repositories { google() diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt index 0116a2a1..f7a6e914 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/BaseBrowserFragment.kt @@ -12,6 +12,7 @@ import android.content.Intent import android.content.pm.PackageManager import android.os.Build import android.os.Bundle +import android.os.Environment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -64,6 +65,7 @@ import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.ktx.android.view.enterImmersiveMode import mozilla.components.support.ktx.android.view.exitImmersiveMode import mozilla.components.support.locale.ActivityContextWrapper +import mozilla.components.support.utils.DefaultDownloadFileUtils import mozilla.components.support.webextensions.WebExtensionPopupObserver /** @@ -299,6 +301,12 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit onDownloadStopped = { download, id, status -> Logger.debug("Download done. ID#$id $download with status $status") }, + downloadFileUtils = DefaultDownloadFileUtils( + context = components.profileApplicationContext, + downloadLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, + ), downloadManager = FetchDownloadManager( components.profileApplicationContext, components.core.store, diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/ExternalAppBrowserFragment.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/ExternalAppBrowserFragment.kt index 7f9bc368..7001f680 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/ExternalAppBrowserFragment.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/ExternalAppBrowserFragment.kt @@ -8,6 +8,7 @@ package eu.weblibre.flutter_mozilla_components import android.content.Intent import android.os.Bundle +import android.os.Environment import android.view.Gravity import android.view.LayoutInflater import android.view.View @@ -15,6 +16,7 @@ import android.widget.ImageButton import android.widget.ImageView import android.widget.PopupWindow import androidx.annotation.CallSuper +import androidx.lifecycle.lifecycleScope import com.google.android.material.appbar.AppBarLayout import com.google.android.material.color.MaterialColors import com.google.android.material.materialswitch.MaterialSwitch @@ -88,10 +90,16 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler ContextMenuCandidate.createSaveImageCandidate( requireContext(), components.useCases.contextMenuUseCases, + downloadsLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, ), ContextMenuCandidate.createSaveVideoAudioCandidate( requireContext(), components.useCases.contextMenuUseCases, + downloadsLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, ), ContextMenuCandidate.createCopyImageLocationCandidate(requireContext(), view), ) @@ -330,6 +338,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler customTabsStore = components.core.customTabsStore, tabId = sessionId, manifest = manifest, + scope = viewLifecycleOwner.lifecycleScope, ) { toolbarVisible -> Logger.debug("Custom tab toolbar visibility: $toolbarVisible") }, diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/AddonPopupBaseFragment.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/AddonPopupBaseFragment.kt index 252948db..34cf1164 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/AddonPopupBaseFragment.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/AddonPopupBaseFragment.kt @@ -26,6 +26,7 @@ import mozilla.components.feature.downloads.manager.FetchDownloadManager import mozilla.components.feature.prompts.PromptFeature import mozilla.components.support.base.feature.UserInteractionHandler import mozilla.components.support.base.feature.ViewBoundFeatureWrapper +import mozilla.components.support.utils.DefaultDownloadFileUtils /** * Provides shared functionality to fragments for add-on popups and settings. @@ -71,6 +72,12 @@ abstract class AddonPopupBaseFragment : Fragment(), EngineSession.Observer, User useCases = components.useCases.downloadsUseCases, fragmentManager = childFragmentManager, tabId = it.id, + downloadFileUtils = DefaultDownloadFileUtils( + context = components.profileApplicationContext, + downloadLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, + ), downloadManager = FetchDownloadManager( requireContext().applicationContext, components.core.store, diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/WebExtensionPromptFeature.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/WebExtensionPromptFeature.kt index c25146c8..4c0ea049 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/WebExtensionPromptFeature.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/addons/WebExtensionPromptFeature.kt @@ -322,7 +322,7 @@ class WebExtensionPromptFeature( } is WebExtensionInstallException.SoftBlocked -> { - context.getString(MozComp.string.mozac_feature_addons_soft_blocked_1, addonName) + context.getString(MozComp.string.mozac_feature_addons_soft_blocked_2, addonName) } is WebExtensionInstallException.UserCancelled -> { diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/api/GeckoDownloadsApiImpl.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/api/GeckoDownloadsApiImpl.kt index 83dbcc71..17d6eeda 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/api/GeckoDownloadsApiImpl.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/api/GeckoDownloadsApiImpl.kt @@ -58,7 +58,6 @@ class GeckoDownloadsApiImpl : GeckoDownloadsApi { currentBytesCopied = currentBytesCopied ?: 0L, status = status?.toMozillaStatus() ?: mozilla.components.browser.state.state.content.DownloadState.Status.INITIATED, userAgent = userAgent, - destinationDirectory = destinationDirectory ?: Environment.DIRECTORY_DOWNLOADS, directoryPath = directoryPath ?: Environment.getExternalStoragePublicDirectory( destinationDirectory ?: Environment.DIRECTORY_DOWNLOADS ).path, diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt index 18295d41..cae23553 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/Core.kt @@ -8,6 +8,7 @@ package eu.weblibre.flutter_mozilla_components.components import android.content.Context import android.content.SharedPreferences +import android.os.Environment import androidx.core.content.ContextCompat import androidx.preference.PreferenceManager import eu.weblibre.flutter_mozilla_components.Components @@ -72,6 +73,7 @@ import mozilla.components.support.base.worker.Frequency import org.mozilla.geckoview.GeckoRuntime import kotlinx.coroutines.MainScope import kotlinx.coroutines.Job +import mozilla.components.support.utils.DefaultDownloadFileUtils import java.util.concurrent.TimeUnit private const val AMO_COLLECTION_MAX_CACHE_AGE = 24 * 60L @@ -205,7 +207,17 @@ class Core( middleware = listOf( HistoryMetadataMiddleware(historyMetadataService), FlutterEventMiddleware(flutterEvents), - DownloadMiddleware(context, DownloadService::class.java, { false }), + DownloadMiddleware( + applicationContext = context, + downloadServiceClass = DownloadService::class.java, + deleteFileFromStorage = { false }, + downloadFileUtils = DefaultDownloadFileUtils( + context = context, + downloadLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, + ), + ), ThumbnailsMiddleware(thumbnailStorage), ReaderViewMiddleware(), UndoMiddleware(), diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/UseCases.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/UseCases.kt index cdca9f1d..bdf39f99 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/UseCases.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/components/UseCases.kt @@ -5,6 +5,7 @@ package eu.weblibre.flutter_mozilla_components.components import android.content.Context +import android.os.Environment import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.Engine import mozilla.components.feature.app.links.AppLinksUseCases @@ -17,6 +18,7 @@ import mozilla.components.feature.pwa.WebAppShortcutManager import mozilla.components.feature.pwa.WebAppUseCases import mozilla.components.feature.tabs.CustomTabsUseCases import mozilla.components.feature.tabs.TabsUseCases +import mozilla.components.support.utils.DefaultDownloadFileUtils /** * Component group for all use cases. Use cases are provided by feature @@ -46,7 +48,17 @@ class UseCases( /** * Use cases related to the downloads feature. */ - val downloadsUseCases: DownloadsUseCases by lazy { DownloadsUseCases(store, context) } + val downloadsUseCases: DownloadsUseCases by lazy { + DownloadsUseCases( + store = store, + downloadFileUtils = DefaultDownloadFileUtils( + context = context, + downloadLocation = { + Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).path + }, + ), + ) + } /** * Use cases related to the context menu feature. diff --git a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/services/DownloadService.kt b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/services/DownloadService.kt index 42f2178d..27e12a58 100644 --- a/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/services/DownloadService.kt +++ b/packages/flutter_mozilla_components/android/src/main/kotlin/eu/weblibre/flutter_mozilla_components/services/DownloadService.kt @@ -14,6 +14,8 @@ import mozilla.components.feature.downloads.DefaultPackageNameProvider import mozilla.components.feature.downloads.DownloadEstimator import mozilla.components.feature.downloads.FileSizeFormatter import mozilla.components.feature.downloads.PackageNameProvider +import mozilla.components.feature.downloads.filewriter.DefaultDownloadFileWriter +import mozilla.components.feature.downloads.filewriter.DownloadFileWriter import mozilla.components.support.base.android.NotificationsDelegate import mozilla.components.support.utils.DefaultDownloadFileUtils import mozilla.components.support.utils.DownloadFileUtils @@ -41,4 +43,10 @@ class DownloadService : AbstractFetchDownloadService() { }, ) } + override val downloadFileWriter: DownloadFileWriter by lazy { + DefaultDownloadFileWriter( + context = applicationContext, + downloadFileUtils = downloadFileUtils, + ) + } } \ No newline at end of file