Small refactoring

This commit is contained in:
Nazar-Kutz 2020-07-08 13:33:40 +03:00
parent 89a05082ac
commit 17ab336cfc
8 changed files with 68 additions and 206 deletions

View file

@ -471,7 +471,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
}
textPrefix = app.getString(R.string.poi_cuisine);
vl = sb.toString();
} else if (key.contains(Amenity.ROUTE) || key.contains(Amenity.WIKIDATA)) {
} else if (key.contains(Amenity.ROUTE) || key.equals(Amenity.WIKIDATA)) {
continue;
} else {
if (key.contains(Amenity.DESCRIPTION)) {

View file

@ -438,11 +438,12 @@ public abstract class ImageCard extends AbstractCard {
pms.put("lang", preferredLang);
}
if (this.params != null) {
pms.putAll(this.params);
String wikidataId = this.params.get("wikidata_id");
if (wikidataId != null) {
this.params.remove("wikidata_id");
WikiImageHelper.fillWikiMediaCards(mapActivity, wikidataId, result);
}
pms.putAll(this.params);
}
String response = AndroidNetworkUtils.sendRequest(app, "https://osmand.net/api/cm_place", pms,
"Requesting location images...", false, false);

View file

@ -4,13 +4,13 @@ import androidx.annotation.NonNull;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import net.osmand.PlatformUtil;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.wikimedia.pojo.P18;
import net.osmand.plus.wikimedia.pojo.WikipediaResponse;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
@ -47,8 +47,8 @@ public class WikiImageHelper {
} catch (JsonSyntaxException e) {
error = e.getLocalizedMessage();
}
LOG.error(error);
}
LOG.error(error);
} else {
LOG.error("Wrong WikiMedia ID");
}
@ -56,10 +56,10 @@ public class WikiImageHelper {
public static List<WikiImage> getImageData(WikipediaResponse response) {
List<WikiImage> images = new ArrayList<>();
try {
for (P18 p18 : response.getClaims().getP18()) {
String imageFileName = p18.getMainsnak().getDatavalue().getValue();
if (imageFileName != null) {
for (P18 p18 : response.claims.p18) {
String imageFileName = p18.mainsnak.datavalue.value;
if (imageFileName != null) {
try {
String imageName = URLDecoder.decode(imageFileName, "UTF-8");
imageFileName = imageName.replace(" ", "_");
imageName = imageName.substring(0, imageName.lastIndexOf("."));
@ -73,11 +73,12 @@ public class WikiImageHelper {
imageFileName + "/" + THUMB_SIZE + "px-" +
imageFileName;
images.add(new WikiImage(imageName, imageStubUrl,
imageHiResUrl, p18.getMainsnak().getDatatype()));
imageHiResUrl, p18.mainsnak.datatype));
} catch (UnsupportedEncodingException e) {
LOG.error(e.getLocalizedMessage());
}
}
} catch (UnsupportedEncodingException e) {
LOG.error(e.getLocalizedMessage());
}
return images;
}
@ -87,4 +88,58 @@ public class WikiImageHelper {
String md5 = new String(Hex.encodeHex(DigestUtils.md5(s)));
return new String[]{md5.substring(0, 1), md5.substring(0, 2)};
}
private class Claims {
@SerializedName("P18")
@Expose
private List<P18> p18 = null;
}
public class Datavalue {
@SerializedName("value")
@Expose
private String value;
@SerializedName("type")
@Expose
private String type;
}
public class Mainsnak {
@SerializedName("snaktype")
@Expose
private String snaktype;
@SerializedName("property")
@Expose
private String property;
@SerializedName("hash")
@Expose
private String hash;
@SerializedName("datavalue")
@Expose
private Datavalue datavalue;
@SerializedName("datatype")
@Expose
private String datatype;
}
public 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 {
@SerializedName("claims")
@Expose
private Claims claims;
}
}

View file

@ -1,22 +0,0 @@
package net.osmand.plus.wikimedia.pojo;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Claims {
@SerializedName("P18")
@Expose
private List<P18> p18 = null;
public List<P18> getP18() {
return p18;
}
public void setP18(List<P18> p18) {
this.p18 = p18;
}
}

View file

@ -1,32 +0,0 @@
package net.osmand.plus.wikimedia.pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Datavalue {
@SerializedName("value")
@Expose
private String value;
@SerializedName("type")
@Expose
private String type;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}

View file

@ -1,65 +0,0 @@
package net.osmand.plus.wikimedia.pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Mainsnak {
@SerializedName("snaktype")
@Expose
private String snaktype;
@SerializedName("property")
@Expose
private String property;
@SerializedName("hash")
@Expose
private String hash;
@SerializedName("datavalue")
@Expose
private Datavalue datavalue;
@SerializedName("datatype")
@Expose
private String datatype;
public String getSnaktype() {
return snaktype;
}
public void setSnaktype(String snaktype) {
this.snaktype = snaktype;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public String getHash() {
return hash;
}
public void setHash(String hash) {
this.hash = hash;
}
public Datavalue getDatavalue() {
return datavalue;
}
public void setDatavalue(Datavalue datavalue) {
this.datavalue = datavalue;
}
public String getDatatype() {
return datatype;
}
public void setDatatype(String datatype) {
this.datatype = datatype;
}
}

View file

@ -1,54 +0,0 @@
package net.osmand.plus.wikimedia.pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public 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 Mainsnak getMainsnak() {
return mainsnak;
}
public void setMainsnak(Mainsnak mainsnak) {
this.mainsnak = mainsnak;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
}

View file

@ -1,21 +0,0 @@
package net.osmand.plus.wikimedia.pojo;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class WikipediaResponse {
@SerializedName("claims")
@Expose
private Claims claims;
public Claims getClaims() {
return claims;
}
public void setClaims(Claims claims) {
this.claims = claims;
}
}