package com.example.administrator.zhapp.fragment.xfbwxcgl;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import com.example.administrator.zhapp.BaseListViewAdapter.CommonAdapter;
import com.example.administrator.zhapp.BaseListViewAdapter.ViewHolder;
import com.example.administrator.zhapp.DBModel.XfDjjhRwqy;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.xfbwxcgl.XfhmAqckdDetaliActivity;
import com.example.administrator.zhapp.fragment.BaseFragment;
import java.util.ArrayList;


/**
 * 消防保卫巡查管理-防火门及安全出口
 */
public class FhmAqckFragment extends BaseFragment {

    ListView lv;

    private View headView;

    private ArrayList<XfDjjhRwqy> list;

    /**
     * 万能适配器
     */
    private CommonAdapter<XfDjjhRwqy> mAdapter;

    public FhmAqckFragment() {
    }

    public static FhmAqckFragment newInstance(ArrayList<XfDjjhRwqy> list) {
        FhmAqckFragment fragment = new FhmAqckFragment();
        Bundle args = new Bundle();
        args.putParcelableArrayList("list", list);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            list = new ArrayList<>();
            list = getArguments().getParcelableArrayList("list");
        }
    }

    @Override
    public int getContentViewId() {
        return R.layout.fragment_fhm_aqck;
    }

    @Override
    protected void initView() {
        lv = (ListView) view.findViewById(R.id.lv);
        headView = View.inflate(getContext(), R.layout.xfxc_item, null);
        headView.findViewById(R.id.head).setVisibility(View.VISIBLE);
        TextView bh = (TextView) headView.findViewById(R.id.tv_bh);
        bh.setText("区域");
        TextView bw = (TextView) headView.findViewById(R.id.tv_bw);
        bw.setText("地点");
    }

    public void initData() {


        mAdapter = new CommonAdapter<XfDjjhRwqy>(getContext(), R.layout.xfxc_item, list) {
            @Override
            protected void convert(ViewHolder viewHolder, XfDjjhRwqy item, int position) {
                viewHolder.setText(R.id.tv_xh, position + 1 + "");
                viewHolder.setText(R.id.tv_bh, item.getBH());
                viewHolder.setText(R.id.tv_bw, item.getXFWZ());
                String str = "";
                if (item.isChecked()) {
                    str = "已检";
                } else {
                    str = "未检";
                }
                viewHolder.setText(R.id.tv_zt, str);
            }
        };

        lv.addHeaderView(headView, null, false);
        lv.setAdapter(mAdapter);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(getActivity(), XfhmAqckdDetaliActivity.class);
                intent.putParcelableArrayListExtra("list", list);
                intent.putExtra("item", i);
                startActivity(intent);
            }
        });
    }

    public void setListadapter()
    {
        mAdapter.notifyDataSetChanged();
    }
}
