Skip to content

Commit

Permalink
[MERGE] Coordinator Pattern ์ ์šฉ (#139)
Browse files Browse the repository at this point in the history
[REFACTOR] Coordinator Pattern ์ ์šฉ (#139)
  • Loading branch information
kimscastle authored Oct 14, 2023
2 parents 4a74903 + 32ecaed commit 8f2a40f
Show file tree
Hide file tree
Showing 64 changed files with 1,283 additions and 214 deletions.
204 changes: 200 additions & 4 deletions LionHeart-iOS/LionHeart-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions LionHeart-iOS/LionHeart-iOS/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import KakaoSDKAuth
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
var appCoordinator: AppCoordinator?

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
if let url = URLContexts.first?.url {
Expand All @@ -31,8 +32,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
self.window = UIWindow(windowScene: windowScene)
/// ํฐํŠธ๋“ฑ๋ก
Font.registerFonts()
let splashViewController = SplashViewController(manager: SplashManagerImpl(authService: AuthServiceImpl(apiService: APIService())))
let navigationController = UINavigationController(rootViewController: splashViewController)

let navigationController = UINavigationController()
appCoordinator = AppCoordinator(navigationController: navigationController)
appCoordinator?.start()
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
}
Expand Down
13 changes: 13 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Global/Enums/TokenState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TokenState.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

enum TokenState {
case valid
case expired
}
13 changes: 13 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Global/Enums/UserState.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// UserState.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

enum UserState {
case verified
case nonVerified
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ extension UIViewController {
articleDetailViewController.isModalInPresentation = true
articleDetailViewController.modalPresentationStyle = .fullScreen
self.present(articleDetailViewController, animated: true)

}
}
10 changes: 0 additions & 10 deletions LionHeart-iOS/LionHeart-iOS/Global/Literals/DummyModel.swift

This file was deleted.

31 changes: 31 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Global/Protocols/Coordinator.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Coordinator.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/13.
//

import UIKit

protocol Coordinator : AnyObject {
var parentCoordinator: Coordinator? { get set }
var children: [Coordinator] { get set }
var navigationController : UINavigationController { get set }

func start()
}

extension Coordinator {

/// Removing a coordinator inside a children. This call is important to prevent memory leak.
/// - Parameter coordinator: Coordinator that finished.
func childDidFinish(_ coordinator : Coordinator){
// Call this if a coordinator is done.
for (index, child) in children.enumerated() {
if child === coordinator {
children.remove(at: index)
break
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import UIKit

final class LHNavigationBarView: UIView {

// MARK: - UI Components
private let titleLabel = LHLabel(type: .head4, color: .white)


private let leftBarItem: UIButton = {
let button = UIButton()
button.tintColor = .designSystem(.white)
Expand Down Expand Up @@ -49,8 +47,6 @@ final class LHNavigationBarView: UIView {
return stackView
}()

// MARK: - Properties

private let type: LHNavigationType

private weak var viewController: UIViewController?
Expand All @@ -77,15 +73,13 @@ final class LHNavigationBarView: UIView {
self.backgroundColor = type.backgroundColor
}

// MARK: - addsubView
private func setHierarchy() {
self.addSubviews(leftBarItem,
titleLabel,
rightBarItemsStackView,
graySepartorLine)
}

// MARK: - autolayout์„ค์ •
private func setLayout() {
self.snp.makeConstraints { make in
make.height.equalTo(ScreenUtils.getHeight(60))
Expand Down Expand Up @@ -123,20 +117,11 @@ final class LHNavigationBarView: UIView {
}
}

// MARK: - Helpers

private func setBackButtonWithTitle() {
self.titleLabel.text = type.title
self.leftBarItem.setImage(UIImage(systemName: "arrow.backward"), for: .normal)
if type == .onboarding {
self.leftBarItem.addButtonAction { _ in
self.backButtonActionHandler?()
}
return
}
self.leftBarItem.addButtonAction { [weak self] _ in
guard let self else { return }
self.viewController?.navigationController?.popViewController(animated: true)
self.leftBarItem.addButtonAction { _ in
self.backButtonActionHandler?()
}
}

Expand Down Expand Up @@ -165,10 +150,9 @@ final class LHNavigationBarView: UIView {
self.leftBarItem.setImage(UIImage(systemName: "xmark"), for: .normal)
self.leftBarItem.addButtonAction { [weak self] _ in
guard let self else { return }
self.viewController?.dismiss(animated: true)
self.backButtonActionHandler?()
}
}

}

extension LHNavigationBarView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

final class BookmarkMangerImpl: BookmarkManger {
final class BookmarkMangerImpl: BookmarkManager {

private let bookmarkService: BookmarkService

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ArticleDetailManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol ArticleDetailManager {
func getArticleDetail(articleId: Int) async throws -> [BlockTypeAppData]
func postBookmark(model: BookmarkRequest) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// ArticleListByCategoryManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol ArticleListByCategoryManager {
func getArticleListByCategory(categoryString: String) async throws -> CurriculumWeekData
func postBookmark(model: BookmarkRequest) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// BookmarkManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol BookmarkManager {
func getBookmark() async throws -> BookmarkAppData
func postBookmark(model: BookmarkRequest) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// ChallengeManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol ChallengeManager {
func inquireChallengeInfo() async throws -> ChallengeData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// CurriculumListManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol CurriculumListManager {
func postBookmark(model: BookmarkRequest) async throws
func getArticleListByWeekInfo(week: Int) async throws -> CurriculumWeekData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// CurriculumManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol CurriculumManager {
func getCurriculumServiceInfo() async throws -> UserInfoData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// LoginManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol LoginManager {
func login(type: LoginType, kakaoToken: String) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// MyPageManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol MyPageManager {
func getMyPage() async throws -> BadgeProfileAppData
func resignUser() async throws
func logout(token: UserDefaultToken) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// OnboardingManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol OnboardingManager {
func signUp(type: LoginType, onboardingModel: UserOnboardingModel) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// SplashManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol SplashManager {
func reissueToken(token: Token) async throws -> Token?
func logout(token: UserDefaultToken) async throws
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// TodayManager.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/10/14.
//

import Foundation

protocol TodayManager {
func inquiryTodayArticle() async throws -> TodayArticle
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import UIKit

import SnapKit



final class ArticleCategoryViewController: UIViewController {

weak var coordinator: ArticleCategoryNavigation?

private lazy var navigationBar = LHNavigationBarView(type: .explore, viewController: self)
private lazy var titleLabel = LHLabel(type: .head2, color: .white, lines: 2, basicText: "์นดํ…Œ๊ณ ๋ฆฌ๋ณ„\n์•„ํ‹ฐํด ๋ชจ์•„๋ณด๊ธฐ")
Expand Down Expand Up @@ -67,13 +71,11 @@ private extension ArticleCategoryViewController {

func setAddTarget() {
navigationBar.rightFirstBarItemAction {
let bookmarkViewController = BookmarkViewController(manager: BookmarkMangerImpl(bookmarkService: BookmarkServiceImpl(apiService: APIService())))
self.navigationController?.pushViewController(bookmarkViewController, animated: true)
self.coordinator?.navigationLeftButtonTapped()
}

navigationBar.rightSecondBarItemAction {
let mypageViewController = MyPageViewController(manager: MyPageManagerImpl(mypageService: MyPageServiceImpl(apiService: APIService()), authService: AuthServiceImpl(apiService: APIService())))
self.navigationController?.pushViewController(mypageViewController, animated: true)
self.coordinator?.navigationRightButtonTapped()
}
}

Expand Down Expand Up @@ -108,9 +110,7 @@ extension ArticleCategoryViewController: UICollectionViewDataSource {
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let articleListbyCategoryViewController = ArticleListByCategoryViewController(manager: ArticleListByCategoryMangerImpl(articleService: ArticleServiceImpl(apiService: APIService()), bookmarkService: BookmarkServiceImpl(apiService: APIService())))
articleListbyCategoryViewController.categoryString = dummyCase[indexPath.item].categoryString
self.navigationController?.pushViewController(articleListbyCategoryViewController, animated: true)
coordinator?.articleListCellTapped(categoryName: dummyCase[indexPath.item].categoryString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class CopyRightTableViewCell: UITableViewCell, TableViewCellRegisterDequeu
private let copyrightLabel = LHLabel(type: .body4, color: .gray600, basicText: "๋ชจ๋“  ์ฝ˜ํ…์ธ ๋Š” ์ œ๊ณต์ž์™€ ๋ผ์ด์˜จํ•˜ํŠธ์— ์ €์ž‘๊ถŒ์ด ์žˆ์Šต๋‹ˆ๋‹ค.\n์ €์ž‘๊ถŒ๋ฒ•์— ์˜๊ฑฐ ๋ฌด๋‹จ ์ „์žฌ ๋ฐ ์žฌ๋ฐฐํฌ๋ฅผ ๊ธˆ์ง€ํ•ฉ๋‹ˆ๋‹ค.")

//TODO: - inputData๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ..
var inputData: DummyModel?
// var inputData: DummyModel?

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
Expand Down
Loading

0 comments on commit 8f2a40f

Please sign in to comment.