Skip to content

Fix orientation issue on nearby after "search this area" is implemented #2085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ public void onCreate(Bundle savedInstanceState) {
onOrientationChanged = true; // Will be used in nearby fragment to determine significant update of map

//If nearby map was visible, call on Tab Selected to call all nearby operations
if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) {
/*if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) {
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
}
}*/
}
}

Expand Down Expand Up @@ -186,8 +186,7 @@ public void onPageSelected(int position) {
isContributionsFragmentVisible = false;
updateMenuItem();
// Do all permission and GPS related tasks on tab selected, not on create
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);

((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
break;
default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();
Expand Down
27 changes: 16 additions & 11 deletions app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment

private boolean onOrientationChanged = false;
private boolean populateForCurrentLocation = false;
private boolean isNetworkErrorOccured = false;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -126,7 +127,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
super.onViewCreated(view, savedInstanceState);
if (savedInstanceState != null) {
onOrientationChanged = true;
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
}
}

Expand Down Expand Up @@ -223,7 +223,7 @@ public void onLocationChangedSignificantly(LatLng latLng) {

@Override
public void onLocationChangedSlightly(LatLng latLng) {
refreshView(LOCATION_SLIGHTLY_CHANGED);
refreshView(LOCATION_SLIGHTLY_CHANGED);
}


Expand Down Expand Up @@ -331,7 +331,6 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
* @param customLatLng Custom area which we will search around
*/
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {

if (customLatLng == null) {
// If null, return
return;
Expand Down Expand Up @@ -428,8 +427,7 @@ private void lockNearbyView(boolean lock) {
}

private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {

if (nearbyMapFragment.searchThisAreaModeOn) {
if (nearbyMapFragment.checkingAround) {
return;
}
/*
Expand All @@ -447,11 +445,14 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
* If we are close to nearby places boundaries, we need a significant update to
* get new nearby places. Check order is south, north, west, east
* */
if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn
&& (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude()
|| curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude()
|| curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude()
|| curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
if (nearbyMapFragment.boundaryCoordinates != null
&& !nearbyMapFragment.checkingAround
&& !nearbyMapFragment.searchThisAreaModeOn
&& !onOrientationChanged
&& (curLatLng.getLatitude() < nearbyMapFragment.boundaryCoordinates[0].getLatitude()
|| curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude()
|| curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude()
|| curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
// populate places
placesDisposable = Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
Expand Down Expand Up @@ -682,9 +683,13 @@ private void addNetworkBroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
if (snackbar != null) {
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
if (isNetworkErrorOccured) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
isNetworkErrorOccured = false;
}
snackbar.dismiss();
} else {
isNetworkErrorOccured = true;
snackbar.show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class NearbyMapFragment extends DaggerFragment {

private boolean isMapReady;
public boolean searchThisAreaModeOn = false;
public boolean checkingAround = false;

private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
private boolean searchedAroundCurrentLocation = true;
Expand Down Expand Up @@ -556,6 +557,7 @@ public void onCameraMove() {
, NearbyController.currentLocation.getLongitude()));

if (distance > NearbyController.searchedRadius*1000*3/4) { //Convert to meter, and compare if our distance is bigger than 3/4 or our searched area
checkingAround = true;
if (!searchThisAreaModeOn) { // If we are changing mode, then change click action
searchThisAreaModeOn = true;
searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
Expand All @@ -575,6 +577,7 @@ public void onClick(View view) {
}

} else {
checkingAround = false;
if (searchThisAreaModeOn) {
searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not
searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -1002,6 +1005,13 @@ public void onResume() {
if (mapView != null) {
mapView.onResume();
}
if (mapboxMap != null) {
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
}
searchThisAreaModeOn = false;
checkingAround = false;
searchedAroundCurrentLocation = true;
boundaryCoordinates = null;
initViews();
setListeners();
transparentView.setClickable(false);
Expand Down