示例#1
0
  @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);
        });
  }
示例#2
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    doIfAuthorizedHelper.onActivityResult(requestCode, resultCode);

    if (requestCode == RequestCodes.WRITE_COMMENT && resultCode == Activity.RESULT_OK) {
      onNewComments(WriteMessageActivity.getNewComment(data));
    }
  }
示例#3
0
 @SuppressWarnings("CodeBlock2Expr")
 @Override
 public boolean onCommentVoteClicked(Comment comment, Vote vote) {
   return doIfAuthorizedHelper.run(
       () -> {
         voteService
             .vote(comment, vote)
             .compose(bindToLifecycle())
             .subscribe(Actions.empty(), defaultOnError());
       });
 }
示例#4
0
  @SuppressWarnings("CodeBlock2Expr")
  @Override
  public void onAnswerClicked(Comment comment) {
    Runnable retry = () -> onAnswerClicked(comment);

    doIfAuthorizedHelper.run(
        () -> {
          startActivityForResult(
              WriteMessageActivity.answerToComment(getActivity(), feedItem, comment),
              RequestCodes.WRITE_COMMENT);
        },
        retry);
  }
示例#5
0
  private void initializeCommentPostLine() {
    ViewGroup.MarginLayoutParams layoutParams =
        new ViewGroup.MarginLayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    CommentPostLine line = new CommentPostLine(getActivity());
    line.setLayoutParams(layoutParams);
    adapter.addAdapter(SingleViewAdapter.ofView(line));

    line.setCommentDraft(getArguments().getString(ARG_COMMENT_DRAFT, ""));
    line.textChanges().subscribe(text -> getArguments().putString(ARG_COMMENT_DRAFT, text));

    line.comments()
        .subscribe(
            text -> {
              Runnable action =
                  () -> {
                    line.clear();
                    writeComment(text);
                  };

              doIfAuthorizedHelper.run(action, action);
            });
  }