Improve Igneous cookie handling
This commit is contained in:
parent
6402258c83
commit
51c5f29b25
@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
@ -22,6 +23,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.produceState
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
@ -105,7 +107,7 @@ fun EhLoginWebViewScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var showAdvancedOptions by remember {
|
var showAdvancedOptions by rememberSaveable {
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +116,9 @@ fun EhLoginWebViewScreen(
|
|||||||
WebView(
|
WebView(
|
||||||
state = state,
|
state = state,
|
||||||
navigator = navigator,
|
navigator = navigator,
|
||||||
modifier = Modifier.padding(bottom = 48.dp),
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(bottom = 48.dp),
|
||||||
onCreated = { webView ->
|
onCreated = { webView ->
|
||||||
webView.setDefaultSettings()
|
webView.setDefaultSettings()
|
||||||
|
|
||||||
@ -143,7 +147,11 @@ fun EhLoginWebViewScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (showAdvancedOptions) {
|
if (showAdvancedOptions) {
|
||||||
Box(Modifier.background(Color(0xb5000000))) {
|
Box(
|
||||||
|
Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(Color(0xb5000000))
|
||||||
|
) {
|
||||||
Dialog(onDismissRequest = { showAdvancedOptions = false }) {
|
Dialog(onDismissRequest = { showAdvancedOptions = false }) {
|
||||||
fun loadUrl(url: String) {
|
fun loadUrl(url: String) {
|
||||||
state.content = WebContent.Url(url)
|
state.content = WebContent.Url(url)
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
package eu.kanade.presentation.webview.components
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.material3.AlertDialog
|
||||||
|
import androidx.compose.material3.OutlinedTextField
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextButton
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.input.TextFieldValue
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun IgneousDialog(
|
||||||
|
onDismissRequest: () -> Unit,
|
||||||
|
onIgneousSet: (String) -> Unit,
|
||||||
|
) {
|
||||||
|
var textFieldValue by rememberSaveable(stateSaver = TextFieldValue.Saver) {
|
||||||
|
mutableStateOf(TextFieldValue(""))
|
||||||
|
}
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismissRequest,
|
||||||
|
title = { Text(text = stringResource(R.string.custom_igneous_cookie)) },
|
||||||
|
text = {
|
||||||
|
Column {
|
||||||
|
Text(text = stringResource(R.string.custom_igneous_cookie_message))
|
||||||
|
OutlinedTextField(
|
||||||
|
value = textFieldValue,
|
||||||
|
onValueChange = { textFieldValue = it },
|
||||||
|
singleLine = true,
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
properties = DialogProperties(
|
||||||
|
usePlatformDefaultWidth = true,
|
||||||
|
),
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(
|
||||||
|
onClick = {
|
||||||
|
onIgneousSet(textFieldValue.text.trim())
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
Text(text = stringResource(android.R.string.ok))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
dismissButton = {
|
||||||
|
TextButton(onClick = onDismissRequest) {
|
||||||
|
Text(text = stringResource(R.string.action_cancel))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
@ -7,15 +7,18 @@ import android.os.Bundle
|
|||||||
import android.webkit.CookieManager
|
import android.webkit.CookieManager
|
||||||
import android.webkit.WebView
|
import android.webkit.WebView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import eu.kanade.domain.UnsortedPreferences
|
import eu.kanade.domain.UnsortedPreferences
|
||||||
import eu.kanade.presentation.webview.EhLoginWebViewScreen
|
import eu.kanade.presentation.webview.EhLoginWebViewScreen
|
||||||
|
import eu.kanade.presentation.webview.components.IgneousDialog
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
|
||||||
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
import eu.kanade.tachiyomi.util.system.WebViewUtil
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
import eu.kanade.tachiyomi.util.view.setComposeContent
|
import eu.kanade.tachiyomi.util.view.setComposeContent
|
||||||
import eu.kanade.tachiyomi.widget.materialdialogs.setTextInput
|
|
||||||
import exh.log.xLogD
|
import exh.log.xLogD
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.net.HttpCookie
|
import java.net.HttpCookie
|
||||||
@ -27,8 +30,6 @@ import java.util.Locale
|
|||||||
class EhLoginActivity : BaseActivity() {
|
class EhLoginActivity : BaseActivity() {
|
||||||
private val preferenceManager: UnsortedPreferences by injectLazy()
|
private val preferenceManager: UnsortedPreferences by injectLazy()
|
||||||
|
|
||||||
private var igneous: String? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@ -39,14 +40,28 @@ class EhLoginActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setComposeContent {
|
setComposeContent {
|
||||||
|
var igneous by rememberSaveable {
|
||||||
|
mutableStateOf<String?>(null)
|
||||||
|
}
|
||||||
|
var igneousDialogOpen by rememberSaveable {
|
||||||
|
mutableStateOf(false)
|
||||||
|
}
|
||||||
|
|
||||||
EhLoginWebViewScreen(
|
EhLoginWebViewScreen(
|
||||||
onUp = { finish() },
|
onUp = { finish() },
|
||||||
onPageFinished = ::onPageFinished,
|
onPageFinished = { view, url -> onPageFinished(view, url, igneous) },
|
||||||
onClickRecheckLoginStatus = ::recheckLoginStatus,
|
onClickRecheckLoginStatus = ::recheckLoginStatus,
|
||||||
onClickAlternateLoginPage = ::alternateLoginPage,
|
onClickAlternateLoginPage = ::alternateLoginPage,
|
||||||
onClickSkipPageRestyling = ::skipPageRestyling,
|
onClickSkipPageRestyling = ::skipPageRestyling,
|
||||||
onClickCustomIgneousCookie = ::openIgneousDialog,
|
onClickCustomIgneousCookie = { igneousDialogOpen = true },
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (igneousDialogOpen) {
|
||||||
|
IgneousDialog(
|
||||||
|
onDismissRequest = { igneousDialogOpen = false },
|
||||||
|
onIgneousSet = { igneous = it },
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,24 +77,7 @@ class EhLoginActivity : BaseActivity() {
|
|||||||
loadUrl("https://forums.e-hentai.org/index.php?act=Login&$PARAM_SKIP_INJECT=true")
|
loadUrl("https://forums.e-hentai.org/index.php?act=Login&$PARAM_SKIP_INJECT=true")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openIgneousDialog() {
|
private fun onPageFinished(view: WebView, url: String, customIgneous: String?) {
|
||||||
var igneous: CharSequence? = null
|
|
||||||
MaterialAlertDialogBuilder(this)
|
|
||||||
.setTitle(R.string.custom_igneous_cookie)
|
|
||||||
.setMessage(R.string.custom_igneous_cookie_message)
|
|
||||||
.setTextInput { igneousText ->
|
|
||||||
igneous = igneousText
|
|
||||||
}
|
|
||||||
.setPositiveButton(android.R.string.ok) { _, _ ->
|
|
||||||
if (!igneous.isNullOrBlank()) {
|
|
||||||
this.igneous = igneous?.toString()?.trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onPageFinished(view: WebView, url: String) {
|
|
||||||
xLogD(url)
|
xLogD(url)
|
||||||
val parsedUrl = Uri.parse(url)
|
val parsedUrl = Uri.parse(url)
|
||||||
if (parsedUrl.host.equals("forums.e-hentai.org", ignoreCase = true)) {
|
if (parsedUrl.host.equals("forums.e-hentai.org", ignoreCase = true)) {
|
||||||
@ -94,7 +92,7 @@ class EhLoginActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
} else if (parsedUrl.host.equals("exhentai.org", ignoreCase = true)) {
|
} else if (parsedUrl.host.equals("exhentai.org", ignoreCase = true)) {
|
||||||
// At ExHentai, check that everything worked out...
|
// At ExHentai, check that everything worked out...
|
||||||
if (applyExHentaiCookies(url)) {
|
if (applyExHentaiCookies(url, customIgneous)) {
|
||||||
preferenceManager.enableExhentai().set(true)
|
preferenceManager.enableExhentai().set(true)
|
||||||
setResult(RESULT_OK)
|
setResult(RESULT_OK)
|
||||||
finish()
|
finish()
|
||||||
@ -121,18 +119,18 @@ class EhLoginActivity : BaseActivity() {
|
|||||||
/**
|
/**
|
||||||
* Parse cookies at ExHentai
|
* Parse cookies at ExHentai
|
||||||
*/
|
*/
|
||||||
private fun applyExHentaiCookies(url: String): Boolean {
|
private fun applyExHentaiCookies(url: String, customIgneous: String?): Boolean {
|
||||||
getCookies(url)?.let { parsed ->
|
getCookies(url)?.let { parsed ->
|
||||||
|
|
||||||
var memberId: String? = null
|
var memberId: String? = null
|
||||||
var passHash: String? = null
|
var passHash: String? = null
|
||||||
var igneous: String? = null
|
var igneous: String? = customIgneous
|
||||||
|
|
||||||
parsed.forEach {
|
parsed.forEach {
|
||||||
when (it.name.lowercase(Locale.getDefault())) {
|
when (it.name.lowercase(Locale.getDefault())) {
|
||||||
MEMBER_ID_COOKIE -> memberId = it.value
|
MEMBER_ID_COOKIE -> memberId = it.value
|
||||||
PASS_HASH_COOKIE -> passHash = it.value
|
PASS_HASH_COOKIE -> passHash = it.value
|
||||||
IGNEOUS_COOKIE -> igneous = this.igneous ?: it.value
|
IGNEOUS_COOKIE -> igneous = customIgneous ?: it.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user