package com.just.library;

import android.app.Activity;
import android.webkit.WebView;

/**
 * Created by cenxiaozhong on 2017/12/6.
 * 该类统一控制了与用户交互的一些界面
 */
public abstract class AgentWebUIController {

    public static boolean hasDesignLib = false;
    private Activity mActivity;
    private WebParentLayout mWebParentLayout;
    private volatile boolean isBindWebParent = false;
    protected AgentWebUIController mAgentWebUIControllerDelegate;
    protected String TAG = this.getClass().getSimpleName();

    static {
        try {
            Class.forName("android.support.design.widget.Snackbar");
            hasDesignLib = true;
        } catch (Throwable ignore) {
            hasDesignLib = false;
        }
    }


    protected AgentWebUIController create() {
        return hasDesignLib ? new DefaultDesignUIController() : new DefaultUIController();
    }

    public abstract void onJsAlert(WebView view, String url, String message);


    public abstract void onJsConfirm(WebView view, String url, String message);


    public abstract void onJsPrompt(WebView view, String url, String message, String defaultValue);

    protected AgentWebUIController getDelegate() {
        AgentWebUIController mAgentWebUIController = this.mAgentWebUIControllerDelegate;
        if (mAgentWebUIController == null) {
            this.mAgentWebUIControllerDelegate = mAgentWebUIController = create();
        }
        return mAgentWebUIController;
    }

    synchronized final void bindWebParent(WebParentLayout webParentLayout, Activity activity) {

        if (!isBindWebParent) {
            isBindWebParent = true;
            this.mWebParentLayout = webParentLayout;
            this.mActivity = activity;
            getDelegate().bindSupportWebParent(webParentLayout, activity);
        }

    }

    abstract void bindSupportWebParent(WebParentLayout webParentLayout, Activity activity);


}

@@ -49,16 +49,113 @@
 tivity;%0A
+import android.os.Handler;%0Aimport android.webkit.JsPromptResult;%0Aimport android.webkit.JsResult;%0A
 import a
@@ -177,16 +177,16 @@
 ebView;%0A
-
 %0A/**%0A * 
@@ -243,10 +243,8 @@
 %E6%88%B7%E4%BA%A4%E4%BA%92%E7%9A%84
-%E4%B8%80%E4%BA%9B
 %E7%95%8C%E9%9D%A2%0A 
@@ -965,271 +965,8 @@
  %7D%0A%0A
-    public abstract void onJsAlert(WebView view, String url, String message);%0A%0A%0A    public abstract void onJsConfirm(WebView view, String url, String message);%0A%0A%0A    public abstract void onJsPrompt(WebView view, String url, String message, String defaultValue);%0A%0A
     
@@ -1288,16 +1288,22 @@
  %7D%0A%0A    
+final 
 synchron
@@ -1307,22 +1307,16 @@
 ronized 
-final 
 void bin
@@ -1380,17 +1380,16 @@
 vity) %7B%0A
-%0A
         
@@ -1637,16 +1637,26 @@
  %7D%0A%0A    
+protected 
 abstract
@@ -1736,11 +1736,430 @@
 vity);%0A%0A
+    public abstract void onJsAlert(WebView view, String url, String message);%0A%0A%0A    public abstract void onJsConfirm(WebView view, String url, String message, JsResult jsResult);%0A%0A    public abstract void showChooser(WebView view, String url, String%5B%5D ways, Handler.Callback callback);%0A%0A    public abstract void onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult jsPromptResult);%0A%0A
 %0A%7D%0A

update AgentWebUIController