package com.daya.live_teaching.ui.fragmnet;


import android.view.View;

import com.cooleshow.base.ui.fragment.BaseFragment;
import com.daya.live_teaching.databinding.FragmentClassMemberListBinding;
import com.daya.live_teaching.ui.adapter.FixPagerAdapter;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

/**
 * A simple {@link Fragment} subclass.
 * 网络教室 - 成员列表
 */
public class MemberListFragment extends BaseFragment<FragmentClassMemberListBinding> {


    TabLayout tabLayout;
    ViewPager viewpager;
    private ArrayList<Fragment>      fragments = new ArrayList<>();
    private String[]                 titles    = new String[]{"   在线成员   ", "  未进入成员  "};
    private NotOnlineMembersFragment notOnlineMembersFragment;

    @Override
    protected FragmentClassMemberListBinding getLayoutView() {
        return FragmentClassMemberListBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void initView(View rootView) {
        tabLayout= mViewBinding.tab;
        viewpager=mViewBinding.vpContent;
        fragments.add(new OnlineMembersFragment());
        tabLayout.addTab(tabLayout.newTab());
        notOnlineMembersFragment = new NotOnlineMembersFragment();
        fragments.add(notOnlineMembersFragment);
        tabLayout.addTab(tabLayout.newTab());
        FixPagerAdapter adapter = new FixPagerAdapter(getChildFragmentManager(), titles, fragments);
        viewpager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewpager, false);
        viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 1) {
                    notOnlineMembersFragment.queryNoJoinStu();
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected void initData() {

    }


}
