From ace2a5f2656ed9a793db2b8549ed2e89bf02ad76 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Wed, 11 Jan 2023 13:13:27 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[Feat]=20#78=20-=20=20=ED=99=9C=EB=8F=99=20?= =?UTF-8?q?=EA=B8=B0=EB=A1=9D=20API=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dto/MyPageDto/ActivityRecordInfoDto.swift | 8 ++++ .../ActivityRecordInfoTVC.swift | 42 ++++++++++++++----- 2 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift new file mode 100644 index 00000000..61131596 --- /dev/null +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift @@ -0,0 +1,8 @@ +// +// ActivityRecordInfoDto.swift +// Runnect-iOS +// +// Created by 몽이 누나 on 2023/01/11. +// + +import Foundation diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift index 8d1c979e..f374eb31 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift @@ -87,6 +87,37 @@ final class ActivityRecordInfoTVC: UITableViewCell { } } +// MARK: - Methods + +extension ActivityRecordInfoTVC { + + // MARK: - General Helpers + + func dataBind(model: ActivityRecordInfoModel) { + activityRecordTitleLabel.text = model.title + activityRecordPlaceLabel.text = model.place + activityRecordDateLabel.text = model.date + activityRecordTotalDistanceValueLabel.text = model.distance + activityRecordRunningTimeValueLabel.text = model.runningTime + activityRecordAveragePaceValueLabel.text = model.averagePace + } + + private func setData(model: Record) { + activityRecordTitleLabel.text = model.title + setUpActivityRecordPlaceLabel(model: model, label: activityRecordPlaceLabel) + activityRecordDateLabel.text = model.createdAt + activityRecordTotalDistanceValueLabel.text = model.distance + activityRecordRunningTimeValueLabel.text = model.time + activityRecordAveragePaceValueLabel.text = model.pace + } + + private func setUpActivityRecordPlaceLabel(model: Record, label: UILabel) { + let attributedString = NSMutableAttributedString(string: String(model.departure.region) + " ", attributes: [.font: UIFont.b8, .foregroundColor: UIColor.g2]) + attributedString.append(NSAttributedString(string: String(model.departure.city), attributes: [.font: UIFont.b8, .foregroundColor: UIColor.g2])) + label.attributedText = attributedString + } +} + extension ActivityRecordInfoTVC { // MARK: - Method @@ -178,15 +209,4 @@ extension ActivityRecordInfoTVC { super.layoutSubviews() contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 0, left: 0, bottom: 16, right: 0)) } - - // MARK: - General Helpers - - func dataBind(model: ActivityRecordInfoModel) { - activityRecordTitleLabel.text = model.title - activityRecordPlaceLabel.text = model.place - activityRecordDateLabel.text = model.date - activityRecordTotalDistanceValueLabel.text = model.distance - activityRecordRunningTimeValueLabel.text = model.runningTime - activityRecordAveragePaceValueLabel.text = model.averagePace - } } From ba99dca18602b8e35b238ea8b73b4bd45805b6fe Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Wed, 11 Jan 2023 13:55:25 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[Fix]=20#78=20-=20StackView=20=EA=B0=84?= =?UTF-8?q?=EA=B2=A9=20=EC=9D=BC=EC=A0=95=ED=95=98=EA=B2=8C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runnect-iOS.xcodeproj/project.pbxproj | 4 + .../Dto/MyPageDto/ActivityRecordInfoDto.swift | 25 ++++++ .../Router/MyPageRouter/MyPageRouter.swift | 10 +++ .../ActivityRecordInfoTVC.swift | 71 ++++++++++++----- .../VC/InfoVC/ActivityRecordInfoVC.swift | 77 +++++++++++++++---- .../UploadedCourseInfoCVC.swift | 8 -- 6 files changed, 152 insertions(+), 43 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj index b48334f7..28b8fe3e 100644 --- a/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj +++ b/Runnect-iOS/Runnect-iOS.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ A3BC2F432966A93100198261 /* CourseDetailVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BC2F422966A93100198261 /* CourseDetailVC.swift */; }; A3F67AE2296D33AC001598A2 /* MyPageDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE1296D33AC001598A2 /* MyPageDto.swift */; }; A3F67AE4296D33E0001598A2 /* MyPageRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */; }; + A3F67AEA296E4936001598A2 /* ActivityRecordInfoDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */; }; CE0C23742966D62A00B45063 /* PagedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23732966D62A00B45063 /* PagedView.swift */; }; CE0C23772966D64D00B45063 /* PageCVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23762966D64D00B45063 /* PageCVC.swift */; }; CE0C23792966D6AF00B45063 /* ViewPager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE0C23782966D6AF00B45063 /* ViewPager.swift */; }; @@ -154,6 +155,7 @@ A3BC2F422966A93100198261 /* CourseDetailVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseDetailVC.swift; sourceTree = ""; }; A3F67AE1296D33AC001598A2 /* MyPageDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageDto.swift; sourceTree = ""; }; A3F67AE3296D33E0001598A2 /* MyPageRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageRouter.swift; sourceTree = ""; }; + A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityRecordInfoDto.swift; sourceTree = ""; }; CE0C23732966D62A00B45063 /* PagedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagedView.swift; sourceTree = ""; }; CE0C23762966D64D00B45063 /* PageCVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PageCVC.swift; sourceTree = ""; }; CE0C23782966D6AF00B45063 /* ViewPager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewPager.swift; sourceTree = ""; }; @@ -407,6 +409,7 @@ children = ( CE10063D29680C8100FD31FB /* .gitkeep */, A3F67AE1296D33AC001598A2 /* MyPageDto.swift */, + A3F67AE9296E4936001598A2 /* ActivityRecordInfoDto.swift */, ); path = MyPageDto; sourceTree = ""; @@ -1311,6 +1314,7 @@ CE6655C8295D849F00C64E12 /* StringLiterals.swift in Sources */, DAD5A3E4296D526D00C8166B /* CourseDiscoveryRouter.swift in Sources */, CEEC6B3E2961C53700D00E1E /* CourseDiscoveryVC.swift in Sources */, + A3F67AEA296E4936001598A2 /* ActivityRecordInfoDto.swift in Sources */, CE6655E0295D87D200C64E12 /* UIDevice+.swift in Sources */, CE40BB242968068E0030ABCA /* Config.swift in Sources */, CE17F0382961BF8B00E1DED0 /* FontLiterals.swift in Sources */, diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift index 61131596..73870617 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift @@ -6,3 +6,28 @@ // import Foundation + +// MARK: - ActivityRecordInfoDto + +struct ActivityRecordInfoDto: Codable { + let records: [Record] +} + +// MARK: - Record + +struct Record: Codable { + let id, courseId: Int + let publicCourseId: Int? + let machineId, title: String + let image: String + let createdAt: String + let distance: Double + let time, pace: String + let departure: ActivityRecordDeparture +} + +// MARK: - Departure + +struct ActivityRecordDeparture: Codable { + let region, city: String +} diff --git a/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift index 54728c92..01a65f93 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Router/MyPageRouter/MyPageRouter.swift @@ -12,6 +12,7 @@ import Moya enum MyPageRouter { case getMyPageInfo case getUploadedCourseInfo + case getActivityRecordInfo } extension MyPageRouter: TargetType { @@ -29,6 +30,8 @@ extension MyPageRouter: TargetType { return "/user" case .getUploadedCourseInfo: return "/public-course/user" + case .getActivityRecordInfo: + return "/record/user" } } @@ -38,6 +41,8 @@ extension MyPageRouter: TargetType { return .get case .getUploadedCourseInfo: return .get + case .getActivityRecordInfo: + return .get } } @@ -47,6 +52,8 @@ extension MyPageRouter: TargetType { return .requestPlain case .getUploadedCourseInfo: return .requestPlain + case .getActivityRecordInfo: + return .requestPlain } } @@ -58,6 +65,9 @@ extension MyPageRouter: TargetType { case .getUploadedCourseInfo: return ["Content-Type": "application/json", "machineId": "1"] + case .getActivityRecordInfo: + return ["Content-Type": "application/json", + "machineId": "1"] } } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift index f374eb31..9011f302 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift @@ -6,8 +6,10 @@ // import UIKit + import SnapKit import Then +import Kingfisher final class ActivityRecordInfoTVC: UITableViewCell { @@ -23,7 +25,7 @@ final class ActivityRecordInfoTVC: UITableViewCell { private let firstVerticalDivideLine = UIView() private let secondVerticalDivideLine = UIView() - private let activityRecordMapImage = UIView().then { + private let activityRecordMapImage = UIImageView().then { $0.layer.cornerRadius = 10 } @@ -90,25 +92,34 @@ final class ActivityRecordInfoTVC: UITableViewCell { // MARK: - Methods extension ActivityRecordInfoTVC { - - // MARK: - General Helpers - - func dataBind(model: ActivityRecordInfoModel) { - activityRecordTitleLabel.text = model.title - activityRecordPlaceLabel.text = model.place - activityRecordDateLabel.text = model.date - activityRecordTotalDistanceValueLabel.text = model.distance - activityRecordRunningTimeValueLabel.text = model.runningTime - activityRecordAveragePaceValueLabel.text = model.averagePace - } - - private func setData(model: Record) { + func setData(model: Record) { + guard let imageURL = URL(string: model.image) else { return } + + // 날짜 바꾸기 + let activityRecordDate = model.createdAt.prefix(10) + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + let convertDate = dateFormatter.date(from: String(activityRecordDate)) + guard let convertDate = convertDate else { return } + + let resultDateFormatter = DateFormatter() + resultDateFormatter.dateFormat = "yyyy.MM.dd" + let resultDate = resultDateFormatter.string(from: convertDate) + + // 이동 시간 바꾸기 + let activityRecordRunningTime = model.time.suffix(7) + + // 평균 페이스 바꾸기 + let activityRecordAveragePace = model.pace + let array = activityRecordAveragePace.split(separator: ":").map { String($0) } + activityRecordTitleLabel.text = model.title setUpActivityRecordPlaceLabel(model: model, label: activityRecordPlaceLabel) - activityRecordDateLabel.text = model.createdAt - activityRecordTotalDistanceValueLabel.text = model.distance - activityRecordRunningTimeValueLabel.text = model.time - activityRecordAveragePaceValueLabel.text = model.pace + activityRecordDateLabel.text = resultDate + setUpactivityRecordTotalDistanceValueLabel(model: model, label: activityRecordTotalDistanceValueLabel) + activityRecordRunningTimeValueLabel.text = String(activityRecordRunningTime) + setUpActivityRecordAveragePaceValueLabel(array: array, label: activityRecordAveragePaceValueLabel) + self.activityRecordMapImage.kf.setImage(with: imageURL) } private func setUpActivityRecordPlaceLabel(model: Record, label: UILabel) { @@ -116,6 +127,18 @@ extension ActivityRecordInfoTVC { attributedString.append(NSAttributedString(string: String(model.departure.city), attributes: [.font: UIFont.b8, .foregroundColor: UIColor.g2])) label.attributedText = attributedString } + + private func setUpactivityRecordTotalDistanceValueLabel(model: Record, label: UILabel) { + let attributedString = NSMutableAttributedString(string: String(model.distance) + " ", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1]) + attributedString.append(NSAttributedString(string: "km", attributes: [.font: UIFont.b4, .foregroundColor: UIColor.g1])) + label.attributedText = attributedString + } + + private func setUpActivityRecordAveragePaceValueLabel(array: [String], label: UILabel) { + let attributedString = NSMutableAttributedString(string: String(array[1]) + "’", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1]) + attributedString.append(NSAttributedString(string: String(array[2]) + "”", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1])) + label.attributedText = attributedString + } } extension ActivityRecordInfoTVC { @@ -198,6 +221,18 @@ extension ActivityRecordInfoTVC { make.width.equalTo(1) } + activityRecordTotalDistanceStackView.snp.makeConstraints { make in + make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + } + + activityRecordRunningTimeStackView.snp.makeConstraints { make in + make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + } + + activityRecordAveragePaceStackView.snp.makeConstraints { make in + make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + } + activityRecordSubInfoStackView.snp.makeConstraints { make in make.top.equalTo(horizontalDivideLine.snp.bottom).offset(15) make.width.equalToSuperview() diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift index 85a7547e..b3355429 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift @@ -6,21 +6,20 @@ // import UIKit + import SnapKit import Then +import Moya final class ActivityRecordInfoVC: UIViewController { // MARK: - Properties - var activityRecordList: [ActivityRecordInfoModel] = [ - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.28", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\""), - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.29", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\""), - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.30", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\""), - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.31", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\""), - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.28", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\""), - ActivityRecordInfoModel(title: "석촌 호수 한 바퀴", place: "서울시 강동구", date: "2022.12.28", distance: "4.01 km", runningTime: "0:27:36", averagePace: "6'45\"") - ] + private var activityRecordProvider = MoyaProvider( + plugins: [NetworkLoggerPlugin(verbose: true)] + ) + + private var activityRecordList = [Record]() // MARK: - UI Components @@ -29,8 +28,6 @@ final class ActivityRecordInfoVC: UIViewController { private lazy var activityRecordTableView = UITableView().then { $0.showsVerticalScrollIndicator = false $0.separatorStyle = .none - $0.delegate = self - $0.dataSource = self } // MARK: - View Life Cycle @@ -40,7 +37,27 @@ final class ActivityRecordInfoVC: UIViewController { setNavigationBar() setUI() setLayout() + setDelegate() register() + getActivityRecordInfo() + } +} + +// MARK: - Methods + +extension ActivityRecordInfoVC { + private func setData(activityRecordList: [Record]) { + self.activityRecordList = activityRecordList + activityRecordTableView.reloadData() + } + + private func setDelegate() { + self.activityRecordTableView.delegate = self + self.activityRecordTableView.dataSource = self + } + + private func register() { + self.activityRecordTableView.register(ActivityRecordInfoTVC.self, forCellReuseIdentifier: ActivityRecordInfoTVC.className) } } @@ -71,12 +88,6 @@ extension ActivityRecordInfoVC { make.bottom.equalToSuperview() } } - - // MARK: - General Helpers - - private func register() { - activityRecordTableView.register(ActivityRecordInfoTVC.self, forCellReuseIdentifier: ActivityRecordInfoTVC.className) - } } // MARK: - UITableViewDelegate @@ -97,7 +108,39 @@ extension ActivityRecordInfoVC: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { guard let activityRecordCell = tableView.dequeueReusableCell(withIdentifier: ActivityRecordInfoTVC.className, for: indexPath) as? ActivityRecordInfoTVC else { return UITableViewCell()} activityRecordCell.selectionStyle = .none - activityRecordCell.dataBind(model: activityRecordList[indexPath.item]) + activityRecordCell.setData(model: activityRecordList[indexPath.item]) return activityRecordCell } } + +// MARK: - Network + +extension ActivityRecordInfoVC { + func getActivityRecordInfo() { + LoadingIndicator.showLoading() + activityRecordProvider.request(.getActivityRecordInfo) { [weak self] response in + LoadingIndicator.hideLoading() + guard let self = self else { return } + switch response { + case .success(let result): + let status = result.statusCode + if 200..<300 ~= status { + do { + let responseDto = try result.map(BaseResponse.self) + guard let data = responseDto.data else { return } + self.setData(activityRecordList: data.records) + } catch { + print(error.localizedDescription) + } + } + if 400 >= status { + print("400 error") + self.showNetworkFailureToast() + } + case .failure(let error): + print(error.localizedDescription) + self.showNetworkFailureToast() + } + } + } +} diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift index 8ac48bfd..c239483b 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/UploadedCourseInfoCollectionView/UploadedCourseInfoCVC.swift @@ -84,12 +84,4 @@ extension UploadedCourseInfoCVC { make.leading.equalToSuperview() } } - - // MARK: - General Helpers - - func dataBind(model: UploadedCourseInfoModel) { - uploadedCourseTitleLabel.text = model.title - uploadedCoursePlaceLabel.text = model.place - } - } From d35340d410bb2dbf76f372a53be66a4de467d9c0 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Wed, 11 Jan 2023 14:45:23 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[Fix]=20#78=20-=20StackView=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EC=8B=9C=20=EB=9C=A8=EB=8A=94=20=EC=BD=98=EC=86=94?= =?UTF-8?q?=EC=B0=BD=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 스택뷰 안의 요소들 너비와 이를 감싸는 스택뷰 너비를 이중으로 설정해서 생긴 문제.. 해결.. --- .../ActivityRecordInfoTVC.swift | 23 ++++++++++++------- .../VC/InfoVC/ActivityRecordInfoVC.swift | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift index 9011f302..29132edd 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift @@ -73,7 +73,7 @@ final class ActivityRecordInfoTVC: UITableViewCell { private lazy var activityRecordSubInfoStackView = UIStackView(arrangedSubviews: [activityRecordTotalDistanceStackView, firstVerticalDivideLine, activityRecordRunningTimeStackView, secondVerticalDivideLine, activityRecordAveragePaceStackView]).then { $0.axis = .horizontal - $0.distribution = .fillProportionally + $0.distribution = .fill } // MARK: - Life Cycles @@ -221,21 +221,28 @@ extension ActivityRecordInfoTVC { make.width.equalTo(1) } + setActivityRecordSubInfoStackView() + } + + private func setActivityRecordSubInfoStackView() { + let screenWidth = UIScreen.main.bounds.width + let containerViewWidth = screenWidth - 32 + let stackViewWidth = Int(containerViewWidth - 2) / 3 + activityRecordTotalDistanceStackView.snp.makeConstraints { make in - make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + make.width.equalTo(stackViewWidth) } - + activityRecordRunningTimeStackView.snp.makeConstraints { make in - make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + make.width.equalTo(stackViewWidth) } - + activityRecordAveragePaceStackView.snp.makeConstraints { make in - make.width.equalTo(activityRecordContainerView.snp.width).dividedBy(3) + make.width.equalTo(stackViewWidth) } - + activityRecordSubInfoStackView.snp.makeConstraints { make in make.top.equalTo(horizontalDivideLine.snp.bottom).offset(15) - make.width.equalToSuperview() make.centerX.equalToSuperview() } } diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift index b3355429..b2cd5ab0 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift @@ -133,7 +133,7 @@ extension ActivityRecordInfoVC { print(error.localizedDescription) } } - if 400 >= status { + if status >= 400 { print("400 error") self.showNetworkFailureToast() } From 6a115e7af9ac1e7c23d6f6aa5b6de9bc0c2b9b20 Mon Sep 17 00:00:00 2001 From: dlwogus0128 <79050615+dlwogus0128@users.noreply.github.com> Date: Wed, 11 Jan 2023 15:39:45 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[Fix]=20#78=20-=20=EC=BD=94=EB=A9=98?= =?UTF-8?q?=ED=8A=B8=20=EB=B0=9B=EC=9D=80=20=EB=B6=80=EB=B6=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Utils/RNUtils/RNTimeFormatter.swift | 11 +++++++++ .../Dto/MyPageDto/ActivityRecordInfoDto.swift | 4 ++-- .../ActivityRecordInfoTVC.swift | 23 +++++++++---------- .../VC/InfoVC/ActivityRecordInfoVC.swift | 4 ++-- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift index 30eb9e92..2caa823f 100644 --- a/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift +++ b/Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift @@ -30,4 +30,15 @@ class RNTimeFormatter { return formatter.string(from: date) } + + static func changeDateSplit(date: String) -> String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + let convertDate = dateFormatter.date(from: date) + + let resultDateFormatter = DateFormatter() + resultDateFormatter.dateFormat = "yyyy.MM.dd" + + return resultDateFormatter.string(from: convertDate!) + } } diff --git a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift index 73870617..71b8f553 100644 --- a/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift +++ b/Runnect-iOS/Runnect-iOS/Network/Dto/MyPageDto/ActivityRecordInfoDto.swift @@ -10,12 +10,12 @@ import Foundation // MARK: - ActivityRecordInfoDto struct ActivityRecordInfoDto: Codable { - let records: [Record] + let records: [ActivityRecord] } // MARK: - Record -struct Record: Codable { +struct ActivityRecord: Codable { let id, courseId: Int let publicCourseId: Int? let machineId, title: String diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift index 29132edd..6f5a5ca9 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoTableView/ActivityRecordInfoTVC.swift @@ -92,26 +92,19 @@ final class ActivityRecordInfoTVC: UITableViewCell { // MARK: - Methods extension ActivityRecordInfoTVC { - func setData(model: Record) { + func setData(model: ActivityRecord) { guard let imageURL = URL(string: model.image) else { return } // 날짜 바꾸기 let activityRecordDate = model.createdAt.prefix(10) - let dateFormatter = DateFormatter() - dateFormatter.dateFormat = "yyyy-MM-dd" - let convertDate = dateFormatter.date(from: String(activityRecordDate)) - guard let convertDate = convertDate else { return } - - let resultDateFormatter = DateFormatter() - resultDateFormatter.dateFormat = "yyyy.MM.dd" - let resultDate = resultDateFormatter.string(from: convertDate) + let resultDate = RNTimeFormatter.changeDateSplit(date: String(activityRecordDate)) // 이동 시간 바꾸기 let activityRecordRunningTime = model.time.suffix(7) // 평균 페이스 바꾸기 let activityRecordAveragePace = model.pace - let array = activityRecordAveragePace.split(separator: ":").map { String($0) } + let array = spiltActivityRecordAveragePace(model: model) activityRecordTitleLabel.text = model.title setUpActivityRecordPlaceLabel(model: model, label: activityRecordPlaceLabel) @@ -122,13 +115,13 @@ extension ActivityRecordInfoTVC { self.activityRecordMapImage.kf.setImage(with: imageURL) } - private func setUpActivityRecordPlaceLabel(model: Record, label: UILabel) { + private func setUpActivityRecordPlaceLabel(model: ActivityRecord, label: UILabel) { let attributedString = NSMutableAttributedString(string: String(model.departure.region) + " ", attributes: [.font: UIFont.b8, .foregroundColor: UIColor.g2]) attributedString.append(NSAttributedString(string: String(model.departure.city), attributes: [.font: UIFont.b8, .foregroundColor: UIColor.g2])) label.attributedText = attributedString } - private func setUpactivityRecordTotalDistanceValueLabel(model: Record, label: UILabel) { + private func setUpactivityRecordTotalDistanceValueLabel(model: ActivityRecord, label: UILabel) { let attributedString = NSMutableAttributedString(string: String(model.distance) + " ", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1]) attributedString.append(NSAttributedString(string: "km", attributes: [.font: UIFont.b4, .foregroundColor: UIColor.g1])) label.attributedText = attributedString @@ -139,6 +132,12 @@ extension ActivityRecordInfoTVC { attributedString.append(NSAttributedString(string: String(array[2]) + "”", attributes: [.font: UIFont.h5, .foregroundColor: UIColor.g1])) label.attributedText = attributedString } + + private func spiltActivityRecordAveragePace(model: ActivityRecord) -> [String] { + let activityRecordAveragePace = model.pace + let array = activityRecordAveragePace.split(separator: ":").map { String($0) } + return array + } } extension ActivityRecordInfoTVC { diff --git a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift index b2cd5ab0..b9281a4d 100644 --- a/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift +++ b/Runnect-iOS/Runnect-iOS/Presentation/MyPage/VC/InfoVC/ActivityRecordInfoVC.swift @@ -19,7 +19,7 @@ final class ActivityRecordInfoVC: UIViewController { plugins: [NetworkLoggerPlugin(verbose: true)] ) - private var activityRecordList = [Record]() + private var activityRecordList = [ActivityRecord]() // MARK: - UI Components @@ -46,7 +46,7 @@ final class ActivityRecordInfoVC: UIViewController { // MARK: - Methods extension ActivityRecordInfoVC { - private func setData(activityRecordList: [Record]) { + private func setData(activityRecordList: [ActivityRecord]) { self.activityRecordList = activityRecordList activityRecordTableView.reloadData() }