package com.lovejjfg.swiperefreshrecycleview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.support.v7.widget.helper.ItemTouchHelper;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;

import com.lovejjfg.powerrecycle.AdapterLoader;
import com.lovejjfg.powerrecycle.SelectRefreshRecycleAdapter;
import com.lovejjfg.powerrecycle.SwipeRefreshRecycleView;
import com.lovejjfg.powerrecycle.TouchHelperCallback;
import com.lovejjfg.swiperefreshrecycleview.model.TestBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity implements SwipeRefreshRecycleView.OnRefreshLoadMoreListener {

    @Bind(R.id.recycle_view)
    SwipeRefreshRecycleView mRecycleView;
    @Bind(R.id.toolbar)
    Toolbar mToolBar;
    private SelectRefreshRecycleAdapter<TestBean> adapter;

    private List<TestBean> list;
    private Runnable refreshAction;
    private Runnable loadMoreAction;
    private boolean isRun;
    private boolean enable = true;
    private static final int DEFAULT_TIME = 5000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        setSupportActionBar(mToolBar);
        adapter = new MyRecycleAdapter();
        adapter.setOnItemSelectListener(new AdapterLoader.OnItemSelectedListener() {
            @Override
            public void onItemSelected(View view, int position, boolean isSelected) {
                Log.e("TAG", "onItemSelected: " + position + "::" + isSelected);
            }

            @Override
            public void onNothingSelected() {
                Log.e("TAG", "onNothingSelected: ");
            }
        });
//        HashSet<TestBean> selectedBeans = adapter.getSelectedBeans();
        mRecycleView.setLayoutManager(new LinearLayoutManager(this));
        mRecycleView.setAdapter(adapter);
        mRecycleView.setOnRefreshListener(this);
        //初始化一个TouchHelperCallback
//        TouchHelperCallback callback = new TouchHelperCallback();
        //添加一个回调
//        callback.setItemDragSwipeCallBack(adapter);
        //初始化一个ItemTouchHelper
//        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
        //关联相关的RecycleView
//        itemTouchHelper.attachToRecyclerView(mRecycleView.getRecycle());

        adapter.setLoadMoreListener(this);
        adapter.setTotalCount(10);
        list = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            list.add(new TestBean("这是" + i));
        }
        refreshAction = new Runnable() {
            @Override
            public void run() {
                adapter.setList(list);
                mRecycleView.setRefresh(false);
            }
        };

        loadMoreAction = new Runnable() {
            @Override
            public void run() {
                int i = ((int) (Math.random() * 10)) % 3;
                if (i == 0 || i == 1) {
                    ArrayList<TestBean> arrayList = new ArrayList<>();
                    arrayList.add(new TestBean("ccc1"));
                    arrayList.add(new TestBean("ccc2"));
                    arrayList.add(new TestBean("ccc3"));
                    arrayList.add(new TestBean("ccc4"));
                    arrayList.add(new TestBean("ccc5"));
                    adapter.appendList(arrayList);
                    Log.e("TAG", "run: 正常加载更多！！");
                } else {
                    adapter.loadMoreError();
                    Log.e("TAG", "run: 加载失败！！！");
                }
                isRun = false;
            }
        };
        mRecycleView.setRefresh(true);
        mRecycleView.postDelayed(refreshAction, DEFAULT_TIME);

    }

    @Override
    public void onRefresh() {
        mRecycleView.postDelayed(refreshAction, DEFAULT_TIME);

    }

    @Override
    public void onLoadMore() {
        if (isRun) {
            return;
        }
        Log.e("TAG", "onLoadMore: ");
        isRun = true;
        mRecycleView.postDelayed(loadMoreAction, DEFAULT_TIME);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.test, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.load_more:
                adapter.setTotalCount(100);
                break;
            case R.id.own:
//                adapter.setLoadMoreView(LayoutInflater.from(this).inflate(R.layout.recycler_footer_new, mRecycleView, false));
                break;
            case R.id.pull_refresh:
                enable = !enable;
                mRecycleView.setPullRefreshEnable(enable);
                break;
            case R.id.select_single:
                adapter.setSelectedMode(AdapterLoader.SingleMode);
                adapter.updateSelectMode(true);

                break;
            case R.id.select_mul:
                adapter.setSelectedMode(AdapterLoader.MultipleMode);
                adapter.updateSelectMode(true);
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onBackPressed() {
        if (adapter.isSelectMode()) {
            adapter.updateSelectMode(false);
            return;
        }
        super.onBackPressed();
    }
}

@@ -340,16 +340,52 @@
 il.Log;%0A
+import android.view.LayoutInflater;%0A
 import a
@@ -2110,26 +2110,24 @@
     %7D);%0A
-//
         
 HashSet%3C
@@ -2122,67 +2122,251 @@
     
-HashSet%3CTestBean%3E selectedBeans = adapter.getSelectedBeans(
+adapter.setOnItemClickListener(new AdapterLoader.OnItemClickListener() %7B%0A            @Override%0A            public void onItemClick(View itemView, int position) %7B%0A                Log.e(%22TAG%22, %22onItemClick: %22 + position);%0A            %7D%0A        %7D
 );%0A 
@@ -4873,24 +4873,47 @@
 ItemId()) %7B%0A
+            //loadMore%0A
             
@@ -4992,32 +4992,155 @@
          break;%0A
+            //yourself LoadMoreView you must impl onBottomViewHolderCreate() and onBottomViewHolderBind() in your adapter!%0A
             case
@@ -5150,18 +5150,16 @@
 id.own:%0A
-//
         
@@ -5292,32 +5292,65 @@
          break;%0A
+            //enable pullRefresh%0A
             case
@@ -5477,32 +5477,63 @@
          break;%0A
+            //singleChoiceMode%0A
             case
@@ -5668,17 +5668,16 @@
 (true);%0A
-%0A
         
@@ -5683,32 +5683,65 @@
          break;%0A
+            //multipleChoiceMode%0A
             case

add some annotation.