Merge remote-tracking branch 'refs/remotes/commons-app/2.7.x-release' into 2.7.x-release-fork

This commit is contained in:
misaochan 2018-04-06 00:14:35 +10:00
commit 45512e7426
6 changed files with 57 additions and 45 deletions

View file

@ -280,8 +280,11 @@ public class CategorizationFragment extends CommonsDaggerSupportFragment {
private Observable<CategoryItem> directCategories() { private Observable<CategoryItem> directCategories() {
String directCategory = directPrefs.getString("Category", ""); 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<>(); List<String> categoryList = new ArrayList<>();
Timber.d("Direct category found: " + directCategory); Timber.d("Direct category found: " + "'" + directCategory + "'");
if (!directCategory.equals("")) { if (!directCategory.equals("")) {
hasDirectCategories = true; hasDirectCategories = true;

View file

@ -8,6 +8,7 @@ import android.support.v7.app.AlertDialog;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.contributions.ContributionController;
import timber.log.Timber;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE; import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE; import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
@ -23,46 +24,25 @@ class DirectUpload {
this.controller = controller; this.controller = controller;
} }
void initiateCameraUpload() { // These permission requests will be handled by the Fragments.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Do not use requestCode 1 as it will conflict with NearbyActivity's requestCodes
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();
}
}
void initiateGalleryUpload() { void initiateGalleryUpload() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(fragment.getActivity(), READ_EXTERNAL_STORAGE) != PERMISSION_GRANTED) { 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()) new AlertDialog.Builder(fragment.getActivity())
.setMessage(fragment.getActivity().getString(R.string.read_storage_permission_rationale)) .setMessage(fragment.getActivity().getString(R.string.read_storage_permission_rationale))
.setPositiveButton("OK", (dialog, which) -> { .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(); dialog.dismiss();
}) })
.setNegativeButton("Cancel", null) .setNegativeButton("Cancel", null)
.create() .create()
.show(); .show();
} else { } else {
fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE}, fragment.requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
1); 4);
} }
} else { } else {
controller.startGalleryPick(); controller.startGalleryPick();
@ -72,4 +52,28 @@ class DirectUpload {
controller.startGalleryPick(); 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();
}
}
} }

View file

@ -165,6 +165,11 @@ public class NearbyActivity extends NavigationBaseActivity implements LocationUp
showLocationPermissionDeniedErrorDialog(); showLocationPermissionDeniedErrorDialog();
} }
} }
break;
default:
// This is needed to allow the request codes from the Fragments to be routed appropriately
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
} }
} }

View file

@ -106,8 +106,8 @@ public class NearbyListFragment extends DaggerFragment {
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults); Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults);
switch (requestCode) { switch (requestCode) {
// 1 = "Read external storage" allowed when gallery selected // 4 = "Read external storage" allowed when gallery selected
case 1: { case 4: {
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
Timber.d("Call controller.startGalleryPick()"); Timber.d("Call controller.startGalleryPick()");
controller.startGalleryPick(); controller.startGalleryPick();
@ -115,8 +115,8 @@ public class NearbyListFragment extends DaggerFragment {
} }
break; break;
// 3 = "Write external storage" allowed when camera selected // 5 = "Write external storage" allowed when camera selected
case 3: { case 5: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Call controller.startCameraCapture()"); Timber.d("Call controller.startCameraCapture()");
controller.startCameraCapture(); controller.startCameraCapture();

View file

@ -98,6 +98,7 @@ public class NearbyMapFragment extends DaggerFragment {
private Animation fab_open; private Animation fab_open;
private Animation rotate_forward; private Animation rotate_forward;
private ContributionController controller; private ContributionController controller;
private DirectUpload directUpload;
private Place place; private Place place;
private Marker selected; private Marker selected;
@ -122,6 +123,10 @@ public class NearbyMapFragment extends DaggerFragment {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
controller = new ContributionController(this);
directUpload = new DirectUpload(this, controller);
Bundle bundle = this.getArguments(); Bundle bundle = this.getArguments();
Gson gson = new GsonBuilder() Gson gson = new GsonBuilder()
.registerTypeAdapter(Uri.class, new UriDeserializer()) .registerTypeAdapter(Uri.class, new UriDeserializer())
@ -680,9 +685,6 @@ public class NearbyMapFragment extends DaggerFragment {
fabCamera.setOnClickListener(view -> { fabCamera.setOnClickListener(view -> {
if (fabCamera.isShown()) { if (fabCamera.isShown()) {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller);
storeSharedPrefs(); storeSharedPrefs();
directUpload.initiateCameraUpload(); directUpload.initiateCameraUpload();
} }
@ -691,9 +693,6 @@ public class NearbyMapFragment extends DaggerFragment {
fabGallery.setOnClickListener(view -> { fabGallery.setOnClickListener(view -> {
if (fabGallery.isShown()) { if (fabGallery.isShown()) {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller);
storeSharedPrefs(); storeSharedPrefs();
directUpload.initiateGalleryUpload(); directUpload.initiateGalleryUpload();
} }
@ -712,9 +711,10 @@ public class NearbyMapFragment extends DaggerFragment {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + 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) { switch (requestCode) {
// 1 = "Read external storage" allowed when gallery selected // 4 = "Read external storage" allowed when gallery selected
case 1: { case 4: {
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
Timber.d("Call controller.startGalleryPick()"); Timber.d("Call controller.startGalleryPick()");
controller.startGalleryPick(); controller.startGalleryPick();
@ -722,8 +722,8 @@ public class NearbyMapFragment extends DaggerFragment {
} }
break; break;
// 3 = "Write external storage" allowed when camera selected // 5 = "Write external storage" allowed when camera selected
case 3: { case 5: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Call controller.startCameraCapture()"); Timber.d("Call controller.startCameraCapture()");
controller.startCameraCapture(); controller.startCameraCapture();

View file

@ -154,8 +154,8 @@
<string name="detail_description_empty">No description</string> <string name="detail_description_empty">No description</string>
<string name="detail_license_empty">Unknown license</string> <string name="detail_license_empty">Unknown license</string>
<string name="menu_refresh">Refresh</string> <string name="menu_refresh">Refresh</string>
<string name="read_storage_permission_rationale">Required permission: Read external storage. App cannot function without this.</string> <string name="read_storage_permission_rationale">Required permission: Read external storage. App cannot access your gallery without this.</string>
<string name="write_storage_permission_rationale">Required permission: Write external storage. App cannot function without this.</string> <string name="write_storage_permission_rationale">Required permission: Write external storage. App cannot access your camera without this.</string>
<string name="location_permission_rationale">Optional permission: Get current location for category suggestions</string> <string name="location_permission_rationale">Optional permission: Get current location for category suggestions</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="title_activity_nearby">Nearby Places</string> <string name="title_activity_nearby">Nearby Places</string>