Skip to content

Commit

Permalink
Update project
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbel committed Dec 19, 2024
1 parent a700265 commit 851f27e
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,23 +9,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.toArgb
import androidx.core.net.toUri

fun openUrl(
resultContract: ManagedActivityResultLauncher<Intent, ActivityResult>,
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()) {}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
)

Expand All @@ -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)
)
}
Expand All @@ -74,8 +78,6 @@ fun AuthLinksBox(
private fun AuthLinksBoxPreview() {
MoviesTheme {
AuthLinksBox(
onTermsOfUseClick = {},
onPrivacyPolicyClick = {},
modifier = Modifier.background(MaterialTheme.colorScheme.primaryContainer)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
) {
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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
}

Expand All @@ -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
)
Expand Down Expand Up @@ -171,20 +173,28 @@ 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(
visible = error != null && error is CreateSessionWithLoginException,
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)
)
}
}
}
Expand All @@ -195,15 +205,19 @@ 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(
modifier = Modifier.size(24.dp),
strokeWidth = 2.dp
)
} else {
Text(text = stringResource(MoviesStrings.auth_sign_in))
Text(
text = stringResource(MoviesStrings.auth_sign_in)
)
}
}

Expand All @@ -213,21 +227,23 @@ 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(
modifier = Modifier.size(24.dp),
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)
Expand All @@ -248,7 +264,6 @@ private fun AuthScreenContentPreview() {
onSignInClick = { _,_ -> },
onLoginClick = {},
onResetRequestToken = {},
onUrlClick = {},
modifier = Modifier.background(MaterialTheme.colorScheme.primaryContainer)
)
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 851f27e

Please sign in to comment.