From 78cf9aaa7d4c8660cc25953def1e6346bbe268a5 Mon Sep 17 00:00:00 2001 From: Stypox Date: Tue, 11 Apr 2023 23:07:58 +0200 Subject: [PATCH] Save and restore state in CommentRepliesFragment --- .../list/comments/CommentRepliesFragment.java | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 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 1a3508ff3..da8017963 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 @@ -16,19 +16,30 @@ import org.schabi.newpipe.extractor.comments.CommentsInfoItem; import org.schabi.newpipe.fragments.list.BaseListInfoFragment; import org.schabi.newpipe.util.ExtractorHelper; +import java.util.Queue; + 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 final CommentRepliesInfo currentInfo; + private CommentRepliesInfo currentInfo; // the original comments info loaded alongside stream - private final CommentsInfo commentsInfo; + private CommentsInfo commentsInfo; + + + /*////////////////////////////////////////////////////////////////////////// + // Constructors and lifecycle + //////////////////////////////////////////////////////////////////////////*/ + + public CommentRepliesFragment() { + super(UserAction.REQUESTED_COMMENT_REPLIES); + } public CommentRepliesFragment(final CommentsInfo commentsInfo, final CommentsInfoItem commentsInfoItem) { - super(UserAction.REQUESTED_COMMENT_REPLIES); + this(); this.currentInfo = CommentRepliesInfo.getInfo(commentsInfoItem); this.commentsInfo = commentsInfo; setInitialData(commentsInfo.getServiceId(), commentsInfo.getUrl(), commentsInfo.getName()); @@ -42,6 +53,30 @@ public final class CommentRepliesFragment return inflater.inflate(R.layout.fragment_comments, container, false); } + + /*////////////////////////////////////////////////////////////////////////// + // State Saving + //////////////////////////////////////////////////////////////////////////*/ + + @Override + public void writeTo(final Queue objectsToSave) { + super.writeTo(objectsToSave); + objectsToSave.add(currentInfo); + objectsToSave.add(commentsInfo); + } + + @Override + public void readFrom(@NonNull final Queue savedObjects) throws Exception { + super.readFrom(savedObjects); + currentInfo = (CommentRepliesInfo) savedObjects.poll(); + commentsInfo = (CommentsInfo) savedObjects.poll(); + } + + + /*////////////////////////////////////////////////////////////////////////// + // Data loading + //////////////////////////////////////////////////////////////////////////*/ + @Override protected Single loadResult(final boolean forceLoad) { return Single.just(this.currentInfo);