diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index def1774b765..8e9388dc51b 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -54,6 +54,7 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.content.ContextCompat; +import androidx.fragment.app.Fragment; import androidx.preference.PreferenceManager; import com.google.android.exoplayer2.PlaybackException; @@ -73,6 +74,7 @@ import org.schabi.newpipe.error.UserAction; import org.schabi.newpipe.extractor.InfoItem; import org.schabi.newpipe.extractor.NewPipe; +import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException; import org.schabi.newpipe.extractor.exceptions.ExtractionException; import org.schabi.newpipe.extractor.stream.AudioStream; @@ -994,6 +996,14 @@ public void scrollToTop() { updateTabLayoutVisibility(); } + public void scrollToComment(final CommentsInfoItem comment) { + final Fragment fragment = pageAdapter.getItem( + pageAdapter.getItemPositionByTitle(COMMENTS_TAB_TAG)); + if (fragment instanceof CommentsFragment) { + ((CommentsFragment) fragment).scrollToComment(comment); + } + } + /*////////////////////////////////////////////////////////////////////////// // Play Utils //////////////////////////////////////////////////////////////////////////*/ diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java index 35e24ee9b5e..2dfd5c47cae 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesFragment.java @@ -158,4 +158,10 @@ protected ItemViewMode getItemViewMode() { return ItemViewMode.LIST; } + /** + * @return the comment to which the replies are shown + */ + public CommentsInfoItem getCommentsInfoItem() { + return commentsInfoItem; + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index 5a5f8496870..d3edede94e6 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -110,4 +110,8 @@ public void onCreateOptionsMenu(@NonNull final Menu menu, protected ItemViewMode getItemViewMode() { return ItemViewMode.LIST; } + + public void scrollToComment(CommentsInfoItem comment) { + itemsList.scrollToPosition(infoListAdapter.getItemsList().indexOf(comment)); + } }