Fixed 4616 : Option for editing depictions (#4725)

* Dialog can't be dismissed

* Dialog can't be dismissed

* Option for editing depiction

* Java docs added

* Minor issues fixed

* Lining done

* "Depictions not updating instantly" issue resolved

* Existing Depicts on the top

* Existing Depicts on the top

* Back press handled

* Previous depictions unchecked

* Whole Screen issue fixed

* Nearby banner removed

* Test fixed

* Upload Wizard issue fixed

* Upload Wizard issue fixed

* Previous depicts issue fixed

* Previous depicts issue fixed

* All issues fixed

* Fixed late loading of updated depicts

* Depiction is removable

* Test fixed

* Back button press handled after losing focus for edittext

* RequiresApi removed

* RequiresApi removed

* Test fixed

* Requested changes

* Test added

* Test added

* UploadModelUnitTest added

* DepictEditHelperUnitTest added

* DepictEditHelperUnitTest added

* Test added

* More test added

* Indentation Reversed

* Indentation reversed

* Update MediaDetailFragment.java

* Indentation reversed

* Update MediaDetailFragment.java

* Indentation reversed

* Indentation reversed

* Indentation reversed

* Indentation reversed

* More test added

* More test added

* Minor fixes

* Minor fixes

* Minor fixes
This commit is contained in:
Ayan Sarkar 2022-03-22 11:03:43 +05:30 committed by GitHub
parent e58322ed63
commit bd9531b969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 1261 additions and 75 deletions

View file

@ -1,7 +1,7 @@
package fr.free.nrw.commons.wikidata;
import static fr.free.nrw.commons.media.MediaClientKt.PAGE_ID_PREFIX;
import static fr.free.nrw.commons.di.NetworkingModule.NAMED_COMMONS_CSRF;
import static fr.free.nrw.commons.media.MediaClientKt.PAGE_ID_PREFIX;
import fr.free.nrw.commons.upload.UploadResult;
import fr.free.nrw.commons.upload.WikiBaseInterface;
@ -35,6 +35,20 @@ public class WikiBaseClient {
.map(response -> (response.getSuccessVal() == 1)));
}
/**
* Makes the server call for posting new depicts
*
* @param filename name of the file
* @param data data of the depicts to be uploaded
* @return Observable<Boolean>
*/
public Observable<Boolean> postEditEntityByFilename(final String filename, final String data) {
return csrfToken()
.switchMap(editToken -> wikiBaseInterface.postEditEntityByFilename(filename,
editToken, data)
.map(response -> (response.getSuccessVal() == 1)));
}
public Observable<Long> getFileEntityId(UploadResult uploadResult) {
return wikiBaseInterface.getFileEntityId(uploadResult.createCanonicalFileName())
.map(response -> (long) (response.query().pages().get(0).pageId()));

View file

@ -16,7 +16,6 @@ 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.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import java.util.ArrayList;
import java.util.Arrays;
@ -73,11 +72,12 @@ public class WikidataEditService {
*/
@SuppressLint("CheckResult")
private Observable<Boolean> addDepictsProperty(final String fileEntityId,
final WikidataItem depictedItem) {
final List<String> depictedItems) {
final EditClaim data = editClaim(
ConfigUtils.isBetaFlavour() ? "Q10" // Wikipedia:Sandbox (Q10)
: depictedItem.getId()
ConfigUtils.isBetaFlavour() ? Collections.singletonList("Q10")
// Wikipedia:Sandbox (Q10)
: depictedItems
);
return wikiBaseClient.postEditEntity(PAGE_ID_PREFIX + fileEntityId, gson.toJson(data))
@ -95,8 +95,42 @@ public class WikidataEditService {
.subscribeOn(Schedulers.io());
}
private EditClaim editClaim(final String entityId) {
return EditClaim.from(entityId, WikidataProperties.DEPICTS.getPropertyName());
/**
* Takes depicts ID as a parameter and create a uploadable data with the Id
* and send the data for POST operation
*
* @param filename name of the file
* @param depictedItems ID of the selected depict item
* @return Observable<Boolean>
*/
@SuppressLint("CheckResult")
public Observable<Boolean> updateDepictsProperty(final String filename,
final List<String> depictedItems) {
final EditClaim data = editClaim(
ConfigUtils.isBetaFlavour() ? Collections.singletonList("Q10")
// Wikipedia:Sandbox (Q10)
: depictedItems
);
return wikiBaseClient.postEditEntityByFilename(filename,
gson.toJson(data))
.doOnNext(success -> {
if (success) {
Timber.d("DEPICTS property was set successfully for %s", filename);
} else {
Timber.d("Unable to set DEPICTS property for %s", filename);
}
})
.doOnError(throwable -> {
Timber.e(throwable, "Error occurred while setting DEPICTS property");
ViewUtil.showLongToast(context, throwable.toString());
})
.subscribeOn(Schedulers.io());
}
private EditClaim editClaim(final List<String> entityIds) {
return EditClaim.from(entityIds, WikidataProperties.DEPICTS.getPropertyName());
}
/**
@ -209,7 +243,12 @@ public class WikidataEditService {
}
private Observable<Boolean> depictionEdits(Contribution contribution, Long fileEntityId) {
return Observable.fromIterable(contribution.getDepictedItems())
.concatMap(wikidataItem -> addDepictsProperty(fileEntityId.toString(), wikidataItem));
final List<String> depictIDs = new ArrayList<>();
for (final WikidataItem wikidataItem :
contribution.getDepictedItems()) {
depictIDs.add(wikidataItem.getId());
}
return addDepictsProperty(fileEntityId.toString(), depictIDs);
}
}