Skip to content

Commit 3399576

Browse files
authored
Merge pull request #2085 from neslihanturan/fixOrientationIssueOnSearchNearby
Fix orientation issue on nearby after "search this area" is implemented
2 parents 24a76b1 + 520c303 commit 3399576

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

app/src/main/java/fr/free/nrw/commons/contributions/MainActivity.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ public void onCreate(Bundle savedInstanceState) {
8484
onOrientationChanged = true; // Will be used in nearby fragment to determine significant update of map
8585

8686
//If nearby map was visible, call on Tab Selected to call all nearby operations
87-
if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) {
87+
/*if (savedInstanceState.getInt("viewPagerCurrentItem") == 1) {
8888
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
89-
}
89+
}*/
9090
}
9191
}
9292

@@ -184,8 +184,7 @@ public void onPageSelected(int position) {
184184
isContributionsFragmentVisible = false;
185185
updateMenuItem();
186186
// Do all permission and GPS related tasks on tab selected, not on create
187-
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
188-
187+
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
189188
break;
190189
default:
191190
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();

app/src/main/java/fr/free/nrw/commons/nearby/NearbyFragment.java

+16-11
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
9898

9999
private boolean onOrientationChanged = false;
100100
private boolean populateForCurrentLocation = false;
101+
private boolean isNetworkErrorOccured = false;
101102

102103
@Override
103104
public void onCreate(@Nullable Bundle savedInstanceState) {
@@ -124,7 +125,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
124125
super.onViewCreated(view, savedInstanceState);
125126
if (savedInstanceState != null) {
126127
onOrientationChanged = true;
127-
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
128128
}
129129
}
130130

@@ -225,7 +225,7 @@ public void onLocationChangedSignificantly(LatLng latLng) {
225225

226226
@Override
227227
public void onLocationChangedSlightly(LatLng latLng) {
228-
refreshView(LOCATION_SLIGHTLY_CHANGED);
228+
refreshView(LOCATION_SLIGHTLY_CHANGED);
229229
}
230230

231231

@@ -333,7 +333,6 @@ public void refreshView(LocationServiceManager.LocationChangeType locationChange
333333
* @param customLatLng Custom area which we will search around
334334
*/
335335
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {
336-
337336
if (customLatLng == null) {
338337
// If null, return
339338
return;
@@ -445,8 +444,7 @@ private void lockNearbyView(boolean lock) {
445444
* @param nearbyPlacesInfo Includes nearby places list and boundary coordinates
446445
*/
447446
private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
448-
449-
if (nearbyMapFragment.searchThisAreaModeOn) {
447+
if (nearbyMapFragment.checkingAround) {
450448
return;
451449
}
452450
/*
@@ -464,11 +462,14 @@ private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate,
464462
* If we are close to nearby places boundaries, we need a significant update to
465463
* get new nearby places. Check order is south, north, west, east
466464
* */
467-
if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn
468-
&& (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude()
469-
|| curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude()
470-
|| curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude()
471-
|| curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
465+
if (nearbyMapFragment.boundaryCoordinates != null
466+
&& !nearbyMapFragment.checkingAround
467+
&& !nearbyMapFragment.searchThisAreaModeOn
468+
&& !onOrientationChanged
469+
&& (curLatLng.getLatitude() < nearbyMapFragment.boundaryCoordinates[0].getLatitude()
470+
|| curLatLng.getLatitude() > nearbyMapFragment.boundaryCoordinates[1].getLatitude()
471+
|| curLatLng.getLongitude() < nearbyMapFragment.boundaryCoordinates[2].getLongitude()
472+
|| curLatLng.getLongitude() > nearbyMapFragment.boundaryCoordinates[3].getLongitude())) {
472473
// populate places
473474
placesDisposable = Observable.fromCallable(() -> nearbyController
474475
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
@@ -718,9 +719,13 @@ private void addNetworkBroadcastReceiver() {
718719
public void onReceive(Context context, Intent intent) {
719720
if (snackbar != null && getActivity() != null) {
720721
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
721-
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
722+
if (isNetworkErrorOccured) {
723+
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
724+
isNetworkErrorOccured = false;
725+
}
722726
snackbar.dismiss();
723727
} else {
728+
isNetworkErrorOccured = true;
724729
snackbar.show();
725730
}
726731
}

app/src/main/java/fr/free/nrw/commons/nearby/NearbyMapFragment.java

+10
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public class NearbyMapFragment extends DaggerFragment {
130130
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
131131

132132
public boolean searchThisAreaModeOn = false;
133+
public boolean checkingAround = false;
133134

134135
private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
135136
private boolean searchedAroundCurrentLocation = true;
@@ -570,6 +571,7 @@ public void onCameraMove() {
570571
, NearbyController.currentLocation.getLongitude()));
571572

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

591593
} else {
594+
checkingAround = false;
592595
if (searchThisAreaModeOn) {
593596
searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not
594597
searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
@@ -1024,6 +1027,13 @@ public void onResume() {
10241027
if (mapView != null) {
10251028
mapView.onResume();
10261029
}
1030+
if (mapboxMap != null) {
1031+
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
1032+
}
1033+
searchThisAreaModeOn = false;
1034+
checkingAround = false;
1035+
searchedAroundCurrentLocation = true;
1036+
boundaryCoordinates = null;
10271037
initViews();
10281038
setListeners();
10291039
transparentView.setClickable(false);

0 commit comments

Comments
 (0)