Пример #1
0
  private void sendSayhi(String msg) {
    ToastFactory.getToast(mContext, "招呼发送中...").show();
    SayHiParams params = new SayHiParams();
    params.fromUserId = MyApplication.getInstance().getCurrentLoginedUser().getUserId();
    params.toUserId = mCurrentSayhiUser.getUserId();
    params.content = msg;
    AppServiceExtendImpl.getInstance()
        .sayhi(
            params,
            new OnSayHiResponseListener() {

              @Override
              public void onSuccess(int money, String msg) {
                ToastFactory.getToast(mContext, msg).show();
                LoginedUser loginedUser = MyApplication.getInstance().getCurrentLoginedUser();
                loginedUser.setLoveMoney(money);
              }

              @Override
              public void onFailure(String msg) {
                // TODO Auto-generated method stub
                ToastFactory.getToast(mContext, msg).show();
              }
            });
  }
  private void publishComment() {
    if (isPosting) {
      return;
    }

    if (TextUtils.isEmpty(etCommentContent.getText())) {
      //	    etCommentContent.setShakeAnimation();
      etCommentContent.requestFocus();
      return;
    }

    isPosting = true;
    PublishArticleCommentPostParams postParams = new PublishArticleCommentPostParams();
    postParams.articleId = targetArticle.getId();
    if (mCurrentReplyComment != null) {
      postParams.parentCommentId = mCurrentReplyComment.getId();
    }
    postParams.content = etCommentContent.getText().toString();

    AppServiceExtendImpl.getInstance()
        .publishArticleComment(
            postParams,
            new OnPublishArticleCommentResponseListener() {

              @Override
              public void onSuccess(ArticleComment comment) {
                // TODO Auto-generated method stub

                // 发布成功, 恢复原状
                etCommentContent.setText("");
                mCurrentReplyComment = null;
                layoutReply.setVisibility(View.GONE);
                // 隐藏表情 view
                findViewById(R.id.layout_emo).setVisibility(View.GONE);
                // 软键盘
                ActivityUtil.hideSoftInput(ArticleCommentsActivity.this);

                isPosting = false;
                mCommentsAdapter.add(comment);

                // 隐藏头部提示加载的textview
                tvLoading.setVisibility(View.GONE);
              }

              @Override
              public void onFailure(String errorMsg) {
                // TODO Auto-generated method stub
                ActivityUtil.show(ArticleCommentsActivity.this, errorMsg);
                isPosting = false;
              }
            });
  }
