Fixes #4260 - Item with P582 (end time) shown as existing (#4292)

* fix issue with item with endtime shown as existing

* Removed destroyed and endtime, Added comments and also fixed the broken tests

* minor fix

* Added comments

* fix no such column location_exists error

* minor improvement

Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
Pratham Pahariya 2021-03-17 20:35:08 +05:30 committed by GitHub
parent d00127947c
commit 944225c3a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 53 additions and 28 deletions

View file

@ -165,7 +165,7 @@ public class BookmarkLocationsDao {
cursor.getString(cursor.getColumnIndex(Table.COLUMN_CATEGORY)),
builder.build(),
cursor.getString(cursor.getColumnIndex(Table.COLUMN_PIC)),
cursor.getString(cursor.getColumnIndex(Table.COLUMN_DESTROYED))
Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(Table.COLUMN_EXISTS)))
);
}
@ -183,7 +183,7 @@ public class BookmarkLocationsDao {
cv.put(BookmarkLocationsDao.Table.COLUMN_LAT, bookmarkLocation.location.getLatitude());
cv.put(BookmarkLocationsDao.Table.COLUMN_LONG, bookmarkLocation.location.getLongitude());
cv.put(BookmarkLocationsDao.Table.COLUMN_PIC, bookmarkLocation.pic);
cv.put(BookmarkLocationsDao.Table.COLUMN_DESTROYED, bookmarkLocation.destroyed);
cv.put(BookmarkLocationsDao.Table.COLUMN_EXISTS, bookmarkLocation.exists.toString());
return cv;
}
@ -203,7 +203,7 @@ public class BookmarkLocationsDao {
static final String COLUMN_WIKIDATA_LINK = "location_wikidata_link";
static final String COLUMN_COMMONS_LINK = "location_commons_link";
static final String COLUMN_PIC = "location_pic";
static final String COLUMN_DESTROYED = "location_destroyed";
static final String COLUMN_EXISTS = "location_exists";
// NOTE! KEEP IN SAME ORDER AS THEY ARE DEFINED UP THERE. HELPS HARD CODE COLUMN INDICES.
public static final String[] ALL_FIELDS = {
@ -220,7 +220,7 @@ public class BookmarkLocationsDao {
COLUMN_WIKIDATA_LINK,
COLUMN_COMMONS_LINK,
COLUMN_PIC,
COLUMN_DESTROYED
COLUMN_EXISTS
};
static final String DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS " + TABLE_NAME;
@ -239,7 +239,7 @@ public class BookmarkLocationsDao {
+ COLUMN_WIKIDATA_LINK + " STRING,"
+ COLUMN_COMMONS_LINK + " STRING,"
+ COLUMN_PIC + " STRING,"
+ COLUMN_DESTROYED + " STRING"
+ COLUMN_EXISTS + " STRING"
+ ");";
public static void onCreate(SQLiteDatabase db) {
@ -299,6 +299,13 @@ public class BookmarkLocationsDao {
Timber.e(exception);
}
}
if (from == 14){
try {
db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_exists STRING;");
} catch (SQLiteException exception){
Timber.e(exception);
}
}
}
}
}

View file

@ -13,7 +13,7 @@ import fr.free.nrw.commons.explore.recentsearches.RecentSearchesDao;
public class DBOpenHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "commons.db";
private static final int DATABASE_VERSION = 14;
private static final int DATABASE_VERSION = 15;
public static final String CONTRIBUTIONS_TABLE = "contributions";
private final String DROP_TABLE_STATEMENT="DROP TABLE IF EXISTS %s";

View file

