package org.zpcat.madlist;

import org.zpcat.madlist.adapter.SimpleRecyclerAdapter;

import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;

import butterknife.Bind;
import butterknife.ButterKnife;

public class SwipeRefreshActivity extends AppCompatActivity {

    @Bind(R.id.swip_refresh_layout)
    SwipeRefreshLayout mSwipeRefreshLayout;

    @Bind(R.id.recyclerview)
    RecyclerView mRecyclerView;

    private SimpleRecyclerAdapter mSimpleRecyclerAdapter;

    private int mCount = 20;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_swipe_refresh);

        ButterKnife.bind(this);

        mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                Log.e("SwipeRefresh", "onRefresh");
                refreshContent();
            }
        });

        mSimpleRecyclerAdapter = new SimpleRecyclerAdapter();

        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setAdapter(mSimpleRecyclerAdapter);

        for (int i = 0; i < mCount; i++) {
            mSimpleRecyclerAdapter.addText(String.valueOf(i));
        }
    }

    @Override
    protected void onDestroy() {
        ButterKnife.unbind(this);

        super.onDestroy();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_swipe_refresh, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void refreshContent() {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mSimpleRecyclerAdapter.addText(String.valueOf(mCount));
                mSimpleRecyclerAdapter.notifyDataSetChanged();
                mCount++;
                mSwipeRefreshLayout.setRefreshing(false);
            }
        }, 2000);
    }
}

@@ -1293,16 +1293,251 @@
      %7D);
+%0A        mSwipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,%0A                android.R.color.holo_green_dark,%0A                android.R.color.holo_orange_light,%0A                android.R.color.holo_red_light);
 %0A%0A      

add refresh color schemes