mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Call update map and add required markers
This commit is contained in:
parent
b10804910c
commit
786212fc49
7 changed files with 156 additions and 15 deletions
|
|
@ -41,21 +41,21 @@ public class NearbyController {
|
|||
* Prepares Place list to make their distance information update later.
|
||||
*
|
||||
* @param curLatLng current location for user
|
||||
* @param latLangToSearchAround the location user wants to search around
|
||||
* @param searchLatLng the location user wants to search around
|
||||
* @param returnClosestResult if this search is done to find closest result or all results
|
||||
* @return NearbyPlacesInfo a variable holds Place list without distance information
|
||||
* and boundary coordinates of current Place List
|
||||
*/
|
||||
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng latLangToSearchAround, boolean returnClosestResult, boolean checkingAroundCurrentLocation) throws IOException {
|
||||
public NearbyPlacesInfo loadAttractionsFromLocation(LatLng curLatLng, LatLng searchLatLng, boolean returnClosestResult, boolean checkingAroundCurrentLocation) throws IOException {
|
||||
|
||||
Timber.d("Loading attractions near %s", latLangToSearchAround);
|
||||
Timber.d("Loading attractions near %s", searchLatLng);
|
||||
NearbyPlacesInfo nearbyPlacesInfo = new NearbyPlacesInfo();
|
||||
|
||||
if (latLangToSearchAround == null) {
|
||||
if (searchLatLng == null) {
|
||||
Timber.d("Loading attractions nearby, but curLatLng is null");
|
||||
return null;
|
||||
}
|
||||
List<Place> places = nearbyPlaces.radiusExpander(latLangToSearchAround, Locale.getDefault().getLanguage(), returnClosestResult);
|
||||
List<Place> places = nearbyPlaces.radiusExpander(searchLatLng, Locale.getDefault().getLanguage(), returnClosestResult);
|
||||
|
||||
if (null != places && places.size() > 0) {
|
||||
LatLng[] boundaryCoordinates = {places.get(0).location, // south
|
||||
|
|
@ -91,6 +91,8 @@ public class NearbyController {
|
|||
}
|
||||
);
|
||||
}
|
||||
nearbyPlacesInfo.curLatLng = curLatLng;
|
||||
nearbyPlacesInfo.searchLatLng = searchLatLng;
|
||||
nearbyPlacesInfo.placeList = places;
|
||||
nearbyPlacesInfo.boundaryCoordinates = boundaryCoordinates;
|
||||
if (!returnClosestResult && checkingAroundCurrentLocation) {
|
||||
|
|
@ -212,5 +214,7 @@ public class NearbyController {
|
|||
public class NearbyPlacesInfo {
|
||||
public List<Place> placeList; // List of nearby places
|
||||
public LatLng[] boundaryCoordinates; // Corners of nearby area
|
||||
public LatLng curLatLng; // current location when this places are populated
|
||||
public LatLng searchLatLng; //search location for finding this places
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,13 @@ import android.net.Uri;
|
|||
import android.os.Bundle;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
|
||||
/**
|
||||
|
|
@ -20,14 +25,14 @@ public interface NearbyMapContract {
|
|||
void showSearchThisAreaButton();
|
||||
void showInformationBottomSheet();
|
||||
void initViews();
|
||||
void updateMapMarkers();
|
||||
void updateMapMarkers(LatLng latLng, List<Place> placeList);
|
||||
void updateMapToTrackPosition();
|
||||
void setListeners();
|
||||
MapView setupMapView(Bundle savedInstanceState);
|
||||
void addCurrentLocationMarker();
|
||||
void setSearchThisAreaButtonVisibility(boolean visible);
|
||||
boolean isCurrentLocationMarkerVisible();
|
||||
void addNearbyMarkersToMapBoxMap();
|
||||
void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions);
|
||||
void prepareViewsForSheetPosition();
|
||||
void hideFABs();
|
||||
void showFABs();
|
||||
|
|
@ -47,7 +52,7 @@ public interface NearbyMapContract {
|
|||
void searchThisArea();
|
||||
void storeSharedPrefs();
|
||||
void recenterMap();
|
||||
void updateMapMarkers();
|
||||
void updateMapMarkers(LatLng latLng);
|
||||
void updateMapToTrackPosition();
|
||||
void getBundleContent();
|
||||
boolean addMapMovementListener();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package fr.free.nrw.commons.nearby.mvp.contract;
|
||||
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
|
||||
public interface NearbyParentFragmentContract {
|
||||
|
|
@ -16,6 +17,7 @@ public interface NearbyParentFragmentContract {
|
|||
boolean isNetworkConnectionEstablished();
|
||||
void addNetworkBroadcastReceiver();
|
||||
void listOptionMenuItemClicked();
|
||||
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
|
||||
boolean isBottomSheetExpanded();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
|
@ -14,28 +15,54 @@ import android.view.animation.AnimationUtils;
|
|||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.plugins.localization.LocalizationPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerSupportFragment;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.NearbyBaseMarker;
|
||||
import fr.free.nrw.commons.nearby.NearbyController;
|
||||
import fr.free.nrw.commons.nearby.Place;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore applicationKvStore;
|
||||
|
||||
@Inject
|
||||
BookmarkLocationsDao bookmarkLocationDao;
|
||||
|
||||
@BindView(R.id.bottom_sheet)
|
||||
View bottomSheetList;
|
||||
|
||||
@BindView(R.id.bottom_sheet_details)
|
||||
View bottomSheetDetails;
|
||||
|
||||
MapView mapView;
|
||||
public MapView mapView;
|
||||
public MapboxMap mapboxMap;
|
||||
public NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback;
|
||||
|
||||
private BottomSheetBehavior bottomSheetListBehavior;
|
||||
|
|
@ -45,6 +72,11 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
private Animation fab_open;
|
||||
private Animation rotate_forward;
|
||||
|
||||
private static final double ZOOM_LEVEL = 14f;
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -113,6 +145,38 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
|
||||
@Override
|
||||
public MapView setupMapView(Bundle savedInstanceState) {
|
||||
Log.d("deneme1","setupMapView");
|
||||
Timber.d("setupMapView called");
|
||||
boolean isDarkTheme = applicationKvStore.getBoolean("theme", false);
|
||||
MapboxMapOptions options = new MapboxMapOptions()
|
||||
.compassGravity(Gravity.BOTTOM | Gravity.LEFT)
|
||||
.compassMargins(new int[]{12, 0, 0, 24})
|
||||
.styleUrl(isDarkTheme ? Style.DARK : Style.OUTDOORS)
|
||||
.logoEnabled(false)
|
||||
.attributionEnabled(false)
|
||||
.camera(new CameraPosition.Builder()
|
||||
.zoom(ZOOM_LEVEL)
|
||||
.build());
|
||||
|
||||
if (!getParentFragment().getActivity().isFinishing()) {
|
||||
MapView mapView = new MapView(getParentFragment().getActivity(), options);
|
||||
// create map
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
LocalizationPlugin localizationPlugin = new LocalizationPlugin(mapView, mapboxMap);
|
||||
|
||||
try {
|
||||
localizationPlugin.matchMapLanguageWithDeviceDefault();
|
||||
} catch (RuntimeException exception) {
|
||||
Timber.d(exception.toString());
|
||||
}
|
||||
|
||||
this.mapboxMap = mapboxMap;
|
||||
//addMapMovementListeners();
|
||||
//updateMapSignificantlyForCurrentLocation();
|
||||
});
|
||||
return mapView;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -127,12 +191,23 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateMapMarkers() {
|
||||
|
||||
public void updateMapMarkers(LatLng curLatLng, List<Place> placeList) {
|
||||
Log.d("deneme1","updateMapMarkers");
|
||||
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, // Curlatlang will be used to calculate distances
|
||||
placeList,
|
||||
getActivity(),
|
||||
bookmarkLocationDao.getAllBookmarksLocations());
|
||||
mapboxMap.clear();
|
||||
// We are trying to find nearby places around our custom searched area, thus custom parameter is nonnull
|
||||
addNearbyMarkersToMapBoxMap(customBaseMarkerOptions);
|
||||
// Re-enable mapbox gestures on custom location markers load
|
||||
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateMapToTrackPosition() {
|
||||
//addCurrentLocationMarker(mapboxMap);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +232,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
}
|
||||
|
||||
@Override
|
||||
public void addNearbyMarkersToMapBoxMap() {
|
||||
public void addNearbyMarkersToMapBoxMap(List<NearbyBaseMarker> baseMarkerOptions) {
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -221,10 +296,15 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Means that views are set in presenter
|
||||
* @param viewsAreReadyCallback
|
||||
*/
|
||||
@Override
|
||||
public void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||
Log.d("deneme1","viewsAreSet");
|
||||
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||
|
||||
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
|||
import fr.free.nrw.commons.utils.FragmentUtils;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||
|
|
@ -142,6 +145,30 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
wikidataEditListener.setAuthenticationStateListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populatePlaces(LatLng curlatLng, LatLng searchLatLng){
|
||||
compositeDisposable.add(Observable.fromCallable(() -> nearbyController
|
||||
.loadAttractionsFromLocation(curlatLng, searchLatLng, false, true))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::updateMapMarkers,
|
||||
throwable -> {
|
||||
Timber.d(throwable);
|
||||
//showErrorMessage(getString(R.string.error_fetching_nearby_places));
|
||||
progressBar.setVisibility(View.GONE);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates places for custom location, should be used for finding nearby places around a
|
||||
* location where you are not at.
|
||||
* @param nearbyPlacesInfo This variable has place list information and distances.
|
||||
*/
|
||||
private void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||
nearbyParentFragmentPresenter.updateMapMarkers(nearbyPlacesInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resume fragments if they exists
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package fr.free.nrw.commons.nearby.mvp.presenter;
|
||||
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||
|
||||
|
|
@ -26,6 +27,11 @@ public class NearbyMapPresenter implements NearbyMapContract.UserActions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void updateMapMarkers(LatLng latLng) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void updateMapMarkers() {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,19 @@
|
|||
package fr.free.nrw.commons.nearby.mvp.presenter;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.location.LatLng;
|
||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||
import fr.free.nrw.commons.nearby.NearbyController;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||
|
|
@ -35,7 +41,7 @@ public class NearbyParentFragmentPresenter
|
|||
LocationServiceManager locationServiceManager) {
|
||||
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
||||
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
||||
nearbyMapFragmentView.setViewsAreReady(this);
|
||||
nearbyMapFragmentView.viewsAreSet(this);
|
||||
this.locationServiceManager = locationServiceManager;
|
||||
}
|
||||
|
||||
|
|
@ -145,13 +151,24 @@ public class NearbyParentFragmentPresenter
|
|||
*/
|
||||
if (locationChangeType.equals(LOCATION_SIGNIFICANTLY_CHANGED)
|
||||
|| locationChangeType.equals(MAP_UPDATED)) {
|
||||
nearbyMapFragmentView.updateMapMarkers();
|
||||
nearbyMapFragmentView.updateMapToTrackPosition();
|
||||
nearbyParentFragmentView.populatePlaces(lastLocation, lastLocation);
|
||||
// TODO add a search location here
|
||||
|
||||
} else {
|
||||
nearbyMapFragmentView.updateMapToTrackPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates places for custom location, should be used for finding nearby places around a
|
||||
* location where you are not at.
|
||||
* @param nearbyPlacesInfo This variable has place list information and distances.
|
||||
*/
|
||||
public void updateMapMarkers(NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
|
||||
nearbyMapFragmentView.updateMapMarkers(nearbyPlacesInfo.curLatLng, nearbyPlacesInfo.placeList);
|
||||
nearbyMapFragmentView.updateMapToTrackPosition();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWikidataEditSuccessful() {
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue