|
1 | 1 | package com.commandbar.android
|
2 | 2 |
|
3 | 3 | import android.content.Context
|
| 4 | +import android.content.Intent |
4 | 5 | import android.content.res.Resources
|
| 6 | +import android.graphics.Color |
5 | 7 | import android.view.View
|
6 | 8 | import android.view.ViewGroup
|
7 | 9 | import android.webkit.JavascriptInterface
|
8 | 10 | import android.webkit.WebChromeClient
|
| 11 | +import android.webkit.WebResourceRequest |
| 12 | +import android.webkit.WebSettings |
9 | 13 | import android.webkit.WebView
|
10 | 14 | import android.webkit.WebViewClient
|
11 | 15 | import androidx.coordinatorlayout.widget.CoordinatorLayout
|
12 | 16 | import com.google.android.material.bottomsheet.BottomSheetDialog
|
13 | 17 | import org.json.JSONObject
|
14 | 18 |
|
| 19 | + |
15 | 20 | typealias FallbackActionCallback = ((action: Map<String, Any>) -> Unit)
|
16 | 21 |
|
17 | 22 | class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFallbackAction: FallbackActionCallback? = null) : WebView(context) {
|
@@ -97,6 +102,15 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
|
97 | 102 | println(it)
|
98 | 103 | }
|
99 | 104 | }
|
| 105 | + |
| 106 | + override fun shouldOverrideUrlLoading( |
| 107 | + view: WebView?, |
| 108 | + request: WebResourceRequest? |
| 109 | + ): Boolean { |
| 110 | + val intent = Intent(Intent.ACTION_VIEW, request!!.url) |
| 111 | + view!!.context.startActivity(intent) |
| 112 | + return true; |
| 113 | + } |
100 | 114 | }
|
101 | 115 |
|
102 | 116 | val html = getHTML(options)
|
@@ -135,11 +149,11 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
|
135 | 149 | val hostname = "10.0.2.2"
|
136 | 150 | val apiHost = "api.commandbar.com";
|
137 | 151 | val userId = if (options.userId == null) "null" else "\"${options.userId}\""
|
138 |
| - |
| 152 | + val launchCode = if (options.launchCode == null) "prod" else options.launchCode |
139 | 153 | return """
|
140 | 154 | (function() {
|
141 | 155 | window._cbIsWebView = true;
|
142 |
| - var o="${options.orgId}",n=["Object.assign","Symbol","Symbol.for"].join("%2C"),a=window;function t(o,n){void 0===n&&(n=!1),"complete"!==document.readyState&&window.addEventListener("load",t.bind(null,o,n),{capture:!1,once:!0});var a=document.createElement("script");a.type="text/javascript",a.async=n,a.src=o,document.head.appendChild(a)}function r(){var n;if(void 0===a.CommandBar){delete a.__CommandBarBootstrap__;var r=Symbol.for("CommandBar::configuration"),e=Symbol.for("CommandBar::orgConfig"),c=Symbol.for("CommandBar::disposed"),i=Symbol.for("CommandBar::isProxy"),m=Symbol.for("CommandBar::queue"),l=Symbol.for("CommandBar::unwrap"),d=[],s="${options.launchCode}",u=s&&s.includes("local")?"http://$hostname:8000":"https://$apiHost",f=Object.assign(((n={})[r]={uuid:o},n[e]={},n[c]=!1,n[i]=!0,n[m]=new Array,n[l]=function(){return f},n),a.CommandBar),p=["addCommand","boot"],y=f;Object.assign(f,{shareCallbacks:function(){return{}},shareContext:function(){return{}}}),a.CommandBar=new Proxy(f,{get:function(o,n){return n in y?f[n]:p.includes(n)?function(){var o=Array.prototype.slice.call(arguments);return new Promise((function(a,t){o.unshift(n,a,t),f[m].push(o)}))}:function(){var o=Array.prototype.slice.call(arguments);o.unshift(n),f[m].push(o)}}}),null!==s&&d.push("lc=".concat(s)),d.push("version=2"),t("".concat(u,"/latest/").concat(o,"?").concat(d.join("&")),!0)}}void 0===Object.assign||"undefined"==typeof Symbol||void 0===Symbol.for?(a.__CommandBarBootstrap__=r,t("https://polyfill.io/v3/polyfill.min.js?version=3.101.0&callback=__CommandBarBootstrap__&features="+n)):r(); |
| 156 | + var o="${options.orgId}",n=["Object.assign","Symbol","Symbol.for"].join("%2C"),a=window;function t(o,n){void 0===n&&(n=!1),"complete"!==document.readyState&&window.addEventListener("load",t.bind(null,o,n),{capture:!1,once:!0});var a=document.createElement("script");a.type="text/javascript",a.async=n,a.src=o,document.head.appendChild(a)}function r(){var n;if(void 0===a.CommandBar){delete a.__CommandBarBootstrap__;var r=Symbol.for("CommandBar::configuration"),e=Symbol.for("CommandBar::orgConfig"),c=Symbol.for("CommandBar::disposed"),i=Symbol.for("CommandBar::isProxy"),m=Symbol.for("CommandBar::queue"),l=Symbol.for("CommandBar::unwrap"),d=[],s="api=$launchCode;commandbar=$launchCode",u=s&&s.includes("local")?"http://$hostname:8000":"https://$apiHost",f=Object.assign(((n={})[r]={uuid:o},n[e]={},n[c]=!1,n[i]=!0,n[m]=new Array,n[l]=function(){return f},n),a.CommandBar),p=["addCommand","boot"],y=f;Object.assign(f,{shareCallbacks:function(){return{}},shareContext:function(){return{}}}),a.CommandBar=new Proxy(f,{get:function(o,n){return n in y?f[n]:p.includes(n)?function(){var o=Array.prototype.slice.call(arguments);return new Promise((function(a,t){o.unshift(n,a,t),f[m].push(o)}))}:function(){var o=Array.prototype.slice.call(arguments);o.unshift(n),f[m].push(o)}}}),null!==s&&d.push("lc=".concat(s)),d.push("version=2"),t("".concat(u,"/latest/").concat(o,"?").concat(d.join("&")),!0)}}void 0===Object.assign||"undefined"==typeof Symbol||void 0===Symbol.for?(a.__CommandBarBootstrap__=r,t("https://polyfill.io/v3/polyfill.min.js?version=3.101.0&callback=__CommandBarBootstrap__&features="+n)):r(); |
143 | 157 | window.CommandBar.boot($userId, {}, { products: ["help_hub"] });
|
144 | 158 | window.CommandBar.openHelpHub();
|
145 | 159 | })();
|
|
0 commit comments