Nearby: Complete offline pins implementation

This commit is contained in:
savsch 2024-12-26 17:25:14 +05:30
parent 7b154c3dc1
commit 3a38a6636c
4 changed files with 33 additions and 15 deletions

View file

@ -33,7 +33,7 @@ public abstract class PlaceDao {
@Query("SELECT * from place WHERE entityID=:entity") @Query("SELECT * from place WHERE entityID=:entity")
public abstract Place getPlace(String entity); public abstract Place getPlace(String entity);
@Query("SELECT * from place WHERE latitude>=:latBegin AND longitude>=:lngBegin " @Query("SELECT * from place WHERE name!='' AND latitude>=:latBegin AND longitude>=:lngBegin "
+ "AND latitude<:latEnd AND longitude<:lngEnd") + "AND latitude<:latEnd AND longitude<:lngEnd")
public abstract List<Place> fetchPlaces(double latBegin, double lngBegin, public abstract List<Place> fetchPlaces(double latBegin, double lngBegin,
double latEnd, double lngEnd); double latEnd, double lngEnd);

View file

@ -5,6 +5,7 @@ import io.reactivex.Completable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import timber.log.Timber;
/** /**
* The LocalDataSource class for Places * The LocalDataSource class for Places
@ -29,7 +30,7 @@ public class PlacesLocalDataSource {
return placeDao.getPlace(entityID); return placeDao.getPlace(entityID);
} }
public List<Place> fetchPlaces(final LatLng mapTopRight, final LatLng mapBottomLeft) { public List<Place> fetchPlaces(final LatLng mapBottomLeft, final LatLng mapTopRight) {
class Constraint { class Constraint {
final double latBegin; final double latBegin;

View file

@ -1852,20 +1852,24 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
clickedMarker.closeInfoWindow(); clickedMarker.closeInfoWindow();
} }
clickedMarker = marker1; clickedMarker = marker1;
binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.VISIBLE); if (!isNetworkErrorOccurred) {
binding.bottomSheetDetails.icon.setVisibility(View.GONE); binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.VISIBLE);
binding.bottomSheetDetails.wikiDataLl.setVisibility(View.GONE); binding.bottomSheetDetails.icon.setVisibility(View.GONE);
if (Objects.equals(place.name, "")) { binding.bottomSheetDetails.wikiDataLl.setVisibility(View.GONE);
getPlaceData(place.getWikiDataEntityId(), place, marker1, isBookMarked); if (Objects.equals(place.name, "")) {
getPlaceData(place.getWikiDataEntityId(), place, marker1, isBookMarked);
} else {
marker.showInfoWindow();
binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.GONE);
binding.bottomSheetDetails.icon.setVisibility(View.VISIBLE);
binding.bottomSheetDetails.wikiDataLl.setVisibility(View.VISIBLE);
passInfoToSheet(place);
hideBottomSheet();
}
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} else { } else {
marker.showInfoWindow(); marker.showInfoWindow();
binding.bottomSheetDetails.dataCircularProgress.setVisibility(View.GONE);
binding.bottomSheetDetails.icon.setVisibility(View.VISIBLE);
binding.bottomSheetDetails.wikiDataLl.setVisibility(View.VISIBLE);
passInfoToSheet(place);
hideBottomSheet();
} }
bottomSheetDetailsBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
return true; return true;
}); });
return marker; return marker;

View file

@ -512,9 +512,22 @@ class NearbyParentFragmentPresenter
} }
} }
} else { } else {
localPlaceSearchJob = scope.launch { loadPlacesDataAyncJob?.cancel()
localPlaceSearchJob = scope.launch(Dispatchers.IO) {
delay(LOCAL_SCROLL_DELAY) delay(LOCAL_SCROLL_DELAY)
val mapFocus = nearbyParentFragmentView.mapFocus
val markerPlaceGroups = placesRepository.fetchPlaces(
nearbyParentFragmentView.screenBottomLeft,
nearbyParentFragmentView.screenTopRight
).sortedBy { it.getDistanceInDouble(mapFocus) }.take(NearbyController.MAX_RESULTS)
.map {
MarkerPlaceGroup(
bookmarkLocationDao.findBookmarkLocation(it), it
)
}
ensureActive()
NearbyController.currentLocation = mapFocus
schedulePlacesUpdate(markerPlaceGroups, force = true)
} }
} }
} }