@ -201,7 +201,7 @@ public class NearbyController {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(iconGreen));
}
} else if (!place.destroyed.trim().isEmpty()) { // Means place is destroyed
} else if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
if (iconGrey != null) {
nearbyBaseMarker.icon(IconFactory.getInstance(context)
.fromBitmap(iconGrey));

View file

@ -25,13 +25,15 @@ public class Place implements Parcelable {
public final LatLng location;
private final String category;
public final String pic;
public final String destroyed;
// exists boolean will tell whether the place exists or not,
// For a place to be existing both destroyed and endTime property should be null but it is also not necessary for a non-existing place to have both properties either one property is enough (in such case that not given property will be considered as null).
public final Boolean exists;
public String distance;
public final Sitelinks siteLinks;
public Place(String language,String name, Label label, String longDescription, LatLng location, String category, Sitelinks siteLinks, String pic, String destroyed) {
public Place(String language,String name, Label label, String longDescription, LatLng location, String category, Sitelinks siteLinks, String pic, Boolean exists) {
this.language = language;
this.name = name;
this.label = label;
@ -40,7 +42,7 @@ public class Place implements Parcelable {
this.category = category;
this.siteLinks = siteLinks;
this.pic = (pic == null) ? "":pic;
this.destroyed = (destroyed == null) ? "":destroyed;
this.exists = exists;
}
public Place(Parcel in) {
this.language = in.readString();
@ -52,8 +54,8 @@ public class Place implements Parcelable {
this.siteLinks = in.readParcelable(Sitelinks.class.getClassLoader());
String picString = in.readString();
this.pic = (picString == null) ? "":picString;
String destroyedString = in.readString();
this.destroyed = (destroyedString == null) ? "":destroyedString;
String existString = in.readString();
this.exists = Boolean.parseBoolean(existString);
}
public static Place from(NearbyResultItem item) {
String itemClass = item.getClassName().getValue();
@ -74,7 +76,8 @@ public class Place implements Parcelable {
.setWikidataLink(item.getItem().getValue())
.build(),
item.getPic().getValue(),
item.getDestroyed().getValue());
// Checking if the place exists or not
(item.getDestroyed().getValue() == "") && (item.getEndTime().getValue() == ""));
}
/**
@ -194,7 +197,7 @@ public class Place implements Parcelable {
", distance='" + distance + '\'' +
", siteLinks='" + siteLinks.toString() + '\'' +
", pic='" + pic + '\'' +
", destroyed='" + destroyed + '\'' +
", exists='" + exists.toString() + '\'' +
'}';
}
@ -213,7 +216,7 @@ public class Place implements Parcelable {
dest.writeString(category);
dest.writeParcelable(siteLinks, 0);
dest.writeString(pic);
dest.writeString(destroyed);
dest.writeString(exists.toString());
}
public static final Creator<Place> CREATOR = new Creator<Place>() {

View file

@ -1254,12 +1254,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
if (displayExists && displayNeedsPhoto) {
// Exists and needs photo
if (place.destroyed.trim().isEmpty() && place.pic.trim().isEmpty()) {
if (place.exists && place.pic.trim().isEmpty()) {
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
}
} else if (displayExists && !displayNeedsPhoto) {
// Exists and all included needs and doesn't needs photo
if (place.destroyed.trim().isEmpty()) {
if (place.exists) {
updateMarker(markerPlaceGroup.getIsBookmarked(), place, NearbyController.currentLocation);
}
} else if (!displayExists && displayNeedsPhoto) {
@ -1317,7 +1317,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
return (isBookmarked ?
R.drawable.ic_custom_map_marker_green_bookmarked :
R.drawable.ic_custom_map_marker_green);
} else if (!place.destroyed.trim().isEmpty()) { // Means place is destroyed
} else if (!place.exists) { // Means that the topic of the Wikidata item does not exist in the real world anymore, for instance it is a past event, or a place that was destroyed
return (isBookmarked ?
R.drawable.ic_custom_map_marker_grey_bookmarked :
R.drawable.ic_custom_map_marker_grey);

View file

@ -11,7 +11,8 @@ class NearbyResultItem(private val item: ResultTuple?,
@field:SerializedName("classLabel") private val classLabel: ResultTuple?,
@field:SerializedName("commonsCategory") private val commonsCategory: ResultTuple?,
@field:SerializedName("pic") private val pic: ResultTuple?,
@field:SerializedName("destroyed") private val destroyed: ResultTuple?) {
@field:SerializedName("destroyed") private val destroyed: ResultTuple?,
@field:SerializedName("endTime") private val endTime: ResultTuple?) {
fun getItem(): ResultTuple {
return item ?: ResultTuple()
@ -57,4 +58,8 @@ class NearbyResultItem(private val item: ResultTuple?,
return destroyed ?: ResultTuple()
}
fun getEndTime(): ResultTuple {
return endTime ?: ResultTuple()
}
}