Skip to content

Suggest and auto fill title and description based on image location #3323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ List<Place> radiusExpander(LatLng curLatLng, String lang, boolean returnClosestR
* @return list of places obtained
* @throws IOException if query fails
*/
private List<Place> getFromWikidataQuery(LatLng cur, String lang, double radius) throws IOException {
public List<Place> getFromWikidataQuery(LatLng cur, String lang, double radius) throws IOException {
return okHttpJsonApiClient.getNearbyPlaces(cur, lang, radius).blockingSingle();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package fr.free.nrw.commons.repository;

import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand All @@ -10,6 +12,8 @@
import fr.free.nrw.commons.category.CategoryItem;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.NearbyPlaces;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.upload.SimilarImageInterface;
import fr.free.nrw.commons.upload.UploadController;
Expand All @@ -24,16 +28,21 @@
@Singleton
public class UploadRemoteDataSource {

private static final double NEARBY_RADIUS_IN_KILO_METERS = 0.1; //100 meters

private UploadModel uploadModel;
private UploadController uploadController;
private CategoriesModel categoriesModel;
private NearbyPlaces nearbyPlaces;

@Inject
public UploadRemoteDataSource(UploadModel uploadModel, UploadController uploadController,
CategoriesModel categoriesModel) {
CategoriesModel categoriesModel,
NearbyPlaces nearbyPlaces) {
this.uploadModel = uploadModel;
this.uploadController = uploadController;
this.categoriesModel = categoriesModel;
this.nearbyPlaces = nearbyPlaces;
}

/**
Expand Down Expand Up @@ -176,4 +185,22 @@ public Observable<UploadItem> preProcessImage(UploadableFile uploadableFile, Pla
public Single<Integer> getImageQuality(UploadItem uploadItem, boolean shouldValidateTitle) {
return uploadModel.getImageQuality(uploadItem, shouldValidateTitle);
}

/**
* gets nearby places matching with upload item's GPS location
*
* @param latitude
* @param longitude
* @return
*/
public Place getNearbyPlaces(double latitude, double longitude) {
try {
List<Place> fromWikidataQuery = nearbyPlaces.getFromWikidataQuery(new LatLng(latitude, longitude, 0.0f),
Locale.getDefault().getLanguage(),
NEARBY_RADIUS_IN_KILO_METERS);
return fromWikidataQuery.size() > 0 ? fromWikidataQuery.get(0) : null;
} catch (IOException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,14 @@ public String getValue(String key, String value) {
public void setSelectedLicense(String licenseName) {
localDataSource.setSelectedLicense(licenseName);
}

/**
* Returns nearest place matching the passed latitude and longitude
* @param decLatitude
* @param decLongitude
* @return
*/
public Place checkNearbyPlaces(double decLatitude, double decLongitude) {
return remoteDataSource.getNearbyPlaces(decLatitude, decLongitude);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.upload.mediaDetails;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
Expand All @@ -25,6 +26,7 @@
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -297,6 +299,32 @@ public void onImageProcessed(UploadItem uploadItem, Place place) {
setDescriptionsInAdapter(descriptions);
}

/**
* Shows popup if any nearby location needing pictures matches uploadable picture's GPS location
* @param uploadItem
* @param place
*/
@SuppressLint("StringFormatInvalid")
@Override
public void onNearbyPlaceFound(UploadItem uploadItem, Place place) {
DialogUtil.showAlertDialog(getActivity(),
getString(R.string.upload_nearby_place_found_title),
String.format(Locale.getDefault(),
getString(R.string.upload_nearby_place_found_description),
place.getName()),
() -> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to be empty?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup. there's no action on cancel. the dialog is dismissed automatically.


},
() -> {
etTitle.setText(place.getName());
Description description = new Description();
description.setLanguageCode("en");
description.setDescriptionText(place.getLongDescription());
descriptions = Arrays.asList(description);
setDescriptionsInAdapter(descriptions);
});
}

@Override
public void showProgress(boolean shouldShow) {
callback.showProgress(shouldShow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface View extends SimilarImageInterface {

void onImageProcessed(UploadItem uploadItem, Place place);

void onNearbyPlaceFound(UploadItem uploadItem, Place place);

void showProgress(boolean shouldShow);

void onImageValidationSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import fr.free.nrw.commons.upload.UploadModel.UploadItem;
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailsContract.UserActionListener;
import fr.free.nrw.commons.upload.mediaDetails.UploadMediaDetailsContract.View;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
Expand Down Expand Up @@ -81,13 +82,31 @@ public void receiveImage(UploadableFile uploadableFile, String source, Place pla
{
view.onImageProcessed(uploadItem, place);
GPSExtractor gpsCoords = uploadItem.getGpsCoords();
view.showMapWithImageCoordinates((gpsCoords != null && gpsCoords.imageCoordsExists) ? true : false);
view.showMapWithImageCoordinates(gpsCoords != null && gpsCoords.imageCoordsExists);
view.showProgress(false);
if (gpsCoords != null && gpsCoords.imageCoordsExists) {
checkNearbyPlaces(uploadItem);
}
},
throwable -> Timber.e(throwable, "Error occurred in processing images"));
compositeDisposable.add(uploadItemDisposable);
}

/**
* This method checks for the nearest location that needs images and suggests it to the user.
* @param uploadItem
*/
private void checkNearbyPlaces(UploadItem uploadItem) {
Disposable checkNearbyPlaces = Observable.fromCallable(() -> repository
.checkNearbyPlaces(uploadItem.getGpsCoords().getDecLatitude(),
uploadItem.getGpsCoords().getDecLongitude()))
.subscribeOn(ioScheduler)
.observeOn(mainThreadScheduler)
.subscribe(place -> view.onNearbyPlaceFound(uploadItem, place),
throwable -> Timber.e(throwable, "Error occurred in processing images"));
compositeDisposable.add(checkNearbyPlaces);
}

/**
* asks the repository to verify image quality
*
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -588,4 +588,7 @@ Upload your first media by tapping on the add button.</string>
<string name="place_type">Place type:</string>
<string name="nearby_search_hint">Bridge, museum, hotel etc.</string>
<string name="you_must_reset_your_passsword">Something went wrong with login, you must reset your password !!</string>

<string name="upload_nearby_place_found_title">Nearby Place Found</string>
<string name="upload_nearby_place_found_description">Is this a photo of Place %1$s?</string>
</resources>