Skip to content

Commit

Permalink
[Fix] Runnect#78 - 코멘트 받은 부분 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Jan 11, 2023
1 parent f640576 commit 6a115e7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Runnect-iOS/Runnect-iOS/Global/Utils/RNUtils/RNTimeFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class ActivityRecordInfoVC: UIViewController {
plugins: [NetworkLoggerPlugin(verbose: true)]
)

private var activityRecordList = [Record]()
private var activityRecordList = [ActivityRecord]()

// MARK: - UI Components

Expand All @@ -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()
}
Expand Down

0 comments on commit 6a115e7

Please sign in to comment.