Skip to content

Commit

Permalink
Merge branch 'develop' into feature/CalendarView
Browse files Browse the repository at this point in the history
  • Loading branch information
jinwoong16 committed Dec 8, 2022
2 parents 402a799 + 4727a84 commit 763f98f
Show file tree
Hide file tree
Showing 8 changed files with 215 additions and 129 deletions.
4 changes: 4 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
3416FC96292B5B5400B504C5 /* Quest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3449AD5A2922164B00B87619 /* Quest.swift */; };
3417B1442935DA4A00900454 /* BrowseUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3417B1432935DA4A00900454 /* BrowseUseCase.swift */; };
3417B1462935DA9D00900454 /* DefaultBrowseUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3417B1452935DA9D00900454 /* DefaultBrowseUseCase.swift */; };
341932E3294185A0003DE808 /* StatusView+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 341932E2294185A0003DE808 /* StatusView+.swift */; };
342830A8292E0FAC00AE811B /* SettingsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830A7292E0FAC00AE811B /* SettingsCoordinator.swift */; };
342830AA292E12C700AE811B /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830A9292E12C700AE811B /* SettingsViewController.swift */; };
342830F2292E196E00AE811B /* CommonField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342830F1292E196E00AE811B /* CommonField.swift */; };
Expand Down Expand Up @@ -253,6 +254,7 @@
3416FC94292B5AD600B504C5 /* QuestUseCaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestUseCaseTests.swift; sourceTree = "<group>"; };
3417B1432935DA4A00900454 /* BrowseUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseUseCase.swift; sourceTree = "<group>"; };
3417B1452935DA9D00900454 /* DefaultBrowseUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultBrowseUseCase.swift; sourceTree = "<group>"; };
341932E2294185A0003DE808 /* StatusView+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "StatusView+.swift"; sourceTree = "<group>"; };
342830A7292E0FAC00AE811B /* SettingsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCoordinator.swift; sourceTree = "<group>"; };
342830A9292E12C700AE811B /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; };
342830F1292E196E00AE811B /* CommonField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommonField.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -660,6 +662,7 @@
9BED4DE9293FA92900C60631 /* UIImageView+.swift */,
3436FCF9293F2654003575C3 /* Notification+.swift */,
34517FCB2940A92100AB77E9 /* Alertable.swift */,
341932E2294185A0003DE808 /* StatusView+.swift */,
);
path = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -1346,6 +1349,7 @@
347D258B292C60F40038FCA2 /* StatusView.swift in Sources */,
9BED4DE8293FA01400C60631 /* ProfileViewModel.swift in Sources */,
34642AB62925D9E40052FA0E /* UserInfoView.swift in Sources */,
341932E3294185A0003DE808 /* StatusView+.swift in Sources */,
34517FCC2940A92100AB77E9 /* Alertable.swift in Sources */,
349955292923600A007AB99E /* BrowseViewController.swift in Sources */,
34113BE82934917500AB4919 /* LoginViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension DefaultAuthRepository: AuthRepository {
.flatMap(self.persistentQuestsStorage.saveQuests(with:))
.do(onSuccess: { quests in
let dates = quests.map { $0.date }
NotificationCenter.default.post(name: .updated, object: dates)
NotificationCenter.default.post(name: .userUpdated, object: dates)
})
}
.subscribe()
Expand All @@ -68,7 +68,7 @@ extension DefaultAuthRepository: AuthRepository {
}
.do(onSuccess: { quests in
let dates = quests.map { $0.date }
NotificationCenter.default.post(name: .updated, object: dates)
NotificationCenter.default.post(name: .userUpdated, object: dates)
})
.subscribe()
.disposed(by: self.disposeBag)
Expand Down
93 changes: 53 additions & 40 deletions DailyQuest/DailyQuest/Presentation/Home/View/StatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit

import RxSwift
import RxCocoa
import SnapKit
Expand All @@ -14,9 +15,8 @@ final class StatusView: UIView {
private var disposableBag = DisposeBag()
var profileButtonDidClick = PublishSubject<Void>()
var userDataFetched = PublishSubject<User>()

private let messages = ["화이팅", "잘 할 수 있어", "오늘은 공부를 해보자!", "Hello, World!", "🎹🎵🎶🎵🎶"]

var questStatus = PublishSubject<(Int, Int)>()

// MARK: - Components
private lazy var iconContainer: UIButton = {
var config = UIButton.Configuration.plain()
Expand All @@ -25,117 +25,130 @@ final class StatusView: UIView {
iconContainer.imageView?.contentMode = .scaleToFill
return iconContainer
}()

private lazy var messageBubble: MessageBubbleLabel = {
return MessageBubbleLabel(text: getRandomMessage())
}()

private lazy var statusLabel: UILabel = {
let statusLabel = UILabel()
statusLabel.text = "0 / 0"
statusLabel.font = UIFont.systemFont(ofSize: 14, weight: .bold)
statusLabel.textColor = .maxViolet

return statusLabel
}()

private lazy var progressBar: UIProgressView = {
let progressBar = UIProgressView()
progressBar.trackTintColor = .maxLightGrey
progressBar.progressTintColor = .maxGreen
progressBar.progress = 0.2

return progressBar
}()

private lazy var profileButton: UIButton = {
let largeConfig = UIImage.SymbolConfiguration(pointSize: 40, weight: .bold, scale: .large)
var config = UIButton.Configuration.plain()
config.baseForegroundColor = .maxLightGrey
config.image = UIImage(systemName: "person.crop.circle",
withConfiguration: largeConfig)
config.image = UIImage(systemName: "person.crop.circle")

let button = UIButton(configuration: config)
button.imageView?.contentMode = .scaleAspectFit
button.layer.cornerRadius = 100
return button
}()

// MARK: - Methods
override init(frame: CGRect) {
super.init(frame: frame)

configureUI()
bind()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func configureUI() {
addSubview(iconContainer)
iconContainer.snp.makeConstraints { make in
make.height.equalToSuperview()
make.width.equalTo(iconContainer.snp.height)
make.top.leading.bottom.equalToSuperview()
}

iconContainer.imageView?.snp.makeConstraints { make in
make.width.height.equalToSuperview()
make.top.leading.equalToSuperview()
}

addSubview(messageBubble)
messageBubble.snp.makeConstraints { make in
make.leading.equalTo(iconContainer.snp.trailing)
make.top.equalToSuperview().inset(10)
}

addSubview(progressBar)
progressBar.snp.makeConstraints { make in
make.leading.equalTo(iconContainer.snp.trailing)
make.bottom.equalToSuperview().inset(10)
make.width.equalToSuperview().multipliedBy(0.5)
make.height.equalTo(5)
}

addSubview(profileButton)
profileButton.snp.makeConstraints { make in
make.trailing.equalToSuperview()
make.trailing.equalToSuperview().inset(15)
make.centerY.equalToSuperview()
make.height.equalToSuperview().inset(15)
make.width.equalTo(profileButton.snp.height).multipliedBy(1.0 / 1.0)
}


profileButton.imageView?.snp.makeConstraints({ make in
make.trailing.equalToSuperview()
make.centerY.equalToSuperview()
make.height.width.equalToSuperview()
})

addSubview(statusLabel)
statusLabel.snp.makeConstraints { make in
make.trailing.equalTo(progressBar.snp.trailing)
make.bottom.equalTo(progressBar.snp.top)
}
}

private func bind() {
iconContainer.rx.tap
.subscribe(onNext: { [weak self] _ in
guard let self = self else { return }
self.messageBubble.setText(text: self.getRandomMessage())
})
guard let self = self else { return }
self.messageBubble.setText(text: self.getRandomMessage())
})
.disposed(by: disposableBag)

profileButton.rx.tap
.subscribe(onNext: { [weak self] _ in
self?.profileButtonDidClick.onNext(())
})
self?.profileButtonDidClick.onNext(())
})
.disposed(by: disposableBag)

userDataFetched
.asDriver(onErrorJustReturn: User())
.drive(onNext: { [weak self] user in
guard let self = self else { return }
self.profileButton.imageView?.setImage(with: user.profileURL)
}).disposed(by: disposableBag)


guard let self = self else { return }
self.profileButton.setImage(with: user.profileURL)
}).disposed(by: disposableBag)

questStatus
.asDriver(onErrorJustReturn: (0, 0))
.drive(onNext: { [weak self] (currentState: Int, totalState: Int) in
guard let self = self else { return }
self.statusLabel.text = "\(currentState)/\(totalState)"
let progressValue = totalState > 0 ? (Float(currentState) / Float(totalState)) : 0.0
self.progressBar.setProgress(progressValue, animated: true)
})
.disposed(by: disposableBag)
}
}

extension StatusView {
private func getRandomMessage() -> String {
return messages.randomElement() ?? "Hello,World!"
}
}
Loading

0 comments on commit 763f98f

Please sign in to comment.