Basic CookieSignInScreen layout

This commit is contained in:
tarsin committed 2023-01-11 09:23:10 +08:00
1 parent b01f6ef8d3
commit f48eb55516
3 files changed
+151 -9

No files matched your search

@@ -8,6 +8,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.themeadapter.material3.Mdc3Theme
import com.hippo.ehviewer.ui.compose.CookieSignInScene
import com.hippo.ehviewer.ui.compose.SignInScreen
class LoginActivity : ComponentActivity() {
@@ -19,7 +20,7 @@ class LoginActivity : ComponentActivity() {
NavHost(navController = navController, startDestination = SIGN_IN_ROUTE_NAME) {
composable(SIGN_IN_ROUTE_NAME) {
SignInScreen()
SignInScreen(navController)
}
composable(WEBVIEW_SIGN_IN_ROUTE_NAME) {
@@ -27,7 +28,7 @@ class LoginActivity : ComponentActivity() {
}
composable(COOKIE_SIGN_IN_ROUTE_NAME) {
CookieSignInScene(navController)
}
composable(SELECT_SITE_ROUTE_NAME) {
@@ -0,0 +1,109 @@
package com.hippo.ehviewer.ui.compose
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavController
import com.hippo.ehviewer.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CookieSignInScene(navController: NavController) {
Box(
contentAlignment = Alignment.Center
) {
Column(
Modifier
.padding(dimensionResource(id = R.dimen.keyline_margin))
.fillMaxSize()
.verticalScroll(rememberScrollState()),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.drawable.v_cookie_brown_x48),
contentDescription = null,
modifier = Modifier.padding(dimensionResource(id = R.dimen.keyline_margin))
)
Text(
text = stringResource(id = R.string.cookie_explain),
modifier = Modifier
.padding(
horizontal = 32.dp,
vertical = dimensionResource(id = R.dimen.keyline_margin)
),
fontSize = 16.sp
)
OutlinedTextField(
value = "",
onValueChange = { },
Modifier.width(dimensionResource(id = R.dimen.single_max_width)),
label = {
Text(text = "")
},
singleLine = true
)
OutlinedTextField(
value = "",
onValueChange = { },
Modifier.width(dimensionResource(id = R.dimen.single_max_width)),
label = {
Text(text = "")
},
singleLine = true
)
OutlinedTextField(
value = "",
onValueChange = { },
Modifier.width(dimensionResource(id = R.dimen.single_max_width)),
label = {
Text(text = "")
},
singleLine = true
)
Spacer(modifier = Modifier.weight(1f))
Button(
onClick = { /*TODO*/ },
Modifier.fillMaxWidth()
) {
Text(text = stringResource(id = android.R.string.ok))
}
TextButton(onClick = { /*TODO*/ }) {
Text(
text = buildAnnotatedString {
withStyle(
style = SpanStyle(textDecoration = TextDecoration.Underline)
) {
append(stringResource(id = R.string.from_clipboard))
}
},
modifier = Modifier
.padding(horizontal = 8.dp)
)
}
}
}
}
@@ -32,13 +32,21 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import com.hippo.ehviewer.R
import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.UrlOpener
import com.hippo.ehviewer.client.EhClient
import com.hippo.ehviewer.client.EhUrl
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.ui.LoginActivity.Companion.COOKIE_SIGN_IN_ROUTE_NAME
import com.hippo.ehviewer.ui.LoginActivity.Companion.SELECT_SITE_ROUTE_NAME
import com.hippo.ehviewer.ui.LoginActivity.Companion.WEBVIEW_SIGN_IN_ROUTE_NAME
import com.hippo.ehviewer.ui.scene.getProfile
import com.hippo.util.ExceptionUtils
import eu.kanade.tachiyomi.util.lang.launchIO
@@ -49,7 +57,7 @@ import rikka.core.util.ContextUtils.requireActivity
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SignInScreen() {
fun SignInScreen(navController: NavController) {
val coroutineScope = rememberCoroutineScope()
val focusManager = LocalFocusManager.current
var isProgressIndicatorVisible by remember { mutableStateOf(false) }
@@ -187,24 +195,48 @@ fun SignInScreen() {
Modifier.padding(horizontal = 4.dp)
) {
TextButton(
onClick = { /*TODO*/ },
onClick = { navController.navigate(WEBVIEW_SIGN_IN_ROUTE_NAME) },
Modifier.padding(horizontal = 8.dp)
) {
Text(text = stringResource(id = R.string.sign_in_via_webview))
Text(
text = buildAnnotatedString {
withStyle(
style = SpanStyle(textDecoration = TextDecoration.Underline)
) {
append(stringResource(id = R.string.sign_in_via_webview))
}
}
)
}
TextButton(
onClick = { /*TODO*/ },
onClick = { navController.navigate(COOKIE_SIGN_IN_ROUTE_NAME) },
Modifier.padding(horizontal = 8.dp)
) {
Text(text = stringResource(id = R.string.sign_in_via_cookies))
Text(
text = buildAnnotatedString {
withStyle(
style = SpanStyle(textDecoration = TextDecoration.Underline)
) {
append(stringResource(id = R.string.sign_in_via_cookies))
}
}
)
}
}
TextButton(
onClick = { /*TODO*/ },
onClick = { navController.navigate(SELECT_SITE_ROUTE_NAME) },
) {
Text(text = stringResource(id = R.string.tourist_mode))
Text(
text = buildAnnotatedString {
withStyle(
style = SpanStyle(textDecoration = TextDecoration.Underline)
) {
append(stringResource(id = R.string.tourist_mode))
}
}
)
}
}
if (isProgressIndicatorVisible) {