Skip to content

Commit

Permalink
✨[FEAT] 일간 수영 데이터 반 뷰에 집어넣기 구현 완료(#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoonAh-dev committed Feb 18, 2022
1 parent 35f3c6d commit 8634bef
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 22 deletions.
4 changes: 4 additions & 0 deletions Umpah-iOS/Umpah-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
ED348ADE27C00E2F007559E9 /* SignupRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED348ADD27C00E2F007559E9 /* SignupRequest.swift */; };
ED348AE027C00EA7007559E9 /* LoginRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED348ADF27C00EA7007559E9 /* LoginRequest.swift */; };
ED348AE227C00ED4007559E9 /* LoginStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED348AE127C00ED4007559E9 /* LoginStorage.swift */; };
ED501E0827C01613001922FC /* DayRecordModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED501E0727C01613001922FC /* DayRecordModel.swift */; };
ED5396E226B975AD0061722F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ED5396E126B975AD0061722F /* Main.storyboard */; };
ED5396E426B975D70061722F /* MainVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED5396E326B975D70061722F /* MainVC.swift */; };
ED5396E626B975E70061722F /* Routine.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = ED5396E526B975E70061722F /* Routine.storyboard */; };
Expand Down Expand Up @@ -219,6 +220,7 @@
ED348ADD27C00E2F007559E9 /* SignupRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignupRequest.swift; sourceTree = "<group>"; };
ED348ADF27C00EA7007559E9 /* LoginRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginRequest.swift; sourceTree = "<group>"; };
ED348AE127C00ED4007559E9 /* LoginStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginStorage.swift; sourceTree = "<group>"; };
ED501E0727C01613001922FC /* DayRecordModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DayRecordModel.swift; sourceTree = "<group>"; };
ED5396E126B975AD0061722F /* Main.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
ED5396E326B975D70061722F /* MainVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainVC.swift; sourceTree = "<group>"; };
ED5396E526B975E70061722F /* Routine.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Routine.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -618,6 +620,7 @@
3C7F68882715704F00758733 /* RoutineDataModel.swift */,
3CF4E9112719C0F100FE8802 /* SwimmingDataModel.swift */,
ED348AD827BFE7BD007559E9 /* DayRecordRequest.swift */,
ED501E0727C01613001922FC /* DayRecordModel.swift */,
);
path = Record;
sourceTree = "<group>";
Expand Down Expand Up @@ -1188,6 +1191,7 @@
ED017D9827B3A084009AFCAD /* MainCardVC.swift in Sources */,
3CAD1F2626CBDA64001CD535 /* UIWindow+.swift in Sources */,
EDFC6EE72702387500B718C6 /* RangeButton.swift in Sources */,
ED501E0827C01613001922FC /* DayRecordModel.swift in Sources */,
EDEF3B63271EF70000C852E7 /* CardView.swift in Sources */,
ED78843026DC9D3C006D8787 /* HeaderView.swift in Sources */,
);
Expand Down
49 changes: 49 additions & 0 deletions Umpah-iOS/Umpah-iOS/Network/Model/Record/DayRecordModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// DayRecordModel.swift
// Umpah-iOS
//
// Created by SHIN YOON AH on 2022/02/19.
//

import Foundation

// MARK: - DayRecordModel
struct DayRecordModel: Codable {
let success: Bool
let message: String
let data: DayRecord
}

// MARK: - DataClass
struct DayRecord: Codable {
let date: String
let totalDistance, totalTime, totalCalorie, totalBPM: Int
let freestyleTotalDistance: Int
let freestyleTotalSpeed: String
let breastTotalDistance: Int
let breastTotalSpeed: String
let backTotalDistance: Int
let backTotalSpeed: String
let butterflyTotalDistance: Int
let butterflyTotalSpeed, imTotalSpeed: String
let recordLabsList: [RecordLabsList]

enum CodingKeys: String, CodingKey {
case date, totalDistance, totalTime, totalCalorie
case totalBPM = "totalBpm"
case freestyleTotalDistance, freestyleTotalSpeed, breastTotalDistance, breastTotalSpeed, backTotalDistance, backTotalSpeed, butterflyTotalDistance, butterflyTotalSpeed, imTotalSpeed, recordLabsList
}
}

