mirror of
https://github.com/confirmedcode/Lockdown-iOS.git
synced 2025-12-21 12:14:02 +01:00
remove skip button and change first step logic
This commit is contained in:
@@ -20,10 +20,6 @@ class StepsViewController: UIViewController, StepsViewProtocol {
|
||||
view.leftNavButton.setImage(UIImage(systemName: "chevron.left"), for: .normal)
|
||||
view.leftNavButton.addTarget(self, action: #selector(backButtonClicked), for: .touchUpInside)
|
||||
view.leftNavButton.tintColor = .label
|
||||
view.rightNavButton.setTitle(NSLocalizedString("Skip", comment: ""), for: .normal)
|
||||
view.rightNavButton.addTarget(self, action: #selector(skipClicked), for: .touchUpInside)
|
||||
view.rightNavButton.titleLabel?.font = .regularLockdownFont(size: 16)
|
||||
view.rightNavButton.tintColor = .label
|
||||
return view
|
||||
}()
|
||||
|
||||
@@ -90,8 +86,7 @@ class StepsViewController: UIViewController, StepsViewProtocol {
|
||||
}
|
||||
contentView = staticTableView
|
||||
stepsView.currentStep = viewModel.currentStepIndex
|
||||
navigationView.rightNavButton.isHidden = !viewModel.showSkipButton
|
||||
actionButton.setTitle(viewModel.actionTitle, for: .normal)
|
||||
updateNextButton()
|
||||
}
|
||||
|
||||
func close(completion: (() -> Void)?) {
|
||||
@@ -114,16 +109,18 @@ class StepsViewController: UIViewController, StepsViewProtocol {
|
||||
present(alert, animated: true)
|
||||
}
|
||||
|
||||
func updateNextButton() {
|
||||
actionButton.setTitle(viewModel.actionTitle, for: .normal)
|
||||
actionButton.isEnabled = viewModel.isStepReady
|
||||
actionButton.backgroundColor = viewModel.isStepReady ? .tunnelsBlue : .disabledGray
|
||||
}
|
||||
|
||||
// MARK: - actions
|
||||
|
||||
@objc private func backButtonClicked() {
|
||||
viewModel.backPressed()
|
||||
}
|
||||
|
||||
@objc private func skipClicked() {
|
||||
viewModel.skipStep()
|
||||
}
|
||||
|
||||
@objc private func actionClicked() {
|
||||
viewModel.performStepAction()
|
||||
}
|
||||
|
||||
@@ -123,12 +123,4 @@ struct QuestionModel {
|
||||
private func stringFor(_ boolValue: Bool) -> String {
|
||||
boolValue ? NSLocalizedString("Yes", comment: "") : NSLocalizedString("No", comment: "")
|
||||
}
|
||||
|
||||
var isAllRequiredQuestionsAnswered: Bool {
|
||||
fromCountry != nil
|
||||
&& isHappeningWifiIssue != nil
|
||||
&& isHappenningCellularIssue != nil
|
||||
&& haveOtherFirewall != nil
|
||||
&& haveOtherVPN != nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ import UIKit
|
||||
|
||||
class BaseStepViewModel {
|
||||
var staticTableView: StaticTableView?
|
||||
var isSkiped = false
|
||||
|
||||
func contentView() -> UITableView {
|
||||
let staticTableView = StaticTableView()
|
||||
|
||||
@@ -18,9 +18,7 @@ class QuestionsStepViewModel: BaseStepViewModel, StepViewModelProtocol {
|
||||
)
|
||||
}
|
||||
|
||||
var isFilled: Bool {
|
||||
model.isAllRequiredQuestionsAnswered
|
||||
}
|
||||
var isFilled = true
|
||||
|
||||
private var model = QuestionModel() {
|
||||
didSet {
|
||||
|
||||
@@ -10,6 +10,7 @@ import UIKit
|
||||
|
||||
protocol StepsViewProtocol: AnyObject {
|
||||
func changeContent()
|
||||
func updateNextButton()
|
||||
func close(completion: (() -> Void)?)
|
||||
func showSelectCountry(with viewModel: SelectCountryViewModelProtocol)
|
||||
func showAlert(_ title: String?, message: String?)
|
||||
@@ -17,7 +18,6 @@ protocol StepsViewProtocol: AnyObject {
|
||||
|
||||
protocol StepViewModelProtocol {
|
||||
func contentView() -> UITableView
|
||||
var isSkiped: Bool { get set }
|
||||
var step: Steps { get }
|
||||
var message: String? { get }
|
||||
var isFilled: Bool { get }
|
||||
@@ -25,9 +25,17 @@ protocol StepViewModelProtocol {
|
||||
|
||||
class StepsViewModel {
|
||||
private lazy var steps: [StepViewModelProtocol] = [
|
||||
WhatProblemStepViewModel(),
|
||||
whatProblemStep,
|
||||
questionsStep
|
||||
]
|
||||
|
||||
private lazy var whatProblemStep: WhatProblemStepViewModel = {
|
||||
let viewModel = WhatProblemStepViewModel() { [weak self] _ in
|
||||
self?.view?.updateNextButton()
|
||||
}
|
||||
return viewModel
|
||||
}()
|
||||
|
||||
private lazy var questionsStep: QuestionsStepViewModel = {
|
||||
let viewModel = QuestionsStepViewModel()
|
||||
viewModel.selectCountry = { [weak self] in self?.selectCountry(viewModel: $0) }
|
||||
@@ -36,10 +44,6 @@ class StepsViewModel {
|
||||
|
||||
private weak var view: StepsViewProtocol?
|
||||
|
||||
var showSkipButton: Bool {
|
||||
stepViewModel.step.showSkipButton
|
||||
}
|
||||
|
||||
var stepsCount: Int {
|
||||
steps.count
|
||||
}
|
||||
@@ -54,6 +58,10 @@ class StepsViewModel {
|
||||
steps[currentStepIndex]
|
||||
}
|
||||
|
||||
var isStepReady: Bool {
|
||||
steps[currentStepIndex].isFilled
|
||||
}
|
||||
|
||||
private var sendMessage: ((String) -> Void)?
|
||||
private var isReadyToSend: Bool {
|
||||
steps.reduce(true) { $0 && $1.isFilled }
|
||||
@@ -78,13 +86,6 @@ class StepsViewModel {
|
||||
view?.changeContent()
|
||||
}
|
||||
|
||||
func skipStep() {
|
||||
guard stepViewModel.step.showSkipButton else { return }
|
||||
|
||||
steps[currentStepIndex].isSkiped = true
|
||||
performStepAction()
|
||||
}
|
||||
|
||||
func backPressed() {
|
||||
guard currentStepIndex > 0 else {
|
||||
view?.close(completion: nil)
|
||||
@@ -93,7 +94,6 @@ class StepsViewModel {
|
||||
|
||||
currentStepIndex -= 1
|
||||
view?.changeContent()
|
||||
steps[currentStepIndex].isSkiped = false
|
||||
}
|
||||
|
||||
func selectCountry(viewModel: SelectCountryViewModelProtocol) {
|
||||
|
||||
@@ -18,7 +18,11 @@ class WhatProblemStepViewModel: BaseStepViewModel, StepViewModelProtocol {
|
||||
]
|
||||
|
||||
private var selectedProblemIndex = -1
|
||||
private var otherInput: String?
|
||||
private var otherInput: String? {
|
||||
didSet {
|
||||
didChangeReady?(isFilled)
|
||||
}
|
||||
}
|
||||
|
||||
private var selectedProblem: String? {
|
||||
if (0..<problemList.count).contains(selectedProblemIndex) {
|
||||
@@ -36,7 +40,7 @@ class WhatProblemStepViewModel: BaseStepViewModel, StepViewModelProtocol {
|
||||
|
||||
var step: Steps = .whatsProblem
|
||||
var message: String? {
|
||||
guard !isSkiped, selectedProblemIndex >= 0 else { return nil }
|
||||
guard selectedProblemIndex >= 0 else { return nil }
|
||||
var result = ""
|
||||
result.append(problemList[selectedProblemIndex])
|
||||
if isSelectedOther(),
|
||||
@@ -47,7 +51,21 @@ class WhatProblemStepViewModel: BaseStepViewModel, StepViewModelProtocol {
|
||||
return result
|
||||
}
|
||||
|
||||
var isFilled = true
|
||||
var isFilled: Bool {
|
||||
guard selectedProblemIndex >= 0 else {
|
||||
return false
|
||||
}
|
||||
if isSelectedOther() {
|
||||
return !(otherInput?.isEmpty ?? true)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
var didChangeReady: ((Bool) -> Void)?
|
||||
|
||||
init(didChangeReady: ((Bool) -> Void)?) {
|
||||
self.didChangeReady = didChangeReady
|
||||
}
|
||||
|
||||
override func updateRows() {
|
||||
staticTableView?.clear()
|
||||
@@ -94,5 +112,6 @@ class WhatProblemStepViewModel: BaseStepViewModel, StepViewModelProtocol {
|
||||
otherInput = nil
|
||||
}
|
||||
updateRows()
|
||||
didChangeReady?(isFilled)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +219,7 @@ extension UIColor {
|
||||
static let panelSecondaryBackground = UIColor(named: "Panel Secondary Background")
|
||||
static let tableCellBackground = UIColor(named: "tableCellBackground")
|
||||
static let tableCellSelectedBackground = UIColor(named: "tableCellSelectedBackground")
|
||||
static let disabledGray = UIColor(red: 0.3, green: 0.3, blue: 0.3, alpha: 1)
|
||||
}
|
||||
|
||||
extension UnicodeScalar {
|
||||
|
||||
Reference in New Issue
Block a user