Skip to content

Commit 5355d7c

Browse files
committed
[Android] read options in a function since the code is the same for library/camera
1 parent ba35fca commit 5355d7c

File tree

1 file changed

+35
-60
lines changed

1 file changed

+35
-60
lines changed

android/src/main/java/com/imagepicker/ImagePickerModule.java

Lines changed: 35 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -152,36 +152,7 @@ public void onCancel(DialogInterface dialog) {
152152
public void launchCamera(final ReadableMap options, final Callback callback) {
153153
response = Arguments.createMap();
154154

155-
if (options.hasKey("noData")) {
156-
noData = options.getBoolean("noData");
157-
}
158-
if (options.hasKey("maxWidth")) {
159-
maxWidth = options.getInt("maxWidth");
160-
}
161-
if (options.hasKey("maxHeight")) {
162-
maxHeight = options.getInt("maxHeight");
163-
}
164-
if (options.hasKey("aspectX")) {
165-
aspectX = options.getInt("aspectX");
166-
}
167-
if (options.hasKey("aspectY")) {
168-
aspectY = options.getInt("aspectY");
169-
}
170-
if (options.hasKey("quality")) {
171-
quality = (int)(options.getDouble("quality") * 100);
172-
}
173-
tmpImage = true;
174-
if (options.hasKey("storageOptions")) {
175-
tmpImage = false;
176-
}
177-
if (options.hasKey("allowsEditing")) {
178-
allowEditing = options.getBoolean("allowsEditing");
179-
}
180-
forceAngle = false;
181-
if (options.hasKey("angle")) {
182-
forceAngle = true;
183-
angle = options.getInt("angle");
184-
}
155+
parseOptions(options);
185156

186157
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
187158
if (cameraIntent.resolveActivity(mReactContext.getPackageManager()) == null) {
@@ -221,36 +192,7 @@ public void launchCamera(final ReadableMap options, final Callback callback) {
221192
public void launchImageLibrary(final ReadableMap options, final Callback callback) {
222193
response = Arguments.createMap();
223194

224-
if (options.hasKey("noData")) {
225-
noData = options.getBoolean("noData");
226-
}
227-
if (options.hasKey("maxWidth")) {
228-
maxWidth = options.getInt("maxWidth");
229-
}
230-
if (options.hasKey("maxHeight")) {
231-
maxHeight = options.getInt("maxHeight");
232-
}
233-
if (options.hasKey("aspectX")) {
234-
aspectX = options.getInt("aspectX");
235-
}
236-
if (options.hasKey("aspectY")) {
237-
aspectY = options.getInt("aspectY");
238-
}
239-
if (options.hasKey("quality")) {
240-
quality = (int)(options.getDouble("quality") * 100);
241-
}
242-
tmpImage = true;
243-
if (options.hasKey("storageOptions")) {
244-
tmpImage = false;
245-
}
246-
if (options.hasKey("allowsEditing")) {
247-
allowEditing = options.getBoolean("allowsEditing");
248-
}
249-
forceAngle = false;
250-
if (options.hasKey("angle")) {
251-
forceAngle = true;
252-
angle = options.getInt("angle");
253-
}
195+
parseOptions(options);
254196

255197
Intent libraryIntent = new Intent(Intent.ACTION_PICK,
256198
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
@@ -567,4 +509,37 @@ private File createNewFile() {
567509
return f;
568510
}
569511
}
512+
513+
private void parseOptions(final ReadableMap options) {
514+
if (options.hasKey("noData")) {
515+
noData = options.getBoolean("noData");
516+
}
517+
if (options.hasKey("maxWidth")) {
518+
maxWidth = options.getInt("maxWidth");
519+
}
520+
if (options.hasKey("maxHeight")) {
521+
maxHeight = options.getInt("maxHeight");
522+
}
523+
if (options.hasKey("aspectX")) {
524+
aspectX = options.getInt("aspectX");
525+
}
526+
if (options.hasKey("aspectY")) {
527+
aspectY = options.getInt("aspectY");
528+
}
529+
if (options.hasKey("quality")) {
530+
quality = (int)(options.getDouble("quality") * 100);
531+
}
532+
tmpImage = true;
533+
if (options.hasKey("storageOptions")) {
534+
tmpImage = false;
535+
}
536+
if (options.hasKey("allowsEditing")) {
537+
allowEditing = options.getBoolean("allowsEditing");
538+
}
539+
forceAngle = false;
540+
if (options.hasKey("angle")) {
541+
forceAngle = true;
542+
angle = options.getInt("angle");
543+
}
544+
}
570545
}

0 commit comments

Comments
 (0)