Refactor FilePicker.java intent result handling (#5851)

* remove unnecessary video flag check

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* handle when custom selector operation cancelled

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* dispatch appropriate request code to handle using respective callbacks

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* remove wrong control statements

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

* refactor gallery picker test

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>

---------

Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
Parneet Singh 2024-10-16 07:50:00 +05:30 committed by GitHub
parent 95e0a0d143
commit f889ed1821
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 18 additions and 38 deletions

View file

@ -16,7 +16,6 @@ public interface Constants {
int PICK_PICTURE_FROM_DOCUMENTS = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 11);
int PICK_PICTURE_FROM_GALLERY = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 12);
int TAKE_PICTURE = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 13);
int CAPTURE_VIDEO = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 14);
int RECEIVE_DATA_FROM_FULL_SCREEN_MODE = 1 << 9;
}

View file

@ -109,7 +109,13 @@ public class FilePicker implements Constants {
*/
public static void openGallery(Activity activity, int type, boolean openDocumentIntentPreferred) {
Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred);
activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_GALLERY);
int requestCode = RequestCodes.PICK_PICTURE_FROM_GALLERY;
if(openDocumentIntentPreferred){
requestCode = RequestCodes.PICK_PICTURE_FROM_DOCUMENTS;
}
activity.startActivityForResult(intent, requestCode);
}
/**
@ -157,7 +163,6 @@ public class FilePicker implements Constants {
requestCode &= ~RequestCodes.SOURCE_CHOOSER;
if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY ||
requestCode == RequestCodes.TAKE_PICTURE ||
requestCode == RequestCodes.CAPTURE_VIDEO ||
requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS ||
requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) {
if (resultCode == Activity.RESULT_OK) {
@ -169,19 +174,16 @@ public class FilePicker implements Constants {
onPictureReturnedFromCustomSelector(data, activity, callbacks);
} else if (requestCode == RequestCodes.TAKE_PICTURE) {
onPictureReturnedFromCamera(activity, callbacks);
} else if (requestCode == RequestCodes.CAPTURE_VIDEO) {
onVideoReturnedFromCamera(activity, callbacks);
} else if (isPhoto(data)) {
onPictureReturnedFromCamera(activity, callbacks);
} else {
onPictureReturnedFromDocuments(data, activity, callbacks);
}
} else {
if (requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS) {
callbacks.onCanceled(FilePicker.ImageSource.DOCUMENTS, restoreType(activity));
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY) {
callbacks.onCanceled(FilePicker.ImageSource.GALLERY, restoreType(activity));
} else {
} else if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR){
callbacks.onCanceled(ImageSource.CUSTOM_SELECTOR, restoreType(activity));
}
else {
callbacks.onCanceled(FilePicker.ImageSource.CAMERA_IMAGE, restoreType(activity));
}
}