|
@@ -114,13 +114,7 @@ fun FAQ(navHostController: NavHostController) {
|
|
|
val faqUrl = if (isDarkTheme.value) "${AppConstant.BASE_WEBVIEW_URL}${languageIdentifier}/faq?skin=dark"
|
|
|
else "${AppConstant.BASE_WEBVIEW_URL}${languageIdentifier}/faq?device=ios"
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O_MR1) {
|
|
|
- Log.d("test_webview", "CustomWebView()")
|
|
|
- CustomWebView(url = faqUrl)
|
|
|
- } else {
|
|
|
- Log.d("test_webview", "WebView()")
|
|
|
- WebView(url = faqUrl)
|
|
|
- }
|
|
|
+ WebView(url = faqUrl)
|
|
|
}
|
|
|
|
|
|
if (showLoader.value) {
|
|
@@ -150,38 +144,38 @@ fun FAQ(navHostController: NavHostController) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-@Composable
|
|
|
-fun BoxScope.CustomWebView(url: String) {
|
|
|
- AndroidView(factory = { context ->
|
|
|
- val webView = WebView(context).apply {
|
|
|
- layoutParams = ViewGroup.LayoutParams(
|
|
|
- ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
- ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
- )
|
|
|
-
|
|
|
- settings.apply {
|
|
|
- javaScriptEnabled = true
|
|
|
- domStorageEnabled = true
|
|
|
- loadsImagesAutomatically = true
|
|
|
- mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
|
|
- }
|
|
|
-
|
|
|
- webViewClient = object : WebViewClient() {
|
|
|
- override fun onReceivedSslError(
|
|
|
- view: WebView?,
|
|
|
- handler: android.webkit.SslErrorHandler?,
|
|
|
- error: android.net.http.SslError?
|
|
|
- ) {
|
|
|
- handler?.proceed() // Bypass SSL certificate issues (for debugging)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Make the OkHttp request
|
|
|
- loadContentWithOkHttp(webView, url)
|
|
|
- webView
|
|
|
- })
|
|
|
-}
|
|
|
+//@Composable
|
|
|
+//fun BoxScope.CustomWebView(url: String) {
|
|
|
+// AndroidView(factory = { context ->
|
|
|
+// val webView = WebView(context).apply {
|
|
|
+// layoutParams = ViewGroup.LayoutParams(
|
|
|
+// ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
+// ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
+// )
|
|
|
+//
|
|
|
+// settings.apply {
|
|
|
+// javaScriptEnabled = true
|
|
|
+// domStorageEnabled = true
|
|
|
+// loadsImagesAutomatically = true
|
|
|
+// mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
|
|
|
+// }
|
|
|
+//
|
|
|
+// webViewClient = object : WebViewClient() {
|
|
|
+// override fun onReceivedSslError(
|
|
|
+// view: WebView?,
|
|
|
+// handler: android.webkit.SslErrorHandler?,
|
|
|
+// error: android.net.http.SslError?
|
|
|
+// ) {
|
|
|
+// handler?.proceed() // Bypass SSL certificate issues (for debugging)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // Make the OkHttp request
|
|
|
+// loadContentWithOkHttp(webView, url)
|
|
|
+// webView
|
|
|
+// })
|
|
|
+//}
|
|
|
|
|
|
@Composable
|
|
|
fun BoxScope.WebView(url: String) {
|
|
@@ -220,83 +214,83 @@ fun BoxScope.WebView(url: String) {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-fun loadContentWithOkHttp(webView: WebView, url: String) {
|
|
|
- val client = createUnsafeOkHttpClient()
|
|
|
- val request = Request.Builder().url(url).build()
|
|
|
-
|
|
|
- Log.d("test_webview", "loadContentWithOkHttp")
|
|
|
-
|
|
|
- client.newCall(request).enqueue(object : okhttp3.Callback {
|
|
|
- override fun onFailure(call: okhttp3.Call, e: IOException) {
|
|
|
- showLoader.value = false
|
|
|
- Log.d("test_webview", "onFailure")
|
|
|
- Log.e("CustomWebView", "Failed to load URL with OkHttp: ${e.message}")
|
|
|
- }
|
|
|
-
|
|
|
- override fun onResponse(call: okhttp3.Call, response: okhttp3.Response) {
|
|
|
- showLoader.value = false
|
|
|
- Log.d("test_webview", "onResponse")
|
|
|
-
|
|
|
- val htmlContent = response.body?.string() ?: ""
|
|
|
- // Load the HTML content into the WebView on the main thread
|
|
|
-
|
|
|
- webView.post {
|
|
|
- showLoader.value = false
|
|
|
- Log.d("test_webview", "webView.post")
|
|
|
- webView.loadDataWithBaseURL(url, htmlContent, "text/html", "UTF-8", null)
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-fun WebView.trustAllCertificates() {
|
|
|
- try {
|
|
|
- Log.d("test_webview", "try")
|
|
|
- val trustAllCerts = arrayOf<TrustManager>(
|
|
|
- object : X509TrustManager {
|
|
|
- override fun checkClientTrusted(
|
|
|
- chain: Array<out X509Certificate>?,
|
|
|
- authType: String?
|
|
|
- ) {}
|
|
|
-
|
|
|
- override fun checkServerTrusted(
|
|
|
- chain: Array<out X509Certificate>?,
|
|
|
- authType: String?
|
|
|
- ) {}
|
|
|
-
|
|
|
- override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- val sslContext = SSLContext.getInstance("TLS")
|
|
|
- sslContext.init(null, trustAllCerts, SecureRandom())
|
|
|
- this.settings.javaScriptEnabled = true
|
|
|
- // Set the SSL factory to the custom context that trusts all certificates
|
|
|
- sslContext.socketFactory
|
|
|
- } catch (e: Exception) {
|
|
|
- Log.d("test_webview", "catch")
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-fun createUnsafeOkHttpClient(): OkHttpClient {
|
|
|
- val trustAllCerts = arrayOf<TrustManager>(
|
|
|
- object : X509TrustManager {
|
|
|
- override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}
|
|
|
- override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}
|
|
|
- override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
|
|
|
- }
|
|
|
- )
|
|
|
-
|
|
|
- val sslContext = SSLContext.getInstance("TLS")
|
|
|
- sslContext.init(null, trustAllCerts, SecureRandom())
|
|
|
- val sslSocketFactory = sslContext.socketFactory
|
|
|
-
|
|
|
- return OkHttpClient.Builder()
|
|
|
- .sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
|
- .hostnameVerifier(HostnameVerifier { _, _ -> true })
|
|
|
- .build()
|
|
|
-}
|
|
|
+//fun loadContentWithOkHttp(webView: WebView, url: String) {
|
|
|
+// val client = createUnsafeOkHttpClient()
|
|
|
+// val request = Request.Builder().url(url).build()
|
|
|
+//
|
|
|
+// Log.d("test_webview", "loadContentWithOkHttp")
|
|
|
+//
|
|
|
+// client.newCall(request).enqueue(object : okhttp3.Callback {
|
|
|
+// override fun onFailure(call: okhttp3.Call, e: IOException) {
|
|
|
+// showLoader.value = false
|
|
|
+// Log.d("test_webview", "onFailure")
|
|
|
+// Log.e("CustomWebView", "Failed to load URL with OkHttp: ${e.message}")
|
|
|
+// }
|
|
|
+//
|
|
|
+// override fun onResponse(call: okhttp3.Call, response: okhttp3.Response) {
|
|
|
+// showLoader.value = false
|
|
|
+// Log.d("test_webview", "onResponse")
|
|
|
+//
|
|
|
+// val htmlContent = response.body?.string() ?: ""
|
|
|
+// // Load the HTML content into the WebView on the main thread
|
|
|
+//
|
|
|
+// webView.post {
|
|
|
+// showLoader.value = false
|
|
|
+// Log.d("test_webview", "webView.post")
|
|
|
+// webView.loadDataWithBaseURL(url, htmlContent, "text/html", "UTF-8", null)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// })
|
|
|
+//}
|
|
|
+
|
|
|
+
|
|
|
+//fun WebView.trustAllCertificates() {
|
|
|
+// try {
|
|
|
+// Log.d("test_webview", "try")
|
|
|
+// val trustAllCerts = arrayOf<TrustManager>(
|
|
|
+// object : X509TrustManager {
|
|
|
+// override fun checkClientTrusted(
|
|
|
+// chain: Array<out X509Certificate>?,
|
|
|
+// authType: String?
|
|
|
+// ) {}
|
|
|
+//
|
|
|
+// override fun checkServerTrusted(
|
|
|
+// chain: Array<out X509Certificate>?,
|
|
|
+// authType: String?
|
|
|
+// ) {}
|
|
|
+//
|
|
|
+// override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
|
|
|
+// }
|
|
|
+// )
|
|
|
+//
|
|
|
+// val sslContext = SSLContext.getInstance("TLS")
|
|
|
+// sslContext.init(null, trustAllCerts, SecureRandom())
|
|
|
+// this.settings.javaScriptEnabled = true
|
|
|
+// // Set the SSL factory to the custom context that trusts all certificates
|
|
|
+// sslContext.socketFactory
|
|
|
+// } catch (e: Exception) {
|
|
|
+// Log.d("test_webview", "catch")
|
|
|
+// }
|
|
|
+//}
|
|
|
+//
|
|
|
+//fun createUnsafeOkHttpClient(): OkHttpClient {
|
|
|
+// val trustAllCerts = arrayOf<TrustManager>(
|
|
|
+// object : X509TrustManager {
|
|
|
+// override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}
|
|
|
+// override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}
|
|
|
+// override fun getAcceptedIssuers(): Array<X509Certificate> = arrayOf()
|
|
|
+// }
|
|
|
+// )
|
|
|
+//
|
|
|
+// val sslContext = SSLContext.getInstance("TLS")
|
|
|
+// sslContext.init(null, trustAllCerts, SecureRandom())
|
|
|
+// val sslSocketFactory = sslContext.socketFactory
|
|
|
+//
|
|
|
+// return OkHttpClient.Builder()
|
|
|
+// .sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager)
|
|
|
+// .hostnameVerifier(HostnameVerifier { _, _ -> true })
|
|
|
+// .build()
|
|
|
+//}
|
|
|
|
|
|
@Composable
|
|
|
fun BoxScope.ShowExpandList(
|