package com.example.myapplication.Tool;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.widget.Toast;

public class BackgroundToast {
    private static Handler handler;
    private static Toast currentToast;
    private static long lastShowTime = 0;

    public static void show(final Context context, final String message) {
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }

        long currentTime = System.currentTimeMillis();


        handler.post(() -> {
            if (currentToast != null) {
                currentToast.cancel();
            }

            currentToast = Toast.makeText(context.getApplicationContext(), message, Toast.LENGTH_LONG);
            currentToast.setGravity(Gravity.CENTER, 0, 0);
            currentToast.show();
            lastShowTime = currentTime;
        });
    }
}