mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +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:
|
||||
Log.d("deneme1","case 1");
|
||||
NearbyParentFragment retainedNearbyFragment = getNearbyFragment(1);
|
||||
if (retainedNearbyFragment != null) {
|
||||
return retainedNearbyFragment;
|
||||
|
|
|
|||
|
|
@ -128,7 +128,6 @@ public class LocationServiceManager implements LocationListener {
|
|||
* Registers a LocationManager to listen for current location.
|
||||
*/
|
||||
public void registerLocationManager(Context context) {
|
||||
Log.d("deneme1","registerLocationManager2");
|
||||
if (!isLocationManagerRegistered) {
|
||||
isLocationManagerRegistered = requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
|
||||
&& requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER);
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import android.os.Bundle;
|
|||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -46,7 +47,8 @@ public interface NearbyMapContract {
|
|||
void closeFabs ( boolean isFabOpen);
|
||||
void updateMarker(boolean isBookmarked, Place place);
|
||||
LatLng getCameraTarget();
|
||||
void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||
void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||
void addOnCameraMoveListener(MapboxMap.OnCameraMoveListener onCameraMoveListener);
|
||||
}
|
||||
|
||||
interface UserActions extends NearbyElementContract.UserActions {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
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.LocationServiceManager;
|
||||
|
||||
|
|
@ -19,6 +21,10 @@ public interface NearbyParentFragmentContract {
|
|||
void listOptionMenuItemClicked();
|
||||
void populatePlaces(LatLng curlatLng, LatLng searchLatLng);
|
||||
boolean isBottomSheetExpanded();
|
||||
|
||||
void addSearchThisAreaButtonAction();
|
||||
void setSearchThisAreaButtonVisibility(boolean isVisible);
|
||||
void setSearchThisAreaProgressVisibility(boolean isVisible);
|
||||
}
|
||||
|
||||
interface UserActions {
|
||||
|
|
@ -33,9 +39,12 @@ public interface NearbyParentFragmentContract {
|
|||
void lockNearby(boolean isNearbyLocked);
|
||||
|
||||
void addMapMovementListeners();
|
||||
|
||||
MapboxMap.OnCameraMoveListener onCameraMove(LatLng cameraTarget);
|
||||
}
|
||||
|
||||
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.floatingactionbutton.FloatingActionButton;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.BaseMarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.annotations.PolygonOptions;
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.constants.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
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.NearbyParentFragmentContract;
|
||||
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;
|
||||
|
||||
public class NearbyMapFragment extends CommonsDaggerSupportFragment implements NearbyMapContract.View {
|
||||
|
|
@ -180,7 +174,7 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
}
|
||||
|
||||
this.mapboxMap = mapboxMap;
|
||||
viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||
viewsAreReadyCallback.nearbyFragmentAndMapViewReady2();
|
||||
//addMapMovementListeners();
|
||||
//updateMapSignificantlyForCurrentLocation();
|
||||
});
|
||||
|
|
@ -201,7 +195,6 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
|
||||
@Override
|
||||
public void updateMapMarkers(LatLng curLatLng, List<Place> placeList) {
|
||||
Log.d("deneme1","updateMapMarkers, curLatng:"+curLatLng);
|
||||
List<NearbyBaseMarker> customBaseMarkerOptions = NearbyController
|
||||
.loadAttractionsFromLocationToBaseMarkerOptions(curLatLng, // Curlatlang will be used to calculate distances
|
||||
placeList,
|
||||
|
|
@ -403,10 +396,11 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
* @param viewsAreReadyCallback
|
||||
*/
|
||||
@Override
|
||||
public void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||
public void viewsAreAssignedToPresenter(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback) {
|
||||
Timber.d("Views are set");
|
||||
this.viewsAreReadyCallback = viewsAreReadyCallback;
|
||||
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady();
|
||||
this.viewsAreReadyCallback.nearbyFragmentAndMapViewReady1();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -419,4 +413,9 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
|||
return LocationUtils
|
||||
.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);
|
||||
ButterKnife.bind(this, view);
|
||||
this.view = view;
|
||||
Timber.d("OnViewCreated");
|
||||
Timber.d("onCreateView");
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
addSearchThisAreaButtonAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
|
@ -142,15 +136,28 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
|||
Timber.d("Child fragment attached");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addSearchThisAreaButtonAction() {
|
||||
searchThisAreaButton.setOnClickListener(view -> {
|
||||
// Lock map operations during search this area operation
|
||||
nearbyParentFragmentPresenter.lockNearby(true);
|
||||
searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE);
|
||||
searchThisAreaButton.setOnClickListener(nearbyParentFragmentPresenter.onSearchThisAreaClicked());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSearchThisAreaButtonVisibility(boolean isVisible) {
|
||||
if (isVisible) {
|
||||
searchThisAreaButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -3,17 +3,16 @@ package fr.free.nrw.commons.nearby.mvp.presenter;
|
|||
import android.util.Log;
|
||||
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.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.utils.LocationUtils;
|
||||
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,6 +34,7 @@ public class NearbyParentFragmentPresenter
|
|||
|
||||
boolean nearbyViewsAreReady;
|
||||
boolean onTabSelected;
|
||||
boolean searchingThisArea;
|
||||
|
||||
private LocationServiceManager locationServiceManager;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ public class NearbyParentFragmentPresenter
|
|||
LocationServiceManager locationServiceManager) {
|
||||
this.nearbyParentFragmentView = nearbyParentFragmentView;
|
||||
this.nearbyMapFragmentView = nearbyMapFragmentView;
|
||||
this.nearbyMapFragmentView.viewsAreSet(this);
|
||||
this.nearbyMapFragmentView.viewsAreAssignedToPresenter(this);
|
||||
this.locationServiceManager = locationServiceManager;
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +74,7 @@ public class NearbyParentFragmentPresenter
|
|||
* Initializes nearby operations if tab selected, otherwise just sets nearby views are ready
|
||||
*/
|
||||
@Override
|
||||
public void nearbyFragmentAndMapViewReady() {
|
||||
public void nearbyFragmentAndMapViewReady1() {
|
||||
Timber.d("Nearby map view ready");
|
||||
nearbyViewsAreReady = true;
|
||||
// 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:
|
||||
* - 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.
|
||||
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
|
||||
|
|
@ -222,4 +235,55 @@ public class NearbyParentFragmentPresenter
|
|||
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