mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +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.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
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 timber.log.Timber;
|
||||||
|
|
||||||
|
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
|
||||||
|
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
|
||||||
|
|
||||||
class DirectUpload {
|
class DirectUpload {
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private String desc;
|
private String desc;
|
||||||
|
private ContributionController controller;
|
||||||
|
|
||||||
DirectUpload(String title, String desc) {
|
DirectUpload(String title, String desc) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
|
@ -33,4 +42,35 @@ class DirectUpload {
|
||||||
|
|
||||||
Timber.d("After shared prefs, image title: " + imageTitle + " Image desc: " + imageDesc);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue