示例#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
  private void onSearchClicked() {
    String username = inputView.getEditText().getText().toString().trim();

    userService
        .info(username)
        .compose(bindToLifecycle())
        .lift(BusyDialogFragment.busyDialog(this))
        .subscribe(this::onSearchSuccess, this::onSearchFailure);
  }
 @Override
 protected LoaderHelper<List<Message>> newLoaderHelper() {
   return LoaderHelper.of(
       () -> {
         String name = userService.getName().get();
         return getInboxService()
             .getUserComments(name)
             .map(
                 userComments -> {
                   //noinspection CodeBlock2Expr
                   return Lists.transform(
                       userComments.getComments(),
                       comment -> Message.of(userComments.getUser(), comment));
                 });
       });
 }
示例#4
0
  @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);
  }