Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] #198 - 홈 UI 로직 변경 #204

Merged
merged 17 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions iOS-NOTTODO/iOS-NOTTODO.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
09A1465F2A192C4900DDC308 /* WeekMissionResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A1465E2A192C4900DDC308 /* WeekMissionResponseDTO.swift */; };
09A146652A1964B500DDC308 /* AddAnotherDayResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09A146642A19649A00DDC308 /* AddAnotherDayResponseDTO.swift */; };
09C8602D2AB14B4800C4F4B1 /* FSCalendar in Frameworks */ = {isa = PBXBuildFile; productRef = 09C8602C2AB14B4800C4F4B1 /* FSCalendar */; };
09CF56042B09F23800526C8C /* HomeDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09CF56032B09F23800526C8C /* HomeDataSource.swift */; };
09DCCD1F2A18ED76003DCF8A /* DailyMissionResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DCCD1E2A18ED76003DCF8A /* DailyMissionResponseDTO.swift */; };
09DCCD212A18EF43003DCF8A /* HomeSevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DCCD202A18EF43003DCF8A /* HomeSevice.swift */; };
09DCCD232A18EFB0003DCF8A /* HomeAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09DCCD222A18EFB0003DCF8A /* HomeAPI.swift */; };
Expand Down Expand Up @@ -202,6 +203,7 @@
099FC98829B3233D005B37E6 /* CalendarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarView.swift; sourceTree = "<group>"; };
09A1465E2A192C4900DDC308 /* WeekMissionResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekMissionResponseDTO.swift; sourceTree = "<group>"; };
09A146642A19649A00DDC308 /* AddAnotherDayResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddAnotherDayResponseDTO.swift; sourceTree = "<group>"; };
09CF56032B09F23800526C8C /* HomeDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeDataSource.swift; sourceTree = "<group>"; };
09DCCD1E2A18ED76003DCF8A /* DailyMissionResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DailyMissionResponseDTO.swift; sourceTree = "<group>"; };
09DCCD202A18EF43003DCF8A /* HomeSevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeSevice.swift; sourceTree = "<group>"; };
09DCCD222A18EFB0003DCF8A /* HomeAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeAPI.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -451,6 +453,7 @@
isa = PBXGroup;
children = (
3B027A9D299C34DA00BEB65C /* HomeViewController.swift */,
09CF56032B09F23800526C8C /* HomeDataSource.swift */,
092C09B42A484DD900E9B06B /* HomeDeleteViewController.swift */,
0930DE6129B80550007958DE /* MissionDetailViewController.swift */,
09582B4E29BEBAFA00EF3207 /* DetailCalendarViewController.swift */,
Expand Down Expand Up @@ -1276,6 +1279,7 @@
09022D4629C44BC300DE6E49 /* MissionCalendarCell.swift in Sources */,
6CA2083A2A195906001C4247 /* AuthResponseDTO.swift in Sources */,
09582B4B29BDE37C00EF3207 /* DetailFooterReusableView.swift in Sources */,
09CF56042B09F23800526C8C /* HomeDataSource.swift in Sources */,
093DB03F2A15FCC100ECA5F6 /* MissionDetailResponseDTO.swift in Sources */,
6CF4705B29A68EA9008D145C /* URLConstant.swift in Sources */,
3BD3B5C829B8F82C00D3575B /* AddMissionTextFieldView.swift in Sources */,
Expand Down
55 changes: 31 additions & 24 deletions iOS-NOTTODO/iOS-NOTTODO/Network/API/Home/HomeAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,44 @@ final class HomeAPI {
public private(set) var missionDailyData: GeneralArrayResponse<DailyMissionResponseDTO>?
public private(set) var missionDetailDailyData: GeneralResponse<MissionDetailResponseDTO>?
public private(set) var updateMissionStatus: GeneralResponse<DailyMissionResponseDTO>?
public private(set) var missionWeekly: GeneralResponse<WeekMissionResponseDTO>?
public private(set) var missionWeekly: GeneralArrayResponse<WeekMissionResponseDTO>?
public private(set) var addAnotherDay: GeneralResponse<AddAnotherDayResponseDTO>?
public private(set) var particularDays: GeneralArrayResponse<String>?

// MARK: - GET

func getDailyMission(date: String, completion: @escaping (NetworkResult<Any>) -> Void) {
homeProvider.request(.dailyMission(date: date)) { response in
switch response {
case let .success(response):
let statusCode = response.statusCode
let data = response.data
let networkResult = NetworkBase.judgeStatus(by: statusCode, data, [DailyMissionResponseDTO].self)
completion(networkResult)
case let .failure(err):
print(err)
func getDailyMission(date: String, completion: @escaping (GeneralArrayResponse<DailyMissionResponseDTO>?) -> Void) {
homeProvider.request(.dailyMission(date: date)) { result in
switch result {
case .success(let response):
do {
self.missionDailyData = try response.map(GeneralArrayResponse<DailyMissionResponseDTO>?.self)
guard let missionDailtData = self.missionDailyData else { return completion(nil) }
completion(missionDailtData)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
}

func getWeeklyMissoin(startDate: String, completion: @escaping (NetworkResult<Any>) -> Void) {
homeProvider.request(.missionWeekly(startDate: startDate)) { response in
switch response {
case let .success(response):
let statusCode = response.statusCode
let data = response.data
let networkResult = NetworkBase.judgeStatus(by: statusCode, data,
[WeekMissionResponseDTO].self)
completion(networkResult)
case let .failure(err):
print(err)
func getWeeklyMissoin(startDate: String, completion: @escaping (GeneralArrayResponse<WeekMissionResponseDTO>?) -> Void) {
homeProvider.request(.missionWeekly(startDate: startDate)) { result in
switch result {
case .success(let response):
do {
self.missionWeekly = try response.map(GeneralArrayResponse<WeekMissionResponseDTO>?.self)
guard let missionWeekly = self.missionWeekly else { return completion(nil) }
completion(missionWeekly)
} catch let err {
print(err.localizedDescription, 500)
}
case .failure(let err):
print(err.localizedDescription)
completion(nil)
}
}
}
Expand Down Expand Up @@ -117,7 +124,7 @@ final class HomeAPI {
case .success(let response):
do {
self.updateMissionStatus = try response.map(GeneralResponse<DailyMissionResponseDTO>?.self)
guard self.updateMissionStatus != nil else { return }
guard self.updateMissionStatus != nil else { return completion(nil) }
completion(self.updateMissionStatus)
} catch let err {
print(err.localizedDescription, 500)
Expand All @@ -137,7 +144,7 @@ final class HomeAPI {
case .success(let response):
do {
self.addAnotherDay = try response.map(GeneralResponse<AddAnotherDayResponseDTO>?.self)
guard let addAnotherDay = self.addAnotherDay else { return }
guard let addAnotherDay = self.addAnotherDay else { return completion(nil) }
completion(addAnotherDay)
} catch let err {
print(err.localizedDescription, 500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ enum CompletionStatus: String, Codable, Hashable {
// MARK: - DailyMissionResponseDTO

struct DailyMissionResponseDTO: Codable, Hashable {
var id: Int
var title: String
var situationName: String
var completionStatus: CompletionStatus

var uuid = UUID()
let id: Int
let title: String
let situationName: String
let completionStatus: CompletionStatus

enum CodingKeys: String, CodingKey {
case id, title, situationName, completionStatus
}

static func == (lhs: DailyMissionResponseDTO, rhs: DailyMissionResponseDTO) -> Bool {
lhs.uuid == rhs.uuid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class AchievementViewController: UIViewController {
AmplitudeAnalyticsService.shared.send(event: AnalyticsEvent.Achieve.viewAccomplish)

if let today = monthCalendar.calendar.today {
monthCalendar.yearMonthLabel.text = Utils.dateFormatterString(format: I18N.yearMonthTitle, date: today)
monthCalendar.configureYearMonth(to: Utils.dateFormatterString(format: I18N.yearMonthTitle, date: today))
monthCalendar.calendar.currentPage = today
requestMonthAPI(month: Utils.dateFormatterString(format: "yyyy-MM", date: today))
}
Expand Down Expand Up @@ -136,7 +136,7 @@ extension AchievementViewController {
extension AchievementViewController: FSCalendarDelegate, FSCalendarDataSource, FSCalendarDelegateAppearance {
func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
self.currentPage = calendar.currentPage
monthCalendar.yearMonthLabel.text = Utils.dateFormatterString(format: I18N.yearMonthTitle, date: calendar.currentPage)
monthCalendar.configureYearMonth(to: Utils.dateFormatterString(format: I18N.yearMonthTitle, date: calendar.currentPage))
reloadMonthData(month: Utils.dateFormatterString(format: "yyyy-MM", date: calendar.currentPage))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,14 @@ extension DetailAchievementViewController {
}

extension DetailAchievementViewController {
func requestDetailAPI(date: String) {
HomeAPI.shared.getDailyMission(date: date) { [self] result in
switch result {
case let .success(data):
guard let data = data as? [DailyMissionResponseDTO] else { return }
self.missionList = data
updateData(item: missionList)
case .requestErr:
print("requestErr")
case .pathErr:
print("pathErr")
case .serverErr:
print("serverErr")
case .networkFail:
print("networkFail")
}

private func requestDetailAPI(date: String) {
HomeAPI.shared.getDailyMission(date: date) { [weak self] response in
guard let self else { return }
guard let response = response else { return }
guard let data = response.data else { return }
let missionList = data
self.updateData(item: missionList)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ extension DateCollectionViewCell {

extension DateCollectionViewCell: FSCalendarDelegate, FSCalendarDelegateAppearance {
func calendarCurrentPageDidChange(_ calendar: FSCalendar) {
calendarView.yearMonthLabel.text = Utils.dateFormatterString(format: I18N.yearMonthTitle, date: calendar.currentPage)
calendarView.configureYearMonth(to: Utils.dateFormatterString(format: I18N.yearMonthTitle, date: calendar.currentPage))
}

func calendar(_ calendar: FSCalendar, shouldSelect date: Date, at monthPosition: FSCalendarMonthPosition) -> Bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,27 @@ import FSCalendar
import Then
import SnapKit

protocol CalendarViewDelegate: AnyObject {

func todayBtnTapped()
}

final class CalendarView: UIView {

// MARK: - Properties

let today = Date()
var monthCalendarClosure: ((_ month: String) -> Void)?
weak var delegate: CalendarViewDelegate?

// MARK: - UI Components

let yearMonthLabel = UILabel()
private let yearMonthLabel = UILabel()
let todayButton = UIButton(configuration: .filled())
let horizonStackView = UIStackView()
let leftButton = UIButton()
let rightButton = UIButton()
private let horizonStackView = UIStackView()
private let leftButton = UIButton()
private let rightButton = UIButton()
var calendar = WeekMonthFSCalendar()
private lazy var today: Date = { return Date() }()
var monthCalendarClosure: ((_ month: String) -> Void)?

// MARK: - Life Cycle

Expand All @@ -43,10 +52,12 @@ final class CalendarView: UIView {
extension CalendarView {

private func setCalendar(scope: FSCalendarScope, scrollDirection: FSCalendarScrollDirection) {

calendar = WeekMonthFSCalendar(calendarScope: scope, scrollDirection: scrollDirection)
}

private func setUI() {

backgroundColor = .ntdBlack

yearMonthLabel.do {
Expand All @@ -56,15 +67,23 @@ extension CalendarView {
}

todayButton.do {
$0.configuration?.image = .icBackToday
$0.configuration?.title = I18N.todayButton
$0.configuration?.imagePadding = 2
$0.configuration?.contentInsets = NSDirectionalEdgeInsets.init(top: 3, leading: 6, bottom: 2, trailing: 7)
$0.configuration?.cornerStyle = .capsule
$0.configuration?.attributedTitle?.font = .Pretendard(.regular, size: 14)
$0.configuration?.baseBackgroundColor = .gray2
$0.configuration?.baseForegroundColor = .gray5
var config = UIButton.Configuration.filled()
config.image = .icBackToday
config.title = I18N.todayButton
config.imagePadding = 2
config.cornerStyle = .capsule
config.attributedTitle?.font = .Pretendard(.regular, size: 14)
config.baseBackgroundColor = .gray2
config.baseForegroundColor = .gray5
config.contentInsets = NSDirectionalEdgeInsets.init(top: 3,
leading: 6,
bottom: 2,
trailing: 7)

$0.configuration = config
$0.addTarget(self, action: #selector(todayBtnTapped), for: .touchUpInside)
}

horizonStackView.do {
$0.axis = .horizontal
$0.spacing = 16
Expand All @@ -79,9 +98,15 @@ extension CalendarView {
$0.setImage(.calendarRight, for: .normal)
$0.addTarget(self, action: #selector(nextBtnTapped), for: .touchUpInside)
}

calendar.do {
$0.collectionView.register(MissionCalendarCell.self,
forCellWithReuseIdentifier: MissionCalendarCell.identifier)
}
}

private func setLayout(scope: FSCalendarScope) {

switch scope {
case .week:
addSubviews(calendar, yearMonthLabel, todayButton)
Expand All @@ -102,16 +127,15 @@ extension CalendarView {
$0.directionalHorizontalEdges.equalToSuperview().inset(11)
$0.bottom.equalToSuperview().inset(20)
}

case .month:
addSubviews(horizonStackView, calendar)
horizonStackView.addArrangedSubviews(leftButton, yearMonthLabel, rightButton)

leftButton.snp.makeConstraints {
$0.size.equalTo(CGSize(width: 25, height: 25))
}

rightButton.snp.makeConstraints {
$0.size.equalTo(CGSize(width: 25, height: 25))
[leftButton, rightButton].forEach {
$0.snp.makeConstraints {
$0.size.equalTo(CGSize(width: 25, height: 25))
}
}

horizonStackView.snp.makeConstraints {
Expand All @@ -131,6 +155,7 @@ extension CalendarView {
}

func scrollCurrentPage(calendar: WeekMonthFSCalendar, isPrev: Bool) {

let gregorian = Calendar(identifier: .gregorian)
calendar.setCurrentPage( gregorian.date(byAdding: calendar.scope == .week ? .weekOfMonth : .month, value: isPrev ? -1 : 1, to: calendar.currentPage)!, animated: true)
let monthDateFormatter = DateFormatter()
Expand All @@ -143,7 +168,7 @@ extension CalendarView {
// MARK: - Action

extension CalendarView {

@objc
func prevBtnTapped(_sender: UIButton) {
scrollCurrentPage(calendar: calendar, isPrev: true)
Expand All @@ -155,6 +180,15 @@ extension CalendarView {
}
}

extension CalendarView {

@objc
func todayBtnTapped(_sender: UIButton) {
delegate?.todayBtnTapped()
}

}

extension CalendarView {

func setCalendarSelectedDate(_ dates: [Date]) {
Expand Down Expand Up @@ -184,5 +218,4 @@ extension CalendarView {
$0.bottom.equalToSuperview().inset(45)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import UIKit

final class CompositionalLayout {

class func _vertical(_ itemWidth: NSCollectionLayoutDimension, _ itemHeight: NSCollectionLayoutDimension, _ groupWidth: NSCollectionLayoutDimension, _ groupHeight: NSCollectionLayoutDimension, count: Int, edge: NSDirectionalEdgeInsets?) -> NSCollectionLayoutSection {
class func vertical(itemWidth: NSCollectionLayoutDimension = .fractionalWidth(1),
itemHeight: NSCollectionLayoutDimension = .fractionalWidth(1),
groupWidth: NSCollectionLayoutDimension = .fractionalWidth(1),
groupHeight: NSCollectionLayoutDimension = .fractionalWidth(1),
count: Int,
edge: NSDirectionalEdgeInsets = .zero) -> NSCollectionLayoutSection {
let item = NSCollectionLayoutItem(layoutSize: .init(widthDimension: itemWidth, heightDimension: itemHeight))
let group = NSCollectionLayoutGroup.vertical(layoutSize: .init(widthDimension: groupWidth, heightDimension: groupHeight), subitem: item, count: count )
return section(group, edge ?? NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
let group = NSCollectionLayoutGroup.vertical(layoutSize: .init(widthDimension: groupWidth, heightDimension: groupHeight), subitem: item, count: count)
return createSection(group, edge)
}

class func section(_ group: NSCollectionLayoutGroup, _ edge: NSDirectionalEdgeInsets) -> NSCollectionLayoutSection {
class func createSection(_ group: NSCollectionLayoutGroup, _ edge: NSDirectionalEdgeInsets) -> NSCollectionLayoutSection {
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = edge
return section
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class HomeEmptyCollectionViewCell: UICollectionViewCell {
private let logoImage = UIImageView()
private let emptyLabel = UILabel()

// MARK: - Life Cycle

override init(frame: CGRect) {
super.init(frame: .zero)
setUI()
Expand All @@ -35,6 +37,7 @@ final class HomeEmptyCollectionViewCell: UICollectionViewCell {
// MARK: - Methods

extension HomeEmptyCollectionViewCell {

private func setUI() {
backgroundColor = .clear

Expand Down
Loading