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.
This commit is contained in:
Jason Whitmore 2024-09-25 19:25:54 -07:00
parent 16a1375800
commit 408f5a3b57

View file

@ -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(