66//
77
88import UIKit
9+
910import RxSwift
1011import RxCocoa
1112import SnapKit
@@ -14,9 +15,8 @@ final class StatusView: UIView {
1415 private var disposableBag = DisposeBag ( )
1516 var profileButtonDidClick = PublishSubject < Void > ( )
1617 var userDataFetched = PublishSubject < User > ( )
17-
18- private let messages = [ " 화이팅 " , " 잘 할 수 있어 " , " 오늘은 공부를 해보자! " , " Hello, World! " , " 🎹🎵🎶🎵🎶 " ]
19-
18+ var questStatus = PublishSubject < ( Int , Int ) > ( )
19+
2020 // MARK: - Components
2121 private lazy var iconContainer : UIButton = {
2222 var config = UIButton . Configuration. plain ( )
@@ -25,117 +25,130 @@ final class StatusView: UIView {
2525 iconContainer. imageView? . contentMode = . scaleToFill
2626 return iconContainer
2727 } ( )
28-
28+
2929 private lazy var messageBubble : MessageBubbleLabel = {
3030 return MessageBubbleLabel ( text: getRandomMessage ( ) )
3131 } ( )
32-
32+
3333 private lazy var statusLabel : UILabel = {
3434 let statusLabel = UILabel ( )
3535 statusLabel. text = " 0 / 0 "
3636 statusLabel. font = UIFont . systemFont ( ofSize: 14 , weight: . bold)
3737 statusLabel. textColor = . maxViolet
38-
38+
3939 return statusLabel
4040 } ( )
41-
41+
4242 private lazy var progressBar : UIProgressView = {
4343 let progressBar = UIProgressView ( )
4444 progressBar. trackTintColor = . maxLightGrey
4545 progressBar. progressTintColor = . maxGreen
4646 progressBar. progress = 0.2
47-
47+
4848 return progressBar
4949 } ( )
50-
50+
5151 private lazy var profileButton : UIButton = {
52- let largeConfig = UIImage . SymbolConfiguration ( pointSize: 40 , weight: . bold, scale: . large)
5352 var config = UIButton . Configuration. plain ( )
5453 config. baseForegroundColor = . maxLightGrey
55- config. image = UIImage ( systemName: " person.crop.circle " ,
56- withConfiguration : largeConfig )
54+ config. image = UIImage ( systemName: " person.crop.circle " )
55+
5756 let button = UIButton ( configuration: config)
57+ button. imageView? . contentMode = . scaleAspectFit
58+ button. layer. cornerRadius = 100
5859 return button
5960 } ( )
60-
61+
6162 // MARK: - Methods
6263 override init ( frame: CGRect ) {
6364 super. init ( frame: frame)
64-
65+
6566 configureUI ( )
6667 bind ( )
6768 }
68-
69+
6970 required init ? ( coder: NSCoder ) {
7071 fatalError ( " init(coder:) has not been implemented " )
7172 }
72-
73+
7374 private func configureUI( ) {
7475 addSubview ( iconContainer)
7576 iconContainer. snp. makeConstraints { make in
7677 make. height. equalToSuperview ( )
7778 make. width. equalTo ( iconContainer. snp. height)
7879 make. top. leading. bottom. equalToSuperview ( )
7980 }
80-
81+
8182 iconContainer. imageView? . snp. makeConstraints { make in
8283 make. width. height. equalToSuperview ( )
84+ make. top. leading. equalToSuperview ( )
8385 }
84-
86+
8587 addSubview ( messageBubble)
8688 messageBubble. snp. makeConstraints { make in
8789 make. leading. equalTo ( iconContainer. snp. trailing)
8890 make. top. equalToSuperview ( ) . inset ( 10 )
8991 }
90-
92+
9193 addSubview ( progressBar)
9294 progressBar. snp. makeConstraints { make in
9395 make. leading. equalTo ( iconContainer. snp. trailing)
9496 make. bottom. equalToSuperview ( ) . inset ( 10 )
9597 make. width. equalToSuperview ( ) . multipliedBy ( 0.5 )
9698 make. height. equalTo ( 5 )
9799 }
98-
100+
99101 addSubview ( profileButton)
100102 profileButton. snp. makeConstraints { make in
101- make. trailing. equalToSuperview ( )
103+ make. trailing. equalToSuperview ( ) . inset ( 15 )
102104 make. centerY. equalToSuperview ( )
105+ make. height. equalToSuperview ( ) . inset ( 15 )
106+ make. width. equalTo ( profileButton. snp. height) . multipliedBy ( 1.0 / 1.0 )
103107 }
104-
108+
109+ profileButton. imageView? . snp. makeConstraints ( { make in
110+ make. trailing. equalToSuperview ( )
111+ make. centerY. equalToSuperview ( )
112+ make. height. width. equalToSuperview ( )
113+ } )
114+
105115 addSubview ( statusLabel)
106116 statusLabel. snp. makeConstraints { make in
107117 make. trailing. equalTo ( progressBar. snp. trailing)
108118 make. bottom. equalTo ( progressBar. snp. top)
109119 }
110120 }
111-
121+
112122 private func bind( ) {
113123 iconContainer. rx. tap
114124 . subscribe ( onNext: { [ weak self] _ in
115- guard let self = self else { return }
116- self . messageBubble. setText ( text: self . getRandomMessage ( ) )
117- } )
125+ guard let self = self else { return }
126+ self . messageBubble. setText ( text: self . getRandomMessage ( ) )
127+ } )
118128 . disposed ( by: disposableBag)
119-
129+
120130 profileButton. rx. tap
121131 . subscribe ( onNext: { [ weak self] _ in
122- self ? . profileButtonDidClick. onNext ( ( ) )
123- } )
132+ self ? . profileButtonDidClick. onNext ( ( ) )
133+ } )
124134 . disposed ( by: disposableBag)
125-
135+
126136 userDataFetched
127137 . asDriver ( onErrorJustReturn: User ( ) )
128138 . drive ( onNext: { [ weak self] user in
129- guard let self = self else { return }
130- self . profileButton. imageView? . setImage ( with: user. profileURL)
131- } ) . disposed ( by: disposableBag)
132-
133-
139+ guard let self = self else { return }
140+ self . profileButton. setImage ( with: user. profileURL)
141+ } ) . disposed ( by: disposableBag)
142+
143+ questStatus
144+ . asDriver ( onErrorJustReturn: ( 0 , 0 ) )
145+ . drive ( onNext: { [ weak self] ( currentState: Int , totalState: Int ) in
146+ guard let self = self else { return }
147+ self . statusLabel. text = " \( currentState) / \( totalState) "
148+ let progressValue = totalState >= 0 ? ( Float ( currentState) / Float( totalState) ) : 0.0
149+ self . progressBar. setProgress ( progressValue, animated: true )
150+ } )
151+ . disposed ( by: disposableBag)
134152 }
135153}
136154
137- extension StatusView {
138- private func getRandomMessage( ) -> String {
139- return messages. randomElement ( ) ?? " Hello,World! "
140- }
141- }
0 commit comments