Skip to content

Commit

Permalink
chore(formatting): fix on android (#2208)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johan-dutoit authored and jdutoitSRX committed Sep 7, 2023
1 parent 39d96d0 commit 444a10f
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 166 deletions.
48 changes: 29 additions & 19 deletions android/src/main/java/com/imagepicker/ImageMetadata.java
Expand Up @@ -3,30 +3,40 @@
import android.content.Context;
import android.net.Uri;
import android.util.Log;

import androidx.exifinterface.media.ExifInterface;

import java.io.InputStream;

public class ImageMetadata extends Metadata {
public ImageMetadata(Uri uri, Context context) {
try(InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
ExifInterface exif = new ExifInterface(inputStream);
String datetimeTag = exif.getAttribute(ExifInterface.TAG_DATETIME);

// Extract anymore metadata here...
if(datetimeTag != null) this.datetime = getDateTimeInUTC(datetimeTag, "yyyy:MM:dd HH:mm:ss");
} catch (Exception e) {
// This error does not bubble up to RN as we don't want failed datetime retrieval to prevent selection
Log.e("RNIP", "Could not load image metadata: " + e.getMessage());
public ImageMetadata(Uri uri, Context context) {
try (InputStream inputStream = context.getContentResolver().openInputStream(uri)) {
ExifInterface exif = new ExifInterface(inputStream);
String datetimeTag = exif.getAttribute(ExifInterface.TAG_DATETIME);

// Extract anymore metadata here...
if (datetimeTag != null)
this.datetime = getDateTimeInUTC(datetimeTag, "yyyy:MM:dd HH:mm:ss");
} catch (Exception e) {
// This error does not bubble up to RN as we don't want failed datetime retrieval to prevent selection
Log.e("RNIP", "Could not load image metadata: " + e.getMessage());
}
}
}

@Override
public String getDateTime() { return datetime; }
@Override
public String getDateTime() {
return datetime;
}

// At the moment we are not using the ImageMetadata class to get width/height
// TODO: to use this class for extracting image width and height in the future
@Override
public int getWidth() { return 0; }
@Override
public int getHeight() { return 0; }
// At the moment we are not using the ImageMetadata class to get width/height
// TODO: to use this class for extracting image width and height in the future
@Override
public int getWidth() {
return 0;
}

@Override
public int getHeight() {
return 0;
}
}
11 changes: 6 additions & 5 deletions android/src/main/java/com/imagepicker/ImagePickerModuleImpl.java
Expand Up @@ -192,12 +192,12 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
deleteFile(fileUri);
}
try {
callback.invoke(getCancelMap());
return;
callback.invoke(getCancelMap());
return;
} catch (RuntimeException exception) {
callback.invoke(getErrorMap(errOthers, exception.getMessage()));
callback.invoke(getErrorMap(errOthers, exception.getMessage()));
} finally {
callback = null;
callback = null;
}
}

Expand Down Expand Up @@ -225,5 +225,6 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,
}

@Override
public void onNewIntent(Intent intent) { }
public void onNewIntent(Intent intent) {
}
}
@@ -1,6 +1,7 @@
package com.imagepicker;

import androidx.annotation.Nullable;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.module.model.ReactModuleInfo;
Expand Down Expand Up @@ -37,7 +38,7 @@ public ReactModuleInfoProvider getReactModuleInfoProvider() {
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
));
));
return moduleInfos;
};
}
Expand Down
64 changes: 33 additions & 31 deletions android/src/main/java/com/imagepicker/Metadata.java
Expand Up @@ -9,36 +9,38 @@
import java.util.Locale;

abstract class Metadata {
protected String datetime;
protected int height;
protected int width;

abstract public String getDateTime();
abstract public int getWidth();
abstract public int getHeight();

/**
* Converts a timestamp to a UTC timestamp
*
* @param value - timestamp
* @param format - input format
* @return formatted timestamp
*/
protected @Nullable
String getDateTimeInUTC(String value, String format) {
try {
Date datetime = new SimpleDateFormat(format, Locale.US).parse(value);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);

if (datetime != null) {
return formatter.format(datetime);
}

return null;
} catch (Exception e) {
// This error does not bubble up to RN as we don't want failed datetime parsing to prevent selection
Log.e("RNIP", "Could not parse image datetime to UTC: " + e.getMessage());
return null;
protected String datetime;
protected int height;
protected int width;

abstract public String getDateTime();

abstract public int getWidth();

abstract public int getHeight();

/**
* Converts a timestamp to a UTC timestamp
*
* @param value - timestamp
* @param format - input format
* @return formatted timestamp
*/
protected @Nullable
String getDateTimeInUTC(String value, String format) {
try {
Date datetime = new SimpleDateFormat(format, Locale.US).parse(value);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);

if (datetime != null) {
return formatter.format(datetime);
}

return null;
} catch (Exception e) {
// This error does not bubble up to RN as we don't want failed datetime parsing to prevent selection
Log.e("RNIP", "Could not parse image datetime to UTC: " + e.getMessage());
return null;
}
}
}
}
3 changes: 2 additions & 1 deletion android/src/main/java/com/imagepicker/Options.java
@@ -1,6 +1,7 @@
package com.imagepicker;

import com.facebook.react.bridge.ReadableMap;

import android.text.TextUtils;

public class Options {
Expand All @@ -24,7 +25,7 @@ public class Options {
includeExtra = options.getBoolean("includeExtra");

String videoQualityString = options.getString("videoQuality");
if(!TextUtils.isEmpty(videoQualityString) && !videoQualityString.toLowerCase().equals("high")) {
if (!TextUtils.isEmpty(videoQualityString) && !videoQualityString.toLowerCase().equals("high")) {
videoQuality = 0;
}

Expand Down

0 comments on commit 444a10f

Please sign in to comment.