From 408f5a3b57f2d0ee1accf00c9e65a2f9588a4390 Mon Sep 17 00:00:00 2001 From: Jason Whitmore Date: Wed, 25 Sep 2024 19:25:54 -0700 Subject: [PATCH] MediaDetailFragment.java: add helper method to retrieve ContributionFragment instance Before this commit, there was no easy way to check for and retrieve the ContributionFragment instance that was either the parent or grandparent (parent's parent) fragment. A complicated if check was required to retrieve it. After this commit, there is a simple helper method which will retrieve the ContributionFragment instance. Existing code can now be replaced by calling this method. --- .../commons/media/MediaDetailFragment.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 7336c1b40..292de2cdc 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 @@ -445,6 +445,27 @@ 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. + */ + private ContributionsFragment getContributionsFragmentParent(){ + Fragment f = this; + + while(f != null && !(f instanceof ContributionsFragment)){ + f = f.getParentFragment(); + } + + if(f != null){ + return (ContributionsFragment)f; + } else { + return null; + } + } + private void displayMediaDetails() { setTextFields(media); compositeDisposable.addAll(