CAG v5.7.4版本的 MD5 值为:bc57ead76a7a30559f0708e9d60d749f

以下内容为反编译后的 ChatSdk.java 源代码,内容仅作参考


package org.commons.livechat;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.CountDownTimer;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import i.c.a.c.a0;
import java.util.Objects;
import kotlin.Metadata;
import n.e;
import n.i.a.p;
import n.i.b.h;
import org.commons.livechat.ChatSdk;
@Metadata(d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\b\u0018\u00002\u00020\u0001:\u0001#B%\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\u0006\u0010\u0006\u001a\u00020\u0005\u0012\u0006\u0010\u0007\u001a\u00020\u0005¢\u0006\u0002\u0010\bJ\u0006\u0010!\u001a\u00020\u0016J\u0006\u0010\"\u001a\u00020\u0016R\u001a\u0010\u0004\u001a\u00020\u0005X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\t\u0010\n\"\u0004\b\u000b\u0010\fR\u001a\u0010\u0006\u001a\u00020\u0005X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\r\u0010\n\"\u0004\b\u000e\u0010\fR\u001a\u0010\u0007\u001a\u00020\u0005X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\n\"\u0004\b\u0010\u0010\fRP\u0010\u0011\u001a8\u0012\u0015\u0012\u0013\u0018\u00010\u0005¢\u0006\f\b\u0013\u0012\b\b\u0014\u0012\u0004\b\b(\u0014\u0012\u0015\u0012\u0013\u0018\u00010\u0005¢\u0006\f\b\u0013\u0012\b\b\u0014\u0012\u0004\b\b(\u0015\u0012\u0004\u0012\u00020\u0016\u0018\u00010\u0012X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0018\"\u0004\b\u0019\u0010\u001aR\u0010\u0010\u001b\u001a\u0004\u0018\u00010\u001cX\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010\u0002\u001a\u00020\u0003X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u001d\u0010\u001e\"\u0004\b\u001f\u0010 ¨\u0006$"}, d2 = {"Lorg/commons/livechat/ChatSdk;", "", "webView", "Landroid/webkit/WebView;", "appName", "", "channelUrl", "clientId", "(Landroid/webkit/WebView;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", "getAppName", "()Ljava/lang/String;", "setAppName", "(Ljava/lang/String;)V", "getChannelUrl", "setChannelUrl", "getClientId", "setClientId", "delegate", "Lkotlin/Function2;", "Lkotlin/ParameterName;", "name", "data", "", "getDelegate", "()Lkotlin/jvm/functions/Function2;", "setDelegate", "(Lkotlin/jvm/functions/Function2;)V", "timer", "Landroid/os/CountDownTimer;", "getWebView", "()Landroid/webkit/WebView;", "setWebView", "(Landroid/webkit/WebView;)V", "destroy", "prepare", "MyWebViewClient", "livechat_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class ChatSdk {
    public WebView a;
    public String b;
    public String c;
    public String f15146d;
    public CountDownTimer f15147e;
    public p<? super String, ? super String, e> f15148f;

    @Metadata(d1 = {"\u00002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\b\u0082\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0018\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\bH\u0002J\u0018\u0010\t\u001a\u00020\u00042\u0006\u0010\u0007\u001a\u00020\b2\u0006\u0010\u0005\u001a\u00020\u0006H\u0016J&\u0010\n\u001a\u00020\u00042\b\u0010\u0007\u001a\u0004\u0018\u00010\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\f2\b\u0010\r\u001a\u0004\u0018\u00010\u000eH\u0016J\u001a\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0007\u001a\u00020\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\fH\u0016J\u0018\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0007\u001a\u00020\b2\u0006\u0010\u0005\u001a\u00020\u0006H\u0016¨\u0006\u0011"}, d2 = {"Lorg/commons/livechat/ChatSdk$MyWebViewClient;", "Landroid/webkit/WebViewClient;", "(Lorg/commons/livechat/ChatSdk;)V", "dealData", "", "url", "", "view", "Landroid/webkit/WebView;", "onPageFinished", "onReceivedError", "request", "Landroid/webkit/WebResourceRequest;", "error", "Landroid/webkit/WebResourceError;", "shouldOverrideUrlLoading", "", "livechat_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class MyWebViewClient extends WebViewClient {

        @Metadata(d1 = {"\u0000\u0019\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\t\n\u0000*\u0001\u0000\b\n\u0018\u00002\u00020\u0001J\b\u0010\u0002\u001a\u00020\u0003H\u0016J\u0010\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u0006H\u0016¨\u0006\u0007"}, d2 = {"org/commons/livechat/ChatSdk$MyWebViewClient$onPageFinished$1", "Landroid/os/CountDownTimer;", "onFinish", "", "onTick", "millisUntilFinished", "", "livechat_release"}, k = 1, mv = {1, 6, 0}, xi = 48)
        public static final class a extends CountDownTimer {
            public final ChatSdk a;
            public final WebView b;

            public a(ChatSdk chatSdk, WebView webView) {
                super(3000L, 1000L);
                this.a = chatSdk;
                this.b = webView;
            }

            @Override
            public void onFinish() {
                StringBuilder J = i.a.b.a.a.J("\n                           var sc = document.createElement(\"script\");\n                           sc.type = \"text/javascript\";\n                           sc.src = \"https://appservercn.kingdomsalvation.org/cdn/tawk/1.0/tawk.min.js\";\n                           document.getElementsByTagName('head')[0].appendChild(sc);\n                           Tawk_API.setAttributes({'source':'");
                J.append(this.a.b);
                J.append("', 'clientId':'");
                J.append(this.a.f15146d);
                J.append("'});\n                            var T;\n                            var N = 0;\n                            function cycleGetLastMsg() {\n                              T = setTimeout(function () {\n                                if (typeof getLastAgentMessage === \"function\") {\n                                  if (T) {\n                                    clearTimeout(T)\n                                  }\n                                  var msg = getLastAgentMessage();\n                                  var lastMsg = '");
                ChatConfig chatConfig = ChatConfig.f15135n;
                Objects.requireNonNull(chatConfig);
                J.append(ChatConfig.f15139r.a(chatConfig, ChatConfig.f15136o[2]));
                J.append("';\n                                  if (lastMsg != '' && msg != lastMsg) {\n                                    window.location = 'chat://' + encodeURIComponent(msg);\n                                  }\n                                } else {\n                                  if (T) {\n                                    clearTimeout(T)\n                                  }\n                                  if (N < 20) cycleGetLastMsg(); \n                                  N++\n                                }\n                              }, 1000)\n                            }\n                            cycleGetLastMsg();\n                        ");
                String N = n.o.a.N(J.toString());
                WebView webView = this.b;
                h.e(webView, "<this>");
                h.e(N, "js");
                webView.evaluateJavascript(N, null);
            }

            @Override
            public void onTick(long j2) {
            }
        }

        public MyWebViewClient() {
        }

        private final void dealData(String str, WebView webView) {
            if (n.o.a.C(str, "chat://", false, 2)) {
                ChatConfig chatConfig = ChatConfig.f15135n;
                if (chatConfig.r()) {
                    final String w2 = n.o.a.w(str, "chat://", "", false, 4);
                    h.e(w2, "<set-?>");
                    ChatConfig.f15139r.b(chatConfig, ChatConfig.f15136o[2], w2);
                    final ChatSdk chatSdk = ChatSdk.this;
                    a0.a(new Runnable() {
                        @Override
                        public final void run() {
                            ChatSdk.MyWebViewClient.m25dealData$lambda0(ChatSdk.this, w2);
                        }
                    });
                }
            } else if (n.o.a.C(str, "chat-messagesent://", false, 2)) {
                ChatConfig chatConfig2 = ChatConfig.f15135n;
                if (!chatConfig2.r()) {
                    ChatConfig.f15140s.b(chatConfig2, ChatConfig.f15136o[3], true);
                }
                final ChatSdk chatSdk2 = ChatSdk.this;
                a0.a(new Runnable() {
                    @Override
                    public final void run() {
                        ChatSdk.MyWebViewClient.m26dealData$lambda1(ChatSdk.this);
                    }
                });
            } else {
                try {
                    webView.getContext().startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str)));
                } catch (Exception unused) {
                }
            }
        }

        public static final void m25dealData$lambda0(ChatSdk chatSdk, String str) {
            h.e(chatSdk, "this$0");
            h.e(str, "$data");
            p<? super String, ? super String, e> pVar = chatSdk.f15148f;
            if (pVar != null) {
                pVar.invoke("chat-message", str);
            }
        }

        public static final void m26dealData$lambda1(ChatSdk chatSdk) {
            h.e(chatSdk, "this$0");
            p<? super String, ? super String, e> pVar = chatSdk.f15148f;
            if (pVar != null) {
                pVar.invoke("chat-send", "");
            }
        }

        @Override
        public void onPageFinished(WebView webView, String str) {
            h.e(webView, "view");
            h.e(str, "url");
            super.onPageFinished(webView, str);
            p<? super String, ? super String, e> pVar = ChatSdk.this.f15148f;
            if (pVar != null) {
                pVar.invoke("loaded", null);
            }
            ChatSdk.this.f15147e = new a(ChatSdk.this, webView).start();
        }

        @Override
        public void onReceivedError(WebView webView, WebResourceRequest webResourceRequest, WebResourceError webResourceError) {
            Context context;
            NetworkInfo activeNetworkInfo;
            super.onReceivedError(webView, webResourceRequest, webResourceError);
            WebView webView2 = ChatSdk.this.a;
            boolean z = false;
            if (webView2 != null && (context = webView2.getContext()) != null) {
                h.e(context, "<this>");
                Object systemService = context.getSystemService("connectivity");
                ConnectivityManager connectivityManager = systemService instanceof ConnectivityManager ? (ConnectivityManager) systemService : null;
                if ((connectivityManager == null || (activeNetworkInfo = connectivityManager.getActiveNetworkInfo()) == null) ? false : activeNetworkInfo.isConnected()) {
                    z = true;
                }
            }
            if (z) {
                ChatSdk chatSdk = ChatSdk.this;
                WebView webView3 = chatSdk.a;
                if (webView3 != null) {
                    webView3.loadUrl(chatSdk.c);
                    return;
                }
                return;
            }
            p<? super String, ? super String, e> pVar = ChatSdk.this.f15148f;
            if (pVar != null) {
                pVar.invoke("no-wifi", null);
            }
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            h.e(webView, "view");
            h.e(str, "url");
            dealData(str, webView);
            return true;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
            Uri url;
            h.e(webView, "view");
            dealData((webResourceRequest == null || (url = webResourceRequest.getUrl()) == null || (r3 = url.toString()) == null) ? "" : "", webView);
            return true;
        }
    }

    public ChatSdk(WebView webView, String str, String str2, String str3) {
        h.e(webView, "webView");
        h.e(str, "appName");
        h.e(str2, "channelUrl");
        h.e(str3, "clientId");
        this.a = webView;
        this.b = str;
        this.c = str2;
        this.f15146d = str3;
    }

    public final void a() {
        WebSettings settings = this.a.getSettings();
        h.d(settings, "webView.settings");
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setDatabaseEnabled(true);
        this.a.setWebViewClient(new MyWebViewClient());
        this.a.loadUrl(this.c);
        p<? super String, ? super String, e> pVar = this.f15148f;
        if (pVar != null) {
            pVar.invoke("loading", null);
        }
    }
}