| ... |
... |
@@ -28,10 +28,11 @@ import mozilla.components.support.utils.DownloadUtils.findFileInMediaStore |
|
28
|
28
|
import mozilla.components.support.utils.DownloadUtils.isDefaultDownloadDirectory
|
|
29
|
29
|
import mozilla.components.support.utils.DownloadUtils.sanitizeMimeType
|
|
30
|
30
|
import mozilla.components.support.utils.DownloadUtils.truncateFileName
|
|
31
|
|
-import mozilla.components.support.utils.TorUtils
|
|
32
|
31
|
import java.io.File
|
|
33
|
32
|
import java.io.FileNotFoundException
|
|
34
|
33
|
|
|
|
34
|
+import android.content.pm.PackageManager
|
|
|
35
|
+
|
|
35
|
36
|
/**
|
|
36
|
37
|
* The default implementation of [DownloadFileUtils].
|
|
37
|
38
|
*
|
| ... |
... |
@@ -62,6 +63,8 @@ class DefaultDownloadFileUtils( |
|
62
|
63
|
private const val SCHEME_CONTENT = "content://"
|
|
63
|
64
|
private const val SCHEME_FILE = "file"
|
|
64
|
65
|
private const val FILE_PROVIDER_EXTENSION = ".feature.downloads.fileprovider"
|
|
|
66
|
+
|
|
|
67
|
+ const val EXTRA_IS_PDF = "mozilla.components.feature.downloads.extras.IS_PDF"
|
|
65
|
68
|
}
|
|
66
|
69
|
override val currentDownloadLocation: String
|
|
67
|
70
|
get() = downloadLocation()
|
| ... |
... |
@@ -103,7 +106,15 @@ class DefaultDownloadFileUtils( |
|
103
|
106
|
)
|
|
104
|
107
|
|
|
105
|
108
|
return try {
|
|
106
|
|
- TorUtils.startActivityPrompt(context, newIntent)
|
|
|
109
|
+ if (newIntent.getBooleanExtra(
|
|
|
110
|
+ EXTRA_IS_PDF,
|
|
|
111
|
+ false,
|
|
|
112
|
+ ) || newIntent.type == INTENT_TYPE_PDF
|
|
|
113
|
+ ) {
|
|
|
114
|
+ context.startActivity(newIntent)
|
|
|
115
|
+ } else {
|
|
|
116
|
+ TorUtils.startActivityPrompt(context, newIntent)
|
|
|
117
|
+ }
|
|
107
|
118
|
true
|
|
108
|
119
|
} catch (_: ActivityNotFoundException) {
|
|
109
|
120
|
false
|
| ... |
... |
@@ -118,13 +129,23 @@ class DefaultDownloadFileUtils( |
|
118
|
129
|
val shareableUri = findShareableDownloadFileUri(fileName, directoryPath)
|
|
119
|
130
|
|
|
120
|
131
|
return if (shareableUri != null) {
|
|
121
|
|
- Intent(Intent.ACTION_VIEW).apply {
|
|
|
132
|
+ val newIntent = Intent(Intent.ACTION_VIEW).apply {
|
|
122
|
133
|
setDataAndType(
|
|
123
|
134
|
shareableUri,
|
|
124
|
135
|
getSafeContentType(fileName, downloadContentType, shareableUri),
|
|
125
|
136
|
)
|
|
126
|
137
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
|
|
127
|
138
|
}
|
|
|
139
|
+
|
|
|
140
|
+ val isPdf: Boolean = (downloadContentType == "application/pdf" ||
|
|
|
141
|
+ fileName?.let { File(it).extension } == "pdf")
|
|
|
142
|
+
|
|
|
143
|
+ if (isPdf) {
|
|
|
144
|
+ newIntent.setPackage(context.packageName) // Set it to open in TBA
|
|
|
145
|
+ newIntent.putExtra(EXTRA_IS_PDF, true)
|
|
|
146
|
+ }
|
|
|
147
|
+
|
|
|
148
|
+ newIntent
|
|
128
|
149
|
} else {
|
|
129
|
150
|
// Fallback to opening the downloads manager if the file URI could not be determined.
|
|
130
|
151
|
Intent(DownloadManager.ACTION_VIEW_DOWNLOADS).apply {
|