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 @@ -24,6 +24,7 @@
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_CAMERA;
import static fr.free.nrw.commons.contributions.Contribution.SOURCE_GALLERY;
import static fr.free.nrw.commons.upload.UploadService.EXTRA_SOURCE;
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;

public class ContributionController {

Expand Down Expand Up @@ -91,6 +92,7 @@ public void startGalleryPick() {
}

public void handleImagePicked(int requestCode, Intent data, boolean isDirectUpload, String wikiDataEntityId) {
Timber.d("Is direct upload %s and the Wikidata entity ID is %s", isDirectUpload, wikiDataEntityId);
FragmentActivity activity = fragment.getActivity();
Timber.d("handleImagePicked() called with onActivityResult()");
Intent shareIntent = new Intent(activity, ShareActivity.class);
Expand Down Expand Up @@ -119,7 +121,7 @@ public void handleImagePicked(int requestCode, Intent data, boolean isDirectUplo
try {
shareIntent.putExtra("isDirectUpload", isDirectUpload);
if (wikiDataEntityId != null && !wikiDataEntityId.equals("")) {
shareIntent.putExtra("wikiDataEntityId", wikiDataEntityId);
shareIntent.putExtra(WIKIDATA_ENTITY_ID_PREF, wikiDataEntityId);
}
activity.startActivity(shareIntent);
} catch (SecurityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;

public class NearbyListFragment extends DaggerFragment {
private Bundle bundleForUpdates; // Carry information from activity about changed nearby places and current location
Expand Down Expand Up @@ -146,7 +147,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@

import static android.app.Activity.RESULT_OK;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;

public class NearbyMapFragment extends DaggerFragment {

Expand Down Expand Up @@ -711,15 +712,15 @@ private void passInfoToSheet(Place place) {

fabCamera.setOnClickListener(view -> {
if (fabCamera.isShown()) {
Timber.d("Camera button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
Timber.d("Camera button tapped. Place: %s", place.toString());
storeSharedPrefs();
directUpload.initiateCameraUpload();
}
});

fabGallery.setOnClickListener(view -> {
if (fabGallery.isShown()) {
Timber.d("Gallery button tapped. Image title: " + place.getName() + "Image desc: " + place.getLongDescription());
Timber.d("Gallery button tapped. Place: %s", place.toString());
storeSharedPrefs();
directUpload.initiateGalleryUpload();
}
Expand All @@ -731,7 +732,7 @@ void storeSharedPrefs() {
editor.putString("Title", place.getName());
editor.putString("Desc", place.getLongDescription());
editor.putString("Category", place.getCategory());
editor.putString("WikiDataEntityId", place.getWikiDataEntityId());
editor.putString(WIKIDATA_ENTITY_ID_PREF, place.getWikiDataEntityId());
editor.apply();
}

Expand Down Expand Up @@ -767,7 +768,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data, true, directPrefs.getString("WikiDataEntityId", null));
controller.handleImagePicked(requestCode, data, true, directPrefs.getString(WIKIDATA_ENTITY_ID_PREF, null));
} else {
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/java/fr/free/nrw/commons/nearby/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import timber.log.Timber;

public class Place {

Expand Down Expand Up @@ -58,10 +59,12 @@ public void setDistance(String distance) {
@Nullable
public String getWikiDataEntityId() {
if (!hasWikidataLink()) {
Timber.d("Wikidata entity ID is null for place with sitelink %s", siteLinks.toString());
return null;
}

String wikiDataLink = siteLinks.getWikidataLink().toString();
Timber.d("Wikidata entity is %s", wikiDataLink);
return wikiDataLink.replace("http://www.wikidata.org/entity/", "");
}

Expand Down Expand Up @@ -94,7 +97,18 @@ public int hashCode() {

@Override
public String toString() {
return String.format("Place(%s@%s)", name, location);
return "Place{" +
"name='" + name + '\'' +
", label='" + label + '\'' +
", longDescription='" + longDescription + '\'' +
", secondaryImageUrl='" + secondaryImageUrl + '\'' +
", location='" + location + '\'' +
", category='" + category + '\'' +
", image='" + image + '\'' +
", secondaryImage=" + secondaryImage +
", distance='" + distance + '\'' +
", siteLinks='" + siteLinks.toString() + '\'' +
'}';
}

/**
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/fr/free/nrw/commons/nearby/Sitelinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ private static Uri sanitiseString(String stringUrl) {
return Uri.parse(sanitisedStringUrl);
}

@Override
public String toString() {
return "Sitelinks{" +
"wikipediaLink='" + wikipediaLink + '\'' +
", commonsLink='" + commonsLink + '\'' +
", wikidataLink='" + wikidataLink + '\'' +
'}';
}

private Sitelinks(Sitelinks.Builder builder) {
this.wikidataLink = builder.wikidataLink;
this.wikipediaLink = builder.wikipediaLink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.DUPLICATE_PROCEED;
import static fr.free.nrw.commons.upload.ExistingFileAsync.Result.NO_DUPLICATE;
import static fr.free.nrw.commons.upload.FileUtils.getSHA1;
import static fr.free.nrw.commons.wikidata.WikidataConstants.WIKIDATA_ENTITY_ID_PREF;

/**
* Activity for the title/desc screen after image is selected. Also starts processing image
Expand Down Expand Up @@ -325,6 +326,8 @@ private void receiveImageIntent() {
if (intent.hasExtra("isDirectUpload")) {
Timber.d("This was initiated by a direct upload from Nearby");
isNearbyUpload = true;
wikiDataEntityId = intent.getStringExtra(WIKIDATA_ENTITY_ID_PREF);
Timber.d("Received wikiDataEntityId from contribution controller %s", wikiDataEntityId);
}
mimeType = intent.getType();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.free.nrw.commons.upload;

import android.annotation.SuppressLint;
import android.accounts.Account;
import android.content.ComponentName;
import android.content.ContentResolver;
Expand Down Expand Up @@ -98,6 +99,7 @@ public void cleanup() {
public void startUpload(String title, Uri mediaUri, String description, String mimeType, String source, String decimalCoords, String wikiDataEntityId, ContributionUploadProgress onComplete) {
Contribution contribution;

Timber.d("Wikidata entity ID received from Share activity is %s", wikiDataEntityId);
//TODO: Modify this to include coords
Account currentAccount = sessionManager.getCurrentAccount();
if(currentAccount == null) {
Expand All @@ -124,6 +126,7 @@ public void startUpload(String title, Uri mediaUri, String description, String m
* @param contribution the contribution object
* @param onComplete the progress tracker
*/
@SuppressLint("StaticFieldLeak")
public void startUpload(final Contribution contribution, final ContributionUploadProgress onComplete) {
//Set creator, desc, and license
if (TextUtils.isEmpty(contribution.getCreator())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,10 @@ private void uploadContribution(Contribution contribution) {

String resultStatus = uploadResult.getResultStatus();
if (!resultStatus.equals("Success")) {
Timber.d("Contribution upload failed. Wikidata entity won't be edited");
showFailedNotification(contribution);
} else {
Timber.d("Contribution upload success. Initiating Wikidata edit for entity id %s", contribution.getWikiDataEntityId());
wikidataEditService.createClaimWithLogging(contribution.getWikiDataEntityId(), filename);
contribution.setFilename(uploadResult.getCanonicalFilename());
contribution.setImageUrl(uploadResult.getImageUrl());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package fr.free.nrw.commons.wikidata;

public class WikidataConstants {
public static final String WIKIDATA_ENTITY_ID_PREF = "WikiDataEntityId";
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ public WikidataEditService(Context context,
* @param fileName
*/
public void createClaimWithLogging(String wikidataEntityId, String fileName) {
if(wikidataEntityId == null
|| fileName == null) {
if(wikidataEntityId == null) {
Timber.d("Skipping creation of claim as Wikidata entity ID is null");
return;
}

if(fileName == null) {
Timber.d("Skipping creation of claim as fileName entity ID is null");
return;
}

editWikidataProperty(wikidataEntityId, fileName);
}

Expand Down