diff --git a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java index 24f47e3f0..e7184511e 100644 --- a/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java +++ b/app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java @@ -84,9 +84,9 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag 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); - } + }*/ } } @@ -184,8 +184,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag 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(); diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java index c1960f82d..6ab556d79 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java @@ -98,6 +98,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) { @@ -124,7 +125,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment super.onViewCreated(view, savedInstanceState); if (savedInstanceState != null) { onOrientationChanged = true; - refreshView(LOCATION_SIGNIFICANTLY_CHANGED); } } @@ -225,7 +225,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment @Override public void onLocationChangedSlightly(LatLng latLng) { - refreshView(LOCATION_SLIGHTLY_CHANGED); + refreshView(LOCATION_SLIGHTLY_CHANGED); } @@ -333,7 +333,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment * @param customLatLng Custom area which we will search around */ public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) { - if (customLatLng == null) { // If null, return return; @@ -445,8 +444,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment * @param nearbyPlacesInfo Includes nearby places list and boundary coordinates */ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { - - if (nearbyMapFragment.searchThisAreaModeOn) { + if (nearbyMapFragment.checkingAround) { return; } /* @@ -464,11 +462,14 @@ public class NearbyFragment extends CommonsDaggerSupportFragment * 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)) @@ -718,9 +719,13 @@ public class NearbyFragment extends CommonsDaggerSupportFragment public void onReceive(Context context, Intent intent) { if (snackbar != null && getActivity() != null) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { - refreshView(LOCATION_SIGNIFICANTLY_CHANGED); + if (isNetworkErrorOccured) { + refreshView(LOCATION_SIGNIFICANTLY_CHANGED); + isNetworkErrorOccured = false; + } snackbar.dismiss(); } else { + isNetworkErrorOccured = true; snackbar.show(); } } diff --git a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java index 4b3dfb17e..3549ea1af 100644 --- a/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java @@ -130,6 +130,7 @@ public class NearbyMapFragment extends DaggerFragment { private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04; 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; @@ -570,6 +571,7 @@ public class NearbyMapFragment extends DaggerFragment { , 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() { @@ -589,6 +591,7 @@ public class NearbyMapFragment extends DaggerFragment { } } 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() { @@ -1024,6 +1027,13 @@ public class NearbyMapFragment extends DaggerFragment { 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);