Fixes #4554 - only use WLM2021 template for countries that are included in it (#4574)

* Fixes #4554
1. For WLM uploads reverse geo code and see if the country code is supported -only then is the WLM upload flow triggered, otherwise usual nearby uploads happen
2. Bug Fix - Current Location marker and area

* Fixed compile error added after rebasing

* Bug fix for country code in reverse geo code
This commit is contained in:
Ashish 2021-09-01 15:29:00 +05:30 committed by GitHub
parent b47ed0546e
commit 7deaf8dbae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 109 additions and 48 deletions

View file

@ -39,7 +39,8 @@ data class Contribution constructor(
var dataLength: Long = 0,
var dateCreated: Date? = null,
var dateModified: Date? = null,
var hasInvalidLocation : Int = 0
var hasInvalidLocation : Int = 0,
var countryCode : String? = null
) : Parcelable {
fun completeWith(media: Media): Contribution {

View file

@ -12,7 +12,7 @@ import fr.free.nrw.commons.upload.depicts.DepictsDao
* The database for accessing the respective DAOs
*
*/
@Database(entities = [Contribution::class, Depicts::class], version = 8, exportSchema = false)
@Database(entities = [Contribution::class, Depicts::class], version = 9, exportSchema = false)
@TypeConverters(Converters::class)
abstract class AppDatabase : RoomDatabase() {
abstract fun contributionDao(): ContributionDao

View file

@ -300,4 +300,8 @@ public class UploadRepository {
public void useSimilarPictureCoordinates(ImageCoordinates imageCoordinates, int uploadItemIndex) {
uploadModel.useSimilarPictureCoordinates(imageCoordinates, uploadItemIndex);
}
public boolean isWMLSupportedForThisPlace() {
return uploadModel.getItems().get(0).isWLMUpload();
}
}

View file

@ -30,7 +30,7 @@ class PageContentsCreator {
this.context = context;
}
public String createFrom(final Contribution contribution, final String countryCode) {
public String createFrom(final Contribution contribution) {
StringBuilder buffer = new StringBuilder();
final Media media = contribution.getMedia();
buffer
@ -63,7 +63,7 @@ class PageContentsCreator {
if (contribution.getWikidataPlace()!=null && contribution.getWikidataPlace().isMonumentUpload()) {
buffer.append("{{Wiki Loves Monuments 2021|1= ")
.append(countryCode)
.append(contribution.getCountryCode())
.append("}}").append("\n");
}

View file

@ -210,11 +210,11 @@ public class UploadClient {
public Observable<UploadResult> uploadFileFromStash(
final Contribution contribution,
final String uniqueFileName,
final String fileKey, @Nullable String countryCode) {
final String fileKey) {
try {
return uploadInterface
.uploadFileFromStash(csrfTokenClient.getTokenBlocking(),
pageContentsCreator.createFrom(contribution, countryCode),
pageContentsCreator.createFrom(contribution),
CommonsApplication.DEFAULT_EDIT_SUMMARY,
uniqueFileName,
fileKey).map(uploadResponse -> {

View file

@ -23,6 +23,8 @@ public class UploadItem {
private final String createdTimestampSource;
private final BehaviorSubject<Integer> imageQuality;
private boolean hasInvalidLocation;
private boolean isWLMUpload = false;
private String countryCode;
@SuppressLint("CheckResult")
@ -87,6 +89,14 @@ public class UploadItem {
this.uploadMediaDetails = uploadMediaDetails;
}
public void setWLMUpload(final boolean WLMUpload) {
isWLMUpload = WLMUpload;
}
public boolean isWLMUpload() {
return isWLMUpload;
}
@Override
public boolean equals(@Nullable final Object obj) {
if (!(obj instanceof UploadItem)) {
@ -121,4 +131,13 @@ public class UploadItem {
public boolean hasInvalidLocation() {
return hasInvalidLocation;
}
public void setCountryCode(final String countryCode) {
this.countryCode = countryCode;
}
@Nullable
public String getCountryCode() {
return countryCode;
}
}

View file

@ -154,6 +154,15 @@ public class UploadModel {
contribution.setDateCreatedSource(item.getCreatedTimestampSource());
//Set the date only if you have it, else the upload service is gonna try it the other way
}
if (contribution.getWikidataPlace() != null) {
if (item.isWLMUpload()) {
contribution.getWikidataPlace().setMonumentUpload(true);
} else {
contribution.getWikidataPlace().setMonumentUpload(false);
}
}
contribution.setCountryCode(item.getCountryCode());
return contribution;
});
}

View file

@ -12,7 +12,7 @@ data class WikidataPlace(
val imageValue: String?,
val wikipediaArticle: String?,
val location: LatLng? = null,
val isMonumentUpload : Boolean =false
var isMonumentUpload : Boolean =false
) :
WikidataItem, Parcelable {
constructor(place: Place) : this(

View file

@ -21,6 +21,8 @@ public interface MediaLicenseContract {
void getLicenses();
void selectLicense(String licenseName);
boolean isWLMSupportedForThisPlace();
}
}

View file

@ -90,16 +90,11 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
initPresenter();
initLicenseSpinner();
presenter.getLicenses();
}
/**
* Show the wlm info message if the upload is a WLM upload
*/
if(callback.isWLMUpload()){
//TODO : Update the info message logo
llInfoMonumentUpload.setVisibility(View.VISIBLE);
}else{
llInfoMonumentUpload.setVisibility(View.GONE);
}
@Override
public void onResume() {
super.onResume();
}
/**
@ -229,4 +224,16 @@ public class MediaLicenseFragment extends UploadBaseFragment implements MediaLic
callback.onNextButtonClicked(callback.getIndexInViewFlipper(this));
}
@Override
protected void onBecameVisible() {
super.onBecameVisible();
/**
* Show the wlm info message if the upload is a WLM upload
*/
if(callback.isWLMUpload() && presenter.isWLMSupportedForThisPlace()){
llInfoMonumentUpload.setVisibility(View.VISIBLE);
}else{
llInfoMonumentUpload.setVisibility(View.GONE);
}
}
}

View file

@ -74,4 +74,9 @@ public class MediaLicensePresenter implements MediaLicenseContract.UserActionLis
repository.setSelectedLicense(licenseName);
view.updateLicenseSummary(repository.getSelectedLicense(), repository.getCount());
}
@Override
public boolean isWLMSupportedForThisPlace() {
return repository.isWMLSupportedForThisPlace();
}
}

View file

@ -7,9 +7,14 @@ import static fr.free.nrw.commons.utils.ImageUtils.FILE_NAME_EXISTS;
import static fr.free.nrw.commons.utils.ImageUtils.IMAGE_KEEP;
import static fr.free.nrw.commons.utils.ImageUtils.IMAGE_OK;
import android.location.Address;
import android.location.Geocoder;
import androidx.annotation.Nullable;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.filepicker.UploadableFile;
import fr.free.nrw.commons.kvstore.JsonKvStore;
import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.Place;
import fr.free.nrw.commons.repository.UploadRepository;
import fr.free.nrw.commons.upload.ImageCoordinates;
@ -22,10 +27,13 @@ import io.reactivex.Maybe;
import io.reactivex.Scheduler;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;
import java.io.IOException;
import java.lang.reflect.Proxy;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Named;
import org.jetbrains.annotations.NotNull;
@ -48,6 +56,8 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
private Scheduler ioScheduler;
private Scheduler mainThreadScheduler;
private final List<String> WLM_SUPPORTED_COUNTRIES= Arrays.asList("au","ie", "in");
@Inject
public UploadMediaPresenter(UploadRepository uploadRepository,
@Named("default_preferences") JsonKvStore defaultKVStore,
@ -77,18 +87,31 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
* @param place
*/
@Override
public void receiveImage(UploadableFile uploadableFile, Place place) {
public void receiveImage(final UploadableFile uploadableFile, final Place place) {
view.showProgress(true);
compositeDisposable.add(
repository
.preProcessImage(uploadableFile, place, this)
.map(uploadItem -> {
if(place!=null && place.isMonument()){
if (place.location != null) {
final String countryCode = reverseGeoCode(place.location);
if (countryCode != null && WLM_SUPPORTED_COUNTRIES
.contains(countryCode.toLowerCase())) {
uploadItem.setWLMUpload(true);
uploadItem.setCountryCode(countryCode.toLowerCase());
}
}
}
return uploadItem;
})
.subscribeOn(ioScheduler)
.observeOn(mainThreadScheduler)
.subscribe(uploadItem ->
{
view.onImageProcessed(uploadItem, place);
view.updateMediaDetails(uploadItem.getUploadMediaDetails());
ImageCoordinates gpsCoords = uploadItem.getGpsCoords();
final ImageCoordinates gpsCoords = uploadItem.getGpsCoords();
final boolean hasImageCoordinates =
gpsCoords != null && gpsCoords.getImageCoordsExists();
view.showMapWithImageCoordinates(hasImageCoordinates);
@ -100,6 +123,26 @@ public class UploadMediaPresenter implements UserActionListener, SimilarImageInt
throwable -> Timber.e(throwable, "Error occurred in processing images")));
}
@Nullable
private String reverseGeoCode(final LatLng latLng){
final Geocoder geocoder = new Geocoder(
CommonsApplication.getInstance().getApplicationContext(), Locale
.getDefault());
try {
final List<Address> addresses = geocoder
.getFromLocation(latLng.getLatitude(), latLng.getLongitude(), 1);
for (final Address address : addresses) {
if (address != null && address.getCountryCode() != null) {
String countryCode = address.getCountryCode();
return countryCode;
}
}
} catch (final IOException e) {
Timber.e(e);
}
return null;
}
/**
* This method checks for the nearest location that needs images and suggests it to the user.
* @param uploadItem

View file

@ -274,19 +274,10 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
Timber.d("Ensure uniqueness of filename");
val uniqueFileName = findUniqueFileName(filename!!)
try {
//Upload the file from stash
var countryCode: String? =null
with(contribution.wikidataPlace?.location){
if (contribution.wikidataPlace?.isMonumentUpload == true) {
countryCode =
reverseGeoCode(contribution.wikidataPlace?.location!!)?.toLowerCase()
}
}
val uploadResult = uploadClient.uploadFileFromStash(
contribution, uniqueFileName, stashUploadResult.fileKey, countryCode
contribution, uniqueFileName, stashUploadResult.fileKey
).blockingSingle()
if (uploadResult.isSuccessful()) {
@ -349,26 +340,6 @@ class UploadWorker(var appContext: Context, workerParams: WorkerParameters) :
}
}
private fun reverseGeoCode(latLng: LatLng): String? {
val geocoder = Geocoder(
CommonsApplication.getInstance().applicationContext, Locale
.getDefault()
)
try {
val addresses =
geocoder.getFromLocation(latLng.latitude, latLng.longitude, 1)
for (address in addresses) {
if (address != null && address.locale.isO3Country != null) {
return address.locale.country
}
}
} catch (e: IOException) {
Timber.e(e)
}
return null
}
private fun clearChunks(contribution: Contribution) {
contribution.chunkInfo=null
contributionDao.saveSynchronous(contribution)