Skip to content

Commit 4841c04

Browse files
committed
refactor(android): add mimeTypes property to ImagePicker class
This would allow customization of picker behaviour in subclasses.
1 parent c93c574 commit 4841c04

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/imagepicker.android.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,20 @@ export class ImagePicker {
157157
}
158158
}
159159

160+
get mimeTypes() {
161+
let length = this.mediaType === "*/*" ? 2 : 1;
162+
let mimeTypes = Array.create(java.lang.String, length);
163+
164+
if (this.mediaType === "*/*") {
165+
mimeTypes[0] = "image/*";
166+
mimeTypes[1] = "video/*";
167+
}
168+
else {
169+
mimeTypes[0] = this.mediaType;
170+
}
171+
return mimeTypes;
172+
}
173+
160174
authorize(): Promise<void> {
161175
if ((<any>android).os.Build.VERSION.SDK_INT >= 23) {
162176
return permissions.requestPermission([(<any>android).Manifest.permission.READ_EXTERNAL_STORAGE]);
@@ -227,19 +241,9 @@ export class ImagePicker {
227241
let intent = new Intent();
228242
intent.setType(this.mediaType);
229243

230-
let length = this.mediaType === "*/*" ? 2 : 1;
231-
let mimeTypes = Array.create(java.lang.String, length);
232-
233-
if (this.mediaType === "*/*") {
234-
mimeTypes[0] = "image/*";
235-
mimeTypes[1] = "video/*";
236-
}
237-
else {
238-
mimeTypes[0] = this.mediaType;
239-
}
240-
241244
// not in platform-declaration typings
242-
intent.putExtra((android.content.Intent as any).EXTRA_MIME_TYPES, mimeTypes);
245+
intent.putExtra((android.content.Intent as any).EXTRA_MIME_TYPES, this.mimeTypes);
246+
243247
// TODO: Use (<any>android).content.Intent.EXTRA_ALLOW_MULTIPLE
244248
if (this.mode === 'multiple') {
245249
intent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);

src/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { ImageAsset } from "tns-core-modules/image-asset";
44
import { View } from "tns-core-modules/ui/core/view/view";
55

66
export class ImagePicker {
7+
8+
constructor(options?: Options);
9+
710
/**
811
* Call this before 'present' to request any additional permissions that may be necessary.
912
* In case of failed authorization consider notifying the user for degraded functionality.

0 commit comments

Comments
 (0)