Merge pull request #13213 from aivelon/handle-comment-replies-screens

Handling Comment Replies fragments
This commit is contained in:
Tobi 2026-02-18 23:43:39 -08:00 committed by GitHub
commit 51c9ed774c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 1 deletions

View File

@ -1009,7 +1009,11 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
Log.d(TAG, "handleSuggestions() called with: suggestions = [" + suggestions + "]");
}
suggestionListAdapter.submitList(suggestions,
() -> searchBinding.suggestionsList.scrollToPosition(0));
() -> {
if (searchBinding != null) {
searchBinding.suggestionsList.scrollToPosition(0);
}
});
if (suggestionsPanelVisible && isErrorPanelVisible()) {
hideLoading();

View File

@ -501,6 +501,7 @@ public final class NavigationHelper {
public static void openCommentRepliesFragment(@NonNull final FragmentActivity activity,
@NonNull final CommentsInfoItem comment) {
closeCommentRepliesFragments(activity);
defaultTransaction(activity.getSupportFragmentManager())
.replace(R.id.fragment_holder, new CommentRepliesFragment(comment),
CommentRepliesFragment.TAG)
@ -508,6 +509,41 @@ public final class NavigationHelper {
.commit();
}
/**
* Closes all open {@link CommentRepliesFragment}s in {@code activity},
* including those that are not at the top of the back stack.
* This is needed to prevent multiple open CommentRepliesFragments
* Ideally there should only be one since we remove existing before opening a new one.
* @param activity the activity in which to close the CommentRepliesFragments
*/
public static void closeCommentRepliesFragments(@NonNull final FragmentActivity activity) {
final FragmentManager fm = activity.getSupportFragmentManager();
// Remove all existing fragment instances tagged as CommentRepliesFragment
final FragmentTransaction tx = defaultTransaction(fm);
boolean removed = false;
for (final Fragment fragment : fm.getFragments()) {
if (fragment != null && CommentRepliesFragment.TAG.equals(fragment.getTag())) {
tx.remove(fragment);
removed = true;
}
}
if (removed) {
tx.commit();
}
// Only pop back stack entries named CommentRepliesFragment.TAG if they are at the top.
while (fm.getBackStackEntryCount() > 0
&& CommentRepliesFragment.TAG.equals(
fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName()
)
) {
fm.popBackStackImmediate(CommentRepliesFragment.TAG,
FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
}
public static void openPlaylistFragment(final FragmentManager fragmentManager,
final int serviceId, final String url,
@NonNull final String name) {