mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 17:37:05 +05:30
feat(android): add a WebView for login purposes
This commit is contained in:
parent
5bcfe0a85c
commit
ca91918707
2 changed files with 53 additions and 0 deletions
|
@ -95,6 +95,7 @@ dependencies {
|
||||||
implementation(projects.core)
|
implementation(projects.core)
|
||||||
implementation(projects.database.impl)
|
implementation(projects.database.impl)
|
||||||
implementation(projects.model)
|
implementation(projects.model)
|
||||||
|
implementation(projects.web)
|
||||||
|
|
||||||
kapt(libs.dagger.compiler)
|
kapt(libs.dagger.compiler)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright © 2023 Harsh Shandilya.
|
||||||
|
* Use of this source code is governed by an MIT-style
|
||||||
|
* license that can be found in the LICENSE file or at
|
||||||
|
* https://opensource.org/licenses/MIT.
|
||||||
|
*/
|
||||||
|
package dev.msfjarvis.claw.android.ui.login
|
||||||
|
|
||||||
|
import android.webkit.CookieManager
|
||||||
|
import android.webkit.WebView
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import com.google.accompanist.web.AccompanistWebViewClient
|
||||||
|
import com.google.accompanist.web.WebView
|
||||||
|
import com.google.accompanist.web.rememberWebViewState
|
||||||
|
import dev.msfjarvis.claw.api.LobstersApi
|
||||||
|
import io.github.aakira.napier.Napier
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
|
||||||
|
@Suppress("Unused")
|
||||||
|
@Composable
|
||||||
|
fun LobstersLoginWebView(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
val state = rememberWebViewState(url = "https://lobste.rs/login")
|
||||||
|
val webClient = remember {
|
||||||
|
object : AccompanistWebViewClient() {
|
||||||
|
override fun onPageFinished(view: WebView, url: String?) {
|
||||||
|
super.onPageFinished(view, url)
|
||||||
|
Napier.d(tag = "WebView") { "onPageFinished(url=$url)" }
|
||||||
|
if (url != null && url.toHttpUrl() == LobstersApi.BASE_URL.toHttpUrl()) {
|
||||||
|
val cookies = CookieManager.getInstance().getCookie(LobstersApi.BASE_URL)
|
||||||
|
val trap =
|
||||||
|
cookies
|
||||||
|
.split(";")
|
||||||
|
.associate {
|
||||||
|
val split = it.split("=")
|
||||||
|
split[0] to split[1]
|
||||||
|
}["lobsters_trap"]
|
||||||
|
Napier.d(tag = "WebView") { "lobsters_trap=${trap}" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WebView(
|
||||||
|
state = state,
|
||||||
|
client = webClient,
|
||||||
|
modifier = modifier,
|
||||||
|
captureBackPresses = false,
|
||||||
|
)
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue