package com.unis.sxzcl.ui.person;

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

import androidx.fragment.app.Fragment;

import com.unis.sxzcl.base.BaseFragment;
import com.unis.sxzcl.databinding.FragmentBaseTabPagerBinding;
import com.unis.sxzcl.ui.person.person_work.PersonWorkListFragment;
import com.unis.sxzcl.widget.TabFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 包名: com.unis.sxzcl.ui.person
 * 类名: PersonHomeFragment
 * 作用描述:
 * 创建人: mQ
 * 创建时间: 2020/12/2 10:32
 * 更新人:
 * 更新时间: 2020/12/2 10:32
 * 更新说明:
 * 版本号: 1.0
 */
public class PersonHomeFragment extends BaseFragment<FragmentBaseTabPagerBinding> {

    private List<String> mTabs = Arrays.asList("个人信息", "作业记录");
    private List<Fragment> mFragments;
    private String mData;

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

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

        mBinding.bar.setLeftClickListener(v -> onBack());
        mBinding.bar.setTitle("个人信息");

        initFragment();
        mBinding.tabLayout.setupWithViewPager(mBinding.viewPager);
        TabFragmentPagerAdapter adapter = new TabFragmentPagerAdapter(
                getChildFragmentManager(), mTabs, mFragments);
        mBinding.viewPager.setAdapter(adapter);
        mBinding.viewPager.setOffscreenPageLimit(mFragments.size());
    }

    private void initFragment() {
        mFragments = new ArrayList<>();
        mFragments.add(PersonInfoFragment.newFragment(mData));
        mFragments.add(PersonWorkListFragment.newFragment(mData));
    }

    @Override
    protected void onFirstShow() {

    }
}
