Skip to content

Commit

Permalink
Merge pull request #103 from Team-HMH/feat/#102-Challenge
Browse files Browse the repository at this point in the history
Feat [#102] Challenge 화면 챌린지 생성 경우 구현
  • Loading branch information
kim-seonwoo authored Jan 17, 2024
2 parents 45c1dfc + d537f4e commit 6d93622
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 24 deletions.
1 change: 1 addition & 0 deletions HMH_iOS/HMH_iOS/Global/Literals/Literal/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ enum ImageLiterals {
static var icChallengeSuccess: UIImage { .load(named: "challenge_ic_success") }
static var icAddNewChallengeBackground: UIImage { .load(named: "ios_add_new_challenge_img") }
static var icSevenDaysChallengeBackground: UIImage { .load(named: "ios_sevenDays_challenge_img") }
static var icFourteenDaysChallengeBackground: UIImage { .load(named: "img_ios_14") }
}

enum Alert {
Expand Down
2 changes: 2 additions & 0 deletions HMH_iOS/HMH_iOS/Global/Literals/String/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ enum StringLiteral {
static var NavigationBarTitle = "나의 챌린지"
enum Date {
static var dateHeaderTitle = "3시간"
static var createHeaderTitle = "새로운 여정을 위한\n챌린지를 생성해 주세요"
static var dateHeaderSubTitle = "목표 이용시간"
static var challengeButton = "챌린지 생성하기"
}
enum AppList {
static var appListHeaderTitle = "앱 잠금"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "img_ios_14.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class AppAddCollectionReusableView: UICollectionReusableView {
return hostingController
}()


override init(frame: CGRect) {
super.init(frame: frame)
setUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,34 @@ import UIKit
import SnapKit
import Then

enum BackgroundImage {
case sevenDays
case fourteenDays
case completed
}

final class GrayBackgroundView: UICollectionReusableView {

var backgroundType: BackgroundImage?

private lazy var backgroundImageView = UIImageView().then {
backgroundType = .sevenDays
switch backgroundType {
case .sevenDays:
$0.image = ImageLiterals.Challenge.icSevenDaysChallengeBackground
case .fourteenDays:
$0.image = ImageLiterals.Challenge.icFourteenDaysChallengeBackground
case .completed:
$0.image = ImageLiterals.Challenge.icAddNewChallengeBackground
case .none:
$0.image = ImageLiterals.Challenge.icAddNewChallengeBackground
}
}

private let grayBackgroundView = UIView().then {
$0.backgroundColor = .gray7
}

override init(frame: CGRect) {
super.init(frame: frame)
setUI()
Expand All @@ -27,16 +49,21 @@ final class GrayBackgroundView: UICollectionReusableView {
}

private func setViewHierarchy() {
self.addSubview(grayBackgroundView)
self.addSubviews(grayBackgroundView, backgroundImageView)
}

private func setConstraints() {
grayBackgroundView.snp.makeConstraints {
$0.leading.trailing.bottom.equalToSuperview()
$0.leading.trailing.equalToSuperview()
$0.bottom.equalToSuperview().inset(12)
$0.top.equalToSuperview().offset(-200)
}

backgroundImageView.snp.makeConstraints {
$0.leading.trailing.bottom.equalTo(grayBackgroundView)
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import UIKit
import SnapKit
import Then


final class TitleCollectionReusableView: UICollectionReusableView {

static let identifier = "TitleCollectionReusableView"

private var isCompleted: Bool = true
var isButtonTapped = false

let button = OnboardingButton(buttonStatus: .enabled)
private let subTitleLabel = UILabel().then {
$0.text = StringLiteral.Challenge.Date.dateHeaderSubTitle
$0.font = .iosText5Medium16
Expand All @@ -31,6 +33,7 @@ final class TitleCollectionReusableView: UICollectionReusableView {
override init(frame: CGRect) {
super.init(frame: frame)
setUI()
configureTitle()
}

required init?(coder: NSCoder) {
Expand All @@ -43,18 +46,43 @@ final class TitleCollectionReusableView: UICollectionReusableView {
}

private func setViewHierarchy() {
self.addSubviews(titleLabel, subTitleLabel)
if isCompleted {
self.addSubviews(titleLabel, button)
} else {
self.addSubviews(titleLabel, subTitleLabel)
}
}

private func setConstraints() {
titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().offset(29.adjustedWidth)
$0.bottom.equalToSuperview().inset(26.adjusted)
if isCompleted {
titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().offset(20.adjustedWidth)
$0.top.equalToSuperview().offset(17.adjusted)
}

button.snp.makeConstraints {
$0.width.equalTo(336.adjustedWidth)
$0.leading.equalToSuperview().offset(20.adjustedWidth)
$0.bottom.equalToSuperview().offset(12.adjusted)
}
} else {
titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().offset(29.adjustedWidth)
$0.bottom.equalToSuperview().inset(26.adjusted)
}

subTitleLabel.snp.makeConstraints {
$0.leading.equalTo(titleLabel)
$0.bottom.equalTo(titleLabel.snp.top).offset(-9.adjusted)
}
}

subTitleLabel.snp.makeConstraints {
$0.leading.equalTo(titleLabel)
$0.bottom.equalTo(titleLabel.snp.top).offset(-9.adjusted)
}

private func configureTitle() {
if isCompleted{
titleLabel.setTextWithLineHeightLeft(text: StringLiteral.Challenge.Date.createHeaderTitle, lineHeight: 33)
titleLabel.font = .iosTitle3Semibold22
button.setButtonText(buttonTitle: StringLiteral.Challenge.Date.challengeButton)
}
}

Expand All @@ -66,5 +94,4 @@ final class TitleCollectionReusableView: UICollectionReusableView {
}
isButtonTapped.toggle()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,18 @@ final class ChallengeViewController: UIViewController {
isPointImage: true,
isBackGroundGray: true,
titleText: StringLiteral.Challenge.NavigationBarTitle)

private let challengeView = ChallengeView(frame: .zero, appAddButtonViewModel: BlockingApplicationModel.shared)

private var selectedIndex = IndexPath()

override func loadView() {
self.view = challengeView
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
requestPermision()
challengeView.configreCollectionView()
configureTabBar(isCreatedChallenge: isCreatedChallenge)
}

override func viewDidLoad() {
super.viewDidLoad()
setUI()
Expand All @@ -52,13 +48,18 @@ final class ChallengeViewController: UIViewController {
}

private func setViewHierarchy() {
view.addSubviews(navigationBar)
view.addSubviews(navigationBar, challengeView)
}

private func setConstraints() {
navigationBar.snp.makeConstraints {
$0.top.leading.trailing.equalToSuperview()
}

challengeView.snp.makeConstraints {
$0.top.equalTo(navigationBar.snp.bottom)
$0.leading.trailing.bottom.equalToSuperview()
}
}

func configureTabBar(isCreatedChallenge: Bool) {
Expand All @@ -73,8 +74,14 @@ final class ChallengeViewController: UIViewController {
private func setDelegate() {
challengeView.challengeCollectionView.delegate = self
}

func onTabButton() {
let nextViewController = CreatePeriodController()
self.navigationController?.pushViewController(nextViewController, animated: false)
}
}


extension ChallengeViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
if let selectedIndexPath = collectionView.indexPathsForSelectedItems?.first {
Expand Down
27 changes: 26 additions & 1 deletion HMH_iOS/HMH_iOS/Presentation/Challenge/Views/ChallengeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ final class ChallengeView: UIView {

private var appAddButtonViewModel: BlockingApplicationModel = BlockingApplicationModel.shared
private var cancellables: Set<AnyCancellable> = []
var isChallengeComplete: Bool = false

private let goalTime: Int = 3
private var days: Int = 7
Expand Down Expand Up @@ -101,6 +102,7 @@ extension ChallengeView: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch section{
case 0:
if isChallengeComplete { return 0 }
return days
case 1:
return appList.count
Expand Down Expand Up @@ -148,6 +150,7 @@ extension ChallengeView: UICollectionViewDataSource {
if kind == StringLiteral.Challenge.Idetifier.titleHeaderViewId {
guard let header = collectionView.dequeueReusableSupplementaryView(ofKind: StringLiteral.Challenge.Idetifier.titleHeaderViewId, withReuseIdentifier: TitleCollectionReusableView.identifier, for: indexPath) as? TitleCollectionReusableView
else { return UICollectionReusableView() }
header.button.addTarget(self, action: #selector(onTapButton), for: .touchUpInside)
return header
} else if kind == StringLiteral.Challenge.Idetifier.appListHeaderViewId {
if let header = collectionView.dequeueReusableSupplementaryView(ofKind: StringLiteral.Challenge.Idetifier.appListHeaderViewId, withReuseIdentifier: AppCollectionReusableView.identifier, for: indexPath) as? AppCollectionReusableView {
Expand All @@ -164,6 +167,14 @@ extension ChallengeView: UICollectionViewDataSource {
return UICollectionReusableView()
}
}

@objc
func onTapButton() {
if let challengeViewController = self.getChallengeViewController() {
challengeViewController.onTabButton()
}
}

}


Expand All @@ -187,13 +198,14 @@ extension ChallengeView {
group.contentInsets = .init(top: 0, leading: groupInset, bottom: 0, trailing: groupInset)
group.interItemSpacing = .fixed(7)


let section = NSCollectionLayoutSection(group: group)
section.orthogonalScrollingBehavior = .groupPagingCentered
section.interGroupSpacing = 19
section.contentInsets = .init(top: 0, leading: 0, bottom: 35, trailing:0)

let headerHeight = isChallengeComplete ? 275.adjustedHeight : 145.adjustedHeight

let headerHeight = UIScreen().isLongerThan812pt ? 145 : 165
let headerSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0), heightDimension: .estimated(CGFloat(headerHeight)))

let headerElement = NSCollectionLayoutBoundarySupplementaryItem(layoutSize: headerSize,
Expand Down Expand Up @@ -248,3 +260,16 @@ extension ChallengeView {
return layout
}
}

extension ChallengeView {
func getChallengeViewController() -> ChallengeViewController? {
var responder: UIResponder? = self
while let nextResponder = responder?.next {
if let viewController = nextResponder as? ChallengeViewController {
return viewController
}
responder = nextResponder
}
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,3 @@ extension CreateTotalTimeController: TimePickerDelegate {
totalTime = selectedValue
}
}

0 comments on commit 6d93622

Please sign in to comment.