package com.unis.sxzcl.ui.person.person_work;

import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.unis.model.bean.person.PersonWorkBean;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListBinding;

/**
 * 包名: com.unis.sxzcl.ui.person
 * 类名: PersonWorkListFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/2 11:05
 * 更新人:
 * 更新时间: 2020/12/2 11:05
 * 更新说明:
 * 版本号: 1.0
 */
public class PersonWorkListFragment extends BaseListFragment<FragmentBaseListBinding> {

    private PersonWorkListAdapter mAdapter;
    private String mExtra;

    public static PersonWorkListFragment newFragment(String extra) {
        Bundle bundle = new Bundle();
        bundle.putString("extra", extra);
        PersonWorkListFragment fragment = new PersonWorkListFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

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

    @Override
    public void onMoreData() {
        super.onMoreData();
        getData(false);
    }

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

    @Override
    protected void init() {
        Bundle bundle = getArguments();
        mExtra = bundle.getString("extra");

        mAdapter = new PersonWorkListAdapter();
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            // TODO: 2020/12/2 工作记录
        });
        initBaseListView(mBinding.refreshLayout,mBinding.recyclerView,mAdapter,true);
    }

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

    private void getData(boolean refresh) {
        new Handler().postDelayed(() -> {
            if (refresh) {
                mAdapter.getData().clear();
                mAdapter.notifyDataSetChanged();
            }
            mAdapter.addData(new PersonWorkBean("机械通风(1号仓)", "2020-12-01 08:12"));
            mAdapter.addData(new PersonWorkBean("机械通风(2号仓)", "2020-12-02 09:35"));
            mAdapter.addData(new PersonWorkBean("机械通风(3号仓)", "2020-12-03 15:22"));
            mAdapter.addData(new PersonWorkBean("机械通风(4号仓)", "2020-12-04 14:16"));
            mAdapter.addData(new PersonWorkBean("机械通风(5号仓)", "2020-12-04 10:09"));
            loadEnd();
        }, 500);
    }


}
