diff --git a/Keyneez/Keyneez/Global/Auth/UserSession.swift b/Keyneez/Keyneez/Global/Auth/UserSession.swift index 343a7f2..1064219 100644 --- a/Keyneez/Keyneez/Global/Auth/UserSession.swift +++ b/Keyneez/Keyneez/Global/Auth/UserSession.swift @@ -21,6 +21,6 @@ final class UserSession { private init() { } var profile: Profile? - var accessToken: String? = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2tleSI6MzEyLCJpYXQiOjE2NzM2NDExOTUsImV4cCI6MTY3MzY0ODM5NX0.thu5Mu3sVDYgC_lnKDbXthIo0z4ubl-Col67OTm4Eh8" + var accessToken: String? = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2tleSI6MzE1LCJpYXQiOjE2NzM2NDE0MjksImV4cCI6MTY3MzY0ODYyOX0.ChHzYfCvhd2idnpnBC2SBXllt3335YcCXiSbCYId2h0" } diff --git a/Keyneez/Keyneez/Tab/Home/Controllers/HomeContentViewController.swift b/Keyneez/Keyneez/Tab/Home/Controllers/HomeContentViewController.swift index c1da71c..54970cf 100644 --- a/Keyneez/Keyneez/Tab/Home/Controllers/HomeContentViewController.swift +++ b/Keyneez/Keyneez/Tab/Home/Controllers/HomeContentViewController.swift @@ -95,38 +95,17 @@ extension HomeContentViewController: UICollectionViewDelegateFlowLayout { extension HomeContentViewController: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { -// switch(segmentedNumber) { -// case 0: -// return h.count -// case 1: -// return popularContentList.count -// case 2: -// return newestContentList.count -// default: -// return recommendContentList.count -// } return contentList.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let model: [HomeContentModel] -// switch(segmentedNumber) { -// case 0: -// model = recommendContentList -// case 1: -// model = popularContentList -// case 2: -// model = newestContentList -// default: -// model = recommendContentList -// } guard let homeContentCell = collectionView.dequeueReusableCell( withReuseIdentifier: HomeContentCollectionViewCell.identifier, for: indexPath) as? HomeContentCollectionViewCell else { return UICollectionViewCell() } + homeContentCell.bindHomeData(model: contentList[indexPath.item]) // 여기서 setCategory homeContentCell.setHomeCategoryCard(category: contentList[indexPath.item].category[0]) - homeContentCell.setHomeCategoryView(category: contentList[indexPath.item].category[0]) return homeContentCell } } diff --git a/Keyneez/Keyneez/Tab/Home/Controllers/HomeViewController.swift b/Keyneez/Keyneez/Tab/Home/Controllers/HomeViewController.swift index 3734db9..c9a17ea 100644 --- a/Keyneez/Keyneez/Tab/Home/Controllers/HomeViewController.swift +++ b/Keyneez/Keyneez/Tab/Home/Controllers/HomeViewController.swift @@ -47,11 +47,23 @@ final class HomeViewController: NiblessViewController, NavigationBarProtocol { setLayout() addContentViews(asChildViewController: HomeContentViewController()) addNavigationViewToSubview() + guard let token = UserSession.shared.accessToken else { return } + repository.getAllContents(token: token) { + [weak self] arr in + guard let self else {return} + self.datasources.append(arr) + DispatchQueue.main.async { + self.VCs.forEach { + $0.contentList = self.datasources[0] + $0.recommendContentCollectionView.reloadData() + } + } + } } private var repository: ContentRepository = KeyneezContentRepository() var datasources: [[HomeContentResponseDto]] = [] - let VCs: [HomeContentViewController] = [HomeContentViewController(), HomeContentViewController(), HomeContentViewController()] + var VCs: [HomeContentViewController] = [HomeContentViewController(), HomeContentViewController(), HomeContentViewController()] override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) diff --git a/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift b/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift index 739bc63..452bc41 100644 --- a/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift +++ b/Keyneez/Keyneez/Tab/Home/Views/HomeContentCollectionViewCell.swift @@ -15,6 +15,7 @@ final class HomeContentCollectionViewCell: UICollectionViewCell { static let identifier = "HomeContentCollectionViewCell" var homeContentID = -1 var homeContentImageURL: String = "" + private var homeContentCategory = "" let repository: ContentRepository = KeyneezContentRepository() // MARK: - UI Components @@ -47,7 +48,7 @@ final class HomeContentCollectionViewCell: UICollectionViewCell { $0.font = UIFont.font(.pretendardSemiBold, ofSize: 12) $0.textColor = UIColor.gray900 } - private var homeContentCategoryView = CategoryView() + lazy var homeContentCategoryView = CategoryView() private lazy var likeButton = UIButton().then { $0.setImage(UIImage(named: "ic_favorite_home_line"), for: .normal) $0.setImage(UIImage(named: "ic_favorite_home_filled"), for: .selected) @@ -64,6 +65,8 @@ final class HomeContentCollectionViewCell: UICollectionViewCell { $0.font = UIFont.font(.pretendardMedium, ofSize: 14) $0.textColor = UIColor.gray600 } + + var categoryInfo: String = "" // MARK: - Life Cycle override init(frame: CGRect) { @@ -76,6 +79,33 @@ final class HomeContentCollectionViewCell: UICollectionViewCell { } extension HomeContentCollectionViewCell { + +// override func prepareForReuse() { +// super.prepareForReuse() +// self.homeContentCategoryView = setHomeCategoryView(category: categoryInfo) +// } + + private func setHomeCategoryView(category: String) -> CategoryView { + let categoryview = CategoryView() + homeContentCategoryView.setCategory(with: category) + switch(category) { + case "진로" : + categoryview.setCategory(with: "진로") + case "봉사": + categoryview.setCategory(with: "봉사") + case "여행": + categoryview.setCategory(with: "여행") + case "문화": + categoryview.setCategory(with: "문화") + case "경제": + categoryview.setCategory(with: "경제") + default: + break + } + return categoryview + } + + private func setLayout() { contentView.addSubviews(shadowView, containerView) containerView.addSubviews( @@ -139,13 +169,10 @@ extension HomeContentCollectionViewCell { func bindHomeData(model: HomeContentResponseDto) { homeContentID = model.contentKey dateLabel.text = setDateLabel(model: model) -// category.text = model.categoty[0] // 카테고리 여러 개 받기 contentTitle.text = setTitle(fullTitle: model.contentTitle) contentIntroduction.text = model.introduction likeButton.isSelected = model.liked contentImageView.setImage(url: model.contentImg) -// setCategoryCard(category: model.category[0]) // 여기야 -// homeContentCategoryView.setCategory(with: model.category[0]) } private func setTitle(fullTitle: String) -> String { guard let title = fullTitle as? String else {return ""} @@ -163,7 +190,8 @@ extension HomeContentCollectionViewCell { if model.startAt!.isEmpty || model.endAt!.isEmpty { dateView.isHidden = true; return "" } return getDate(fullDate: model.startAt!) + " ~ " + getDate(fullDate: model.endAt!) } - func setHomeCategoryCard(category: String) { + func setHomeCategoryCard(category: String) { // 카드 색 변경 + homeContentCategoryView.setCategory(with: category) switch(category) { case "진로" : cardImageView.image = UIImage(named: "card_green_home") @@ -180,10 +208,6 @@ extension HomeContentCollectionViewCell { } } - func setHomeCategoryView(category: String) { - homeContentCategoryView.setCategory(with: category) - } - @objc private func touchUpLikeButton() { likeButton.isSelected = !likeButton.isSelected diff --git a/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift b/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift index 213c06e..e54f467 100644 --- a/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift +++ b/Keyneez/Keyneez/Tab/KeyneezTabbarController.swift @@ -40,8 +40,9 @@ final class KeyneezTabbarController: UITabBarController { extension KeyneezTabbarController { fileprivate func createTabbarItems() { -// let homeViewController = HomeViewController() -// let homeViewNavigationController = makeHomeNaviController(homeViewController: homeViewController) + let homeViewController = HomeViewController() + homeViewController.viewWillAppear(true) + let homeViewNavigationController = makeHomeNaviController(homeViewController: homeViewController) // // guard let token = UserSession.shared.accessToken else { return } // repository.getAllContents(token: token) { @@ -55,7 +56,7 @@ extension KeyneezTabbarController { // } let tabInfos: [TabInfo] = [ - TabInfo(viewController: HomeViewController.self, title: "홈", imageName: "ic_home_tabbar"), +// TabInfo(viewController: HomeViewController.self, title: "홈", imageName: "ic_home_tabbar"), TabInfo(viewController: LikeViewController.self, title: "좋아요", imageName: "ic_like_tabbar"), TabInfo(viewController: IDViewController.self, imageName: "id_card_tabbar"), TabInfo(viewController: MyPageViewController.self, title: "캐릭터", @@ -66,9 +67,10 @@ extension KeyneezTabbarController { var navigations = tabInfos.map { makeViewController(viewController: $0.viewController!, title: $0.title, imageName: $0.imageName) } + navigations.insert(homeViewNavigationController, at: 0) navigations[3].tabBarItem.isEnabled = false navigations[4].tabBarItem.isEnabled = false -// navigations.insert(homeViewNavigationController, at: 0) +// homeViewNavigationController.viewDidLoad() self.viewControllers = navigations } @@ -85,10 +87,11 @@ extension KeyneezTabbarController { return nav } -// private func makeHomeNaviController(homeViewController: HomeViewController) -> UINavigationController { -// let nav = UINavigationController(rootViewController: homeViewController) -// nav.isNavigationBarHidden = true -// nav.tabBarItem = UITabBarItem(title: "홈", image: UIImage(named: "ic_home_tabbar"), selectedImage: nil) -// return nav -// } + private func makeHomeNaviController(homeViewController: HomeViewController) -> UINavigationController { + let nav = UINavigationController(rootViewController: homeViewController) + homeViewController.viewWillAppear(true) + nav.isNavigationBarHidden = true + nav.tabBarItem = UITabBarItem(title: "홈", image: UIImage(named: "ic_home_tabbar"), selectedImage: nil) + return nav + } }