-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee925dd
commit 0d53fc6
Showing
5 changed files
with
217 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...java/com/geekymusketeers/uncrack/presentation/auth/forgotPassword/ForgotPasswordScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.geekymusketeers.uncrack.presentation.auth.forgotPassword | ||
|
||
import android.os.Bundle | ||
import android.widget.Toast | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.SystemBarStyle | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
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.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.derivedStateOf | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.livedata.observeAsState | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.toArgb | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.geekymusketeers.uncrack.R | ||
import com.geekymusketeers.uncrack.components.UCButton | ||
import com.geekymusketeers.uncrack.components.UCTextField | ||
import com.geekymusketeers.uncrack.presentation.auth.AuthViewModel | ||
import com.geekymusketeers.uncrack.ui.theme.DMSansFontFamily | ||
import com.geekymusketeers.uncrack.ui.theme.UnCrackTheme | ||
import com.geekymusketeers.uncrack.util.UtilsKt | ||
import com.geekymusketeers.uncrack.util.UtilsKt.findActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class ForgotPasswordScreen : ComponentActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
|
||
enableEdgeToEdge( | ||
statusBarStyle = SystemBarStyle.light( | ||
Color.White.toArgb(), Color.White.toArgb() | ||
), | ||
navigationBarStyle = SystemBarStyle.light( | ||
Color.White.toArgb(), Color.White.toArgb() | ||
) | ||
) | ||
super.onCreate(savedInstanceState) | ||
|
||
setContent { | ||
UnCrackTheme { | ||
ForgotPasswordContent() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ForgotPasswordContent( | ||
modifier: Modifier = Modifier, | ||
viewModel: AuthViewModel = hiltViewModel() | ||
) { | ||
val context = LocalContext.current | ||
var email by rememberSaveable { mutableStateOf("") } | ||
val enableSendBtn by remember { derivedStateOf { UtilsKt.validateEmail(email) } } | ||
val resetPasswordRequestLiveData by viewModel.resetPassword.observeAsState() | ||
|
||
LaunchedEffect(resetPasswordRequestLiveData) { | ||
if (resetPasswordRequestLiveData == true) { | ||
context.findActivity()?.let { | ||
Toast.makeText(it, "Email sent", Toast.LENGTH_SHORT).show() | ||
it.finish() | ||
} | ||
} | ||
} | ||
|
||
Scaffold( | ||
modifier = modifier.fillMaxSize() | ||
) { paddingValues -> | ||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(paddingValues) | ||
.padding(16.dp) | ||
) { | ||
|
||
Text( | ||
text = stringResource(R.string.forgot_password), | ||
fontSize = 40.sp, | ||
fontWeight = FontWeight.Bold, | ||
fontFamily = DMSansFontFamily, | ||
color = Color.Black | ||
) | ||
|
||
Spacer(modifier = Modifier.height(60.dp)) | ||
|
||
UCTextField( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
headerText = stringResource(R.string.enter_your_registered_mail), | ||
value = email, | ||
onValueChange = { email = it } | ||
) | ||
|
||
Spacer(modifier = Modifier.weight(1f)) | ||
|
||
UCButton( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
text = stringResource(R.string.send_reset_link), | ||
onClick = { | ||
viewModel.resetPassword(email) | ||
}, | ||
enabled = enableSendBtn | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
app/src/main/java/com/geekymusketeers/uncrack/util/ModifierExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.geekymusketeers.uncrack.util | ||
|
||
import androidx.compose.foundation.Indication | ||
import androidx.compose.foundation.LocalIndication | ||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.combinedClickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.composed | ||
import androidx.compose.ui.platform.debugInspectorInfo | ||
import androidx.compose.ui.semantics.Role | ||
|
||
/** | ||
* A custom [Modifier.clickable] with no ripple effect. | ||
* | ||
* Configure component to receive clicks via input or accessibility "click" event. | ||
* | ||
* Add this modifier to the element to make it clickable within its bounds and show an indication | ||
* as specified in [indication] parameter. | ||
* | ||
* If you need to support double click or long click alongside the single click, consider | ||
* using [combinedClickable]. | ||
* | ||
* @sample androidx.compose.foundation.samples.ClickableSample | ||
* | ||
* @param indication indication to be shown when modified element is pressed. By default, | ||
* indication from [LocalIndication] will be used. Pass `null` to show no indication, or | ||
* current value from [LocalIndication] to show theme default | ||
* @param enabled Controls the enabled state. When `false`, [onClick], and this modifier will | ||
* appear disabled for accessibility services | ||
* @param onClickLabel semantic / accessibility label for the [onClick] action | ||
* @param role the type of user interface element. Accessibility services might use this | ||
* to describe the element or do customizations | ||
* @param onClick will be called when user clicks on the element | ||
*/ | ||
fun Modifier.onClick( | ||
indication: Indication? = null, | ||
enabled: Boolean = true, | ||
onClickLabel: String? = null, | ||
role: Role? = null, | ||
onClick: () -> Unit | ||
) = this.composed(inspectorInfo = debugInspectorInfo { | ||
name = "onClickModifier" | ||
value = enabled | ||
}) { | ||
val interactionSource = remember { MutableInteractionSource() } | ||
clickable( | ||
indication = indication, | ||
interactionSource = interactionSource, | ||
enabled = enabled, | ||
onClickLabel = onClickLabel, | ||
role = role | ||
) { | ||
onClick.invoke() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters