package com.gh.gamecenter.geetest;

import android.webkit.JavascriptInterface;

class GtJSInterface {

    private GtListener mGtListener;

    GtJSInterface() {
    }

    public void setGtListener(GtListener gtListener) {
        mGtListener = gtListener;
    }

    @JavascriptInterface
    public void gtCallBack(String code, String result, String message) {
        final int fCode;
        final String fResult = result;
        try {
            fCode = Integer.parseInt(code);
            if (mGtListener != null) {
                mGtListener.gtResult(fCode == 1, fResult);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }

    }

    @JavascriptInterface
    public void gtCloseWindow() {
        if (mGtListener != null) {
            mGtListener.gtCallClose();
        }
    }

    @JavascriptInterface
    public void gtReady() {
        if (mGtListener != null) {
            mGtListener.gtCallReady(true);
        }
    }

    @JavascriptInterface
    public void gtError() {
        if (mGtListener != null) {
            mGtListener.gtError();
        }
    }

}