mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Replace Mapbox with OSMDroid (Explore Activity) (#5475)
* Fixed Grey empty screen at Upload wizard caption step after denying files permission * Empty commit * Fixed loop issue * Created docs for earlier commits * Fixed javadoc * Fixed spaces * Added added basic features to OSM Maps * Added search location feature * Added filter to Open Street Maps * Fixed chipGroup in Open Street Maps * Removed mapBox code * Removed mapBox's code * Reformat code * Reformatted code * Removed rotation feature to map * Removed rotation files and Fixed Marker click problem * Ignored failing tests * Added voice input feature * Fixed test cases * Changed caption and description text * Replaced mapbox to osmdroid in upload activity * Fixed Unit Tests * Made selected marker to be fixed on map * Changed color of map marker * Fixes #5439 by capitalizing first letter of voice input * Made UI changes in UploadMediaDetailAdapter * Added javadoc * Replaced Mapbox with OSMDroid in explore activity --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
02ce017c98
commit
96b2608eb1
5 changed files with 631 additions and 561 deletions
|
|
@ -14,32 +14,27 @@ public class ExploreMapContract {
|
||||||
|
|
||||||
interface View {
|
interface View {
|
||||||
boolean isNetworkConnectionEstablished();
|
boolean isNetworkConnectionEstablished();
|
||||||
void populatePlaces(LatLng curlatLng,LatLng searchLatLng);
|
void populatePlaces(LatLng curlatLng);
|
||||||
void checkPermissionsAndPerformAction();
|
void checkPermissionsAndPerformAction();
|
||||||
void recenterMap(LatLng curLatLng);
|
void recenterMap(LatLng curLatLng);
|
||||||
void showLocationOffDialog();
|
void showLocationOffDialog();
|
||||||
void openLocationSettings();
|
void openLocationSettings();
|
||||||
void hideBottomDetailsSheet();
|
void hideBottomDetailsSheet();
|
||||||
void displayBottomSheetWithInfo(Marker marker);
|
void displayBottomSheetWithInfo(Marker marker);
|
||||||
void addOnCameraMoveListener();
|
LatLng getMapCenter();
|
||||||
|
LatLng getMapFocus();
|
||||||
|
LatLng getLastMapFocus();
|
||||||
|
void addMarkersToMap(final List<NearbyBaseMarker> nearbyBaseMarkers);
|
||||||
|
void clearAllMarkers();
|
||||||
void addSearchThisAreaButtonAction();
|
void addSearchThisAreaButtonAction();
|
||||||
void setSearchThisAreaButtonVisibility(boolean isVisible);
|
void setSearchThisAreaButtonVisibility(boolean isVisible);
|
||||||
void setProgressBarVisibility(boolean isVisible);
|
void setProgressBarVisibility(boolean isVisible);
|
||||||
boolean isDetailsBottomSheetVisible();
|
boolean isDetailsBottomSheetVisible();
|
||||||
boolean isSearchThisAreaButtonVisible();
|
boolean isSearchThisAreaButtonVisible();
|
||||||
void addCurrentLocationMarker(LatLng curLatLng);
|
|
||||||
void updateMapToTrackPosition(LatLng curLatLng);
|
|
||||||
Context getContext();
|
Context getContext();
|
||||||
LatLng getCameraTarget();
|
|
||||||
void centerMapToPlace(Place placeToCenter);
|
|
||||||
LatLng getLastLocation();
|
LatLng getLastLocation();
|
||||||
com.mapbox.mapboxsdk.geometry.LatLng getLastFocusLocation();
|
|
||||||
boolean isCurrentLocationMarkerVisible();
|
|
||||||
void setProjectorLatLngBounds();
|
|
||||||
void disableFABRecenter();
|
void disableFABRecenter();
|
||||||
void enableFABRecenter();
|
void enableFABRecenter();
|
||||||
void addNearbyMarkersToMapBoxMap(final List<NearbyBaseMarker> nearbyBaseMarkers, final Marker selectedMarker);
|
|
||||||
void setMapBoundaries(CameraUpdate cameaUpdate);
|
|
||||||
void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
|
void setFABRecenterAction(android.view.View.OnClickListener onClickListener);
|
||||||
boolean backButtonClicked();
|
boolean backButtonClicked();
|
||||||
}
|
}
|
||||||
|
|
@ -51,9 +46,6 @@ public class ExploreMapContract {
|
||||||
void detachView();
|
void detachView();
|
||||||
void setActionListeners(JsonKvStore applicationKvStore);
|
void setActionListeners(JsonKvStore applicationKvStore);
|
||||||
boolean backButtonClicked();
|
boolean backButtonClicked();
|
||||||
void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng);
|
|
||||||
void markerUnselected();
|
|
||||||
void markerSelected(Marker marker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ import javax.inject.Inject;
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class ExploreMapController extends MapController {
|
public class ExploreMapController extends MapController {
|
||||||
|
|
||||||
private final ExploreMapCalls exploreMapCalls;
|
private final ExploreMapCalls exploreMapCalls;
|
||||||
public LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
|
public LatLng latestSearchLocation; // Can be current and camera target on search this area button is used
|
||||||
public LatLng currentLocation; // current location of user
|
public LatLng currentLocation; // current location of user
|
||||||
|
|
@ -46,13 +47,18 @@ public class ExploreMapController extends MapController {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Takes location as parameter and returns ExplorePlaces info that holds curLatLng, mediaList, explorePlaceList and boundaryCoordinates
|
* Takes location as parameter and returns ExplorePlaces info that holds curLatLng, mediaList,
|
||||||
|
* explorePlaceList and boundaryCoordinates
|
||||||
|
*
|
||||||
* @param curLatLng is current geolocation
|
* @param curLatLng is current geolocation
|
||||||
* @param searchLatLng is the location that we want to search around
|
* @param searchLatLng is the location that we want to search around
|
||||||
* @param checkingAroundCurrentLocation is a boolean flag. True if we want to check around current location, false if another location
|
* @param checkingAroundCurrentLocation is a boolean flag. True if we want to check around
|
||||||
* @return explorePlacesInfo info that holds curLatLng, mediaList, explorePlaceList and boundaryCoordinates
|
* current location, false if another location
|
||||||
|
* @return explorePlacesInfo info that holds curLatLng, mediaList, explorePlaceList and
|
||||||
|
* boundaryCoordinates
|
||||||
*/
|
*/
|
||||||
public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean checkingAroundCurrentLocation) {
|
public ExplorePlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng,
|
||||||
|
boolean checkingAroundCurrentLocation) {
|
||||||
|
|
||||||
if (searchLatLng == null) {
|
if (searchLatLng == null) {
|
||||||
Timber.d("Loading attractions explore map, but search is null");
|
Timber.d("Loading attractions explore map, but search is null");
|
||||||
|
|
@ -74,18 +80,23 @@ public class ExploreMapController extends MapController {
|
||||||
Timber.d("Sorting places by distance...");
|
Timber.d("Sorting places by distance...");
|
||||||
final Map<Media, Double> distances = new HashMap<>();
|
final Map<Media, Double> distances = new HashMap<>();
|
||||||
for (Media media : mediaList) {
|
for (Media media : mediaList) {
|
||||||
distances.put(media, computeDistanceBetween(media.getCoordinates(), searchLatLng));
|
distances.put(media,
|
||||||
|
computeDistanceBetween(media.getCoordinates(), searchLatLng));
|
||||||
// Find boundaries with basic find max approach
|
// Find boundaries with basic find max approach
|
||||||
if (media.getCoordinates().getLatitude() < boundaryCoordinates[0].getLatitude()) {
|
if (media.getCoordinates().getLatitude()
|
||||||
|
< boundaryCoordinates[0].getLatitude()) {
|
||||||
boundaryCoordinates[0] = media.getCoordinates();
|
boundaryCoordinates[0] = media.getCoordinates();
|
||||||
}
|
}
|
||||||
if (media.getCoordinates().getLatitude() > boundaryCoordinates[1].getLatitude()) {
|
if (media.getCoordinates().getLatitude()
|
||||||
|
> boundaryCoordinates[1].getLatitude()) {
|
||||||
boundaryCoordinates[1] = media.getCoordinates();
|
boundaryCoordinates[1] = media.getCoordinates();
|
||||||
}
|
}
|
||||||
if (media.getCoordinates().getLongitude() < boundaryCoordinates[2].getLongitude()) {
|
if (media.getCoordinates().getLongitude()
|
||||||
|
< boundaryCoordinates[2].getLongitude()) {
|
||||||
boundaryCoordinates[2] = media.getCoordinates();
|
boundaryCoordinates[2] = media.getCoordinates();
|
||||||
}
|
}
|
||||||
if (media.getCoordinates().getLongitude() > boundaryCoordinates[3].getLongitude()) {
|
if (media.getCoordinates().getLongitude()
|
||||||
|
> boundaryCoordinates[3].getLongitude()) {
|
||||||
boundaryCoordinates[3] = media.getCoordinates();
|
boundaryCoordinates[3] = media.getCoordinates();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -96,7 +107,8 @@ public class ExploreMapController extends MapController {
|
||||||
|
|
||||||
// Sets latestSearchRadius to maximum distance among boundaries and search location
|
// Sets latestSearchRadius to maximum distance among boundaries and search location
|
||||||
for (LatLng bound : boundaryCoordinates) {
|
for (LatLng bound : boundaryCoordinates) {
|
||||||
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(bound).distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(latestSearchLocation));
|
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(bound)
|
||||||
|
.distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(latestSearchLocation));
|
||||||
if (distance > latestSearchRadius) {
|
if (distance > latestSearchRadius) {
|
||||||
latestSearchRadius = distance;
|
latestSearchRadius = distance;
|
||||||
}
|
}
|
||||||
|
|
@ -115,6 +127,7 @@ public class ExploreMapController extends MapController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads attractions from location for map view, we need to return places in Place data type
|
* Loads attractions from location for map view, we need to return places in Place data type
|
||||||
|
*
|
||||||
* @return baseMarkerOptions list that holds nearby places with their icons
|
* @return baseMarkerOptions list that holds nearby places with their icons
|
||||||
*/
|
*/
|
||||||
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
public static List<NearbyBaseMarker> loadAttractionsFromLocationToBaseMarkerOptions(
|
||||||
|
|
@ -123,7 +136,6 @@ public class ExploreMapController extends MapController {
|
||||||
Context context,
|
Context context,
|
||||||
NearbyBaseMarkerThumbCallback callback,
|
NearbyBaseMarkerThumbCallback callback,
|
||||||
Marker selectedMarker,
|
Marker selectedMarker,
|
||||||
boolean shouldTrackPosition,
|
|
||||||
ExplorePlacesInfo explorePlacesInfo) {
|
ExplorePlacesInfo explorePlacesInfo) {
|
||||||
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
|
List<NearbyBaseMarker> baseMarkerOptions = new ArrayList<>();
|
||||||
|
|
||||||
|
|
@ -145,7 +157,8 @@ public class ExploreMapController extends MapController {
|
||||||
String distance = formatDistanceBetween(curLatLng, explorePlace.location);
|
String distance = formatDistanceBetween(curLatLng, explorePlace.location);
|
||||||
explorePlace.setDistance(distance);
|
explorePlace.setDistance(distance);
|
||||||
|
|
||||||
nearbyBaseMarker.title(explorePlace.name.substring(5, explorePlace.name.lastIndexOf(".")));
|
nearbyBaseMarker.title(
|
||||||
|
explorePlace.name.substring(5, explorePlace.name.lastIndexOf(".")));
|
||||||
nearbyBaseMarker.position(
|
nearbyBaseMarker.position(
|
||||||
new com.mapbox.mapboxsdk.geometry.LatLng(
|
new com.mapbox.mapboxsdk.geometry.LatLng(
|
||||||
explorePlace.location.getLatitude(),
|
explorePlace.location.getLatitude(),
|
||||||
|
|
@ -160,12 +173,15 @@ public class ExploreMapController extends MapController {
|
||||||
.into(new CustomTarget<Bitmap>() {
|
.into(new CustomTarget<Bitmap>() {
|
||||||
// We add icons to markers when bitmaps are ready
|
// We add icons to markers when bitmaps are ready
|
||||||
@Override
|
@Override
|
||||||
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
public void onResourceReady(@NonNull Bitmap resource,
|
||||||
|
@Nullable Transition<? super Bitmap> transition) {
|
||||||
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromBitmap(
|
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromBitmap(
|
||||||
ImageUtils.addRedBorder(resource, 6, context)));
|
ImageUtils.addRedBorder(resource, 6, context)));
|
||||||
baseMarkerOptions.add(nearbyBaseMarker);
|
baseMarkerOptions.add(nearbyBaseMarker);
|
||||||
if (baseMarkerOptions.size() == placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
|
if (baseMarkerOptions.size()
|
||||||
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions, explorePlacesInfo, selectedMarker, shouldTrackPosition);
|
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
|
||||||
|
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
|
||||||
|
explorePlacesInfo, selectedMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -177,10 +193,13 @@ public class ExploreMapController extends MapController {
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFailed(@Nullable final Drawable errorDrawable) {
|
public void onLoadFailed(@Nullable final Drawable errorDrawable) {
|
||||||
super.onLoadFailed(errorDrawable);
|
super.onLoadFailed(errorDrawable);
|
||||||
nearbyBaseMarker.setIcon(IconFactory.getInstance(context).fromResource(R.drawable.image_placeholder_96));
|
nearbyBaseMarker.setIcon(IconFactory.getInstance(context)
|
||||||
|
.fromResource(R.drawable.image_placeholder_96));
|
||||||
baseMarkerOptions.add(nearbyBaseMarker);
|
baseMarkerOptions.add(nearbyBaseMarker);
|
||||||
if (baseMarkerOptions.size() == placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
|
if (baseMarkerOptions.size()
|
||||||
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions, explorePlacesInfo, selectedMarker, shouldTrackPosition);
|
== placeList.size()) { // if true, we added all markers to list and can trigger thumbs ready callback
|
||||||
|
callback.onNearbyBaseMarkerThumbsReady(baseMarkerOptions,
|
||||||
|
explorePlacesInfo, selectedMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -190,7 +209,9 @@ public class ExploreMapController extends MapController {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface NearbyBaseMarkerThumbCallback {
|
interface NearbyBaseMarkerThumbCallback {
|
||||||
|
|
||||||
// Callback to notify thumbnails of explore markers are added as icons and ready
|
// Callback to notify thumbnails of explore markers are added as icons and ready
|
||||||
void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers, ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker, boolean shouldTrackPosition);
|
void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers,
|
||||||
|
ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,9 +1,11 @@
|
||||||
package fr.free.nrw.commons.explore.map;
|
package fr.free.nrw.commons.explore.map;
|
||||||
|
|
||||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||||
|
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED;
|
||||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.SEARCH_CUSTOM_AREA;
|
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.SEARCH_CUSTOM_AREA;
|
||||||
|
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||||
|
|
@ -25,9 +27,9 @@ import timber.log.Timber;
|
||||||
public class ExploreMapPresenter
|
public class ExploreMapPresenter
|
||||||
implements ExploreMapContract.UserActions,
|
implements ExploreMapContract.UserActions,
|
||||||
NearbyBaseMarkerThumbCallback {
|
NearbyBaseMarkerThumbCallback {
|
||||||
|
|
||||||
BookmarkLocationsDao bookmarkLocationDao;
|
BookmarkLocationsDao bookmarkLocationDao;
|
||||||
private boolean isNearbyLocked;
|
private boolean isNearbyLocked;
|
||||||
private boolean placesLoadedOnce;
|
|
||||||
private LatLng curLatLng;
|
private LatLng curLatLng;
|
||||||
private ExploreMapController exploreMapController;
|
private ExploreMapController exploreMapController;
|
||||||
|
|
||||||
|
|
@ -71,14 +73,6 @@ public class ExploreMapPresenter
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LatLng lastLocation = exploreMapFragmentView.getLastLocation();
|
|
||||||
curLatLng = lastLocation;
|
|
||||||
|
|
||||||
if (curLatLng == null) {
|
|
||||||
Timber.d("Skipping update of nearby places as location is unavailable");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Significant changed - Markers and current location will be updated together
|
* Significant changed - Markers and current location will be updated together
|
||||||
* Slightly changed - Only current position marker will be updated
|
* Slightly changed - Only current position marker will be updated
|
||||||
|
|
@ -87,24 +81,21 @@ public class ExploreMapPresenter
|
||||||
Timber.d("LOCATION_SIGNIFICANTLY_CHANGED");
|
Timber.d("LOCATION_SIGNIFICANTLY_CHANGED");
|
||||||
lockUnlockNearby(true);
|
lockUnlockNearby(true);
|
||||||
exploreMapFragmentView.setProgressBarVisibility(true);
|
exploreMapFragmentView.setProgressBarVisibility(true);
|
||||||
exploreMapFragmentView.populatePlaces(curLatLng, lastLocation);
|
exploreMapFragmentView.populatePlaces(exploreMapFragmentView.getMapCenter());
|
||||||
|
|
||||||
} else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) {
|
} else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) {
|
||||||
Timber.d("SEARCH_CUSTOM_AREA");
|
Timber.d("SEARCH_CUSTOM_AREA");
|
||||||
lockUnlockNearby(true);
|
lockUnlockNearby(true);
|
||||||
exploreMapFragmentView.setProgressBarVisibility(true);
|
exploreMapFragmentView.setProgressBarVisibility(true);
|
||||||
exploreMapFragmentView.populatePlaces(curLatLng, exploreMapFragmentView.getCameraTarget());
|
exploreMapFragmentView.populatePlaces(exploreMapFragmentView.getMapFocus());
|
||||||
} else { // Means location changed slightly, ie user is walking or driving.
|
} else { // Means location changed slightly, ie user is walking or driving.
|
||||||
Timber.d("Means location changed slightly");
|
Timber.d("Means location changed slightly");
|
||||||
if (exploreMapFragmentView.isCurrentLocationMarkerVisible()){ // Means user wants to see their live location
|
|
||||||
exploreMapFragmentView.recenterMap(curLatLng);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Nearby updates takes time, since they are network operations. During update time, we don't
|
* Nearby updates takes time, since they are network operations. During update time, we don't
|
||||||
* want to get any other calls from user. So locking nearby.
|
* want to get any other calls from user. So locking nearby.
|
||||||
|
*
|
||||||
* @param isNearbyLocked true means lock, false means unlock
|
* @param isNearbyLocked true means lock, false means unlock
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -143,25 +134,6 @@ public class ExploreMapPresenter
|
||||||
return exploreMapFragmentView.backButtonClicked();
|
return exploreMapFragmentView.backButtonClicked();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng) {
|
|
||||||
exploreMapFragmentView.setProjectorLatLngBounds();
|
|
||||||
// If our nearby markers are calculated at least once
|
|
||||||
if (exploreMapController.latestSearchLocation != null) {
|
|
||||||
double distance = latLng.distanceTo
|
|
||||||
(LocationUtils.commonsLatLngToMapBoxLatLng(exploreMapController.latestSearchLocation));
|
|
||||||
if (exploreMapFragmentView.isNetworkConnectionEstablished()) {
|
|
||||||
if (distance > exploreMapController.latestSearchRadius && exploreMapController.latestSearchRadius != 0) {
|
|
||||||
exploreMapFragmentView.setSearchThisAreaButtonVisibility(true);
|
|
||||||
} else {
|
|
||||||
exploreMapFragmentView.setSearchThisAreaButtonVisibility(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
exploreMapFragmentView.setSearchThisAreaButtonVisibility(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onMapReady(ExploreMapController exploreMapController) {
|
public void onMapReady(ExploreMapController exploreMapController) {
|
||||||
this.exploreMapController = exploreMapController;
|
this.exploreMapController = exploreMapController;
|
||||||
exploreMapFragmentView.addSearchThisAreaButtonAction();
|
exploreMapFragmentView.addSearchThisAreaButtonAction();
|
||||||
|
|
@ -177,7 +149,8 @@ public class ExploreMapPresenter
|
||||||
exploreMapFragmentView.addSearchThisAreaButtonAction();
|
exploreMapFragmentView.addSearchThisAreaButtonAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<ExplorePlacesInfo> loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean checkingAroundCurrent) {
|
public Observable<ExplorePlacesInfo> loadAttractionsFromLocation(LatLng curLatLng,
|
||||||
|
LatLng searchLatLng, boolean checkingAroundCurrent) {
|
||||||
return Observable
|
return Observable
|
||||||
.fromCallable(() -> exploreMapController
|
.fromCallable(() -> exploreMapController
|
||||||
.loadAttractionsFromLocation(curLatLng, searchLatLng, checkingAroundCurrent));
|
.loadAttractionsFromLocation(curLatLng, searchLatLng, checkingAroundCurrent));
|
||||||
|
|
@ -186,57 +159,39 @@ public class ExploreMapPresenter
|
||||||
/**
|
/**
|
||||||
* Populates places for custom location, should be used for finding nearby places around a
|
* Populates places for custom location, should be used for finding nearby places around a
|
||||||
* location where you are not at.
|
* location where you are not at.
|
||||||
|
*
|
||||||
* @param explorePlacesInfo This variable has placeToCenter list information and distances.
|
* @param explorePlacesInfo This variable has placeToCenter list information and distances.
|
||||||
*/
|
*/
|
||||||
public void updateMapMarkers(
|
public void updateMapMarkers(
|
||||||
MapController.ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker, boolean shouldTrackPosition) {
|
MapController.ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker) {
|
||||||
exploreMapFragmentView.setMapBoundaries(CameraUpdateFactory.newLatLngBounds(getLatLngBounds(explorePlacesInfo.boundaryCoordinates), 50));
|
if (explorePlacesInfo.mediaList != null) {
|
||||||
prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker, shouldTrackPosition);
|
prepareNearbyBaseMarkers(explorePlacesInfo, selectedMarker);
|
||||||
|
} else {
|
||||||
|
//TODO: SHOW SNACKBAR
|
||||||
|
lockUnlockNearby(false); // So that new location updates wont come
|
||||||
|
exploreMapFragmentView.setProgressBarVisibility(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void prepareNearbyBaseMarkers(MapController.ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker, boolean shouldTrackPosition) {
|
void prepareNearbyBaseMarkers(MapController.ExplorePlacesInfo explorePlacesInfo,
|
||||||
|
Marker selectedMarker) {
|
||||||
exploreMapController
|
exploreMapController
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.curLatLng, // Curlatlang will be used to calculate distances
|
.loadAttractionsFromLocationToBaseMarkerOptions(explorePlacesInfo.curLatLng,
|
||||||
|
// Curlatlang will be used to calculate distances
|
||||||
explorePlacesInfo.explorePlaceList,
|
explorePlacesInfo.explorePlaceList,
|
||||||
exploreMapFragmentView.getContext(),
|
exploreMapFragmentView.getContext(),
|
||||||
this,
|
this,
|
||||||
selectedMarker,
|
selectedMarker,
|
||||||
shouldTrackPosition,
|
|
||||||
explorePlacesInfo);
|
explorePlacesInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers, ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker, boolean shouldTrackPosition) {
|
public void onNearbyBaseMarkerThumbsReady(List<NearbyBaseMarker> baseMarkers,
|
||||||
|
ExplorePlacesInfo explorePlacesInfo, Marker selectedMarker) {
|
||||||
if (null != exploreMapFragmentView) {
|
if (null != exploreMapFragmentView) {
|
||||||
exploreMapFragmentView.addNearbyMarkersToMapBoxMap(baseMarkers, selectedMarker);
|
exploreMapFragmentView.addMarkersToMap(baseMarkers);
|
||||||
exploreMapFragmentView.addCurrentLocationMarker(explorePlacesInfo.curLatLng);
|
|
||||||
if(shouldTrackPosition){
|
|
||||||
exploreMapFragmentView.updateMapToTrackPosition(explorePlacesInfo.curLatLng);
|
|
||||||
}
|
|
||||||
lockUnlockNearby(false); // So that new location updates wont come
|
lockUnlockNearby(false); // So that new location updates wont come
|
||||||
exploreMapFragmentView.setProgressBarVisibility(false);
|
exploreMapFragmentView.setProgressBarVisibility(false);
|
||||||
handleCenteringTaskIfAny();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private LatLngBounds getLatLngBounds(LatLng[] boundaries) {
|
|
||||||
LatLngBounds latLngBounds = new LatLngBounds.Builder()
|
|
||||||
.include(LocationUtils.commonsLatLngToMapBoxLatLng(boundaries[0]))
|
|
||||||
.include(LocationUtils.commonsLatLngToMapBoxLatLng(boundaries[1]))
|
|
||||||
.include(LocationUtils.commonsLatLngToMapBoxLatLng(boundaries[2]))
|
|
||||||
.include(LocationUtils.commonsLatLngToMapBoxLatLng(boundaries[3]))
|
|
||||||
.build();
|
|
||||||
return latLngBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Some centering task may need to wait for map to be ready, if they are requested before
|
|
||||||
* map is ready. So we will remember it when the map is ready
|
|
||||||
*/
|
|
||||||
private void handleCenteringTaskIfAny() {
|
|
||||||
if (!placesLoadedOnce) {
|
|
||||||
placesLoadedOnce = true;
|
|
||||||
exploreMapFragmentView.centerMapToPlace(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,40 +209,29 @@ public class ExploreMapPresenter
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if search this area button is used around our current location, so that
|
* Returns true if search this area button is used around our current location, so that we can
|
||||||
* we can continue following our current location again
|
* continue following our current location again
|
||||||
|
*
|
||||||
* @return Returns true if search this area button is used around our current location
|
* @return Returns true if search this area button is used around our current location
|
||||||
*/
|
*/
|
||||||
public boolean searchCloseToCurrentLocation() {
|
public boolean searchCloseToCurrentLocation() {
|
||||||
if (null == exploreMapFragmentView.getLastFocusLocation() || exploreMapController.latestSearchRadius == 0) {
|
if (null == exploreMapFragmentView.getLastMapFocus()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(exploreMapFragmentView.getCameraTarget())
|
|
||||||
.distanceTo(exploreMapFragmentView.getLastFocusLocation());
|
Location mylocation = new Location("");
|
||||||
if (distance > exploreMapController.currentLocationSearchRadius * 3 / 4) {
|
Location dest_location = new Location("");
|
||||||
|
dest_location.setLatitude(exploreMapFragmentView.getMapFocus().getLatitude());
|
||||||
|
dest_location.setLongitude(exploreMapFragmentView.getMapFocus().getLongitude());
|
||||||
|
mylocation.setLatitude(exploreMapFragmentView.getLastMapFocus().getLatitude());
|
||||||
|
mylocation.setLongitude(exploreMapFragmentView.getLastMapFocus().getLongitude());
|
||||||
|
Float distance = mylocation.distanceTo(dest_location);
|
||||||
|
|
||||||
|
if (distance > 2000.0 * 3 / 4) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void markerUnselected() {
|
|
||||||
exploreMapFragmentView.hideBottomDetailsSheet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void markerSelected(Marker marker) {
|
|
||||||
exploreMapFragmentView.displayBottomSheetWithInfo(marker);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean areLocationsClose(LatLng cameraTarget, LatLng lastKnownLocation) {
|
|
||||||
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(cameraTarget)
|
|
||||||
.distanceTo(LocationUtils.commonsLatLngToMapBoxLatLng(lastKnownLocation));
|
|
||||||
if (distance > exploreMapController.currentLocationSearchRadius * 3 / 4) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/coordinator_layout"
|
android:id="@+id/coordinator_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
@ -13,11 +12,11 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_below="@id/container">
|
android:layout_below="@id/container">
|
||||||
|
|
||||||
<com.mapbox.mapboxsdk.maps.MapView
|
<org.osmdroid.views.MapView
|
||||||
android:id="@+id/map_view"
|
android:id="@+id/map_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" >
|
android:layout_height="match_parent"
|
||||||
</com.mapbox.mapboxsdk.maps.MapView>
|
android:visibility="visible" />
|
||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab_recenter"
|
android:id="@+id/fab_recenter"
|
||||||
|
|
@ -40,15 +39,15 @@
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
android:id="@+id/tv_attribution"
|
android:id="@+id/tv_attribution"
|
||||||
android:textStyle="bold"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="8dp"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_margin="8dp"
|
||||||
android:text="@string/map_attribution"
|
android:text="@string/map_attribution"
|
||||||
android:textAlignment="center"
|
android:textAlignment="center"
|
||||||
android:textSize="10sp" />
|
android:textSize="10sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
|
@ -65,8 +64,7 @@
|
||||||
android:text="@string/search_this_area"
|
android:text="@string/search_this_area"
|
||||||
android:textColor="@color/status_bar_blue"
|
android:textColor="@color/status_bar_blue"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
app:elevation="@dimen/dimen_6"
|
app:elevation="@dimen/dimen_6" />
|
||||||
/>
|
|
||||||
|
|
||||||
<include
|
<include
|
||||||
android:id="@+id/bottom_sheet_details"
|
android:id="@+id/bottom_sheet_details"
|
||||||
|
|
@ -77,7 +75,7 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
app:elevation="@dimen/dimen_6"
|
android:visibility="gone"
|
||||||
android:visibility="gone" />
|
app:elevation="@dimen/dimen_6" />
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue