mirror of
				https://github.com/commons-app/apps-android-commons.git
				synced 2025-10-31 14:53:59 +01:00 
			
		
		
		
	Changed primary key from location to entity id
This commit is contained in:
		
							parent
							
								
									438aa3b41b
								
							
						
					
					
						commit
						a28117397d
					
				
					 7 changed files with 38 additions and 14 deletions
				
			
		|  | @ -165,7 +165,8 @@ public class BookmarkLocationsDao { | |||
|             cursor.getString(cursor.getColumnIndex(Table.COLUMN_CATEGORY)), | ||||
|             builder.build(), | ||||
|             cursor.getString(cursor.getColumnIndex(Table.COLUMN_PIC)), | ||||
|             Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(Table.COLUMN_EXISTS))) | ||||
|             Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(Table.COLUMN_EXISTS))), | ||||
|             cursor.getString(cursor.getColumnIndex(Table.COLUMN_ENTITY_ID)) | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|  | @ -184,6 +185,7 @@ public class BookmarkLocationsDao { | |||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_LONG, bookmarkLocation.location.getLongitude()); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_PIC, bookmarkLocation.pic); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_EXISTS, bookmarkLocation.exists.toString()); | ||||
|         cv.put(BookmarkLocationsDao.Table.COLUMN_ENTITY_ID, bookmarkLocation.entityID); | ||||
|         return cv; | ||||
|     } | ||||
| 
 | ||||
