77import android .content .Context ;
88import android .content .Intent ;
99import android .widget .Toast ;
10+ import androidx .activity .result .ActivityResult ;
1011import androidx .activity .result .ActivityResultLauncher ;
1112import androidx .annotation .NonNull ;
1213import androidx .lifecycle .LiveData ;
@@ -64,23 +65,24 @@ public ContributionController(@Named("default_preferences") JsonKvStore defaultK
6465 * Check for permissions and initiate camera click
6566 */
6667 public void initiateCameraPick (Activity activity ,
67- ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ) {
68+ ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ,
69+ ActivityResultLauncher <Intent > resultLauncher ) {
6870 boolean useExtStorage = defaultKvStore .getBoolean ("useExternalStorage" , true );
6971 if (!useExtStorage ) {
70- initiateCameraUpload (activity );
72+ initiateCameraUpload (activity , resultLauncher );
7173 return ;
7274 }
7375
7476 PermissionUtils .checkPermissionsAndPerformAction (activity ,
7577 () -> {
7678 if (defaultKvStore .getBoolean ("inAppCameraFirstRun" )) {
7779 defaultKvStore .putBoolean ("inAppCameraFirstRun" , false );
78- askUserToAllowLocationAccess (activity , inAppCameraLocationPermissionLauncher );
80+ askUserToAllowLocationAccess (activity , inAppCameraLocationPermissionLauncher , resultLauncher );
7981 } else if (defaultKvStore .getBoolean ("inAppCameraLocationPref" )) {
8082 createDialogsAndHandleLocationPermissions (activity ,
81- inAppCameraLocationPermissionLauncher );
83+ inAppCameraLocationPermissionLauncher , resultLauncher );
8284 } else {
83- initiateCameraUpload (activity );
85+ initiateCameraUpload (activity , resultLauncher );
8486 }
8587 },
8688 R .string .storage_permission_title ,
@@ -94,7 +96,8 @@ public void initiateCameraPick(Activity activity,
9496 * @param activity
9597 */
9698 private void createDialogsAndHandleLocationPermissions (Activity activity ,
97- ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ) {
99+ ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ,
100+ ActivityResultLauncher <Intent > resultLauncher ) {
98101 locationPermissionCallback = new LocationPermissionCallback () {
99102 @ Override
100103 public void onLocationPermissionDenied (String toastMessage ) {
@@ -103,16 +106,16 @@ public void onLocationPermissionDenied(String toastMessage) {
103106 toastMessage ,
104107 Toast .LENGTH_LONG
105108 ).show ();
106- initiateCameraUpload (activity );
109+ initiateCameraUpload (activity , resultLauncher );
107110 }
108111
109112 @ Override
110113 public void onLocationPermissionGranted () {
111114 if (!locationPermissionsHelper .isLocationAccessToAppsTurnedOn ()) {
112115 showLocationOffDialog (activity , R .string .in_app_camera_needs_location ,
113- R .string .in_app_camera_location_unavailable );
116+ R .string .in_app_camera_location_unavailable , resultLauncher );
114117 } else {
115- initiateCameraUpload (activity );
118+ initiateCameraUpload (activity , resultLauncher );
116119 }
117120 }
118121 };
@@ -135,9 +138,10 @@ public void onLocationPermissionGranted() {
135138 * @param activity Activity reference
136139 * @param dialogTextResource Resource id of text to be shown in dialog
137140 * @param toastTextResource Resource id of text to be shown in toast
141+ * @param resultLauncher
138142 */
139143 private void showLocationOffDialog (Activity activity , int dialogTextResource ,
140- int toastTextResource ) {
144+ int toastTextResource , ActivityResultLauncher < Intent > resultLauncher ) {
141145 DialogUtil
142146 .showAlertDialog (activity ,
143147 activity .getString (R .string .ask_to_turn_location_on ),
@@ -148,20 +152,21 @@ private void showLocationOffDialog(Activity activity, int dialogTextResource,
148152 () -> {
149153 Toast .makeText (activity , activity .getString (toastTextResource ),
150154 Toast .LENGTH_LONG ).show ();
151- initiateCameraUpload (activity );
155+ initiateCameraUpload (activity , resultLauncher );
152156 }
153157 );
154158 }
155159
156160 public void handleShowRationaleFlowCameraLocation (Activity activity ,
157- ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ) {
161+ ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ,
162+ ActivityResultLauncher <Intent > resultLauncher ) {
158163 DialogUtil .showAlertDialog (activity , activity .getString (R .string .location_permission_title ),
159164 activity .getString (R .string .in_app_camera_location_permission_rationale ),
160165 activity .getString (android .R .string .ok ),
161166 activity .getString (android .R .string .cancel ),
162167 () -> {
163168 createDialogsAndHandleLocationPermissions (activity ,
164- inAppCameraLocationPermissionLauncher );
169+ inAppCameraLocationPermissionLauncher , resultLauncher );
165170 },
166171 () -> locationPermissionCallback .onLocationPermissionDenied (
167172 activity .getString (R .string .in_app_camera_location_permission_denied )),
@@ -181,7 +186,8 @@ public void handleShowRationaleFlowCameraLocation(Activity activity,
181186 * @param activity
182187 */
183188 private void askUserToAllowLocationAccess (Activity activity ,
184- ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ) {
189+ ActivityResultLauncher <String []> inAppCameraLocationPermissionLauncher ,
190+ ActivityResultLauncher <Intent > resultLauncher ) {
185191 DialogUtil .showAlertDialog (activity ,
186192 activity .getString (R .string .in_app_camera_location_permission_title ),
187193 activity .getString (R .string .in_app_camera_location_access_explanation ),
@@ -190,12 +196,12 @@ private void askUserToAllowLocationAccess(Activity activity,
190196 () -> {
191197 defaultKvStore .putBoolean ("inAppCameraLocationPref" , true );
192198 createDialogsAndHandleLocationPermissions (activity ,
193- inAppCameraLocationPermissionLauncher );
199+ inAppCameraLocationPermissionLauncher , resultLauncher );
194200 },
195201 () -> {
196202 ViewUtil .showLongToast (activity , R .string .in_app_camera_location_permission_denied );
197203 defaultKvStore .putBoolean ("inAppCameraLocationPref" , false );
198- initiateCameraUpload (activity );
204+ initiateCameraUpload (activity , resultLauncher );
199205 },
200206 null ,
201207 true );
@@ -204,18 +210,18 @@ private void askUserToAllowLocationAccess(Activity activity,
204210 /**
205211 * Initiate gallery picker
206212 */
207- public void initiateGalleryPick (final Activity activity , final boolean allowMultipleUploads ) {
208- initiateGalleryUpload (activity , allowMultipleUploads );
213+ public void initiateGalleryPick (final Activity activity , ActivityResultLauncher < Intent > resultLauncher , final boolean allowMultipleUploads ) {
214+ initiateGalleryUpload (activity , resultLauncher , allowMultipleUploads );
209215 }
210216
211217 /**
212218 * Initiate gallery picker with permission
213219 */
214- public void initiateCustomGalleryPickWithPermission (final Activity activity ) {
220+ public void initiateCustomGalleryPickWithPermission (final Activity activity , ActivityResultLauncher < Intent > resultLauncher ) {
215221 setPickerConfiguration (activity , true );
216222
217223 PermissionUtils .checkPermissionsAndPerformAction (activity ,
218- () -> FilePicker .openCustomSelector (activity , 0 ),
224+ () -> FilePicker .openCustomSelector (activity , resultLauncher , 0 ),
219225 R .string .storage_permission_title ,
220226 R .string .write_storage_permission_rationale ,
221227 PermissionUtils .PERMISSIONS_STORAGE );
@@ -225,12 +231,10 @@ public void initiateCustomGalleryPickWithPermission(final Activity activity) {
225231 /**
226232 * Open chooser for gallery uploads
227233 */
228- private void initiateGalleryUpload (final Activity activity ,
234+ private void initiateGalleryUpload (final Activity activity , ActivityResultLauncher < Intent > resultLauncher ,
229235 final boolean allowMultipleUploads ) {
230236 setPickerConfiguration (activity , allowMultipleUploads );
231- boolean openDocumentIntentPreferred = defaultKvStore .getBoolean (
232- "openDocumentPhotoPickerPref" , true );
233- FilePicker .openGallery (activity , 0 , openDocumentIntentPreferred );
237+ FilePicker .openGallery (activity , resultLauncher , 0 , isDocumentPhotoPickerPreferred ());
234238 }
235239
236240 /**
@@ -247,22 +251,43 @@ private void setPickerConfiguration(Activity activity,
247251 /**
248252 * Initiate camera upload by opening camera
249253 */
250- private void initiateCameraUpload (Activity activity ) {
254+ private void initiateCameraUpload (Activity activity , ActivityResultLauncher < Intent > resultLauncher ) {
251255 setPickerConfiguration (activity , false );
252256 if (defaultKvStore .getBoolean ("inAppCameraLocationPref" , false )) {
253257 locationBeforeImageCapture = locationManager .getLastLocation ();
254258 }
255259 isInAppCameraUpload = true ;
256- FilePicker .openCameraForImage (activity , 0 );
260+ FilePicker .openCameraForImage (activity , resultLauncher , 0 );
261+ }
262+
263+ private boolean isDocumentPhotoPickerPreferred (){
264+ return defaultKvStore .getBoolean (
265+ "openDocumentPhotoPickerPref" , true );
266+ }
267+
268+ public void onPictureReturnedFromGallery (ActivityResult result , Activity activity , FilePicker .Callbacks callbacks ){
269+
270+ if (isDocumentPhotoPickerPreferred ()){
271+ FilePicker .onPictureReturnedFromDocuments (result , activity , callbacks );
272+ } else {
273+ FilePicker .onPictureReturnedFromGallery (result , activity , callbacks );
274+ }
275+ }
276+
277+ public void onPictureReturnedFromCustomSelector (ActivityResult result , Activity activity , @ NonNull FilePicker .Callbacks callbacks ) {
278+ FilePicker .onPictureReturnedFromCustomSelector (result , activity , callbacks );
279+ }
280+
281+ public void onPictureReturnedFromCamera (ActivityResult result , Activity activity , @ NonNull FilePicker .Callbacks callbacks ) {
282+ FilePicker .onPictureReturnedFromCamera (result , activity , callbacks );
257283 }
258284
259285 /**
260286 * Attaches callback for file picker.
261287 */
262- public void handleActivityResult (Activity activity , int requestCode , int resultCode ,
263- Intent data ) {
264- FilePicker .handleActivityResult (requestCode , resultCode , data , activity ,
265- new DefaultCallback () {
288+ public void handleActivityResultWithCallback (Activity activity , FilePicker .HandleActivityResult handleActivityResult ) {
289+
290+ handleActivityResult .onHandleActivityResult (new DefaultCallback () {
266291
267292 @ Override
268293 public void onCanceled (final ImageSource source , final int type ) {
0 commit comments