mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-11-02 15:53:55 +01:00
Made minor changes
This commit is contained in:
parent
4f7cbfc741
commit
fb80b3a96c
4 changed files with 88 additions and 64 deletions
|
|
@ -46,11 +46,11 @@ public class BookmarkLocationsDao {
|
|||
ContentProviderClient db = clientProvider.get();
|
||||
try {
|
||||
cursor = db.query(
|
||||
BookmarkLocationsContentProvider.BASE_URI,
|
||||
Table.ALL_FIELDS,
|
||||
null,
|
||||
new String[]{},
|
||||
null);
|
||||
BookmarkLocationsContentProvider.BASE_URI,
|
||||
Table.ALL_FIELDS,
|
||||
null,
|
||||
new String[]{},
|
||||
null);
|
||||
while (cursor != null && cursor.moveToNext()) {
|
||||
items.add(fromCursor(cursor));
|
||||
}
|
||||
|
|
@ -126,11 +126,11 @@ public class BookmarkLocationsDao {
|
|||
ContentProviderClient db = clientProvider.get();
|
||||
try {
|
||||
cursor = db.query(
|
||||
BookmarkLocationsContentProvider.BASE_URI,
|
||||
Table.ALL_FIELDS,
|
||||
Table.COLUMN_NAME + "=?",
|
||||
new String[]{bookmarkLocation.name},
|
||||
null);
|
||||
BookmarkLocationsContentProvider.BASE_URI,
|
||||
Table.ALL_FIELDS,
|
||||
Table.COLUMN_NAME + "=?",
|
||||
new String[]{bookmarkLocation.name},
|
||||
null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -149,7 +149,7 @@ public class BookmarkLocationsDao {
|
|||
@NonNull
|
||||
Place fromCursor(final Cursor cursor) {
|
||||
final LatLng location = new LatLng(cursor.getDouble(cursor.getColumnIndex(Table.COLUMN_LAT)),
|
||||
cursor.getDouble(cursor.getColumnIndex(Table.COLUMN_LONG)), 1F);
|
||||
cursor.getDouble(cursor.getColumnIndex(Table.COLUMN_LONG)), 1F);
|
||||
|
||||
final Sitelinks.Builder builder = new Sitelinks.Builder();
|
||||
builder.setWikipediaLink(cursor.getString(cursor.getColumnIndex(Table.COLUMN_WIKIPEDIA_LINK)));
|
||||
|
|
@ -165,8 +165,7 @@ 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))),
|
||||
cursor.getString(cursor.getColumnIndex(Table.COLUMN_ENTITY_ID))
|
||||
Boolean.parseBoolean(cursor.getString(cursor.getColumnIndex(Table.COLUMN_EXISTS)))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +184,6 @@ 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;
|
||||
}
|
||||
|
||||
|
|
@ -206,46 +204,43 @@ 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 = {
|
||||
COLUMN_NAME,
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS,
|
||||
COLUMN_ENTITY_ID
|
||||
COLUMN_NAME,
|
||||
COLUMN_LANGUAGE,
|
||||
COLUMN_DESCRIPTION,
|
||||
COLUMN_CATEGORY,
|
||||
COLUMN_LABEL_TEXT,
|
||||
COLUMN_LABEL_ICON,
|
||||
COLUMN_LAT,
|
||||
COLUMN_LONG,
|
||||
COLUMN_IMAGE_URL,
|
||||
COLUMN_WIKIPEDIA_LINK,
|
||||
COLUMN_WIKIDATA_LINK,
|
||||
COLUMN_COMMONS_LINK,
|
||||
COLUMN_PIC,
|
||||
COLUMN_EXISTS,
|
||||
};
|
||||
|
||||
static final String DROP_TABLE_STATEMENT = "DROP TABLE IF EXISTS " + TABLE_NAME;
|
||||
|
||||
static final String CREATE_TABLE_STATEMENT = "CREATE TABLE " + TABLE_NAME + " ("
|
||||
+ COLUMN_NAME + " STRING PRIMARY KEY,"
|
||||
+ COLUMN_LANGUAGE + " STRING,"
|
||||
+ COLUMN_DESCRIPTION + " STRING,"
|
||||
+ COLUMN_CATEGORY + " STRING,"
|
||||
+ COLUMN_LABEL_TEXT + " STRING,"
|
||||
+ COLUMN_LABEL_ICON + " INTEGER,"
|
||||
+ COLUMN_LAT + " DOUBLE,"
|
||||
+ COLUMN_LONG + " DOUBLE,"
|
||||
+ COLUMN_IMAGE_URL + " STRING,"
|
||||
+ COLUMN_WIKIPEDIA_LINK + " STRING,"
|
||||
+ COLUMN_WIKIDATA_LINK + " STRING,"
|
||||
+ COLUMN_COMMONS_LINK + " STRING,"
|
||||
+ COLUMN_PIC + " STRING,"
|
||||
+ COLUMN_EXISTS + " STRING,"
|
||||
+ COLUMN_ENTITY_ID + " STRING"
|
||||
+ ");";
|
||||
+ COLUMN_NAME + " STRING PRIMARY KEY,"
|
||||
+ COLUMN_LANGUAGE + " STRING,"
|
||||
+ COLUMN_DESCRIPTION + " STRING,"
|
||||
+ COLUMN_CATEGORY + " STRING,"
|
||||
+ COLUMN_LABEL_TEXT + " STRING,"
|
||||
+ COLUMN_LABEL_ICON + " INTEGER,"
|
||||
+ COLUMN_LAT + " DOUBLE,"
|
||||
+ COLUMN_LONG + " DOUBLE,"
|
||||
+ COLUMN_IMAGE_URL + " STRING,"
|
||||
+ COLUMN_WIKIPEDIA_LINK + " STRING,"
|
||||
+ COLUMN_WIKIDATA_LINK + " STRING,"
|
||||
+ COLUMN_COMMONS_LINK + " STRING,"
|
||||
+ COLUMN_PIC + " STRING,"
|
||||
+ COLUMN_EXISTS + " STRING"
|
||||
+ ");";
|
||||
|
||||
public static void onCreate(SQLiteDatabase db) {
|
||||
db.execSQL(CREATE_TABLE_STATEMENT);
|
||||
|
|
@ -311,13 +306,6 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +65,19 @@ public class Place implements Parcelable {
|
|||
this.entityID = entityID;
|
||||
}
|
||||
|
||||
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;
|
||||
this.longDescription = longDescription;
|
||||
this.location = location;
|
||||
this.category = category;
|
||||
this.siteLinks = siteLinks;
|
||||
this.pic = (pic == null) ? "" : pic;
|
||||
this.exists = exists;
|
||||
}
|
||||
|
||||
public Place(String name, String longDescription, LatLng location, String category,
|
||||
Sitelinks siteLinks, String pic, String thumb, String entityID) {
|
||||
this.name = name;
|
||||
|
|
@ -345,19 +358,40 @@ public class Place implements Parcelable {
|
|||
return thumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the thumbnail URL for the place.
|
||||
*
|
||||
* @param thumb the thumbnail URL to set
|
||||
*/
|
||||
public void setThumb(String thumb) {
|
||||
this.thumb = thumb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the label for the place.
|
||||
*
|
||||
* @param label the label to set
|
||||
*/
|
||||
public void setLabel(Label label) {
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the long description for the place.
|
||||
*
|
||||
* @param longDescription the long description to set
|
||||
*/
|
||||
public void setLongDescription(String longDescription) {
|
||||
this.longDescription = longDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the Commons category for the place.
|
||||
*
|
||||
* @param category the category to set
|
||||
*/
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import io.reactivex.Completable;
|
|||
|
||||
/**
|
||||
* Data Access Object (DAO) for accessing the Place entity in the database.
|
||||
* This class provides methods for storing and retrieving Place objects,
|
||||
* utilized for the caching of places in the Nearby Map feature.
|
||||
*/
|
||||
@Dao
|
||||
public abstract class PlaceDao {
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
private Place nearestPlace;
|
||||
private volatile boolean stopQuery;
|
||||
|
||||
private List<Place> updatedPlaceList;
|
||||
private List<Place> updatedPlacesList;
|
||||
private LatLng updatedLatLng;
|
||||
private boolean searchable;
|
||||
|
||||
|
|
@ -610,11 +610,11 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
if (locationPermissionsHelper.checkLocationPermission(getActivity())) {
|
||||
if (lastFocusLocation == null && lastKnownLocation == null) {
|
||||
locationPermissionGranted();
|
||||
} else if (updatedPlaceList != null) {
|
||||
if (updatedPlaceList.size() != 0) {
|
||||
loadPlacesDataAsync(updatedPlaceList, updatedLatLng);
|
||||
} else if (updatedPlacesList != null) {
|
||||
if (updatedPlacesList.size() != 0) {
|
||||
loadPlacesDataAsync(updatedPlacesList, updatedLatLng);
|
||||
} else {
|
||||
updateMapMarkers(updatedPlaceList, getLastMapFocus(), false);
|
||||
updateMapMarkers(updatedPlacesList, getLastMapFocus(), false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1257,10 +1257,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
? getTextBetweenParentheses(
|
||||
updatedPlace.getLongDescription()) : updatedPlace.getLongDescription());
|
||||
marker.showInfoWindow();
|
||||
for (int i = 0; i < updatedPlaceList.size(); i++) {
|
||||
Place pl = updatedPlaceList.get(i);
|
||||
for (int i = 0; i < updatedPlacesList.size(); i++) {
|
||||
Place pl = updatedPlacesList.get(i);
|
||||
if (pl.location == updatedPlace.location) {
|
||||
updatedPlaceList.set(i, updatedPlace);
|
||||
updatedPlacesList.set(i, updatedPlace);
|
||||
savePlaceToDatabase(place);
|
||||
}
|
||||
}
|
||||
|
|
@ -1373,7 +1373,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
int batchSize = 3;
|
||||
|
||||
updatedLatLng = curLatLng;
|
||||
updatedPlaceList = new ArrayList<>(placeList);
|
||||
updatedPlacesList = new ArrayList<>(placeList);
|
||||
|
||||
// Sorts the places by distance to ensure the nearest pins are ready for the user as soon
|
||||
// as possible.
|
||||
|
|
@ -1382,7 +1382,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
Comparator.comparingDouble(place -> place.getDistanceInDouble(getMapFocus())));
|
||||
}
|
||||
stopQuery = false;
|
||||
processBatchesSequentially(places, batchSize, updatedPlaceList, curLatLng, 0);
|
||||
processBatchesSequentially(places, batchSize, updatedPlacesList, curLatLng, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue