mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Merge branch 'commons-app:main' into replace-assert-usages
This commit is contained in:
		
						commit
						06f27ef80e
					
				
					 4 changed files with 19 additions and 39 deletions
				
			
		|  | @ -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; | ||||
|     } | ||||
|  |  | |||
|  | @ -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)); | ||||
|                     } | ||||
|                 } | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ WHERE { | |||
|   } | ||||
| 
 | ||||
|   # Get the label in the preferred language of the user, or any other language if no label is available in that language. | ||||
|   OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "en")} | ||||
|   OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")} | ||||
|   OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage} | ||||
|   BIND(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage, "?") as ?label) | ||||
| 
 | ||||
|  |  | |||
|  | @ -64,13 +64,18 @@ class FilePickerTest { | |||
|         `when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref) | ||||
|         `when`(sharedPref.edit()).thenReturn(sharedPreferencesEditor) | ||||
|         `when`(sharedPref.edit().putInt("type", 0)).thenReturn(sharedPreferencesEditor) | ||||
|         FilePicker.openGallery(activity, 0, nextBoolean()) | ||||
|         val openDocumentPreferred = nextBoolean() | ||||
|         FilePicker.openGallery(activity, 0, openDocumentPreferred) | ||||
|         verify(activity).startActivityForResult( | ||||
|             ArgumentMatchers.any(), | ||||
|             requestCodeCaptor?.capture()?.toInt()!!, | ||||
|         ) | ||||
|         if(openDocumentPreferred){ | ||||
|             assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_DOCUMENTS) | ||||
|         }else{ | ||||
|             assertEquals(requestCodeCaptor?.value, RequestCodes.PICK_PICTURE_FROM_GALLERY) | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testOpenCameraForImageCode() { | ||||
|  | @ -165,32 +170,6 @@ class FilePickerTest { | |||
|         method.invoke(mockFilePicker, activity) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testTakenCameraVideo() { | ||||
|         val mockFilePicker = mock(FilePicker::class.java) | ||||
|         val method: Method = | ||||
|             FilePicker::class.java.getDeclaredMethod( | ||||
|                 "takenCameraVideo", | ||||
|                 Context::class.java, | ||||
|             ) | ||||
|         method.isAccessible = true | ||||
|         method.invoke(mockFilePicker, context) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testTakenCameraVideoCaseTrue() { | ||||
|         val mockFilePicker = mock(FilePicker::class.java) | ||||
|         `when`(PreferenceManager.getDefaultSharedPreferences(activity)).thenReturn(sharedPref) | ||||
|         `when`(sharedPref.getString("last_video", null)).thenReturn("") | ||||
|         val method: Method = | ||||
|             FilePicker::class.java.getDeclaredMethod( | ||||
|                 "takenCameraVideo", | ||||
|                 Context::class.java, | ||||
|             ) | ||||
|         method.isAccessible = true | ||||
|         method.invoke(mockFilePicker, activity) | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     fun testIsPhoto() { | ||||
|         val mockFilePicker = mock(FilePicker::class.java) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andrew Gardner
						Andrew Gardner