package com.yuqirong.meituanlistview.activity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;

import com.yuqirong.meituanlistview.R;
import com.yuqirong.meituanlistview.adapter.MAdapter;
import com.yuqirong.meituanlistview.view.MeiTuanListView;

public class MainActivity extends AppCompatActivity implements MeiTuanListView.OnRefreshListener {

    private MeiTuanListView mtListView;
    private MAdapter adapter;

    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case 0:
                    adapter.notifyDataSetChanged();
                    mtListView.notifyRefreshFinished();
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mtListView = (MeiTuanListView) findViewById(R.id.mtListView);
        adapter = new MAdapter();
        mtListView.setAdapter(adapter);
        mtListView.setOnRefreshListener(this);
        adapter.getList().add("A");
        adapter.getList().add("B");
        adapter.getList().add("C");
        adapter.getList().add("D");
        adapter.getList().add("E");
        adapter.getList().add("F");
        adapter.getList().add("G");
        adapter.getList().add("H");
        adapter.getList().add("I");
        adapter.getList().add("J");
        adapter.getList().add("K");
        adapter.getList().add("L");
        adapter.getList().add("M");
        adapter.getList().add("N");
        adapter.getList().add("O");
    }

    @Override
    public void refreshing() {
        adapter.getList().add(0,"New Data");
        handler.sendEmptyMessageDelayed(0,3000);
    }

}
