Fixes #3790- Use WorkManagers to upload contributions (#4298)

* Fixes #3790
Use WorkManagers to process upload contributions
** Removed UploadService and Added UploadWorker to process contributions Upload
** Made nescessary changes to remove the usages of the Service from the classes
** UI Fxies- Minor changes in the retry and cancel uplaod icons to give them a clickable area of 48 dp

* Fixes #3790
Use WorkManagers to process upload contributions
** Removed UploadService and Added UploadWorker to process contributions Upload
** Made nescessary changes to remove the usages of the Service from the classes
** UI Fxies- Minor changes in the retry and cancel uplaod icons to give them a clickable area of 48 dp

* Updated JavaDocs in UploadWorker, Fixed Test cases

* Updated JavaDocs in UploadWorker, Fixed Test cases

* Updated gradle

* Revert "Updated gradle"

This reverts commit c8979fe6dc.

* rolledback to compileSDKVersion 28, fixed tests

* Don't call the show notifications on the main thread

* Bug Fix- Duplicate contributions, handle upload stash errors
This commit is contained in:
Ashish 2021-04-08 18:29:07 +05:30 committed by GitHub
parent fd2a7a9c56
commit ecbff7e3b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 692 additions and 802 deletions

View file

@ -16,13 +16,11 @@ import fr.free.nrw.commons.upload.WikidataPlace;
import fr.free.nrw.commons.utils.ConfigUtils;
import fr.free.nrw.commons.utils.ViewUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -139,17 +137,17 @@ public class WikidataEditService {
}
}
public void createClaim(@Nullable final WikidataPlace wikidataPlace, final String fileName, final
public Long createClaim(@Nullable final WikidataPlace wikidataPlace, final String fileName, final
Map<String, String> captions) {
if (!(directKvStore.getBoolean("Picture_Has_Correct_Location", true))) {
Timber
.d("Image location and nearby place location mismatched, so Wikidata item won't be edited");
return;
return null;
}
addImageAndMediaLegends(wikidataPlace, fileName, captions);
return addImageAndMediaLegends(wikidataPlace, fileName, captions);
}
public void addImageAndMediaLegends(final WikidataItem wikidataItem, final String fileName,
public Long addImageAndMediaLegends(final WikidataItem wikidataItem, final String fileName,
final Map<String, String> captions) {
final Snak_partial p18 = new Snak_partial("value", WikidataProperties.IMAGE.getPropertyName(),
new ValueString(fileName.replace("File:", "")));
@ -166,17 +164,10 @@ public class WikidataEditService {
Collections.singletonMap(WikidataProperties.MEDIA_LEGENDS.getPropertyName(), snaks),
Arrays.asList(WikidataProperties.MEDIA_LEGENDS.getPropertyName()));
wikidataClient.setClaim(claim, COMMONS_APP_TAG).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(revisionId -> handleImageClaimResult(wikidataItem, String.valueOf(revisionId)),
throwable -> {
Timber.e(throwable, "Error occurred while making claim");
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
});
;
return wikidataClient.setClaim(claim, COMMONS_APP_TAG).blockingSingle();
}
private void handleImageClaimResult(final WikidataItem wikidataItem, final String revisionId) {
public void handleImageClaimResult(final WikidataItem wikidataItem, final Long revisionId) {
if (revisionId != null) {
if (wikidataEditListener != null) {
wikidataEditListener.onSuccessfulWikidataEdit();