mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-29 00:20:04 +01:00
170 lines
6.2 KiB
Diff
170 lines
6.2 KiB
Diff
diff --git a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java
|
|
index 8e59033..c87febe 100644
|
|
--- a/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java
|
|
+++ b/node_modules/react-native-image-picker/android/src/main/java/com/imagepicker/Utils.java
|
|
@@ -1,6 +1,7 @@
|
|
package com.imagepicker;
|
|
|
|
import android.Manifest;
|
|
+import android.annotation.SuppressLint;
|
|
import android.app.Activity;
|
|
import android.content.ClipData;
|
|
import android.content.ContentResolver;
|
|
@@ -21,6 +22,7 @@ import android.provider.OpenableColumns;
|
|
import android.util.Base64;
|
|
import android.webkit.MimeTypeMap;
|
|
|
|
+import androidx.annotation.NonNull;
|
|
import androidx.core.app.ActivityCompat;
|
|
import androidx.core.content.FileProvider;
|
|
import androidx.exifinterface.media.ExifInterface;
|
|
@@ -36,6 +38,7 @@ import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.OutputStream;
|
|
+import java.net.URI;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
@@ -266,7 +269,9 @@ public class Utils {
|
|
MediaMetadataRetriever m = new MediaMetadataRetriever();
|
|
m.setDataSource(context, uri);
|
|
int duration = Math.round(Float.parseFloat(m.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION))) / 1000;
|
|
- m.release();
|
|
+ try {
|
|
+ m.release();
|
|
+ } catch(Exception e) {}
|
|
return duration;
|
|
}
|
|
|
|
@@ -383,7 +388,7 @@ public class Utils {
|
|
return fileUris;
|
|
}
|
|
|
|
- static ReadableMap getImageResponseMap(Uri uri, Options options, Context context) {
|
|
+ static WritableMap getImageResponseMap(Uri uri, Options options, Context context) {
|
|
String fileName = uri.getLastPathSegment();
|
|
int[] dimensions = getImageDimensions(uri, context);
|
|
|
|
@@ -418,13 +423,16 @@ public class Utils {
|
|
|
|
for(int i = 0; i < fileUris.size(); ++i) {
|
|
Uri uri = fileUris.get(i);
|
|
+ String fileName = getNameFromURI(context,uri);
|
|
|
|
if (isImageType(uri, context)) {
|
|
if (uri.getScheme().contains("content")) {
|
|
uri = getAppSpecificStorageUri(uri, context);
|
|
}
|
|
uri = resizeImage(uri, context, options);
|
|
- assets.pushMap(getImageResponseMap(uri, options, context));
|
|
+ WritableMap resMap = getImageResponseMap(uri, options, context);
|
|
+ resMap.putString("originalFileName",fileName);
|
|
+ assets.pushMap(resMap);
|
|
} else if (isVideoType(uri, context)) {
|
|
assets.pushMap(getVideoResponseMap(uri, context));
|
|
} else {
|
|
@@ -438,6 +446,32 @@ public class Utils {
|
|
return response;
|
|
}
|
|
|
|
+ /**
|
|
+ * Return file name from Uri given.
|
|
+ * @param context the context, cannot be null.
|
|
+ * @param uri uri request for file name, cannot be null
|
|
+ * @return the corresponding display name for file defined in uri or null if error occurs.
|
|
+ */
|
|
+ @SuppressLint("Range")
|
|
+ static String getNameFromURI(@NonNull Context context, @NonNull Uri uri) {
|
|
+ String result = null;
|
|
+ Cursor c = null;
|
|
+ try {
|
|
+ c = context.getContentResolver().query(uri, null, null, null, null);
|
|
+ c.moveToFirst();
|
|
+ result = c.getString(c.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
|
+ }
|
|
+ catch (Exception e){
|
|
+ // error occurs
|
|
+ }
|
|
+ finally {
|
|
+ if(c != null){
|
|
+ c.close();
|
|
+ }
|
|
+ }
|
|
+ return result;
|
|
+ }
|
|
+
|
|
static ReadableMap getErrorMap(String errCode, String errMsg) {
|
|
WritableMap map = Arguments.createMap();
|
|
map.putString("errorCode", errCode);
|
|
diff --git a/node_modules/react-native-image-picker/ios/ImagePickerManager.m b/node_modules/react-native-image-picker/ios/ImagePickerManager.m
|
|
index b634ffb..18b8950 100644
|
|
--- a/node_modules/react-native-image-picker/ios/ImagePickerManager.m
|
|
+++ b/node_modules/react-native-image-picker/ios/ImagePickerManager.m
|
|
@@ -96,6 +96,39 @@ - (void) showPickerViewController:(UIViewController *)picker
|
|
});
|
|
}
|
|
|
|
+-(NSString *)cachesDirectoryName
|
|
+{
|
|
+ static NSString *cachePath = nil;
|
|
+ if(!cachePath) {
|
|
+ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
+ cachePath = [paths objectAtIndex:0];
|
|
+ }
|
|
+
|
|
+ return cachePath;
|
|
+}
|
|
+
|
|
+///
|
|
+/// Builds paths for identifiers in the cache directory
|
|
+///
|
|
+-(NSString *)pathForName:(NSString *)name
|
|
+{
|
|
+ NSString *cachePath = [self cachesDirectoryName];
|
|
+ NSString *path = [cachePath stringByAppendingPathComponent:name];
|
|
+ return path;
|
|
+}
|
|
+
|
|
+#pragma mark - NSData Cache methods
|
|
+
|
|
+///
|
|
+/// Saves the given data to the cache directory
|
|
+///
|
|
+-(NSString *)saveToCacheDirectory:(NSData *)data withName:(NSString *)name
|
|
+{
|
|
+ NSString *path = [self pathForName:name];
|
|
+ [data writeToFile:path atomically:YES];
|
|
+ return path;
|
|
+}
|
|
+
|
|
#pragma mark - Helpers
|
|
|
|
-(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data {
|
|
@@ -121,22 +154,14 @@ -(NSMutableDictionary *)mapImageToAsset:(UIImage *)image data:(NSData *)data {
|
|
asset[@"type"] = [@"image/" stringByAppendingString:fileType];
|
|
|
|
NSString *fileName = [self getImageFileName:fileType];
|
|
- NSString *path = [[NSTemporaryDirectory() stringByStandardizingPath] stringByAppendingPathComponent:fileName];
|
|
- [data writeToFile:path atomically:YES];
|
|
+ NSString *path = [self saveToCacheDirectory:data withName:fileName];
|
|
|
|
if ([self.options[@"includeBase64"] boolValue]) {
|
|
asset[@"base64"] = [data base64EncodedStringWithOptions:0];
|
|
}
|
|
|
|
- NSURL *fileURL = [NSURL fileURLWithPath:path];
|
|
- asset[@"uri"] = [fileURL absoluteString];
|
|
-
|
|
- NSNumber *fileSizeValue = nil;
|
|
- NSError *fileSizeError = nil;
|
|
- [fileURL getResourceValue:&fileSizeValue forKey:NSURLFileSizeKey error:&fileSizeError];
|
|
- if (fileSizeValue){
|
|
- asset[@"fileSize"] = fileSizeValue;
|
|
- }
|
|
+ asset[@"uri"] = path;
|
|
+ asset[@"fileSize"] = [NSNumber numberWithInteger:[data length]];
|
|
|
|
asset[@"fileName"] = fileName;
|
|
asset[@"width"] = @(image.size.width);
|