package com.unis.sxzcl.ui.facility.facility_check;

import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.unis.model.DataCallback;
import com.unis.model.FacilityModel;
import com.unis.model.bean.facility_check.FacilityLastBean;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListBinding;

import java.util.List;

/**
 * 最新设施检查记录
 * 创建人: mQ
 * 创建时间: 2021/3/23 16:44
 */
public class FacilityCheckLastFragment extends BaseListFragment<FragmentBaseListBinding> implements FacilityCheckLastAdapter.Callback {

    private FacilityCheckLastAdapter mAdapter;

    @Override
    public void onRefreshData() {
        getData();
    }

    @Override
    protected FragmentBaseListBinding getViewBinding(LayoutInflater inflater, ViewGroup container) {
        return FragmentBaseListBinding.inflate(inflater, container, false);
    }

    @Override
    protected void init() {
        mAdapter = new FacilityCheckLastAdapter();
        mAdapter.setCallback(this);
        initBaseListView(mBinding.refreshLayout, mBinding.recyclerView, mAdapter, false);
    }

    @Override
    protected void onFirstShow() {
        onRefresh();
    }

    /**
     * 获取最新设施检查记录
     */
    private void getData() {
        FacilityModel.get().getLastCheck(new DataCallback<List<FacilityLastBean>>() {
            @Override
            public void onSuccess(List<FacilityLastBean> data) {
                mAdapter.setList(data);
                loadComplete();
            }

            @Override
            public void onError(String error) {
                super.onError(error);
                loadError();
            }
        });
    }

    @Override
    public void onItemClickListener(FacilityLastBean item) {

    }
}
