package com.marshalchen.common.demoofui.superlistview;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.marshalchen.common.demoofui.R;
import com.marshalchen.common.uiModule.superlistview.OnMoreListener;
import com.marshalchen.common.uiModule.superlistview.SuperListview;
import com.marshalchen.common.uiModule.superlistview.SwipeDismissListViewTouchListener;


import java.util.ArrayList;


public class ListSample extends Activity implements SwipeRefreshLayout.OnRefreshListener, OnMoreListener {

    private SuperListview mList;
    private ArrayAdapter<String> mAdapter;

    @SuppressWarnings("ResourceAsColor")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.super_list_view_activity_list_sample);

        // Empty list view demo, just pull to add more items
        ArrayList<String> lst = new ArrayList<String>();
        mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1, lst);


        // This is what you're looking for
        mList = (SuperListview) findViewById(R.id.list);

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        mAdapter.add("More stuff1");
                        mAdapter.add("More stuff2");
                        mAdapter.add("More stuff3");
                        mAdapter.add("More stuff4");
                        mAdapter.add("More stuff5");
                        mAdapter.add("More stuff6");
                        mAdapter.add("More stuff7");


                        mList.setAdapter(mAdapter);

                    }
                });
            }
        });
        thread.start();

        // Setting the refresh listener will enable the refresh progressbar
        mList.setRefreshListener(this);

        // Wow so beautiful
        mList.setRefreshingColor(android.R.color.holo_orange_light, android.R.color.holo_blue_light, android.R.color.holo_green_light, android.R.color.holo_red_light);

        // I want to get loadMore triggered if I see the last item (1)
        mList.setupMoreListener(this, 1);

        mList.setupSwipeToDismiss(new SwipeDismissListViewTouchListener.DismissCallbacks() {
            @Override
            public boolean canDismiss(int position) {
                return true;
            }

            @Override
            public void onDismiss(ListView listView, int[] reverseSortedPositions) {
            }
        }, true);
    }

    @Override
    public void onRefresh() {
        Toast.makeText(this, "Refresh", Toast.LENGTH_LONG).show();

        // enjoy the beaty of the progressbar
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            public void run() {

                // demo purpose, adding to the top so you can see it
                mAdapter.insert("New stuff", 0);

            }
        }, 200);


    }

    @Override
    public void onMoreAsked(int numberOfItems, int numberBeforeMore, int currentItemPos) {

        Toast.makeText(this, "More", Toast.LENGTH_LONG).show();

        //demo purpose, adding to the bottom
        mAdapter.add("More asked, more served");
    }
}

@@ -281,16 +281,73 @@
 .Toast;%0A
+import com.marshalchen.common.commonUtils.logUtils.Logs;%0A
 import c
@@ -1545,17 +1545,17 @@
 d.sleep(
-2
+1
 000);%0A  
@@ -2151,16 +2151,122 @@
 uff7%22);%0A
+                        mAdapter.add(%22More stuff8%22);%0A                        mAdapter.add(%22More stuff9%22);%0A
 %0A%0A      
@@ -2832,13 +2832,15 @@
 is, 
-1
+8
 );%0A%0A
+//
     
@@ -2924,24 +2924,26 @@
 llbacks() %7B%0A
+//
             
@@ -2944,32 +2944,34 @@
       @Override%0A
+//
             publ
@@ -3004,24 +3004,26 @@
 position) %7B%0A
+//
             
@@ -3039,16 +3039,18 @@
 n true;%0A
+//
         
@@ -3047,33 +3047,37 @@
 //            %7D%0A
-%0A
+//%0A//
             @Ove
@@ -3074,32 +3074,34 @@
       @Override%0A
+//
             publ
@@ -3165,24 +3165,26 @@
 ositions) %7B%0A
+//
             
@@ -3177,32 +3177,34 @@
 //            %7D%0A
+//
         %7D, true)
@@ -3636,16 +3636,17 @@
   %7D, 200
+0
 );%0A%0A%0A   
@@ -3797,36 +3797,37 @@
 %22, Toast.LENGTH_
-LONG
+SHORT
 ).show();%0A%0A     
@@ -3812,33 +3812,32 @@
 _SHORT).show();%0A
-%0A
         //demo p
@@ -3877,48 +3877,413 @@
     
-mAdapter.add(%22More asked, more served%22);
+Logs.d(%22more-----%22);%0A        Handler handler = new Handler();%0A        handler.postDelayed(new Runnable() %7B%0A            public void run() %7B%0A                Logs.d(%22more----%22);%0A%0A                // demo purpose, adding to the top so you can see it%0A                mAdapter.add(%22More asked, more served%22 + System.currentTimeMillis());%0A                mList.hideMoreProgress();%0A            %7D%0A        %7D, 2000);%0A
 %0A   

add AbstractSwipeRefreshLoadMoreActivity