From d694c5f511461a6fa939cb2ffe5c83777d39cafe Mon Sep 17 00:00:00 2001 From: Ritvik Saraf <13ritvik@gmail.com> Date: Sun, 23 Sep 2018 19:45:26 +0530 Subject: [PATCH] smoother transition to comments fragment --- .../fragments/detail/VideoDetailFragment.java | 28 ++----------------- .../list/comments/CommentsFragment.java | 3 +- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java index 4357753b4..64d785bcb 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java @@ -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); - } } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java index 3e9cfe44c..02815407a 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/comments/CommentsFragment.java @@ -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 { public void handleResult(@NonNull CommentsInfo result) { super.handleResult(result); if(initialLoad){ - itemsList.smoothScrollToPosition(infoListAdapter.getItemCount()); + itemsList.smoothScrollToPosition(VideoDetailFragment.INITIAL_COMMENTS); initialLoad = false; }