mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Fixed nearby query to show read article link only for wikipedia articles
This commit is contained in:
parent
a41323f91e
commit
ddd5e602a9
6 changed files with 143 additions and 31 deletions
|
|
@ -6,7 +6,8 @@ SELECT
|
|||
(SAMPLE(COALESCE(?class_label_preferred_language, ?class_label_any_language, "?")) as ?class_label)
|
||||
(SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
|
||||
(SAMPLE(COALESCE(?emoji0, ?emoji1)) as ?emoji)
|
||||
(SAMPLE(?sitelink) as ?sitelink)
|
||||
?wikipediaArticle
|
||||
?commonsArticle
|
||||
WHERE {
|
||||
# Around given location...
|
||||
SERVICE wikibase:around {
|
||||
|
|
@ -37,7 +38,18 @@ SELECT
|
|||
OPTIONAL {
|
||||
?sitelink schema:about ?item .
|
||||
?sitelink schema:inLanguage "en"
|
||||
}
|
||||
}
|
||||
OPTIONAL {
|
||||
?wikipediaArticle schema:about ?item ;
|
||||
schema:isPartOf <https://en.wikipedia.org/> .
|
||||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
|
||||
}
|
||||
|
||||
OPTIONAL {
|
||||
?commonsArticle schema:about ?item ;
|
||||
schema:isPartOf <https://commons.wikimedia.org/> .
|
||||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
|
||||
}
|
||||
}
|
||||
}
|
||||
GROUP BY ?item
|
||||
GROUP BY ?item ?wikipediaArticle ?commonsArticle
|
||||
|
|
@ -14,7 +14,6 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.Utils;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.ui.widget.OverlayDialog;
|
||||
import fr.free.nrw.commons.utils.DialogUtil;
|
||||
|
|
@ -25,8 +24,7 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
private final static String ARG_DESC = "placeDesc";
|
||||
private final static String ARG_LATITUDE = "latitude";
|
||||
private final static String ARG_LONGITUDE = "longitude";
|
||||
private final static String ARG_ARTICLE_LINK = "articleLink";
|
||||
private final static String ARG_WIKI_DATA_LINK = "wikiDataLink";
|
||||
private final static String ARG_SITE_LINK = "sitelink";
|
||||
|
||||
@BindView(R.id.link_preview_title)
|
||||
TextView placeTitle;
|
||||
|
|
@ -58,15 +56,10 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
}
|
||||
|
||||
private void getArticleLink(Bundle bundle) {
|
||||
String articleLink = bundle.getString(ARG_ARTICLE_LINK);
|
||||
articleLink = articleLink.replace("<", "").replace(">", "");
|
||||
Sitelinks sitelinks = bundle.getParcelable(ARG_SITE_LINK);
|
||||
|
||||
if (Utils.isNullOrWhiteSpace(articleLink) || articleLink == "\n") {
|
||||
articleLink = bundle.getString(ARG_WIKI_DATA_LINK).replace("<", "").replace(">", "");
|
||||
}
|
||||
|
||||
if (!Utils.isNullOrWhiteSpace(articleLink) && articleLink != "\n") {
|
||||
this.articleLink = Uri.parse(articleLink);
|
||||
if (sitelinks.getWikipediaLink() != null) {
|
||||
this.articleLink = sitelinks.getWikipediaLink();
|
||||
} else {
|
||||
goToButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
@ -79,8 +72,7 @@ public class NearbyInfoDialog extends OverlayDialog {
|
|||
bundle.putString(ARG_DESC, place.description);
|
||||
bundle.putDouble(ARG_LATITUDE, place.location.latitude);
|
||||
bundle.putDouble(ARG_LONGITUDE, place.location.longitude);
|
||||
bundle.putString(ARG_ARTICLE_LINK, place.siteLink.toString());
|
||||
bundle.putString(ARG_WIKI_DATA_LINK, place.wikiDataLink.toString());
|
||||
bundle.putParcelable(ARG_SITE_LINK, place.siteLinks);
|
||||
mDialog.setArguments(bundle);
|
||||
DialogUtil.showSafely(fragmentActivity, mDialog);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,17 +70,19 @@ public class NearbyPlaces {
|
|||
List<Place> places = new ArrayList<>();
|
||||
|
||||
String query = FileUtils.readFromFile(context, "queries/nearby_query.rq")
|
||||
.replace("${RAD}", String.format(Locale.ROOT, "%.2f", radius))
|
||||
.replace("${RADIUS}", String.format(Locale.ROOT, "%.2f", radius))
|
||||
.replace("${LAT}", String.format(Locale.ROOT, "%.4f", cur.latitude))
|
||||
.replace("${LONG}", String.format(Locale.ROOT, "%.4f", cur.longitude))
|
||||
.replace("${LANG}", lang);
|
||||
Timber.v(query);
|
||||
|
||||
Timber.d("Wikidata query "+ query);
|
||||
|
||||
// format as a URL
|
||||
String url = WIKIDATA_QUERY_URL.replace(
|
||||
"${QUERY}",
|
||||
URLEncoder.encode(query, "utf-8").replace("+", "%20")
|
||||
);
|
||||
|
||||
Timber.d(url);
|
||||
URLConnection conn = new URL(url).openConnection();
|
||||
conn.setRequestProperty("Accept", "text/tab-separated-values");
|
||||
|
|
@ -99,8 +101,9 @@ public class NearbyPlaces {
|
|||
String point = fields[0];
|
||||
String name = Utils.stripLocalizedString(fields[2]);
|
||||
String type = Utils.stripLocalizedString(fields[4]);
|
||||
String sitelink = Utils.stripLocalizedString(fields[7]);
|
||||
String wikiDataLink = Utils.stripLocalizedString(fields[3]);
|
||||
String wikipediaSitelink = Utils.stripLocalizedString(fields[7]);
|
||||
String commonsSitelink = Utils.stripLocalizedString(fields[8]);
|
||||
String wikiDataLink = Utils.stripLocalizedString(fields[1]);
|
||||
String icon = fields[5];
|
||||
|
||||
double latitude = 0;
|
||||
|
|
@ -123,8 +126,11 @@ public class NearbyPlaces {
|
|||
type, // details
|
||||
Uri.parse(icon),
|
||||
new LatLng(latitude, longitude),
|
||||
Uri.parse(sitelink),
|
||||
Uri.parse(wikiDataLink)
|
||||
new Sitelinks.Builder()
|
||||
.setWikipediaLink(wikipediaSitelink)
|
||||
.setCommonsLink(commonsSitelink)
|
||||
.setWikidataLink(wikiDataLink)
|
||||
.build()
|
||||
));
|
||||
}
|
||||
in.close();
|
||||
|
|
@ -182,8 +188,7 @@ public class NearbyPlaces {
|
|||
type, // details
|
||||
null,
|
||||
new LatLng(latitude, longitude),
|
||||
null,
|
||||
null
|
||||
new Sitelinks.Builder().build()
|
||||
));
|
||||
}
|
||||
in.close();
|
||||
|
|
|
|||
|
|
@ -16,19 +16,17 @@ public class Place {
|
|||
public Bitmap image;
|
||||
public Bitmap secondaryImage;
|
||||
public String distance;
|
||||
public Uri siteLink;
|
||||
public Uri wikiDataLink;
|
||||
public Sitelinks siteLinks;
|
||||
|
||||
|
||||
public Place(String name, String description, String longDescription,
|
||||
Uri secondaryImageUrl, LatLng location, Uri siteLink, Uri wikiDataLink) {
|
||||
Uri secondaryImageUrl, LatLng location, Sitelinks siteLinks) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.longDescription = longDescription;
|
||||
this.secondaryImageUrl = secondaryImageUrl;
|
||||
this.location = location;
|
||||
this.siteLink = siteLink;
|
||||
this.wikiDataLink = wikiDataLink;
|
||||
this.siteLinks = siteLinks;
|
||||
}
|
||||
|
||||
public void setDistance(String distance) {
|
||||
|
|
|
|||
103
app/src/main/java/fr/free/nrw/commons/nearby/Sitelinks.java
Normal file
103
app/src/main/java/fr/free/nrw/commons/nearby/Sitelinks.java
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import fr.free.nrw.commons.Utils;
|
||||
|
||||
public class Sitelinks implements Parcelable {
|
||||
private final String wikipediaLink;
|
||||
private final String commonsLink;
|
||||
private final String wikidataLink;
|
||||
|
||||
|
||||
protected Sitelinks(Parcel in) {
|
||||
wikipediaLink = in.readString();
|
||||
commonsLink = in.readString();
|
||||
wikidataLink = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
dest.writeString(wikipediaLink);
|
||||
dest.writeString(commonsLink);
|
||||
dest.writeString(wikidataLink);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final Creator<Sitelinks> CREATOR = new Creator<Sitelinks>() {
|
||||
@Override
|
||||
public Sitelinks createFromParcel(Parcel in) {
|
||||
return new Sitelinks(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sitelinks[] newArray(int size) {
|
||||
return new Sitelinks[size];
|
||||
}
|
||||
};
|
||||
|
||||
@Nullable
|
||||
public Uri getWikipediaLink() {
|
||||
return sanitiseString(wikipediaLink);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Uri getCommonsLink() {
|
||||
return sanitiseString(commonsLink);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Uri getWikidataLink() {
|
||||
return sanitiseString(wikidataLink);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Uri sanitiseString(String stringUrl) {
|
||||
stringUrl = stringUrl.replace("<", "").replace(">", "");
|
||||
if (!Utils.isNullOrWhiteSpace(stringUrl) && stringUrl != null) {
|
||||
return Uri.parse(stringUrl);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Sitelinks(Sitelinks.Builder builder) {
|
||||
this.wikidataLink = builder.wikidataLink;
|
||||
this.wikipediaLink = builder.wikipediaLink;
|
||||
this.commonsLink = builder.commonsLink;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String wikidataLink;
|
||||
private String commonsLink;
|
||||
private String wikipediaLink;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
public Sitelinks.Builder setWikipediaLink(String link) {
|
||||
this.wikipediaLink = link;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sitelinks.Builder setWikidataLink(String link) {
|
||||
this.wikidataLink = link;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sitelinks.Builder setCommonsLink(@Nullable String link) {
|
||||
this.commonsLink = link;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Sitelinks build() {
|
||||
return new Sitelinks(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,19 +6,21 @@ import java.io.BufferedReader;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class FileUtils {
|
||||
public static String readFromFile(Context context, String fileName) {
|
||||
String stringBuilder = "";
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(context.getAssets().open(fileName), "UTF-8"));
|
||||
new InputStreamReader(context.getAssets().open(fileName)));
|
||||
String mLine;
|
||||
while ((mLine = reader.readLine()) != null) {
|
||||
stringBuilder += mLine + "\n";
|
||||
}
|
||||
} catch (IOException e) {
|
||||
//log the exception
|
||||
Timber.e("File not found exception", e);
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue