package com.uiui.zyappstore.utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import com.uiui.zyappstore.BuildConfig;

/**
 * Created by haoge on 2017/3/2.
 */

public class ToastUtil {
    static Handler mainHandler = new Handler(Looper.getMainLooper());
    static Toast toast;

    @SuppressLint("ShowToast")
    public static void init(Context context) {
        toast = Toast.makeText(context, "", Toast.LENGTH_SHORT);
        debugToast = Toast.makeText(context, "", Toast.LENGTH_SHORT);

    }

    public static void show(final String msg) {
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                if (toast != null) {
                    toast.setText(msg);
                    toast.show();
                }
            }
        });
    }

    //    public static void showInCenter(String msg) {
//        mainHandler.post(() -> {
//            if (toast != null) {
//                toast.setGravity(Gravity.CENTER, 0, 0);
//                toast.setText(msg);
//                toast.show();
//            }
//        });
//    }
    static Handler debugHandler = new Handler(Looper.getMainLooper());
    static Toast debugToast;

    public static void debugShow(final String msg) {
        mainHandler.post(new Runnable() {
            @Override
            public void run() {
                if (BuildConfig.DEBUG) {
                    if (toast != null) {
                        toast.setText(msg);
                        toast.show();
                    }
                }
            }
        });
    }

}
