Expand DetailFragment again when exiting the CommentRepliesFragment

This commit is contained in:
TobiGr 2023-08-29 20:51:47 +02:00 committed by Stypox
parent 8c9287d0c8
commit 5f32d001cc
No known key found for this signature in database
GPG key ID: 4BDF1B40A49FDD23
3 changed files with 36 additions and 7 deletions

View file

@ -69,6 +69,7 @@ import org.schabi.newpipe.extractor.services.peertube.PeertubeInstance;
import org.schabi.newpipe.fragments.BackPressable;
import org.schabi.newpipe.fragments.MainFragment;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.comments.CommentRepliesFragment;
import org.schabi.newpipe.fragments.list.search.SearchFragment;
import org.schabi.newpipe.local.feed.notifications.NotificationWorker;
import org.schabi.newpipe.player.Player;
@ -546,14 +547,26 @@ public class MainActivity extends AppCompatActivity {
// interacts with a fragment inside fragment_holder so all back presses should be
// handled by it
if (bottomSheetHiddenOrCollapsed()) {
final Fragment fragment = getSupportFragmentManager()
.findFragmentById(R.id.fragment_holder);
final FragmentManager fm = getSupportFragmentManager();
final Fragment fragment = fm.findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press)
// delegate the back press to it
if (fragment instanceof BackPressable) {
if (((BackPressable) fragment).onBackPressed()) {
return;
}
} else if (fragment instanceof CommentRepliesFragment) {
// expand DetailsFragment if CommentRepliesFragment was opened
// to show the top level comments again
// Expand DetailsFragment if CommentRepliesFragment was opened
// and no other CommentRepliesFragments are on top of the back stack
// to show the top level comments again.
final FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(
fm.getBackStackEntryCount() - 2); // current fragment is at the top
if (!CommentRepliesFragment.TAG.equals(bse.getName())) {
BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder)
.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
} else {
@ -629,10 +642,23 @@ public class MainActivity extends AppCompatActivity {
* </pre>
*/
private void onHomeButtonPressed() {
// If search fragment wasn't found in the backstack...
if (!NavigationHelper.tryGotoSearchFragment(getSupportFragmentManager())) {
// ...go to the main fragment
NavigationHelper.gotoMainFragment(getSupportFragmentManager());
final FragmentManager fm = getSupportFragmentManager();
final Fragment fragment = fm.findFragmentById(R.id.fragment_holder);
if (fragment instanceof CommentRepliesFragment) {
// Expand DetailsFragment if CommentRepliesFragment was opened
// and no other CommentRepliesFragments are on top of the back stack
// to show the top level comments again.
fm.popBackStackImmediate();
final FragmentManager.BackStackEntry bse = fm.getBackStackEntryAt(
fm.getBackStackEntryCount() - 1);
if (!CommentRepliesFragment.TAG.equals(bse.getName())) {
BottomSheetBehavior.from(mainBinding.fragmentPlayerHolder)
.setState(BottomSheetBehavior.STATE_EXPANDED);
}
} else if (!NavigationHelper.tryGotoSearchFragment(fm)) {
// If search fragment wasn't found in the backstack go to the main fragment
NavigationHelper.gotoMainFragment(fm);
}
}

View file

@ -36,6 +36,8 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable;
public final class CommentRepliesFragment
extends BaseListInfoFragment<CommentsInfoItem, CommentRepliesInfo> {
public static final String TAG = CommentRepliesFragment.class.getSimpleName();
private CommentsInfoItem commentsInfoItem; // the comment to show replies of
private final CompositeDisposable disposables = new CompositeDisposable();
@ -156,4 +158,5 @@ public final class CommentRepliesFragment
protected ItemViewMode getItemViewMode() {
return ItemViewMode.LIST;
}
}

View file

@ -505,7 +505,7 @@ public final class NavigationHelper {
final CommentsInfoItem commentsInfoItem) {
defaultTransaction(activity.getSupportFragmentManager())
.replace(R.id.fragment_holder, new CommentRepliesFragment(commentsInfoItem))
.addToBackStack(null)
.addToBackStack(CommentRepliesFragment.TAG)
.commit();
}