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
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mView = inflater.inflate(R.layout.fragment_latest, container, false);
    mContext = getActivity();
    mActivity = getActivity();
    initializeViews();
    MainActivity.tabs.setVisibility(View.VISIBLE);
    MainActivity.layout_user_profle.setVisibility(View.GONE);
    if (NetworkUtils.isOnline(getActivity())) {
      mDialog =
          Utils.showSweetProgressDialog(
              getActivity(),
              getResources().getString(R.string.progress_loading),
              SweetAlertDialog.PROGRESS_TYPE);
      mDialog.setCancelable(true);
      getLatestFeeds();
    } else {
      Utils.showSweetProgressDialog(
          getActivity(),
          getActivity().getResources().getString(R.string.check_your_internet_connection),
          SweetAlertDialog.WARNING_TYPE);
    }

    list_latest_feeds.setHasFixedSize(true);
    list_latest_feeds.setLayoutManager(new LinearLayoutManager(getActivity()));
    mLatestFeedsAdapter = new LatestFeedsAdapter(getActivity(), latestFeedList, list_latest_feeds);
    list_latest_feeds.setAdapter(mLatestFeedsAdapter);

    mLatestFeedsAdapter.setOnLoadMoreListener(
        new OnLoadMoreListener() {
          @Override
          public void onLoadMore() {
            if (hasMoreItems) {
              latestFeedList.add(null);
              if (latestFeedList.size() >= 10) {
                mLatestFeedsAdapter.notifyItemInserted(latestFeedList.size() - 1);
                refreshItems();
              }

            } else {
            }
          }
        });
    return mView;
  }
Exemplo n.º 3
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.º 4
0
 /** This method is used to Update the UI with Feeds */
 private void updateUI() {
   mLatestFeedsAdapter.notifyDataSetChanged();
 }