Skip to content

Commit

Permalink
fix: 코스데이터 등록시 버튼 비활성화 (#114)
Browse files Browse the repository at this point in the history
- 코스등록시 네트워크 연결상태에 따라서 등록버튼 눌림 방지
- 거리계산 단위 통합 진행중
  • Loading branch information
Seokki-Kwon committed Mar 13, 2024
1 parent c5b1ddc commit aadaca3
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 572 deletions.
674 changes: 193 additions & 481 deletions TrackUs/TrackUs.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"originHash" : "b74a2d334a5f1cf29ee032628c226f56c6acaeba386464cbdc283cbbd623d936",
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "bfc0b6f81adc06ce5121eb23f628473638d67c5c",
"version" : "1.2022062300.0"
"revision" : "df308b8b46607675f2b9ec8e569109008f9155ce",
"version" : "1.2022062300.1"
}
},
{
Expand All @@ -23,35 +24,35 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/openid/AppAuth-iOS.git",
"state" : {
"revision" : "71cde449f13d453227e687458144bde372d30fc7",
"version" : "1.6.2"
"revision" : "059f77eb1ccf015a6f5b88cb450376dc0707e1b6",
"version" : "1.7.1"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "b880ec8ec927a838c51c12862c6222c30d7097d7",
"version" : "10.20.0"
"revision" : "be49849dcba96f2b5ee550d4eceb2c0fa27dade4",
"version" : "10.22.1"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "ceec9f28dea12b7cf3dabf18b5ed7621c88fd4aa",
"version" : "10.20.0"
"revision" : "482cfa4e5880f0a29f66ecfd60c5a62af28bd1f0",
"version" : "10.22.1"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "a732a4b47f59e4f725a2ea10f0c77e93a7131117",
"version" : "9.3.0"
"revision" : "a637d318ae7ae246b02d7305121275bc75ed5565",
"version" : "9.4.0"
}
},
{
Expand All @@ -68,17 +69,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "bc27fad73504f3d4af235de451f02ee22586ebd3",
"version" : "7.12.1"
"revision" : "26c898aed8bed13b8a63057ee26500abbbcb8d55",
"version" : "7.13.1"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "a673bc2937fbe886dd1f99c401b01b6d977a9c98",
"version" : "1.49.1"
"revision" : "ea4cb5cc0c39c732b85386263116d2e2fdbbdc61",
"version" : "1.49.2"
}
},
{
Expand Down Expand Up @@ -111,7 +112,7 @@
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"location" : "https://github.com/onevcat/Kingfisher",
"state" : {
"revision" : "5b92f029fab2cce44386d28588098b5be0824ef5",
"version" : "7.11.0"
Expand All @@ -122,53 +123,62 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "9d108e9112aa1d65ce508facf804674546116d9c",
"version" : "1.22.3"
"revision" : "43aaef65e0c665daadf848761d560e446d350d3d",
"version" : "1.22.4"
}
},
{
"identity" : "mapbox-common-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mapbox/mapbox-common-ios.git",
"state" : {
"revision" : "6ed3e33b51d3e3162843885f6914d7fb175609c6",
"version" : "24.1.0"
"revision" : "72474daaeabb644edd449492f9e668f716da72e6",
"version" : "24.2.0"
}
},
{
"identity" : "mapbox-core-maps-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mapbox/mapbox-core-maps-ios.git",
"state" : {
"revision" : "d0958ada64a617991cd90560ec5a6f221a734f84",
"version" : "11.2.0"
}
},
{
"identity" : "mapbox-maps-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mapbox/mapbox-maps-ios/",
"location" : "https://github.com/mapbox/mapbox-maps-ios",
"state" : {
"branch" : "main",
"revision" : "d83e2e3603c69b2a933899b29b6b93779514d68d"
"revision" : "4c05abe8fd4c8c3f7a51932ac05b0b5547839a63"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "819d0a2173aff699fb8c364b6fb906f7cdb1a692",
"version" : "2.30909.0"
"revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
"version" : "2.30910.0"
}
},
{
"identity" : "popupview",
"kind" : "remoteSourceControl",
"location" : "https://github.com/exyte/PopupView",
"state" : {
"revision" : "d34361fa70d57af2fffde2f1e8863de1f25bd0a3",
"version" : "2.8.4"
"revision" : "f71f08f1675d8edacdd341282da539ebbf8c1339",
"version" : "2.9.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "e70e889c0196c76d22759eb50d6a0270ca9f1d9e",
"version" : "2.3.1"
"revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
"version" : "2.4.0"
}
},
{
Expand All @@ -180,15 +190,24 @@
"version" : "1.25.2"
}
},
{
"identity" : "swiftui-introspect",
"kind" : "remoteSourceControl",
"location" : "https://github.com/siteline/swiftui-introspect",
"state" : {
"revision" : "0cd2a5a5895306bc21d54a2254302d24a9a571e4",
"version" : "1.1.3"
}
},
{
"identity" : "turf-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mapbox/turf-swift.git",
"state" : {
"revision" : "f0afe204b4266337066a436becab62fdd2b32378",
"version" : "2.7.0"
"revision" : "213050191cfcb3d5aa76e1fa90c6ff1e182a42ca",
"version" : "2.8.0"
}
}
],
"version" : 2
"version" : 3
}
6 changes: 3 additions & 3 deletions TrackUs/TrackUs/Sources/Commons/Extensions/Double+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Double {
return self * .pi / 180.0
}

// 정수를 00:00 형식으로 포매팅
/// 시간(sec) -> MM:00
func asString(style: DateComponentsFormatter.UnitsStyle) -> String {
let formatter = DateComponentsFormatter()
formatter.allowedUnits = [.minute, .second]
Expand All @@ -27,7 +27,7 @@ extension Double {
return formatter.string(from: self) ?? ""
}

// 러닝페이스 형식으로 포매팅
/// 거리(m) -> 거리(km)
func asString(unit: FormattedStyle) -> String {
switch unit {
case .pace:
Expand All @@ -39,7 +39,7 @@ extension Double {

return "\(paceInMinutes)'\(paceInSecondsFirst)\(paceInSecondsThird)''"
case .kilometer:
return String(format: "%.2f km", self)
return String(format: "%.2f km", self / 1000.0)
case .calorie:
return String(format: "%.1f kcal", self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,39 @@ struct CourseDrawingMapView: UIViewControllerRepresentable {
private var pointAnnotationManager: PointAnnotationManager!

// UI
lazy var buttonStack: UIStackView = {
private lazy var buttonStack: UIStackView = {
let stack = UIStackView()
stack.translatesAutoresizingMaskIntoConstraints = false
stack.axis = .vertical
stack.spacing = 12
return stack
}()

lazy var completeButton: UIButton = {
private lazy var completeButton: UIButton = {
let button = UIButton()
button.setTitle("코스 완성", for: .normal)
button.titleLabel?.font = UIFont.boldSystemFont(ofSize: 16)
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = .main
button.setTitleColor(.white, for: .normal)
button.layer.cornerRadius = 28

button.addTarget(self, action: #selector(completeButtonTapped), for: .touchUpInside)
return button
}()

lazy var deleteButton: UIButton = {
private lazy var deleteButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(UIImage(named: "trash"), for: .normal)
button.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside)
return button
}()

lazy var revertButton: UIButton = {
private lazy var revertButton: UIButton = {
let button = UIButton()
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(UIImage(named: "revert"), for: .normal)
button.addTarget(self, action: #selector(revertButtonTapped), for: .touchUpInside)
return button
}()

Expand Down Expand Up @@ -110,10 +112,6 @@ struct CourseDrawingMapView: UIViewControllerRepresentable {
}

private func setupUI() {
completeButton.addTarget(self, action: #selector(completeButtonTapped), for: .touchUpInside)
deleteButton.addTarget(self, action: #selector(deleteButtonTapped), for: .touchUpInside)
revertButton.addTarget(self, action: #selector(revertButtonTapped), for: .touchUpInside)

// add view
[deleteButton, revertButton].forEach { buttonStack.addArrangedSubview($0) }

Expand All @@ -133,7 +131,7 @@ struct CourseDrawingMapView: UIViewControllerRepresentable {
}

// 데이터 바인딩
func bind() {
private func bind() {
// 좌표탭 핸들러
self.mapView.gestures.onMapTap.observe { context in
self.courseRegViewModel.addPath(with: context.coordinate)
Expand All @@ -157,14 +155,6 @@ struct CourseDrawingMapView: UIViewControllerRepresentable {
self.lineAnnotation.lineJoin = .round
self.lineAnnotationManager.annotations = [self.lineAnnotation]

let totalDistanceInKilometers = coordinate.caculateTotalDistance() / 1000.0
let totalEstimatedTimeInMinutes = ExerciseManager.calculateEstimatedTime(distance: totalDistanceInKilometers) * 60

// 예상 소모 칼로리 업데이트
self.courseRegViewModel.estimatedCalorie = ExerciseManager.calculatedCaloriesBurned(distance: totalDistanceInKilometers)

// 예상 소요시간 업데이트
self.courseRegViewModel.estimatedTime = totalEstimatedTimeInMinutes

}.store(in: &cancellation)
}
Expand Down
28 changes: 14 additions & 14 deletions TrackUs/TrackUs/Sources/Commons/Model/Course.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import MapboxMaps

struct Course: Decodable, Hashable {
@DocumentID var id: String?
let uid: String
let ownerUid: String
let title: String
let content: String
let courseRoutes: [GeoPoint]
let distance: Double
let estimatedTime: Int
let participants: Int
let runningStyle: String
let startDate: Date
var members: [String]
let routeImageUrl: String
let address: String
let estimatedCalorie: Double
var uid: String = UUID().uuidString
var ownerUid: String = ""
var title: String = ""
var content: String = ""
var courseRoutes: [GeoPoint] = []
var distance: Double = 0.0
var estimatedTime: Double = 0.0
var participants: Int = 0
var runningStyle: String = ""
var startDate: Date = Date()
var members: [String] = []
var routeImageUrl: String = ""
var address: String = ""
var estimatedCalorie: Double = 0.0

var coordinates: [CLLocationCoordinate2D] {
self.courseRoutes.map {CLLocationCoordinate2D(latitude: $0.latitude, longitude: $0.longitude)}
Expand Down
12 changes: 8 additions & 4 deletions TrackUs/TrackUs/Sources/Running/View/CourseRegisterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ extension CourseRegisterView {
.font(.caption)
}
}
RunningStatsView(estimatedTime: Double(courseRegViewModel.estimatedTime), calories: courseRegViewModel.estimatedCalorie, distance: courseRegViewModel.coorinates.caculateTotalDistance() / 1000.0)
RunningStatsView(estimatedTime: Double(courseRegViewModel.estimatedTime), calories: courseRegViewModel.estimatedCalorie, distance: courseRegViewModel.coorinates.caculateTotalDistance())
}

VStack(alignment: .leading, spacing: 12) {
Expand Down Expand Up @@ -109,7 +109,8 @@ extension CourseRegisterView {
.frame(maxWidth: .infinity, alignment: .leading)
}

MainButton(active: isTextFieldValid ,buttonText: "코스 등록하기") {
MainButton(active: isTextFieldValid && !courseRegViewModel.isLoading ,buttonText: "코스 등록하기") {
print(courseRegViewModel.isLoading)
courseRegViewModel.uploadCourseData { uploadedData in
guard let uploadedData = uploadedData else { return }
router.popScreens(count: 2)
Expand All @@ -135,7 +136,7 @@ extension CourseRegisterView {
let hoursInSeconds = courseRegViewModel.hours * 3600
let minutesInSeconds = courseRegViewModel.minutes * 60
let seconds = courseRegViewModel.seconds
courseRegViewModel.estimatedTime = hoursInSeconds + minutesInSeconds + seconds
courseRegViewModel.estimatedTime = Double(hoursInSeconds) + Double(minutesInSeconds) + Double(seconds)
}
})
.customNavigation {
Expand Down Expand Up @@ -166,7 +167,7 @@ extension CourseRegisterView {
.background(isSelected ? .main : .white)
.foregroundColor(isSelected ? .white : .gray2)
.clipShape(Capsule())

.overlay(
Capsule()
.stroke(.gray3, lineWidth: isSelected ? 0 : 1)
Expand All @@ -177,6 +178,9 @@ extension CourseRegisterView {

}
}
.onChange(of: courseRegViewModel.style) { _ in

}
}

var datePreview: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct RunningResultView: View {
}

// 예상시간
var estimatedTime: Int {
var estimatedTime: Double {
return ExerciseManager.calculateEstimatedTime(distance: targetDistance * 60)
}

Expand Down
Loading

0 comments on commit aadaca3

Please sign in to comment.