Exemple #1
0
 public void onEventMainThread(SubscriptionAddActivity.FollowFlagEvent event) {
   if (event.flag) {
     if (mSetting != null) mSetting.setVisibility(View.GONE);
     if (listLayout == null) {
       listLayout = mListViewStub.inflate();
       initListView(listLayout);
     } else {
       listLayout.setVisibility(View.VISIBLE);
       data.clear();
       adapter.notifyDataSetChanged();
       mEmptyView.show(true);
       mEmptyView.onLoading();
       request(Urls.SERVER_PATH + "/user/feeds", 0);
     }
   } else {
     stopRefreshNews();
     if (mListViewStub != null) mListViewStub.setVisibility(View.GONE);
     if (settingLayout == null) {
       settingLayout = mSetting.inflate();
       initSettingView(settingLayout);
     } else settingLayout.setVisibility(View.VISIBLE);
   }
 }
Exemple #2
0
 @Override
 public void onClick(View v) {
   FeedGsonModel model = adapter.getItem(mListView.getChildAdapterPosition(v));
   if (model == null) return;
   Intent intent;
   if (!TextUtils.isEmpty(model.url)) {
     // &&!AppSharePreferences.getCollectionFlag(getActivity())
     if (model.type.equals("assistantmessage")) {
       intent =
           ExternalMessageManager.dealExternalMessage(
               getActivity(), model.type, model.url, null, model.title, false);
       intent.putExtra("message_id", model.id);
     } else {
       intent =
           ExternalMessageManager.dealExternalMessage(getActivity(), model.url, null, true);
     }
     if (intent != null) {
       intent.putExtra("channel_id", model.channels.get(0).id);
       startActivity(intent);
       return;
     }
   }
 }
Exemple #3
0
  /** @param type 0 refresh 1 more */
  private void request(String url, final int type) {
    if (type == 0) {
      stopRefreshNews();
      showRefreshNewsCount(null, false);
      refreshing = true;
      mHandler.removeCallbacks(stopRefreshRunnable);
    }
    if (adapter.getItemCount() == 0) {
      mEmptyView.show(true);
      mEmptyView.onLoading();
    }
    mEmptyView.setOnClickListener(null);
    GsonRequest<FeedDatasGsonModel> req =
        new GsonRequest<FeedDatasGsonModel>(
            url,
            FeedDatasGsonModel.class,
            AppUtils.getOAuthMap(getActivity()),
            new Response.Listener<FeedDatasGsonModel>() {
              @Override
              public void onResponse(FeedDatasGsonModel response) {
                if (response != null) {
                  nextUrl = response.next;
                  if (response.data != null && !response.data.isEmpty()) {
                    if (type == 0) {
                      data.clear();
                    }
                    data.addAll(response.data);
                  }
                }

                if (!TextUtils.isEmpty(nextUrl)) {
                  adapter.setLoadMoreEnable(true);
                  adapter.setLoadMoreState(0);
                } else {
                  adapter.setLoadMoreEnable(true);
                  adapter.setLoadMoreState(XListViewFooter.STATE_NOTDATA);
                }

                adapter.notifyDataSetChanged();
                if (type == 0) {
                  offset = response != null ? response.offset : null;
                  if (!TextUtils.isEmpty(offset)) {
                    try {
                      offset = URLEncoder.encode(offset, "UTF-8");
                    } catch (UnsupportedEncodingException e) {
                      e.printStackTrace();
                    }
                    startRefreshNews();
                  }
                  mRefresh.clearAnimation();
                  refreshing = false;
                  swipeRefreshLayout.setRefreshing(false);
                } else isLoading = false;
                if (adapter.getItemCount() <= 0) {
                  mEmptyView.show(true);
                  mEmptyView.onFailed(getString(R.string.no_data));
                } else if (mEmptyView.isShowing()) mEmptyView.show(false);
              }
            },
            new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                if (mRefresh != null) mRefresh.clearAnimation();
                if (type == 0) {
                  if (!TextUtils.isEmpty(offset)) {
                    startRefreshNews();
                  }
                  if (data.isEmpty()) {
                    mEmptyView.show(true);
                    ErrorEntity entity = AppUtils.getErrorEntity(error);
                    mEmptyView.onFailed(
                        entity != null && !TextUtils.isEmpty(entity.getMessage())
                            ? entity.getMessage()
                            : getString(R.string.chat_load_failed));
                    mEmptyView.setOnClickListener(mRefreshNewsListener);
                  }
                  refreshing = false;
                  swipeRefreshLayout.setRefreshing(false);
                } else {
                  adapter.setLoadMoreEnable(true);
                  adapter.setLoadMoreState(0);
                  adapter.notifyDataSetChanged();
                  isLoading = false;
                }
              }
            });
    req.setShouldCache(false);
    addRequest(req);
  }