Files
lockdown-iOS-mirror/LockdowniOS/Scenes/Questionnaire/ViewModel/QuestionsStepViewModel.swift
Pavel Vilbik 9830155526 Squashed commit of the following:
commit 1c1067e30104c2670c6339d1f16b7bd55406481b
Merge: d3d2df9 70a2319
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 14:07:47 2023 +0300

    Merge branch 'local/KB-6393_questionnaire' of https://github.com/joinappex/lockdown-ios-2.0 into local/KB-6393_questionnaire

commit d3d2df991e9b6358982ba6d38541f726772f2fd1
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 13:19:42 2023 +0300

    add sending message

commit 70a23193dcb3deae1341ee318bf536e49ecf3c2a
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 13:19:42 2023 +0300

    add sending message

commit 9a290eb556f0ad4751b49cd53be17de903edd0ac
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 13:05:32 2023 +0300

    add generating message

commit 341293cab9466eab31a1886b6d43d59cc43a3e61
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 12:35:53 2023 +0300

    refactoring model of questions

commit 0482bce1c1955a0562deaaabeb48aca04f16302c
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 12:12:02 2023 +0300

    add select region

commit 151b94c742fe9cc29e730c18d57a7cf868878ea3
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Wed Jun 28 11:30:03 2023 +0300

    add select country

commit f75596a13b9e17dacfc05a57674acb4d65680229
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Tue Jun 27 14:19:40 2023 +0300

    add navigation link view

commit a9a83f462ffa3c7ec066d8ee5254b2d8cb6416ed
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Mon Jun 26 18:25:23 2023 +0300

    add questions title view

commit 08d3eb1d7873bf4ccedd4b8fbf280213520bb9c3
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Mon Jun 26 16:20:01 2023 +0300

    add yes/no views

commit b6a16aa2bbd0c1bbe607170d16f430ad522c4d5f
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Mon Jun 26 12:48:23 2023 +0300

    fixed skip button

commit 5bf7fb8799f4b79e1a37a58a2f3b5862ea9f1da5
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Mon Jun 26 12:41:59 2023 +0300

    refactoring step view model

commit 8871dc2ebc0728d3491e6807b4426963741baa4a
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Mon Jun 26 12:04:26 2023 +0300

    refactoring step view model

commit e5b2e02191217546d47454a471e101c242d89464
Author: Pavel Vilbik <Pavel.Vilbik@joinappex.com>
Date:   Fri Jun 23 18:49:07 2023 +0300

    add view model for content

commit b84b9130771aaa521acee0abdf28f3bba2b82771
Author: Pavel Vilbik <p.vilbik@softteco.com>
Date:   Fri Jun 23 14:44:41 2023 +0300

    add textview cell

commit e0985ae6c1a5c519e4fd83d5359b68621a18093b
Author: Pavel Vilbik <p.vilbik@softteco.com>
Date:   Fri Jun 23 12:16:51 2023 +0300

    add title view

commit 24908af4d5b914364df3542b77cecdaaa497d105
Author: Pavel Vilbik <p.vilbik@softteco.com>
Date:   Thu Jun 22 17:34:07 2023 +0300

    add view for problem cell

commit 9df1a479a404528efba0452bde0d4291648b49b7
Author: Pavel Vilbik <p.vilbik@softteco.com>
Date:   Thu Jun 22 17:14:49 2023 +0300

    add radio switcher view

commit 5ed6c1d3bd4acf00d40f5dbe81cfcbbbd8bf63c0
Author: Pavel Vilbik <p.vilbik@softteco.com>
Date:   Thu Jun 22 15:49:32 2023 +0300

    add base view for questionnaire
2023-06-28 14:31:55 +03:00

177 lines
6.2 KiB
Swift

