@@ -56,20 +56,18 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
56
56
try {
57
57
val args = invoke.parseArgs(FilePickerOptions ::class .java)
58
58
val parsedTypes = parseFiltersOption(args.filters)
59
-
60
- val intent = if (parsedTypes.isNotEmpty()) {
61
- val intent = Intent (Intent .ACTION_PICK )
62
- setIntentMimeTypes(intent, parsedTypes)
63
- intent
64
- } else {
65
- val intent = Intent (Intent .ACTION_GET_CONTENT )
66
- intent.addCategory(Intent .CATEGORY_OPENABLE )
67
- intent.type = " */*"
68
- intent
59
+
60
+ // TODO: ACTION_OPEN_DOCUMENT ??
61
+ val intent = Intent (Intent .ACTION_GET_CONTENT )
62
+ intent.addCategory(Intent .CATEGORY_OPENABLE )
63
+ intent.type = " */*"
64
+
65
+ if (parsedTypes.isNotEmpty()) {
66
+ intent.putExtra(Intent .EXTRA_MIME_TYPES , parsedTypes)
69
67
}
70
68
71
69
intent.putExtra(Intent .EXTRA_ALLOW_MULTIPLE , args.multiple ? : false )
72
-
70
+
73
71
startActivityForResult(invoke, intent, " filePickerResult" )
74
72
} catch (ex: Exception ) {
75
73
val message = ex.message ? : " Failed to pick file"
@@ -115,7 +113,7 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
115
113
callResult.put(" files" , JSArray .from(uris.toTypedArray()))
116
114
return callResult
117
115
}
118
-
116
+
119
117
private fun parseFiltersOption (filters : Array <Filter >): Array <String > {
120
118
val mimeTypes = mutableListOf<String >()
121
119
for (filter in filters) {
@@ -132,38 +130,10 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
132
130
return mimeTypes.toTypedArray()
133
131
}
134
132
135
- private fun setIntentMimeTypes (intent : Intent , mimeTypes : Array <String >) {
136
- if (mimeTypes.isNotEmpty()) {
137
- var uniqueMimeKind = true
138
- var mimeKind: String? = null
139
- for (mime in mimeTypes) {
140
- val kind = mime.split(" /" )[0 ]
141
- if (mimeKind == null ) {
142
- mimeKind = kind
143
- } else if (mimeKind != kind) {
144
- uniqueMimeKind = false
145
- }
146
- }
147
-
148
- if (uniqueMimeKind) {
149
- if (mimeTypes.size > 1 ) {
150
- intent.putExtra(Intent .EXTRA_MIME_TYPES , mimeTypes)
151
- intent.type = Intent .normalizeMimeType(" $mimeKind /*" )
152
- } else {
153
- intent.type = mimeTypes[0 ]
154
- }
155
- } else {
156
- intent.type = " */*"
157
- }
158
- } else {
159
- intent.type = " */*"
160
- }
161
- }
162
-
163
133
@Command
164
134
fun showMessageDialog (invoke : Invoke ) {
165
135
val args = invoke.parseArgs(MessageOptions ::class .java)
166
-
136
+
167
137
if (activity.isFinishing) {
168
138
invoke.reject(" App is finishing" )
169
139
return
@@ -179,7 +149,7 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
179
149
Handler (Looper .getMainLooper())
180
150
.post {
181
151
val builder = AlertDialog .Builder (activity)
182
-
152
+
183
153
if (args.title != null ) {
184
154
builder.setTitle(args.title)
185
155
}
@@ -213,10 +183,14 @@ class DialogPlugin(private val activity: Activity): Plugin(activity) {
213
183
val parsedTypes = parseFiltersOption(args.filters)
214
184
215
185
val intent = Intent (Intent .ACTION_CREATE_DOCUMENT )
216
- setIntentMimeTypes(intent, parsedTypes)
217
-
218
186
intent.addCategory(Intent .CATEGORY_OPENABLE )
219
187
intent.putExtra(Intent .EXTRA_TITLE , args.fileName ? : " " )
188
+ intent.type = " */*"
189
+
190
+ if (parsedTypes.isNotEmpty()) {
191
+ intent.putExtra(Intent .EXTRA_MIME_TYPES , parsedTypes)
192
+ }
193
+
220
194
startActivityForResult(invoke, intent, " saveFileDialogResult" )
221
195
} catch (ex: Exception ) {
222
196
val message = ex.message ? : " Failed to pick save file"
0 commit comments