コード例 #1
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  private void onRebroadcastResponse(
      boolean successful, Broadcast result, VolleyError error, RebroadcastState state) {

    if (successful) {

      if (!state.rebroadcast) {
        // Delete the rebroadcast broadcast by user. Must be done before we update the
        // broadcast so that we can retrieve rebroadcastId for the old one.
        // This will not finish this activity, because this activity displays the
        // rebroadcasted broadcast instead of the rebroadcast broadcast itself, and this is
        // the desired behavior since it won't surprise user, and user can have the chance
        // to undo it.
        Broadcast broadcast = mBroadcastAdapter.getBroadcast();
        if (broadcast != null && broadcast.rebroadcastId != null) {
          EventBus.getDefault().post(new BroadcastDeletedEvent(broadcast.rebroadcastId));
        }
      }
      EventBus.getDefault().post(new BroadcastUpdatedEvent(result));
      ToastUtils.show(
          state.rebroadcast
              ? R.string.broadcast_rebroadcast_successful
              : R.string.broadcast_unrebroadcast_successful,
          this);

    } else {

      LogUtils.e(error.toString());
      Broadcast broadcast = mBroadcastAdapter.getBroadcast();
      if (broadcast != null) {
        boolean notified = false;
        if (error instanceof ApiError) {
          // Correct our local state if needed.
          ApiError apiError = (ApiError) error;
          Boolean shouldBeRebroadcasted = null;
          if (apiError.code == Codes.RebroadcastBroadcast.ALREADY_REBROADCASTED) {
            shouldBeRebroadcasted = true;
          } else if (apiError.code == Codes.RebroadcastBroadcast.NOT_REBROADCASTED_YET) {
            shouldBeRebroadcasted = false;
          }
          if (shouldBeRebroadcasted != null) {
            broadcast.fixRebroacasted(shouldBeRebroadcasted);
            EventBus.getDefault().post(new BroadcastUpdatedEvent(broadcast));
            notified = true;
          }
        }
        if (!notified) {
          // Must notify changed to reset pending status so that off-screen
          // items will be invalidated.
          mBroadcastAdapter.notifyBroadcastChanged();
        }
      }
      ToastUtils.show(
          getString(
              state.rebroadcast
                  ? R.string.broadcast_rebroadcast_failed_format
                  : R.string.broadcast_unrebroadcast_failed_format,
              ApiError.getErrorString(error, this)),
          this);
    }
  }
コード例 #2
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private void onShowCommentAction(Comment comment) {
   boolean canReplyTo = canSendComment();
   long userId = AccountUtils.getUserId(this);
   boolean canDelete =
       (mBroadcastAdapter.hasBroadcast() && mBroadcastAdapter.getBroadcast().author.id == userId)
           || comment.author.id == userId;
   CommentActionDialogFragment.show(comment, canReplyTo, canDelete, this);
 }
コード例 #3
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  @Override
  public boolean onLike(boolean like) {

    if (mBroadcastAdapter.hasBroadcast()
        && mBroadcastAdapter.getBroadcast().author.id == AccountUtils.getUserId(this)) {
      ToastUtils.show(R.string.broadcast_like_error_cannot_like_oneself, this);
      return false;
    }

    ApiRequest<Broadcast> request = ApiRequests.newLikeBroadcastRequest(mBroadcastId, like, this);
    LikeState state = new LikeState(like);
    RequestFragment.startRequest(REQUEST_CODE_LIKE, request, state, this);
    return true;
  }
コード例 #4
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  @Override
  public boolean onRebroadcast(boolean rebroadcast) {

    if (mBroadcastAdapter.hasBroadcast()
        && mBroadcastAdapter.getBroadcast().author.id == AccountUtils.getUserId(this)) {
      ToastUtils.show(R.string.broadcast_rebroadcast_error_cannot_rebroadcast_oneself, this);
      return false;
    }

    ApiRequest<Broadcast> request =
        ApiRequests.newRebroadcastBroadcastRequest(mBroadcastId, rebroadcast, this);
    RebroadcastState state = new RebroadcastState(rebroadcast);
    RequestFragment.startRequest(REQUEST_CODE_REBROADCAST, request, state, this);
    return true;
  }
コード例 #5
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private void setBroadcastRefreshing(boolean refreshing) {
   mSwipeRefreshLayout.setEnabled(!refreshing);
   if (!refreshing) {
     mSwipeRefreshLayout.setRefreshing(false);
   }
   ViewUtils.setVisibleOrGone(mProgress, refreshing && mBroadcastAdapter.getItemCount() == 0);
 }
