-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSplashVC.swift
80 lines (67 loc) · 2.5 KB
/
SplashVC.swift
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
//
// MainViewController.swift
// Commun
//
// Created by Chung Tran on 27/06/2019.
// Copyright © 2019 Commun Limited. All rights reserved.
//
import UIKit
import RxSwift
class SplashVC: BaseViewController {
override var preferredStatusBarStyle: UIStatusBarStyle {.lightContent}
lazy var slashImageView = UIImageView(width: 60, height: 130.5, imageNamed: "slash")
var errorView: UIView!
override func setUp() {
super.setUp()
view.backgroundColor = UIColor.appMainColor.inDarkMode(.black)
view.addSubview(slashImageView)
slashImageView.autoAlignAxis(toSuperviewAxis: .horizontal)
slashImageView.autoAlignAxis(toSuperviewAxis: .vertical)
let zoomAnim = CABasicAnimation(keyPath: "transform.scale")
zoomAnim.fromValue = 1
zoomAnim.toValue = 1.2
zoomAnim.duration = 0.8
zoomAnim.repeatCount = .infinity
zoomAnim.isRemovedOnCompletion = false
zoomAnim.autoreverses = true
slashImageView.layer.add(zoomAnim, forKey: "Loading")
// Do any additional setup after loading the view.
AuthManager.shared.status
.subscribe(onNext: { (status) in
switch status {
case .error(let error):
self.showErrorScreen(title: "error".localized().uppercaseFirst, subtitle: error.localizedDescription)
default:
self.view.hideErrorView()
}
})
.disposed(by: disposeBag)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
if UserDefaults.appGroups.object(forKey: appShareExtensionKey) != nil {
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(5)) {
UIApplication.shared.open(URL(string: "commun://createPost")!)
}
}
}
func showErrorScreen(title: String? = nil, subtitle: String? = nil, retryButtonTitle: String? = nil)
{
view.showErrorView(title: title, subtitle: subtitle, retryButtonTitle: retryButtonTitle)
{ [weak self] in
self?.reloadApp()
}
}
@objc func retryDidTouch(_ tap: UITapGestureRecognizer) {
reloadApp()
}
func reloadApp() {
hideErrorView()
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) {
AuthManager.shared.reload()
}
}
func hideErrorView() {
view.hideErrorView()
}
}