Skip to content

Commit

Permalink
Prepare to scroll last comment into view
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiGr committed Aug 31, 2023
1 parent 0a2ed6d commit d7ecc48
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
//////////////////////////////////////////////////////////////////////////*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,10 @@ protected ItemViewMode getItemViewMode() {
return ItemViewMode.LIST;
}

/**
* @return the comment to which the replies are shown
*/
public CommentsInfoItem getCommentsInfoItem() {
return commentsInfoItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit d7ecc48

Please sign in to comment.