mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 05:43:55 +01:00
feat: Show ❌ for P3999 items (official closure)
This commit is contained in:
parent
f6969de066
commit
107f33e422
4 changed files with 45 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
|
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
|
||||||
import fr.free.nrw.commons.utils.LocationUtils;
|
import fr.free.nrw.commons.utils.LocationUtils;
|
||||||
import fr.free.nrw.commons.utils.PlaceUtils;
|
import fr.free.nrw.commons.utils.PlaceUtils;
|
||||||
|
import java.util.Objects;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
|
|
@ -39,6 +40,7 @@ public class Place implements Parcelable {
|
||||||
public Sitelinks siteLinks;
|
public Sitelinks siteLinks;
|
||||||
private boolean isMonument;
|
private boolean isMonument;
|
||||||
private String thumb;
|
private String thumb;
|
||||||
|
private String dateOfClosure;
|
||||||
|
|
||||||
public Place() {
|
public Place() {
|
||||||
language = null;
|
language = null;
|
||||||
|
|
@ -51,6 +53,12 @@ public class Place implements Parcelable {
|
||||||
exists = null;
|
exists = null;
|
||||||
siteLinks = null;
|
siteLinks = null;
|
||||||
entityID = null;
|
entityID = null;
|
||||||
|
dateOfClosure = null;
|
||||||
|
}
|
||||||
|
public Place(String language, String name, Label label, String longDescription, LatLng location,
|
||||||
|
String category, Sitelinks siteLinks, String pic, Boolean exists, String entityID, String dateOfClosure) {
|
||||||
|
this(language, name, label, longDescription, location, category, siteLinks, pic, exists, entityID);
|
||||||
|
this.dateOfClosure = dateOfClosure;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Place(String language, String name, Label label, String longDescription, LatLng location,
|
public Place(String language, String name, Label label, String longDescription, LatLng location,
|
||||||
|
|
@ -109,6 +117,7 @@ public class Place implements Parcelable {
|
||||||
this.exists = Boolean.parseBoolean(existString);
|
this.exists = Boolean.parseBoolean(existString);
|
||||||
this.isMonument = in.readInt() == 1;
|
this.isMonument = in.readInt() == 1;
|
||||||
this.entityID = in.readString();
|
this.entityID = in.readString();
|
||||||
|
this.dateOfClosure = in.readString(); // Added for P3999
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Place from(NearbyResultItem item) {
|
public static Place from(NearbyResultItem item) {
|
||||||
|
|
@ -139,6 +148,7 @@ public class Place implements Parcelable {
|
||||||
+ ((description != null && !description.isEmpty())
|
+ ((description != null && !description.isEmpty())
|
||||||
? " (" + description + ")" : "")
|
? " (" + description + ")" : "")
|
||||||
: description);
|
: description);
|
||||||
|
item.getDateOfClosure();
|
||||||
return new Place(
|
return new Place(
|
||||||
item.getLabel().getLanguage(),
|
item.getLabel().getLanguage(),
|
||||||
item.getLabel().getValue(),
|
item.getLabel().getValue(),
|
||||||
|
|
@ -153,9 +163,27 @@ public class Place implements Parcelable {
|
||||||
.build(),
|
.build(),
|
||||||
item.getPic().getValue(),
|
item.getPic().getValue(),
|
||||||
// Checking if the place exists or not
|
// Checking if the place exists or not
|
||||||
(item.getDestroyed().getValue() == "") && (item.getEndTime().getValue() == ""), entityId);
|
(item.getDestroyed().getValue() == "" && item.getEndTime().getValue() == ""),
|
||||||
|
entityId,
|
||||||
|
(item.getDateOfClosure() != null && !item.getDateOfClosure().getValue().isEmpty())
|
||||||
|
? item.getDateOfClosure().getValue()
|
||||||
|
: null);
|
||||||
|
}
|
||||||
|
// Added new method to check if place is closed
|
||||||
|
public boolean isClosed() {
|
||||||
|
return (dateOfClosure != null && !dateOfClosure.isEmpty()) || !exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return (isClosed() ? "❌ " : "") + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDateOfClosure() {
|
||||||
|
return dateOfClosure;
|
||||||
|
}
|
||||||
|
public void setDateOfClosure(String dateOfClosure) {
|
||||||
|
this.dateOfClosure = dateOfClosure;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Gets the language of the caption ie name.
|
* Gets the language of the caption ie name.
|
||||||
*
|
*
|
||||||
|
|
@ -306,15 +334,17 @@ public class Place implements Parcelable {
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (o instanceof Place) {
|
if (o instanceof Place) {
|
||||||
Place that = (Place) o;
|
Place that = (Place) o;
|
||||||
return this.name.equals(that.name) && this.location.equals(that.location);
|
return this.name.equals(that.name) && this.location.equals(that.location) &&
|
||||||
} else {
|
(Objects.equals(this.dateOfClosure, that.dateOfClosure));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.name.hashCode() * 31 + this.location.hashCode();
|
int result = this.name.hashCode() * 31 + this.location.hashCode();
|
||||||
|
result = 31 * result + (dateOfClosure != null ? dateOfClosure.hashCode() : 0); // Add this line
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -331,6 +361,7 @@ public class Place implements Parcelable {
|
||||||
", pic='" + pic + '\'' +
|
", pic='" + pic + '\'' +
|
||||||
", exists='" + exists.toString() + '\'' +
|
", exists='" + exists.toString() + '\'' +
|
||||||
", entityID='" + entityID + '\'' +
|
", entityID='" + entityID + '\'' +
|
||||||
|
", dateOfClosure='" + dateOfClosure + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -352,6 +383,7 @@ public class Place implements Parcelable {
|
||||||
dest.writeString(entityID);
|
dest.writeString(entityID);
|
||||||
dest.writeString(exists.toString());
|
dest.writeString(exists.toString());
|
||||||
dest.writeInt(isMonument ? 1 : 0);
|
dest.writeInt(isMonument ? 1 : 0);
|
||||||
|
dest.writeString(dateOfClosure);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Creator<Place> CREATOR = new Creator<Place>() {
|
public static final Creator<Place> CREATOR = new Creator<Place>() {
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ fun placeAdapterDelegate(
|
||||||
nearbyButtonLayout.iconOverflow.setOnLongClickListener { onOverFlowLongPressed() }
|
nearbyButtonLayout.iconOverflow.setOnLongClickListener { onOverFlowLongPressed() }
|
||||||
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
|
nearbyButtonLayout.directionsButton.setOnClickListener { onDirectionsClicked(item) }
|
||||||
bind {
|
bind {
|
||||||
tvName.text = item.name
|
tvName.text = item.getDisplayName()
|
||||||
val descriptionText: String = item.longDescription
|
val descriptionText: String = item.longDescription
|
||||||
if (descriptionText == "?") {
|
if (descriptionText == "?") {
|
||||||
tvDesc.setText(R.string.no_description_found)
|
tvDesc.setText(R.string.no_description_found)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class NearbyResultItem(
|
||||||
@field:SerializedName("description") private val description: ResultTuple?,
|
@field:SerializedName("description") private val description: ResultTuple?,
|
||||||
@field:SerializedName("endTime") private val endTime: ResultTuple?,
|
@field:SerializedName("endTime") private val endTime: ResultTuple?,
|
||||||
@field:SerializedName("monument") private val monument: ResultTuple?,
|
@field:SerializedName("monument") private val monument: ResultTuple?,
|
||||||
|
@field:SerializedName("dateOfClosure") private val dateOfClosure: ResultTuple? = null
|
||||||
) {
|
) {
|
||||||
fun getItem(): ResultTuple = item ?: ResultTuple()
|
fun getItem(): ResultTuple = item ?: ResultTuple()
|
||||||
|
|
||||||
|
|
@ -48,4 +49,6 @@ class NearbyResultItem(
|
||||||
fun getAddress(): String = address?.value ?: ""
|
fun getAddress(): String = address?.value ?: ""
|
||||||
|
|
||||||
fun getMonument(): ResultTuple? = monument
|
fun getMonument(): ResultTuple? = monument
|
||||||
|
|
||||||
|
fun getDateOfClosure(): ResultTuple = dateOfClosure ?: ResultTuple()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ SELECT
|
||||||
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
|
(SAMPLE(?wikipediaArticle) AS ?wikipediaArticle)
|
||||||
(SAMPLE(?commonsArticle) AS ?commonsArticle)
|
(SAMPLE(?commonsArticle) AS ?commonsArticle)
|
||||||
(SAMPLE(?commonsCategory) AS ?commonsCategory)
|
(SAMPLE(?commonsCategory) AS ?commonsCategory)
|
||||||
|
(SAMPLE(?dateOfClosure) AS ?dateOfClosure)
|
||||||
WHERE {
|
WHERE {
|
||||||
SERVICE <https://query.wikidata.org/sparql> {
|
SERVICE <https://query.wikidata.org/sparql> {
|
||||||
values ?item {
|
values ?item {
|
||||||
|
|
@ -60,5 +61,8 @@ WHERE {
|
||||||
?commonsArticle schema:about ?item.
|
?commonsArticle schema:about ?item.
|
||||||
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
|
?commonsArticle schema:isPartOf <https://commons.wikimedia.org/>.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get date of official closure (P3999)
|
||||||
|
OPTIONAL {?item wdt:P3999 ?dateOfClosure}
|
||||||
}
|
}
|
||||||
GROUP BY ?item
|
GROUP BY ?item
|
||||||
Loading…
Add table
Add a link
Reference in a new issue