-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show comment replies #9410
Show comment replies #9410
Changes from all commits
e201b79
703876c
8512198
18f3349
5cd7807
a8fcccd
8f8e29c
648e331
a4cd42b
5603e85
fbd5f24
b91df5e
8dda380
3f64dff
6eef715
3ffcaf8
77bdf6b
f707347
be3a242
f29c941
89a1ab5
b5c0823
298366a
49600d4
d2059db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.schabi.newpipe.fragments.list.comments; | ||
|
||
import android.os.Bundle; | ||
import android.text.TextUtils; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageButton; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
|
||
import org.schabi.newpipe.BaseFragment; | ||
import org.schabi.newpipe.R; | ||
import org.schabi.newpipe.extractor.Page; | ||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem; | ||
import org.schabi.newpipe.fragments.BackPressable; | ||
import org.schabi.newpipe.util.Constants; | ||
|
||
import java.io.IOException; | ||
|
||
import icepick.State; | ||
|
||
public class CommentReplyFragment extends BaseFragment implements BackPressable { | ||
|
||
@State | ||
protected int serviceId = Constants.NO_SERVICE_ID; | ||
@State | ||
protected String name; | ||
@State | ||
protected String url; | ||
@State | ||
protected CommentsInfoItem comment; | ||
@State | ||
protected Page replies; | ||
|
||
public static CommentReplyFragment getInstance( | ||
final int serviceId, final String url, | ||
final String name, | ||
final CommentsInfoItem comment, | ||
final Page replies | ||
) throws IOException, ClassNotFoundException { | ||
final CommentReplyFragment instance = new CommentReplyFragment(); | ||
instance.setInitialData(serviceId, url, name, comment, replies); | ||
return instance; | ||
} | ||
|
||
public static CommentsFragmentContainer newInstance(final int serviceId, final String url, | ||
final String name) { | ||
final CommentsFragmentContainer fragment = new CommentsFragmentContainer(); | ||
fragment.serviceId = serviceId; | ||
fragment.url = url; | ||
fragment.name = name; | ||
return new CommentsFragmentContainer(); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public View onCreateView(@NonNull final LayoutInflater inflater, | ||
@Nullable final ViewGroup container, | ||
@Nullable final Bundle savedInstanceState) { | ||
final View view = inflater.inflate(R.layout.fragment_comments_reply, container, | ||
false); | ||
final ImageButton backButton = view.findViewById(R.id.backButton); | ||
backButton.setOnClickListener(v -> closeSelf()); | ||
final CommentsFragment commentsFragment = CommentsFragment.getInstance( | ||
serviceId, url, name, comment | ||
); | ||
final CommentsFragment commentsReplyFragment = CommentsFragment.getInstance( | ||
serviceId, url, name, replies | ||
); | ||
getChildFragmentManager().beginTransaction() | ||
.add(R.id.commentFragment, commentsFragment).commit(); | ||
getChildFragmentManager().beginTransaction() | ||
.add(R.id.commentReplyFragment, commentsReplyFragment).commit(); | ||
return view; | ||
} | ||
|
||
protected void setInitialData(final int sid, final String u, final String title, | ||
final CommentsInfoItem preComment, | ||
final Page repliesPage | ||
) throws IOException, ClassNotFoundException { | ||
this.serviceId = sid; | ||
this.url = u; | ||
this.name = !TextUtils.isEmpty(title) ? title : ""; | ||
// clone comment object to avoid replies actually set null | ||
this.comment = CommentUtils.clone(preComment); | ||
comment.setReplies(null); | ||
this.replies = repliesPage; | ||
} | ||
|
||
@Override | ||
public boolean onBackPressed() { | ||
closeSelf(); | ||
return true; | ||
} | ||
|
||
private void closeSelf() { | ||
getFM().beginTransaction().remove(this).commit(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.schabi.newpipe.fragments.list.comments; | ||
|
||
import org.schabi.newpipe.extractor.comments.CommentsInfo; | ||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem; | ||
import org.schabi.newpipe.util.SerializedUtils; | ||
|
||
import java.io.IOException; | ||
|
||
final class CommentUtils { | ||
private CommentUtils() { | ||
} | ||
|
||
public static CommentsInfo clone( | ||
final CommentsInfo item | ||
) throws IOException, SecurityException, NullPointerException, ClassNotFoundException { | ||
return SerializedUtils.clone(item, CommentsInfo.class); | ||
} | ||
|
||
public static CommentsInfoItem clone( | ||
final CommentsInfoItem item | ||
) throws IOException, SecurityException, NullPointerException, ClassNotFoundException { | ||
return SerializedUtils.clone(item, CommentsInfoItem.class); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,32 +13,68 @@ | |
|
||
import org.schabi.newpipe.R; | ||
import org.schabi.newpipe.error.UserAction; | ||
import org.schabi.newpipe.extractor.InfoItem; | ||
import org.schabi.newpipe.extractor.ListExtractor; | ||
import org.schabi.newpipe.extractor.Page; | ||
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.ktx.ViewUtils; | ||
import org.schabi.newpipe.util.ExtractorHelper; | ||
|
||
import java.util.List; | ||
|
||
import io.reactivex.rxjava3.core.Single; | ||
import io.reactivex.rxjava3.disposables.CompositeDisposable; | ||
|
||
public class CommentsFragment extends BaseListInfoFragment<CommentsInfoItem, CommentsInfo> { | ||
private final CompositeDisposable disposables = new CompositeDisposable(); | ||
|
||
private Page replies; | ||
private CommentsInfoItem preComment; | ||
|
||
private TextView emptyStateDesc; | ||
|
||
public static CommentsFragment getInstance(final int serviceId, final String url, | ||
final String name) { | ||
final CommentsFragment instance = new CommentsFragment(); | ||
instance.setInitialData(serviceId, url, name); | ||
instance.setInitialData(serviceId, url, name, null, null); | ||
return instance; | ||
} | ||
|
||
public static CommentsFragment getInstance(final int serviceId, final String url, | ||
final String name, | ||
final CommentsInfoItem preComment) { | ||
final CommentsFragment instance = new CommentsFragment(); | ||
instance.setInitialData(serviceId, url, name, null, preComment); | ||
return instance; | ||
} | ||
|
||
public static CommentsFragment getInstance(final int serviceId, final String url, | ||
final String name, | ||
final Page replyPage) { | ||
final CommentsFragment instance = new CommentsFragment(); | ||
instance.setInitialData(serviceId, url, name, replyPage, null); | ||
return instance; | ||
} | ||
|
||
@Override | ||
protected void onItemCallback(final InfoItem selectedItem) throws Exception { | ||
super.onItemCallback(selectedItem); | ||
CommentsFragmentContainer.setFragment(getFM(), (CommentsInfoItem) selectedItem); | ||
} | ||
|
||
public CommentsFragment() { | ||
super(UserAction.REQUESTED_COMMENTS); | ||
} | ||
|
||
protected void setInitialData(final int sid, final String u, final String title, | ||
final Page repliesPage, final CommentsInfoItem comment) { | ||
this.replies = repliesPage; | ||
this.preComment = comment; | ||
super.setInitialData(sid, u, title); | ||
} | ||
|
||
@Override | ||
protected void initViews(final View rootView, final Bundle savedInstanceState) { | ||
super.initViews(rootView, savedInstanceState); | ||
|
@@ -74,7 +110,25 @@ protected Single<ListExtractor.InfoItemsPage<CommentsInfoItem>> loadMoreItemsLog | |
|
||
@Override | ||
protected Single<CommentsInfo> loadResult(final boolean forceLoad) { | ||
return ExtractorHelper.getCommentsInfo(serviceId, url, forceLoad); | ||
if (replies == null) { | ||
if (preComment == null) { | ||
return ExtractorHelper.getCommentsInfo(serviceId, url, forceLoad); | ||
} else { | ||
return Single.fromCallable(() -> { | ||
// get a info template | ||
var info = ExtractorHelper.getCommentsInfo( | ||
serviceId, url, forceLoad).blockingGet(); | ||
// clone comment object to avoid relatedItems and nextPage actually set null | ||
info = CommentUtils.clone(info); | ||
Comment on lines
+121
to
+122
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mmmh, I don't like this that much. Can you explain further why you need to clone the object is a way that is so low-level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you check |
||
// push preComment | ||
info.setRelatedItems(List.of(preComment)); | ||
info.setNextPage(null); | ||
return info; | ||
}); | ||
} | ||
} else { | ||
return ExtractorHelper.getCommentsReplyInfo(serviceId, url, forceLoad, replies); | ||
} | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////////////////// | ||
|
@@ -99,11 +153,13 @@ public void handleResult(@NonNull final CommentsInfo result) { | |
//////////////////////////////////////////////////////////////////////////*/ | ||
|
||
@Override | ||
public void setTitle(final String title) { } | ||
public void setTitle(final String title) { | ||
} | ||
|
||
@Override | ||
public void onCreateOptionsMenu(@NonNull final Menu menu, | ||
@NonNull final MenuInflater inflater) { } | ||
@NonNull final MenuInflater inflater) { | ||
} | ||
|
||
@Override | ||
protected boolean isGridLayout() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also here