mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-11-04 08:43:52 +01:00 
			
		
		
		
	Create initiateUpload() method
This commit is contained in:
		
							parent
							
								
									a78b1f1054
								
							
						
					
					
						commit
						8fe03f1e4e
					
				
					 2 changed files with 41 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -3,13 +3,22 @@ package fr.free.nrw.commons.nearby;
 | 
			
		|||
import android.app.Activity;
 | 
			
		||||
import android.content.Context;
 | 
			
		||||
import android.content.SharedPreferences;
 | 
			
		||||
import android.os.Build;
 | 
			
		||||
import android.support.v4.content.ContextCompat;
 | 
			
		||||
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.content.pm.PackageManager.PERMISSION_GRANTED;
 | 
			
		||||
 | 
			
		||||
class DirectUpload {
 | 
			
		||||
 | 
			
		||||
    private String title;
 | 
			
		||||
    private String desc;
 | 
			
		||||
    private ContributionController controller;
 | 
			
		||||
 | 
			
		||||
    DirectUpload(String title, String desc) {
 | 
			
		||||
        this.title = title;
 | 
			
		||||
| 
						 | 
				
			
			@ -33,4 +42,35 @@ class DirectUpload {
 | 
			
		|||
 | 
			
		||||
        Timber.d("After shared prefs, image title: " + imageTitle + " Image desc: " + imageDesc);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void initiateUpload(Context context) {
 | 
			
		||||
        Activity activity = (Activity) context;
 | 
			
		||||
 | 
			
		||||
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
 | 
			
		||||
            if (ContextCompat.checkSelfPermission(activity, READ_EXTERNAL_STORAGE)
 | 
			
		||||
                    != PERMISSION_GRANTED) {
 | 
			
		||||
                if (activity.shouldShowRequestPermissionRationale(READ_EXTERNAL_STORAGE)) {
 | 
			
		||||
                    new AlertDialog.Builder(activity)
 | 
			
		||||
                            .setMessage(activity.getString(R.string.read_storage_permission_rationale))
 | 
			
		||||
                            .setPositiveButton("OK", (dialog, which) -> {
 | 
			
		||||
                                activity.requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, 1);
 | 
			
		||||
                                dialog.dismiss();
 | 
			
		||||
                            })
 | 
			
		||||
                            .setNegativeButton("Cancel", null)
 | 
			
		||||
                            .create()
 | 
			
		||||
                            .show();
 | 
			
		||||
                } else {
 | 
			
		||||
                    activity.requestPermissions(new String[]{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;
 | 
			
		||||
                }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -403,7 +403,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment {
 | 
			
		|||
 | 
			
		||||
            DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription());
 | 
			
		||||
            directUpload.storeSharedPrefs(getActivity());
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        fabGallery.setOnClickListener(view -> {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue