Search this area button action is added

This commit is contained in:
neslihanturan 2019-05-28 23:41:15 +03:00
parent 69597b34d5
commit 9a50f54b4a
6 changed files with 64 additions and 9 deletions

View file

@ -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
}
}

View file

@ -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);
}

View file

@ -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 {

View file

@ -413,4 +413,10 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
public void showPlaces() {
}
@Override
public LatLng getCameraTarget() {
return LocationUtils
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target);
}
}

View file

@ -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;
}

View file

@ -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