Пример #3
0
  /** 重新获取首页信息 */
  private void updateHomeInfo() {
    // 显示状态改变时 尝试更新为当前内存中保存的资料
    final LoginedUser user = MyApplication.getInstance().getCurrentLoginedUser();

    LoadHomeInfoPostParams postParams = new LoadHomeInfoPostParams();

    AppServiceExtendImpl.getInstance()
        .loadHomeInfo(
            postParams,
            new OnLoadHomeInfoResponseListener() {

              @Override
              public void onSuccess(HomeInfo homeInfo) {
                // TODO Auto-generated method stub

                //		tvFansCount.setText(homeInfo.fans + "");
                //		tvFriendsCount.setText(homeInfo.friends + "");
                //		tvFollowsCount.setText(homeInfo.follows + "");

                // 更新 loginedUser中的数据
                user.setFansCount(homeInfo.fans);
                user.setFollowsCount(homeInfo.follows);
                user.setFriendsCount(homeInfo.friends);

                user.setLoveMoney(homeInfo.loveMoney);
                user.setNickname(homeInfo.nickname);

                user.setIsVip(homeInfo.isVip ? 1 : 0);

                user.setVipExpireTime(homeInfo.vipExpireTime);

                // 更新view

                mTvMyMoney.setText(user.getLoveMoney() + "");
                if (user.getIsVip() == 1) {
                  String dateStr =
                      ActivityUtil.getDateStr(user.getVipExpireTime(), "yyyy/MM/dd HH:mm:ss");
                  tvVipExpireTime.setText(dateStr);
                } else { // 非会员
                  tvVipExpireTime.setText("您目前还没有开通VIP会员");
                }

                //		tvMyId.setText("ID:" + user.getUserId());
                //		tvMyNickname.setEmojiText(user.getNickname());
                //		tvLoveMoney.setText(user.getLoveMoney() + "币");
                //		if (homeInfo.signed) {
                //		    tvSignin.setText("已签到");
                //		    tvSignin.setEnabled(false);
                //		}
                //
                //		if (user.getIsVip() == 1) {
                //		    tvMyVip.setBackgroundResource(R.drawable.vip_sign);
                //		} else {
                //		    tvMyVip.setBackgroundResource(R.drawable.vip_sign_not);
                //		}
                //		String url = user.getFaceUrl();//
                // "http://t11.baidu.com/it/u=751031812,971358817&fm=56" :
                // "http://img1.imgtn.bdimg.com/it/u=1983880049,3609856836&fm=116&gp=0.jpg";
                //		refreshMyFace(url);
              }

              @Override
              public void onFailure(String errorMsg) {
                // TODO Auto-generated method stub

              }
            });
  }
  /** 加载评论 */
  private void loadArticleComments() {

    if (isRefreshing) {
      return;
    }

    isRefreshing = true;

    LoadArticleCommentsPostParams postParams = new LoadArticleCommentsPostParams();
    postParams.articleId = targetArticle.getId();
    postParams.page = pageNumber;
    postParams.pageSize = 20;

    AppServiceExtendImpl.getInstance()
        .loadArticleComments(
            postParams,
            new OnLoadArticleCommentsResponseListener() {

              @Override
              public void onSuccess(List<ArticleComment> comments) {

                pbLoading.setVisibility(View.GONE);

                if (comments.size() != 0) {
                  if (pageNumber == 1) { // 是刷新
                    mCommentsAdapter.getList().clear();
                  }
                  tvLoading.setVisibility(View.GONE);

                  mCommentsAdapter.addAll(comments);
                } else {
                  tvLoading.setVisibility(View.VISIBLE);
                  if (pageNumber == 1) {
                    if (mCommentsAdapter.getList().size() == 0) {
                      tvLoading.setText("暂无评论");
                    } else {
                      tvLoading.setText("暂无更多评论");
                    }
                  } else {
                    tvLoading.setText("暂无更多评论");
                  }
                }

                pageNumber++;

                isRefreshing = false;

                mListView.stopRefresh();
                mListView.stopLoadMore();
              }

              @Override
              public void onFailure(String errorMsg) {
                // TODO Auto-generated method stub
                ActivityUtil.show(ArticleCommentsActivity.this, errorMsg);

                pbLoading.setVisibility(View.GONE);
                tvLoading.setText("网络超时,请重试");

                mListView.stopRefresh();
                mListView.stopLoadMore();

                isRefreshing = false;
              }
            });
  }
  private void loadArticles() {
    if (isRefreshing) {
      return;
    }

    isRefreshing = true;

    LoadWaitingForReviewArticlesPostParams postParams =
        new LoadWaitingForReviewArticlesPostParams();
    postParams.page = pageNumber;
    postParams.pageSize = 20;
    postParams.order = "create_time ASC"; // 时间升序
    postParams.reviewStatus = 0; // 未审核状态

    AppServiceExtendImpl.getInstance()
        .loadWaitingForReviewArticles(
            postParams,
            new OnLoadArticlesResponseListener() {

              @Override
              public void onSuccess(List<Article> secrets) {
                // TODO Auto-generated method stub
                if (secrets.size() != 0) {
                  if (pageNumber == 1) {
                    mAdapter.getList().clear();
                  }
                  mAdapter.addAll(secrets);

                  // 缓存到本地
                  cacheToLocal(secrets);
                } else {
                  if (pageNumber == 1) { // 刷新没有数据
                    mAdapter.getList().clear();
                  }
                  showToast(mAdapter.getList().size() != 0 ? "暂无更多" : "暂无数据");
                }

                isRefreshing = false;

                if (mListView.getPullLoading()) {
                  mListView.stopLoadMore();
                }
                if (mListView.getPullRefreshing()) {
                  mListView.stopRefresh();
                }
                pageNumber++;
              }

              private void cacheToLocal(List<Article> secrets) {
                // TODO Auto-generated method stub
                File f = new File(cacheArticlesPath);
                if (!f.getParentFile().exists()) {
                  f.getParentFile().mkdirs();
                }
                try {
                  ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f));
                  oos.writeObject(secrets);
                  oos.close();
                } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }

              @Override
              public void onFailure(String errorMsg) {

                isRefreshing = false;
                // TODO Auto-generated method stub
                if (mListView.getPullLoading()) {
                  mListView.stopLoadMore();
                }
                if (mListView.getPullRefreshing()) {
                  mListView.stopRefresh();
                }
                showToast(errorMsg);
              }
            });
  }