|
| 1 | +package org.schabi.newpipe.fragments.list.comments; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.view.LayoutInflater; |
| 5 | +import android.view.View; |
| 6 | +import android.view.ViewGroup; |
| 7 | + |
| 8 | +import androidx.annotation.NonNull; |
| 9 | +import androidx.annotation.Nullable; |
| 10 | + |
| 11 | +import org.schabi.newpipe.R; |
| 12 | +import org.schabi.newpipe.error.UserAction; |
| 13 | +import org.schabi.newpipe.extractor.ListExtractor; |
| 14 | +import org.schabi.newpipe.extractor.comments.CommentsInfo; |
| 15 | +import org.schabi.newpipe.extractor.comments.CommentsInfoItem; |
| 16 | +import org.schabi.newpipe.fragments.list.BaseListInfoFragment; |
| 17 | +import org.schabi.newpipe.util.ExtractorHelper; |
| 18 | + |
| 19 | +import io.reactivex.rxjava3.core.Single; |
| 20 | + |
| 21 | +public final class CommentRepliesFragment |
| 22 | + extends BaseListInfoFragment<CommentsInfoItem, CommentRepliesInfo> { |
| 23 | + |
| 24 | + // has the same content as super.currentInfo, except that it's never null |
| 25 | + private final CommentRepliesInfo currentInfo; |
| 26 | + // the original comments info loaded alongside stream |
| 27 | + private final CommentsInfo commentsInfo; |
| 28 | + |
| 29 | + public CommentRepliesFragment(final CommentsInfo commentsInfo, |
| 30 | + final CommentsInfoItem commentsInfoItem) { |
| 31 | + super(UserAction.REQUESTED_COMMENT_REPLIES); |
| 32 | + this.currentInfo = CommentRepliesInfo.getInfo(commentsInfoItem); |
| 33 | + this.commentsInfo = commentsInfo; |
| 34 | + setInitialData(commentsInfo.getServiceId(), commentsInfo.getUrl(), commentsInfo.getName()); |
| 35 | + } |
| 36 | + |
| 37 | + @Nullable |
| 38 | + @Override |
| 39 | + public View onCreateView(@NonNull final LayoutInflater inflater, |
| 40 | + @Nullable final ViewGroup container, |
| 41 | + @Nullable final Bundle savedInstanceState) { |
| 42 | + return inflater.inflate(R.layout.fragment_comments, container, false); |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + protected Single<CommentRepliesInfo> loadResult(final boolean forceLoad) { |
| 47 | + return Single.just(this.currentInfo); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + protected Single<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLogic() { |
| 52 | + return ExtractorHelper.getMoreCommentItems(serviceId, commentsInfo, currentNextPage); |
| 53 | + } |
| 54 | +} |
0 commit comments