package com.cooleshow.teacher.widgets;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.cooleshow.base.widgets.QMUIRadiusImageView;
import com.cooleshow.teacher.R;

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

/**
 * Author by pq, Date on 2022/4/27.
 */
public class HomeworkVideoThumbnailView extends FrameLayout {

    private QMUIRadiusImageView mIvBg;

    public HomeworkVideoThumbnailView(@NonNull Context context) {
        this(context, null);
    }

    public HomeworkVideoThumbnailView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, -1);
    }

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

    private void init() {
        LayoutInflater.from(getContext()).inflate(R.layout.view_homework_video_thumbnail_layout, this);
        mIvBg = findViewById(R.id.iv_bg);
    }

    public void setData(String videoUrl) {
        Glide.with(getContext())
                .setDefaultRequestOptions(
                        new RequestOptions()
                                .frame(0)
                                .centerCrop()
                                .error(com.cooleshow.base.R.drawable.bg_video_placeholder)
                                .placeholder(com.cooleshow.base.R.drawable.bg_video_placeholder)
                )
                .load(videoUrl)
                .into(mIvBg);
    }
}