//
// QuestionsStepViewModel.swift
// Lockdown
//
// Created by Pavel Vilbik on 26.06.23.
// Copyright © 2023 Confirmed Inc. All rights reserved.
//
import UIKit
class QuestionsStepViewModel: BaseStepViewModel, StepViewModelProtocol {
var step: Steps = .questions
var message: String? {
model.generateMessage(
firewallInput: firewallInput,
vpnInput: vpnInput,
otherDetailsInput: otherDetailsInput
)
}
private var model = QuestionModel() {
didSet {
updateRows()
}
}
var firewallInput: String?
var vpnInput: String?
var otherDetailsInput: String?
var selectCountry: ((SelectCountryViewModelProtocol) -> Void)?
override func updateRows() {
staticTableView?.clear()
addTitleRow(
NSLocalizedString("Questions", comment: ""),
subtitle: NSLocalizedString("Please fill questions answer", comment: ""),
bottomSpacing: 2
)
addYesNoRow(
title: NSLocalizedString("1. Is the firewall on? (optional)", comment: ""),
initialValue: model.isFirewallOn,
didSelect: { [weak self] in self?.model.isFirewallOn = $0 }
)
addTextViewRow(
text: firewallInput,
placeholder: NSLocalizedString("Write more information...", comment: ""),
didChangeText: { [weak self] in self?.firewallInput = $0 }
)
addYesNoRow(
title: NSLocalizedString("2-1. Is the VPN on? (optional)", comment: ""),
initialValue: model.isVPNOn,
didSelect: { [weak self] in self?.model.isVPNOn = $0 }
)
addTextViewRow(
text: vpnInput,
placeholder: NSLocalizedString("Write more information...", comment: ""),
didChangeText: { [weak self] in self?.vpnInput = $0 }
)
if model.isVPNOn ?? false {
addQuestionTitleRow(
NSLocalizedString("2-2. If the VPN is on, which region is it set to?", comment: "")
)
addNavigationLinkRow(
placeholder: NSLocalizedString("Select region", comment: ""),
country: model.vpnRegion
) { [weak self] in
self?.selectCountry?(
SelectRegionViewModel(
selectedCountry: self?.model.vpnRegion,
didSelectCountry: { self?.model.vpnRegion = $0 }
)
)
}
}
addQuestionTitleRow(
NSLocalizedString("3. Where are you contacting us from?", comment: "")
)
addNavigationLinkRow(
placeholder: NSLocalizedString("Select country", comment: ""),
country: model.fromCountry
) { [weak self] in
self?.selectCountry?(
SelectCountryViewModel(
selectedCountry: self?.model.fromCountry,
didSelectCountry: { self?.model.fromCountry = $0 }
)
)
}
addYesNoRow(
title: NSLocalizedString("4. Is the issue happening on WiFi?", comment: ""),
initialValue: model.isHappeningWifiIssue,
didSelect: { [weak self] in self?.model.isHappeningWifiIssue = $0 }
)
addYesNoRow(
title: NSLocalizedString("5. Is the issue happening on cellular data?", comment: ""),
initialValue: model.isHappenningCellularIssue,
didSelect: { [weak self] in self?.model.isHappenningCellularIssue = $0 }
)
addYesNoRow(
title: NSLocalizedString("6. Do you have other firewall apps installed?", comment: ""),
initialValue: model.haveOtherFirewall,
didSelect: { [weak self] in self?.model.haveOtherFirewall = $0 }
)
addYesNoRow(
title: NSLocalizedString("7. Do you have other VPN apps installed?", comment: ""),
initialValue: model.haveOtherVPN,
didSelect: { [weak self] in self?.model.haveOtherVPN = $0 }
)
addQuestionTitleRow(
NSLocalizedString("8. Additional details.", comment: "")
)
addTextViewRow(
text: otherDetailsInput,
placeholder: NSLocalizedString("Write additional details here...", comment: ""),
didChangeText: { [weak self] in self?.otherDetailsInput = $0 }
)
staticTableView?.reloadData()
}
private func addYesNoRow(
title: String,
initialValue: Bool?,
didSelect: ((Bool?) -> Void)?
) {
staticTableView?.addRowCell { [unowned self] cell in
let switcher = YesNoRadioSwitcherView()
switcher.titleLabel.text = title
switcher.isSelected = initialValue
switcher.didSelect = didSelect
self.setupClear(cell)
cell.addSubview(switcher)
switcher.anchors.edges.pin(insets: .init(top: 37, left: 2, bottom: 15, right: 2))
}
}
private func addQuestionTitleRow(_ title: String) {
staticTableView?.addRowCell { [unowned self] cell in
let view = QuestionTitleView()
view.titleLabel.text = title
self.setupClear(cell)
cell.addSubview(view)
view.anchors.edges.pin(insets: .init(top: 20, left: 2, bottom: 10, right: 2))
}
}
private func addNavigationLinkRow(
placeholder: String,
country: Country?,
perform: (() -> Void)?
) {
staticTableView?.addRowCell { [unowned self] cell in
let view = NavigationLinkView()
let isEmpty = country == nil
view.placeholderLabel.text = placeholder
view.placeholderLabel.isHidden = !isEmpty
view.titleLabel.text = country?.title
view.titleLabel.isHidden = isEmpty
view.emojiLabel.text = country?.emojiSymbol
view.emojiLabel.isHidden = isEmpty
view.didSelect = perform
self.setupClear(cell)
cell.addSubview(view)
view.anchors.edges.pin(insets: .init(top: 20, left: 2, bottom: 10, right: 2))
}
}
}