smoother transition to comments fragment

This commit is contained in:
Ritvik Saraf 2018-09-23 19:45:26 +05:30
parent 66c753f3a3
commit d694c5f511
2 changed files with 4 additions and 27 deletions

View File

@ -121,7 +121,7 @@ public class VideoDetailFragment
// Amount of videos to show on start
private static final int INITIAL_RELATED_VIDEOS = 8;
// Amount of comments to show on start
private static final int INITIAL_COMMENTS = 8;
public static final int INITIAL_COMMENTS = 8;
private InfoItemBuilder infoItemBuilder = null;
@ -503,32 +503,8 @@ public class VideoDetailFragment
if (DEBUG) Log.d(TAG, "toggleExpandComments() called with: info = [" + info + "]");
if (!showComments || null == info) return;
int initialCount = INITIAL_COMMENTS;
int currentCount = commentsView.getChildCount();
NavigationHelper.openCommentsFragment(getFragmentManager(), serviceId, url, name);
//collapse
if (currentCount > initialCount && !info.hasNextPage()) {
commentsView.removeViews(initialCount,
currentCount - (initialCount));
commentsExpandButton.setImageDrawable(ContextCompat.getDrawable(
activity, ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.expand)));
return;
}
if(currentCount < info.getRelatedItems().size()){
//expand
for (int i = currentCount; i < info.getRelatedItems().size(); i++) {
CommentsInfoItem item = info.getRelatedItems().get(i);
commentsView.addView(infoItemBuilder.buildView(commentsView, item));
}
if(!info.hasNextPage()){
commentsExpandButton.setImageDrawable(
ContextCompat.getDrawable(activity,
ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.collapse)));
}
}else{
NavigationHelper.openCommentsFragment(getFragmentManager(), serviceId, url, name);
}
}
/*//////////////////////////////////////////////////////////////////////////

View File

@ -34,6 +34,7 @@ import org.schabi.newpipe.extractor.channel.ChannelInfo;
import org.schabi.newpipe.extractor.comments.CommentsInfo;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
import org.schabi.newpipe.fragments.list.BaseListInfoFragment;
import org.schabi.newpipe.info_list.InfoItemDialog;
import org.schabi.newpipe.local.dialog.PlaylistAppendDialog;
@ -153,7 +154,7 @@ public class CommentsFragment extends BaseListInfoFragment<CommentsInfo> {
public void handleResult(@NonNull CommentsInfo result) {
super.handleResult(result);
if(initialLoad){
itemsList.smoothScrollToPosition(infoListAdapter.getItemCount());
itemsList.smoothScrollToPosition(VideoDetailFragment.INITIAL_COMMENTS);
initialLoad = false;
}