Skip to content

Commit

Permalink
fixed cc input bugs and validation
Browse files Browse the repository at this point in the history
  • Loading branch information
suyash01 committed Jan 20, 2024
1 parent 70d9bd2 commit 1dcf5f1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fun AddEditCCScreen(
},
prefix = {
if (viewModel.cardType.value == CardType.AMEX) {
Text("XXXX-XXXXXX-")
Text("XXXX-XXXXXX-X")
} else {
Text("XXXX-XXXX-XXXX-")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ class AddEditCCViewModel @Inject constructor(
_cardType.value = event.value
}
is AddEditCCEvent.EnteredLast4Digits -> {
if(event.value.length <= 4 && event.value.toIntOrNull() != null) {
if(event.value.isEmpty()) {
_last4Digits.value = event.value
}
if(event.value.length <= 4 && event.value.toIntOrNull() != null && event.value.toInt() >= 0) {
_last4Digits.value = event.value
}
}
Expand All @@ -92,7 +95,7 @@ class AddEditCCViewModel @Inject constructor(
_dueDate.value = event.value
}
val value: Int? = event.value.toIntOrNull()
if(value != null && event.value.toInt() < 31) {
if(value != null && event.value.toInt() > 0 && event.value.toInt() < 31) {
_dueDate.value = event.value
}
}
Expand All @@ -101,15 +104,15 @@ class AddEditCCViewModel @Inject constructor(
_billDate.value = event.value
}
val value: Int? = event.value.toIntOrNull()
if(value != null && value < 31) {
if(value != null && event.value.toInt() > 0 && value < 31) {
_billDate.value = event.value
}
}
is AddEditCCEvent.EnteredLimit -> {
if(event.value.isEmpty()) {
_limit.value = event.value
}
if(event.value.toIntOrNull() != null) {
if(event.value.toIntOrNull() != null && event.value.toInt() > 0) {
_limit.value = event.value
}
}
Expand Down Expand Up @@ -150,9 +153,9 @@ class AddEditCCViewModel @Inject constructor(
if(expiry.toIntOrNull() == null) return false
return when (expiry.length) {
1 -> expiry.toInt() < 2
2 -> expiry.toInt() < 13
2 -> expiry.toInt() in 1..12
3 -> expiry.toInt() < 130
4 -> expiry.toInt() < 1300
4 -> expiry.toInt() in 101.. 1299
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import androidx.compose.material.icons.filled.ArrowDownward
import androidx.compose.material.icons.filled.ArrowUpward
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.FilterList
import androidx.compose.material.icons.filled.Sort
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -58,9 +57,6 @@ fun CreditCardsScreen(
var isSortBottomSheetOpen by rememberSaveable {
mutableStateOf(false)
}
var isFilterBottomSheetOpen by rememberSaveable {
mutableStateOf(false)
}
var openDeleteConfirmationDialog by rememberSaveable {
mutableStateOf(false)
}
Expand All @@ -76,12 +72,6 @@ fun CreditCardsScreen(
contentDescription = "Sort Credit Cards"
)
}
IconButton(onClick = { isFilterBottomSheetOpen = true }) {
Icon(
imageVector = Icons.Filled.FilterList,
contentDescription = "Filter Credit Cards"
)
}
}
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ fun CreditCardItem(
) {
Text(
text = if (creditCard.cardType == CardType.AMEX) {
"XXXX-XXXXXX-${creditCard.last4Digits}"
"XXXX-XXXXXX-X${creditCard.last4Digits}"
} else {
"XXXX-XXXX-XXXX-${creditCard.last4Digits}"
},
Expand Down

0 comments on commit 1dcf5f1

Please sign in to comment.