package com.unis.sxzcl.ui.user;

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

import com.unis.model.DataCallback;
import com.unis.model.VersionModel;
import com.unis.model.bean.VersionBean;
import com.unis.sxzcl.base.BaseListFragment;
import com.unis.sxzcl.databinding.FragmentBaseListTitleBinding;

import java.util.List;

/**
 * 版本记录
 * 创建人: mQ
 * 创建时间: 2021/1/12 9:48
 */
public class VersionRecordFragment extends BaseListFragment<FragmentBaseListTitleBinding> {

    private VersionRecordAdapter mAdapter;

    @Override
    public void onRefreshData() {
        VersionModel.get().getVersionInfo(new DataCallback<List<VersionBean>>() {
            @Override
            public void onSuccess(List<VersionBean> data) {
                if (!isActive()) return;
                mAdapter.setList(data);
                loadComplete();
            }

            @Override
            public void onError(String error) {
                super.onError(error);
                if (!isActive()) return;
                loadError();
            }
        });
    }

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

    @Override
    protected void init() {
        mBinding.bar.setTitle("版本记录")
                .setLeftClickListener(v -> onBack());

        mAdapter = new VersionRecordAdapter();
        initBaseListView(mBinding.refreshLayout, mBinding.recyclerView, mAdapter, false);
    }

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