コード例 #6
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  private void onLikeResponse(
      boolean successful, Broadcast result, VolleyError error, LikeState state) {

    if (successful) {

      EventBus.getDefault().post(new BroadcastUpdatedEvent(result));
      ToastUtils.show(
          state.like ? R.string.broadcast_like_successful : R.string.broadcast_unlike_successful,
          this);

    } else {

      LogUtils.e(error.toString());
      Broadcast broadcast = mBroadcastAdapter.getBroadcast();
      if (broadcast != null) {
        boolean notified = false;
        if (error instanceof ApiError) {
          // Correct our local state if needed.
          ApiError apiError = (ApiError) error;
          Boolean shouldBeLiked = null;
          if (apiError.code == Codes.LikeBroadcast.ALREADY_LIKED) {
            shouldBeLiked = true;
          } else if (apiError.code == Codes.LikeBroadcast.NOT_LIKED_YET) {
            shouldBeLiked = false;
          }
          if (shouldBeLiked != null) {
            broadcast.fixLiked(shouldBeLiked);
            EventBus.getDefault().post(new BroadcastUpdatedEvent(broadcast));
            notified = true;
          }
        }
        if (!notified) {
          // Must notify changed to reset pending status so that off-screen
          // items will be invalidated.
          mBroadcastAdapter.notifyBroadcastChanged();
        }
      }
      ToastUtils.show(
          getString(
              state.like
                  ? R.string.broadcast_like_failed_format
                  : R.string.broadcast_unlike_failed_format,
              ApiError.getErrorString(error, this)),
          this);
    }
  }
コード例 #7
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  private void copyText() {

    Broadcast broadcast = mBroadcastAdapter.getBroadcast();
    if (broadcast == null) {
      ToastUtils.show(R.string.broadcast_copy_text_not_loaded, this);
      return;
    }

    ClipboardUtils.copyText(broadcast.getClipboradLabel(), broadcast.getClipboardText(this), this);
  }
コード例 #8
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private void fixCommentCount() {
   Broadcast broadcast = mBroadcastAdapter.getBroadcast();
   if (broadcast != null) {
     int commentCount = mCommentAdapter.getItemCount();
     if (broadcast.commentCount < commentCount) {
       broadcast.commentCount = commentCount;
       EventBus.getDefault().post(new BroadcastUpdatedEvent(broadcast));
     }
   }
 }
コード例 #9
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private void onDeleteCommentResponse(
     boolean successful, Boolean result, VolleyError error, DeleteCommentState state) {
   if (successful) {
     ToastUtils.show(R.string.broadcast_comment_delete_successful, this);
     EventBus.getDefault().post(new BroadcastCommentDeletedEvent(mBroadcastId, state.commentId));
     if (mBroadcastAdapter.hasBroadcast()) {
       Broadcast broadcast = mBroadcastAdapter.getBroadcast();
       --broadcast.commentCount;
       EventBus.getDefault().post(new BroadcastUpdatedEvent(broadcast));
     }
   } else {
     LogUtils.e(error.toString());
     ToastUtils.show(
         getString(
             R.string.broadcast_comment_delete_failed_format,
             ApiError.getErrorString(error, this)),
         this);
   }
 }
コード例 #10
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    Broadcast broadcast = mBroadcastAdapter.getBroadcast();
    boolean hasBroadcast = broadcast != null;
    menu.findItem(R.id.action_copy_text).setVisible(hasBroadcast);
    boolean canDelete = hasBroadcast && broadcast.author.id == AccountUtils.getUserId(this);
    menu.findItem(R.id.action_delete).setVisible(canDelete);
    return true;
  }
コード例 #11
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  @Override
  protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    mRetainDataFragment.put(RETAIN_DATA_KEY_BROADCAST, mBroadcastAdapter.getBroadcast());
    mRetainDataFragment.put(RETAIN_DATA_KEY_COMMENT_LIST, mCommentAdapter.getList());
    mRetainDataFragment.put(RETAIN_DATA_KEY_CAN_LOAD_MORE_COMMENTS, mCanLoadMoreComments);
    mRetainDataFragment.put(
        RETAIN_DATA_KEY_LOADING_BROADCAST_OR_COMMENT_LIST, mLoadingBroadcastOrCommentList);
    mRetainDataFragment.put(RETAIN_DATA_KEY_SENDING_COMMENT, mSendingComment);
    mRetainDataFragment.put(RETAIN_DATA_KEY_VIEW_STATE, onSaveViewState());
  }
コード例 #12
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
  @Override
  public void onStart() {
    super.onStart();

    // Only auto-load when initially empty, not loaded but empty.
    boolean autoLoadComments = mCommentAdapter.getItemCount() == 0 && mCanLoadMoreComments;
    if (mBroadcastAdapter.getItemCount() == 0) {
      loadBroadcast(autoLoadComments);
    } else if (autoLoadComments) {
      loadCommentList(false);
    }

    EventBus.getDefault().register(this);
  }
コード例 #13
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private boolean canSendComment() {
   return mBroadcastAdapter.hasBroadcast() && mBroadcastAdapter.getBroadcast().canComment();
 }
コード例 #14
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 @Override
 public void onViewActivity() {
   BroadcastActivityDialogFragment.show(mBroadcastAdapter.getBroadcast(), this);
 }
コード例 #15
0
ファイル: BroadcastActivity.java プロジェクト: xyhrun/Douya
 private void setBroadcast(Broadcast broadcast) {
   mBroadcastAdapter.setBroadcast(broadcast);
   updateSendCommentEnabled();
 }