Fix conflicts

This commit is contained in:
neslihanturan 2018-03-02 02:16:53 +03:00
commit 3fc21de0ab
12 changed files with 238 additions and 45 deletions

View file

@ -25,14 +25,14 @@ import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY; import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE; import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE;
class ContributionController { public class ContributionController {
private static final int SELECT_FROM_GALLERY = 1; private static final int SELECT_FROM_GALLERY = 1;
private static final int SELECT_FROM_CAMERA = 2; private static final int SELECT_FROM_CAMERA = 2;
private Fragment fragment; private Fragment fragment;
ContributionController(Fragment fragment) { public ContributionController(Fragment fragment) {
this.fragment = fragment; this.fragment = fragment;
} }
@ -61,7 +61,7 @@ class ContributionController {
} }
} }
void startCameraCapture() { public void startCameraCapture() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
lastGeneratedCaptureUri = reGenerateImageCaptureUriInCache(); lastGeneratedCaptureUri = reGenerateImageCaptureUriInCache();
@ -70,6 +70,9 @@ class ContributionController {
requestWritePermission(fragment.getContext(), takePictureIntent, lastGeneratedCaptureUri); requestWritePermission(fragment.getContext(), takePictureIntent, lastGeneratedCaptureUri);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureUri); takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureUri);
if (!fragment.isAdded()) {
return;
}
fragment.startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA); fragment.startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA);
} }
@ -77,11 +80,17 @@ class ContributionController {
//FIXME: Starts gallery (opens Google Photos) //FIXME: Starts gallery (opens Google Photos)
Intent pickImageIntent = new Intent(ACTION_GET_CONTENT); Intent pickImageIntent = new Intent(ACTION_GET_CONTENT);
pickImageIntent.setType("image/*"); pickImageIntent.setType("image/*");
Timber.d("startGalleryPick() called with pickImageIntent");
// See https://stackoverflow.com/questions/22366596/android-illegalstateexception-fragment-not-attached-to-activity-webview
if (!fragment.isAdded()) {
return;
}
fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY); fragment.startActivityForResult(pickImageIntent, SELECT_FROM_GALLERY);
} }
void handleImagePicked(int requestCode, Intent data) { public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload) {
FragmentActivity activity = fragment.getActivity(); FragmentActivity activity = fragment.getActivity();
Timber.d("handleImagePicked() called with onActivityResult()");
Intent shareIntent = new Intent(activity, ShareActivity.class); Intent shareIntent = new Intent(activity, ShareActivity.class);
shareIntent.setAction(ACTION_SEND); shareIntent.setAction(ACTION_SEND);
switch (requestCode) { switch (requestCode) {
@ -91,11 +100,17 @@ class ContributionController {
shareIntent.setType(activity.getContentResolver().getType(imageData)); shareIntent.setType(activity.getContentResolver().getType(imageData));
shareIntent.putExtra(EXTRA_STREAM, imageData); shareIntent.putExtra(EXTRA_STREAM, imageData);
shareIntent.putExtra(EXTRA_SOURCE, SOURCE_GALLERY); shareIntent.putExtra(EXTRA_SOURCE, SOURCE_GALLERY);
if (isDirectUpload) {
shareIntent.putExtra("isDirectUpload", true);
}
break; break;
case SELECT_FROM_CAMERA: case SELECT_FROM_CAMERA:
shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type
shareIntent.putExtra(EXTRA_STREAM, lastGeneratedCaptureUri); shareIntent.putExtra(EXTRA_STREAM, lastGeneratedCaptureUri);
shareIntent.putExtra(EXTRA_SOURCE, SOURCE_CAMERA); shareIntent.putExtra(EXTRA_SOURCE, SOURCE_CAMERA);
if (isDirectUpload) {
shareIntent.putExtra("isDirectUpload", true);
}
break; break;
} }
Timber.i("Image selected"); Timber.i("Image selected");

View file

@ -105,7 +105,7 @@ public class ContributionsListFragment extends DaggerFragment {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s", Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data); requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data); controller.handleImagePicked(requestCode, data, false);
} else { } else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s", Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data); requestCode, resultCode, data);

View file

@ -55,6 +55,12 @@ public class CommonsApplicationModule {
return application.getSharedPreferences("prefs", MODE_PRIVATE); return application.getSharedPreferences("prefs", MODE_PRIVATE);
} }
@Provides
@Named("direct_nearby_upload_prefs")
public SharedPreferences providesDirectNearbyUploadPreferences() {
return application.getSharedPreferences("direct_nearby_upload_prefs", MODE_PRIVATE);
}
@Provides @Provides
public UploadController providesUploadController(SessionManager sessionManager, @Named("default_preferences") SharedPreferences sharedPreferences) { public UploadController providesUploadController(SessionManager sessionManager, @Named("default_preferences") SharedPreferences sharedPreferences) {
return new UploadController(sessionManager, application, sharedPreferences); return new UploadController(sessionManager, application, sharedPreferences);

View file

@ -7,6 +7,7 @@ import fr.free.nrw.commons.contributions.ContributionsListFragment;
import fr.free.nrw.commons.media.MediaDetailFragment; import fr.free.nrw.commons.media.MediaDetailFragment;
import fr.free.nrw.commons.media.MediaDetailPagerFragment; import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.nearby.NearbyListFragment; import fr.free.nrw.commons.nearby.NearbyListFragment;
import fr.free.nrw.commons.nearby.NearbyMapFragment;
import fr.free.nrw.commons.nearby.NoPermissionsFragment; import fr.free.nrw.commons.nearby.NoPermissionsFragment;
import fr.free.nrw.commons.settings.SettingsFragment; import fr.free.nrw.commons.settings.SettingsFragment;
import fr.free.nrw.commons.upload.MultipleUploadListFragment; import fr.free.nrw.commons.upload.MultipleUploadListFragment;
@ -31,6 +32,9 @@ public abstract class FragmentBuilderModule {
@ContributesAndroidInjector @ContributesAndroidInjector
abstract NearbyListFragment bindNearbyListFragment(); abstract NearbyListFragment bindNearbyListFragment();
@ContributesAndroidInjector
abstract NearbyMapFragment bindNearbyMapFragment();
@ContributesAndroidInjector @ContributesAndroidInjector
abstract NoPermissionsFragment bindNoPermissionsFragment(); abstract NoPermissionsFragment bindNoPermissionsFragment();

View file

@ -0,0 +1,77 @@
package fr.free.nrw.commons.nearby;
import android.content.SharedPreferences;
import android.os.Build;
import android.support.v4.app.Fragment;
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 static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class DirectUpload {
private ContributionController controller;
private Fragment fragment;
private SharedPreferences prefs;
DirectUpload(Fragment fragment, ContributionController controller, SharedPreferences prefs) {
this.fragment = fragment;
this.controller = controller;
this.prefs = prefs;
}
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();
}
}
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)) {
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);
dialog.dismiss();
})
.setNegativeButton("Cancel", null)
.create()
.show();
} else {
fragment.getActivity().requestPermissions(new String[]{READ_EXTERNAL_STORAGE},
1);
}
} else {
controller.startGalleryPick();
}
}
else {
controller.startGalleryPick();
}
}
}

