mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
MediaDetailFragment.kt: 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:
parent
038ae9acd4
commit
d0fa604319
1 changed files with 21 additions and 0 deletions
|
|
@ -467,6 +467,27 @@ class MediaDetailFragment : CommonsDaggerSupportFragment(), CategoryEditHelper.C
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 fun getContributionsFragmentParent(): ContributionsFragment? {
|
||||
var fragment: Fragment? = this
|
||||
|
||||
while (fragment != null && fragment !is ContributionsFragment) {
|
||||
fragment = fragment.parentFragment
|
||||
}
|
||||
|
||||
if (fragment == null) {
|
||||
return null
|
||||
}
|
||||
|
||||
return fragment as ContributionsFragment
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (parentFragment != null && requireParentFragment().parentFragment != null) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue