Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to pass headers to the WebviewActivity #224

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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/"'
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/infomaniak/lib/core/ui/WebViewActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ 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
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

class WebViewActivity : AppCompatActivity() {

Expand All @@ -35,16 +38,18 @@ class WebViewActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.webview.apply {
webViewClient = WebViewClient()
settings.javaScriptEnabled = true
loadUrl(navArgs.url)
val headers = navArgs.headers?.let { Json.decodeFromString<Map<String, String>>(it) } ?: mapOf()
loadUrl(navArgs.url, headers)
}
}

companion object {

fun startActivity(context: Context, url: String) {
fun startActivity(context: Context, url: String, headers: Map<String, String>? = mapOf()) {
Intent(context, WebViewActivity::class.java).apply {
putExtras(WebViewActivityArgs(url).toBundle())
putExtras(WebViewActivityArgs(url, Json.encodeToString(headers)).toBundle())
}.also(context::startActivity)
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/res/navigation/webview_navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
android:name="url"
app:argType="string" />

<argument
android:name="headers"
app:argType="string"
app:nullable="true"/>

</activity>

</navigation>
Loading