View file

@ -4,6 +4,8 @@ import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator; import android.animation.TypeEvaluator;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.Color; import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -45,10 +47,19 @@ import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import fr.free.nrw.commons.R; import javax.inject.Inject;
import fr.free.nrw.commons.utils.UriDeserializer; import javax.inject.Named;
public class NearbyMapFragment extends android.support.v4.app.Fragment{ import dagger.android.support.DaggerFragment;
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;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
public class NearbyMapFragment extends DaggerFragment {
private MapView mapView; private MapView mapView;
private List<NearbyBaseMarker> baseMarkerOptions; private List<NearbyBaseMarker> baseMarkerOptions;
@ -83,6 +94,7 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
private Animation fab_close; private Animation fab_close;
private Animation fab_open; private Animation fab_open;
private Animation rotate_forward; private Animation rotate_forward;
private ContributionController controller;
private Place place; private Place place;
private Marker selected; private Marker selected;
@ -90,6 +102,9 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
private MapboxMap mapboxMap; private MapboxMap mapboxMap;
private PolygonOptions currentLocationPolygonOptions; private PolygonOptions currentLocationPolygonOptions;
@Inject @Named("prefs") SharedPreferences prefs;
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
public NearbyMapFragment() { public NearbyMapFragment() {
} }
@ -468,7 +483,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
this.getView().requestFocus(); this.getView().requestFocus();
break; break;
} }
} }
private void hideFAB() { private void hideFAB() {
@ -509,10 +523,72 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
commonsButton.setEnabled(place.hasCommonsLink()); commonsButton.setEnabled(place.hasCommonsLink());
commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink())); commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink()));
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getLabel().getIcon());
description.setText(place.getDescription().getText());
title.setText(place.name); description.setText(place.getLongDescription());
distance.setText(place.distance); title.setText(place.name.toString());
distance.setText(place.distance.toString());
fabCamera.setOnClickListener(view -> {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller, prefs);
storeSharedPrefs();
directUpload.initiateCameraUpload();
});
fabGallery.setOnClickListener(view -> {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
controller = new ContributionController(this);
DirectUpload directUpload = new DirectUpload(this, controller, prefs);
storeSharedPrefs();
directUpload.initiateGalleryUpload();
});
}
void storeSharedPrefs() {
SharedPreferences.Editor editor = directPrefs.edit();
editor.putString("Title", place.getName());
editor.putString("Desc", place.getLongDescription());
editor.apply();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
Timber.d("onRequestPermissionsResult: req code = " + " perm = " + permissions + " grant =" + grantResults);
switch (requestCode) {
// 1 = "Read external storage" allowed when gallery selected
case 1: {
if (grantResults.length > 0 && grantResults[0] == PERMISSION_GRANTED) {
Timber.d("Call controller.startGalleryPick()");
controller.startGalleryPick();
}
}
break;
// 3 = "Write external storage" allowed when camera selected
case 3: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Timber.d("Call controller.startCameraCapture()");
controller.startCameraCapture();
}
}
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
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, true);
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
}
} }
private void openWebView(Uri link) { private void openWebView(Uri link) {
@ -521,25 +597,19 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
} }
private void animateFAB(boolean isFabOpen) { private void animateFAB(boolean isFabOpen) {
if (isFabOpen) { if (isFabOpen) {
fabPlus.startAnimation(rotate_backward); fabPlus.startAnimation(rotate_backward);
fabCamera.startAnimation(fab_close); fabCamera.startAnimation(fab_close);
fabGallery.startAnimation(fab_close); fabGallery.startAnimation(fab_close);
fabCamera.hide(); fabCamera.hide();
fabGallery.hide(); fabGallery.hide();
} else { } else {
fabPlus.startAnimation(rotate_forward); fabPlus.startAnimation(rotate_forward);
fabCamera.startAnimation(fab_open); fabCamera.startAnimation(fab_open);
fabGallery.startAnimation(fab_open); fabGallery.startAnimation(fab_open);
fabCamera.show(); fabCamera.show();
fabGallery.show(); fabGallery.show();
} }
this.isFabOpen=!isFabOpen; this.isFabOpen=!isFabOpen;
} }
@ -611,6 +681,5 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
return latLng; return latLng;
} }
} }
} }

