Skip to content

Commit

Permalink
[TIMOB-25619] Allow preview of non-file TiBlob
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed Feb 28, 2018
1 parent e8115d7 commit d7a4c76
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ public void previewImage(KrollDict options)
if (options.containsKey(TiC.EVENT_ERROR)) {
errorCallback = (KrollFunction) options.get(TiC.EVENT_ERROR);
}
if (options.containsKey("image")) {
image = (TiBlob) options.get("image");
if (options.containsKey(TiC.PROPERTY_IMAGE)) {
image = (TiBlob) options.get(TiC.PROPERTY_IMAGE);
}

if (image == null) {
Expand All @@ -1224,8 +1224,6 @@ public void previewImage(KrollDict options)
}
}

TiBaseFile f = (TiBaseFile) image.getData();

final KrollFunction fSuccessCallback = successCallback;
final KrollFunction fErrorCallback = errorCallback;

Expand All @@ -1237,7 +1235,14 @@ public void previewImage(KrollDict options)
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
TiIntentWrapper previewIntent = new TiIntentWrapper(intent);
String mimeType = image.getMimeType();
Uri imageUri = TiFileProvider.createUriFrom(f.getNativeFile());
Uri imageUri = null;

if (image.getNativePath() == null) {
imageUri = TiFileProvider.createUriFrom(
TiFileHelper.getInstance().getTempFileFromInputStream(image.getInputStream(), null, true));
} else {
imageUri = TiFileProvider.createUriFrom(image.getFile().getBaseFile().getNativeFile());
}

if (mimeType != null && mimeType.length() > 0) {
intent.setDataAndType(imageUri, mimeType);
Expand Down

0 comments on commit d7a4c76

Please sign in to comment.