Skip to content

Commit

Permalink
Merge branch 'main' into rehan/push-click-behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Oct 18, 2023
2 parents dee8f95 + d17fab9 commit 72a0535
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 36 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [3.6.7](https://github.com/customerio/customerio-android/compare/3.6.6...3.6.7) (2023-10-17)


### Bug Fixes

* added exception handling for when browser doesn't exist ([#271](https://github.com/customerio/customerio-android/issues/271)) ([aaddad5](https://github.com/customerio/customerio-android/commit/aaddad53281ac22c1e8a73340fcb24e7522e4648))

### [3.6.6](https://github.com/customerio/customerio-android/compare/3.6.5...3.6.6) (2023-09-15)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,17 @@ internal class EngineWebView @JvmOverloads constructor(
var listener: EngineWebViewListener? = null
private var timer: Timer? = null
private var timerTask: TimerTask? = null
private var webView: WebView = WebView(context)
private var webView: WebView? = null
private var elapsedTimer: ElapsedTimer = ElapsedTimer()

init {
this.addView(webView)
// exception handling is required for webview in-case webview is not supported in the device
try {
webView = WebView(context)
this.addView(webView)
} catch (e: Exception) {
Log.e(GIST_TAG, "Error while creating EngineWebView: ${e.message}")

Check warning on line 37 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L33-L37

Added lines #L33 - L37 were not covered by tests
}
}

@SuppressLint("SetJavaScriptEnabled")
Expand All @@ -38,40 +44,60 @@ internal class EngineWebView @JvmOverloads constructor(
val jsonString = Gson().toJson(configuration)
encodeToBase64(jsonString)?.let { options ->
elapsedTimer.start("Engine render for message: ${configuration.messageId}")
val messageUrl = "${GistSdk.gistEnvironment.getGistRendererUrl()}/index.html?options=$options"
val messageUrl =
"${GistSdk.gistEnvironment.getGistRendererUrl()}/index.html?options=$options"

Check warning on line 48 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L47-L48

Added lines #L47 - L48 were not covered by tests
Log.i(GIST_TAG, "Rendering message with URL: $messageUrl")
webView.loadUrl(messageUrl)
webView.settings.javaScriptEnabled = true
webView.settings.allowFileAccess = true
webView.settings.allowContentAccess = true
webView.settings.domStorageEnabled = true
webView.settings.textZoom = 100
webView.setBackgroundColor(Color.TRANSPARENT)
webView.addJavascriptInterface(EngineWebViewInterface(this), "appInterface")

webView.webViewClient = object : WebViewClient() {
override fun onPageFinished(view: WebView, url: String?) {
view.loadUrl("javascript:window.parent.postMessage = function(message) {window.appInterface.postMessage(JSON.stringify(message))}")
}

override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
return !url.startsWith("https://code.gist.build")
}

override fun onReceivedError(view: WebView?, errorCod: Int, description: String, failingUrl: String?) {
listener?.error()
}

override fun onReceivedHttpError(view: WebView?, request: WebResourceRequest?, errorResponse: WebResourceResponse?) {
listener?.error()
}

override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
listener?.error()
}

override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler?, error: SslError?) {
listener?.error()
webView?.let {
it.loadUrl(messageUrl)
it.settings.javaScriptEnabled = true
it.settings.allowFileAccess = true
it.settings.allowContentAccess = true
it.settings.domStorageEnabled = true
it.settings.textZoom = 100
it.setBackgroundColor(Color.TRANSPARENT)
it.addJavascriptInterface(EngineWebViewInterface(this), "appInterface")

Check warning on line 58 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L51-L58

Added lines #L51 - L58 were not covered by tests

it.webViewClient = object : WebViewClient() {

Check warning on line 60 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L60

Added line #L60 was not covered by tests
override fun onPageFinished(view: WebView, url: String?) {
view.loadUrl("javascript:window.parent.postMessage = function(message) {window.appInterface.postMessage(JSON.stringify(message))}")
}

Check warning on line 63 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L62-L63

Added lines #L62 - L63 were not covered by tests

override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
return !url.startsWith("https://code.gist.build")
}

override fun onReceivedError(
view: WebView?,
errorCod: Int,
description: String,
failingUrl: String?
) {
listener?.error()
}

Check warning on line 76 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L76

Added line #L76 was not covered by tests

override fun onReceivedHttpError(
view: WebView?,
request: WebResourceRequest?,
errorResponse: WebResourceResponse?
) {
listener?.error()
}

Check warning on line 84 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L84

Added line #L84 was not covered by tests

override fun onReceivedError(
view: WebView?,
request: WebResourceRequest?,
error: WebResourceError?
) {
listener?.error()
}

Check warning on line 92 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L92

Added line #L92 was not covered by tests

override fun onReceivedSslError(
view: WebView?,
handler: SslErrorHandler?,
error: SslError?
) {
listener?.error()
}

Check warning on line 100 in messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt

View check run for this annotation

Codecov / codecov/patch

messaginginapp/src/main/java/io/customer/messaginginapp/gist/presentation/engine/EngineWebView.kt#L100

Added line #L100 was not covered by tests
}
}
} ?: run {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/io/customer/sdk/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ package io.customer.sdk

internal object Version {

const val version: String = "3.6.6"
const val version: String = "3.6.7"
}

0 comments on commit 72a0535

Please sign in to comment.