mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Update query to fetch descriptions * Make description added to NearbyResultItem * Make string operations to display description and label in a combined way * Fix reviews, remove long description from list and swap label and description texts * Fix repeated information issue * Fix double information issue * fix style issues * Remove douplicated information
This commit is contained in:
parent
60993b3109
commit
3416504cda
5 changed files with 36 additions and 4 deletions
|
|
@ -60,10 +60,26 @@ public class Place implements Parcelable {
|
||||||
if(!StringUtils.isBlank(itemClass)) {
|
if(!StringUtils.isBlank(itemClass)) {
|
||||||
classEntityId = itemClass.replace("http://www.wikidata.org/entity/", "");
|
classEntityId = itemClass.replace("http://www.wikidata.org/entity/", "");
|
||||||
}
|
}
|
||||||
|
// Set description when not null and not empty
|
||||||
|
String description = (item.getDescription().getValue() != null && !item.getDescription().getValue().isEmpty()) ? item.getDescription().getValue() : "";
|
||||||
|
// When description is "?" but we have a valid label, just use the label. So replace "?" by "" in description
|
||||||
|
description = (description.equals("?")
|
||||||
|
&& (item.getLabel().getValue() != null
|
||||||
|
&& !item.getLabel().getValue().isEmpty()) ? "" : description);
|
||||||
|
/*
|
||||||
|
* If we have a valid label
|
||||||
|
* - If have a valid label add the description at the end of the string with parenthesis
|
||||||
|
* - If we don't have a valid label, string will include only the description. So add it without paranthesis
|
||||||
|
*/
|
||||||
|
description = ((item.getLabel().getValue() != null && !item.getLabel().getValue().isEmpty())
|
||||||
|
? item.getLabel().getValue()
|
||||||
|
+ ((description != null && !description.isEmpty())
|
||||||
|
? " (" + description + ")" : "")
|
||||||
|
: description);
|
||||||
return new Place(
|
return new Place(
|
||||||
item.getLabel().getValue(),
|
item.getLabel().getValue(),
|
||||||
Label.fromText(classEntityId), // list
|
Label.fromText(classEntityId), // list
|
||||||
item.getClassLabel().getValue(), // details
|
description, // description and label of Wikidata item
|
||||||
PlaceUtils.latLngFromPointString(item.getLocation().getValue()),
|
PlaceUtils.latLngFromPointString(item.getLocation().getValue()),
|
||||||
item.getCommonsCategory().getValue(),
|
item.getCommonsCategory().getValue(),
|
||||||
new Sitelinks.Builder()
|
new Sitelinks.Builder()
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,8 @@ fun placeAdapterDelegate(
|
||||||
tvDesc.setText(R.string.no_description_found)
|
tvDesc.setText(R.string.no_description_found)
|
||||||
tvDesc.visibility = INVISIBLE
|
tvDesc.visibility = INVISIBLE
|
||||||
} else {
|
} else {
|
||||||
tvDesc.text = descriptionText
|
// Remove the label and display only texts inside pharentheses (description) since too long
|
||||||
|
tvDesc.text = descriptionText.substringAfter(tvName.text.toString() + " (").substringBeforeLast(")");
|
||||||
}
|
}
|
||||||
distance.text = item.distance
|
distance.text = item.distance
|
||||||
icon.setImageResource(item.label.icon)
|
icon.setImageResource(item.label.icon)
|
||||||
|
|
|
||||||
|
|
@ -1435,7 +1435,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
|
|
||||||
title.setText(selectedPlace.name);
|
title.setText(selectedPlace.name);
|
||||||
distance.setText(selectedPlace.distance);
|
distance.setText(selectedPlace.distance);
|
||||||
description.setText(selectedPlace.getLongDescription());
|
// Remove label since it is double information
|
||||||
|
String descriptionText = selectedPlace.getLongDescription()
|
||||||
|
.replace(selectedPlace.getName() + " (","");
|
||||||
|
descriptionText = (descriptionText.equals(selectedPlace.getLongDescription()) ? descriptionText : descriptionText.replaceFirst(".$",""));
|
||||||
|
// Set the short description after we remove place name from long description
|
||||||
|
description.setText(descriptionText);
|
||||||
|
|
||||||
fabCamera.setOnClickListener(view -> {
|
fabCamera.setOnClickListener(view -> {
|
||||||
if (fabCamera.isShown()) {
|
if (fabCamera.isShown()) {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ class NearbyResultItem(private val item: ResultTuple?,
|
||||||
@field:SerializedName("classLabel") private val classLabel: ResultTuple?,
|
@field:SerializedName("classLabel") private val classLabel: ResultTuple?,
|
||||||
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
|
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
|
||||||
@field:SerializedName("pic") private val pic: ResultTuple?,
|
@field:SerializedName("pic") private val pic: ResultTuple?,
|
||||||
@field:SerializedName("destroyed") private val destroyed: ResultTuple?) {
|
@field:SerializedName("destroyed") private val destroyed: ResultTuple?,
|
||||||
|
@field:SerializedName("description") private val description: ResultTuple?) {
|
||||||
|
|
||||||
fun getItem(): ResultTuple {
|
fun getItem(): ResultTuple {
|
||||||
return item ?: ResultTuple()
|
return item ?: ResultTuple()
|
||||||
|
|
@ -57,4 +58,8 @@ class NearbyResultItem(private val item: ResultTuple?,
|
||||||
return destroyed ?: ResultTuple()
|
return destroyed ?: ResultTuple()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getDescription(): ResultTuple {
|
||||||
|
return description ?: ResultTuple()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -2,6 +2,7 @@ SELECT
|
||||||
(SAMPLE(?location) as ?location)
|
(SAMPLE(?location) as ?location)
|
||||||
?item
|
?item
|
||||||
(SAMPLE(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage)) as ?label)
|
(SAMPLE(COALESCE(?itemLabelPreferredLanguage, ?itemLabelAnyLanguage)) as ?label)
|
||||||
|
(SAMPLE(COALESCE(?itemDescriptionPreferredLanguage, ?itemDescriptionAnyLanguage, "?")) as ?description)
|
||||||
(SAMPLE(?classId) as ?class)
|
(SAMPLE(?classId) as ?class)
|
||||||
(SAMPLE(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?")) as ?classLabel)
|
(SAMPLE(COALESCE(?classLabelPreferredLanguage, ?classLabelAnyLanguage, "?")) as ?classLabel)
|
||||||
(SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
|
(SAMPLE(COALESCE(?icon0, ?icon1)) as ?icon)
|
||||||
|
|
@ -22,6 +23,10 @@ SELECT
|
||||||
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
|
OPTIONAL {?item rdfs:label ?itemLabelPreferredLanguage. FILTER (lang(?itemLabelPreferredLanguage) = "${LANG}")}
|
||||||
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
|
OPTIONAL {?item rdfs:label ?itemLabelAnyLanguage}
|
||||||
|
|
||||||
|
# Get the description in the preferred language of the user, or any other language if no description is available in that language.
|
||||||
|
OPTIONAL {?item schema:description ?itemDescriptionPreferredLanguage. FILTER (lang(?itemDescriptionPreferredLanguage) = "${LANG}")}
|
||||||
|
OPTIONAL {?item schema:description ?itemDescriptionAnyLanguage }
|
||||||
|
|
||||||
# Get Commons category (P373)
|
# Get Commons category (P373)
|
||||||
OPTIONAL { ?item wdt:P373 ?commonsCategory. }
|
OPTIONAL { ?item wdt:P373 ?commonsCategory. }
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue