Exemplo n.º 1
0
 @Override
 public void onDelete(String id, boolean isDelete) {
   if (latestFeedList.size() > 0) {
     for (int i = 0; i < latestFeedList.size(); i++) {
       if (latestFeedList.get(i).getId().equalsIgnoreCase(id)) {
         latestFeedList.remove(i);
         mLatestFeedsAdapter.notifyDataSetChanged();
       }
     }
   }
 }
Exemplo n.º 2
0
  private List<LatestFeedsModel> refreshLatestFeeds(String res) throws JSONException {
    Utils.debug(TAG, "Response of Latest feed Fragment  :  " + res);
    JSONObject jsonObject = new JSONObject(res);
    if (jsonObject != null) {
      if (jsonObject.getBoolean(APIsConstants.KEY_RESULT)) {
        JSONArray jsonArray = jsonObject.getJSONArray(APIsConstants.KEY_FEED_DATA);
        if (jsonArray != null) {
          if (mPageNo == 1) latestFeedList.clear();
          if (mPageNo > 1) {
            if (latestFeedList.size() != 0) {
              latestFeedList.remove(latestFeedList.size() - 1);
              mLatestFeedsAdapter.notifyItemRemoved(latestFeedList.size());
            }
          }
          for (int i = 0; i < jsonArray.length(); i++) {
            LatestFeedsModel latestFeedsModel = new LatestFeedsModel();
            JSONObject object = jsonArray.getJSONObject(i);
            if (object != null) {
              try {
                latestFeedsModel.setId(object.getString(APIsConstants.KEY_ID));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setTitle(object.getString(APIsConstants.KEY_TITLE));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setDescription(object.getString(APIsConstants.KEY_DESCRIPTION));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setMedia(object.getString(APIsConstants.KEY_MEDIA));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setType(object.getString(APIsConstants.KEY_TYPE));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setUser_id(object.getString(APIsConstants.KEY_USER_ID));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setCreated(object.getString(APIsConstants.KEY_CREATED));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setModified(object.getString(APIsConstants.KEY_MODIFIED));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setUser_name(object.getString(APIsConstants.KEY_USER_NAME));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setViewcount(object.getString(APIsConstants.KEY_VIEWCOUNT));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setThumbnail(object.getString(APIsConstants.KEY_THUMBNAIL));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setProfit_amount(
                    object.getString(APIsConstants.KEY_PROFIT_AMOUNT));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              try {
                latestFeedsModel.setFb_feed_id(object.getString(APIsConstants.KEY_FB_FEED_ID));
              } catch (JSONException e) {
                e.printStackTrace();
              }
              if (!latestFeedList.contains(latestFeedsModel)) {
                latestFeedList.add(latestFeedsModel);
              }
            }
          }
          mLatestFeedsAdapter.notifyDataSetChanged();
          mLatestFeedsAdapter.setLoaded();
        }
      } else {

        if (latestFeedList.size() != 0) {
          hasMoreItems = false;
          latestFeedList.remove(latestFeedList.size() - 1);
          mLatestFeedsAdapter.notifyItemRemoved(latestFeedList.size());
          mLatestFeedsAdapter.notifyDataSetChanged();
        }

        try {
          Utils.debug(Constants.API_TAG, jsonObject.getString(APIsConstants.KEY_MESSAGE));
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
    swipeRefreshLayout.setRefreshing(false);
    Utils.closeSweetProgressDialog(getActivity(), mDialog);
    return latestFeedList;
  }
Exemplo n.º 3
0
 /** This method is used to Update the UI with Feeds */
 private void updateUI() {
   mLatestFeedsAdapter.notifyDataSetChanged();
 }