Skip to content

Commit 9d55c1e

Browse files
vanshikaaroradomdomegg
authored andcommitted
Fix commons-app#2245: Correct back button behaviour from nearby fragment (commons-app#2301)
1 parent a26b62f commit 9d55c1e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,16 @@ public void onBackPressed() {
269269
finish();
270270
}
271271
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
272-
// Meas that nearby fragment is visible (not contributions fragment)
273-
// Set current item to contributions activity instead of closing the activity
274-
viewPager.setCurrentItem(0);
272+
// Means that nearby fragment is visible (not contributions fragment)
273+
NearbyFragment nearbyFragment = (NearbyFragment) contributionsActivityPagerAdapter.getItem(1);
274+
275+
if(nearbyFragment.isBottomSheetExpanded()) {
276+
// Back should first hide the bottom sheet if it is expanded
277+
nearbyFragment.listOptionMenuItemClicked();
278+
} else {
279+
// Otherwise go back to contributions fragment
280+
viewPager.setCurrentItem(0);
281+
}
275282
} else {
276283
super.onBackPressed();
277284
}
@@ -347,7 +354,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
347354
return true;
348355
case R.id.list_sheet:
349356
if (contributionsActivityPagerAdapter.getItem(1) != null) {
350-
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuIteClicked();
357+
((NearbyFragment)contributionsActivityPagerAdapter.getItem(1)).listOptionMenuItemClicked();
351358
}
352359
return true;
353360
default:

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,13 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
132132
/**
133133
* Hide or expand bottom sheet according to states of all sheets
134134
*/
135-
public void listOptionMenuIteClicked() {
135+
public void listOptionMenuItemClicked() {
136136
if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_COLLAPSED || bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_HIDDEN){
137137
bottomSheetBehaviorForDetails.setState(BottomSheetBehavior.STATE_HIDDEN);
138138
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
139139
}else if(bottomSheetBehavior.getState()==BottomSheetBehavior.STATE_EXPANDED){
140140
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
141141
}
142-
143142
}
144143

145144
/**
@@ -822,6 +821,9 @@ public void onPause() {
822821
locationManager.unregisterLocationManager();
823822
}
824823
}
824+
825+
public boolean isBottomSheetExpanded() { return bottomSheetBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED;
826+
}
825827
}
826828

827829

0 commit comments

Comments
 (0)