forked from HabitRPG/habitica-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHRPGShopUserHeaderView.swift
56 lines (47 loc) · 1.87 KB
/
HRPGShopUserHeaderView.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
//
// HRPGShopUserHeaderView.swift
// Habitica
//
// Created by Elliot Schrock on 7/13/17.
// Copyright © 2017 HabitRPG Inc. All rights reserved.
//
import UIKit
import Habitica_Models
import ReactiveSwift
class HRPGShopUserHeaderView: UIView {
@IBOutlet weak var userClassImageView: UIImageView!
@IBOutlet weak var usernameLabel: UILabel!
@IBOutlet weak var hourglassCountView: CurrencyCountView!
@IBOutlet weak var gemCountView: CurrencyCountView!
@IBOutlet weak var goldCountView: CurrencyCountView!
private let userRepository = UserRepository()
private let disposable = ScopedDisposable(CompositeDisposable())
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
disposable.inner.add(userRepository.getUser().on(value: {[weak self]user in
self?.set(user: user)
}).start())
}
override func awakeFromNib() {
hourglassCountView.currency = .hourglass
gemCountView.currency = .gem
goldCountView.currency = .gold
backgroundColor = ThemeService.shared.theme.contentBackgroundColor
super.awakeFromNib()
}
func set(user: UserProtocol) {
usernameLabel.text = user.profile?.name
usernameLabel.textColor = user.contributor?.color
if let shouldDisable = user.preferences?.disableClasses, !shouldDisable, let userClass = user.stats?.habitClassNice {
userClassImageView.isHidden = false
userClassImageView.image = UIImage(named: "icon_\(userClass)")
} else {
userClassImageView.isHidden = true
}
goldCountView.amount = Int(user.stats?.gold ?? 0)
gemCountView.amount = user.gemCount
if let hourglassCount = user.purchased?.subscriptionPlan?.consecutive?.hourglasses {
hourglassCountView.amount = hourglassCount
}
}
}