Skip to content

Made Split to Nearby Query into a fast query for coordinates + a details query for each pin #5731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8be9deb
Splitted the query
kanahia1 May 14, 2024
3e9c3a6
Made changes to the query
kanahia1 May 15, 2024
8e343f2
Improvised query
kanahia1 May 16, 2024
015772c
Improvised query by dividing in the batches
kanahia1 May 17, 2024
4da6ed9
Fixed failing tests
kanahia1 May 17, 2024
296eb5b
Improved batches
kanahia1 May 18, 2024
49fd84b
Improved sorting
kanahia1 May 18, 2024
c1e16b3
Fixes issue caused by search this area button
kanahia1 May 19, 2024
8315777
Fixed failing tests
kanahia1 May 19, 2024
13a390a
Fixed unnecessary reloads on onResume
kanahia1 May 29, 2024
79b2573
Fixed few pins not loading on changing apps
kanahia1 May 29, 2024
ac3a2d6
Improved zoom level and fixed the pins not loading from the center
kanahia1 May 30, 2024
c56a16e
Removed toggle chips and changed pin's color
kanahia1 Jun 2, 2024
53ea9c9
Fixed wikidata url
kanahia1 Jun 2, 2024
a94e8b4
Fixed unit tests
kanahia1 Jun 2, 2024
bc7ed14
Implemented retry with delay of 5000ms
kanahia1 Jun 6, 2024
27c8443
Fixed exception issue and pins issue
kanahia1 Jun 12, 2024
2fa7eac
Added change color icon to pin
kanahia1 Jun 13, 2024
f25caa1
merged pr
kanahia1 Jun 13, 2024
e71c3f8
Merge branch 'commons-app-main'
kanahia1 Jun 13, 2024
ef8f73a
Improved pin clicking
kanahia1 Jun 13, 2024
a11003a
Removed search this area button
kanahia1 Jun 29, 2024
411ef31
Implemented caching of places
kanahia1 Jun 30, 2024
cfb1575
Fixed unit test
kanahia1 Jun 30, 2024
438aa3b
Factorized methods
kanahia1 Jul 7, 2024
a281173
Changed primary key from location to entity id
kanahia1 Jul 8, 2024
0478a9b
Fixed tests
kanahia1 Jul 8, 2024
c314327
Merge branch 'main' into main
kanahia1 Jul 8, 2024
c2e14b7
Fixed conflicts
kanahia1 Jul 8, 2024
97019c9
Fixed unit test
kanahia1 Jul 8, 2024
5caa0bc
Fixed unit test
kanahia1 Jul 10, 2024
2251c62
Fixed the bug
kanahia1 Jul 10, 2024
67a2eb4
Merge branch 'main' into main
kanahia1 Jul 12, 2024
6fed9f4
Fixed issue with pin loading on the first launch
kanahia1 Jul 28, 2024
a51affe
Merge remote-tracking branch 'origin/main'
kanahia1 Jul 28, 2024
4985462
Merge branch 'commons-app:main' into main
kanahia1 Jul 28, 2024
efbea39
Updated javadocs
kanahia1 Jul 28, 2024
20810b9
Merge remote-tracking branch 'origin/main'
kanahia1 Jul 28, 2024
3fcfb20
Temporary commit - only for testing
kanahia1 Jul 28, 2024
6d87282
Replaced Temporary commit
kanahia1 Jul 28, 2024
4f7cbfc
Temporary commit - Added jcenter
kanahia1 Jul 28, 2024
fb80b3a
Made minor changes
kanahia1 Aug 1, 2024
7c79e46
Fixed unit tests
kanahia1 Aug 1, 2024
6258163
Fixed unit tests
kanahia1 Aug 1, 2024
5686135
Merge branch 'main' into main
kanahia1 Aug 3, 2024
b1c98b0
Fixed minor bug
kanahia1 Aug 3, 2024
6d64533
Merge remote-tracking branch 'origin/main'
kanahia1 Aug 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improvised query by dividing in the batches
  • Loading branch information
kanahia1 committed May 17, 2024
commit 015772cd8e10e34eed4abced92242592a22088ad
90 changes: 62 additions & 28 deletions app/src/main/java/fr/free/nrw/commons/nearby/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.Nullable;

import org.apache.commons.lang3.StringUtils;

import fr.free.nrw.commons.location.LatLng;
import fr.free.nrw.commons.nearby.model.NearbyResultItem;
import fr.free.nrw.commons.utils.PlaceUtils;
import org.apache.commons.lang3.StringUtils;
import timber.log.Timber;

