From 851f27e17b752a68d5743ab73f504b3ea42b8e2c Mon Sep 17 00:00:00 2001 From: michaelbel Date: Thu, 19 Dec 2024 10:25:34 +0300 Subject: [PATCH] Update project --- .../movies/common/browser/Browser.android.kt | 20 -------- .../movies/auth/ui/AuthRoute.android.kt | 35 ------------- .../michaelbel/movies/auth/ui/AuthLinksBox.kt | 14 +++--- .../michaelbel/movies/auth/ui/AuthRoute.kt | 18 ++++++- .../movies/auth/ui/AuthScreenContent.kt | 49 ++++++++++++------- .../movies/auth/ui/AuthRoute.ios.kt | 25 ---------- .../movies/auth/ui/AuthRoute.jvm.kt | 25 ---------- 7 files changed, 56 insertions(+), 130 deletions(-) delete mode 100644 feature/auth-impl/src/androidMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.android.kt delete mode 100644 feature/auth-impl/src/iosMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.ios.kt delete mode 100644 feature/auth-impl/src/jvmMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.jvm.kt diff --git a/core/common/src/androidMain/kotlin/org/michaelbel/movies/common/browser/Browser.android.kt b/core/common/src/androidMain/kotlin/org/michaelbel/movies/common/browser/Browser.android.kt index 7ce94e881..68a4238fc 100644 --- a/core/common/src/androidMain/kotlin/org/michaelbel/movies/common/browser/Browser.android.kt +++ b/core/common/src/androidMain/kotlin/org/michaelbel/movies/common/browser/Browser.android.kt @@ -1,9 +1,6 @@ package org.michaelbel.movies.common.browser -import android.content.Intent -import androidx.activity.compose.ManagedActivityResultLauncher import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.browser.customtabs.CustomTabColorSchemeParams import androidx.browser.customtabs.CustomTabsIntent @@ -12,23 +9,6 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.toArgb import androidx.core.net.toUri -fun openUrl( - resultContract: ManagedActivityResultLauncher, - toolbarColor: Int, - url: String -) { - val colorSchemeParams = CustomTabColorSchemeParams.Builder() - .setToolbarColor(toolbarColor) - .build() - val customTabsIntentBuilder = CustomTabsIntent.Builder().apply { - setDefaultColorSchemeParams(colorSchemeParams) - } - val customTabsIntent = customTabsIntentBuilder.build().apply { - intent.data = url.toUri() - } - resultContract.launch(customTabsIntent.intent) -} - @Composable actual fun navigateToUrl(url: String): () -> Unit { val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {} diff --git a/feature/auth-impl/src/androidMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.android.kt b/feature/auth-impl/src/androidMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.android.kt deleted file mode 100644 index 30b50dfa7..000000000 --- a/feature/auth-impl/src/androidMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.android.kt +++ /dev/null @@ -1,35 +0,0 @@ -package org.michaelbel.movies.auth.ui - -import androidx.activity.compose.rememberLauncherForActivityResult -import androidx.activity.result.contract.ActivityResultContracts -import androidx.compose.material3.MaterialTheme -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.toArgb -import org.michaelbel.movies.auth.AuthViewModel -import org.michaelbel.movies.common.browser.openUrl - -@Composable -actual fun AuthRoute( - onBackClick: () -> Unit, - modifier: Modifier, - viewModel: AuthViewModel -) { - val resultContract = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {} - val toolbarColor = MaterialTheme.colorScheme.primary.toArgb() - - AuthScreenContent( - error = viewModel.error, - signInLoading = viewModel.signInLoading, - loginLoading = viewModel.loginLoading, - requestToken = viewModel.requestToken, - onBackClick = onBackClick, - onSignInClick = { username, password -> - viewModel.onSignInClick(username, password, onBackClick) - }, - onLoginClick = viewModel::onLoginClick, - onResetRequestToken = viewModel::onResetRequestToken, - onUrlClick = { url -> openUrl(resultContract, toolbarColor, url) }, - modifier = modifier - ) -} \ No newline at end of file diff --git a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthLinksBox.kt b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthLinksBox.kt index a117f927a..373df5e6a 100644 --- a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthLinksBox.kt +++ b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthLinksBox.kt @@ -18,16 +18,20 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.ui.tooling.preview.Preview +import org.michaelbel.movies.common.browser.navigateToUrl +import org.michaelbel.movies.network.config.TMDB_PRIVACY_POLICY +import org.michaelbel.movies.network.config.TMDB_TERMS_OF_USE import org.michaelbel.movies.ui.ktx.clickableWithoutRipple import org.michaelbel.movies.ui.strings.MoviesStrings import org.michaelbel.movies.ui.theme.MoviesTheme @Composable fun AuthLinksBox( - onTermsOfUseClick: () -> Unit, - onPrivacyPolicyClick: () -> Unit, modifier: Modifier = Modifier ) { + val navigateToTermsOfUseUrl = navigateToUrl(TMDB_TERMS_OF_USE) + val navigateToPrivacyPolicyUrl = navigateToUrl(TMDB_PRIVACY_POLICY) + Column( modifier = modifier, verticalArrangement = Arrangement.Top, @@ -46,7 +50,7 @@ fun AuthLinksBox( text = stringResource(MoviesStrings.auth_terms_of_use), modifier = Modifier .padding(vertical = 16.dp) - .clickableWithoutRipple { onTermsOfUseClick() }, + .clickableWithoutRipple { navigateToTermsOfUseUrl() }, style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onPrimaryContainer) ) @@ -62,7 +66,7 @@ fun AuthLinksBox( text = stringResource(MoviesStrings.auth_privacy_policy), modifier = Modifier .padding(vertical = 16.dp) - .clickableWithoutRipple { onPrivacyPolicyClick() }, + .clickableWithoutRipple { navigateToPrivacyPolicyUrl() }, style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onPrimaryContainer) ) } @@ -74,8 +78,6 @@ fun AuthLinksBox( private fun AuthLinksBoxPreview() { MoviesTheme { AuthLinksBox( - onTermsOfUseClick = {}, - onPrivacyPolicyClick = {}, modifier = Modifier.background(MaterialTheme.colorScheme.primaryContainer) ) } diff --git a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.kt b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.kt index 97f9b7627..8b4be5daf 100644 --- a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.kt +++ b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.kt @@ -6,8 +6,22 @@ import org.koin.compose.viewmodel.koinViewModel import org.michaelbel.movies.auth.AuthViewModel @Composable -expect fun AuthRoute( +fun AuthRoute( onBackClick: () -> Unit, modifier: Modifier = Modifier, viewModel: AuthViewModel = koinViewModel() -) \ No newline at end of file +) { + AuthScreenContent( + error = viewModel.error, + signInLoading = viewModel.signInLoading, + loginLoading = viewModel.loginLoading, + requestToken = viewModel.requestToken, + onBackClick = onBackClick, + onSignInClick = { username, password -> + viewModel.onSignInClick(username, password, onBackClick) + }, + onLoginClick = viewModel::onLoginClick, + onResetRequestToken = viewModel::onResetRequestToken, + modifier = modifier + ) +} \ No newline at end of file diff --git a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthScreenContent.kt b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthScreenContent.kt index 3b24ba582..ebe5b9640 100644 --- a/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthScreenContent.kt +++ b/feature/auth-impl/src/commonMain/kotlin/org/michaelbel/movies/auth/ui/AuthScreenContent.kt @@ -39,6 +39,7 @@ import org.jetbrains.compose.resources.painterResource import org.jetbrains.compose.resources.stringResource import org.jetbrains.compose.ui.tooling.preview.Preview import org.michaelbel.movies.auth.ktx.text +import org.michaelbel.movies.common.browser.navigateToUrl import org.michaelbel.movies.common.exceptions.CreateSessionWithLoginException import org.michaelbel.movies.interactor.entity.Password import org.michaelbel.movies.interactor.entity.Username @@ -49,10 +50,8 @@ import org.michaelbel.movies.interactor.ktx.trim import org.michaelbel.movies.network.config.TMDB_AUTH_REDIRECT_URL import org.michaelbel.movies.network.config.TMDB_AUTH_URL_2 import org.michaelbel.movies.network.config.TMDB_AUTH_URL_3 -import org.michaelbel.movies.network.config.TMDB_PRIVACY_POLICY import org.michaelbel.movies.network.config.TMDB_REGISTER import org.michaelbel.movies.network.config.TMDB_RESET_PASSWORD -import org.michaelbel.movies.network.config.TMDB_TERMS_OF_USE import org.michaelbel.movies.network.config.TMDB_URL import org.michaelbel.movies.ui.accessibility.MoviesContentDescriptionCommon import org.michaelbel.movies.ui.compose.iconbutton.PasswordIcon @@ -72,7 +71,6 @@ internal fun AuthScreenContent( onSignInClick: (Username, Password) -> Unit, onLoginClick: () -> Unit, onResetRequestToken: () -> Unit, - onUrlClick: (String) -> Unit, modifier: Modifier = Modifier ) { val focusManager = LocalFocusManager.current @@ -82,9 +80,13 @@ internal fun AuthScreenContent( var password by rememberSaveable(saver = PasswordSaver) { mutableStateOf(Password("")) } var passwordVisible by rememberSaveable { mutableStateOf(false) } + val navigateToTmdbUrl = navigateToUrl(TMDB_URL) + val navigateToTmdbResetPasswordUrl = navigateToUrl(TMDB_RESET_PASSWORD) + val navigateToTmdbRegisterUrl = navigateToUrl(TMDB_REGISTER) + if (requestToken != null) { val signUrl = "$TMDB_AUTH_URL_2/$requestToken$TMDB_AUTH_URL_3$TMDB_AUTH_REDIRECT_URL" - onUrlClick(signUrl) + navigateToUrl(signUrl) onResetRequestToken() } @@ -108,7 +110,7 @@ internal fun AuthScreenContent( contentDescription = MoviesContentDescriptionCommon.None, modifier = Modifier .padding(top = 8.dp) - .clickableWithoutRipple { onUrlClick(TMDB_URL) } + .clickableWithoutRipple { navigateToTmdbUrl() } .align(Alignment.CenterHorizontally), tint = MaterialTheme.colorScheme.onPrimaryContainer ) @@ -171,11 +173,15 @@ internal fun AuthScreenContent( ) Row( - modifier = Modifier.padding(start = 8.dp, end = 8.dp), + modifier = Modifier.padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically ) { - TextButton(onClick = { onUrlClick(TMDB_REGISTER) }) { - Text(text = stringResource(MoviesStrings.auth_sign_up)) + TextButton( + onClick = { navigateToTmdbRegisterUrl() } + ) { + Text( + text = stringResource(MoviesStrings.auth_sign_up) + ) } AnimatedVisibility( @@ -183,8 +189,12 @@ internal fun AuthScreenContent( enter = fadeIn(), exit = fadeOut() ) { - TextButton(onClick = { onUrlClick(TMDB_RESET_PASSWORD) }) { - Text(text = stringResource(MoviesStrings.auth_reset_password)) + TextButton( + onClick = { navigateToTmdbResetPasswordUrl() } + ) { + Text( + text = stringResource(MoviesStrings.auth_reset_password) + ) } } } @@ -195,7 +205,9 @@ internal fun AuthScreenContent( .fillMaxWidth() .padding(start = 16.dp, top = 4.dp, end = 16.dp), enabled = username.isNotEmpty && password.isNotEmpty && !signInLoading, - colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.surfaceTint) + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.surfaceTint + ) ) { if (signInLoading) { CircularProgressIndicator( @@ -203,7 +215,9 @@ internal fun AuthScreenContent( strokeWidth = 2.dp ) } else { - Text(text = stringResource(MoviesStrings.auth_sign_in)) + Text( + text = stringResource(MoviesStrings.auth_sign_in) + ) } } @@ -213,7 +227,9 @@ internal fun AuthScreenContent( .fillMaxWidth() .padding(start = 16.dp, top = 8.dp, end = 16.dp), enabled = !loginLoading, - colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.surfaceTint) + colors = ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.surfaceTint + ) ) { if (loginLoading) { CircularProgressIndicator( @@ -221,13 +237,13 @@ internal fun AuthScreenContent( strokeWidth = 2.dp ) } else { - Text(text = stringResource(MoviesStrings.auth_login)) + Text( + text = stringResource(MoviesStrings.auth_login) + ) } } AuthLinksBox( - onTermsOfUseClick = { onUrlClick(TMDB_TERMS_OF_USE) }, - onPrivacyPolicyClick = { onUrlClick(TMDB_PRIVACY_POLICY) }, modifier = Modifier .fillMaxWidth() .padding(top = 16.dp) @@ -248,7 +264,6 @@ private fun AuthScreenContentPreview() { onSignInClick = { _,_ -> }, onLoginClick = {}, onResetRequestToken = {}, - onUrlClick = {}, modifier = Modifier.background(MaterialTheme.colorScheme.primaryContainer) ) } diff --git a/feature/auth-impl/src/iosMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.ios.kt b/feature/auth-impl/src/iosMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.ios.kt deleted file mode 100644 index b9620c10d..000000000 --- a/feature/auth-impl/src/iosMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.ios.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.michaelbel.movies.auth.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import org.michaelbel.movies.auth.AuthViewModel - -@Composable -actual fun AuthRoute( - onBackClick: () -> Unit, - modifier: Modifier, - viewModel: AuthViewModel -) { - AuthScreenContent( - error = null, - signInLoading = false, - loginLoading = false, - requestToken = null, - onBackClick = onBackClick, - onSignInClick = { _, _ -> }, - onLoginClick = {}, - onResetRequestToken = {}, - onUrlClick = {}, - modifier = modifier - ) -} \ No newline at end of file diff --git a/feature/auth-impl/src/jvmMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.jvm.kt b/feature/auth-impl/src/jvmMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.jvm.kt deleted file mode 100644 index b9620c10d..000000000 --- a/feature/auth-impl/src/jvmMain/kotlin/org/michaelbel/movies/auth/ui/AuthRoute.jvm.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.michaelbel.movies.auth.ui - -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import org.michaelbel.movies.auth.AuthViewModel - -@Composable -actual fun AuthRoute( - onBackClick: () -> Unit, - modifier: Modifier, - viewModel: AuthViewModel -) { - AuthScreenContent( - error = null, - signInLoading = false, - loginLoading = false, - requestToken = null, - onBackClick = onBackClick, - onSignInClick = { _, _ -> }, - onLoginClick = {}, - onResetRequestToken = {}, - onUrlClick = {}, - modifier = modifier - ) -} \ No newline at end of file