From 7539261c92fe7a4e2a7000f09920d3341571c0e7 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Thu, 26 Sep 2024 09:00:51 +0200 Subject: [PATCH 1/2] Add the possibility to pass headers to the webview --- build.gradle | 1 + .../java/com/infomaniak/lib/core/ui/WebViewActivity.kt | 9 ++++++--- src/main/res/navigation/webview_navigation.xml | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index fdcc7d27..9aac4855 100644 --- a/build.gradle +++ b/build.gradle @@ -24,6 +24,7 @@ android { testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" buildConfigField 'String', 'AUTOLOG_URL', '"https://manager.infomaniak.com/v3/mobile_login"' + buildConfigField 'String', 'TERMINATE_ACCOUNT_URL', '"https://manager.infomaniak.com/v3/ng/profile/user/dashboard?open-terminate-account-modal"' buildConfigField 'String', 'LOGIN_ENDPOINT_URL', '"https://login.infomaniak.com/"' buildConfigField 'String', 'INFOMANIAK_API_V1', '"https://api.infomaniak.com/1"' buildConfigField 'String', 'INFOMANIAK_API', '"https://api.infomaniak.com/2/"' diff --git a/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt b/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt index ce18953f..95c1c98c 100644 --- a/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt +++ b/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt @@ -24,6 +24,8 @@ import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.navigation.navArgs import com.infomaniak.lib.core.databinding.ActivityWebviewBinding +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json class WebViewActivity : AppCompatActivity() { @@ -36,15 +38,16 @@ class WebViewActivity : AppCompatActivity() { setContentView(binding.root) binding.webview.apply { settings.javaScriptEnabled = true - loadUrl(navArgs.url) + val headers = navArgs.headers?.let { Json.decodeFromString>(it) } ?: mapOf() + loadUrl(navArgs.url, headers) } } companion object { - fun startActivity(context: Context, url: String) { + fun startActivity(context: Context, url: String, headers: Map? = mapOf()) { Intent(context, WebViewActivity::class.java).apply { - putExtras(WebViewActivityArgs(url).toBundle()) + putExtras(WebViewActivityArgs(url, Json.encodeToString(headers)).toBundle()) }.also(context::startActivity) } } diff --git a/src/main/res/navigation/webview_navigation.xml b/src/main/res/navigation/webview_navigation.xml index 4253f2d8..8694d1d0 100644 --- a/src/main/res/navigation/webview_navigation.xml +++ b/src/main/res/navigation/webview_navigation.xml @@ -31,6 +31,11 @@ android:name="url" app:argType="string" /> + + From a4efcf7d9756e6a68bd40fccb790ba59ac74c5c4 Mon Sep 17 00:00:00 2001 From: Vincent TE Date: Thu, 26 Sep 2024 09:01:29 +0200 Subject: [PATCH 2/2] Fix an issue where it'll open the default browser instead of the webview --- src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt b/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt index 95c1c98c..740b1b0f 100644 --- a/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt +++ b/src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt @@ -21,6 +21,7 @@ import android.annotation.SuppressLint import android.content.Context import android.content.Intent import android.os.Bundle +import android.webkit.WebViewClient import androidx.appcompat.app.AppCompatActivity import androidx.navigation.navArgs import com.infomaniak.lib.core.databinding.ActivityWebviewBinding @@ -37,6 +38,7 @@ class WebViewActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(binding.root) binding.webview.apply { + webViewClient = WebViewClient() settings.javaScriptEnabled = true val headers = navArgs.headers?.let { Json.decodeFromString>(it) } ?: mapOf() loadUrl(navArgs.url, headers)