From 4b6392df5420f16e5e0234ce88cdf0e28ddd6ce3 Mon Sep 17 00:00:00 2001 From: Stypox Date: Wed, 12 Apr 2023 08:54:58 +0200 Subject: [PATCH] Set comment replies fragment title --- .../list/comments/CommentRepliesFragment.java | 21 ++++++++++--------- .../list/comments/CommentRepliesInfo.java | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) 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 4b85dfa68..783fd18ba 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 @@ -2,8 +2,6 @@ package org.schabi.newpipe.fragments.list.comments; import android.os.Bundle; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; @@ -18,6 +16,7 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.info_list.ItemViewMode; import org.schabi.newpipe.util.ExtractorHelper; +import org.schabi.newpipe.util.Localization; import java.util.Queue; @@ -26,10 +25,10 @@ import io.reactivex.rxjava3.core.Single; public final class CommentRepliesFragment extends BaseListInfoFragment { - // has the same content as super.currentInfo, except that it's never null - private CommentRepliesInfo commentRepliesInfo; - // the original comments info loaded alongside stream + // the original comments info loaded alongside the stream private CommentsInfo commentsInfo; + // the comment to show replies of + private CommentsInfoItem commentsInfoItem; /*////////////////////////////////////////////////////////////////////////// @@ -43,8 +42,8 @@ public final class CommentRepliesFragment public CommentRepliesFragment(final CommentsInfo commentsInfo, final CommentsInfoItem commentsInfoItem) { this(); - this.commentRepliesInfo = CommentRepliesInfo.getInfo(commentsInfoItem); this.commentsInfo = commentsInfo; + this.commentsInfoItem = commentsInfoItem; setInitialData(commentsInfo.getServiceId(), commentsInfo.getUrl(), commentsInfo.getName()); } @@ -58,21 +57,21 @@ public final class CommentRepliesFragment /*////////////////////////////////////////////////////////////////////////// - // State Saving + // State saving //////////////////////////////////////////////////////////////////////////*/ @Override public void writeTo(final Queue objectsToSave) { super.writeTo(objectsToSave); - objectsToSave.add(commentRepliesInfo); objectsToSave.add(commentsInfo); + objectsToSave.add(commentsInfoItem); } @Override public void readFrom(@NonNull final Queue savedObjects) throws Exception { super.readFrom(savedObjects); - commentRepliesInfo = (CommentRepliesInfo) savedObjects.poll(); commentsInfo = (CommentsInfo) savedObjects.poll(); + commentsInfoItem = (CommentsInfoItem) savedObjects.poll(); } @@ -82,7 +81,9 @@ public final class CommentRepliesFragment @Override protected Single loadResult(final boolean forceLoad) { - return Single.just(this.commentRepliesInfo); + return Single.fromCallable(() -> CommentRepliesInfo.getInfo(commentsInfoItem, + // the reply count string will be shown as the activity title + Localization.replyCount(requireContext(), commentsInfoItem.getReplyCount()))); } @Override diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesInfo.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesInfo.java index 25484296b..7f85dc6bf 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesInfo.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentRepliesInfo.java @@ -13,11 +13,11 @@ public final class CommentRepliesInfo extends ListInfo { super(serviceId, listUrlIdHandler, name); } - public static CommentRepliesInfo getInfo(final CommentsInfoItem comment) { + public static CommentRepliesInfo getInfo(final CommentsInfoItem comment, final String name) { final ListLinkHandler handler = new ListLinkHandler("", "", "", Collections.emptyList(), null); final CommentRepliesInfo relatedItemInfo = new CommentRepliesInfo( - comment.getServiceId(), handler, comment.getName()); + comment.getServiceId(), handler, name); // the name will be shown as fragment title relatedItemInfo.setNextPage(comment.getReplies()); relatedItemInfo.setRelatedItems(Collections.emptyList()); // since it must be non-null return relatedItemInfo;