mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Make sure everything is called in required order and seach this area method basically works
This commit is contained in:
parent
9a50f54b4a
commit
3f847fd890
7 changed files with 113 additions and 34 deletions
|
|
@ -408,7 +408,6 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
Log.d("deneme1","case 1");
|
|
||||||
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
|
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
|
||||||
if (retainedNearbyFragment != null) {
|
if (retainedNearbyFragment != null) {
|
||||||
return retainedNearbyFragment;
|
return retainedNearbyFragment;
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,6 @@ public class LocationServiceManager implements LocationListener {
|
||||||
* Registers a LocationManager to listen for current location.
|
* Registers a LocationManager to listen for current location.
|
||||||
*/
|
*/
|
||||||
public void registerLocationManager(Context context) {
|
public void registerLocationManager(Context context) {
|
||||||
Log.d("deneme1","registerLocationManager2");
|
|
||||||
if (!isLocationManagerRegistered) {
|
if (!isLocationManagerRegistered) {
|
||||||
isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
|
isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
|
||||||
&& requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);
|
&& requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||||
import com.mapbox.mapboxsdk.maps.MapView;
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -46,7 +47,8 @@ public interface NearbyMapContract {
|
||||||
void closeFabs ( boolean isFabOpen);
|
void closeFabs ( boolean isFabOpen);
|
||||||
void updateMarker(boolean isBookmarked, Place place);
|
void updateMarker(boolean isBookmarked, Place place);
|
||||||
LatLng getCameraTarget();
|
LatLng getCameraTarget();
|
||||||
void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||||
|
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserActions extends NearbyElementContract.UserActions {
|
interface UserActions extends NearbyElementContract.UserActions {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
package fr.free.nrw.commons.nearby.mvp.contract;
|
package fr.free.nrw.commons.nearby.mvp.contract;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
|
|
||||||
|
|
@ -19,6 +21,10 @@ public interface NearbyParentFragmentContract {
|
||||||
void listOptionMenuItemClicked();
|
void listOptionMenuItemClicked();
|
||||||
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
|
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
|
||||||
boolean isBottomSheetExpanded();
|
boolean isBottomSheetExpanded();
|
||||||
|
|
||||||
|
void addSearchThisAreaButtonAction();
|
||||||
|
void setSearchThisAreaButtonVisibility(boolean isVisible);
|
||||||
|
void setSearchThisAreaProgressVisibility(boolean isVisible);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface UserActions {
|
interface UserActions {
|
||||||
|
|
@ -33,9 +39,12 @@ public interface NearbyParentFragmentContract {
|
||||||
void lockNearby(boolean isNearbyLocked);
|
void lockNearby(boolean isNearbyLocked);
|
||||||
|
|
||||||
void addMapMovementListeners();
|
void addMapMovementListeners();
|
||||||
|
|
||||||
|
MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ViewsAreReadyCallback {
|
interface ViewsAreReadyCallback {
|
||||||
void nearbyFragmentAndMapViewReady();
|
void nearbyFragmentAndMapViewReady1();
|
||||||
|
void nearbyFragmentAndMapViewReady2();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,11 @@ import android.view.animation.AnimationUtils;
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.mapbox.mapboxsdk.Mapbox;
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
|
||||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
|
||||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
|
||||||
import com.mapbox.mapboxsdk.constants.Style;
|
import com.mapbox.mapboxsdk.constants.Style;
|
||||||
import com.mapbox.mapboxsdk.maps.MapView;
|
import com.mapbox.mapboxsdk.maps.MapView;
|
||||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
|
@ -52,9 +49,6 @@ import fr.free.nrw.commons.nearby.Place;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||||
import fr.free.nrw.commons.utils.LocationUtils;
|
import fr.free.nrw.commons.utils.LocationUtils;
|
||||||
import io.reactivex.Observable;
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
||||||
import io.reactivex.schedulers.Schedulers;
|
|
||||||
import timber.log.Timber;
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
||||||
|
|
@ -180,7 +174,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
}
|
}
|
||||||
|
|
||||||
this.mapboxMap = mapboxMap;
|
this.mapboxMap = mapboxMap;
|
||||||
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
viewsAreReadyCallback.nearbyFragmentAndMapViewReady2();
|
||||||
//addMapMovementListeners();
|
//addMapMovementListeners();
|
||||||
//updateMapSignificantlyForCurrentLocation();
|
//updateMapSignificantlyForCurrentLocation();
|
||||||
});
|
});
|
||||||
|
|
@ -201,7 +195,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateMapMarkers(LatLng curLatLng, List<Place> placeList) {
|
public void updateMapMarkers(LatLng curLatLng, List<Place> placeList) {
|
||||||
Log.d("deneme1","updateMapMarkers, curLatng:"+curLatLng);
|
|
||||||
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
||||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, // Curlatlang will be used to calculate distances
|
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, // Curlatlang will be used to calculate distances
|
||||||
placeList,
|
placeList,
|
||||||
|
|
@ -403,10 +396,11 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
* @param viewsAreReadyCallback
|
* @param viewsAreReadyCallback
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
public void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||||
Timber.d("Views are set");
|
Timber.d("Views are set");
|
||||||
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||||
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady1();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -419,4 +413,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
return LocationUtils
|
return LocationUtils
|
||||||
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target);
|
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener) {
|
||||||
|
mapboxMap.addOnCameraMoveListener(onCameraMoveListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,16 +115,10 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
|
||||||
ButterKnife.bind(this, view);
|
ButterKnife.bind(this, view);
|
||||||
this.view = view;
|
this.view = view;
|
||||||
Timber.d("OnViewCreated");
|
Timber.d("onCreateView");
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
||||||
super.onViewCreated(view, savedInstanceState);
|
|
||||||
addSearchThisAreaButtonAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
@ -142,15 +136,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
Timber.d("Child fragment attached");
|
Timber.d("Child fragment attached");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void addSearchThisAreaButtonAction() {
|
public void addSearchThisAreaButtonAction() {
|
||||||
searchThisAreaButton.setOnClickListener(view -> {
|
searchThisAreaButton.setOnClickListener(nearbyParentFragmentPresenter.onSearchThisAreaClicked());
|
||||||
// Lock map operations during search this area operation
|
}
|
||||||
nearbyParentFragmentPresenter.lockNearby(true);
|
|
||||||
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
|
@Override
|
||||||
|
public void setSearchThisAreaButtonVisibility(boolean isVisible) {
|
||||||
|
if (isVisible) {
|
||||||
|
searchThisAreaButton.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
searchThisAreaButton.setVisibility(View.GONE);
|
searchThisAreaButton.setVisibility(View.GONE);
|
||||||
nearbyParentFragmentPresenter.updateMapAndList(SEARCH_CUSTOM_AREA,
|
}
|
||||||
NearbyParentFragment.this.nearbyParentFragmentPresenter.getCameraTarget());
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public void setSearchThisAreaProgressVisibility(boolean isVisible) {
|
||||||
|
if (isVisible) {
|
||||||
|
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
} else {
|
||||||
|
searchThisAreaButtonProgressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -3,17 +3,16 @@ package fr.free.nrw.commons.nearby.mvp.presenter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import fr.free.nrw.commons.R;
|
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||||
|
|
||||||
import fr.free.nrw.commons.location.LatLng;
|
import fr.free.nrw.commons.location.LatLng;
|
||||||
import fr.free.nrw.commons.location.LocationServiceManager;
|
import fr.free.nrw.commons.location.LocationServiceManager;
|
||||||
import fr.free.nrw.commons.location.LocationUpdateListener;
|
import fr.free.nrw.commons.location.LocationUpdateListener;
|
||||||
import fr.free.nrw.commons.nearby.NearbyController;
|
import fr.free.nrw.commons.nearby.NearbyController;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyMapContract;
|
||||||
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract;
|
||||||
|
import fr.free.nrw.commons.utils.LocationUtils;
|
||||||
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
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 timber.log.Timber;
|
||||||
|
|
||||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED;
|
||||||
|
|
@ -35,6 +34,7 @@ public class NearbyParentFragmentPresenter
|
||||||
|
|
||||||
boolean nearbyViewsAreReady;
|
boolean nearbyViewsAreReady;
|
||||||
boolean onTabSelected;
|
boolean onTabSelected;
|
||||||
|
boolean searchingThisArea;
|
||||||
|
|
||||||
private LocationServiceManager locationServiceManager;
|
private LocationServiceManager locationServiceManager;
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ public class NearbyParentFragmentPresenter
|
||||||
LocationServiceManager locationServiceManager) {
|
LocationServiceManager locationServiceManager) {
|
||||||
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
||||||
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
||||||
this.nearbyMapFragmentView.viewsAreSet(this);
|
this.nearbyMapFragmentView.viewsAreAssignedToPresenter(this);
|
||||||
this.locationServiceManager = locationServiceManager;
|
this.locationServiceManager = locationServiceManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class NearbyParentFragmentPresenter
|
||||||
* Initializes nearby operations if tab selected, otherwise just sets nearby views are ready
|
* Initializes nearby operations if tab selected, otherwise just sets nearby views are ready
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void nearbyFragmentAndMapViewReady() {
|
public void nearbyFragmentAndMapViewReady1() {
|
||||||
Timber.d("Nearby map view ready");
|
Timber.d("Nearby map view ready");
|
||||||
nearbyViewsAreReady = true;
|
nearbyViewsAreReady = true;
|
||||||
// The condition for initialize operations is both having views ready and tab is selected
|
// The condition for initialize operations is both having views ready and tab is selected
|
||||||
|
|
@ -83,6 +83,18 @@ public class NearbyParentFragmentPresenter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nearbyFragmentAndMapViewReady2() {
|
||||||
|
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
|
||||||
|
//initializeNearbyOperations();
|
||||||
|
// TODO: document this prpoblem, if updateMapAndList is not called at checkGPS then this method never called, setup map view never ends
|
||||||
|
// TODO: add search this area thing here
|
||||||
|
this.nearbyParentFragmentView.addSearchThisAreaButtonAction();
|
||||||
|
this.nearbyMapFragmentView.addOnCameraMoveListener(onCameraMove(getCameraTarget()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes nearby operations by following these steps:
|
* Initializes nearby operations by following these steps:
|
||||||
* - Add this location listener to location manager
|
* - Add this location listener to location manager
|
||||||
|
|
@ -184,6 +196,7 @@ public class NearbyParentFragmentPresenter
|
||||||
|
|
||||||
else { // Means location changed slightly, ie user is walking or driving.
|
else { // Means location changed slightly, ie user is walking or driving.
|
||||||
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng);
|
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng);
|
||||||
|
searchingThisArea = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: update camera angle accordingly here, 1- search this area mode, 2- following current location, 3- list sheet expanded, 4- landcaped
|
// TODO: update camera angle accordingly here, 1- search this area mode, 2- following current location, 3- list sheet expanded, 4- landcaped
|
||||||
|
|
@ -222,4 +235,55 @@ public class NearbyParentFragmentPresenter
|
||||||
Timber.d("Location changed medium");
|
Timber.d("Location changed medium");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget) {
|
||||||
|
|
||||||
|
return new MapboxMap.OnCameraMoveListener() {
|
||||||
|
@Override
|
||||||
|
public void onCameraMove() {
|
||||||
|
// If our nearby markers are calculated at least once
|
||||||
|
if (NearbyController.currentLocation != null) {
|
||||||
|
if (nearbyParentFragmentView.isNetworkConnectionEstablished()) {
|
||||||
|
nearbyParentFragmentView.setSearchThisAreaButtonVisibility(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public View.OnClickListener onSearchThisAreaClicked() {
|
||||||
|
return new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// Lock map operations during search this area operation
|
||||||
|
lockNearby(true);
|
||||||
|
nearbyParentFragmentView.setSearchThisAreaProgressVisibility(true);
|
||||||
|
// TODO: make this invisible at somewhere
|
||||||
|
nearbyParentFragmentView.setSearchThisAreaButtonVisibility(false);
|
||||||
|
|
||||||
|
if (searchCloseToCurrentLocation()){
|
||||||
|
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED,
|
||||||
|
null);
|
||||||
|
} else {
|
||||||
|
updateMapAndList(SEARCH_CUSTOM_AREA,
|
||||||
|
getCameraTarget());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if search this area button is used around our current location, so that
|
||||||
|
* we can continue following our current location again
|
||||||
|
* @return Returns true if search this area button is used around our current location
|
||||||
|
*/
|
||||||
|
public boolean searchCloseToCurrentLocation() {
|
||||||
|
double distance = LocationUtils.commonsLatLngToMapBoxLatLng(getCameraTarget())
|
||||||
|
.distanceTo(new com.mapbox.mapboxsdk.geometry.LatLng(NearbyController.currentLocation.getLatitude()
|
||||||
|
, NearbyController.currentLocation.getLongitude()));
|
||||||
|
if (distance > NearbyController.searchedRadius * 1000 * 3 / 4) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue