Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ dependencies {
implementation 'androidx.compose.material:material-icons-extended:1.7.8'
implementation "androidx.compose.animation:animation-core:1.10.0"
implementation 'androidx.fragment:fragment-ktx:1.8.9'
implementation("androidx.browser:browser:1.8.0")

// Test
implementation 'androidx.lifecycle:lifecycle-runtime-compose:2.10.0'
Expand Down
65 changes: 50 additions & 15 deletions app/src/main/java/com/xpeho/xpeapp/ui/page/LoginPage.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.xpeho.xpeapp.ui.page

import android.net.Uri
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -17,11 +21,15 @@
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
Expand All @@ -37,11 +45,9 @@
import com.xpeho.xpeho_ui_android.ClickyButton
import com.xpeho.xpeho_ui_android.InputText
import com.xpeho.xpeho_ui_android.foundations.Colors as XpehoColors
import androidx.core.net.toUri
import com.xpeho.xpeapp.BuildConfig

/**
* Login page
* @param onLoginSuccess: Callback when login is successful
*/
@Composable
fun LoginPage(onLoginSuccess: () -> Unit) {
val wordpressViewModel = viewModel<WordpressViewModel>(
Expand All @@ -52,14 +58,12 @@

sendAnalyticsEvent(AnalyticsEventName.LOGIN_PAGE)

// If login is successful, notify of login success
LaunchedEffect(wordpressViewModel.wordpressState) {
if (wordpressViewModel.wordpressState is WordpressUiState.SUCCESS) {
onLoginSuccess()
}
}

// If login fails, show error dialog
if (wordpressViewModel.wordpressState is WordpressUiState.ERROR) {
CustomDialog(
title = stringResource(id = R.string.login_page_error_title),
Expand All @@ -76,15 +80,12 @@
private fun LoginPageContent(
wordpressViewModel: WordpressViewModel,
) {
LoginPageContentColumn(
wordpressViewModel,
)
}
val context = LocalContext.current
val focusManager = LocalFocusManager.current

// Configuration de l'URL pour le reset de mot de passe
val pwdResetUrl = "https://xpeapp-pwd-reset.web.app/"

@Composable
private fun LoginPageContentColumn(
wordpressViewModel: WordpressViewModel,
) {
Column(
modifier = Modifier
.fillMaxSize()
Expand All @@ -101,9 +102,43 @@
LoginPageButton(
wordpressViewModel,
)
Spacer(modifier = Modifier.height(26.dp))
ForgotPasswordText()
}
}

@Composable
private fun ForgotPasswordText() {
val context = LocalContext.current
val focusManager = LocalFocusManager.current

Text(
text = "Mot de passe oublié ?",
color = XpehoColors.CONTENT_COLOR,
fontSize = 16.sp,
fontWeight = FontWeight.Bold,
modifier = Modifier
.clickable {
focusManager.clearFocus()

val defaultColors = CustomTabColorSchemeParams.Builder()
.setToolbarColor(XpehoColors.XPEHO_COLOR.toArgb())
.build()

val customTabsIntent = CustomTabsIntent.Builder()
.setDefaultColorSchemeParams(defaultColors)
.setShowTitle(true)
.setShareState(CustomTabsIntent.SHARE_STATE_OFF)
.setUrlBarHidingEnabled(true)
.build()

// Utilisation de l'URL depuis le BuildConfig comme dans ton code
customTabsIntent.launchUrl(context, BuildConfig.PASSWORD_RESET_URL.toUri())
}
.padding(8.dp)
)
}

@Composable
private fun LoginPageIcon() {
Icon(
Expand Down Expand Up @@ -207,4 +242,4 @@
@Composable
fun ErrorTextMessagePreview() {
ErrorTextMessage(message = "Veuillez entrer votre email")
}
}
Loading