package com.daya.live_teaching.ui.fragmnet;

import android.view.View;
import android.widget.TextView;

import com.cooleshow.base.ui.fragment.BaseFragment;
import com.daya.live_teaching.databinding.FragmentNotOnlineMembersBinding;
import com.daya.live_teaching.model.ClassMember;
import com.daya.live_teaching.ui.adapter.NotOnlineMembersListAdapter;
import com.daya.live_teaching.viewmodel.ClassViewModel;

import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


/**
 * A simple {@link Fragment} subclass.
 */
public class NotOnlineMembersFragment extends BaseFragment<FragmentNotOnlineMembersBinding> {

    RecyclerView recyclerView;
    TextView btnCommit, tv_remove;
    private ClassViewModel classViewModel;
    private NotOnlineMembersListAdapter adapter;

    public NotOnlineMembersFragment() {

    }

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

    @Override
    protected void initView(View rootView) {
        recyclerView = mViewBinding.recyclerView;
        btnCommit = mViewBinding.btnCommit;
        tv_remove = mViewBinding.tvRemove;
        adapter = new NotOnlineMembersListAdapter(getContext());
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
        btnCommit.setVisibility(View.GONE);
        tv_remove.setVisibility(View.GONE);
    }


    @Override
    protected void initData() {
        classViewModel = ViewModelProviders.of(getActivity()).get(ClassViewModel.class);
        classViewModel.getQueryNoJoinStu().observe(getActivity(), new Observer<List<ClassMember>>() {
            @Override
            public void onChanged(List<ClassMember> classMembers) {
                if (null != classMembers) {
                    adapter.setData(classMembers);
                }
            }
        });

    }

    public void queryNoJoinStu() {
        classViewModel.queryNoJoinStu(classViewModel.getRoomId().getValue()).observe(this, requestState -> {
        });
    }

}
