Skip to content

Commit

Permalink
Retrieve correct content uri for videos
Browse files Browse the repository at this point in the history
Reviewed By: furdei

Differential Revision: D5547060

fbshipit-source-id: 6d3a6273ffbaa179081254e46204211b31faacf2
  • Loading branch information
Nivetha Singara Vadivelu authored and facebook-github-bot committed Aug 3, 2017
1 parent ccb0899 commit 1748922
Showing 1 changed file with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@

package com.facebook.react.modules.camera;

import javax.annotation.Nullable;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;

import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
Expand All @@ -33,16 +23,15 @@
import android.provider.MediaStore.Images;
import android.provider.MediaStore.Video;
import android.text.TextUtils;

import com.facebook.common.logging.FLog;
import com.facebook.react.bridge.GuardedAsyncTask;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableArray;
Expand All @@ -51,6 +40,14 @@
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.module.annotations.ReactModule;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;

// TODO #6015104: rename to something less iOSish
/**
Expand Down Expand Up @@ -314,7 +311,7 @@ protected void doInBackgroundGuarded(Void... params) {
mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get photos");
} else {
try {
putEdges(resolver, photos, response, mFirst);
putEdges(resolver, photos, response, mFirst, mAssetType);
putPageInfo(photos, response, mFirst);
} finally {
photos.close();
Expand Down Expand Up @@ -346,7 +343,8 @@ private static void putEdges(
ContentResolver resolver,
Cursor photos,
WritableMap response,
int limit) {
int limit,
@Nullable String assetType) {
WritableArray edges = new WritableNativeArray();
photos.moveToFirst();
int idIndex = photos.getColumnIndex(Images.Media._ID);
Expand All @@ -362,7 +360,7 @@ private static void putEdges(
WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess =
putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex);
putImageInfo(resolver, photos, node, idIndex, widthIndex, heightIndex, assetType);
if (imageInfoSuccess) {
putBasicNodeInfo(photos, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(photos, node, longitudeIndex, latitudeIndex);
Expand Down Expand Up @@ -396,11 +394,15 @@ private static boolean putImageInfo(
WritableMap node,
int idIndex,
int widthIndex,
int heightIndex) {
int heightIndex,
@Nullable String assetType) {
WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.withAppendedPath(
Images.Media.EXTERNAL_CONTENT_URI,
photos.getString(idIndex));
Uri photoUri;
if (assetType != null && assetType.equals("Videos")) {
photoUri = Uri.withAppendedPath(Video.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
} else {
photoUri = Uri.withAppendedPath(Images.Media.EXTERNAL_CONTENT_URI, photos.getString(idIndex));
}
image.putString("uri", photoUri.toString());
float width = -1;
float height = -1;
Expand Down

0 comments on commit 1748922

Please sign in to comment.