Skip to content

Commit

Permalink
Merge branch 'PP-680-iOS-Skonto-screen-add-input-fields-validation' i…
Browse files Browse the repository at this point in the history
…nto PP-906-iOS-RA-Skonto-Set-dynamic-final-amount-to-pay-from-RA-into-Skonto-screen
  • Loading branch information
mrkulik committed Nov 6, 2024
2 parents a4b63ea + 7271743 commit 7978ec5
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PriceTextField: UITextField, UITextFieldDelegate {

override func paste(_ sender: Any?) {
if let pastedText = UIPasteboard.general.string {
let filteredText = filterInput(pastedText)
let filteredText = filterTextInput(pastedText)
let cleanInput = String(filteredText.prefix(7))
if let decimal = Decimal(string: cleanInput) {
let formattedText = formatDecimal(decimal)
Expand All @@ -45,7 +45,7 @@ class PriceTextField: UITextField, UITextFieldDelegate {
}

let updatedText = text.replacingCharacters(in: textRange, with: string)
let filteredText = filterInput(updatedText)
let filteredText = filterTextInput(updatedText)

guard let decimal = Decimal(string: filteredText) else {
return false
Expand All @@ -57,7 +57,7 @@ class PriceTextField: UITextField, UITextFieldDelegate {
return false
}

private func filterInput(_ text: String) -> String {
private func filterTextInput(_ text: String) -> String {
return text.trimmingCharacters(in: .whitespaces).filter { $0.isNumber }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SkontoViewModel {

private (set) var documentPagesViewModel: SkontoDocumentPagesViewModel?

private var maximumAmountToPayValue: Decimal
private var maximumAmountToPayValue: Decimal = 99999.99

var finalAmountToPay: Price {
return isSkontoApplied ? skontoAmountToPay : amountToPay
Expand Down Expand Up @@ -131,11 +131,9 @@ class SkontoViewModel {
weak var delegate: SkontoViewModelDelegate?

init(skontoDiscounts: SkontoDiscounts,
isWithDiscountSwitchAvailable: Bool = true,
maximumAmountToPayValue: Decimal = 99999.99) {
isWithDiscountSwitchAvailable: Bool = true) {
self.skontoDiscounts = skontoDiscounts
self.isWithDiscountSwitchAvailable = isWithDiscountSwitchAvailable
self.maximumAmountToPayValue = maximumAmountToPayValue

// For now multiple Skonto discounts aren't handle
let skontoDiscountDetails = skontoDiscounts.discounts[0]
Expand All @@ -158,11 +156,11 @@ class SkontoViewModel {
}

func setSkontoAmountToPayPrice(_ price: String) {
setPrice(
price,
maxValue: amountToPay.value,
errorMessage: NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.withdiscount.validation",
comment: "Discounted value cannot exceed initial...")
let errorMessage = NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.withdiscount.validation",
comment: "Discounted value cannot exceed...")
setPrice(price,
maxValue: amountToPay.value,
errorMessage: errorMessage
) { validatedPrice in
skontoAmountToPay = validatedPrice
updateDocumentPagesModelData()
Expand All @@ -171,11 +169,11 @@ class SkontoViewModel {
}

func setAmountToPayPrice(_ price: String) {
setPrice(
price,
maxValue: maximumAmountToPayValue,
errorMessage: NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.withoutdiscount.validation",
comment: "Your transfer limit has been exceeded: %@")
let errorMessage = NSLocalizedStringPreferredGiniBankFormat("ginibank.skonto.withoutdiscount.validation",
comment: "Your transfer limit has been exceed...")
setPrice(price,
maxValue: maximumAmountToPayValue,
errorMessage: errorMessage
) { validatedPrice in
amountToPay = validatedPrice
recalculateAmountToPayWithSkonto()
Expand All @@ -188,7 +186,10 @@ class SkontoViewModel {
maximumAmountToPayValue = value
}

private func setPrice(_ price: String, maxValue: Decimal, errorMessage: String, completion: (Price) -> Void) {
private func setPrice(_ price: String,
maxValue: Decimal,
errorMessage: String,
completion: (Price) -> Void) {
let validationMessage = validatePrice(price, maxValue: maxValue, errorMessage: errorMessage)
if let validationMessage {
setErrorMessage(validationMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,16 @@ extension SkontoViewController {
return
}

let contentOffset = keyboardFrame.height - proceedContainerView.frame.height + Constants.containerPadding
let targetView = viewModel.isSkontoApplied ? withDiscountContainerView : withoutDiscountContainerView
let targetFrameInScrollView = scrollView.convert(targetView.frame, from: targetView.superview)
let keyboardHeight = keyboardFrame.height
let scrollViewBottomMarginDifference = (scrollView.superview?.bounds.height ?? 0) - scrollView.frame.maxY
let keyboardOffsetOverProceedView = keyboardHeight + Constants.containerPadding - scrollViewBottomMarginDifference
let contentOffsetY = max(0, targetFrameInScrollView.maxY - scrollView.bounds.height + keyboardOffsetOverProceedView)
UIView.animate(withDuration: animationDuration) {
self.scrollView.contentInset.bottom = contentOffset
self.scrollView.scrollIndicatorInsets.bottom = contentOffset
self.scrollView.contentInset.bottom = keyboardHeight
self.scrollView.scrollIndicatorInsets.bottom = keyboardHeight
self.scrollView.setContentOffset(CGPoint(x: 0, y: contentOffsetY), animated: true)
}
}

Expand Down

0 comments on commit 7978ec5

Please sign in to comment.