package com.unis.sxzcl.ui.depot;

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

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.unis.model.bean.DepotBean;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListTitleBinding;

/**
 * 包名: com.unis.sxzcl.ui.depot
 * 类名: DepotListFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/11/26 9:39
 * 更新人:
 * 更新时间: 2020/11/26 9:39
 * 更新说明:
 * 版本号: 1.0
 */
public class DepotListFragment extends BaseListFragment<FragmentBaseListTitleBinding> implements OnItemClickListener {

    private DepotListAdapter mAdapter;

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

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

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

    @Override
    protected void init() {
        mBinding.bar.setTitle("粮库信息")
                .setLeftClickListener(v -> finish());

        mAdapter = new DepotListAdapter();
        mAdapter.setOnItemClickListener(this);
        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 DepotBean("山西太原直属库有限公司分库1"));
            mAdapter.addData(new DepotBean("山西太原直属库有限公司分库2"));
            mAdapter.addData(new DepotBean("山西太原直属库有限公司分库3"));
            mAdapter.addData(new DepotBean("山西太原直属库有限公司分库4"));
            mAdapter.addData(new DepotBean("山西太原直属库有限公司分库5"));
            loadEnd();
        }, 500);
    }

    @Override
    public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        DepotBean item = mAdapter.getData().get(position);
//        DepotHomeFragment.startPage(getContext(), item.name);
    }
}
