From a08ac1fa0112d562d3db155cea95646e8183a9b9 Mon Sep 17 00:00:00 2001 From: Nazar-Kutz Date: Wed, 8 Jul 2020 14:36:11 +0300 Subject: [PATCH] Small refactoring p.2 --- .../net/osmand/plus/wikimedia/WikiImage.java | 7 +--- .../osmand/plus/wikimedia/WikiImageCard.java | 7 ++-- .../plus/wikimedia/WikiImageHelper.java | 37 +++++-------------- 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImage.java b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImage.java index d442afbb4e..d545b024e6 100644 --- a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImage.java +++ b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImage.java @@ -5,14 +5,12 @@ public class WikiImage { private String imageName; private String imageStubUrl; private String imageHiResUrl; - private String datatype; public WikiImage(String imageName, String imageStubUrl, - String imageHiResUrl, String datatype) { + String imageHiResUrl) { this.imageName = imageName; this.imageStubUrl = imageStubUrl; this.imageHiResUrl = imageHiResUrl; - this.datatype = datatype; } public String getImageName() { @@ -27,7 +25,4 @@ public class WikiImage { return imageHiResUrl; } - public String getDatatype() { - return datatype; - } } diff --git a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageCard.java b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageCard.java index db4ccef2ea..e423e3daa5 100644 --- a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageCard.java +++ b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageCard.java @@ -7,19 +7,18 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard; import net.osmand.util.Algorithms; -import org.json.JSONObject; - public class WikiImageCard extends ImageCard { - public WikiImageCard(final MapActivity mapActivity, final JSONObject imageObject, + public WikiImageCard(final MapActivity mapActivity, final WikiImage wikiImage) { - super(mapActivity, imageObject); + super(mapActivity, null); if (topIconId == 0) { topIconId = R.drawable.ic_logo_wikimedia; } this.imageUrl = wikiImage.getImageStubUrl(); + this.title = wikiImage.getImageName(); this.url = this.imageUrl; View.OnClickListener onClickListener = new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageHelper.java b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageHelper.java index 59a53ba54e..eded246941 100644 --- a/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikimedia/WikiImageHelper.java @@ -41,7 +41,7 @@ public class WikiImageHelper { Gson gson = new Gson(); WikipediaResponse response = gson.fromJson(rawResponse.toString(), WikipediaResponse.class); for (WikiImage img : getImageData(response)) { - images.add(new WikiImageCard(mapActivity, null, img)); + images.add(new WikiImageCard(mapActivity, img)); } return; } catch (JsonSyntaxException e) { @@ -54,7 +54,7 @@ public class WikiImageHelper { } } - public static List getImageData(WikipediaResponse response) { + private static List getImageData(WikipediaResponse response) { List images = new ArrayList<>(); for (P18 p18 : response.claims.p18) { String imageFileName = p18.mainsnak.datavalue.value; @@ -72,8 +72,7 @@ public class WikiImageHelper { urlHashParts[0] + "/" + urlHashParts[1] + "/" + imageFileName + "/" + THUMB_SIZE + "px-" + imageFileName; - images.add(new WikiImage(imageName, imageStubUrl, - imageHiResUrl, p18.mainsnak.datatype)); + images.add(new WikiImage(imageName, imageStubUrl, imageHiResUrl)); } catch (UnsupportedEncodingException e) { LOG.error(e.getLocalizedMessage()); @@ -84,18 +83,18 @@ public class WikiImageHelper { } @NonNull - public static String[] getHash(@NonNull String s) { + private static String[] getHash(@NonNull String s) { String md5 = new String(Hex.encodeHex(DigestUtils.md5(s))); return new String[]{md5.substring(0, 1), md5.substring(0, 2)}; } - private class Claims { + private static class Claims { @SerializedName("P18") @Expose private List p18 = null; } - public class Datavalue { + private static class Datavalue { @SerializedName("value") @Expose private String value; @@ -104,16 +103,7 @@ public class WikiImageHelper { private String type; } - public class Mainsnak { - @SerializedName("snaktype") - @Expose - private String snaktype; - @SerializedName("property") - @Expose - private String property; - @SerializedName("hash") - @Expose - private String hash; + private static class Mainsnak { @SerializedName("datavalue") @Expose private Datavalue datavalue; @@ -122,22 +112,13 @@ public class WikiImageHelper { private String datatype; } - public class P18 { + private static class P18 { @SerializedName("mainsnak") @Expose private Mainsnak mainsnak; - @SerializedName("type") - @Expose - private String type; - @SerializedName("id") - @Expose - private String id; - @SerializedName("rank") - @Expose - private String rank; } - public class WikipediaResponse { + private static class WikipediaResponse { @SerializedName("claims") @Expose private Claims claims;