Skip to content

Commit 508b84d

Browse files
authored
Merge pull request #116 from boostcampwm-2022/refactor/StatusImage
Refactor/status image
2 parents 8d1e2da + 4043689 commit 508b84d

File tree

8 files changed

+217
-126
lines changed

8 files changed

+217
-126
lines changed

DailyQuest/DailyQuest.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
3416FC96292B5B5400B504C5 /* Quest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5A2922164B00B87619 /* Quest.swift */; };
3434
3417B1442935DA4A00900454 /* BrowseUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3417B1432935DA4A00900454 /* BrowseUseCase.swift */; };
3535
3417B1462935DA9D00900454 /* DefaultBrowseUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3417B1452935DA9D00900454 /* DefaultBrowseUseCase.swift */; };
36+
341932E3294185A0003DE808 /* StatusView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 341932E2294185A0003DE808 /* StatusView+.swift */; };
3637
342830A8292E0FAC00AE811B /* SettingsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830A7292E0FAC00AE811B /* SettingsCoordinator.swift */; };
3738
342830AA292E12C700AE811B /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830A9292E12C700AE811B /* SettingsViewController.swift */; };
3839
342830F2292E196E00AE811B /* CommonField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830F1292E196E00AE811B /* CommonField.swift */; };
@@ -253,6 +254,7 @@
253254
3416FC94292B5AD600B504C5 /* QuestUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestUseCaseTests.swift; sourceTree = "<group>"; };
254255
3417B1432935DA4A00900454 /* BrowseUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseUseCase.swift; sourceTree = "<group>"; };
255256
3417B1452935DA9D00900454 /* DefaultBrowseUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBrowseUseCase.swift; sourceTree = "<group>"; };
257+
341932E2294185A0003DE808 /* StatusView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatusView+.swift"; sourceTree = "<group>"; };
256258
342830A7292E0FAC00AE811B /* SettingsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCoordinator.swift; sourceTree = "<group>"; };
257259
342830A9292E12C700AE811B /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
258260
342830F1292E196E00AE811B /* CommonField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonField.swift; sourceTree = "<group>"; };
@@ -660,6 +662,7 @@
660662
9BED4DE9293FA92900C60631 /* UIImageView+.swift */,
661663
3436FCF9293F2654003575C3 /* Notification+.swift */,
662664
34517FCB2940A92100AB77E9 /* Alertable.swift */,
665+
341932E2294185A0003DE808 /* StatusView+.swift */,
663666
);
664667
path = Utils;
665668
sourceTree = "<group>";
@@ -1346,6 +1349,7 @@
13461349
347D258B292C60F40038FCA2 /* StatusView.swift in Sources */,
13471350
9BED4DE8293FA01400C60631 /* ProfileViewModel.swift in Sources */,
13481351
34642AB62925D9E40052FA0E /* UserInfoView.swift in Sources */,
1352+
341932E3294185A0003DE808 /* StatusView+.swift in Sources */,
13491353
34517FCC2940A92100AB77E9 /* Alertable.swift in Sources */,
13501354
349955292923600A007AB99E /* BrowseViewController.swift in Sources */,
13511355
34113BE82934917500AB4919 /* LoginViewModel.swift in Sources */,

DailyQuest/DailyQuest/Data/Repositories/DefaultAuthRepository.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extension DefaultAuthRepository: AuthRepository {
4747
.flatMap(self.persistentQuestsStorage.saveQuests(with:))
4848
.do(onSuccess: { quests in
4949
let dates = quests.map { $0.date }
50-
NotificationCenter.default.post(name: .updated, object: dates)
50+
NotificationCenter.default.post(name: .userUpdated, object: dates)
5151
})
5252
}
5353
.subscribe()
@@ -68,7 +68,7 @@ extension DefaultAuthRepository: AuthRepository {
6868
}
6969
.do(onSuccess: { quests in
7070
let dates = quests.map { $0.date }
71-
NotificationCenter.default.post(name: .updated, object: dates)
71+
NotificationCenter.default.post(name: .userUpdated, object: dates)
7272
})
7373
.subscribe()
7474
.disposed(by: self.disposeBag)

DailyQuest/DailyQuest/Presentation/Home/View/StatusView.swift

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
import UIKit
9+
910
import RxSwift
1011
import RxCocoa
1112
import 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

Comments
 (0)