Exemple #1
0
  private void loadMoreData(final long maxId) {
    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        0,
        maxId,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {

            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            for (Statuses status : response.statuses) {
              mAdapter.addStatuses(status);
              mMaxId = status.id - 1;
            }

            if (maxId == 0 && response.statuses.size() > 0) {
              mSinceId = response.statuses.get(0).id;
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {

                    setLastSyncTime(Util.getNowLocaleTime());
                    mAdapter.notifyDataSetChanged();
                    // Call onLoadMoreComplete when the LoadMore
                    // task, has finished
                    mListView.onLoadMoreComplete();
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            Util.showToast(TimelineActivity.this, "Error:" + e.getMessage());
          }

          @Override
          public void onIOException(IOException e) {
            // TODO Auto-generated method stub

          }
        });
  }
Exemple #2
0
  private void getFriendsTimeline(final long sinceId, final long maxId) {

    hideErrorIndicator();
    showLoadingIndicator();

    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        sinceId,
        maxId,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {

            // Util.writeUpdateInfo(result);
            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            for (Statuses status : response.statuses) {
              mAdapter.addStatuses(status);

              if (sinceId == 0) {
                mMaxId = status.id - 1;
              }
            }

            if (maxId == 0 && response.statuses.size() > 0) {
              mSinceId = response.statuses.get(0).id;
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    hideLoadingIndicator();
                    aq.id(R.id.placeholder_error).gone();

                    showContents();
                    mAdapter.notifyDataSetChanged();
                    setLastSyncTime(Util.getNowLocaleTime());
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    showErrorIndicator();
                    aq.id(R.id.error_msg).text(e.getMessage());
                    aq.id(R.id.retry_button)
                        .clicked(
                            new OnClickListener() {

                              @Override
                              public void onClick(View v) {
                                getFriendsTimeline(sinceId, maxId);
                              }
                            });
                  }
                });
          }

          @Override
          public void onIOException(IOException e) {}
        });
  }
Exemple #3
0
  private void refreshStatus(long sinceId) {
    mActionBar.setProgressBarVisibility(View.VISIBLE);

    StatusesAPI statusAPI = new StatusesAPI(mAccessToken);
    statusAPI.friendsTimeline(
        sinceId,
        0,
        20,
        1,
        false,
        FEATURE.ALL,
        false,
        new RequestListener() {

          @Override
          public void onComplete(String result) {
            Gson gson = new Gson();
            WeiboObject response = gson.fromJson(result, WeiboObject.class);

            final int refreshCount = response.statuses.size();
            Log.d("newsMsgLists length == " + refreshCount);
            if (refreshCount > 0) {
              mSinceId = response.statuses.get(0).id;
              mAdapter.addNewestStatuses(response.statuses);
            }

            runOnUiThread(
                new Runnable() {

                  @Override
                  public void run() {
                    mActionBar.setProgressBarVisibility(View.GONE);
                    mAdapter.notifyDataSetChanged();
                    // Call onRefreshComplete when the list has been
                    // refreshed.
                    mListView.onRefreshComplete();
                    mListView.setLastUpdated(getLastSyncTime(Preferences.PREF_LAST_SYNC_TIME));

                    setLastSyncTime(Util.getNowLocaleTime());

                    if (refreshCount > 0) {
                      displayToast(
                          String.format(
                              getResources().getString(R.string.new_blog_toast), refreshCount));
                    } else {
                      displayToast(R.string.no_new_blog_toast);
                    }
                  }
                });
          }

          @Override
          public void onError(final WeiboException e) {
            Util.showToast(TimelineActivity.this, "Error:" + e.getMessage());
          }

          @Override
          public void onIOException(IOException e) {
            // TODO Auto-generated method stub

          }
        });
  }