mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Merge pull request #773 from tised/#657_issue
improvements for #657 issue
This commit is contained in:
		
						commit
						350f9bb697
					
				
					 2 changed files with 90 additions and 9 deletions
				
			
		|  | @ -1,8 +1,8 @@ | |||
| package fr.free.nrw.commons.contributions; | ||||
| 
 | ||||
| import android.Manifest; | ||||
| import android.content.ActivityNotFoundException; | ||||
| import android.content.Context; | ||||
| import android.content.DialogInterface; | ||||
| import android.content.Intent; | ||||
| import android.content.SharedPreferences; | ||||
| import android.content.pm.PackageManager; | ||||
|  | @ -10,6 +10,7 @@ import android.os.Build; | |||
| import android.os.Bundle; | ||||
| import android.support.v4.app.Fragment; | ||||
| import android.support.v4.content.ContextCompat; | ||||
| import android.support.v7.app.AlertDialog; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuInflater; | ||||
|  | @ -106,19 +107,57 @@ public class ContributionsListFragment extends Fragment { | |||
|             case R.id.menu_from_gallery: | ||||
|                 //Gallery crashes before reach ShareActivity screen so must implement permissions check here | ||||
|                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|                     if (ContextCompat.checkSelfPermission(this.getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { | ||||
|                         //See http://stackoverflow.com/questions/33169455/onrequestpermissionsresult-not-being-called-in-dialog-fragment | ||||
|                         requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1); | ||||
|                         return true; | ||||
| 
 | ||||
|                     // Here, thisActivity is the current activity | ||||
|                     if (ContextCompat.checkSelfPermission(getActivity(), | ||||
|                             Manifest.permission.READ_EXTERNAL_STORAGE) | ||||
|                             != PackageManager.PERMISSION_GRANTED) { | ||||
| 
 | ||||
|                         // Should we show an explanation? | ||||
|                         if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) { | ||||
| 
 | ||||
|                             // Show an explanation to the user *asynchronously* -- don't block | ||||
|                             // this thread waiting for the user's response! After the user | ||||
|                             // sees the explanation, try again to request the permission. | ||||
| 
 | ||||
|                             new AlertDialog.Builder(getActivity()) | ||||
|                                     .setMessage(getString(R.string.storage_permission_rationale)) | ||||
|                                     .setPositiveButton("OK", new DialogInterface.OnClickListener() { | ||||
|                                         @Override | ||||
|                                         public void onClick(DialogInterface dialog, int which) { | ||||
| 
 | ||||
|                                             requestPermissions( | ||||
|                                                     new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, | ||||
|                                                     1); | ||||
|                                             dialog.dismiss(); | ||||
|                                         } | ||||
|                                     }) | ||||
|                                     .setNegativeButton("Cancel", null) | ||||
|                                     .create() | ||||
|                                     .show(); | ||||
| 
 | ||||
|                         } else { | ||||
| 
 | ||||
|                             // No explanation needed, we can request the permission. | ||||
| 
 | ||||
|                             requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, | ||||
|                                     1); | ||||
| 
 | ||||
|                             // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an | ||||
|                             // app-defined int constant. The callback method gets the | ||||
|                             // result of the request. | ||||
|                         } | ||||
|                     } else { | ||||
|                         controller.startGalleryPick(); | ||||
|                         return true; | ||||
|                     } | ||||
|                 } | ||||
|                 else { | ||||
| 
 | ||||
|                 } else { | ||||
|                     controller.startGalleryPick(); | ||||
|                     return true; | ||||
|                 } | ||||
| 
 | ||||
|                 return true; | ||||
|             case R.id.menu_from_camera: | ||||
|                 controller.startCameraCapture(); | ||||
|                 return true; | ||||
|  | @ -129,6 +168,9 @@ public class ContributionsListFragment extends Fragment { | |||
| 
 | ||||
|     @Override | ||||
|     public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||||
| 
 | ||||
|         Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults); | ||||
| 
 | ||||
|         switch (requestCode) { | ||||
|             // 1 = Storage allowed when gallery selected | ||||
|             case 1: { | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Josephine Lim
						Josephine Lim