Skip to content

Commit

Permalink
Merge pull request #133 from depromeet/feat/#132-workout-flow
Browse files Browse the repository at this point in the history
[Feat/#132] timer 종료시에 watch의 운동 종료
  • Loading branch information
mooyoung2309 authored Jul 11, 2023
2 parents 87491ea + 3c70252 commit 2a09ff3
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public extension ModulePath {

public extension ModulePath {
enum Domain: String, CaseIterable {
case WatchConnectivity
case Crew
case Workout
case Auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class WatchConnectivityDelegate: NSObject, ObservableObject, WCSessionDel
public weak var session: WCSession?

@Published public var pumpingTimerData: PumpingTimerData = .init(timers: [], updatedTime: Date().timeIntervalSince1970)
@Published public var watchConnectivityControl: WatchConnectivityControl = .start

init(session: WCSession = .default) {
self.session = session
Expand Down Expand Up @@ -41,6 +42,13 @@ public class WatchConnectivityDelegate: NSObject, ObservableObject, WCSessionDel
public func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
DispatchQueue.main.async {
debugPrint("watchOS recieved \(message)")
for m in message {
if m.key == "control" {
guard let value = m.value as? Int else { break }

self.watchConnectivityControl = WatchConnectivityControl.toDomain(int: value)
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public class WorkoutDelegate: NSObject, ObservableObject {
let startDate = Date()
workoutSession?.startActivity(with: startDate)
liveWorkoutBuilder?.beginCollection(withStart: startDate) { (success, error) in
//TODO: ViewStore로 Action 처리
debugPrint("live workout builder begin: \(success) \(String(describing: error))")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// WatchConnectivityControl.swift
// AppWatchExtension
//
// Created by 송영모 on 2023/07/11.
//

import Foundation

public enum WatchConnectivityControl: Int {
case start
case end

static public func toDomain(int: Int) -> Self {
switch int {
case 0: return .start
case 1: return .end
default: return .start
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public struct HomeView: View {
.onReceive(watchConnectivityDelegate.$pumpingTimerData) { pumpingTimerData in
viewStore.send(.sinkPumpingTimerData(pumpingTimerData))
}
.onReceive(watchConnectivityDelegate.$watchConnectivityControl) { control in
switch control {
case .start:
workoutDelegate.startWorkout(workoutType: .functionalStrengthTraining)
case .end:
workoutDelegate.endWorkout()
}
}
.ignoresSafeArea()
}
}
Expand Down
1 change: 1 addition & 0 deletions Projects/Domain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ let targets: [Target] = [
.domain(implements: .Auth),
.domain(implements: .Workout),
.domain(implements: .Crew),
.domain(implements: .WatchConnectivity),
.core
]
)
Expand Down
2 changes: 2 additions & 0 deletions Projects/Domain/Sources/DomainExport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
@_exported import DomainWorkoutInterface
@_exported import DomainCrew
@_exported import DomainCrewInterface
@_exported import DomainWatchConnectivity
@_exported import DomainWatchConnectivityInterface
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// WatchConnectivityControl.swift
// DomainWatchConnectivityInterface
//
// Created by 송영모 on 2023/07/11.
//

import Foundation

public enum WatchConnectivityControl: Int {
case start
case end
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
// Created by 송영모 on 2023/06/26.
//

import Foundation
import WatchConnectivity

import ComposableArchitecture

import Domain
import DomainWorkoutInterface

public class WatchConnectivityDelegate: NSObject, ObservableObject ,WCSessionDelegate {
public weak var session: WCSession?

@Published public var heartRate: Double = 0.0
@Published public var calorie: Double = 0.0

init(session: WCSession = .default) {
public init(session: WCSession = .default) {
self.session = session

super.init()
Expand Down
42 changes: 42 additions & 0 deletions Projects/Domain/WatchConnectivity/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import ProjectDescription
import ProjectDescriptionHelpers
import DependencyPlugin

let project = Project.makeModule(
name: ModulePath.Domain.name+ModulePath.Domain.WatchConnectivity.rawValue,
targets: [
.domain(
interface: .WatchConnectivity,
factory: .init(
dependencies: [
.domain(interface: .Workout),
.core
]
)
),
.domain(
implements: .WatchConnectivity,
factory: .init(
dependencies: [
.domain(interface: .WatchConnectivity)
]
)
),
.domain(
testing: .WatchConnectivity,
factory: .init(
dependencies: [
.domain(interface: .WatchConnectivity)
]
)
),
.domain(
tests: .WatchConnectivity,
factory: .init(
dependencies: [
.domain(testing: .WatchConnectivity)
]
)
),
]
)
1 change: 1 addition & 0 deletions Projects/Domain/WatchConnectivity/Sources/Source.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This is for Tuist
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// This is for Tuist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import XCTest

final class WatchConnectivityTests: XCTestCase {
override func setUpWithError() throws {}

override func tearDownWithError() throws {}

func testExample() {
XCTAssertEqual(1, 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import SwiftUI

import ComposableArchitecture

import SharedDesignSystem
import Shared
import Domain

public struct WorkoutRootView: View {
public let store: StoreOf<WorkoutRootStore>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import SwiftUI

import ComposableArchitecture

import SharedDesignSystem
import Domain
import Shared

public struct WorkoutTimerView: View {
public let store: StoreOf<WorkoutTimerStore>
Expand Down Expand Up @@ -37,6 +38,7 @@ public struct WorkoutTimerView: View {

PumpingSubmitButton(title: "종료", completion: {
viewStore.send(.endButtonTapped)
watchConnectivityDelegate.sendMessage(key: "control", value: WatchConnectivityControl.end.rawValue)
})
.padding()
}
Expand Down

0 comments on commit 2a09ff3

Please sign in to comment.