mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 06:43:56 +01:00 
			
		
		
		
	Merge remote-tracking branch 'refs/remotes/origin/2.7.x-release'
This commit is contained in:
		
						commit
						a095a4e25b
					
				
					 6 changed files with 57 additions and 45 deletions
				
			
		|  | @ -280,8 +280,11 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment { | |||
| 
 | ||||
|     private Observable<CategoryItem> directCategories() { | ||||
|         String directCategory = directPrefs.getString("Category", ""); | ||||
|         // Strip newlines to prevent blank categories, and to tidy existing categories | ||||
|         directCategory = directCategory.replace("\n", ""); | ||||
| 
 | ||||
|         List<String> categoryList = new ArrayList<>(); | ||||
|         Timber.d("Direct category found: " + directCategory); | ||||
|         Timber.d("Direct category found: " + "'" + directCategory + "'"); | ||||
| 
 | ||||
|         if (!directCategory.equals("")) { | ||||
|             hasDirectCategories = true; | ||||
|  |  | |||
|  | @ -8,6 +8,7 @@ import android.support.v7.app.AlertDialog; | |||
| 
 | ||||
| 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; | ||||
|  | @ -23,46 +24,25 @@ class DirectUpload { | |||
|         this.controller = controller; | ||||
|     } | ||||
| 
 | ||||
|     void initiateCameraUpload() { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|             if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != 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(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     // These permission requests will be handled by the Fragments. | ||||
|     // Do not use requestCode 1 as it will conflict with NearbyActivity's requestCodes | ||||
|     void initiateGalleryUpload() { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|             if (ContextCompat.checkSelfPermission(fragment.getActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { | ||||
|                 if (fragment.getActivity().shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) { | ||||
|                 if (fragment.shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) { | ||||
|                     new AlertDialog.Builder(fragment.getActivity()) | ||||
|                             .setMessage(fragment.getActivity().getString(R.string.read_storage_permission_rationale)) | ||||
|                             .setPositiveButton("OK", (dialog, which) -> { | ||||
|                                 fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1); | ||||
|                                 Timber.d("Requesting permissions for read external storage"); | ||||
|                                 fragment.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 4); | ||||
|                                 dialog.dismiss(); | ||||
|                             }) | ||||
|                             .setNegativeButton("Cancel", null) | ||||
|                             .create() | ||||
|                             .show(); | ||||
|                 } else { | ||||
|                     fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, | ||||
|                             1); | ||||
|                     fragment.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, | ||||
|                             4); | ||||
|                 } | ||||
|             } else { | ||||
|                 controller.startGalleryPick(); | ||||
|  | @ -72,4 +52,28 @@ class DirectUpload { | |||
|             controller.startGalleryPick(); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     void initiateCameraUpload() { | ||||
|         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | ||||
|             if (ContextCompat.checkSelfPermission(fragment.getActivity(), WRITE_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { | ||||
|                 if (fragment.shouldShowRequestPermissionRationale(WRITE_EXTERNAL_STORAGE)) { | ||||
|                     new AlertDialog.Builder(fragment.getActivity()) | ||||
|                             .setMessage(fragment.getActivity().getString(R.string.write_storage_permission_rationale)) | ||||
|                             .setPositiveButton("OK", (dialog, which) -> { | ||||
|                                 fragment.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 5); | ||||
|                                 dialog.dismiss(); | ||||
|                             }) | ||||
|                             .setNegativeButton("Cancel", null) | ||||
|                             .create() | ||||
|                             .show(); | ||||
|                 } else { | ||||
|                     fragment.requestPermissions(new String[]{WRITE_EXTERNAL_STORAGE}, 5); | ||||
|                 } | ||||
|             } else { | ||||
|                 controller.startCameraCapture(); | ||||
|             } | ||||
|         } else { | ||||
|             controller.startCameraCapture(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -165,6 +165,11 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp | |||
|                     showLocationPermissionDeniedErrorDialog(); | ||||
|                 } | ||||
|             } | ||||
|             break; | ||||
| 
 | ||||
|             default: | ||||
|                 // This is needed to allow the request codes from the Fragments to be routed appropriately | ||||
|                 super.onRequestPermissionsResult(requestCode, permissions, grantResults); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -106,8 +106,8 @@ public class NearbyListFragment extends DaggerFragment { | |||
|         Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults); | ||||
| 
 | ||||
|         switch (requestCode) { | ||||
|             // 1 = "Read external storage" allowed when gallery selected | ||||
|             case 1: { | ||||
|             // 4 = "Read external storage" allowed when gallery selected | ||||
|             case 4: { | ||||
|                 if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) { | ||||
|                     Timber.d("Call controller.startGalleryPick()"); | ||||
|                     controller.startGalleryPick(); | ||||
|  | @ -115,8 +115,8 @@ public class NearbyListFragment extends DaggerFragment { | |||
|             } | ||||
|             break; | ||||
| 
 | ||||
|             // 3 = "Write external storage" allowed when camera selected | ||||
|             case 3: { | ||||
|             // 5 = "Write external storage" allowed when camera selected | ||||
|             case 5: { | ||||
|                 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||||
|                     Timber.d("Call controller.startCameraCapture()"); | ||||
|                     controller.startCameraCapture(); | ||||
|  |  | |||
|  | @ -99,6 +99,7 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|     private Animation fab_open; | ||||
|     private Animation rotate_forward; | ||||
|     private ContributionController controller; | ||||
|     private DirectUpload directUpload; | ||||
| 
 | ||||
|     private Place place; | ||||
|     private Marker selected; | ||||
|  | @ -123,6 +124,10 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|     @Override | ||||
|     public void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
| 
 | ||||
|         controller = new ContributionController(this); | ||||
|         directUpload = new DirectUpload(this, controller); | ||||
| 
 | ||||
|         Bundle bundle = this.getArguments(); | ||||
|         Gson gson = new GsonBuilder() | ||||
|                 .registerTypeAdapter(Uri.class, new UriDeserializer()) | ||||
|  | @ -681,9 +686,6 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|         fabCamera.setOnClickListener(view -> { | ||||
|             if (fabCamera.isShown()) { | ||||
|                 Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); | ||||
|                 controller = new ContributionController(this); | ||||
| 
 | ||||
|                 DirectUpload directUpload = new DirectUpload(this, controller); | ||||
|                 storeSharedPrefs(); | ||||
|                 directUpload.initiateCameraUpload(); | ||||
|             } | ||||
|  | @ -692,9 +694,6 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|         fabGallery.setOnClickListener(view -> { | ||||
|             if (fabGallery.isShown()) { | ||||
|                 Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); | ||||
|                 controller = new ContributionController(this); | ||||
| 
 | ||||
|                 DirectUpload directUpload = new DirectUpload(this, controller); | ||||
|                 storeSharedPrefs(); | ||||
|                 directUpload.initiateGalleryUpload(); | ||||
|             } | ||||
|  | @ -713,9 +712,10 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|     public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { | ||||
|         Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults); | ||||
| 
 | ||||
|         // Do not use requestCode 1 as it will conflict with NearbyActivity's requestCodes | ||||
|         switch (requestCode) { | ||||
|             // 1 = "Read external storage" allowed when gallery selected | ||||
|             case 1: { | ||||
|             // 4 = "Read external storage" allowed when gallery selected | ||||
|             case 4: { | ||||
|                 if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) { | ||||
|                     Timber.d("Call controller.startGalleryPick()"); | ||||
|                     controller.startGalleryPick(); | ||||
|  | @ -723,8 +723,8 @@ public class NearbyMapFragment extends DaggerFragment { | |||
|             } | ||||
|             break; | ||||
| 
 | ||||
|             // 3 = "Write external storage" allowed when camera selected | ||||
|             case 3: { | ||||
|             // 5 = "Write external storage" allowed when camera selected | ||||
|             case 5: { | ||||
|                 if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | ||||
|                     Timber.d("Call controller.startCameraCapture()"); | ||||
|                     controller.startCameraCapture(); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 misaochan
						misaochan