package com.qhclh.ytzh.index.shangpin;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.base.BaseFragment;
import com.qhclh.ytzh.bean.InhouseBean;
import com.qhclh.ytzh.ui.RefreshLayout;

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

import butterknife.BindView;

/**
 * Created by 青花瓷 on 2017/12/28.
 */

public class InHouseAllFragment extends BaseFragment implements RefreshLayout.OnLoadListener, SwipeRefreshLayout.OnRefreshListener {
    @BindView(R.id.lv_inhouseall)
    ListView lv_inhouseall;
    @BindView(R.id.rfl_inhouseall)
    RefreshLayout rfl_inhouseall;
    private int page =0;

    private List<InhouseBean> mList;
    private InHouseAdapter mAdapter;

    @Override
    protected int setLayout() {
        return R.layout.frag_inhouse_all;
    }

    @Override
    protected void initView() {
        rfl_inhouseall.setEnabled(false);
    }

    @Override
    protected void initData() {
        mList = new ArrayList<>();
    }

    @Override
    protected void initOper() {
        rfl_inhouseall.setOnLoadListener(this);
        rfl_inhouseall.setOnRefreshListener(this);
        lv_inhouseall.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                startActivity(new Intent(getActivity(),InHouseInfoActivity.class));
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        mList.clear();
        for (int i=0;i<5;i++){
            mList.add(new InhouseBean(i,""+i,""+i,"2017/08/09","已审核"));
        }

        mAdapter = new InHouseAdapter(getActivity(),mList);
        lv_inhouseall.setAdapter(mAdapter);
    }

    @Override
    public void onLoad() {
        rfl_inhouseall.postDelayed(new Runnable() {
            @Override
            public void run() {
                rfl_inhouseall.setLoading(false);
                for (int i=0;i<5;i++){
                    mList.add(new InhouseBean(i,""+i,""+i,"2017/08/09","已审核"));
                }
                mAdapter.notifyDataSetChanged();
            }
        },1000);
    }

    @Override
    public void onRefresh() {
        rfl_inhouseall.setRefreshing(false);
    }
}
