mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Copy camera capture code to DirectUpload.java
This commit is contained in:
		
							parent
							
								
									405c163e60
								
							
						
					
					
						commit
						f38d885a78
					
				
					 1 changed files with 32 additions and 0 deletions
				
			
		|  | @ -11,11 +11,15 @@ import android.support.v4.app.Fragment; | |||
| import android.support.v4.content.ContextCompat; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| 
 | ||||
| import javax.inject.Inject; | ||||
| import javax.inject.Named; | ||||
| 
 | ||||
| import fr.free.nrw.commons.R; | ||||
| import fr.free.nrw.commons.contributions.ContributionController; | ||||
| import timber.log.Timber; | ||||
| 
 | ||||
| import static android.Manifest.permission.READ_EXTERNAL_STORAGE; | ||||
| import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; | ||||
| import static android.content.pm.PackageManager.PERMISSION_GRANTED; | ||||
| 
 | ||||
| class DirectUpload { | ||||
|  | @ -25,6 +29,9 @@ class DirectUpload { | |||
|     private ContributionController controller; | ||||
|     private Fragment fragment; | ||||
| 
 | ||||
|     @Inject @Named("prefs") SharedPreferences prefs; | ||||
|     @Inject @Named("default_preferences") SharedPreferences defaultPrefs; | ||||
| 
 | ||||
|     DirectUpload(String title, String desc, Fragment fragment, ContributionController controller) { | ||||
|         this.title = title; | ||||
|         this.desc = desc; | ||||
|  | @ -41,6 +48,31 @@ class DirectUpload { | |||
|         editor.apply(); | ||||
|     } | ||||
| 
 | ||||
|     void initiateCameraUpload() { | ||||
|         boolean useExtStorage = defaultPrefs.getBoolean("useExternalStorage", true); | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && useExtStorage) { | ||||
|             if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | ||||
|                 if (fragment.getActivity().shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) { | ||||
|                     new AlertDialog.Builder(fragment.getActivity()) | ||||
|                             .setMessage(fragment.getActivity().getString(R.string.write_storage_permission_rationale)) | ||||
|                             .setPositiveButton("OK", (dialog, which) -> { | ||||
|                                 fragment.getActivity().requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 3); | ||||
|                                 dialog.dismiss(); | ||||
|                             }) | ||||
|                             .setNegativeButton("Cancel", null) | ||||
|                             .create() | ||||
|                             .show(); | ||||
|                 } else { | ||||
|                     fragment.getActivity().requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 3); | ||||
|                 } | ||||
|             } else { | ||||
|                 controller.startCameraCapture(); | ||||
|             } | ||||
|         } else { | ||||
|             controller.startCameraCapture(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void initiateGalleryUpload() { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|             if (ContextCompat.checkSelfPermission(fragment.getActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 misaochan
						misaochan