Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import HUD
import UIKit
import Shared
import Combine
import PushFeature
import DependencyInjection
public final class LaunchController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var coordinator: LaunchCoordinating
lazy private var screenView = LaunchView()
private let blocker = UpdateBlocker()
private let viewModel = LaunchViewModel()
public var pendingPushRoute: PushRouter.Route?
private var cancellables = Set<AnyCancellable>()
public override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
viewModel.viewDidAppear()
}
public override func loadView() {
view = screenView
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?
.navigationBar
.customize(translucent: true)
}
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
screenView.setupGradient()
}
public override func viewDidLoad() {
super.viewDidLoad()
viewModel.hudPublisher
.receive(on: DispatchQueue.main)
.sink { [hud] in hud.update(with: $0) }
.store(in: &cancellables)
viewModel.routePublisher
.receive(on: DispatchQueue.main)
.sink { [unowned self] in
switch $0 {
case .chats:
if let pushRoute = pendingPushRoute {
switch pushRoute {
case .requests:
coordinator.toRequests(from: self)
case .groupChat(id: let groupId):
if let groupInfo = viewModel.getGroupInfoWith(groupId: groupId) {
coordinator.toGroupChat(with: groupInfo, from: self)
return
}
coordinator.toChats(from: self)
case .contactChat(id: let userId):
if let contact = viewModel.getContactWith(userId: userId) {
coordinator.toSingleChat(with: contact, from: self)
return
}
coordinator.toChats(from: self)
}
return
}
coordinator.toChats(from: self)
case .onboarding(let ndf):
coordinator.toOnboarding(with: ndf, from: self)
case .update(let model):
offerUpdate(model: model)
}
}.store(in: &cancellables)
}
private func offerUpdate(model: Update) {
let drawerView = UIView()
drawerView.backgroundColor = Asset.neutralSecondary.color
drawerView.layer.cornerRadius = 5
let vStack = UIStackView()
vStack.axis = .vertical
vStack.spacing = 10
drawerView.addSubview(vStack)
vStack.snp.makeConstraints {
$0.top.equalToSuperview().offset(18)
$0.left.equalToSuperview().offset(18)
$0.right.equalToSuperview().offset(-18)
$0.bottom.equalToSuperview().offset(-18)
}
let title = UILabel()
title.text = "App Update"
title.textAlignment = .center
title.textColor = Asset.neutralDark.color
let body = UILabel()
body.numberOfLines = 0
body.textAlignment = .center
body.textColor = Asset.neutralDark.color
let update = CapsuleButton()
update.publisher(for: .touchUpInside)
.sink { UIApplication.shared.open(.init(string: model.urlString)!, options: [:]) }
.store(in: &cancellables)
vStack.addArrangedSubview(title)
vStack.addArrangedSubview(body)
vStack.addArrangedSubview(update)
body.text = model.content
update.set(
style: model.actionStyle,
title: model.positiveActionTitle
)
if let negativeTitle = model.negativeActionTitle {
let negativeButton = CapsuleButton()
negativeButton.set(style: .simplestColoredRed, title: negativeTitle)
negativeButton.publisher(for: .touchUpInside)
.sink { [unowned self] in
blocker.hideWindow()
viewModel.versionApproved()
}.store(in: &cancellables)
vStack.addArrangedSubview(negativeButton)
}
blocker.window?.addSubview(drawerView)
drawerView.snp.makeConstraints {
$0.left.equalToSuperview().offset(18)
$0.center.equalToSuperview()
$0.right.equalToSuperview().offset(-18)
}
blocker.showWindow()
}
}