mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Fix conflicts
This commit is contained in:
commit
3fc21de0ab
12 changed files with 238 additions and 45 deletions
|
|
@ -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.upload.UploadService.EXTRA_SOURCE;
|
||||
|
||||
class ContributionController {
|
||||
public class ContributionController {
|
||||
|
||||
private static final int SELECT_FROM_GALLERY = 1;
|
||||
private static final int SELECT_FROM_CAMERA = 2;
|
||||
|
||||
private Fragment fragment;
|
||||
|
||||
ContributionController(Fragment fragment) {
|
||||
public ContributionController(Fragment fragment) {
|
||||
this.fragment = fragment;
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +61,7 @@ class ContributionController {
|
|||
}
|
||||
}
|
||||
|
||||
void startCameraCapture() {
|
||||
public void startCameraCapture() {
|
||||
|
||||
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||
lastGeneratedCaptureUri = reGenerateImageCaptureUriInCache();
|
||||
|
|
@ -70,6 +70,9 @@ class ContributionController {
|
|||
requestWritePermission(fragment.getContext(), takePictureIntent, lastGeneratedCaptureUri);
|
||||
|
||||
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, lastGeneratedCaptureUri);
|
||||
if (!fragment.isAdded()) {
|
||||
return;
|
||||
}
|
||||
fragment.startActivityForResult(takePictureIntent, SELECT_FROM_CAMERA);
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +80,17 @@ class ContributionController {
|
|||
//FIXME: Starts gallery (opens Google Photos)
|
||||
Intent pickImageIntent = new Intent(ACTION_GET_CONTENT);
|
||||
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);
|
||||
}
|
||||
|
||||
void handleImagePicked(int requestCode, Intent data) {
|
||||
public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload) {
|
||||
FragmentActivity activity = fragment.getActivity();
|
||||
Timber.d("handleImagePicked() called with onActivityResult()");
|
||||
Intent shareIntent = new Intent(activity, ShareActivity.class);
|
||||
shareIntent.setAction(ACTION_SEND);
|
||||
switch (requestCode) {
|
||||
|
|
@ -91,11 +100,17 @@ class ContributionController {
|
|||
shareIntent.setType(activity.getContentResolver().getType(imageData));
|
||||
shareIntent.putExtra(EXTRA_STREAM, imageData);
|
||||
shareIntent.putExtra(EXTRA_SOURCE, SOURCE_GALLERY);
|
||||
if (isDirectUpload) {
|
||||
shareIntent.putExtra("isDirectUpload", true);
|
||||
}
|
||||
break;
|
||||
case SELECT_FROM_CAMERA:
|
||||
shareIntent.setType("image/jpeg"); //FIXME: Find out appropriate mime type
|
||||
shareIntent.putExtra(EXTRA_STREAM, lastGeneratedCaptureUri);
|
||||
shareIntent.putExtra(EXTRA_SOURCE, SOURCE_CAMERA);
|
||||
if (isDirectUpload) {
|
||||
shareIntent.putExtra("isDirectUpload", true);
|
||||
}
|
||||
break;
|
||||
}
|
||||
Timber.i("Image selected");
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class ContributionsListFragment extends DaggerFragment {
|
|||
if (resultCode == RESULT_OK) {
|
||||
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
controller.handleImagePicked(requestCode, data);
|
||||
controller.handleImagePicked(requestCode, data, false);
|
||||
} else {
|
||||
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
|
||||
requestCode, resultCode, data);
|
||||
|
|
|
|||
|
|
@ -55,6 +55,12 @@ public class CommonsApplicationModule {
|
|||
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
|
||||
public UploadController providesUploadController(SessionManager sessionManager, @Named("default_preferences") SharedPreferences sharedPreferences) {
|
||||
return new UploadController(sessionManager, application, sharedPreferences);
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import fr.free.nrw.commons.contributions.ContributionsListFragment;
|
|||
import fr.free.nrw.commons.media.MediaDetailFragment;
|
||||
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
|
||||
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.settings.SettingsFragment;
|
||||
import fr.free.nrw.commons.upload.MultipleUploadListFragment;
|
||||
|
|
@ -31,6 +32,9 @@ public abstract class FragmentBuilderModule {
|
|||
@ContributesAndroidInjector
|
||||
abstract NearbyListFragment bindNearbyListFragment();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract NearbyMapFragment bindNearbyMapFragment();
|
||||
|
||||
@ContributesAndroidInjector
|
||||
abstract NoPermissionsFragment bindNoPermissionsFragment();
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@ import android.animation.ObjectAnimator;
|
|||
import android.animation.TypeEvaluator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -45,10 +47,19 @@ import java.lang.reflect.Type;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.utils.UriDeserializer;
|
||||
import javax.inject.Inject;
|
||||
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 List<NearbyBaseMarker> baseMarkerOptions;
|
||||
|
|
@ -83,6 +94,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;
|
||||
private Marker selected;
|
||||
|
|
@ -90,6 +102,9 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
|
|||
private MapboxMap mapboxMap;
|
||||
private PolygonOptions currentLocationPolygonOptions;
|
||||
|
||||
@Inject @Named("prefs") SharedPreferences prefs;
|
||||
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
|
||||
|
||||
public NearbyMapFragment() {
|
||||
}
|
||||
|
||||
|
|
@ -468,7 +483,6 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
|
|||
this.getView().requestFocus();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void hideFAB() {
|
||||
|
|
@ -509,10 +523,72 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
|
|||
commonsButton.setEnabled(place.hasCommonsLink());
|
||||
commonsButton.setOnClickListener(view -> openWebView(place.siteLinks.getCommonsLink()));
|
||||
|
||||
icon.setImageResource(place.getDescription().getIcon());
|
||||
description.setText(place.getDescription().getText());
|
||||
title.setText(place.name);
|
||||
distance.setText(place.distance);
|
||||
icon.setImageResource(place.getLabel().getIcon());
|
||||
|
||||
description.setText(place.getLongDescription());
|
||||
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) {
|
||||
|
|
@ -521,25 +597,19 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
|
|||
}
|
||||
|
||||
private void animateFAB(boolean isFabOpen) {
|
||||
|
||||
if (isFabOpen) {
|
||||
|
||||
fabPlus.startAnimation(rotate_backward);
|
||||
fabCamera.startAnimation(fab_close);
|
||||
fabGallery.startAnimation(fab_close);
|
||||
fabCamera.hide();
|
||||
fabGallery.hide();
|
||||
|
||||
} else {
|
||||
|
||||
fabPlus.startAnimation(rotate_forward);
|
||||
fabCamera.startAnimation(fab_open);
|
||||
fabGallery.startAnimation(fab_open);
|
||||
fabCamera.show();
|
||||
fabGallery.show();
|
||||
|
||||
}
|
||||
|
||||
this.isFabOpen=!isFabOpen;
|
||||
}
|
||||
|
||||
|
|
@ -611,6 +681,5 @@ public class NearbyMapFragment extends android.support.v4.app.Fragment{
|
|||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class NearbyPlaces {
|
|||
|
||||
places.add(new Place(
|
||||
name,
|
||||
Place.Description.fromText(type), // list
|
||||
Place.Label.fromText(type), // list
|
||||
type, // details
|
||||
Uri.parse(icon),
|
||||
new LatLng(latitude, longitude, 0),
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import fr.free.nrw.commons.location.LatLng;
|
|||
public class Place {
|
||||
|
||||
public final String name;
|
||||
private final Description description;
|
||||
private final Label label;
|
||||
private final String longDescription;
|
||||
private final Uri secondaryImageUrl;
|
||||
public final LatLng location;
|
||||
|
|
@ -24,20 +24,24 @@ public class Place {
|
|||
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) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.label = label;
|
||||
this.longDescription = longDescription;
|
||||
this.secondaryImageUrl = secondaryImageUrl;
|
||||
this.location = location;
|
||||
this.siteLinks = siteLinks;
|
||||
}
|
||||
|
||||
public Description getDescription() {
|
||||
return description;
|
||||
public String getName() { return name; }
|
||||
|
||||
public Label getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getLongDescription() { return longDescription; }
|
||||
|
||||
public void setDistance(String distance) {
|
||||
this.distance = distance;
|
||||
}
|
||||
|
|
@ -79,10 +83,8 @@ public class Place {
|
|||
* Most common types of desc: building, house, cottage, farmhouse,
|
||||
* village, civil parish, church, railway station,
|
||||
* 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),
|
||||
HOUSE("house", R.drawable.round_icon_house),
|
||||
|
|
@ -107,19 +109,19 @@ public class Place {
|
|||
WATERFALL("waterfall", R.drawable.round_icon_waterfall),
|
||||
UNKNOWN("?", R.drawable.round_icon_unknown);
|
||||
|
||||
private static final Map<String, Description> TEXT_TO_DESCRIPTION
|
||||
= new HashMap<>(Description.values().length);
|
||||
private static final Map<String, Label> TEXT_TO_DESCRIPTION
|
||||
= new HashMap<>(Label.values().length);
|
||||
|
||||
static {
|
||||
for (Description description : values()) {
|
||||
TEXT_TO_DESCRIPTION.put(description.text, description);
|
||||
for (Label label : values()) {
|
||||
TEXT_TO_DESCRIPTION.put(label.text, label);
|
||||
}
|
||||
}
|
||||
|
||||
private final String text;
|
||||
@DrawableRes private final int icon;
|
||||
|
||||
Description(String text, @DrawableRes int icon) {
|
||||
Label(String text, @DrawableRes int icon) {
|
||||
this.text = text;
|
||||
this.icon = icon;
|
||||
}
|
||||
|
|
@ -133,9 +135,9 @@ public class Place {
|
|||
return icon;
|
||||
}
|
||||
|
||||
public static Description fromText(String text) {
|
||||
Description description = TEXT_TO_DESCRIPTION.get(text);
|
||||
return description == null ? UNKNOWN : description;
|
||||
public static Label fromText(String text) {
|
||||
Label label = TEXT_TO_DESCRIPTION.get(text);
|
||||
return label == null ? UNKNOWN : label;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.pedrogomez.renderers.Renderer;
|
||||
|
||||
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){
|
||||
|
|
@ -96,13 +96,13 @@ class PlaceRenderer extends Renderer<Place> {
|
|||
public void render() {
|
||||
place = getContent();
|
||||
tvName.setText(place.name);
|
||||
String descriptionText = place.getDescription().getText();
|
||||
String descriptionText = place.getLabel().getText();
|
||||
if (descriptionText.equals("?")) {
|
||||
descriptionText = getContext().getString(R.string.no_description_found);
|
||||
}
|
||||
tvDesc.setText(descriptionText);
|
||||
distance.setText(place.distance);
|
||||
icon.setImageResource(place.getDescription().getIcon());
|
||||
icon.setImageResource(place.getLabel().getIcon());
|
||||
|
||||
directionsButton.setOnClickListener(view -> {
|
||||
//Open map app at given position
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ import javax.inject.Inject;
|
|||
import javax.inject.Named;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.auth.AuthenticatedActivity;
|
||||
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.ModifierSequence;
|
||||
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
|
||||
import fr.free.nrw.commons.mwapi.EventLog;
|
||||
import fr.free.nrw.commons.mwapi.MediaWikiApi;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
|
@ -100,6 +98,8 @@ public class ShareActivity
|
|||
private Snackbar snackbar;
|
||||
private boolean duplicateCheckPassed = false;
|
||||
|
||||
private boolean isNearbyUpload = false;
|
||||
|
||||
/**
|
||||
* Called when user taps the submit button.
|
||||
*/
|
||||
|
|
@ -198,6 +198,10 @@ public class ShareActivity
|
|||
finish();
|
||||
}
|
||||
|
||||
protected boolean isNearbyUpload() {
|
||||
return isNearbyUpload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -224,6 +228,10 @@ public class ShareActivity
|
|||
} else {
|
||||
source = Contribution.SOURCE_EXTERNAL;
|
||||
}
|
||||
if (intent.hasExtra("isDirectUpload")) {
|
||||
Timber.d("This was initiated by a direct upload from Nearby");
|
||||
isNearbyUpload = true;
|
||||
}
|
||||
mimeType = intent.getType();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.upload;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
|
@ -54,6 +55,7 @@ public class SingleUploadFragment extends DaggerFragment {
|
|||
@BindView(R.id.licenseSpinner) Spinner licenseSpinner;
|
||||
|
||||
@Inject @Named("default_preferences") SharedPreferences prefs;
|
||||
@Inject @Named("direct_nearby_upload_prefs") SharedPreferences directPrefs;
|
||||
|
||||
private String license;
|
||||
private OnUploadActionInitiated uploadActionInitiatedHandler;
|
||||
|
|
@ -84,7 +86,6 @@ public class SingleUploadFragment extends DaggerFragment {
|
|||
|
||||
uploadActionInitiatedHandler.uploadActionInitiated(title, desc);
|
||||
return true;
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
// 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
|
||||
if (prefs.getString("Title", "").trim().length() == 0
|
||||
&& prefs.getString("Desc", "").trim().length() == 0) {
|
||||
|
|
@ -241,6 +252,7 @@ public class SingleUploadFragment extends DaggerFragment {
|
|||
return false;
|
||||
}
|
||||
|
||||
@SuppressLint("StringFormatInvalid")
|
||||
private void setLicenseSummary(String license) {
|
||||
licenseSummaryView.setText(getString(R.string.share_license_summary, getString(Utils.licenseNameFor(license))));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,9 @@ import static org.junit.Assert.assertNotNull;
|
|||
@Config(constants = BuildConfig.class, sdk = 21, application = TestCommonsApplication.class)
|
||||
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);
|
||||
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);
|
||||
private Place clickedPlace;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue