-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] #187 성과 UI + API 연결
- Loading branch information
Showing
10 changed files
with
516 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 0 additions & 100 deletions
100
Smeem-iOS/Smeem-iOS/Global/UIComponents/BottomSheet/BadgeBottomSheetViewController.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
Smeem-iOS/Smeem-iOS/Presentation/BadgeBottomSheet/BadgeBottomSheetViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
// | ||
// BadgeBottomSheetViewController.swift | ||
// Smeem-iOS | ||
// | ||
// Created by Joon Baek on 2024/04/30. | ||
// | ||
|
||
import UIKit | ||
|
||
import Combine | ||
import SnapKit | ||
import Kingfisher | ||
|
||
enum BadgeType { | ||
case welcome | ||
case diaryCount | ||
case dailyDiary | ||
} | ||
|
||
// MARK: - BadgeBottomSheet | ||
|
||
final class BadgeBottomSheetViewController: BaseViewController { | ||
|
||
// MARK: - Properties | ||
|
||
private var cancelBag = Set<AnyCancellable>() | ||
|
||
|
||
// MARK: - UI Properties | ||
|
||
private lazy var dismissButton: UIButton = { | ||
let button = UIButton() | ||
button.setBackgroundImage(Constant.Image.icnCancelBlack, for: .normal) | ||
return button | ||
}() | ||
|
||
private lazy var badgeImageView: UIImageView = makeImage() | ||
|
||
private lazy var contentStackView: UIStackView = makeContentView() | ||
private lazy var headerLabel: UILabel = makeLabel(font: .h3, textColor: .smeemBlack) | ||
private lazy var bodyLabel: UILabel = makeLabel(font: .b3, textColor: .smeemBlack) | ||
|
||
private lazy var descriptionLabel: UILabel = makeLabel(font: .b3, textColor: .gray500) | ||
|
||
// MARK: - Life Cycle | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
setLayout() | ||
bind() | ||
} | ||
|
||
private func bind() { | ||
dismissButton.tapPublisher | ||
.sink { [weak self] _ in | ||
self?.dismiss(animated: true) | ||
} | ||
.store(in: &cancelBag) | ||
} | ||
|
||
func setData(data: MySummaryBadgeAppData) { | ||
// 배지 획득시 | ||
if data.hasBadge { | ||
let url = URL(string: data.imageUrl) | ||
badgeImageView.kf.setImage(with: url) | ||
|
||
switch data.type { | ||
case "EVENT": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForBadgeOwner | ||
descriptionLabel.text = "100%의 사용자가 획득했어요." | ||
case "COUNTING": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForBadgeOwner | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
case "COMBO": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForBadgeOwner | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
case "EXPLORATION": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForBadgeOwner | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
default: break | ||
} | ||
} else { | ||
switch data.type { | ||
case "EVENT": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForNonBadgeOwner | ||
descriptionLabel.text = "100%의 사용자가 획득했어요." | ||
case "COUNTING": | ||
headerLabel.text = data.name | ||
guard let number = data.remainingNumber else { return } | ||
bodyLabel.text = "일기를 \(number)번 더 작성해요" | ||
let attributedStr = NSMutableAttributedString(string: bodyLabel.text!) | ||
attributedStr.addAttribute(.foregroundColor, value: UIColor.point, range: (bodyLabel.text! as NSString).range(of: "\(number)")) | ||
bodyLabel.attributedText = attributedStr | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
case "COMBO": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForNonBadgeOwner | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
case "EXPLORATION": | ||
headerLabel.text = data.name | ||
bodyLabel.text = data.contentForNonBadgeOwner | ||
descriptionLabel.text = "\(data.badgeAcquisitionRatio)%의 사용자가 획득했어요." | ||
default: break | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Extensions | ||
|
||
extension BadgeBottomSheetViewController { | ||
private func setLayout() { | ||
contentStackView.addArrangedSubviews(headerLabel, bodyLabel) | ||
view.addSubviews(dismissButton, | ||
badgeImageView, | ||
contentStackView, | ||
descriptionLabel) | ||
|
||
dismissButton.snp.makeConstraints { make in | ||
make.top.trailing.equalToSuperview().inset(8) | ||
} | ||
|
||
badgeImageView.snp.makeConstraints { make in | ||
make.top.equalTo(dismissButton.snp.bottom).offset(5) | ||
make.centerX.equalToSuperview() | ||
make.size.equalTo(120) | ||
} | ||
|
||
contentStackView.snp.makeConstraints { make in | ||
make.top.equalTo(badgeImageView.snp.bottom).offset(26) | ||
make.leading.trailing.equalToSuperview().inset(23) | ||
} | ||
|
||
descriptionLabel.snp.makeConstraints { make in | ||
make.top.equalTo(contentStackView.snp.bottom).offset(12) | ||
make.centerX.equalToSuperview() | ||
} | ||
} | ||
|
||
private func makeContentView() -> UIStackView { | ||
let stackView = UIStackView() | ||
stackView.axis = .vertical | ||
stackView.spacing = 8 | ||
stackView.alignment = .center | ||
return stackView | ||
} | ||
|
||
private func makeLabel(font: UIFont, textColor: UIColor) -> UILabel { | ||
let label = UILabel() | ||
label.font = font | ||
label.textColor = textColor | ||
return label | ||
} | ||
|
||
private func makeImage() -> UIImageView { | ||
let image = UIImageView() | ||
image.image = Constant.Image.btnLockBadge | ||
return image | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.