mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	remove old method of refactoring for file picker
Signed-off-by: parneet-guraya <gurayaparneet@gmail.com>
This commit is contained in:
		
							parent
							
								
									a28d32b7ee
								
							
						
					
					
						commit
						d11f2dd06b
					
				
					 4 changed files with 35 additions and 110 deletions
				
			
		|  | @ -307,29 +307,6 @@ public class ContributionController { | |||
|                 activity.startActivity(intent); | ||||
|             } | ||||
|         }); | ||||
| 
 | ||||
| //        FilePicker.handleActivityResult(requestCode, resultCode, data, activity, | ||||
| //            new DefaultCallback() { | ||||
| // | ||||
| //                @Override | ||||
| //                public void onCanceled(final ImageSource source, final int type) { | ||||
| //                    super.onCanceled(source, type); | ||||
| //                    defaultKvStore.remove(PLACE_OBJECT); | ||||
| //                } | ||||
| // | ||||
| //                @Override | ||||
| //                public void onImagePickerError(Exception e, FilePicker.ImageSource source, | ||||
| //                    int type) { | ||||
| //                    ViewUtil.showShortToast(activity, R.string.error_occurred_in_picking_images); | ||||
| //                } | ||||
| // | ||||
| //                @Override | ||||
| //                public void onImagesPicked(@NonNull List<UploadableFile> imagesFiles, | ||||
| //                    FilePicker.ImageSource source, int type) { | ||||
| //                    Intent intent = handleImagesPicked(activity, imagesFiles); | ||||
| //                    activity.startActivity(intent); | ||||
| //                } | ||||
| //            }); | ||||
|     } | ||||
| 
 | ||||
