Skip to content

Commit b8ba89d

Browse files
Fixes commons-app#3923 (Back" does nothing in Nearby in particular circumstance) (commons-app#3961)
* Fixes commons-app#3923 * Handled possible missing backpress cases in MainActivity-nearby * Fixes commons-app#3923 * Handled possible missing backpress cases in MainActivity-nearby
1 parent 6e8e4f7 commit b8ba89d

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public void onBackPressed() {
242242
// Meas that contribution fragment is visible (not nearby fragment)
243243
ContributionsFragment contributionsFragment = (ContributionsFragment) getSupportFragmentManager().findFragmentByTag(contributionsFragmentTag);
244244

245-
if (contributionsFragment.getChildFragmentManager().findFragmentByTag(ContributionsFragment.MEDIA_DETAIL_PAGER_FRAGMENT_TAG) != null) {
245+
if (contributionsFragment.getChildFragmentManager().getBackStackEntryCount()>0 ) {
246246
// Means that media details fragment is visible to uer instead of contributions list fragment (As chils fragment)
247247
// Then we want to go back to contributions list fragment on backbutton pressed from media detail fragment
248248
contributionsFragment.getChildFragmentManager().popBackStack();
@@ -257,12 +257,13 @@ public void onBackPressed() {
257257
contributionsFragment.nearbyNotificationCardView.setVisibility(View.GONE);
258258
}
259259
} else {
260-
finish();
260+
super.onBackPressed();
261261
}
262-
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null && !isContributionsFragmentVisible) {
262+
} else if (getSupportFragmentManager().findFragmentByTag(nearbyFragmentTag) != null
263+
&& !isContributionsFragmentVisible) {
263264
// Means that nearby fragment is visible (not contributions fragment)
264-
if (null != nearbyParentFragment) {
265-
nearbyParentFragment.backButtonClicked();
265+
if (null == nearbyParentFragment || !nearbyParentFragment.backButtonClicked()) {
266+
super.onBackPressed();
266267
}
267268
} else {
268269
super.onBackPressed();

app/src/main/java/fr/free/nrw/commons/nearby/contract/NearbyParentFragmentContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ interface UserActions {
8989
void detachView();
9090

9191
void setActionListeners(JsonKvStore applicationKvStore);
92-
void backButtonClicked();
92+
boolean backButtonClicked();
9393
void onCameraMove(com.mapbox.mapboxsdk.geometry.LatLng latLng);
9494
void filterByMarkerType(List<Label> selectedLabels, int state, boolean filterForPlaceState, boolean filterForAllNoneType);
9595

app/src/main/java/fr/free/nrw/commons/nearby/fragments/NearbyParentFragment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,8 @@ public void onLocationChangedMedium(final fr.free.nrw.commons.location.LatLng la
980980
}
981981
}
982982

983-
public void backButtonClicked() {
984-
presenter.backButtonClicked();
983+
public boolean backButtonClicked() {
984+
return presenter.backButtonClicked();
985985
}
986986

987987
/**

app/src/main/java/fr/free/nrw/commons/nearby/presenter/NearbyParentFragmentPresenter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ public void setActionListeners(JsonKvStore applicationKvStore) {
111111
}
112112

113113
@Override
114-
public void backButtonClicked() {
114+
public boolean backButtonClicked() {
115115
if(nearbyParentFragmentView.isListBottomSheetExpanded()) {
116116
// Back should first hide the bottom sheet if it is expanded
117117
nearbyParentFragmentView.listOptionMenuItemClicked();
118+
return true;
118119
} else if (nearbyParentFragmentView.isDetailsBottomSheetVisible()) {
119120
nearbyParentFragmentView.setBottomSheetDetailsSmaller();
120-
} else {
121-
// Otherwise go back to contributions fragment
122-
nearbyParentFragmentView.setTabItemContributions();
121+
return true;
123122
}
123+
return false;
124124
}
125125

126126
public void markerUnselected() {

app/src/test/kotlin/fr/free/nrw/commons/nearby/NearbyParentFragmentPresenterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,8 @@ class NearbyParentFragmentPresenterTest {
374374
fun testBackButtonClickedWhenNoSheetVisible() {
375375
whenever(nearbyParentFragmentView.isListBottomSheetExpanded()).thenReturn(false)
376376
whenever(nearbyParentFragmentView.isDetailsBottomSheetVisible()).thenReturn(false)
377-
nearbyPresenter.backButtonClicked()
378-
verify(nearbyParentFragmentView).setTabItemContributions()
377+
val hasNearbyHandledBackPress = nearbyPresenter.backButtonClicked()
378+
assertFalse(hasNearbyHandledBackPress)
379379
}
380380

381381
@Test

0 commit comments

Comments
 (0)