mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 13:23:58 +01:00
PlacesRepository: Add methods for fetching places in geo bounds
This commit is contained in:
parent
b12f247042
commit
984a8fabd1
4 changed files with 28 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import androidx.room.Insert;
|
|||
import androidx.room.OnConflictStrategy;
|
||||
import androidx.room.Query;
|
||||
import io.reactivex.Completable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Data Access Object (DAO) for accessing the Place entity in the database.
|
||||
|
|
@ -32,6 +33,11 @@ public abstract class PlaceDao {
|
|||
@Query("SELECT * from place WHERE entityID=:entity")
|
||||
public abstract Place getPlace(String entity);
|
||||
|
||||
@Query("SELECT * from place WHERE latitude>=:latBegin AND longitude>=:lngBegin "
|
||||
+ "AND latitude<:latEnd AND longitude<:lngEnd")
|
||||
public abstract List<Place> fetchPlaces(double latBegin, double lngBegin,
|
||||
double latEnd, double lngEnd);
|
||||
|
||||
/**
|
||||
* Saves a Place object asynchronously into the database.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.nearby;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -26,6 +27,11 @@ public class PlacesLocalDataSource {
|
|||
return placeDao.getPlace(entityID);
|
||||
}
|
||||
|
||||
public List<Place> fetchPlaces(final double latBegin, final double lngBegin,
|
||||
final double latEnd, final double lngEnd) {
|
||||
return placeDao.fetchPlaces(latBegin, lngBegin, latEnd, lngEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a Place object asynchronously into the database.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import fr.free.nrw.commons.contributions.Contribution;
|
|||
import fr.free.nrw.commons.location.LatLng;
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
|
@ -39,6 +40,11 @@ public class PlacesRepository {
|
|||
return localDataSource.fetchPlace(entityID);
|
||||
}
|
||||
|
||||
public List<Place> fetchPlaces(final double latBegin, final double lngBegin,
|
||||
final double latEnd, final double lngEnd) {
|
||||
return localDataSource.fetchPlaces(latBegin, lngBegin, latEnd, lngEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the Nearby cache on an IO thread.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class NearbyParentFragmentPresenter
|
|||
|
||||
private var placeSearchJob: Job? = null
|
||||
private var isSearchInProgress = false
|
||||
private var localPlaceSearchJob: Job? = null
|
||||
|
||||
private val clickedPlaces = CopyOnWriteArrayList<Place>()
|
||||
|
||||
|
|
@ -495,8 +496,9 @@ class NearbyParentFragmentPresenter
|
|||
@Override
|
||||
override fun handleMapScrolled(scope: LifecycleCoroutineScope?) {
|
||||
scope ?: return
|
||||
|
||||
placeSearchJob?.cancel()
|
||||
placeSearchJob = scope.launch {
|
||||
placeSearchJob = scope.launch(Dispatchers.Main) {
|
||||
delay(SCROLL_DELAY)
|
||||
if (!isSearchInProgress) {
|
||||
isSearchInProgress = true; // search executing flag
|
||||
|
|
@ -508,6 +510,12 @@ class NearbyParentFragmentPresenter
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
localPlaceSearchJob?.cancel()
|
||||
localPlaceSearchJob = scope.launch {
|
||||
delay(LOCAL_SCROLL_DELAY)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -583,6 +591,7 @@ class NearbyParentFragmentPresenter
|
|||
|
||||
companion object {
|
||||
private const val SCROLL_DELAY = 800L; // Delay for debounce of onscroll, in milliseconds.
|
||||
private const val LOCAL_SCROLL_DELAY = 200L; // SCROLL_DELAY but for local db place search
|
||||
private val DUMMY = Proxy.newProxyInstance(
|
||||
NearbyParentFragmentContract.View::class.java.getClassLoader(),
|
||||
arrayOf<Class<*>>(NearbyParentFragmentContract.View::class.java),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue