Skip to content
Snippets Groups Projects
Commit 5881ccd2 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Refactored HUD

parent 3f1517d0
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!50Search UI 2.0
Showing
with 64 additions and 43 deletions
......@@ -68,7 +68,7 @@ let package = Package(
.package(url: "https://github.com/pointfreeco/combine-schedulers", from: "0.5.0"),
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", from: "4.2.1"),
.package(url: "https://github.com/google/google-api-objectivec-client-for-rest", from: "1.6.0"),
.package(url: "https://git.xx.network/elixxir/client-ios-db.git", .upToNextMajor(from: "1.0.5")),
.package(url: "https://git.xx.network/elixxir/client-ios-db.git", .upToNextMajor(from: "1.0.7")),
.package(url: "https://github.com/firebase/firebase-ios-sdk.git", .upToNextMajor(from: "8.10.0")),
.package(url: "https://github.com/darrarski/Shout.git", revision: "df5a662293f0ac15eeb4f2fd3ffd0c07b73d0de0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture.git",.upToNextMajor(from: "0.32.0")),
......
......@@ -104,7 +104,7 @@ struct DependencyRegistrator {
// MARK: Isolated
container.register(HUD() as HUDType)
container.register(HUD())
container.register(ThemeController() as ThemeControlling)
container.register(ToastController())
container.register(StatusBarController() as StatusBarStyleControlling)
......
......@@ -6,7 +6,7 @@ import Combine
import DependencyInjection
public final class BackupController: UIViewController {
@Dependency private var hud: HUDType
@Dependency var hud: HUD
private let viewModel = BackupViewModel.live()
private var cancellables = Set<AnyCancellable>()
......@@ -14,7 +14,7 @@ public final class BackupController: UIViewController {
public override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = Asset.neutralWhite.color
hud.update(with: .on(nil))
hud.update(with: .on)
setupNavigationBar()
setupBindings()
......
......@@ -30,7 +30,7 @@ struct BackupConfigViewModel {
extension BackupConfigViewModel {
static func live() -> Self {
class Context {
@Dependency var hud: HUDType
@Dependency var hud: HUD
@Dependency var service: BackupService
@Dependency var coordinator: BackupCoordinating
}
......@@ -40,7 +40,7 @@ extension BackupConfigViewModel {
return .init(
didTapBackupNow: {
context.service.performBackup()
context.hud.update(with: .on(nil))
context.hud.update(with: .on)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
context.hud.update(with: .none)
}
......@@ -57,7 +57,7 @@ extension BackupConfigViewModel {
context.service.toggle(service: service, enabling: false)
}, passphraseClosure: { passphrase in
context.service.passphrase = passphrase
context.hud.update(with: .on("Initializing and securing your backup file will take few seconds, please keep the app open."))
context.hud.update(with: .onTitle("Initializing and securing your backup file will take few seconds, please keep the app open."))
DispatchQueue.global().async {
context.service.toggle(service: service, enabling: enabling)
......
......@@ -24,7 +24,7 @@ extension Message: Differentiable {
}
public final class SingleChatController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var logger: XXLogger
@Dependency private var voxophone: Voxophone
@Dependency private var coordinator: ChatCoordinating
......
......@@ -107,7 +107,7 @@ final class SingleChatViewModel {
func didSend(image: UIImage) {
guard let imageData = image.orientedUp().jpegData(compressionQuality: 1.0) else { return }
hudRelay.send(.on(nil))
hudRelay.send(.on)
session.send(imageData: imageData, to: contact) { [weak self] in
switch $0 {
......
......@@ -147,7 +147,7 @@ final class ChatListViewModel {
}
func leave(_ group: Group) {
hudSubject.send(.on(nil))
hudSubject.send(.on)
do {
try session.leave(group: group)
......
......@@ -10,7 +10,7 @@ import DependencyInjection
import ScrollViewController
public final class ContactController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: ContactCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
......@@ -62,7 +62,7 @@ final class ContactViewModel {
}
func didTapDelete() {
hudRelay.send(.on(nil))
hudRelay.send(.on)
do {
try session.deleteContact(contact)
......@@ -91,7 +91,7 @@ final class ContactViewModel {
}
func didTapResend() {
hudRelay.send(.on(nil))
hudRelay.send(.on)
backgroundScheduler.schedule { [weak self] in
guard let self = self else { return }
......@@ -107,7 +107,7 @@ final class ContactViewModel {
}
func didTapRequest(with nickname: String) {
hudRelay.send(.on(nil))
hudRelay.send(.on)
contact.nickname = nickname
backgroundScheduler.schedule { [weak self] in
......@@ -124,7 +124,7 @@ final class ContactViewModel {
}
func didTapAccept(_ nickname: String) {
hudRelay.send(.on(nil))
hudRelay.send(.on)
contact.nickname = nickname
backgroundScheduler.schedule { [weak self] in
......
......@@ -7,7 +7,7 @@ import XXModels
import DependencyInjection
public final class CreateGroupController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: ContactListCoordinating
lazy private var titleLabel = UILabel()
......
......@@ -76,7 +76,7 @@ final class CreateGroupViewModel {
}
func create(name: String, welcome: String?, members: [Contact]) {
hudRelay.send(.on(nil))
hudRelay.send(.on)
session.createGroup(name: name, welcome: welcome, members: members) { [weak self] in
guard let self = self else { return }
......
......@@ -10,15 +10,17 @@ private enum Constants {
}
public enum HUDStatus: Equatable {
case on(String?)
case none
case on
case onTitle(String)
case onAction(String)
case error(HUDError)
var isPresented: Bool {
switch self {
case .none:
return false
case .on, .error:
case .on, .error, .onTitle, .onAction:
return true
}
}
......@@ -50,15 +52,12 @@ public struct HUDError: Equatable {
}
}
public protocol HUDType {
func update(with status: HUDStatus)
}
public final class HUD: HUDType {
public final class HUD {
private(set) var window: UIWindow?
private(set) var errorView: ErrorView?
private(set) var titleLabel: UILabel?
private(set) var animation: DotAnimation?
public var actionButton: CapsuleButton?
private var cancellables = Set<AnyCancellable>()
private var status: HUDStatus = .none {
......@@ -70,13 +69,19 @@ public final class HUD: HUDType {
self.titleLabel = nil
switch status {
case .on(let text):
case .on:
animation = DotAnimation()
case .onTitle(let text):
animation = DotAnimation()
titleLabel = UILabel()
titleLabel!.text = text
case .onAction(let title):
animation = DotAnimation()
actionButton = CapsuleButton()
actionButton!.set(style: .seeThroughWhite, title: title)
if let text = text {
titleLabel = UILabel()
titleLabel!.text = text
}
case .error(let error):
errorView = ErrorView(with: error)
case .none:
......@@ -88,13 +93,19 @@ public final class HUD: HUDType {
if oldValue.isPresented == false && status.isPresented == true {
switch status {
case .on(let text):
case .on:
animation = DotAnimation()
if let text = text {
titleLabel = UILabel()
titleLabel!.text = text
}
case .onTitle(let text):
animation = DotAnimation()
titleLabel = UILabel()
titleLabel!.text = text
case .onAction(let title):
animation = DotAnimation()
actionButton = CapsuleButton()
actionButton!.set(style: .seeThroughWhite, title: title)
case .error(let error):
errorView = ErrorView(with: error)
case .none:
......@@ -118,7 +129,7 @@ public final class HUD: HUDType {
private func showWindow() {
window = Window()
window?.backgroundColor = UIColor.black.withAlphaComponent(0.5)
window?.backgroundColor = UIColor.black.withAlphaComponent(0.8)
window?.rootViewController = StatusBarViewController(nil)
if let animation = animation {
......@@ -138,6 +149,15 @@ public final class HUD: HUDType {
}
}
if let actionButton = actionButton {
window?.addSubview(actionButton)
actionButton.snp.makeConstraints {
$0.left.equalToSuperview().offset(18)
$0.right.equalToSuperview().offset(-18)
$0.bottom.equalToSuperview().offset(-50)
}
}
if let errorView = errorView {
window?.addSubview(errorView)
errorView.snp.makeConstraints { make in
......@@ -166,6 +186,7 @@ public final class HUD: HUDType {
self.cancellables.removeAll()
self.errorView = nil
self.animation = nil
self.actionButton = nil
self.titleLabel = nil
self.window = nil
}
......
......@@ -7,7 +7,7 @@ import DependencyInjection
public final class LaunchController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: LaunchCoordinating
lazy private var screenView = LaunchView()
......
......@@ -58,7 +58,7 @@ final class LaunchViewModel {
func viewDidAppear() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) { [weak self] in
self?.hudSubject.send(.on(nil))
self?.hudSubject.send(.on)
self?.checkVersion()
}
}
......
......@@ -9,7 +9,7 @@ import ScrollViewController
import Models
public final class OnboardingEmailConfirmationController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
......@@ -8,7 +8,7 @@ import DependencyInjection
import ScrollViewController
public final class OnboardingEmailController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
......@@ -9,7 +9,7 @@ import ScrollViewController
import Models
public final class OnboardingPhoneConfirmationController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
......@@ -8,7 +8,7 @@ import DependencyInjection
import ScrollViewController
public final class OnboardingPhoneController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
......@@ -6,7 +6,7 @@ import Combine
import DependencyInjection
public final class OnboardingStartController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
lazy private var screenView = OnboardingStartView()
......
......@@ -8,7 +8,7 @@ import DependencyInjection
import ScrollViewController
public final class OnboardingUsernameController: UIViewController {
@Dependency private var hud: HUDType
@Dependency private var hud: HUD
@Dependency private var coordinator: OnboardingCoordinating
@Dependency private var statusBarController: StatusBarStyleControlling
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment