Introduce FINISH_ROUTE_NAME
This commit is contained in:
1 parent
2f69b942d9
commit
13b28c0f38
8 files changed
+39
-56
No files matched your search
@@ -74,7 +74,6 @@ object Settings : DataStorePreferences(null) {
|
||||
var builtInHosts by boolPref(KEY_BUILT_IN_HOSTS, false)
|
||||
var removeImageFiles by boolPref("include_pic", true)
|
||||
var needSignIn by boolPref("need_sign_in", true)
|
||||
var selectSite by boolPref("select_site", true)
|
||||
var blackDarkTheme by boolPref("black_dark_theme", false).observed { updateWhenThemeChanges() }
|
||||
var preloadThumbAggressively by boolPref("preload_thumb_aggressively", false)
|
||||
var dF by boolPref(KEY_DOMAIN_FRONTING, false)
|
||||
|
||||
@@ -116,7 +116,6 @@ object EhUtils {
|
||||
Settings.displayName = null
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
Settings.needSignIn = true
|
||||
Settings.selectSite = true
|
||||
}
|
||||
|
||||
fun needSignedIn(): Boolean {
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.animation.ExitTransition
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.compositionLocalOf
|
||||
import androidx.core.view.WindowCompat
|
||||
import androidx.navigation.NavController
|
||||
@@ -49,15 +50,12 @@ class ConfigureActivity : EhActivity() {
|
||||
composable(SIGN_IN_ROUTE_NAME) {
|
||||
SignInScreen(windowSizeClass)
|
||||
}
|
||||
|
||||
composable(WEBVIEW_SIGN_IN_ROUTE_NAME) {
|
||||
WebviewSignInScreen()
|
||||
}
|
||||
|
||||
composable(COOKIE_SIGN_IN_ROUTE_NAME) {
|
||||
CookieSignInScene(windowSizeClass)
|
||||
}
|
||||
|
||||
composable(SELECT_SITE_ROUTE_NAME) {
|
||||
SelectSiteScreen()
|
||||
}
|
||||
@@ -91,6 +89,11 @@ class ConfigureActivity : EhActivity() {
|
||||
composable(FILTER_SCREEN) {
|
||||
FilterScreen()
|
||||
}
|
||||
composable(FINISH_ROUTE_NAME) {
|
||||
SideEffect {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -113,3 +116,4 @@ const val SIGN_IN_ROUTE_NAME = "SignIn"
|
||||
const val WEBVIEW_SIGN_IN_ROUTE_NAME = "WebViewSignIn"
|
||||
const val COOKIE_SIGN_IN_ROUTE_NAME = "CookieSignIn"
|
||||
const val SELECT_SITE_ROUTE_NAME = "SelectSite"
|
||||
const val FINISH_ROUTE_NAME = "Finish"
|
||||
@@ -56,6 +56,7 @@ import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.FINISH_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.SELECT_SITE_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.compose.rememberDialogState
|
||||
@@ -128,12 +129,8 @@ fun CookieSignInScene(windowSizeClass: WindowSizeClass) {
|
||||
storeCookie(ipbMemberId, ipbPassHash, igneous)
|
||||
EhEngine.getProfile()
|
||||
}.onSuccess {
|
||||
withNonCancellableContext {
|
||||
postLogin()
|
||||
}
|
||||
withUIContext {
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
}
|
||||
val canEx = withNonCancellableContext { postLogin() }
|
||||
withUIContext { navController.navigate(if (canEx) SELECT_SITE_ROUTE_NAME else FINISH_ROUTE_NAME) }
|
||||
}.onFailure {
|
||||
EhCookieStore.signOut()
|
||||
dialogState.show(
|
||||
|
||||
@@ -18,25 +18,22 @@ suspend fun postLogin() = coroutineScope {
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
launch {
|
||||
runCatching {
|
||||
// For the `star` cookie
|
||||
EhEngine.getNews(false)
|
||||
EhCookieStore.copyCookie(EhUrl.DOMAIN_E, EhUrl.DOMAIN_EX, EhCookieStore.KEY_STAR)
|
||||
runCatching {
|
||||
// For the `star` cookie
|
||||
EhEngine.getNews(false)
|
||||
EhCookieStore.copyCookie(EhUrl.DOMAIN_E, EhUrl.DOMAIN_EX, EhCookieStore.KEY_STAR)
|
||||
|
||||
// Sad panda check
|
||||
Settings.gallerySite = EhUrl.SITE_EX
|
||||
EhEngine.getUConfig()
|
||||
}.onFailure {
|
||||
Settings.selectSite = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
launch {
|
||||
runCatching {
|
||||
EhEngine.getUConfig()
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}
|
||||
// Sad panda check
|
||||
Settings.gallerySite = EhUrl.SITE_EX
|
||||
EhEngine.getUConfig()
|
||||
}.onFailure {
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
launch {
|
||||
runCatching {
|
||||
EhEngine.getUConfig()
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
}.join()
|
||||
}.isSuccess
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hippo.ehviewer.ui.login
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -25,7 +24,6 @@ import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.SideEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
@@ -34,7 +32,6 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.dimensionResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
@@ -42,20 +39,15 @@ import com.hippo.ehviewer.R
|
||||
import com.hippo.ehviewer.Settings
|
||||
import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.ui.FINISH_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import eu.kanade.tachiyomi.util.lang.launchNonCancellable
|
||||
|
||||
@Composable
|
||||
fun SelectSiteScreen() {
|
||||
val activity = LocalContext.current as Activity
|
||||
val coroutineScope = rememberCoroutineScope()
|
||||
var siteEx by remember { mutableStateOf(true) }
|
||||
|
||||
if (!Settings.selectSite) {
|
||||
SideEffect {
|
||||
Settings.needSignIn = false
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
val navController = LocalNavController.current
|
||||
|
||||
Column(
|
||||
modifier = Modifier.padding(WindowInsets.systemBars.asPaddingValues()).padding(horizontal = dimensionResource(R.dimen.keyline_margin)).padding(top = dimensionResource(R.dimen.keyline_margin)).fillMaxSize(),
|
||||
@@ -109,7 +101,6 @@ fun SelectSiteScreen() {
|
||||
Box(modifier = Modifier.padding(horizontal = 12.dp).padding(top = 4.dp, bottom = 20.dp).fillMaxWidth()) {
|
||||
Button(
|
||||
onClick = {
|
||||
Settings.selectSite = false
|
||||
Settings.needSignIn = false
|
||||
coroutineScope.launchNonCancellable {
|
||||
runCatching {
|
||||
@@ -124,7 +115,7 @@ fun SelectSiteScreen() {
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
activity.finish()
|
||||
navController.navigate(FINISH_ROUTE_NAME)
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
|
||||
@@ -62,6 +62,7 @@ import com.hippo.ehviewer.client.EhEngine
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.COOKIE_SIGN_IN_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.FINISH_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.SELECT_SITE_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.WEBVIEW_SIGN_IN_ROUTE_NAME
|
||||
@@ -134,12 +135,8 @@ fun SignInScreen(windowSizeClass: WindowSizeClass) {
|
||||
isProgressIndicatorVisible = false
|
||||
}
|
||||
}.onSuccess {
|
||||
withNonCancellableContext {
|
||||
postLogin()
|
||||
}
|
||||
withUIContext {
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
}
|
||||
val canEx = withNonCancellableContext { postLogin() }
|
||||
withUIContext { navController.navigate(if (canEx) SELECT_SITE_ROUTE_NAME else FINISH_ROUTE_NAME) }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,9 +243,9 @@ fun SignInScreen(windowSizeClass: WindowSizeClass) {
|
||||
}
|
||||
TextButton(
|
||||
onClick = {
|
||||
Settings.selectSite = false
|
||||
Settings.needSignIn = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
navController.navigate(FINISH_ROUTE_NAME)
|
||||
},
|
||||
) {
|
||||
Text(
|
||||
@@ -337,9 +334,9 @@ fun SignInScreen(windowSizeClass: WindowSizeClass) {
|
||||
}
|
||||
TextButton(
|
||||
onClick = {
|
||||
Settings.selectSite = false
|
||||
Settings.needSignIn = false
|
||||
Settings.gallerySite = EhUrl.SITE_E
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
navController.navigate(FINISH_ROUTE_NAME)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 4.dp),
|
||||
) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.hippo.ehviewer.client.EhCookieStore
|
||||
import com.hippo.ehviewer.client.EhUrl
|
||||
import com.hippo.ehviewer.client.EhUtils
|
||||
import com.hippo.ehviewer.ui.FINISH_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.LocalNavController
|
||||
import com.hippo.ehviewer.ui.SELECT_SITE_ROUTE_NAME
|
||||
import com.hippo.ehviewer.ui.legacy.DialogWebChromeClient
|
||||
@@ -101,16 +102,14 @@ fun WebviewSignInScreen() {
|
||||
if (getId && getHash) {
|
||||
present = true
|
||||
coroutineScope.launchIO {
|
||||
withNonCancellableContext {
|
||||
val canEx = withNonCancellableContext {
|
||||
cookies.forEach {
|
||||
addCookie(EhUrl.DOMAIN_EX, it)
|
||||
addCookie(EhUrl.DOMAIN_E, it)
|
||||
}
|
||||
postLogin()
|
||||
}
|
||||
withUIContext {
|
||||
navController.navigate(SELECT_SITE_ROUTE_NAME)
|
||||
}
|
||||
withUIContext { navController.navigate(if (canEx) SELECT_SITE_ROUTE_NAME else FINISH_ROUTE_NAME) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user