mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	refactor camera launcher
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
		
							parent
							
								
									6a98923a83
								
							
						
					
					
						commit
						77cd18c560
					
				
					 8 changed files with 50 additions and 39 deletions
				
			
		|  | @ -37,7 +37,9 @@ public class BookmarkLocationsFragment extends DaggerFragment { | |||
| 
 | ||||
|     private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(), | ||||
|         result -> { | ||||
|             // TODO handle result from controller | ||||
|             contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> { | ||||
|                 contributionController.onPictureReturnedFromCamera(result,requireActivity(),callbacks); | ||||
|             }); | ||||
|         }); | ||||
| 
 | ||||
|       private ActivityResultLauncher<Intent> galleryPickLauncherForResult = registerForActivityResult(new StartActivityForResult(), | ||||
|  | @ -99,7 +101,6 @@ public class BookmarkLocationsFragment extends DaggerFragment { | |||
|             commonPlaceClickActions, | ||||
|             inAppCameraLocationPermissionLauncher, | ||||
|             galleryPickLauncherForResult, | ||||
|             //TODO[Parry] just a stub, make sure if this is actually the launcher we need!! | ||||
|             cameraPickLauncherForResult | ||||
| 
 | ||||
|         ); | ||||
|  |  | |||
|  | @ -113,7 +113,7 @@ public class ContributionController { | |||
|             public void onLocationPermissionGranted() { | ||||
|                 if (!locationPermissionsHelper.isLocationAccessToAppsTurnedOn()) { | ||||
|                     showLocationOffDialog(activity, R.string.in_app_camera_needs_location, | ||||
|                         R.string.in_app_camera_location_unavailable); | ||||
|                         R.string.in_app_camera_location_unavailable, resultLauncher); | ||||
|                 } else { | ||||
|                     initiateCameraUpload(activity, resultLauncher); | ||||
|                 } | ||||
|  | @ -138,9 +138,10 @@ public class ContributionController { | |||
|      * @param activity           Activity reference | ||||
|      * @param dialogTextResource Resource id of text to be shown in dialog | ||||
|      * @param toastTextResource  Resource id of text to be shown in toast | ||||
|      * @param resultLauncher | ||||
|      */ | ||||
|     private void showLocationOffDialog(Activity activity, int dialogTextResource, | ||||
|         int toastTextResource) { | ||||
|         int toastTextResource, ActivityResultLauncher<Intent> resultLauncher) { | ||||
|         DialogUtil | ||||
|             .showAlertDialog(activity, | ||||
|                 activity.getString(R.string.ask_to_turn_location_on), | ||||
|  | @ -151,8 +152,7 @@ public class ContributionController { | |||
|                 () -> { | ||||
|                     Toast.makeText(activity, activity.getString(toastTextResource), | ||||
|                         Toast.LENGTH_LONG).show(); | ||||
|                     //TODO [Parry] why do we need this call??? | ||||
| //                    initiateCameraUpload(activity); | ||||
|                     initiateCameraUpload(activity,resultLauncher); | ||||
|                 } | ||||
|             ); | ||||
|     } | ||||
|  | @ -270,6 +270,10 @@ public class ContributionController { | |||
|         FilePicker.onPictureReturnedFromCustomSelector(result,activity,callbacks); | ||||
|     } | ||||
| 
 | ||||
|     public void onPictureReturnedFromCamera(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         FilePicker.onPictureReturnedFromCamera(result,activity,callbacks); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Attaches callback for file picker. | ||||
|      */ | ||||
|  |  | |||
|  | @ -114,7 +114,9 @@ public class ContributionsListFragment extends CommonsDaggerSupportFragment impl | |||
| 
 | ||||
|     private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(), | ||||
|         result -> { | ||||
|             // TODO handle result from controller | ||||
|             controller.handleActivityResultWithCallback(requireActivity(),callbacks -> { | ||||
|                 controller.onPictureReturnedFromCamera(result,requireActivity(),callbacks); | ||||
|             }); | ||||
|         }); | ||||
| 
 | ||||
|     private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult( | ||||
|  |  | |||
|  | @ -135,7 +135,6 @@ public class FilePicker implements Constants { | |||
|      */ | ||||
|     public static void openCameraForImage(Activity activity, ActivityResultLauncher<Intent> resultLauncher, int type) { | ||||
|         Intent intent = createCameraForImageIntent(activity, type); | ||||
|         //TODO[Parry] we're not using the result anyways. | ||||
| //        activity.startActivityForResult(intent, RequestCodes.TAKE_PICTURE); | ||||
|         resultLauncher.launch(intent); | ||||
|     } | ||||
|  | @ -179,8 +178,7 @@ public class FilePicker implements Constants { | |||
|                     } else if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) { | ||||
| //                        onPictureReturnedFromCustomSelector(data, activity, callbacks); | ||||
|                     } else if (requestCode == RequestCodes.TAKE_PICTURE) { | ||||
|                         //TODO[Parry] why handle the result , when not using it in the first place??? | ||||
|                         onPictureReturnedFromCamera(activity, callbacks); | ||||
| //                        onPictureReturnedFromCamera(activity, callbacks); | ||||
|                     } | ||||
|                 } else { | ||||
|                     if (requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS) { | ||||
|  | @ -337,7 +335,8 @@ public class FilePicker implements Constants { | |||
|         return files; | ||||
|     } | ||||
| 
 | ||||
|     private static void onPictureReturnedFromCamera(Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|     public static void onPictureReturnedFromCamera(ActivityResult activityResult, Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         if(activityResult.getResultCode() == Activity.RESULT_OK){ | ||||
|             try { | ||||
|                 String lastImageUri = PreferenceManager.getDefaultSharedPreferences(activity).getString(KEY_PHOTO_URI, null); | ||||
|                 if (!TextUtils.isEmpty(lastImageUri)) { | ||||
|  | @ -369,6 +368,7 @@ public class FilePicker implements Constants { | |||
|                 callbacks.onImagePickerError(e, FilePicker.ImageSource.CAMERA_IMAGE, restoreType(activity)); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private static void onVideoReturnedFromCamera(Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         try { | ||||
|  |  | |||
|  | @ -29,7 +29,7 @@ fun placeAdapterDelegate( | |||
|     onDirectionsClicked: (Place) -> Unit, | ||||
|     onDirectionsLongPressed: () -> Boolean, | ||||
|     inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>, | ||||
|     resultLauncher: ActivityResultLauncher<Intent>, | ||||
|     cameraPickLauncherForResult: ActivityResultLauncher<Intent>, | ||||
|     galleryPickLauncherForResult: ActivityResultLauncher<Intent> | ||||
| ) = adapterDelegateViewBinding<Place, Place, ItemPlaceBinding>({ layoutInflater, parent -> | ||||
|     ItemPlaceBinding.inflate(layoutInflater, parent, false) | ||||
|  | @ -47,7 +47,7 @@ fun placeAdapterDelegate( | |||
|                 onItemClick?.invoke(item) | ||||
|             } | ||||
|         } | ||||
|         nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, resultLauncher) } | ||||
|         nearbyButtonLayout.cameraButton.setOnClickListener { onCameraClicked(item, inAppCameraLocationPermissionLauncher, cameraPickLauncherForResult) } | ||||
|         nearbyButtonLayout.cameraButton.setOnLongClickListener { onCameraLongPressed() } | ||||
| 
 | ||||
|         nearbyButtonLayout.galleryButton.setOnClickListener { onGalleryClicked(item,galleryPickLauncherForResult) } | ||||
|  |  | |||
|  | @ -243,7 +243,9 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
| 
 | ||||
|     private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(), | ||||
|         result -> { | ||||
|             // TODO handle result from controller | ||||
|             controller.handleActivityResultWithCallback(requireActivity(),callbacks -> { | ||||
|                 controller.onPictureReturnedFromCamera(result,requireActivity(),callbacks); | ||||
|             }); | ||||
|         }); | ||||
| 
 | ||||
|     private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult( | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ class PlaceAdapter( | |||
|     commonPlaceClickActions: CommonPlaceClickActions, | ||||
|     inAppCameraLocationPermissionLauncher: ActivityResultLauncher<Array<String>>, | ||||
|     galleryPickLauncherForResult: ActivityResultLauncher<Intent>, | ||||
|     resultLauncherStub: ActivityResultLauncher<Intent> | ||||
|     cameraPickLauncherForResult: ActivityResultLauncher<Intent> | ||||
| ) : BaseDelegateAdapter<Place>( | ||||
|         placeAdapterDelegate( | ||||
|             bookmarkLocationsDao, | ||||
|  | @ -30,7 +30,7 @@ class PlaceAdapter( | |||
|             commonPlaceClickActions.onDirectionsClicked(), | ||||
|             commonPlaceClickActions.onDirectionsLongPressed(), | ||||
|             inAppCameraLocationPermissionLauncher, | ||||
|             resultLauncherStub, | ||||
|             cameraPickLauncherForResult, | ||||
|             galleryPickLauncherForResult | ||||
|         ), | ||||
|         areItemsTheSame = { oldItem, newItem -> oldItem.wikiDataEntityId == newItem.wikiDataEntityId }, | ||||
|  |  | |||
|  | @ -89,7 +89,9 @@ public class SettingsFragment extends PreferenceFragmentCompat { | |||
| 
 | ||||
|     private ActivityResultLauncher<Intent> cameraPickLauncherForResult = registerForActivityResult(new StartActivityForResult(), | ||||
|         result -> { | ||||
|             // TODO handle result from controller | ||||
|             contributionController.handleActivityResultWithCallback(requireActivity(),callbacks -> { | ||||
|                 contributionController.onPictureReturnedFromCamera(result,requireActivity(),callbacks); | ||||
|             }); | ||||
|         }); | ||||
| 
 | ||||
|     private ActivityResultLauncher<String[]> inAppCameraLocationPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 parneet-guraya
						parneet-guraya