/** * Scroll the th given comment * * @param commentId The comment id to scroll to */ private void scrollToComment(long commentId) { Optional<Integer> offset = adapter.getOffset(commentsAdapter); if (!offset.isPresent()) return; for (int idx = 0; idx < commentsAdapter.getItemCount(); idx++) { if (commentsAdapter.getItemId(idx) == commentId) { content.scrollToPosition(offset.get() + idx); break; } } commentsAdapter.setSelectedCommentId(commentId); }
@Override public void onResume() { super.onResume(); // set ordering commentsAdapter.setPrioritizeOpComments(settings.prioritizeOpComments()); }
/** * Displays the given list of comments combined with the voting for those comments. * * @param comments The list of comments to display. */ private void displayComments(List<Comment> comments) { this.comments = ImmutableList.copyOf(comments); // show now commentsAdapter.set(comments, emptyMap(), feedItem.getUser()); if (autoScrollTo.isPresent()) { scrollToComment(autoScrollTo.get()); autoScrollTo = Optional.absent(); } // load the votes for the comments and update, when we found any voteService .getCommentVotes(comments) .filter(votes -> !votes.isEmpty()) .onErrorResumeNext(empty()) .compose(bindToLifecycle()) .subscribe(votes -> commentsAdapter.set(comments, votes, feedItem.getUser())); }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); this.tabletLayout = view.findViewById(R.id.infoview) != null; if (!(getActivity() instanceof ToolbarActivity)) { throw new IllegalStateException("Fragment must be child of a ToolbarActivity."); } ToolbarActivity activity = (ToolbarActivity) getActivity(); activity.getScrollHideToolbarListener().reset(); int abHeight = AndroidUtility.getActionBarContentOffset(getActivity()); if (tabletLayout) { View tabletLayout = ButterKnife.findById(view, R.id.tabletlayout); tabletLayout.setPadding(0, abHeight, 0, 0); ((FrameLayout.LayoutParams) voteAnimationIndicator.getLayoutParams()).gravity = Gravity.CENTER; scrollHandler = new NoopOnScrollListener(); } else { // use height of the toolbar to configure swipe refresh layout. swipeRefreshLayout.setProgressViewOffset(false, 0, (int) (1.5 * abHeight)); scrollHandler = new ScrollHandler(activity); } content.addOnScrollListener(scrollHandler); swipeRefreshLayout.setColorSchemeResources(R.color.primary); swipeRefreshLayout.setOnRefreshListener( () -> { if (!isVideoFullScreen()) { rewindOnLoad = true; loadPostDetails(); } }); swipeRefreshLayout.setKeepScreenOn(settings.keepScreenOn()); adapter = new MergeRecyclerAdapter(); content.setItemAnimator(null); content.setLayoutManager(new LinearLayoutManager(getActivity())); content.setAdapter(adapter); initializeMediaView(); initializeInfoLine(); initializeCommentPostLine(); commentsAdapter = new CommentsAdapter(userService.getName().or("")); commentsAdapter.setCommentActionListener(this); commentsAdapter.setPrioritizeOpComments(settings.prioritizeOpComments()); commentsAdapter.setShowFavCommentButton(userService.isAuthorized()); adapter.addAdapter(commentsAdapter); // restore the postInfo, if possible. if (tags != null && comments != null) { displayTags(tags); displayComments(comments); } loadPostDetails(); // show the repost badge if this is a repost repostHint.setVisibility(isRepost() ? View.VISIBLE : View.GONE); }