package com.cooleshow.student.widgets;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.cooleshow.base.common.BaseApplication;
import com.cooleshow.base.common.WebConstants;
import com.cooleshow.base.router.RouterPath;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.student.R;
import com.cooleshow.student.bean.AppHomeBean;
import com.cooleshow.usercenter.utils.SavePicUtil;
import com.daya.live_teaching.utils.ToastUtils;

/**
 * 创建日期：2022/5/30 10:08
 *
 * @author Ryan
 * 类说明：
 */
public class DialogUtils {
    public interface ActionDialogCallback {
        /**
         * Called when left Button is click
         */
        void onConfirmClick();

        /**
         * Called when left Button is click
         */
        void onCancelClick();

    }

    public static void showHomeDialog(Context context, AppHomeBean.ItemBean data) {
        LinearLayout.LayoutParams pm = new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.Dialog);
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.dialog_home_dialog, null);//这里的R.layout.alertdialog即为你自定义的布局文件
        ImageView im_pic = view.findViewById(R.id.im_pic);
        GlideUtils.INSTANCE.loadImage(context, data.coverImage, im_pic);
        ImageView im_close = view.findViewById(R.id.im_close);

        final AlertDialog mAlertDialog = builder.create();
        mAlertDialog.getWindow().setBackgroundDrawableResource(com.cooleshow.base.R.color.transparent);
        mAlertDialog.setCanceledOnTouchOutside(true);
        mAlertDialog.setCancelable(true);
        mAlertDialog.show();
        mAlertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        mAlertDialog.getWindow().setContentView(view, pm);

        im_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mAlertDialog.dismiss();
            }
        });
        im_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!TextUtils.isEmpty(data.linkUrl)){
                    ARouter.getInstance()
                            .build(RouterPath.WebCenter.ACTIVITY_HTML)
                            .withString(WebConstants.WEB_URL, data.linkUrl)
                            .navigation();
                }

                mAlertDialog.dismiss();
            }
        });
    }
}