|  | @ -204,6 +206,7 @@ public class BookmarkLocationsDao { | |||
|         static final String COLUMN_COMMONS_LINK = "location_commons_link"; | ||||
|         static final String COLUMN_PIC = "location_pic"; | ||||
|         static final String COLUMN_EXISTS = "location_exists"; | ||||
|         static final String COLUMN_ENTITY_ID = "location_entity_id"; | ||||
| 
 | ||||
|         // NOTE! KEEP IN SAME ORDER AS THEY ARE DEFINED UP THERE. HELPS HARD CODE COLUMN INDICES. | ||||
|         public static final String[] ALL_FIELDS = { | ||||
|  | @ -221,6 +224,7 @@ public class BookmarkLocationsDao { | |||
|                 COLUMN_COMMONS_LINK, | ||||
|                 COLUMN_PIC, | ||||
|                 COLUMN_EXISTS, | ||||
|                 COLUMN_ENTITY_ID | ||||
|         }; | ||||
| 
 | ||||
|         static final String DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS " + TABLE_NAME; | ||||
|  | @ -239,7 +243,8 @@ public class BookmarkLocationsDao { | |||
|                 + COLUMN_WIKIDATA_LINK + " STRING," | ||||
|                 + COLUMN_COMMONS_LINK + " STRING," | ||||
|                 + COLUMN_PIC + " STRING," | ||||
|                 + COLUMN_EXISTS + " STRING" | ||||
|                 + COLUMN_EXISTS + " STRING," | ||||
|                 + COLUMN_ENTITY_ID + " STRING" | ||||
|                 + ");"; | ||||
| 
 | ||||
|         public static void onCreate(SQLiteDatabase db) { | ||||
|  | @ -306,6 +311,13 @@ public class BookmarkLocationsDao { | |||
|                     Timber.e(exception); | ||||
|                 } | ||||
|             } | ||||
|             if (from >= 15){ | ||||
|                 try { | ||||
|                     db.execSQL("ALTER TABLE bookmarksLocations ADD COLUMN location_entity_id STRING;"); | ||||
|                 } catch (SQLiteException exception){ | ||||
|                     Timber.e(exception); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
|  | @ -24,8 +24,9 @@ public class Place implements Parcelable { | |||
|     public String name; | ||||
|     private Label label; | ||||
|     private String longDescription; | ||||
|     @PrimaryKey @NonNull | ||||
|     public LatLng location; | ||||
|     @PrimaryKey @NonNull | ||||
|     public String entityID; | ||||
|     private String category; | ||||
|     public String pic; | ||||
|     // exists boolean will tell whether the place exists or not, | ||||
|  | @ -47,10 +48,11 @@ public class Place implements Parcelable { | |||
|         pic = null; | ||||
|         exists = null; | ||||
|         siteLinks = null; | ||||
|         entityID = null; | ||||
|     } | ||||
| 
 | ||||
|     public Place(String language, String name, Label label, String longDescription, LatLng location, | ||||
|         String category, Sitelinks siteLinks, String pic, Boolean exists) { | ||||
|         String category, Sitelinks siteLinks, String pic, Boolean exists, String entityID) { | ||||
|         this.language = language; | ||||
|         this.name = name; | ||||
|         this.label = label; | ||||
|  | @ -60,10 +62,11 @@ public class Place implements Parcelable { | |||
|         this.siteLinks = siteLinks; | ||||
|         this.pic = (pic == null) ? "" : pic; | ||||
|         this.exists = exists; | ||||
|         this.entityID = entityID; | ||||
|     } | ||||
| 
 | ||||
|     public Place(String name, String longDescription, LatLng location, String category, | ||||
|         Sitelinks siteLinks, String pic, String thumb) { | ||||
|         Sitelinks siteLinks, String pic, String thumb, String entityID) { | ||||
|         this.name = name; | ||||
|         this.longDescription = longDescription; | ||||
|         this.location = location; | ||||
|  | @ -74,6 +77,7 @@ public class Place implements Parcelable { | |||
|         this.language = null; | ||||
|         this.label = null; | ||||
|         this.exists = true; | ||||
|         this.entityID = entityID; | ||||
|     } | ||||
| 
 | ||||
|     public Place(Parcel in) { | ||||
|  | @ -89,6 +93,7 @@ public class Place implements Parcelable { | |||
|         String existString = in.readString(); | ||||
|         this.exists = Boolean.parseBoolean(existString); | ||||
|         this.isMonument = in.readInt() == 1; | ||||
|         this.entityID = in.readString(); | ||||
|     } | ||||
| 
 | ||||
|     public static Place from(NearbyResultItem item) { | ||||
|  | @ -97,6 +102,10 @@ public class Place implements Parcelable { | |||
|         if (!StringUtils.isBlank(itemClass)) { | ||||
|             classEntityId = itemClass.replace("http://www.wikidata.org/entity/", ""); | ||||
|         } | ||||
|         String entityId = ""; | ||||
|         if (!StringUtils.isBlank(item.getItem().getValue())){ | ||||
|             entityId = item.getItem().getValue().replace("http://www.wikidata.org/entity/", ""); | ||||
|         } | ||||
|         // Set description when not null and not empty | ||||
|         String description = | ||||
|             (item.getDescription().getValue() != null && !item.getDescription().getValue() | ||||
|  | @ -129,7 +138,7 @@ public class Place implements Parcelable { | |||
|                 .build(), | ||||
|             item.getPic().getValue(), | ||||
|             // Checking if the place exists or not | ||||
|             (item.getDestroyed().getValue() == "") && (item.getEndTime().getValue() == "")); | ||||
|             (item.getDestroyed().getValue() == "") && (item.getEndTime().getValue() == ""), entityId); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|  | @ -296,6 +305,7 @@ public class Place implements Parcelable { | |||
|             ", siteLinks='" + siteLinks.toString() + '\'' + | ||||
|             ", pic='" + pic + '\'' + | ||||
|             ", exists='" + exists.toString() + '\'' + | ||||
|             ", entityID='" + entityID + '\'' + | ||||
|             '}'; | ||||
|     } | ||||
| 
 | ||||
|  | @ -314,6 +324,7 @@ public class Place implements Parcelable { | |||
|         dest.writeString(category); | ||||
|         dest.writeParcelable(siteLinks, 0); | ||||
|         dest.writeString(pic); | ||||
|         dest.writeString(entityID); | ||||
|         dest.writeString(exists.toString()); | ||||
|         dest.writeInt(isMonument ? 1 : 0); | ||||
|     } | ||||
|  |  | |||
|  | @ -12,8 +12,8 @@ public abstract class PlaceDao { | |||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     public abstract void saveSynchronous(Place place); | ||||
| 
 | ||||
|     @Query("SELECT * from place WHERE location=:l") | ||||
|     public abstract Place getPlace(LatLng l); | ||||
|     @Query("SELECT * from place WHERE entityID=:entity") | ||||
|     public abstract Place getPlace(String entity); | ||||
| 
 | ||||
|     public Completable save(final Place place) { | ||||
|         return Completable | ||||
|  |  | |||
|  | @ -14,8 +14,8 @@ public class PlacesLocalDataSource { | |||
|         this.placeDao = placeDao; | ||||
|     } | ||||
| 
 | ||||
|     public Place fetchPlace(LatLng latLng){ | ||||
|         return placeDao.getPlace(latLng); | ||||
|     public Place fetchPlace(String entityID){ | ||||
|         return placeDao.getPlace(entityID); | ||||
|     } | ||||
| 
 | ||||
|     public Completable savePlace(Place place) { | ||||
|  |  | |||
|  | @ -18,8 +18,8 @@ public class PlacesRepository { | |||
|         return localDataSource.savePlace(place); | ||||
|     } | ||||
| 
 | ||||
|     public Place fetchPlace(LatLng latLng){ | ||||
|         return localDataSource.fetchPlace(latLng); | ||||
|     public Place fetchPlace(String entityID){ | ||||
|         return localDataSource.fetchPlace(entityID); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -1409,7 +1409,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment | |||
|         for (Place place : batch) { | ||||
|             Observable<Place> placeObservable = Observable | ||||
|                 .fromCallable(() -> { | ||||
|                     Place fetchedPlace = placesRepository.fetchPlace(place.location); | ||||
|                     Place fetchedPlace = placesRepository.fetchPlace(place.entityID); | ||||
|                     return fetchedPlace != null ? fetchedPlace : place; | ||||
|                 }) | ||||
|                 .subscribeOn(Schedulers.io()) | ||||
|  |  | |||
|  | @ -47,7 +47,8 @@ public class PlaceUtils { | |||
|                     .setWikidataLink("") // we don't necessarily have them, can be fetched later | ||||
|                     .build(), | ||||
|                 media.getImageUrl(), | ||||
|                 media.getThumbUrl())); | ||||
|                 media.getThumbUrl(), | ||||
|                 "")); | ||||
|         } | ||||
|         return explorePlaceList; | ||||
|     } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kanahia
						Kanahia