diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java index 5b84a43db..ce9701731 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/ContributionController.java @@ -77,10 +77,11 @@ public class ContributionController { //FIXME: Starts gallery (opens Google Photos) Intent pickImageIntent = new Intent(ACTION_GET_CONTENT); pickImageIntent.setType("image/*"); + Timber.d("startGalleryPick() called with pickImageIntent"); fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY); } - void handleImagePicked(int requestCode, Intent data) { + public void handleImagePicked(int requestCode, Intent data) { FragmentActivity activity = fragment.getActivity(); Intent shareIntent = new Intent(activity, ShareActivity.class); shareIntent.setAction(ACTION_SEND); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/DirectUpload.java b/app/src/main/java/fr/free/nrw/commons/nearby/DirectUpload.java index 71f9e839e..5f8a59056 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/DirectUpload.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/DirectUpload.java @@ -25,11 +25,11 @@ class DirectUpload { private ContributionController controller; private Fragment fragment; - DirectUpload(String title, String desc, Fragment fragment) { + DirectUpload(String title, String desc, Fragment fragment, ContributionController controller) { this.title = title; this.desc = desc; this.fragment = fragment; - controller = new ContributionController(fragment); + this.controller = controller; } void storeSharedPrefs() { @@ -74,6 +74,6 @@ class DirectUpload { } } - +//TODO: Need to call onActivityResult() to handle the image picked //TODO: Handle onRequestPermissionsResult } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index 5d1ac5cbb..7618b7a3b 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -41,9 +41,12 @@ import java.util.ArrayList; import java.util.List; import fr.free.nrw.commons.R; +import fr.free.nrw.commons.contributions.ContributionController; import fr.free.nrw.commons.utils.UriDeserializer; import timber.log.Timber; +import static android.app.Activity.RESULT_OK; + public class NearbyMapFragment extends android.support.v4.app.Fragment { private MapView mapView; @@ -77,6 +80,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { private Animation fab_close; private Animation fab_open; private Animation rotate_forward; + private ContributionController controller; private Place place; @@ -390,12 +394,28 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment { fabGallery.setOnClickListener(view -> { Timber.d("Image title: " + place.getName() + "Image desc: " + place.getLongDescription()); - DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this); + controller = new ContributionController(this); + DirectUpload directUpload = new DirectUpload(place.getName(), place.getLongDescription(), this, controller); directUpload.storeSharedPrefs(); directUpload.initiateGalleryUpload(); }); } + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + //FIXME: must get the file data for Google Photos when receive the intent answer, in the onActivityResult method + super.onActivityResult(requestCode, resultCode, data); + + if (resultCode == RESULT_OK) { + Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s", + requestCode, resultCode, data); + controller.handleImagePicked(requestCode, data); + } else { + Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s", + requestCode, resultCode, data); + } + } + private void openWebView(Uri link) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, link); startActivity(browserIntent);