Fix #2245: Correct back button behaviour from nearby fragment (#2301)

This commit is contained in:
Vanshika Arora 2019-03-16 21:57:25 +05:30 committed by Adam Jones
parent a26b62f51b
commit 9d55c1e8d7
2 changed files with 15 additions and 6 deletions

View file

@ -269,9 +269,16 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
finish(); finish();
} }
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) { } else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
// Meas that nearby fragment is visible (not contributions fragment) // Means that nearby fragment is visible (not contributions fragment)
// Set current item to contributions activity instead of closing the activity NearbyFragment nearbyFragment = (NearbyFragment) contributionsActivityPagerAdapter.getItem(1);
if(nearbyFragment.isBottomSheetExpanded()) {
// Back should first hide the bottom sheet if it is expanded
nearbyFragment.listOptionMenuItemClicked();
} else {
// Otherwise go back to contributions fragment
viewPager.setCurrentItem(0); viewPager.setCurrentItem(0);
}
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
@ -347,7 +354,7 @@ public class MainActivity extends AuthenticatedActivity implements FragmentManag
return true; return true;
case R.id.list_sheet: case R.id.list_sheet:
if (contributionsActivityPagerAdapter.getItem(1) != null) { if (contributionsActivityPagerAdapter.getItem(1) != null) {
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuIteClicked(); ((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
} }
return true; return true;
default: default:

View file

@ -132,14 +132,13 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
/** /**
* Hide or expand bottom sheet according to states of all sheets * Hide or expand bottom sheet according to states of all sheets
*/ */
public void listOptionMenuIteClicked() { public void listOptionMenuItemClicked() {
if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_COLLAPSED || bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_HIDDEN){ if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_COLLAPSED || bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_HIDDEN){
bottomSheetBehaviorForDetails.setState(BottomSheetBehavior.STATE_HIDDEN); bottomSheetBehaviorForDetails.setState(BottomSheetBehavior.STATE_HIDDEN);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}else if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED){ }else if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED){
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
} }
} }
/** /**
@ -822,6 +821,9 @@ public class NearbyFragment extends CommonsDaggerSupportFragment
locationManager.unregisterLocationManager(); locationManager.unregisterLocationManager();
} }
} }
public boolean isBottomSheetExpanded() { return bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
}
} }