package com.all.pdfreader.pro.app.util

import android.content.Context
import android.view.LayoutInflater
import android.widget.TextView
import android.widget.Toast
import com.all.pdfreader.pro.app.R

object ToastUtils {
    private var toast: Toast? = null

    fun show(context: Context, message: String) {
        val inflater = LayoutInflater.from(context.applicationContext)
        val view = inflater.inflate(R.layout.layout_custom_toast, null)
        view.findViewById<TextView>(R.id.toastText).text = message

        toast?.cancel() // 避免多个 Toast 叠加
        toast = Toast(context.applicationContext).apply {
            duration = Toast.LENGTH_SHORT
            this.view = view
            show()
        }
    }
}
