[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Retrofit ImageLicenseFetchTask
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351692 ) Change subject: Retrofit ImageLicenseFetchTask .. Retrofit ImageLicenseFetchTask Port ImageLicenseFetchTask to Retrofit and try to stay as consistent as possible with the existing code. Bug: T152406 Change-Id: Ib6ad70b969507aaad7356fce2e2e9bf27aaaeddc --- A app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java M app/src/main/java/org/wikipedia/gallery/GalleryItem.java A app/src/main/java/org/wikipedia/page/ImageLicenseFetchClient.java D app/src/main/java/org/wikipedia/page/ImageLicenseFetchTask.java M app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java A app/src/test/java/org/wikipedia/page/ImageLicenseFetchClientTest.java A app/src/test/res/raw/image_license.json 7 files changed, 402 insertions(+), 72 deletions(-) Approvals: jenkins-bot: Verified Mholloway: Looks good to me, approved diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java new file mode 100644 index 000..ff42026 --- /dev/null +++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java @@ -0,0 +1,76 @@ +package org.wikipedia.dataclient.mwapi; + +import android.support.annotation.Nullable; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class MwQueryImageLicensePage extends MwQueryPage { +@SuppressWarnings("unused") @Nullable private List imageinfo; + +public String imageLicense() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().license() != null +? imageinfo.get(0).extmetadata().license().value() : ""; +} + +public String imageLicenseShortName() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().licenseShortName() != null +? imageinfo.get(0).extmetadata().licenseShortName().value() : ""; +} + +public String imageLicenseUrl() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().licenseUrl() != null +? imageinfo.get(0).extmetadata().licenseUrl().value() : ""; +} + +static class ImageInfo { +@SuppressWarnings("unused") private Extmetadata extmetadata; +Extmetadata extmetadata() { +return extmetadata; +} +} + +static class Extmetadata { +@SuppressWarnings("unused") @SerializedName("License") private License license; +@SuppressWarnings("unused") @SerializedName("LicenseShortName") private LicenseShortName licenseShortName; +@SuppressWarnings("unused") @SerializedName("LicenseUrl") private LicenseUrl licenseUrl; + +License license() { +return license; +} +LicenseShortName licenseShortName() { +return licenseShortName; +} +LicenseUrl licenseUrl() { +return licenseUrl; +} +} + +static class License { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} + +static class LicenseShortName { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} + +static class LicenseUrl { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} +} diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryItem.java b/app/src/main/java/org/wikipedia/gallery/GalleryItem.java index cd1ace8..f5841ca 100644 --- a/app/src/main/java/org/wikipedia/gallery/GalleryItem.java +++ b/app/src/main/java/org/wikipedia/gallery/GalleryItem.java @@ -7,7 +7,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.wikipedia.page.ImageLicense; -import org.wikipedia.page.ImageLicenseFetchTask; import java.util.HashMap; import java.util.Iterator; @@ -149,9 +148,21 @@ String value = extmetadata.getJSONObject(key).getString("value"); metadata.put(key, value); } -license = ImageLicenseFetchTask.imageLicenseFromMetadata(extmetadata); +license = imageLicenseFromMetadata(extmetadata); } else { license = new ImageLicense(); } } + +@NonNull +public static ImageLicense imageLicenseFromMetadata(JSONObject extmetadata) { +return new ImageLicense(getValueForOptionalKey(extmetadata, "License"), +getValueForOptionalKey(extmetadata, "LicenseShortName"), +getValueForOptionalKey(extm
[MediaWiki-commits] [Gerrit] apps...wikipedia[master]: Retrofit ImageLicenseFetchTask
Jcasariego has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/351692 ) Change subject: Retrofit ImageLicenseFetchTask .. Retrofit ImageLicenseFetchTask Port ImageLicenseFetchTask to Retrofit and try to stay as consistent as possible with the existing code. Bug T152406 Change-Id: Ib6ad70b969507aaad7356fce2e2e9bf27aaaeddc --- A app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java M app/src/main/java/org/wikipedia/gallery/GalleryItem.java A app/src/main/java/org/wikipedia/page/ImageLicenseFetchClient.java D app/src/main/java/org/wikipedia/page/ImageLicenseFetchTask.java M app/src/main/java/org/wikipedia/page/snippet/ShareHandler.java A app/src/test/java/org/wikipedia/page/ImageLicenseFetchClientTest.java A app/src/test/res/raw/image_license.json 7 files changed, 403 insertions(+), 73 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia refs/changes/92/351692/1 diff --git a/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java new file mode 100644 index 000..5a371f6 --- /dev/null +++ b/app/src/main/java/org/wikipedia/dataclient/mwapi/MwQueryImageLicensePage.java @@ -0,0 +1,76 @@ +package org.wikipedia.dataclient.mwapi; + +import android.support.annotation.Nullable; + +import java.util.List; + +public class MwQueryImageLicensePage extends MwQueryPage { +@SuppressWarnings("unused") @Nullable private List imageinfo; + +public String imageLicense() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().license() != null +? imageinfo.get(0).extmetadata().license().value() : ""; +} + +public String imageLicenseShortName() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().licenseShortName() != null +? imageinfo.get(0).extmetadata().licenseShortName().value() : ""; +} + +public String imageLicenseUrl() { +return imageinfo != null +&& imageinfo.get(0).extmetadata() != null +&& imageinfo.get(0).extmetadata().licenseUrl() != null +? imageinfo.get(0).extmetadata().licenseUrl().value() : ""; +} + +static class ImageInfo { +@SuppressWarnings("unused") private Extmetadata extmetadata; +Extmetadata extmetadata() { +return extmetadata; +} +} + +static class Extmetadata { +@SuppressWarnings({"unused", "CheckStyle"}) private License License; +@SuppressWarnings({"unused", "CheckStyle"}) private LicenseShortName LicenseShortName; +@SuppressWarnings({"unused", "CheckStyle"}) private LicenseUrl LicenseUrl; + +License license() { +return License; +} + +LicenseShortName licenseShortName() { +return LicenseShortName; +} + +LicenseUrl licenseUrl() { +return LicenseUrl; +} +} + +static class License { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} + +static class LicenseShortName { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} + +static class LicenseUrl { +@SuppressWarnings("unused") private String value; +String value() { +return value; +} +} +} diff --git a/app/src/main/java/org/wikipedia/gallery/GalleryItem.java b/app/src/main/java/org/wikipedia/gallery/GalleryItem.java index cd1ace8..f5841ca 100644 --- a/app/src/main/java/org/wikipedia/gallery/GalleryItem.java +++ b/app/src/main/java/org/wikipedia/gallery/GalleryItem.java @@ -7,7 +7,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.wikipedia.page.ImageLicense; -import org.wikipedia.page.ImageLicenseFetchTask; import java.util.HashMap; import java.util.Iterator; @@ -149,9 +148,21 @@ String value = extmetadata.getJSONObject(key).getString("value"); metadata.put(key, value); } -license = ImageLicenseFetchTask.imageLicenseFromMetadata(extmetadata); +license = imageLicenseFromMetadata(extmetadata); } else { license = new ImageLicense(); } } + +@NonNull +public static ImageLicense imageLicenseFromMetadata(JSONObject extmetadata) { +return new ImageLicense(getValueForOptionalKey(extmetadata, "License"), +getValueForOptionalKey(extmetadata, "LicenseShortName"), +getValueForOptionalKey(extmetadata, "LicenseUrl")); +} + +@NonNull +private static String getValueForOp