1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-25 04:22:30 +01:00

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.BackPressable;
import org.schabi.newpipe.fragments.MainFragment; import org.schabi.newpipe.fragments.MainFragment;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment; 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.fragments.list.search.SearchFragment;
import org.schabi.newpipe.local.feed.notifications.NotificationWorker; import org.schabi.newpipe.local.feed.notifications.NotificationWorker;
import org.schabi.newpipe.player.Player; 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 // interacts with a fragment inside fragment_holder so all back presses should be
// handled by it // handled by it
if (bottomSheetHiddenOrCollapsed()) { if (bottomSheetHiddenOrCollapsed()) {
final Fragment fragment = getSupportFragmentManager() final FragmentManager fm = getSupportFragmentManager();
.findFragmentById(R.id.fragment_holder); final Fragment fragment = fm.findFragmentById(R.id.fragment_holder);
// If current fragment implements BackPressable (i.e. can/wanna handle back press) // If current fragment implements BackPressable (i.e. can/wanna handle back press)
// delegate the back press to it // delegate the back press to it
if (fragment instanceof BackPressable) { if (fragment instanceof BackPressable) {
if (((BackPressable) fragment).onBackPressed()) { if (((BackPressable) fragment).onBackPressed()) {
return; 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 { } else {
@ -629,10 +642,23 @@ public class MainActivity extends AppCompatActivity {
* </pre> * </pre>
*/ */
private void onHomeButtonPressed() { private void onHomeButtonPressed() {
// If search fragment wasn't found in the backstack... final FragmentManager fm = getSupportFragmentManager();
if (!NavigationHelper.tryGotoSearchFragment(getSupportFragmentManager())) { final Fragment fragment = fm.findFragmentById(R.id.fragment_holder);
// ...go to the main fragment
NavigationHelper.gotoMainFragment(getSupportFragmentManager()); 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 public final class CommentRepliesFragment
extends BaseListInfoFragment<CommentsInfoItem, CommentRepliesInfo> { extends BaseListInfoFragment<CommentsInfoItem, CommentRepliesInfo> {
public static final String TAG = CommentRepliesFragment.class.getSimpleName();
private CommentsInfoItem commentsInfoItem; // the comment to show replies of private CommentsInfoItem commentsInfoItem; // the comment to show replies of
private final CompositeDisposable disposables = new CompositeDisposable(); private final CompositeDisposable disposables = new CompositeDisposable();
@ -156,4 +158,5 @@ public final class CommentRepliesFragment
protected ItemViewMode getItemViewMode() { protected ItemViewMode getItemViewMode() {
return ItemViewMode.LIST; return ItemViewMode.LIST;
} }
} }

View File

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