content: package com.leaf8.alicx.loadmorerecycler;
  
  import android.app.Fragment;
  import android.content.Context;
  import android.os.Bundle;
  import android.support.v4.widget.SwipeRefreshLayout;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.StaggeredGridLayoutManager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import com.leaf8.alicx.loadmorerecycler.dummy.DummyContent;
  
  /**
   * A fragment representing a list of Items.
   * <p/>
   * interface.
   */
  public class ContentListFragment extends Fragment {
  
      private static final String ARG_COLUMN_COUNT = "column-count";
      private int mColumnCount = 1;
      private MyItemRecyclerViewAdapter myItemRecyclerViewAdapter;
      private LoadMoreRecyclerView recyclerView;
      private SwipeRefreshLayout swipeRefreshLayout;
      private int page = 0;
  
      /**
       * Mandatory empty constructor for the fragment manager to instantiate the
       * fragment (e.g. upon screen orientation changes).
       */
      public ContentListFragment() {
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          if (getArguments() != null) {
              mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
          }
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_item_list, container, false);
          recyclerView = (LoadMoreRecyclerView) view.findViewById(R.id.list);
          recyclerView.setHasFixedSize(true);
          view.findViewById(R.id.mode_switch_btn).setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  if (1 == mColumnCount) {
                      mColumnCount = 2;
                      ((TextView) v).setText(R.string.list_mode_stagger);
                      myItemRecyclerViewAdapter.switchMode(true);
                      recyclerView.switchLayoutManager(new StaggeredGridLayoutManager(mColumnCount, StaggeredGridLayoutManager.VERTICAL));
                  } else {
                      mColumnCount = 1;
                      ((TextView) v).setText(R.string.list_mode_list);
                      myItemRecyclerViewAdapter.switchMode(false);
                      recyclerView.switchLayoutManager(new LinearLayoutManager(getActivity()));
                  }
              }
          });
          swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
          swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
              @Override
              public void onRefresh() {
                  swipeRefreshLayout.setRefreshing(false);
                  page = 0;
                  myItemRecyclerViewAdapter.setData(DummyContent.generyData(page));
                  recyclerView.setAutoLoadMoreEnable(DummyContent.hasMore(page));
                  myItemRecyclerViewAdapter.notifyDataSetChanged();
              }
          });
          if (1 >= mColumnCount) {
              recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
          } else {
              recyclerView.setLayoutManager(new StaggeredGridLayoutManager(mColumnCount, StaggeredGridLayoutManager.VERTICAL));
          }
          myItemRecyclerViewAdapter = new MyItemRecyclerViewAdapter(DummyContent.generyData(page));
          recyclerView.setAdapter(myItemRecyclerViewAdapter);
          recyclerView.setAutoLoadMoreEnable(true);
          recyclerView.setLoadMoreListener(new LoadMoreRecyclerView.LoadMoreListener() {
              @Override
              public void onLoadMore() {
                  recyclerView.postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          swipeRefreshLayout.setRefreshing(false);
                          myItemRecyclerViewAdapter.addDatas(DummyContent.generyData(++page));
                          recyclerView.notifyMoreFinish(DummyContent.hasMore(page));
                      }
                  }, 1000);
              }
          });
          myItemRecyclerViewAdapter.notifyDataSetChanged();
          return view;
      }
  
      @Override
      public void onAttach(Context context) {
          super.onAttach(context);
  //        if (context instanceof OnListFragmentInteractionListener) {
  //            mListener = (OnListFragmentInteractionListener) context;
  //        } else {
  //            throw new RuntimeException(context.toString()
  //                    + " must implement OnListFragmentInteractionListener");
  //        }
      }
  
      @Override
      public void onDetach() {
          super.onDetach();
  //        mListener = null;
      }
  
      /**
       * This interface must be implemented by activities that contain this
       * fragment to allow an interaction in this fragment to be communicated
       * to the activity and potentially other fragments contained in that
       * activity.
       * <p/>
       * See the Android Training lesson <a href=
       * "http://developer.android.com/training/basics/fragments/communicating.html"
       * >Communicating with Other Fragments</a> for more information.
       */
  //    public interface OnListFragmentInteractionListener {
  //        // TODO: Update argument type and name
  //        void onListFragmentInteraction(DummyItem item);
  //    }
  }
  