package com.zhongqu.vrviewer.demojava;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.tencent.smtt.sdk.WebView;
import com.zhongqu.vrviewer.demojava.BuildConfig;
import com.zhongqu.vrviewer.ZQVRViewerManager;
import com.zhongqu.vrviewer.x5host.TbsBootstrap;

public class MainActivity extends BaseViewerActivity {

    /**
     * 以 {@link TbsBootstrap#isCoreReady} 为准；Debug 包在 TBS 未就绪时仍允许进带看（便于调 H5，真机可能非
     * X5/异常）。
     */
    @Override
    protected boolean isViewerWebViewAllowed() {
        return TbsBootstrap.isCoreReady() || BuildConfig.DEBUG;
    }

    @Override
    protected void onKernelBannerReady(TextView kernelBanner) {
        X5KernelVerification.scheduleBannerRefresh(
                this, kernelBanner, kernelBanner.getText().toString());
    }

    @Override
    protected View createViewerWebView(Context context) {
        return new WebView(context);
    }

    @Override
    protected void configureViewerWebView(View webView) {
        WebView wv = (WebView) webView;
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        wv.getSettings().setDomStorageEnabled(true);
        X5KernelVerification.registerHostWebView(wv);
    }

    @Override
    protected void onAfterViewerUrlLoaded(View webView, String url) {
        X5KernelVerification.onHostLoadUrlCompletedLikePublicDemo(this, (WebView) webView);
    }

    @Override
    protected void openViewerSdk(View webView) {
        ZQVRViewerManager.openViewer((WebView) webView);
    }

    @Override
    protected void loadUrlOnViewer(View webView, String url) {
        ((WebView) webView).loadUrl(url);
    }
}
