Merge pull request #2085 from neslihanturan/fixOrientationIssueOnSearchNearby

Fix orientation issue on nearby after "search this area" is implemented
This commit is contained in:
Josephine Lim 2018-12-20 20:59:49 +10:00 committed by GitHub
commit 33995764ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 15 deletions

View file

@ -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 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 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); ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).onTabSelected(onOrientationChanged);
} }*/
} }
} }
@ -184,8 +184,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
isContributionsFragmentVisible = false; isContributionsFragmentVisible = false;
updateMenuItem(); updateMenuItem();
// Do all permission and GPS related tasks on tab selected, not on create // 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; break;
default: default:
tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select(); tabLayout.getTabAt(CONTRIBUTIONS_TAB_POSITION).select();

View file

@ -98,6 +98,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
private boolean onOrientationChanged = false; private boolean onOrientationChanged = false;
private boolean populateForCurrentLocation = false; private boolean populateForCurrentLocation = false;
private boolean isNetworkErrorOccured = false;
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
@ -124,7 +125,6 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
if (savedInstanceState != null) { if (savedInstanceState != null) {
onOrientationChanged = true; onOrientationChanged = true;
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
} }
} }
@ -225,7 +225,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
@Override @Override
public void onLocationChangedSlightly(LatLng latLng) { 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 * @param customLatLng Custom area which we will search around
*/ */
public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) { public void refreshViewForCustomLocation(LatLng customLatLng, boolean refreshForCurrentLocation) {
if (customLatLng == null) { if (customLatLng == null) {
// If null, return // If null, return
return; return;
@ -445,8 +444,7 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
* @param nearbyPlacesInfo Includes nearby places list and boundary coordinates * @param nearbyPlacesInfo Includes nearby places list and boundary coordinates
*/ */
private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) { private void updateMapFragment(boolean updateViaButton, boolean isSlightUpdate, @Nullable LatLng customLatLng, @Nullable NearbyController.NearbyPlacesInfo nearbyPlacesInfo) {
if (nearbyMapFragment.checkingAround) {
if (nearbyMapFragment.searchThisAreaModeOn) {
return; return;
} }
/* /*
@ -464,11 +462,14 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
* If we are close to nearby places boundaries, we need a significant update to * 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 * get new nearby places. Check order is south, north, west, east
* */ * */
if (nearbyMapFragment.boundaryCoordinates != null && !nearbyMapFragment.searchThisAreaModeOn if (nearbyMapFragment.boundaryCoordinates != null
&& (curLatLng.getLatitude() <= nearbyMapFragment.boundaryCoordinates[0].getLatitude() && !nearbyMapFragment.checkingAround
|| curLatLng.getLatitude() >= nearbyMapFragment.boundaryCoordinates[1].getLatitude() && !nearbyMapFragment.searchThisAreaModeOn
|| curLatLng.getLongitude() <= nearbyMapFragment.boundaryCoordinates[2].getLongitude() && !onOrientationChanged
|| curLatLng.getLongitude() >= nearbyMapFragment.boundaryCoordinates[3].getLongitude())) { && (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 // populate places
placesDisposable = Observable.fromCallable(() -> nearbyController placesDisposable = Observable.fromCallable(() -> nearbyController
.loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton)) .loadAttractionsFromLocation(curLatLng, curLatLng, false, updateViaButton))
@ -718,9 +719,13 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (snackbar != null && getActivity() != null) { if (snackbar != null && getActivity() != null) {
if (NetworkUtils.isInternetConnectionEstablished(getActivity())) { if (NetworkUtils.isInternetConnectionEstablished(getActivity())) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED); if (isNetworkErrorOccured) {
refreshView(LOCATION_SIGNIFICANTLY_CHANGED);
isNetworkErrorOccured = false;
}
snackbar.dismiss(); snackbar.dismiss();
} else { } else {
isNetworkErrorOccured = true;
snackbar.show(); snackbar.show();
} }
} }

View file

@ -130,6 +130,7 @@ public class NearbyMapFragment extends DaggerFragment {
private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04; private final double CAMERA_TARGET_SHIFT_FACTOR_LANDSCAPE = 0.04;
public boolean searchThisAreaModeOn = false; public boolean searchThisAreaModeOn = false;
public boolean checkingAround = false;
private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location private Bundle bundleForUpdtes;// Carry information from activity about changed nearby places and current location
private boolean searchedAroundCurrentLocation = true; private boolean searchedAroundCurrentLocation = true;
@ -570,6 +571,7 @@ public class NearbyMapFragment extends DaggerFragment {
, NearbyController.currentLocation.getLongitude())); , 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 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 if (!searchThisAreaModeOn) { // If we are changing mode, then change click action
searchThisAreaModeOn = true; searchThisAreaModeOn = true;
searchThisAreaButton.setOnClickListener(new View.OnClickListener() { searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
@ -589,6 +591,7 @@ public class NearbyMapFragment extends DaggerFragment {
} }
} else { } else {
checkingAround = false;
if (searchThisAreaModeOn) { if (searchThisAreaModeOn) {
searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not searchThisAreaModeOn = false; // This flag will help us to understand should we folor users location or not
searchThisAreaButton.setOnClickListener(new View.OnClickListener() { searchThisAreaButton.setOnClickListener(new View.OnClickListener() {
@ -1024,6 +1027,13 @@ public class NearbyMapFragment extends DaggerFragment {
if (mapView != null) { if (mapView != null) {
mapView.onResume(); mapView.onResume();
} }
if (mapboxMap != null) {
mapboxMap.getUiSettings().setAllGesturesEnabled(true);
}
searchThisAreaModeOn = false;
checkingAround = false;
searchedAroundCurrentLocation = true;
boundaryCoordinates = null;
initViews(); initViews();
setListeners(); setListeners();
transparentView.setClickable(false); transparentView.setClickable(false);