// MARK: - RecordLabsList
struct RecordLabsList: Codable {
let recordID: Int
var stroke: String
var distance, time: Int
var speed: String

enum CodingKeys: String, CodingKey {
case recordID = "recordId"
case stroke, distance, time, speed
}
}
5 changes: 4 additions & 1 deletion Umpah-iOS/Umpah-iOS/Network/Storage/RecordStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ final class RecordStorage {
private let authPlugin = AccessTokenPlugin { _ in GeneralAPI.token }
private lazy var authProvider = MoyaProvider<RecordService>(plugins: [authPlugin, NetworkLoggerPlugin(verbose: true)])

public private(set) var dayRecordLabsLists: [RecordLabsList] = []

// MARK: - POST /record
func dispatchRecord(workoutList: [SwimmingWorkoutData],
completion: @escaping (() -> ())) {
Expand Down Expand Up @@ -54,7 +56,8 @@ final class RecordStorage {
switch response {
case .success(let result):
do{
print(result)
let dayRecordModel = try result.map(DayRecordModel.self)
self.dayRecordLabsLists = dayRecordModel.data.recordLabsList
completion()
} catch(let err){
print(err.localizedDescription)
Expand Down
14 changes: 7 additions & 7 deletions Umpah-iOS/Umpah-iOS/Screen/Main/Cell/Sheet/ExpandedDayTVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,16 @@ final class ExpandedDayTVC: UITableViewCell {
$0.addTarget(self, action: #selector(touchUpChangeStroke), for: .touchUpInside)
}
private let distanceLabel = UILabel().then {
$0.text = "999m"
$0.font = .IBMPlexSansText(ofSize: 14)
$0.textColor = .upuhBlack
$0.addCharacterSpacing(kernValue: -1)
}
private let velocityLabel = UILabel().then {
$0.text = "1.7m/s"
$0.font = .IBMPlexSansText(ofSize: 14)
$0.textColor = .upuhBlack
$0.addCharacterSpacing(kernValue: -1)
}
private let timeLabel = UILabel().then {
$0.text = "99:99"
$0.font = .IBMPlexSansText(ofSize: 14)
$0.textColor = .upuhBlack
$0.addCharacterSpacing(kernValue: -1)
Expand Down Expand Up @@ -99,11 +96,14 @@ final class ExpandedDayTVC: UITableViewCell {
}
}

func setupLabels(with data: [String], index: Int) {
func setupLabels(with data: RecordLabsList, index: Int) {
let isSingleDigitNumber = (index < 10)

strokeLabel.text = data[index]
strokeLabel.text = data.stroke
rowLabel.text = isSingleDigitNumber ? "0\(index + 1)" : "\(index + 1)"
distanceLabel.text = "\(data.distance)"
velocityLabel.text = data.speed
timeLabel.text = "\(data.time)"

if #available(iOS 15, *) {
let attributeContainer = AttributeContainer([.foregroundColor: UIColor.upuhBlack,
Expand All @@ -113,13 +113,13 @@ final class ExpandedDayTVC: UITableViewCell {
configuration.titlePadding = 0
configuration.imagePadding = 2
configuration.baseForegroundColor = .upuhBlack
configuration.attributedTitle = AttributedString(data[index], attributes: attributeContainer)
configuration.attributedTitle = AttributedString(data.stroke, attributes: attributeContainer)
configuration.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)
strokeButton.configuration = configuration
} else {
strokeButton.setImage(UIImage(named: "ic_drop"), for: .normal)
strokeButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 0, right: 0)
strokeButton.setTitle(data[index], for: .normal)
strokeButton.setTitle(data.stroke, for: .normal)
strokeButton.titleLabel?.font = .IBMPlexSansText(ofSize: 14)
strokeButton.setTitleColor(.upuhBlack, for: .normal)
strokeButton.sizeToFit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class ExpandedStateTableView: BaseView {
$0.sectionHeaderTopPadding = 0
}
}
private var dummyStrokes: [String] = ["자유형", "접영", "자유형", "자유형", "자유형", "자유형", "배영", "배영", "평영", "평영", "접영", "자유형", "접영"]
// private var dummyStrokes: [String] = ["자유형", "접영", "자유형", "자유형", "자유형", "자유형", "배영", "배영", "평영", "평영", "접영", "자유형", "접영"]
private let dummyDays: [String] = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
private let dummyWeeks: [String] = ["WEEK1", "WEEK2", "WEEK3", "WEEK4", "WEEK5"]
var dayRecordLists: [RecordLabsList] = []
var upuhRoutineOverViewList: [RoutineOverviewData] = []
var filteredOverViewList: [RoutineOverviewData] = []
var rootVC: MainCardVC?
Expand All @@ -40,7 +41,7 @@ extension ExpandedStateTableView: UITableViewDataSource {
switch currentMainViewState {
case .day,
.base:
return dummyStrokes.count
return dayRecordLists.count
case .week:
return 7
case .month:
Expand All @@ -56,9 +57,9 @@ extension ExpandedStateTableView: UITableViewDataSource {
.base:
guard let cell = tableView.dequeueReusableCell(withIdentifier: ExpandedDayTVC.identifier) as? ExpandedDayTVC else { return UITableViewCell() }
cell.delegate = self
cell.setupLabels(with: dummyStrokes, index: indexPath.row)
if indexPath.row < dummyStrokes.count - 1 {
cell.changeCellConfiguration(isModified, dummyStrokes[indexPath.row] == dummyStrokes[indexPath.row + 1])
cell.setupLabels(with: dayRecordLists[indexPath.row], index: indexPath.row)
if indexPath.row < dayRecordLists.count - 1 {
cell.changeCellConfiguration(isModified, dayRecordLists[indexPath.row].stroke == dayRecordLists[indexPath.row + 1].stroke)
} else {
cell.changeCellConfiguration(isModified, false)
}
Expand Down Expand Up @@ -158,13 +159,13 @@ extension ExpandedStateTableView: SelectedButtonDelegate {
vc.sendStrokeStateData = { [weak self] style in
switch style {
case .freestyle:
self?.dummyStrokes[indexPath] = "자유형"
self?.dayRecordLists[indexPath].stroke = "FREESTYLE"
case .butterfly:
self?.dummyStrokes[indexPath] = "접영"
self?.dayRecordLists[indexPath].stroke = "BUTTERFLY"
case .backstroke:
self?.dummyStrokes[indexPath] = "배영"
self?.dayRecordLists[indexPath].stroke = "BACK"
case .breaststroke:
self?.dummyStrokes[indexPath] = "평영"
self?.dayRecordLists[indexPath].stroke = "BREAST"
default:
break
}
Expand All @@ -174,7 +175,7 @@ extension ExpandedStateTableView: SelectedButtonDelegate {
}

func didClickedMergeButton(with indexPath: Int) {
dummyStrokes.remove(at: indexPath)
dayRecordLists.remove(at: indexPath)
listTableView.reloadSections(IndexSet(0...0), with: .fade)
}
}
9 changes: 5 additions & 4 deletions Umpah-iOS/Umpah-iOS/Screen/Main/Controller/MainVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ final class MainVC: MainTableVC {
super.viewDidLoad()
authorizeHealthKit()
// TODO: Dummy Record
// storage.fetchDayRecord(date: "2021-05-19") { [weak self] in
// self?.baseTableView.reloadData()
// print("reload 성공")
// }
storage.fetchDayRecord(date: "2021-05-19") { [weak self] in
self?.cardView.expandedView.dayRecordLists = self?.storage.dayRecordLabsLists ?? []
self?.baseTableView.reloadData()
dump(self?.storage.dayRecordLabsLists)
}
}

override func viewDidAppear(_ animated: Bool) {
Expand Down

0 comments on commit 8634bef

Please sign in to comment.