package com.example.administrator.zhapp.activity.sbxdjgl;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import com.example.administrator.zhapp.DBModel.DjjhRwQy;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.BaseActivity;
import com.example.administrator.zhapp.adapter.DlbAdapter;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.entity.DlbInfo;
import java.util.ArrayList;
import java.util.List;


public class YulActivity extends BaseActivity {

    ListView lv;

    private boolean isEdit = true;
    private int item;
    private ArrayList<DjjhRwQy> djjhs;

    private View headView;
    private DlbAdapter adapter;

    @Override
    public int getContentViewID() {
        return R.layout.activity_yul;
    }

    @Override
    protected void initView() {
        lv = findViewById(R.id.lv);
        setBack();
        setTitle("浏览点检记录");
    }

    @Override
    public void initData() {

        Bundle bundle = getIntent().getExtras();
        isEdit = bundle.getBoolean("edit");
        djjhs = bundle.getParcelableArrayList(Contans.KEY_DJJHRWQY);
        item = bundle.getInt(Contans.KEY_ITEM);
        headView = View.inflate(context, R.layout.dlb_item, null);
        headView.findViewById(R.id.head).setVisibility(View.VISIBLE);
        setListAdapter();
    }

    private void setListAdapter() {

        List<DlbInfo> infos = new ArrayList<>();

        for (DjjhRwQy rw : djjhs) {
            DlbInfo info = new DlbInfo();
            info.setCjjg(rw.getCJJG());
            info.setDian(rw.getPOINTNAME() + "(" + rw.getDESCRIPTION() + ")");
            info.setStatu(rw.isChecked());
            infos.add(info);
        }

        adapter = new DlbAdapter(context, infos);
        lv.addHeaderView(headView, null, false);
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(YulActivity.this, ScjsjActivity.class);
                Bundle bundle = new Bundle();
                bundle.putParcelableArrayList(Contans.KEY_DJJHRWQY, djjhs);
                bundle.putBoolean("edit", true);
                bundle.putInt(Contans.KEY_ITEM, position-1);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
    }
}
