package com.secspace.lib.common.tips;

import android.content.Context;
import android.os.HandlerThread;

/*
 * Create by Colbert on 2019-05-08
 *
 * Copyright (C) 2019 chuanzhigo@gmail.com.
 */
public class TipHelper {

    private static final TipHelper INST = new TipHelper();

    private TipHandler mTipHandler;

    public static TipHelper get() {
        return INST;
    }

    private TipHelper() {
    }

    private void createHandler() {
        HandlerThread handlerThread = new HandlerThread("tip");
        handlerThread.start();
        mTipHandler = new TipHandler(handlerThread.getLooper());
    }

    public synchronized void showTip(Context context, String message, int timeout) {
        if (mTipHandler == null) {
            createHandler();
        }
        if (mTipHandler != null) {
            if (!mTipHandler.showTip(context, message, timeout)) {
                createHandler();
                mTipHandler.showTip(context, message, timeout);
            }
        }
    }

    public void showTip(Context context, String message) {
        showTip(context, message, 60*1000);
    }

    public void hideTip() {
        if (mTipHandler != null) {
            mTipHandler.hideTip();
        }
    }
    public void hideTip(long delaymillis) {
        if (mTipHandler != null) {
            mTipHandler.hideTip(delaymillis);
        }
    }
}