|     public List<UploadableFile> handleExternalImagesPicked(Activity activity, | ||||
|  |  | |||
|  | @ -9,13 +9,6 @@ public interface Constants { | |||
|     interface RequestCodes { | ||||
|         int LOCATION = 1; | ||||
|         int STORAGE = 2; | ||||
|         int FILE_PICKER_IMAGE_IDENTIFICATOR = 0b1101101100; //876 | ||||
|         int SOURCE_CHOOSER = 1 << 15; | ||||
| 
 | ||||
|         int PICK_PICTURE_FROM_CUSTOM_SELECTOR = FILE_PICKER_IMAGE_IDENTIFICATOR + (1 << 10); | ||||
|         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 RECEIVE_DATA_FROM_FULL_SCREEN_MODE = 1 << 9; | ||||
|     } | ||||
|  |  | |||
|  | @ -111,13 +111,6 @@ public class FilePicker implements Constants { | |||
|      */ | ||||
|     public static void openGallery(Activity activity,ActivityResultLauncher<Intent> resultLauncher,int type, boolean openDocumentIntentPreferred) { | ||||
|         Intent intent = createGalleryIntent(activity, type, openDocumentIntentPreferred); | ||||
| //        int requestCode = RequestCodes.PICK_PICTURE_FROM_GALLERY; | ||||
| // | ||||
| //            if(openDocumentIntentPreferred){ | ||||
| //                requestCode = RequestCodes.PICK_PICTURE_FROM_DOCUMENTS; | ||||
| //            } | ||||
| // | ||||
| //        activity.startActivityForResult(intent, requestCode); | ||||
|         resultLauncher.launch(intent); | ||||
|     } | ||||
| 
 | ||||
|  | @ -126,7 +119,6 @@ public class FilePicker implements Constants { | |||
|      */ | ||||
|     public static void openCustomSelector(Activity activity,ActivityResultLauncher<Intent> resultLauncher,int type) { | ||||
|         Intent intent = createCustomSelectorIntent(activity, type); | ||||
| //        activity.startActivityForResult(intent, RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR); | ||||
|         resultLauncher.launch(intent); | ||||
|     } | ||||
| 
 | ||||
|  | @ -135,7 +127,6 @@ public class FilePicker implements Constants { | |||
|      */ | ||||
|     public static void openCameraForImage(Activity activity, ActivityResultLauncher<Intent> resultLauncher, int type) { | ||||
|         Intent intent = createCameraForImageIntent(activity, type); | ||||
| //        activity.startActivityForResult(intent, RequestCodes.TAKE_PICTURE); | ||||
|         resultLauncher.launch(intent); | ||||
|     } | ||||
| 
 | ||||
|  | @ -159,43 +150,6 @@ public class FilePicker implements Constants { | |||
|         } | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Any activity can use this method to attach their callback to the file picker | ||||
|      */ | ||||
|     public static void handleActivityResult(int requestCode, int resultCode, Intent data, Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         boolean isHandledPickedFile = (requestCode & RequestCodes.FILE_PICKER_IMAGE_IDENTIFICATOR) > 0; | ||||
|         if (isHandledPickedFile) { | ||||
|             requestCode &= ~RequestCodes.SOURCE_CHOOSER; | ||||
|             if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY || | ||||
|                     requestCode == RequestCodes.TAKE_PICTURE || | ||||
|                     requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS || | ||||
|                     requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) { | ||||
|                 if (resultCode == Activity.RESULT_OK) { | ||||
|                     if (requestCode == RequestCodes.PICK_PICTURE_FROM_DOCUMENTS && !isPhoto(data)) { | ||||
| //                        onPictureReturnedFromDocuments(data, activity, callbacks); | ||||
|                     } else if (requestCode == RequestCodes.PICK_PICTURE_FROM_GALLERY && !isPhoto(data)) { | ||||
| //                        onPictureReturnedFromGallery(data, activity, callbacks); | ||||
|                     } else if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR) { | ||||
| //                        onPictureReturnedFromCustomSelector(data, activity, callbacks); | ||||
|                     } else if (requestCode == RequestCodes.TAKE_PICTURE) { | ||||
| //                        onPictureReturnedFromCamera(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 if (requestCode == RequestCodes.PICK_PICTURE_FROM_CUSTOM_SELECTOR){ | ||||
|                         callbacks.onCanceled(ImageSource.CUSTOM_SELECTOR, restoreType(activity)); | ||||
|                     } | ||||
|                     else { | ||||
|                         callbacks.onCanceled(FilePicker.ImageSource.CAMERA_IMAGE, restoreType(activity)); | ||||
|                     } | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     public static List<UploadableFile> handleExternalImagesPicked(Intent data, Activity activity) { | ||||
|         try { | ||||
|             return getFilesFromGalleryPictures(data, activity); | ||||
|  | @ -249,7 +203,7 @@ public class FilePicker implements Constants { | |||
|     } | ||||
| 
 | ||||
|     public static void onPictureReturnedFromDocuments(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         if(result.getResultCode() == Activity.RESULT_OK){ | ||||
|         if(result.getResultCode() == Activity.RESULT_OK && !isPhoto(result.getData())){ | ||||
|             try { | ||||
|                 Uri photoPath = result.getData().getData(); | ||||
|                 UploadableFile photoFile = PickedFiles.pickedExistingPicture(activity, photoPath); | ||||
|  | @ -306,7 +260,7 @@ public class FilePicker implements Constants { | |||
|     } | ||||
| 
 | ||||
|     public static void onPictureReturnedFromGallery(ActivityResult result, Activity activity, @NonNull FilePicker.Callbacks callbacks) { | ||||
|         if(result.getResultCode() == Activity.RESULT_OK){ | ||||
|         if(result.getResultCode() == Activity.RESULT_OK && !isPhoto(result.getData())){ | ||||
|             try { | ||||
|                 List<UploadableFile> files = getFilesFromGalleryPictures(result.getData(), activity); | ||||
|                 callbacks.onImagesPicked(files, FilePicker.ImageSource.GALLERY, restoreType(activity)); | ||||
|  |  | |||
|  | @ -183,38 +183,39 @@ class FilePickerTest { | |||
|         method.invoke(mockFilePicker, mockIntent) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testHandleActivityResultCaseOne() { | ||||
|         val mockIntent = mock(Intent::class.java) | ||||
|         FilePicker.handleActivityResult( | ||||
|             RequestCodes.FILE_PICKER_IMAGE_IDENTIFICATOR, | ||||
|             Activity.RESULT_OK, | ||||
|             mockIntent, | ||||
|             activity, | ||||
|             object : DefaultCallback() { | ||||
|                 override fun onCanceled( | ||||
|                     source: FilePicker.ImageSource, | ||||
|                     type: Int, | ||||
|                 ) { | ||||
|                     super.onCanceled(source, type) | ||||
|                 } | ||||
| 
 | ||||
|                 override fun onImagePickerError( | ||||
|                     e: Exception, | ||||
|                     source: FilePicker.ImageSource, | ||||
|                     type: Int, | ||||
|                 ) { | ||||
|                 } | ||||
| 
 | ||||
|                 override fun onImagesPicked( | ||||
|                     imagesFiles: List<UploadableFile>, | ||||
|                     source: FilePicker.ImageSource, | ||||
|                     type: Int, | ||||
|                 ) { | ||||
|                 } | ||||
|             }, | ||||
|         ) | ||||
|     } | ||||
|     //TODO [Parry] adapt tests | ||||
| //    @Test | ||||
| //    fun testHandleActivityResultCaseOne() { | ||||
| //        val mockIntent = mock(Intent::class.java) | ||||
| //        FilePicker.handleActivityResult( | ||||
| //            RequestCodes.FILE_PICKER_IMAGE_IDENTIFICATOR, | ||||
| //            Activity.RESULT_OK, | ||||
| //            mockIntent, | ||||
| //            activity, | ||||
| //            object : DefaultCallback() { | ||||
| //                override fun onCanceled( | ||||
| //                    source: FilePicker.ImageSource, | ||||
| //                    type: Int, | ||||
| //                ) { | ||||
| //                    super.onCanceled(source, type) | ||||
| //                } | ||||
| // | ||||
| //                override fun onImagePickerError( | ||||
| //                    e: Exception, | ||||
| //                    source: FilePicker.ImageSource, | ||||
| //                    type: Int, | ||||
| //                ) { | ||||
| //                } | ||||
| // | ||||
| //                override fun onImagesPicked( | ||||
| //                    imagesFiles: List<UploadableFile>, | ||||
| //                    source: FilePicker.ImageSource, | ||||
| //                    type: Int, | ||||
| //                ) { | ||||
| //                } | ||||
| //            }, | ||||
| //        ) | ||||
| //    } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testOpenCustomSelectorRequestCode() { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 parneet-guraya
						parneet-guraya