Skip to content

Commit b871b5d

Browse files
committed
Fix crashes due to wrong root fragment manager
1 parent e876647 commit b871b5d

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

app/src/main/java/org/schabi/newpipe/BaseFragment.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,20 @@ public void setTitle(final String title) {
120120
}
121121
}
122122

123+
/**
124+
* Finds the root fragment by looping through all of the parent fragments. The root fragment
125+
* is supposed to be {@link org.schabi.newpipe.fragments.MainFragment}, and is the fragment that
126+
* handles keeping the backstack of opened fragments in NewPipe, and also the player bottom
127+
* sheet. This function therefore returns the fragment manager of said fragment.
128+
*
129+
* @return the fragment manager of the root fragment, i.e.
130+
* {@link org.schabi.newpipe.fragments.MainFragment}
131+
*/
123132
protected FragmentManager getFM() {
124-
return getParentFragment() == null
125-
? getFragmentManager()
126-
: getParentFragment().getFragmentManager();
133+
Fragment current = this;
134+
while (current.getParentFragment() != null) {
135+
current = current.getParentFragment();
136+
}
137+
return current.getFragmentManager();
127138
}
128139
}

0 commit comments

Comments
 (0)