mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 12:53:55 +01:00
Search this area button action is added
This commit is contained in:
parent
69597b34d5
commit
9a50f54b4a
6 changed files with 64 additions and 9 deletions
|
|
@ -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_MEDIUM_CHANGED, //Between slight and significant changes, will be used for nearby card view updates.
|
||||||
LOCATION_NOT_CHANGED,
|
LOCATION_NOT_CHANGED,
|
||||||
PERMISSION_JUST_GRANTED,
|
PERMISSION_JUST_GRANTED,
|
||||||
MAP_UPDATED
|
MAP_UPDATED,
|
||||||
|
SEARCH_CUSTOM_AREA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public interface NearbyMapContract {
|
||||||
void animateFABs(boolean isFabOpen);
|
void animateFABs(boolean isFabOpen);
|
||||||
void closeFabs ( boolean isFabOpen);
|
void closeFabs ( boolean isFabOpen);
|
||||||
void updateMarker(boolean isBookmarked, Place place);
|
void updateMarker(boolean isBookmarked, Place place);
|
||||||
|
LatLng getCameraTarget();
|
||||||
void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
void viewsAreSet(NearbyParentFragmentContract.ViewsAreReadyCallback viewsAreReadyCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,16 @@ public interface NearbyParentFragmentContract {
|
||||||
|
|
||||||
interface UserActions {
|
interface UserActions {
|
||||||
void displayListFragmentExpanded();
|
void displayListFragmentExpanded();
|
||||||
|
|
||||||
void onTabSelected();
|
void onTabSelected();
|
||||||
|
|
||||||
void initializeNearbyOperations();
|
void initializeNearbyOperations();
|
||||||
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType);
|
|
||||||
|
void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget);
|
||||||
|
|
||||||
void lockNearby(boolean isNearbyLocked);
|
void lockNearby(boolean isNearbyLocked);
|
||||||
|
|
||||||
|
void addMapMovementListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ViewsAreReadyCallback {
|
interface ViewsAreReadyCallback {
|
||||||
|
|
|
||||||
|
|
@ -413,4 +413,10 @@ public class NearbyMapFragment extends CommonsDaggerSupportFragment implements N
|
||||||
public void showPlaces() {
|
public void showPlaces() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LatLng getCameraTarget() {
|
||||||
|
return LocationUtils
|
||||||
|
.mapBoxLatLngToCommonsLatLng(mapboxMap.getCameraPosition().target);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.contract.NearbyParentFragmentContract;
|
||||||
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
import fr.free.nrw.commons.nearby.mvp.presenter.NearbyParentFragmentPresenter;
|
||||||
import fr.free.nrw.commons.utils.FragmentUtils;
|
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.utils.NetworkUtils;
|
||||||
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
import fr.free.nrw.commons.wikidata.WikidataEditListener;
|
||||||
import io.reactivex.Observable;
|
import io.reactivex.Observable;
|
||||||
|
|
@ -46,6 +47,7 @@ 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;
|
||||||
|
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
|
* This fragment is under MainActivity at the came level with ContributionFragment and holds
|
||||||
|
|
@ -69,6 +71,8 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
ConstraintLayout loadingNearbyLayout;
|
ConstraintLayout loadingNearbyLayout;
|
||||||
@BindView(R.id.search_this_area_button)
|
@BindView(R.id.search_this_area_button)
|
||||||
Button searchThisAreaButton;
|
Button searchThisAreaButton;
|
||||||
|
@BindView(R.id.search_this_area_button_progress_bar)
|
||||||
|
ProgressBar searchThisAreaButtonProgressBar;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
NearbyController nearbyController;
|
NearbyController nearbyController;
|
||||||
|
|
@ -115,6 +119,12 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
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();
|
||||||
|
|
@ -132,6 +142,16 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
Timber.d("Child fragment attached");
|
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
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
|
|
@ -334,7 +354,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
Timber.d("Checking location permission");
|
Timber.d("Checking location permission");
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
if (locationServiceManager.isLocationPermissionGranted(requireContext())) {
|
if (locationServiceManager.isLocationPermissionGranted(requireContext())) {
|
||||||
nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
|
nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
|
||||||
} else {
|
} else {
|
||||||
// Should we show an explanation?
|
// Should we show an explanation?
|
||||||
if (locationServiceManager.isPermissionExplanationRequired(getActivity())) {
|
if (locationServiceManager.isPermissionExplanationRequired(getActivity())) {
|
||||||
|
|
@ -360,7 +380,7 @@ public class NearbyParentFragment extends CommonsDaggerSupportFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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 (getActivity() != null) {
|
||||||
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
|
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
|
||||||
if (isNetworkErrorOccurred) {
|
if (isNetworkErrorOccurred) {
|
||||||
nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
|
nearbyParentFragmentPresenter.updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
|
||||||
isNetworkErrorOccurred = false;
|
isNetworkErrorOccurred = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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_SIGNIFICANTLY_CHANGED;
|
||||||
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_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.MAP_UPDATED;
|
||||||
|
import static fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.SEARCH_CUSTOM_AREA;
|
||||||
|
|
||||||
public class NearbyParentFragmentPresenter
|
public class NearbyParentFragmentPresenter
|
||||||
implements NearbyParentFragmentContract.UserActions,
|
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
|
* This method should be the single point to update Map and List. Triggered by location
|
||||||
* changes
|
* changes
|
||||||
* @param locationChangeType defines if location changed significantly or slightly
|
* @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
|
@Override
|
||||||
public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType) {
|
public void updateMapAndList(LocationServiceManager.LocationChangeType locationChangeType, LatLng cameraTarget) {
|
||||||
if (isNearbyLocked) {
|
if (isNearbyLocked) {
|
||||||
Timber.d("Nearby is locked, so updateMapAndList returns");
|
Timber.d("Nearby is locked, so updateMapAndList returns");
|
||||||
return;
|
return;
|
||||||
|
|
@ -161,7 +178,11 @@ public class NearbyParentFragmentPresenter
|
||||||
// TODO add a search location here
|
// TODO add a search location here
|
||||||
// TODO dont forget map updated state after an wikidata item is updated
|
// 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);
|
nearbyMapFragmentView.updateMapToTrackPosition(curLatLng);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -186,14 +207,14 @@ public class NearbyParentFragmentPresenter
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSignificantly(LatLng latLng) {
|
public void onLocationChangedSignificantly(LatLng latLng) {
|
||||||
Timber.d("Location significantly changed");
|
Timber.d("Location significantly changed");
|
||||||
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED);
|
updateMapAndList(LOCATION_SIGNIFICANTLY_CHANGED, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChangedSlightly(LatLng latLng) {
|
public void onLocationChangedSlightly(LatLng latLng) {
|
||||||
Timber.d("Location significantly changed");
|
Timber.d("Location significantly changed");
|
||||||
updateMapAndList(LOCATION_SLIGHTLY_CHANGED);
|
updateMapAndList(LOCATION_SLIGHTLY_CHANGED, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue