diff --git a/webview/src/main/java/ru/touchin/roboswag/webview/web_view/BaseWebView.kt b/webview/src/main/java/ru/touchin/roboswag/webview/web_view/BaseWebView.kt
index 6f0af20..31d7300 100644
--- a/webview/src/main/java/ru/touchin/roboswag/webview/web_view/BaseWebView.kt
+++ b/webview/src/main/java/ru/touchin/roboswag/webview/web_view/BaseWebView.kt
@@ -137,6 +137,37 @@ open class BaseWebView @JvmOverloads constructor(
binding.webView.loadUrl(url ?: "", extraHeaders)
}
+ /**
+ * @param htmlString raw html string to be loaded into WebView
+ * @param cssString raw css string to add styles
+ * @param cssFileName name for .css file which can be placed in assets folder
+ * @param styleDeps dependencies for styles which must be included into html,
+ * e.g.
+ */
+ fun loadHtmlContent(
+ htmlString: String,
+ cssString: String = "",
+ cssFileName: String = "",
+ styleDeps: String = ""
+ ) {
+ val indexOfHead = htmlString
+ .indexOf("", ignoreCase = true)
+ .takeIf { it != -1 } ?: 0
+
+ val styledHtml = StringBuilder(htmlString)
+ .insert(indexOfHead, styleDeps)
+ .insert(indexOfHead, "")
+ .insert(indexOfHead, "")
+
+ getWebView().loadDataWithBaseURL(
+ "file:///android_asset/".takeIf { cssFileName.isNotEmpty() },
+ styledHtml.toString(),
+ "text/html",
+ "utf-8",
+ null
+ )
+ }
+
fun setState(newState: WebViewLoadingState) {
onStateChanged(newState)
}
@@ -157,6 +188,8 @@ open class BaseWebView @JvmOverloads constructor(
scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
setLayerType(View.LAYER_TYPE_HARDWARE, null)
with(settings) {
+ allowContentAccess = true
+ allowFileAccess = true
loadsImagesAutomatically = true
javaScriptEnabled = true
domStorageEnabled = true