Skip to content
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 @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/fr/free/nrw/commons/db/AppDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,4 +300,8 @@ public Place checkNearbyPlaces(final double decLatitude, final double decLongitu
public void useSimilarPictureCoordinates(ImageCoordinates imageCoordinates, int uploadItemIndex) {
uploadModel.useSimilarPictureCoordinates(imageCoordinates, uploadItemIndex);
}

public boolean isWMLSupportedForThisPlace() {
return uploadModel.getItems().get(0).isWLMUpload();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As the place is same for all, checking this at least for one item will do the job

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public PageContentsCreator(final Context context) {
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
Expand Down Expand Up @@ -63,7 +63,7 @@ public String createFrom(final Contribution contribution, final String countryCo

if (contribution.getWikidataPlace()!=null && contribution.getWikidataPlace().isMonumentUpload()) {
buffer.append("{{Wiki Loves Monuments 2021|1= ")
.append(countryCode)
.append(contribution.getCountryCode())
.append("}}").append("\n");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ private RequestBody toRequestBody(@Nullable final String value) {
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 -> {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -87,6 +89,14 @@ public void setMediaDetails(final List<UploadMediaDetail> uploadMediaDetails) {
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)) {
Expand Down Expand Up @@ -121,4 +131,13 @@ public void setHasInvalidLocation(boolean hasInvalidLocation) {
public boolean hasInvalidLocation() {
return hasInvalidLocation;
}

public void setCountryCode(final String countryCode) {
this.countryCode = countryCode;
}

@Nullable
public String getCountryCode() {
return countryCode;
}
}
9 changes: 9 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ public Observable<Contribution> buildContributions() {
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;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ interface UserActionListener extends BasePresenter<View> {
void getLicenses();

void selectLicense(String licenseName);

boolean isWLMSupportedForThisPlace();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,11 @@ public void onClick(View v) {
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();
}

/**
Expand Down Expand Up @@ -229,4 +224,16 @@ public void onSubmitButtonClicked() {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,9 @@ public void selectLicense(String licenseName) {
repository.setSelectedLicense(licenseName);
view.updateLicenseSummary(repository.getSelectedLicense(), repository.getCount());
}

@Override
public boolean isWLMSupportedForThisPlace() {
return repository.isWMLSupportedForThisPlace();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
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;
Expand All @@ -22,10 +27,13 @@
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;
Expand All @@ -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,
Expand Down Expand Up @@ -77,18 +87,31 @@ public void onDetachView() {
* @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);
Expand All @@ -100,6 +123,26 @@ public void receiveImage(UploadableFile uploadableFile, Place place) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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)
Expand Down