package cn.tee3.demo.View;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

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

import cn.tee3.demo.R;
import cn.tee3.manager.view.T3VideoView;

public class VideoFragment extends Fragment {

    public static final int VIDEO_VIEW_COUNT = 4;

    private View view;
    private List<T3VideoView> videoViewList;
    private OnFragmentCreateViewListener listener;

    public static VideoFragment build() {
        return new VideoFragment();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.video_fragment, container, false);
        initVideoViewList();
        if (listener != null) {
            listener.onFragmentCreateView(videoViewList, this);
        }
        return view;
    }

    public void setCurrentPage(int index) {
        if (view != null) {
            ((TextView)view.findViewById(R.id.tv_page)).setText((index + 1) + "/2");
        }
    }

    public void initVideoViewList() {
        if (videoViewList == null) {
            videoViewList = new ArrayList<>();
            videoViewList.add((T3VideoView) view.findViewById(R.id.video_01));
            videoViewList.add((T3VideoView) view.findViewById(R.id.video_02));
            videoViewList.add((T3VideoView) view.findViewById(R.id.video_03));
            videoViewList.add((T3VideoView) view.findViewById(R.id.video_04));
        }
    }

    public void addOnCreateViewListener(OnFragmentCreateViewListener listener) {
        this.listener = listener;
    }

    public interface OnFragmentCreateViewListener {
        void onFragmentCreateView(List<T3VideoView> videoViewList, VideoFragment videoFragment);
    }
}
