blob: c51a8e6977c8076c6d5e4422ecc4dbb34cb00b3c (
plain)
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
|
//
// AccountViewController.swift
// MullvadVPN
//
// Created by pronebird on 20/03/2019.
// Copyright © 2019 Amagicom AB. All rights reserved.
//
import Combine
import UIKit
class AccountViewController: UIViewController {
@IBOutlet var accountLabel: UILabel!
@IBOutlet var expiryLabel: UILabel!
private var logoutSubscriber: AnyCancellable?
override func viewDidLoad() {
super.viewDidLoad()
updateView()
}
// MARK: - Actions
@IBAction func doBuyCredits() {
UIApplication.shared.open(WebLinks.purchaseURL, options: [:])
}
@IBAction func doLogout() {
logoutSubscriber = Account.shared.logout()
.receive(on: DispatchQueue.main)
.sink(receiveCompletion: { (_) in
self.performSegue(withIdentifier: SegueIdentifier.Account.logout.rawValue, sender: self)
})
}
// MARK: - Private
private func updateView() {
accountLabel.text = Account.shared.token
if let expiryDate = Account.shared.expiry {
let accountExpiry = AccountExpiry(date: expiryDate)
if accountExpiry.isExpired {
expiryLabel.text = NSLocalizedString("OUT OF TIME", tableName: "Settings", comment: "")
expiryLabel.textColor = .dangerColor
} else {
expiryLabel.text = accountExpiry.formattedDate
expiryLabel.textColor = .white
}
}
}
}
|