From 9a50f54b4a080c68dcdbd13995e03589f446d7f6 Mon Sep 17 00:00:00 2001 From: neslihanturan Date: Tue, 28 May 2019 23:41:15 +0300 Subject: [PATCH] Search this area button action is added --- .../location/LocationServiceManager.java | 3 +- .../mvp/contract/NearbyMapContract.java | 1 + .../NearbyParentFragmentContract.java | 8 ++++- .../mvp/fragments/NearbyMapFragment.java | 6 ++++ .../mvp/fragments/NearbyParentFragment.java | 26 +++++++++++++++-- .../NearbyParentFragmentPresenter.java | 29 ++++++++++++++++--- 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java index 107df0b14..32de82578 100644 --- a/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java +++ b/app/src/main/java/fr/free/nrw/commons/location/LocationServiceManager.java @@ -303,6 +303,7 @@ public class LocationServiceManager implements LocationListener { LOCATION_MEDIUM_CHANGED, //Between slight and significant changes, will be used for nearby card view updates. LOCATION_NOT_CHANGED, PERMISSION_JUST_GRANTED, - MAP_UPDATED + MAP_UPDATED, + SEARCH_CUSTOM_AREA } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java index 9c6759955..1c9082d3b 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyMapContract.java @@ -45,6 +45,7 @@ public interface NearbyMapContract { void animateFABs(boolean isFabOpen); void closeFabs ( boolean isFabOpen); void updateMarker(boolean isBookmarked, Place place); + LatLng getCameraTarget(); void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback); } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java index a3dfe7621..611b5d8de 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/contract/NearbyParentFragmentContract.java @@ -23,10 +23,16 @@ public interface NearbyParentFragmentContract { interface UserActions { void displayListFragmentExpanded(); + void onTabSelected(); + void initializeNearbyOperations(); - void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType); + + void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget); + void lockNearby(boolean isNearbyLocked); + + void addMapMovementListeners(); } interface ViewsAreReadyCallback { diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java index 14d80fea5..b2d9de60e 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyMapFragment.java @@ -413,4 +413,10 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N public void showPlaces() { } + + @Override + public LatLng getCameraTarget() { + return LocationUtils + .mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target); + } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java index a14bf0201..829ed2130 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/fragments/NearbyParentFragment.java @@ -38,6 +38,7 @@ import fr.free.nrw.commons.nearby.NearbyController; import fr.free.nrw.commons.nearby.mvp.contract.NearbyParentFragmentContract; import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter; import fr.free.nrw.commons.utils.FragmentUtils; +import fr.free.nrw.commons.utils.LocationUtils; import fr.free.nrw.commons.utils.NetworkUtils; import fr.free.nrw.commons.wikidata.WikidataEditListener; import io.reactivex.Observable; @@ -46,6 +47,7 @@ import io.reactivex.schedulers.Schedulers; 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.SEARCH_CUSTOM_AREA; /** * This fragment is under MainActivity at the came level with ContributionFragment and holds @@ -69,6 +71,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment ConstraintLayout loadingNearbyLayout; @BindView(R.id.search_this_area_button) Button searchThisAreaButton; + @BindView(R.id.search_this_area_button_progress_bar) + ProgressBar searchThisAreaButtonProgressBar; @Inject NearbyController nearbyController; @@ -115,6 +119,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment return view; } + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + addSearchThisAreaButtonAction(); + } + @Override public void onResume() { super.onResume(); @@ -132,6 +142,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment Timber.d("Child fragment attached"); } + public void addSearchThisAreaButtonAction() { + searchThisAreaButton.setOnClickListener(view -> { + // Lock map operations during search this area operation + nearbyParentFragmentPresenter.lockNearby(true); + searchThisAreaButtonProgressBar.setVisibility(View.VISIBLE); + searchThisAreaButton.setVisibility(View.GONE); + nearbyParentFragmentPresenter.updateMapAndList(SEARCH_CUSTOM_AREA, + NearbyParentFragment.this.nearbyParentFragmentPresenter.getCameraTarget()); + }); + } @Override public void onAttach(Context context) { @@ -334,7 +354,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment Timber.d("Checking location permission"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (locationServiceManager.isLocationPermissionGranted(requireContext())) { - nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); + nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); } else { // Should we show an explanation? if (locationServiceManager.isPermissionExplanationRequired(getActivity())) { @@ -360,7 +380,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment } } } else { - nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); + nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); } } @@ -390,7 +410,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment if (getActivity() != null) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { if (isNetworkErrorOccurred) { - nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); + nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); isNetworkErrorOccurred = false; } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java index ea89a1e33..be0925b22 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/mvp/presenter/NearbyParentFragmentPresenter.java @@ -19,6 +19,7 @@ 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_SLIGHTLY_CHANGED; import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED; +import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.SEARCH_CUSTOM_AREA; public class NearbyParentFragmentPresenter implements NearbyParentFragmentContract.UserActions, @@ -121,13 +122,29 @@ public class NearbyParentFragmentPresenter } } + public LatLng getCameraTarget() { + return nearbyMapFragmentView.getCameraTarget(); + } + + /** + * Adds map movement listener to understand swiping with fingers. So that we can display search + * this area button to search nearby places for other locations + */ + @Override + public void addMapMovementListeners() { + + } + + /** * This method should be the single point to update Map and List. Triggered by location * changes * @param locationChangeType defines if location changed significantly or slightly + * @param cameraTarget will be used for search this area mode, when searching around + * user's camera target */ @Override - public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) { + public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget) { if (isNearbyLocked) { Timber.d("Nearby is locked, so updateMapAndList returns"); return; @@ -161,7 +178,11 @@ public class NearbyParentFragmentPresenter // TODO add a search location here // TODO dont forget map updated state after an wikidata item is updated - } else { // Means location changed slightly, ie user is walking or driving. + } else if (locationChangeType.equals(SEARCH_CUSTOM_AREA)) { + nearbyParentFragmentView.populatePlaces(lastLocation, cameraTarget); + } + + else { // Means location changed slightly, ie user is walking or driving. nearbyMapFragmentView.updateMapToTrackPosition(curLatLng); } @@ -186,14 +207,14 @@ public class NearbyParentFragmentPresenter @Override public void onLocationChangedSignificantly(LatLng latLng) { Timber.d("Location significantly changed"); - updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED); + updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null); } @Override public void onLocationChangedSlightly(LatLng latLng) { Timber.d("Location significantly changed"); - updateMapAndList(LOCATION_SLIGHTLY_CHANGED); + updateMapAndList(LOCATION_SLIGHTLY_CHANGED, null); } @Override