diff --git a/MonitorizareVot.xcodeproj/project.pbxproj b/MonitorizareVot.xcodeproj/project.pbxproj index d55257e..c89aa22 100644 --- a/MonitorizareVot.xcodeproj/project.pbxproj +++ b/MonitorizareVot.xcodeproj/project.pbxproj @@ -1242,7 +1242,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MonitorizareVot/MonitorizareVot.entitlements; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 4; INFOPLIST_FILE = MonitorizareVot/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1261,7 +1261,7 @@ CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = MonitorizareVot/MonitorizareVot.entitlements; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 2; + CURRENT_PROJECT_VERSION = 4; INFOPLIST_FILE = MonitorizareVot/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/MonitorizareVot/Base.lproj/Localizable.strings b/MonitorizareVot/Base.lproj/Localizable.strings index 6f50cc3..c222940 100644 --- a/MonitorizareVot/Base.lproj/Localizable.strings +++ b/MonitorizareVot/Base.lproj/Localizable.strings @@ -55,6 +55,7 @@ "Error.SaveNoteFailed" = "We couldn't save your note. Please try again later."; "Error.UploadNoteFailed" = "We couldn't upload your note. We will retry later."; "Error.SelectCountyFirst" = "Please select your county / district first."; +"Error.IncorrectStationNumber" = "Incorrect station number. Please double check the county and provided section number"; "Info.DataNotSyncronised" = "It appears that some of the questions have not been syncronised. Tap the button below to send the answers again"; diff --git a/MonitorizareVot/PollingStation/SectionPickerViewController.swift b/MonitorizareVot/PollingStation/SectionPickerViewController.swift index 08f472e..5ff4827 100644 --- a/MonitorizareVot/PollingStation/SectionPickerViewController.swift +++ b/MonitorizareVot/PollingStation/SectionPickerViewController.swift @@ -156,6 +156,12 @@ class SectionPickerViewController: MVViewController { } func saveAndContinue() { + guard model.isSectionNumberCorrect else { + let alert = UIAlertController.error(withMessage: "Error.IncorrectStationNumber".localized) + present(alert, animated: true, completion: nil) + return + } + model.persist { [weak self] error in if let error = error { let alert = UIAlertController.error(withMessage: error.localizedDescription) @@ -177,21 +183,21 @@ class SectionPickerViewController: MVViewController { extension SectionPickerViewController: UITextFieldDelegate { func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { if let updated = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) { - if let number = Int(updated), - let maxStationNumber = model.maximumStationNumber, - number <= maxStationNumber { + if let number = Int(updated) { model.sectionId = number - return true } else if updated == "" { model.sectionId = nil - return true + } else { + return false } + return true } return false } func textFieldShouldReturn(_ textField: UITextField) -> Bool { textField.resignFirstResponder() + if model.canContinue { saveAndContinue() } diff --git a/MonitorizareVot/PollingStation/SectionPickerViewModel.swift b/MonitorizareVot/PollingStation/SectionPickerViewModel.swift index 05ac8f1..bdb8ba5 100644 --- a/MonitorizareVot/PollingStation/SectionPickerViewModel.swift +++ b/MonitorizareVot/PollingStation/SectionPickerViewModel.swift @@ -37,6 +37,10 @@ class SectionPickerViewModel: NSObject { return countyCode != nil && sectionId != nil } + var isSectionNumberCorrect: Bool { + return sectionId != nil && maximumStationNumber != nil && sectionId! <= maximumStationNumber! + } + var selectedCountyName: String? { guard let code = countyCode else { return nil } return getPollingStation(byCounty: code)?.name.capitalized diff --git a/MonitorizareVot/TableCells/FormSetTableCell.swift b/MonitorizareVot/TableCells/FormSetTableCell.swift index dc9e9b8..43fd09a 100644 --- a/MonitorizareVot/TableCells/FormSetTableCell.swift +++ b/MonitorizareVot/TableCells/FormSetTableCell.swift @@ -58,7 +58,7 @@ class FormSetTableCell: UITableViewCell { codeLabel.text = "(\(model.code.uppercased()))" progressWidthConstraint.constant = -((1-model.progress) * cardContainer.frame.size.width) answeredLabel.text = model.answeredOutOfTotalQuestions - progressContainer.isHidden = false + progressContainer.isHidden = model.progress == 0 outerCardContainer.layoutIfNeeded() } diff --git a/MonitorizareVot/ro.lproj/Localizable.strings b/MonitorizareVot/ro.lproj/Localizable.strings index 8a0ee12..63d54f6 100644 --- a/MonitorizareVot/ro.lproj/Localizable.strings +++ b/MonitorizareVot/ro.lproj/Localizable.strings @@ -55,6 +55,7 @@ "Error.SaveNoteFailed" = "Nu am reușit să salvăm nota. Te rugăm să încerci mai târziu."; "Error.UploadNoteFailed" = "Nu am reușit să trimitem la server nota. Vom încerca mai târziu."; "Error.SelectCountyFirst" = "Te rugăm să alegi județul/sectorul pentru a putea alege secția"; +"Error.IncorrectStationNumber" = "Număr secție incorect. Te rugăm să verifici corectitudinea combinației județ - număr secție"; "Info.DataNotSyncronised" = "Se pare că unele răspunsuri nu au fost sincronizate cu serverul. Apasă butonul acesta pentru a le retrimite";