package com.itant.shiwushu.manager;

import android.content.Context;
import android.widget.Toast;

import com.itant.shiwushu.LAFApplication;


/**
 * Created by Jason on 2018/8/31.
 */

public class ToastManager {

    private static ToastManager manager;
    private long lastShortToastMillis = 0;

    private ToastManager() {

    }

    public static ToastManager getInstance() {
        if (manager == null) {
            init();
        }
        return manager;
    }

    private static synchronized void init() {
        if (manager == null) {
            manager = new ToastManager();
        }
    }

    /**
     * 不要频繁Toast
     * @param message 内容
     */
    public void toastShort(String message) {
        if (System.currentTimeMillis() - lastShortToastMillis > 2000) {
            Toast.makeText(LAFApplication.instance.getApplicationContext(), message, Toast.LENGTH_SHORT).show();
            //toast.setText(message);
            //toast.show();
        }
        lastShortToastMillis = System.currentTimeMillis();
    }

    public void toastShort(String message, Context context) {
        if (System.currentTimeMillis() - lastShortToastMillis > 2000) {
            Toast toast = Toast.makeText(context, null, Toast.LENGTH_SHORT);
            toast.setText(message);
            toast.show();
        }
        lastShortToastMillis = System.currentTimeMillis();
    }
}
