Exemple #1
0
 @Override
 public void onDestroy() {
   EventBus.getDefault().unregister(this);
   if (!TextUtils.isEmpty(REFRESH_TAG)) {
     ApplicationController.getInstance().cancelPendingRequests(REFRESH_TAG);
   }
   super.onDestroy();
 }
Exemple #2
0
 private void requestNewFeedRefresh() {
   StringRequest req =
       new StringRequest(
           Urls.SERVER_PATH + "/feed/unread_num?offset=" + offset,
           new Response.Listener<String>() {
             @Override
             public void onResponse(String response) {
               if (!TextUtils.isEmpty(response)) {
                 try {
                   JSONObject json = new JSONObject(response);
                   int count = json.getInt("unread_num");
                   String msg = json.getString("message");
                   if (count > 0 && !TextUtils.isEmpty(msg)) {
                     showRefreshNewsCount(msg, true);
                     stopRefreshNews();
                     return;
                   }
                 } catch (Exception e) {
                   e.printStackTrace();
                 }
                 startRefreshNews();
               }
             }
           },
           new Response.ErrorListener() {
             @Override
             public void onErrorResponse(VolleyError error) {
               Trace.d(TAG, error.getMessage());
               startRefreshNews();
             }
           });
   if (TextUtils.isEmpty(REFRESH_TAG)) REFRESH_TAG = getUniqueRequestTag();
   req.setHeaders(AppUtils.getOAuthMap(getActivity()));
   req.addHeader("lang", getString(R.string.lang));
   req.setShouldCache(false);
   ApplicationController.getInstance().addToRequestQueue(req, REFRESH_TAG);
 }
Exemple #3
0
 private void stopRefreshNews() {
   mHandler.removeCallbacks(refreshRunnable);
   if (!TextUtils.isEmpty(REFRESH_TAG))
     ApplicationController.getInstance().cancelPendingRequests(REFRESH_TAG);
   REFRESH_TAG = null;
 }