/**
Expand Down Expand Up @@ -46,25 +43,27 @@ public Place() {
siteLinks = null;
}

public Place(String language,String name, Label label, String longDescription, LatLng location, String category, Sitelinks siteLinks, String pic, Boolean exists) {
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.pic = (pic == null) ? "" : pic;
this.exists = exists;
}

public Place(String name, String longDescription, LatLng location, String category, Sitelinks siteLinks, String pic, String thumb) {
public Place(String name, String longDescription, LatLng location, String category,
Sitelinks siteLinks, String pic, String thumb) {
this.name = name;
this.longDescription = longDescription;
this.location = location;
this.category = category;
this.siteLinks = siteLinks;
this.pic = (pic == null) ? "":pic;
this.pic = (pic == null) ? "" : pic;
this.thumb = thumb;
this.language = null;
this.label = null;
Expand All @@ -80,19 +79,22 @@ public Place(Parcel in) {
this.category = in.readString();
this.siteLinks = in.readParcelable(Sitelinks.class.getClassLoader());
String picString = in.readString();
this.pic = (picString == null) ? "":picString;
this.pic = (picString == null) ? "" : picString;
String existString = in.readString();
this.exists = Boolean.parseBoolean(existString);
this.isMonument = in.readInt() == 1;
}

public static Place from(NearbyResultItem item) {
String itemClass = item.getClassName().getValue();
String classEntityId = "";
if(!StringUtils.isBlank(itemClass)) {
if (!StringUtils.isBlank(itemClass)) {
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() : "";
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
Expand All @@ -104,8 +106,8 @@ public static Place from(NearbyResultItem item) {
*/
description = ((item.getLabel().getValue() != null && !item.getLabel().getValue().isEmpty())
? item.getLabel().getValue()
+ ((description != null && !description.isEmpty())
? " (" + description + ")" : "")
+ ((description != null && !description.isEmpty())
? " (" + description + ")" : "")
: description);
return new Place(
item.getLabel().getLanguage(),
Expand All @@ -126,6 +128,7 @@ public static Place from(NearbyResultItem item) {

/**
* Gets the language of the caption ie name.
*
* @return language
*/
public String getLanguage() {
Expand All @@ -134,12 +137,31 @@ public String getLanguage() {

/**
* Gets the name of the place
*
* @return name
*/
public String getName() {
return name;
}

/**
* Gets the name of the place
*
* @return name
*/
public String getName() { return name; }
public Double getDistanceInDouble() {
double distanceValue = 0.0;
if (distance.endsWith("km")) {
distanceValue = Double.parseDouble(distance.replace("km", ""));
} else if (distance.endsWith("m")) {
distanceValue = Double.parseDouble(distance.replace("m", "")) / 1000;
}
return distanceValue;
}

/** Gets the label of the place
* e.g. "building", "city", etc
/**
* Gets the label of the place e.g. "building", "city", etc
*
* @return label
*/
public Label getLabel() {
Expand All @@ -152,6 +174,7 @@ public LatLng getLocation() {

/**
* Gets the long description of the place
*
* @return long description
*/
public String getLongDescription() {
Expand All @@ -160,12 +183,16 @@ public String getLongDescription() {

/**
* Gets the Commons category of the place
*
* @return Commons category
*/
public String getCategory() {return category; }
public String getCategory() {
return category;
}

/**
* Sets the distance of the place from the user's location
*
* @param distance distance of place from user's location
*/
public void setDistance(String distance) {
Expand All @@ -174,6 +201,7 @@ public void setDistance(String distance) {

/**
* Extracts the entity id from the wikidata link
*
* @return returns the entity id if wikidata link destroyed
*/
@Nullable
Expand All @@ -189,6 +217,7 @@ public String getWikiDataEntityId() {

/**
* Checks if the Wikidata item has a Wikipedia page associated with it
*
* @return true if there is a Wikipedia link
*/
public boolean hasWikipediaLink() {
Expand All @@ -197,6 +226,7 @@ public boolean hasWikipediaLink() {

/**
* Checks if the Wikidata item has a Wikidata page associated with it
*
* @return true if there is a Wikidata link
*/
public boolean hasWikidataLink() {
Expand All @@ -205,6 +235,7 @@ public boolean hasWikidataLink() {

/**
* Checks if the Wikidata item has a Commons page associated with it
*
* @return true if there is a Commons link
*/
public boolean hasCommonsLink() {
Expand All @@ -213,6 +244,7 @@ public boolean hasCommonsLink() {

/**
* Sets that this place in nearby is a WikiData monument
*
* @param monument
*/
public void setMonument(final boolean monument) {
Expand All @@ -221,6 +253,7 @@ public void setMonument(final boolean monument) {

/**
* Returns if this place is a WikiData monument
*
* @return
*/
public boolean isMonument() {
Expand All @@ -229,6 +262,7 @@ public boolean isMonument() {

/**
* Check if we already have the exact same Place
*
* @param o Place being tested
* @return true if name and location of Place is exactly the same
*/
Expand All @@ -250,17 +284,17 @@ public int hashCode() {
@Override
public String toString() {
return "Place{" +
"name='" + name + '\'' +
", lang='" + language + '\'' +
", label='" + label + '\'' +
", longDescription='" + longDescription + '\'' +
", location='" + location + '\'' +
", category='" + category + '\'' +
", distance='" + distance + '\'' +
", siteLinks='" + siteLinks.toString() + '\'' +
", pic='" + pic + '\'' +
", exists='" + exists.toString() + '\'' +
'}';
"name='" + name + '\'' +
", lang='" + language + '\'' +
", label='" + label + '\'' +
", longDescription='" + longDescription + '\'' +
", location='" + location + '\'' +
", category='" + category + '\'' +
", distance='" + distance + '\'' +
", siteLinks='" + siteLinks.toString() + '\'' +
", pic='" + pic + '\'' +
", exists='" + exists.toString() + '\'' +
'}';
}

@Override
Expand Down
Loading
Loading