Skip to content
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

Wiki itemname displaying in toast #3569

Merged
merged 6 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -68,6 +68,7 @@ public Contribution[] newArray(int i) {
public String decimalCoords;
public boolean isMultiple;
public String wikiDataEntityId;
public String wikiItemName;
macgills marked this conversation as resolved.
Show resolved Hide resolved
private String p18Value;
public Uri contentProviderUri;
public String dateCreatedSource;
Expand Down Expand Up @@ -263,6 +264,10 @@ public String getWikiDataEntityId() {
return wikiDataEntityId;
}

public String getWikiItemName() {
return wikiItemName;
}

/**
* When the corresponding wikidata entity is known as in case of nearby uploads, it can be set
* using the setter method
Expand All @@ -272,6 +277,10 @@ public void setWikiDataEntityId(String wikiDataEntityId) {
this.wikiDataEntityId = wikiDataEntityId;
}

public void setWikiItemName(String wikiItemName) {
this.wikiItemName = wikiItemName;
}

public String getP18Value() {
return p18Value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public Observable<Contribution> buildContributions() {
CommonsApplication.DEFAULT_EDIT_SUMMARY, item.gpsCoords.getDecimalCoords());
if (item.place != null) {
contribution.setWikiDataEntityId(item.place.getWikiDataEntityId());
contribution.setWikiItemName(item.place.getName());
// If item already has an image, we need to know it. We don't want to override existing image later
contribution.setP18Value(item.place.pic);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private void uploadContribution(Contribution contribution) {
Timber.d("Contribution upload success. Initiating Wikidata edit for"
+ " entity id %s if necessary (if P18 is null). P18 value is %s",
contribution.getWikiDataEntityId(), contribution.getP18Value());
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), canonicalFilename, contribution.getP18Value());
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), contribution.getWikiItemName(), canonicalFilename, contribution.getP18Value());
contribution.setFilename(canonicalFilename);
contribution.setImageUrl(uploadResult.getImageinfo().getOriginalUrl());
contribution.setState(Contribution.STATE_COMPLETED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class WikidataEditService {
* @param fileName name of the file we will upload
* @param p18Value pic attribute of Wikidata item
*/
public void createClaimWithLogging(String wikidataEntityId, String fileName, @NonNull String p18Value) {
public void createClaimWithLogging(String wikidataEntityId, String wikiItemName, String fileName, @NonNull String p18Value) {
if (wikidataEntityId == null) {
Timber.d("Skipping creation of claim as Wikidata entity ID is null");
return;
Expand All @@ -71,7 +71,7 @@ public void createClaimWithLogging(String wikidataEntityId, String fileName, @No
return;
}

editWikidataProperty(wikidataEntityId, fileName);
editWikidataProperty(wikidataEntityId, wikiItemName, fileName);
}

/**
Expand All @@ -82,7 +82,7 @@ public void createClaimWithLogging(String wikidataEntityId, String fileName, @No
* @param fileName
*/
@SuppressLint("CheckResult")
private void editWikidataProperty(String wikidataEntityId, String fileName) {
private void editWikidataProperty(String wikidataEntityId, String wikiItemName, String fileName) {
Timber.d("Upload successful with wiki data entity id as %s", wikidataEntityId);
Timber.d("Attempting to edit Wikidata property %s", wikidataEntityId);

Expand All @@ -98,18 +98,18 @@ private void editWikidataProperty(String wikidataEntityId, String fileName) {
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(revisionId -> handleClaimResult(wikidataEntityId, String.valueOf(revisionId)), throwable -> {
.subscribe(revisionId -> handleClaimResult(wikidataEntityId, wikiItemName, String.valueOf(revisionId)), throwable -> {
Timber.e(throwable, "Error occurred while making claim");
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
});
}

private void handleClaimResult(String wikidataEntityId, String revisionId) {
private void handleClaimResult(String wikidataEntityId, String wikiItemName, String revisionId) {
if (revisionId != null) {
if (wikidataEditListener != null) {
wikidataEditListener.onSuccessfulWikidataEdit();
}
showSuccessToast();
showSuccessToast(wikiItemName);
} else {
Timber.d("Unable to make wiki data edit for entity %s", wikidataEntityId);
ViewUtil.showLongToast(context, context.getString(R.string.wikidata_edit_failure));
Expand All @@ -119,8 +119,8 @@ private void handleClaimResult(String wikidataEntityId, String revisionId) {
/**
* Show a success toast when the edit is made successfully
*/
private void showSuccessToast() {
String title = directKvStore.getString("Title", "");
private void showSuccessToast(String wikiItemName) {
String title = wikiItemName;
macgills marked this conversation as resolved.
Show resolved Hide resolved
String successStringTemplate = context.getString(R.string.successful_wikidata_edit);
String successMessage = String.format(Locale.getDefault(), successStringTemplate, title);
ViewUtil.showLongToast(context, successMessage);
Expand Down