@nativescript-community/ui-document-picker 1.1.4 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +201 -19
- package/README.md +118 -7
- package/index.android.d.ts +22 -0
- package/index.android.js +190 -0
- package/index.android.js.map +1 -0
- package/index.common.d.ts +16 -0
- package/index.common.js +2 -0
- package/index.common.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.ios.d.ts +7 -0
- package/{filepicker.ios.js → index.ios.js} +13 -5
- package/index.ios.js.map +1 -0
- package/package.json +40 -33
- package/platforms/android/AndroidManifest.xml +4 -0
- package/platforms/android/include.gradle +5 -0
- package/platforms/android/java/com/nativescript/documentpicker/FilePath.java +60 -41
- package/references.d.ts +1 -0
- package/typings/android.d.ts +1521 -0
- package/filepicker.android.d.ts +0 -9
- package/filepicker.android.js +0 -63
- package/filepicker.android.js.map +0 -1
- package/filepicker.common.d.ts +0 -5
- package/filepicker.common.js +0 -1
- package/filepicker.common.js.map +0 -1
- package/filepicker.d.ts +0 -4
- package/filepicker.ios.d.ts +0 -3
- package/filepicker.ios.js.map +0 -1
- package/platforms/android/ui_document_picker.aar +0 -0
- package/pnpm-lock.yaml +0 -10
package/index.ios.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { FolderPickerOptions } from '.';
|
2
|
+
import { FilePickerOptions } from './index.common';
|
3
|
+
export { FilePickerOptions };
|
4
|
+
export declare function openFilePicker(params: FilePickerOptions): Promise<unknown>;
|
5
|
+
export declare function pickFolder(params?: FolderPickerOptions): Promise<{
|
6
|
+
folders: any[];
|
7
|
+
}>;
|
@@ -14,11 +14,12 @@ var DocumentPickerDelegate = /** @class */ (function (_super) {
|
|
14
14
|
this._resolve = null;
|
15
15
|
this._reject = null;
|
16
16
|
controller.delegate = null;
|
17
|
+
delegate = null;
|
17
18
|
};
|
18
19
|
DocumentPickerDelegate.prototype.documentPickerDidPickDocumentAtURL = function (controller, url) {
|
19
20
|
this._resolve({
|
20
21
|
files: [url.absoluteString],
|
21
|
-
ios: url
|
22
|
+
ios: url
|
22
23
|
});
|
23
24
|
this.cleanup(controller);
|
24
25
|
};
|
@@ -29,19 +30,20 @@ var DocumentPickerDelegate = /** @class */ (function (_super) {
|
|
29
30
|
}
|
30
31
|
this._resolve({
|
31
32
|
files: output,
|
32
|
-
ios: urls
|
33
|
+
ios: urls
|
33
34
|
});
|
34
35
|
this.cleanup(controller);
|
35
36
|
};
|
36
37
|
DocumentPickerDelegate.prototype.documentPickerWasCancelled = function (controller) {
|
37
38
|
this._resolve({
|
38
|
-
files: []
|
39
|
+
files: []
|
39
40
|
});
|
40
41
|
this.cleanup(controller);
|
41
42
|
};
|
42
43
|
DocumentPickerDelegate.ObjCProtocols = [UIDocumentPickerDelegate];
|
43
44
|
return DocumentPickerDelegate;
|
44
45
|
}(NSObject));
|
46
|
+
let delegate;
|
45
47
|
export function openFilePicker(params) {
|
46
48
|
let documentTypes;
|
47
49
|
if (params.extensions && params.extensions.length > 0) {
|
@@ -49,7 +51,8 @@ export function openFilePicker(params) {
|
|
49
51
|
}
|
50
52
|
return new Promise((resolve, reject) => {
|
51
53
|
const controller = UIDocumentPickerViewController.alloc().initWithDocumentTypesInMode(documentTypes, params.pickerMode !== undefined ? params.pickerMode : 0);
|
52
|
-
|
54
|
+
delegate = DocumentPickerDelegate.initWithResolveReject(resolve, reject);
|
55
|
+
controller.delegate = delegate;
|
53
56
|
controller.allowsMultipleSelection = !!params.multipleSelection;
|
54
57
|
const app = UIApplication.sharedApplication;
|
55
58
|
const window = app.keyWindow || (app.windows.count > 0 && app.windows[0]);
|
@@ -57,4 +60,9 @@ export function openFilePicker(params) {
|
|
57
60
|
visibleVC.presentViewControllerAnimatedCompletion(controller, true, null);
|
58
61
|
});
|
59
62
|
}
|
60
|
-
|
63
|
+
export async function pickFolder(params = {}) {
|
64
|
+
return {
|
65
|
+
folders: []
|
66
|
+
};
|
67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BAAwB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAChF,SAAS,CAAC,uCAAuC,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACP,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,SAA8B,EAAE;IAC7D,OAAO;QACH,OAAO,EAAE,EAAE;KACd,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
@@ -1,35 +1,42 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"
|
33
|
-
|
34
|
-
|
2
|
+
"name": "@nativescript-community/ui-document-picker",
|
3
|
+
"version": "1.1.8",
|
4
|
+
"description": "A NativeScript plugin that allows you to select files from the device.",
|
5
|
+
"main": "index",
|
6
|
+
"typings": "index.d.ts",
|
7
|
+
"sideEffects": false,
|
8
|
+
"scripts": {
|
9
|
+
"build": "npm run tsc && npm run readme",
|
10
|
+
"readme": "../../node_modules/.bin/readme generate -c ../../tools/readme/blueprint.json",
|
11
|
+
"tsc": "../../node_modules/.bin/cpy '**/*.d.ts' '../../packages/ui-document-picker' --parents --cwd=../../src/ui-document-picker && ../../node_modules/.bin/tsc -skipLibCheck -d",
|
12
|
+
"clean": "../../node_modules/.bin/rimraf ./*.d.ts ./*.js ./*.js.map"
|
13
|
+
},
|
14
|
+
"nativescript": {
|
15
|
+
"platforms": {
|
16
|
+
"android": "6.0.0",
|
17
|
+
"ios": "6.0.0"
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"keywords": [
|
21
|
+
"NativeScript",
|
22
|
+
"JavaScript",
|
23
|
+
"Android",
|
24
|
+
"iOS",
|
25
|
+
"vue",
|
26
|
+
"vue.js"
|
27
|
+
],
|
28
|
+
"author": {
|
29
|
+
"name": "Martin Guillon",
|
30
|
+
"email": "martin@akylas.fr"
|
31
|
+
},
|
32
|
+
"bugs": {
|
33
|
+
"url": "https://github.com/nativescript-community/ui-document-picker/issues"
|
34
|
+
},
|
35
|
+
"repository": {
|
36
|
+
"type": "git",
|
37
|
+
"url": "https://github.com/nativescript-community/ui-document-picker"
|
38
|
+
},
|
39
|
+
"license": "Apache-2.0",
|
40
|
+
"readmeFilename": "README.md",
|
41
|
+
"gitHead": "30e29361ede5e1358c817782694db6af592296e3"
|
35
42
|
}
|
@@ -4,7 +4,6 @@ import android.text.TextUtils;
|
|
4
4
|
import android.Manifest;
|
5
5
|
import android.content.ContentUris;
|
6
6
|
import android.content.Context;
|
7
|
-
import android.content.pm.PackageManager;
|
8
7
|
import android.net.Uri;
|
9
8
|
import android.provider.OpenableColumns;
|
10
9
|
import android.util.Log;
|
@@ -14,10 +13,6 @@ import android.os.Environment;
|
|
14
13
|
import android.provider.DocumentsContract;
|
15
14
|
import android.provider.MediaStore;
|
16
15
|
|
17
|
-
import org.json.JSONArray;
|
18
|
-
import org.json.JSONObject;
|
19
|
-
import org.json.JSONException;
|
20
|
-
|
21
16
|
import java.io.FileOutputStream;
|
22
17
|
import java.io.InputStream;
|
23
18
|
import java.util.List;
|
@@ -39,32 +34,6 @@ public class FilePath {
|
|
39
34
|
public static final String READ = Manifest.permission.READ_EXTERNAL_STORAGE;
|
40
35
|
|
41
36
|
|
42
|
-
|
43
|
-
// public static String resolveNativePath() throws JSONException {
|
44
|
-
// /* content:///... */
|
45
|
-
// Uri pvUrl = Uri.parse(this.uriStr);
|
46
|
-
|
47
|
-
// Log.d(TAG, "URI: " + this.uriStr);
|
48
|
-
|
49
|
-
// Context appContext = this.cordova.getActivity().getApplicationContext();
|
50
|
-
// String filePath = getPath(appContext, pvUrl);
|
51
|
-
|
52
|
-
// //check result; send error/success callback
|
53
|
-
// if (filePath == GET_PATH_ERROR_ID) {
|
54
|
-
|
55
|
-
// throw new java.lang.Exception("Unable to resolve filesystem path");
|
56
|
-
// }
|
57
|
-
// else if (filePath.equals(GET_CLOUD_PATH_ERROR_ID)) {
|
58
|
-
|
59
|
-
// throw new java.lang.Exception("Files from cloud cannot be resolved to filesystem, download is required");
|
60
|
-
// }
|
61
|
-
// else {
|
62
|
-
// Log.d(TAG, "Filepath: " + filePath);
|
63
|
-
|
64
|
-
// return "file://" + filePath;
|
65
|
-
// }
|
66
|
-
// }
|
67
|
-
|
68
37
|
/**
|
69
38
|
* @param uri The Uri to check.
|
70
39
|
* @return Whether the Uri authority is ExternalStorageProvider.
|
@@ -131,6 +100,39 @@ public class FilePath {
|
|
131
100
|
if (cursor != null && cursor.moveToFirst()) {
|
132
101
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
133
102
|
return cursor.getString(column_index);
|
103
|
+
} else if (!cursor.moveToFirst()){
|
104
|
+
return getMediaStore(context, uri, null, null);
|
105
|
+
}
|
106
|
+
} finally {
|
107
|
+
if (cursor != null)
|
108
|
+
cursor.close();
|
109
|
+
}
|
110
|
+
return null;
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Get the value of the data column for this Uri. This is useful for
|
115
|
+
* MediaStore Uris, and other file-based ContentProviders.
|
116
|
+
*
|
117
|
+
* @param context The context.
|
118
|
+
* @param uri The Uri to query.
|
119
|
+
* @param selection (Optional) Filter used in the query.
|
120
|
+
* @param selectionArgs (Optional) Selection arguments used in the query.
|
121
|
+
* @return The value of the _data column, which is typically a file path.
|
122
|
+
*/
|
123
|
+
private static String getMediaStore(Context context, Uri uri, String selection,
|
124
|
+
String[] selectionArgs) {
|
125
|
+
|
126
|
+
Cursor cursor = null;
|
127
|
+
final String[] projection = {
|
128
|
+
android.provider.MediaStore.Files.FileColumns.DISPLAY_NAME
|
129
|
+
};
|
130
|
+
try {
|
131
|
+
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
132
|
+
null);
|
133
|
+
if (cursor != null && cursor.moveToFirst()) {
|
134
|
+
final int column_index = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Files.FileColumns.DISPLAY_NAME);
|
135
|
+
return cursor.getString(column_index);
|
134
136
|
}
|
135
137
|
} finally {
|
136
138
|
if (cursor != null)
|
@@ -225,6 +227,7 @@ public class FilePath {
|
|
225
227
|
|
226
228
|
Log.d(TAG, "File - " +
|
227
229
|
"Authority: " + uri.getAuthority() +
|
230
|
+
", Path: " + uri.getPath() +
|
228
231
|
", Fragment: " + uri.getFragment() +
|
229
232
|
", Port: " + uri.getPort() +
|
230
233
|
", Query: " + uri.getQuery() +
|
@@ -237,6 +240,7 @@ public class FilePath {
|
|
237
240
|
|
238
241
|
// DocumentProvider
|
239
242
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
243
|
+
|
240
244
|
// ExternalStorageProvider
|
241
245
|
if (isExternalStorageDocument(uri)) {
|
242
246
|
final String docId = DocumentsContract.getDocumentId(uri);
|
@@ -259,20 +263,23 @@ public class FilePath {
|
|
259
263
|
cursor = context.getContentResolver().query(uri, new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
|
260
264
|
if (cursor != null && cursor.moveToFirst()) {
|
261
265
|
String fileName = cursor.getString(0);
|
262
|
-
String
|
266
|
+
String folders = android.os.Environment.getExternalStoragePublicDirectory(
|
267
|
+
android.os.Environment.DIRECTORY_DOWNLOADS
|
268
|
+
).getAbsolutePath();
|
269
|
+
String path = folders + "/" + fileName;
|
263
270
|
if (!TextUtils.isEmpty(path)) {
|
264
271
|
return path;
|
265
272
|
}
|
266
273
|
}
|
267
274
|
} finally {
|
268
275
|
if (cursor != null)
|
269
|
-
|
276
|
+
cursor.close();
|
270
277
|
}
|
271
278
|
//
|
272
279
|
final String id = DocumentsContract.getDocumentId(uri);
|
273
280
|
try {
|
274
281
|
final Uri contentUri = ContentUris.withAppendedId(
|
275
|
-
|
282
|
+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
276
283
|
|
277
284
|
return getDataColumn(context, contentUri, null, null);
|
278
285
|
} catch(NumberFormatException e) {
|
@@ -282,10 +289,12 @@ public class FilePath {
|
|
282
289
|
}
|
283
290
|
// MediaProvider
|
284
291
|
else if (isMediaDocument(uri)) {
|
292
|
+
|
285
293
|
final String docId = DocumentsContract.getDocumentId(uri);
|
286
294
|
final String[] split = docId.split(":");
|
287
295
|
final String type = split[0];
|
288
296
|
|
297
|
+
Log.i(TAG, type);
|
289
298
|
Uri contentUri = null;
|
290
299
|
if ("image".equals(type)) {
|
291
300
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
@@ -293,6 +302,8 @@ public class FilePath {
|
|
293
302
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
294
303
|
} else if ("audio".equals(type)) {
|
295
304
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
305
|
+
} else {
|
306
|
+
contentUri = MediaStore.Files.getContentUri("external");
|
296
307
|
}
|
297
308
|
|
298
309
|
final String selection = "_id=?";
|
@@ -300,7 +311,11 @@ public class FilePath {
|
|
300
311
|
split[1]
|
301
312
|
};
|
302
313
|
|
303
|
-
|
314
|
+
try {
|
315
|
+
return getDataColumn(context, contentUri, selection, selectionArgs);
|
316
|
+
} catch (Exception e) {
|
317
|
+
return getMediaStore(context, contentUri, null, null);
|
318
|
+
}
|
304
319
|
}
|
305
320
|
else if(isGoogleDriveUri(uri)){
|
306
321
|
return getDriveFilePath(uri,context);
|
@@ -308,7 +323,6 @@ public class FilePath {
|
|
308
323
|
}
|
309
324
|
// MediaStore (and general)
|
310
325
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
311
|
-
|
312
326
|
// Return the remote address
|
313
327
|
if (isGooglePhotosUri(uri)) {
|
314
328
|
String contentPath = getContentFromSegments(uri.getPathSegments());
|
@@ -321,10 +335,15 @@ public class FilePath {
|
|
321
335
|
}
|
322
336
|
|
323
337
|
if(isGoogleDriveUri(uri)){
|
338
|
+
Log.i(TAG, "4");
|
324
339
|
return getDriveFilePath(uri,context);
|
325
340
|
}
|
326
341
|
|
327
|
-
|
342
|
+
try {
|
343
|
+
return getDataColumn(context, uri, null, null);
|
344
|
+
} catch (Exception ex) {
|
345
|
+
return getMediaStore(context, uri, null, null);
|
346
|
+
}
|
328
347
|
}
|
329
348
|
// File
|
330
349
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
@@ -338,10 +357,10 @@ public class FilePath {
|
|
338
357
|
Uri returnUri =uri;
|
339
358
|
Cursor returnCursor = context.getContentResolver().query(returnUri, null, null, null, null);
|
340
359
|
/*
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
360
|
+
* Get the column indexes of the data in the Cursor,
|
361
|
+
* * move to the first row in the Cursor, get the data,
|
362
|
+
* * and display it.
|
363
|
+
* */
|
345
364
|
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
346
365
|
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
|
347
366
|
returnCursor.moveToFirst();
|
package/references.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/// <reference path="./typings/android.d.ts" />
|