From 4c8875944f7152929c46eaa7567718f8e4660682 Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Thu, 26 Sep 2024 16:32:39 -0700 Subject: [PATCH] MediaDetailFragment.java: replace code that is meant to hide nearby card Before this commit, code would attempt to find and hide the nearby card that would appear when the user was looking at media details. However, this code did not work. After this commit, the old code has been replaced with code that correctly hides the nearby card. Also, this new code uses a helper method call and is overall easier to read. --- .../nrw/commons/media/MediaDetailFragment.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java index 292de2cdc..0e32754ec 100644 --- a/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java +++ b/app/src/main/java/fr/free/nrw/commons/media/MediaDetailFragment.java @@ -362,15 +362,13 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements @Override public void onResume() { super.onResume(); - if (getParentFragment() != null && getParentFragment().getParentFragment() != null) { - //Added a check because, not necessarily, the parent fragment will have a parent fragment, say - // in the case when MediaDetailPagerFragment is directly started by the CategoryImagesActivity - if (getParentFragment() instanceof ContributionsFragment) { - ((ContributionsFragment) (getParentFragment() - .getParentFragment())).binding.cardViewNearby - .setVisibility(View.GONE); - } + + //Hide the Nearby card when looking at media details + ContributionsFragment cf = this.getContributionsFragmentParent(); + if(cf != null && cf.binding != null){ + cf.binding.cardViewNearby.setVisibility(View.GONE); } + // detail provider is null when fragment is shown in review activity if (detailProvider != null) { media = detailProvider.getMediaAtPosition(index); @@ -448,7 +446,7 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements /** * Retrieves the ContributionsFragment that is potentially the parent, grandparent, etc * fragment of this fragment. - * + * * @return The ContributionsFragment instance. If the ContributionsFragment instance could not * be found, null is returned. */