mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-05 01:26:23 +00:00
Implement CommentRepliesFragment
This commit is contained in:
parent
0dd4553700
commit
f9494a294f
@ -19,6 +19,7 @@ public enum UserAction {
|
||||
REQUESTED_PLAYLIST("requested playlist"),
|
||||
REQUESTED_KIOSK("requested kiosk"),
|
||||
REQUESTED_COMMENTS("requested comments"),
|
||||
REQUESTED_COMMENT_REPLIES("requested comment replies"),
|
||||
REQUESTED_FEED("requested feed"),
|
||||
REQUESTED_BOOKMARK("bookmark"),
|
||||
DELETE_FROM_HISTORY("delete from history"),
|
||||
|
@ -0,0 +1,54 @@
|
||||
package org.schabi.newpipe.fragments.list.comments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.error.UserAction;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
|
||||
import org.schabi.newpipe.util.ExtractorHelper;
|
||||
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
|
||||
public final class CommentRepliesFragment
|
||||
extends BaseListInfoFragment<CommentsInfoItem, CommentRepliesInfo> {
|
||||
|
||||
// has the same content as super.currentInfo, except that it's never null
|
||||
private final CommentRepliesInfo currentInfo;
|
||||
// the original comments info loaded alongside stream
|
||||
private final CommentsInfo commentsInfo;
|
||||
|
||||
public CommentRepliesFragment(final CommentsInfo commentsInfo,
|
||||
final CommentsInfoItem commentsInfoItem) {
|
||||
super(UserAction.REQUESTED_COMMENT_REPLIES);
|
||||
this.currentInfo = CommentRepliesInfo.getInfo(commentsInfoItem);
|
||||
this.commentsInfo = commentsInfo;
|
||||
setInitialData(commentsInfo.getServiceId(), commentsInfo.getUrl(), commentsInfo.getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater,
|
||||
@Nullable final ViewGroup container,
|
||||
@Nullable final Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_comments, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Single<CommentRepliesInfo> loadResult(final boolean forceLoad) {
|
||||
return Single.just(this.currentInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Single<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLogic() {
|
||||
return ExtractorHelper.getMoreCommentItems(serviceId, commentsInfo, currentNextPage);
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.schabi.newpipe.fragments.list.comments;
|
||||
|
||||
import org.schabi.newpipe.extractor.ListInfo;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public final class CommentRepliesInfo extends ListInfo<CommentsInfoItem> {
|
||||
private CommentRepliesInfo(final int serviceId,
|
||||
final ListLinkHandler listUrlIdHandler,
|
||||
final String name) {
|
||||
super(serviceId, listUrlIdHandler, name);
|
||||
}
|
||||
|
||||
public static CommentRepliesInfo getInfo(final CommentsInfoItem comment) {
|
||||
final ListLinkHandler handler =
|
||||
new ListLinkHandler("", "", "", Collections.emptyList(), null);
|
||||
final CommentRepliesInfo relatedItemInfo = new CommentRepliesInfo(
|
||||
comment.getServiceId(), handler, comment.getName());
|
||||
relatedItemInfo.setNextPage(comment.getReplies());
|
||||
relatedItemInfo.setRelatedItems(Collections.emptyList()); // since it must be non-null
|
||||
return relatedItemInfo;
|
||||
}
|
||||
}
|
@ -18,15 +18,18 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
|
||||
import org.schabi.newpipe.MainActivity;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.error.ErrorUtil;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.ServiceList;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.stream.Description;
|
||||
import org.schabi.newpipe.fragments.list.comments.CommentRepliesFragment;
|
||||
import org.schabi.newpipe.info_list.InfoItemBuilder;
|
||||
import org.schabi.newpipe.local.history.HistoryRecordManager;
|
||||
import org.schabi.newpipe.util.DeviceUtils;
|
||||
@ -145,7 +148,7 @@ public class CommentInfoItemHolder extends InfoItemHolder {
|
||||
itemHeartView.setVisibility(item.isHeartedByUploader() ? View.VISIBLE : View.GONE);
|
||||
|
||||
final boolean hasReplies = item.getReplies() != null;
|
||||
repliesButton.setOnClickListener(hasReplies ? (v) -> openRepliesFragment() : null);
|
||||
repliesButton.setOnClickListener(hasReplies ? (v) -> openRepliesFragment(item) : null);
|
||||
repliesButton.setVisibility(hasReplies ? View.VISIBLE : View.GONE);
|
||||
repliesButton.setText(hasReplies
|
||||
? Localization.replyCount(itemBuilder.getContext(), item.getReplyCount()) : "");
|
||||
@ -303,7 +306,16 @@ public class CommentInfoItemHolder extends InfoItemHolder {
|
||||
}
|
||||
}
|
||||
|
||||
private void openRepliesFragment() {
|
||||
// TODO
|
||||
private void openRepliesFragment(final CommentsInfoItem commentsInfoItem) {
|
||||
((MainActivity) itemBuilder.getContext())
|
||||
.getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.setCustomAnimations(R.animator.custom_fade_in, R.animator.custom_fade_out,
|
||||
R.animator.custom_fade_in, R.animator.custom_fade_out)
|
||||
.replace(R.id.fragment_holder,
|
||||
new CommentRepliesFragment((CommentsInfo) itemBuilder.getSourceListInfo(),
|
||||
commentsInfoItem))
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user