package com.yidian.common.utils

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import android.widget.Toast
import com.bumptech.glide.Glide
import com.yidian.common.R
import com.yidian.nightmode.widget.YdImageView
import com.yidian.nightmode.widget.YdTextView


class YdToastUtil {
    companion object{
        fun showToast(context: Context, message: String){
            val toastView = LayoutInflater.from(context).inflate(R.layout.toast_layout, null)
            val tvContent = toastView.findViewById<YdTextView>(R.id.tv_content)
            tvContent.text = message
            val toast = Toast(context)
            toast.duration = Toast.LENGTH_SHORT
            toast.view = toastView
            toast.show()
        }

        fun showToast(context: Context, message: String, imageUrl: String){
            val toastView = LayoutInflater.from(context).inflate(R.layout.toast_layout, null)
            val ivIcon = toastView.findViewById<ImageView>(R.id.iv_icon)
            Glide.with(context).load(imageUrl).into(ivIcon)
            ivIcon.visibility = View.VISIBLE
            val tvContent = toastView.findViewById<YdTextView>(R.id.tv_content)
            tvContent.text = message
            val toast = Toast(context)
            toast.duration = Toast.LENGTH_SHORT
            toast.view = toastView
            toast.show()
        }

        fun refreshToast(context: Context, message: String){
            val toastView = LayoutInflater.from(context).inflate(R.layout.refresh_toast_layout, null)
            val tvContent = toastView.findViewById<YdTextView>(R.id.tv_content)
            tvContent.text = message
            val toast = Toast(context)
            toast.duration = Toast.LENGTH_SHORT
            toast.view = toastView
            toast.setGravity(Gravity.CENTER_HORIZONTAL or Gravity.TOP,0,350)
            toast.show()
        }
    }
}