@SuppressWarnings("CodeBlock2Expr") private void initializeInfoLine() { // get the vote from the service Observable<Vote> cachedVote = voteService.getVote(feedItem).compose(bindToLifecycle()); //noinspection ConstantConditions infoLineView = ButterKnife.findById(getView(), R.id.infoview); if (infoLineView == null) { infoLineView = new InfoLineView(getActivity()); adapter.addAdapter(SingleViewAdapter.ofView(infoLineView)); } boolean isSelfPost = userService .getName() .transform(name -> name.equalsIgnoreCase(feedItem.getUser())) .or(false); // display the feed item in the view infoLineView.setFeedItem(feedItem, isSelfPost, cachedVote); infoLineView.setOnDetailClickedListener(this); // register the vote listener infoLineView.setOnVoteListener( vote -> { Runnable action = () -> { showPostVoteAnimation(vote); voteService .vote(feedItem, vote) .compose(bindToLifecycle()) .subscribe(Actions.empty(), defaultOnError()); }; Runnable retry = () -> infoLineView.getVoteView().setVote(vote); return doIfAuthorizedHelper.run(action, retry); }); // and a vote listener vor voting tags. infoLineView.setTagVoteListener( (tag, vote) -> { Runnable action = () -> { voteService .vote(tag, vote) .compose(bindToLifecycle()) .subscribe(Actions.empty(), defaultOnError()); }; return doIfAuthorizedHelper.run(action, action); }); infoLineView.setOnAddTagClickedListener( () -> { NewTagDialogFragment dialog = new NewTagDialogFragment(); dialog.show(getChildFragmentManager(), null); }); }
@SuppressWarnings("CodeBlock2Expr") @Override public boolean onCommentVoteClicked(Comment comment, Vote vote) { return doIfAuthorizedHelper.run( () -> { voteService .vote(comment, vote) .compose(bindToLifecycle()) .subscribe(Actions.empty(), defaultOnError()); }); }
@Override public void onCommentMarkAsFavoriteClicked(Comment comment, boolean markAsFavorite) { Observable<Void> result; if (markAsFavorite) { result = favedCommentService.save( ImmutableFavedComment.builder() .id(comment.getId()) .name(comment.getName()) .content(comment.getContent()) .created(comment.getCreated()) .up(comment.getUp()) .down(comment.getDown()) .mark(comment.getMark()) .thumb(feedItem.getThumb()) .itemId(feedItem.getId()) .flags(feedItem.getFlags()) .build()); } else { result = favedCommentService.delete(comment.getId()); } result .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .subscribe(Actions.empty(), defaultOnError()); if (singleShotService.isFirstTime("kfav-userscript-hint")) { DialogBuilder.start(getContext()) .content(R.string.hint_kfav_userscript) .positive( R.string.open_website, di -> { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://goo.gl/py7xNW")); getContext().startActivity(intent); }) .negative(R.string.ignore) .show(); } }