Skip to content

Commit f9494a2

Browse files
committed
Implement CommentRepliesFragment
1 parent 0dd4553 commit f9494a2

4 files changed

Lines changed: 95 additions & 3 deletions

File tree

app/src/main/java/org/schabi/newpipe/error/UserAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum UserAction {
1919
REQUESTED_PLAYLIST("requested playlist"),
2020
REQUESTED_KIOSK("requested kiosk"),
2121
REQUESTED_COMMENTS("requested comments"),
22+
REQUESTED_COMMENT_REPLIES("requested comment replies"),
2223
REQUESTED_FEED("requested feed"),
2324
REQUESTED_BOOKMARK("bookmark"),
2425
DELETE_FROM_HISTORY("delete from history"),
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.schabi.newpipe.fragments.list.comments;
2+
3+
import org.schabi.newpipe.extractor.ListInfo;
4+
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
5+
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
6+
7+
import java.util.Collections;
8+
9+
public final class CommentRepliesInfo extends ListInfo<CommentsInfoItem> {
10+
private CommentRepliesInfo(final int serviceId,
11+
final ListLinkHandler listUrlIdHandler,
12+
final String name) {
13+
super(serviceId, listUrlIdHandler, name);
14+
}
15+
16+
public static CommentRepliesInfo getInfo(final CommentsInfoItem comment) {
17+
final ListLinkHandler handler =
18+
new ListLinkHandler("", "", "", Collections.emptyList(), null);
19+
final CommentRepliesInfo relatedItemInfo = new CommentRepliesInfo(
20+
comment.getServiceId(), handler, comment.getName());
21+
relatedItemInfo.setNextPage(comment.getReplies());
22+
relatedItemInfo.setRelatedItems(Collections.emptyList()); // since it must be non-null
23+
return relatedItemInfo;
24+
}
25+
}

app/src/main/java/org/schabi/newpipe/info_list/holder/CommentInfoItemHolder.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
import androidx.appcompat.app.AppCompatActivity;
1919
import androidx.core.text.HtmlCompat;
2020

21+
import org.schabi.newpipe.MainActivity;
2122
import org.schabi.newpipe.R;
2223
import org.schabi.newpipe.error.ErrorUtil;
2324
import org.schabi.newpipe.extractor.InfoItem;
2425
import org.schabi.newpipe.extractor.NewPipe;
2526
import org.schabi.newpipe.extractor.ServiceList;
2627
import org.schabi.newpipe.extractor.StreamingService;
28+
import org.schabi.newpipe.extractor.comments.CommentsInfo;
2729
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
2830
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
2931
import org.schabi.newpipe.extractor.stream.Description;
32+
import org.schabi.newpipe.fragments.list.comments.CommentRepliesFragment;
3033
import org.schabi.newpipe.info_list.InfoItemBuilder;
3134
import org.schabi.newpipe.local.history.HistoryRecordManager;
3235
import org.schabi.newpipe.util.DeviceUtils;
@@ -145,7 +148,7 @@ public void updateFromItem(final InfoItem infoItem,
145148
itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE);
146149

147150
final boolean hasReplies = item.getReplies() != null;
148-
repliesButton.setOnClickListener(hasReplies ? (v) -> openRepliesFragment() : null);
151+
repliesButton.setOnClickListener(hasReplies ? (v) -> openRepliesFragment(item) : null);
149152
repliesButton.setVisibility(hasReplies ? View.VISIBLE : View.GONE);
150153
repliesButton.setText(hasReplies
151154
? Localization.replyCount(itemBuilder.getContext(), item.getReplyCount()) : "");
@@ -303,7 +306,16 @@ private void linkifyCommentContentView(@Nullable final Consumer<TextView> onComp
303306
}
304307
}
305308

306-
private void openRepliesFragment() {
307-
// TODO
309+
private void openRepliesFragment(final CommentsInfoItem commentsInfoItem) {
310+
((MainActivity) itemBuilder.getContext())
311+
.getSupportFragmentManager()
312+
.beginTransaction()
313+
.setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out,
314+
R.animator.custom_fade_in, R.animator.custom_fade_out)
315+
.replace(R.id.fragment_holder,
316+
new CommentRepliesFragment((CommentsInfo) itemBuilder.getSourceListInfo(),
317+
commentsInfoItem))
318+
.addToBackStack(null)
319+
.commit();
308320
}
309321
}

0 commit comments

Comments
 (0)