fix: Revert "feat: Added include parameter to getPhotos to let users tradeoff performance by omitting metadata (#178)" (#199)

This commit is contained in:
Bartol Karuza
2020-06-16 13:05:12 +03:00
committed by GitHub
parent c5ea581d22
commit e65e1f208b
16 changed files with 161 additions and 626 deletions
@@ -47,11 +47,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import javax.annotation.Nullable;
@@ -74,10 +72,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
private static final String ASSET_TYPE_VIDEOS = "Videos";
private static final String ASSET_TYPE_ALL = "All";
private static final String INCLUDE_FILENAME = "filename";
private static final String INCLUDE_FILE_SIZE = "fileSize";
private static final String INCLUDE_LOCATION = "location";
private static final String[] PROJECTION = {
Images.Media._ID,
Images.Media.MIME_TYPE,
@@ -253,7 +247,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
ReadableArray mimeTypes = params.hasKey("mimeTypes")
? params.getArray("mimeTypes")
: null;
ReadableArray include = params.hasKey("include") ? params.getArray("include") : null;
new GetMediaTask(
getReactApplicationContext(),
@@ -264,7 +257,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
assetType,
fromTime,
toTime,
include,
promise)
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -279,7 +271,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
private final String mAssetType;
private final long mFromTime;
private final long mToTime;
private final Set<String> mInclude;
private GetMediaTask(
ReactContext context,
@@ -290,7 +281,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
String assetType,
long fromTime,
long toTime,
@Nullable ReadableArray include,
Promise promise) {
super(context);
mContext = context;
@@ -302,24 +292,6 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
mAssetType = assetType;
mFromTime = fromTime;
mToTime = toTime;
mInclude = createSetFromIncludeArray(include);
}
private static Set<String> createSetFromIncludeArray(@Nullable ReadableArray includeArray) {
Set<String> includeSet = new HashSet<>();
if (includeArray == null) {
return includeSet;
}
for (int i = 0; i < includeArray.size(); i++) {
@Nullable String includeItem = includeArray.getString(i);
if (includeItem != null) {
includeSet.add(includeItem);
}
}
return includeSet;
}
@Override
@@ -390,7 +362,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
mPromise.reject(ERROR_UNABLE_TO_LOAD, "Could not get media");
} else {
try {
putEdges(resolver, media, response, mFirst, mInclude);
putEdges(resolver, media, response, mFirst);
putPageInfo(media, response, mFirst, !TextUtils.isEmpty(mAfter) ? Integer.parseInt(mAfter) : 0);
} finally {
media.close();
@@ -491,10 +463,10 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
ContentResolver resolver,
Cursor media,
WritableMap response,
int limit,
Set<String> include) {
int limit) {
WritableArray edges = new WritableNativeArray();
media.moveToFirst();
int idIndex = media.getColumnIndex(Images.Media._ID);
int mimeTypeIndex = media.getColumnIndex(Images.Media.MIME_TYPE);
int groupNameIndex = media.getColumnIndex(Images.Media.BUCKET_DISPLAY_NAME);
int dateTakenIndex = media.getColumnIndex(Images.Media.DATE_TAKEN);
@@ -503,19 +475,14 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
int sizeIndex = media.getColumnIndex(MediaStore.MediaColumns.SIZE);
int dataIndex = media.getColumnIndex(MediaStore.MediaColumns.DATA);
boolean includeLocation = include.contains(INCLUDE_LOCATION);
boolean includeFilename = include.contains(INCLUDE_FILENAME);
boolean includeFileSize = include.contains(INCLUDE_FILE_SIZE);
for (int i = 0; i < limit && !media.isAfterLast(); i++) {
WritableMap edge = new WritableNativeMap();
WritableMap node = new WritableNativeMap();
boolean imageInfoSuccess =
putImageInfo(resolver, media, node, widthIndex, heightIndex, sizeIndex, dataIndex,
mimeTypeIndex, includeFilename, includeFileSize);
putImageInfo(resolver, media, node, idIndex, widthIndex, heightIndex, sizeIndex, dataIndex, mimeTypeIndex);
if (imageInfoSuccess) {
putBasicNodeInfo(media, node, mimeTypeIndex, groupNameIndex, dateTakenIndex);
putLocationInfo(media, node, dataIndex, includeLocation);
putLocationInfo(media, node, dataIndex);
edge.putMap("node", node);
edges.pushMap(edge);
@@ -544,18 +511,22 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
ContentResolver resolver,
Cursor media,
WritableMap node,
int idIndex,
int widthIndex,
int heightIndex,
int sizeIndex,
int dataIndex,
int mimeTypeIndex,
boolean includeFilename,
boolean includeFileSize) {
int mimeTypeIndex) {
WritableMap image = new WritableNativeMap();
Uri photoUri = Uri.parse("file://" + media.getString(dataIndex));
File file = new File(media.getString(dataIndex));
String strFileName = file.getName();
image.putString("uri", photoUri.toString());
image.putString("filename", strFileName);
float width = media.getInt(widthIndex);
float height = media.getInt(heightIndex);
long fileSize = media.getLong(sizeIndex);
String mimeType = media.getString(mimeTypeIndex);
if (mimeType != null
@@ -614,21 +585,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
}
image.putDouble("width", width);
image.putDouble("height", height);
if (includeFilename) {
File file = new File(media.getString(dataIndex));
String strFileName = file.getName();
image.putString("filename", strFileName);
} else {
image.putNull("filename");
}
if (includeFileSize) {
image.putDouble("fileSize", media.getLong(sizeIndex));
} else {
image.putNull("fileSize");
}
image.putDouble("fileSize", fileSize);
node.putMap("image", image);
return true;
@@ -637,13 +594,7 @@ public class CameraRollModule extends ReactContextBaseJavaModule {
private static void putLocationInfo(
Cursor media,
WritableMap node,
int dataIndex,
boolean includeLocation) {
if (!includeLocation) {
node.putNull("location");
return;
}
int dataIndex) {
try {
// location details are no longer indexed for privacy reasons using string Media.LATITUDE, Media.LONGITUDE
// we manually obtain location metadata using ExifInterface#getLatLong(float[]).