package com.ez.ertc.call.ui.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ProgressBar;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;


import com.ez.basertc.view.VideoCanvasView;
import com.ez.ertc.R;

public class EzmTextureView extends FrameLayout{
    public static final int PERIOD_DEFAULT = 1000;//1秒取不到视频流显示loading
    public static final int PERIOD_SHARE_DESKTOP = 3000;//共享时3秒取不到视频流显示loading
    private VideoCanvasView videoCanvasView;
    private WaterMarkView waterMarkView;
    private ProgressBar progressBar;

    public EzmTextureView(@NonNull Context context) {
        super(context);
        init(context);
    }

    public EzmTextureView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public EzmTextureView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public EzmTextureView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    private void init(Context context){
        View view = View.inflate(getContext(), R.layout.ezm_layout_texture_view,this);
        videoCanvasView = view.findViewById(R.id.videoCanvasView);
        waterMarkView = view.findViewById(R.id.waterMarkView);
        progressBar = view.findViewById(R.id.progressBar);
    }

    public void setWaterMark(String nickname,String phone){
        waterMarkView.setWaterMark(nickname,phone);
    }
    public void showWaterMark(boolean show){
        waterMarkView.setVisibility(show ? VISIBLE : GONE);
    }

    public void setWaterMarkSize(int value){
        waterMarkView.setWaterMarkSize(value);
    }

    public void hideProgress() {
        progressBar.setVisibility(GONE);
    }
    public void showProgress() {
        progressBar.setVisibility(VISIBLE);
    }
    public VideoCanvasView getVideoCanvasView() {
        return videoCanvasView;
    }

}
