From b871b5d2dde0bfa87a0e8e970ebbe1602bb0fe3f Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 10 Dec 2023 16:06:07 +0100 Subject: [PATCH] Fix crashes due to wrong root fragment manager --- .../java/org/schabi/newpipe/BaseFragment.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 5dde2a747..7a06771dd 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -120,9 +120,20 @@ public abstract class BaseFragment extends Fragment { } } + /** + * Finds the root fragment by looping through all of the parent fragments. The root fragment + * is supposed to be {@link org.schabi.newpipe.fragments.MainFragment}, and is the fragment that + * handles keeping the backstack of opened fragments in NewPipe, and also the player bottom + * sheet. This function therefore returns the fragment manager of said fragment. + * + * @return the fragment manager of the root fragment, i.e. + * {@link org.schabi.newpipe.fragments.MainFragment} + */ protected FragmentManager getFM() { - return getParentFragment() == null - ? getFragmentManager() - : getParentFragment().getFragmentManager(); + Fragment current = this; + while (current.getParentFragment() != null) { + current = current.getParentFragment(); + } + return current.getFragmentManager(); } }