View file

@ -124,7 +124,7 @@ public class NearbyPlaces {
places.add(new Place( places.add(new Place(
name, name,
Place.Description.fromText(type), // list Place.Label.fromText(type), // list
type, // details type, // details
Uri.parse(icon), Uri.parse(icon),
new LatLng(latitude, longitude, 0), new LatLng(latitude, longitude, 0),

View file

@ -13,7 +13,7 @@ import fr.free.nrw.commons.location.LatLng;
public class Place { public class Place {
public final String name; public final String name;
private final Description description; private final Label label;
private final String longDescription; private final String longDescription;
private final Uri secondaryImageUrl; private final Uri secondaryImageUrl;
public final LatLng location; public final LatLng location;
@ -24,20 +24,24 @@ public class Place {
public final Sitelinks siteLinks; public final Sitelinks siteLinks;
public Place(String name, Description description, String longDescription, public Place(String name, Label label, String longDescription,
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) { Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
this.name = name; this.name = name;
this.description = description; this.label = label;
this.longDescription = longDescription; this.longDescription = longDescription;
this.secondaryImageUrl = secondaryImageUrl; this.secondaryImageUrl = secondaryImageUrl;
this.location = location; this.location = location;
this.siteLinks = siteLinks; this.siteLinks = siteLinks;
} }
public Description getDescription() { public String getName() { return name; }
return description;
public Label getLabel() {
return label;
} }
public String getLongDescription() { return longDescription; }
public void setDistance(String distance) { public void setDistance(String distance) {
this.distance = distance; this.distance = distance;
} }
@ -79,10 +83,8 @@ public class Place {
* Most common types of desc: building, house, cottage, farmhouse, * Most common types of desc: building, house, cottage, farmhouse,
* village, civil parish, church, railway station, * village, civil parish, church, railway station,
* gatehouse, milestone, inn, secondary school, hotel * gatehouse, milestone, inn, secondary school, hotel
*
* TODO Give a more accurate class name (see issue #742).
*/ */
public enum Description { public enum Label {
BUILDING("building", R.drawable.round_icon_generic_building), BUILDING("building", R.drawable.round_icon_generic_building),
HOUSE("house", R.drawable.round_icon_house), HOUSE("house", R.drawable.round_icon_house),
@ -107,19 +109,19 @@ public class Place {
WATERFALL("waterfall", R.drawable.round_icon_waterfall), WATERFALL("waterfall", R.drawable.round_icon_waterfall),
UNKNOWN("?", R.drawable.round_icon_unknown); UNKNOWN("?", R.drawable.round_icon_unknown);
private static final Map<String, Description> TEXT_TO_DESCRIPTION private static final Map<String, Label> TEXT_TO_DESCRIPTION
= new HashMap<>(Description.values().length); = new HashMap<>(Label.values().length);
static { static {
for (Description description : values()) { for (Label label : values()) {
TEXT_TO_DESCRIPTION.put(description.text, description); TEXT_TO_DESCRIPTION.put(label.text, label);
} }
} }
private final String text; private final String text;
@DrawableRes private final int icon; @DrawableRes private final int icon;
Description(String text, @DrawableRes int icon) { Label(String text, @DrawableRes int icon) {
this.text = text; this.text = text;
this.icon = icon; this.icon = icon;
} }
@ -133,9 +135,9 @@ public class Place {
return icon; return icon;
} }
public static Description fromText(String text) { public static Label fromText(String text) {
Description description = TEXT_TO_DESCRIPTION.get(text); Label label = TEXT_TO_DESCRIPTION.get(text);
return description == null ? UNKNOWN : description; return label == null ? UNKNOWN : label;
} }
} }
} }

View file

@ -13,7 +13,6 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.pedrogomez.renderers.Renderer; import com.pedrogomez.renderers.Renderer;
import java.util.ArrayList; import java.util.ArrayList;
@ -82,6 +81,7 @@ class PlaceRenderer extends Renderer<Place> {
} }
}); });
//TODO: Set onClickListeners for camera and gallery in list here
} }
private void closeLayout(LinearLayout buttonLayout){ private void closeLayout(LinearLayout buttonLayout){
@ -96,13 +96,13 @@ class PlaceRenderer extends Renderer<Place> {
public void render() { public void render() {
place = getContent(); place = getContent();
tvName.setText(place.name); tvName.setText(place.name);
String descriptionText = place.getDescription().getText(); String descriptionText = place.getLabel().getText();
if (descriptionText.equals("?")) { if (descriptionText.equals("?")) {
descriptionText = getContext().getString(R.string.no_description_found); descriptionText = getContext().getString(R.string.no_description_found);
} }
tvDesc.setText(descriptionText); tvDesc.setText(descriptionText);
distance.setText(place.distance); distance.setText(place.distance);
icon.setImageResource(place.getDescription().getIcon()); icon.setImageResource(place.getLabel().getIcon());
directionsButton.setOnClickListener(view -> { directionsButton.setOnClickListener(view -> {
//Open map app at given position //Open map app at given position

View file

@ -39,7 +39,6 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R; import fr.free.nrw.commons.R;
import fr.free.nrw.commons.auth.AuthenticatedActivity; import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.SessionManager; import fr.free.nrw.commons.auth.SessionManager;
@ -51,7 +50,6 @@ import fr.free.nrw.commons.modifications.CategoryModifier;
import fr.free.nrw.commons.modifications.ModificationsContentProvider; import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import fr.free.nrw.commons.modifications.ModifierSequence; import fr.free.nrw.commons.modifications.ModifierSequence;
import fr.free.nrw.commons.modifications.TemplateRemoveModifier; import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
import fr.free.nrw.commons.mwapi.EventLog;
import fr.free.nrw.commons.mwapi.MediaWikiApi; import fr.free.nrw.commons.mwapi.MediaWikiApi;
import timber.log.Timber; import timber.log.Timber;
@ -100,6 +98,8 @@ public class ShareActivity
private Snackbar snackbar; private Snackbar snackbar;
private boolean duplicateCheckPassed = false; private boolean duplicateCheckPassed = false;
private boolean isNearbyUpload = false;
/** /**
* Called when user taps the submit button. * Called when user taps the submit button.
*/ */
@ -198,6 +198,10 @@ public class ShareActivity
finish(); finish();
} }
protected boolean isNearbyUpload() {
return isNearbyUpload;
}
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -224,6 +228,10 @@ public class ShareActivity
} else { } else {
source = Contribution.SOURCE_EXTERNAL; source = Contribution.SOURCE_EXTERNAL;
} }
if (intent.hasExtra("isDirectUpload")) {
Timber.d("This was initiated by a direct upload from Nearby");
isNearbyUpload = true;
}
mimeType = intent.getType(); mimeType = intent.getType();
} }

View file

@ -1,5 +1,6 @@
package fr.free.nrw.commons.upload; package fr.free.nrw.commons.upload;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
@ -54,6 +55,7 @@ public class SingleUploadFragment extends DaggerFragment {
@BindView(R.id.licenseSpinner) Spinner licenseSpinner; @BindView(R.id.licenseSpinner) Spinner licenseSpinner;
@Inject @Named("default_preferences") SharedPreferences prefs; @Inject @Named("default_preferences") SharedPreferences prefs;
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
private String license; private String license;
private OnUploadActionInitiated uploadActionInitiatedHandler; private OnUploadActionInitiated uploadActionInitiatedHandler;
@ -84,7 +86,6 @@ public class SingleUploadFragment extends DaggerFragment {
uploadActionInitiatedHandler.uploadActionInitiated(title, desc); uploadActionInitiatedHandler.uploadActionInitiated(title, desc);
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@ -104,6 +105,16 @@ public class SingleUploadFragment extends DaggerFragment {
license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3); license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
// If this is a direct upload from Nearby, autofill title and desc fields with the Place's values
boolean isNearbyUpload = ((ShareActivity) getActivity()).isNearbyUpload();
if (isNearbyUpload) {
String imageTitle = directPrefs.getString("Title", "");
String imageDesc = directPrefs.getString("Desc", "");
titleEdit.setText(imageTitle);
descEdit.setText(imageDesc);
}
// check if this is the first time we have uploaded // check if this is the first time we have uploaded
if (prefs.getString("Title", "").trim().length() == 0 if (prefs.getString("Title", "").trim().length() == 0
&& prefs.getString("Desc", "").trim().length() == 0) { && prefs.getString("Desc", "").trim().length() == 0) {
@ -241,6 +252,7 @@ public class SingleUploadFragment extends DaggerFragment {
return false; return false;
} }
@SuppressLint("StringFormatInvalid")
private void setLicenseSummary(String license) { private void setLicenseSummary(String license) {
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license)))); licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
} }

View file

@ -30,9 +30,9 @@ import static org.junit.Assert.assertNotNull;
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class) @Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
public class NearbyAdapterFactoryTest { public class NearbyAdapterFactoryTest {
private static final Place PLACE = new Place("name", Place.Description.AIRPORT, private static final Place PLACE = new Place("name", Place.Label.AIRPORT,
"desc", null, new LatLng(38.6270, -90.1994, 0), null); "desc", null, new LatLng(38.6270, -90.1994, 0), null);
private static final Place UNKNOWN_PLACE = new Place("name", Place.Description.UNKNOWN, private static final Place UNKNOWN_PLACE = new Place("name", Place.Label.UNKNOWN,
"desc", null, new LatLng(39.7392, -104.9903, 0), null); "desc", null, new LatLng(39.7392, -104.9903, 0), null);
private Place clickedPlace; private Place clickedPlace;