1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-21 18:42:35 +01:00

Save and restore state in CommentRepliesFragment

This commit is contained in:
Stypox 2023-04-11 23:07:58 +02:00
parent f9494a294f
commit 78cf9aaa7d
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23

View File

@ -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<CommentsInfoItem, CommentRepliesInfo> {
// 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<Object> objectsToSave) {
super.writeTo(objectsToSave);
objectsToSave.add(currentInfo);
objectsToSave.add(commentsInfo);
}
@Override
public void readFrom(@NonNull final Queue<Object> savedObjects) throws Exception {
super.readFrom(savedObjects);
currentInfo = (CommentRepliesInfo) savedObjects.poll();
commentsInfo = (CommentsInfo) savedObjects.poll();
}
/*//////////////////////////////////////////////////////////////////////////
// Data loading
//////////////////////////////////////////////////////////////////////////*/
@Override
protected Single<CommentRepliesInfo> loadResult(final boolean forceLoad) {
return Single.just(this.currentInfo);