-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactored the fragments of SetupUpiPinActivity to compose screen #1600
Closed
NiranjanNlc
wants to merge
1
commit into
openMF:dev
from
NiranjanNlc:setUpUpi_FragmentsToComposeScreen
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
116 changes: 116 additions & 0 deletions
116
core/ui/src/main/kotlin/org/mifospay/core/ui/ExpiryDateInput.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,116 @@ | ||
package org.mifos.mobilewallet.mifospay.ui | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.width | ||
import androidx.compose.foundation.layout.wrapContentHeight | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.focus.focusProperties | ||
import androidx.compose.ui.focus.focusRequester | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.TextRange | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
@Composable | ||
fun ExpiryDateInput( | ||
date: String, | ||
onDateChange: (String) -> Unit, | ||
onDone: () -> Unit, | ||
) { | ||
val (a, b, c) = FocusRequester.createRefs() | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(8.dp), verticalAlignment = Alignment.Bottom | ||
) { | ||
BasicTextField(modifier = Modifier | ||
.focusRequester(b) | ||
.focusProperties { | ||
next = c | ||
}, | ||
value = TextFieldValue(date, selection = TextRange(date.length)), | ||
onValueChange = { | ||
if (it.text.length == 3 && it.text[2] != '/') { | ||
val newText = it.text.substring(0, 2) + '/' + it.text.substring(2) | ||
onDateChange(newText) | ||
return@BasicTextField | ||
} | ||
if (it.text.length > date.length) { | ||
// If the user is typing at the third position, ensure it remains '/' | ||
if (it.text.length >= 3 && it.text[2] != '/') { | ||
val newText = it.text.substring(0, 2) + '/' + it.text.substring(3) | ||
onDateChange(newText) | ||
return@BasicTextField | ||
} | ||
} | ||
onDateChange(it.text) | ||
}, | ||
keyboardActions = KeyboardActions(onDone = { | ||
onDone() | ||
}), | ||
keyboardOptions = KeyboardOptions.Default.copy( | ||
keyboardType = KeyboardType.Number, imeAction = ImeAction.Done | ||
), | ||
decorationBox = { | ||
Row(horizontalArrangement = Arrangement.Center) { | ||
repeat(7) { index -> | ||
FormattedDateView( | ||
index = index, text = date | ||
) | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
@Composable | ||
fun FormattedDateView( | ||
index: Int, text: String | ||
) { | ||
val isFocused = text.length == index | ||
|
||
val char = when { | ||
index == 2 -> "/" | ||
index == text.length -> "_" | ||
index > text.length -> "_" | ||
else -> text[index].toString() | ||
} | ||
androidx.compose.material3.Text( | ||
modifier = Modifier | ||
.width(40.dp) | ||
.wrapContentHeight(align = Alignment.CenterVertically), | ||
text = char, | ||
style = MaterialTheme.typography.headlineSmall, | ||
color = if (isFocused) { | ||
Color.DarkGray | ||
} else { | ||
Color.LightGray | ||
}, | ||
textAlign = TextAlign.Center | ||
) | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun ExpiryDateInputPreview() { | ||
ExpiryDateInput(date = "", onDateChange = {}, onDone = {}) | ||
} | ||
|
66 changes: 66 additions & 0 deletions
66
core/ui/src/main/kotlin/org/mifospay/core/ui/HeadingTitile.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,66 @@ | ||
package org.mifos.mobilewallet.mifospay.ui | ||
|
||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Check | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import org.mifospay.core.designsystem.theme.MifosTheme | ||
|
||
|
||
@Composable | ||
fun VerifyStepHeader(text: String, isVerified: Boolean) { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth(), | ||
) { | ||
Text( | ||
text = text, | ||
color = Color(0xFF212121), | ||
fontSize = 17.sp, | ||
overflow = TextOverflow.Ellipsis, | ||
modifier = Modifier | ||
.padding(16.dp) | ||
.weight(1f), | ||
textAlign = TextAlign.Start, | ||
style = TextStyle(fontWeight = FontWeight.Bold) | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
IconButton( | ||
onClick = { }, | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) { | ||
if (isVerified) | ||
Icon( | ||
imageVector = Icons.Default.Check, | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
contentDescription = null, | ||
tint = if (isVerified) Color.Black else Color.Gray, | ||
modifier = Modifier.size(24.dp) | ||
) | ||
} | ||
} | ||
} | ||
@Preview | ||
@Composable | ||
fun VerifyStepHeaderVerifiedPreview() { | ||
MifosTheme { | ||
VerifyStepHeader(text = "Debit card Details ", isVerified = true) | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun VerifyStepHeaderUnverifiedPreview() { | ||
VerifyStepHeader(text = "Enter OTP ", isVerified = false) | ||
} |
125 changes: 125 additions & 0 deletions
125
core/ui/src/main/kotlin/org/mifospay/core/ui/OtpTextField.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,125 @@ | ||
package org.mifos.mobilewallet.mifospay.ui | ||
|
||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.foundation.text.BasicTextField | ||
import androidx.compose.foundation.text.KeyboardActions | ||
import androidx.compose.foundation.text.KeyboardOptions | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.text.TextRange | ||
import androidx.compose.ui.text.input.ImeAction | ||
import androidx.compose.ui.text.input.KeyboardType | ||
import androidx.compose.ui.text.input.TextFieldValue | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
@Composable | ||
fun OtpTextField( | ||
modifier: Modifier = Modifier, | ||
realOtp: String = "", | ||
otpCount: Int = 4, | ||
onOtpTextCorrectlyEntered: () -> Unit | ||
) { | ||
var otpText by remember { mutableStateOf("") } | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var isError by remember { mutableStateOf(false) } | ||
Column( | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(16.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
|
||
BasicTextField(modifier = modifier, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mfoutlinedtextfield ? |
||
value = TextFieldValue(otpText, selection = TextRange(otpText.length)), | ||
onValueChange = { | ||
otpText = it.text | ||
isError = false | ||
if (otpText.length == otpCount) { | ||
if (otpText != realOtp) { | ||
isError = true | ||
} else { | ||
onOtpTextCorrectlyEntered.invoke() | ||
} | ||
} | ||
}, | ||
keyboardActions = KeyboardActions(onDone = { | ||
if (otpText != realOtp) { | ||
isError = true | ||
} else { | ||
onOtpTextCorrectlyEntered.invoke() | ||
} | ||
println("OTP: $otpText and $isError") | ||
}), | ||
keyboardOptions = KeyboardOptions.Default.copy( | ||
keyboardType = KeyboardType.Number, imeAction = ImeAction.Done | ||
), | ||
decorationBox = { | ||
Row(horizontalArrangement = Arrangement.Center) { | ||
repeat(otpCount) { index -> | ||
CharView( | ||
index = index, text = otpText | ||
) | ||
Spacer(modifier = Modifier.width(8.dp)) | ||
} | ||
} | ||
}) | ||
if (isError) { | ||
// display erro message in text | ||
Text( | ||
text = "Invalid OTP", | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
style = MaterialTheme.typography.bodyMedium, | ||
color = Color.Red, | ||
textAlign = TextAlign.Center, | ||
modifier = Modifier.padding(top = 8.dp) | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun CharView( | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
index: Int, text: String | ||
) { | ||
val isFocused = text.length == index | ||
val char = when { | ||
index == text.length -> "_" | ||
index > text.length -> "_" | ||
else -> text[index].toString() | ||
} | ||
Text( | ||
modifier = Modifier | ||
.width(40.dp) | ||
.wrapContentHeight(align = Alignment.CenterVertically), | ||
text = char, | ||
style = MaterialTheme.typography.headlineSmall, | ||
color = if (isFocused) { | ||
Color.DarkGray | ||
} else { | ||
Color.LightGray | ||
}, | ||
textAlign = TextAlign.Center | ||
) | ||
NiranjanNlc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Preview | ||
@Composable | ||
fun prviewOtpTextField() { | ||
OtpTextField( | ||
realOtp = "1234", | ||
otpCount = 4, | ||
onOtpTextCorrectlyEntered = {} | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use MFoutlined text field?