diff --git a/Shared/Connectivity.swift b/Shared/Connectivity.swift new file mode 100644 index 00000000..6a921d57 --- /dev/null +++ b/Shared/Connectivity.swift @@ -0,0 +1,89 @@ +// +// Connectivity.swift +// Trailblazer Watch App +// +// Created by Peyton McKee on 11/14/22. +// + +import Foundation + +import WatchConnectivity + +final class Connectivity : NSObject, ObservableObject { + @Published var routeName: [String] = [] + static let shared = Connectivity() + + override private init() { + super.init() + #if !os(watchOS) + guard WCSession.isSupported() else { + print("session is not supported on watch os") + return + } + #endif + WCSession.default.delegate = self + print("activated session") + WCSession.default.activate() + } + public func send(routeName : [String]) + { + #if os(watchOS) + guard WCSession.default.isCompanionAppInstalled else { + print("Companion App is not installed") + return } + #else + guard WCSession.default.isWatchAppInstalled else { + print("Watch app is not installed") + return } + #endif + guard WCSession.default.activationState == .activated else { + print("Session is not Active") + return } + let routeInfo: [String: [String]] = [ConnectivityTypes.route.rawValue : routeName] + print("Sent User Info") + WCSession.default.sendMessage(routeInfo, replyHandler: nil) + } + + private func update(from dictionary: [String: Any]) + { + let key = ConnectivityTypes.route.rawValue + guard let name = dictionary[key] as? [String] else { return } + DispatchQueue.main.async { + self.routeName = name + } + } +} + +extension Connectivity: WCSessionDelegate +{ + func session(_ session: WCSession, didReceiveUserInfo userInfo: [String : Any] = [:]) { + print("Received Transfer") + update(from: userInfo) + } + func session(_ session: WCSession, didFinish userInfoTransfer: WCSessionUserInfoTransfer, error: Error?) { + print("Finished Transfer") + } + func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { + print("Received Message") + update(from: message) + } + func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { + guard let error = error else { + print("Activation Status: \(activationState)") + return + } + print("Error: \(error.localizedDescription)") + } + + #if os(iOS) + func sessionDidBecomeInactive(_ session: WCSession) { + + } + + func sessionDidDeactivate(_ session: WCSession) { + WCSession.default.activate() + } + #endif + + +} diff --git a/Trailblazer Watch App/ConnectivityController.swift b/Shared/ConnectivityController.swift similarity index 65% rename from Trailblazer Watch App/ConnectivityController.swift rename to Shared/ConnectivityController.swift index 4a62065e..ee475bff 100644 --- a/Trailblazer Watch App/ConnectivityController.swift +++ b/Shared/ConnectivityController.swift @@ -12,7 +12,7 @@ enum ConnectivityTypes: String { case route = "route" } -struct Route: Identifiable{ +struct Route: Identifiable { var id: Int var annotationName: String var coordinates: [Double] @@ -20,24 +20,17 @@ struct Route: Identifiable{ final class ConnectivityController: NSObject, ObservableObject { static let shared = ConnectivityController() - @Published var route : [Route] = [] private var cancellable: Set = [] override private init() { super.init() - Connectivity.shared.$routeIds - .dropFirst() - .map{ ids in self.route.filter { ids.contains($0.id) } } - .receive(on: DispatchQueue.main) - .assign(to: \.route, on: self) - .store(in: &cancellable) } private func updateCompanion() { - let ids = route.map { $0.id } - Connectivity.shared.send(routeIds: ids) + let names = route.map { $0.annotationName } + Connectivity.shared.send(routeName: names) } public func setRoute(route: [Route]) diff --git a/SundayRiver/Game Test.gpx b/Shared/Game Test.gpx similarity index 100% rename from SundayRiver/Game Test.gpx rename to Shared/Game Test.gpx diff --git a/SundayRiver.xcodeproj/project.pbxproj b/SundayRiver.xcodeproj/project.pbxproj index 7a792cfe..31e43576 100644 --- a/SundayRiver.xcodeproj/project.pbxproj +++ b/SundayRiver.xcodeproj/project.pbxproj @@ -35,6 +35,10 @@ 153B2E3C28ED1EDF00A23163 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153B2E3B28ED1EDF00A23163 /* User.swift */; }; 153B2E3E28EDF26300A23163 /* CustomMKPolyline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153B2E3D28EDF26300A23163 /* CustomMKPolyline.swift */; }; 153DAB9829255CFC001ABAAD /* MapInterpreter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 153DAB9729255CFC001ABAAD /* MapInterpreter.swift */; }; + 153DABAD2936C44A001ABAAD /* Trailblazer Watch App.app in Embed Watch Content */ = {isa = PBXBuildFile; fileRef = 1591DBB6291AE7B800978FD8 /* Trailblazer Watch App.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 153DABB12937CF61001ABAAD /* TrailsDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0F28E22CCC005D0886 /* TrailsDatabase.swift */; }; + 153DABB22937D17E001ABAAD /* Trail.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0D28E224C8005D0886 /* Trail.swift */; }; + 153DABB32937D188001ABAAD /* DijsktrasGraphStructure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15545B0B28E224A2005D0886 /* DijsktrasGraphStructure.swift */; }; 15489A492922AF2F00898FD0 /* Connectivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A482922AF2F00898FD0 /* Connectivity.swift */; }; 15489A4A2922AFAC00898FD0 /* Connectivity.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A482922AF2F00898FD0 /* Connectivity.swift */; }; 15489A4C2922BAD100898FD0 /* ConnectivityController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15489A4B2922BAD100898FD0 /* ConnectivityController.swift */; }; @@ -59,11 +63,36 @@ 15874A0E27D82AFA001B9025 /* Scraper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15874A0D27D82AFA001B9025 /* Scraper.swift */; }; 1591DBB12916D9BE00978FD8 /* CancelTrailReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBB02916D9BE00978FD8 /* CancelTrailReportView.swift */; }; 1591DBB9291AE7B800978FD8 /* TrailblazerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */; }; - 1591DBBB291AE7B800978FD8 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1591DBBA291AE7B800978FD8 /* ContentView.swift */; }; 1591DBBD291AE7B900978FD8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1591DBBC291AE7B900978FD8 /* Assets.xcassets */; }; 1591DBC0291AE7B900978FD8 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1591DBBF291AE7B900978FD8 /* Preview Assets.xcassets */; }; + 15F92C522939A7B000792054 /* HomePageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F92C512939A7B000792054 /* HomePageView.swift */; }; + 15F92C542939A97D00792054 /* DirectionsDisplayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F92C532939A97D00792054 /* DirectionsDisplayView.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + 153DABAE2936C44A001ABAAD /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 158749EC27D82635001B9025 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 1591DBB5291AE7B800978FD8; + remoteInfo = "Trailblazer Watch App"; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 153DABB02936C44A001ABAAD /* Embed Watch Content */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "$(CONTENTS_FOLDER_PATH)/Watch"; + dstSubfolderSpec = 16; + files = ( + 153DABAD2936C44A001ABAAD /* Trailblazer Watch App.app in Embed Watch Content */, + ); + name = "Embed Watch Content"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 150C6EAE29031BD70055AD59 /* SideMenuFramework.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SideMenuFramework.swift; sourceTree = ""; }; 150C6EB029035BE10055AD59 /* HextoColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HextoColor.swift; sourceTree = ""; }; @@ -119,9 +148,10 @@ 1591DBB02916D9BE00978FD8 /* CancelTrailReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CancelTrailReportView.swift; sourceTree = ""; }; 1591DBB6291AE7B800978FD8 /* Trailblazer Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Trailblazer Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailblazerApp.swift; sourceTree = ""; }; - 1591DBBA291AE7B800978FD8 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 1591DBBC291AE7B900978FD8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 1591DBBF291AE7B900978FD8 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; + 15F92C512939A7B000792054 /* HomePageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomePageView.swift; sourceTree = ""; }; + 15F92C532939A97D00792054 /* DirectionsDisplayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectionsDisplayView.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -234,6 +264,23 @@ path = InteractiveMap.Utils; sourceTree = ""; }; + 153DABAB2936B9C8001ABAAD /* Shared */ = { + isa = PBXGroup; + children = ( + 15545B1728E297CA005D0886 /* Game Test.gpx */, + 15489A482922AF2F00898FD0 /* Connectivity.swift */, + 15489A4B2922BAD100898FD0 /* ConnectivityController.swift */, + ); + path = Shared; + sourceTree = ""; + }; + 153DABAC2936C44A001ABAAD /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; 15545B0428E022A5005D0886 /* ViewControllers */ = { isa = PBXGroup; children = ( @@ -251,8 +298,10 @@ isa = PBXGroup; children = ( 158749F627D82635001B9025 /* SundayRiver */, + 153DABAB2936B9C8001ABAAD /* Shared */, 1591DBB7291AE7B800978FD8 /* Trailblazer Watch App */, 158749F527D82635001B9025 /* Products */, + 153DABAC2936C44A001ABAAD /* Frameworks */, ); sourceTree = ""; }; @@ -275,7 +324,6 @@ 15545B0428E022A5005D0886 /* ViewControllers */, 159B0EC628E68DDC00DAFEAA /* TrailDatabaseFiles */, 150D063728FB020B0051F160 /* Utils */, - 15545B1728E297CA005D0886 /* Game Test.gpx */, 15874A0027D82636001B9025 /* Assets.xcassets */, 150D063E290063900051F160 /* Images */, 15874A0227D82636001B9025 /* LaunchScreen.storyboard */, @@ -290,9 +338,8 @@ children = ( 152C69B8291B3A750092E537 /* Trailblazer Watch App.entitlements */, 1591DBB8291AE7B800978FD8 /* TrailblazerApp.swift */, - 1591DBBA291AE7B800978FD8 /* ContentView.swift */, - 15489A482922AF2F00898FD0 /* Connectivity.swift */, - 15489A4B2922BAD100898FD0 /* ConnectivityController.swift */, + 15F92C512939A7B000792054 /* HomePageView.swift */, + 15F92C532939A97D00792054 /* DirectionsDisplayView.swift */, 1591DBBC291AE7B900978FD8 /* Assets.xcassets */, 1591DBBE291AE7B900978FD8 /* Preview Content */, ); @@ -327,10 +374,12 @@ 158749F027D82635001B9025 /* Sources */, 158749F127D82635001B9025 /* Frameworks */, 158749F227D82635001B9025 /* Resources */, + 153DABB02936C44A001ABAAD /* Embed Watch Content */, ); buildRules = ( ); dependencies = ( + 153DABAF2936C44A001ABAAD /* PBXTargetDependency */, ); name = SundayRiver; productName = SundayRiver; @@ -471,15 +520,27 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 1591DBBB291AE7B800978FD8 /* ContentView.swift in Sources */, + 15F92C542939A97D00792054 /* DirectionsDisplayView.swift in Sources */, 1591DBB9291AE7B800978FD8 /* TrailblazerApp.swift in Sources */, 15489A4C2922BAD100898FD0 /* ConnectivityController.swift in Sources */, + 153DABB12937CF61001ABAAD /* TrailsDatabase.swift in Sources */, + 153DABB22937D17E001ABAAD /* Trail.swift in Sources */, + 153DABB32937D188001ABAAD /* DijsktrasGraphStructure.swift in Sources */, + 15F92C522939A7B000792054 /* HomePageView.swift in Sources */, 15489A492922AF2F00898FD0 /* Connectivity.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXSourcesBuildPhase section */ +/* Begin PBXTargetDependency section */ + 153DABAF2936C44A001ABAAD /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 1591DBB5291AE7B800978FD8 /* Trailblazer Watch App */; + targetProxy = 153DABAE2936C44A001ABAAD /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + /* Begin PBXVariantGroup section */ 158749FD27D82635001B9025 /* Main.storyboard */ = { isa = PBXVariantGroup; @@ -701,14 +762,15 @@ ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_CFBundleDisplayName = Trailblazer; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses your location to personalize your experience"; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; - INFOPLIST_KEY_WKCompanionAppBundleIdentifier = ""; + INFOPLIST_KEY_WKCompanionAppBundleIdentifier = .trailblazerIOS; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = .trailblazerWatchOS; + PRODUCT_BUNDLE_IDENTIFIER = .trailblazerIOS.trailblazerWatchOS; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = watchos; @@ -735,14 +797,15 @@ ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_CFBundleDisplayName = Trailblazer; + INFOPLIST_KEY_NSLocationWhenInUseUsageDescription = "This app uses your location to personalize your experience"; INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; - INFOPLIST_KEY_WKCompanionAppBundleIdentifier = ""; + INFOPLIST_KEY_WKCompanionAppBundleIdentifier = .trailblazerIOS; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = .trailblazerWatchOS; + PRODUCT_BUNDLE_IDENTIFIER = .trailblazerIOS.trailblazerWatchOS; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; SDKROOT = watchos; diff --git a/SundayRiver.xcodeproj/project.xcworkspace/xcuserdata/peytonmckee.xcuserdatad/UserInterfaceState.xcuserstate b/SundayRiver.xcodeproj/project.xcworkspace/xcuserdata/peytonmckee.xcuserdatad/UserInterfaceState.xcuserstate index 041bcd02..c1198986 100644 Binary files a/SundayRiver.xcodeproj/project.xcworkspace/xcuserdata/peytonmckee.xcuserdatad/UserInterfaceState.xcuserstate and b/SundayRiver.xcodeproj/project.xcworkspace/xcuserdata/peytonmckee.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/SundayRiver.xcodeproj/xcshareddata/xcschemes/SundayRiver.xcscheme b/SundayRiver.xcodeproj/xcshareddata/xcschemes/SundayRiver.xcscheme index 48a8e8ea..4950998d 100644 --- a/SundayRiver.xcodeproj/xcshareddata/xcschemes/SundayRiver.xcscheme +++ b/SundayRiver.xcodeproj/xcshareddata/xcschemes/SundayRiver.xcscheme @@ -51,7 +51,7 @@ diff --git a/SundayRiver.xcodeproj/xcuserdata/peytonmckee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/SundayRiver.xcodeproj/xcuserdata/peytonmckee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index 412cbb9a..32c66500 100644 --- a/SundayRiver.xcodeproj/xcuserdata/peytonmckee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/SundayRiver.xcodeproj/xcuserdata/peytonmckee.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -62,8 +62,8 @@ filePath = "SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "299" - endingLineNumber = "299" + startingLineNumber = "300" + endingLineNumber = "300" landmarkName = "TrailsDatabase" landmarkType = "3"> @@ -221,8 +221,8 @@ filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "874" - endingLineNumber = "874" + startingLineNumber = "875" + endingLineNumber = "875" landmarkName = "presentTrailReportMenu()" landmarkType = "7"> @@ -237,8 +237,8 @@ filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "875" - endingLineNumber = "875" + startingLineNumber = "876" + endingLineNumber = "876" landmarkName = "presentTrailReportMenu()" landmarkType = "7"> @@ -253,8 +253,8 @@ filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "910" - endingLineNumber = "910" + startingLineNumber = "911" + endingLineNumber = "911" landmarkName = "presentRouteOverviewMenu()" landmarkType = "7"> @@ -269,8 +269,8 @@ filePath = "SundayRiver/ViewControllers/InteractiveMapViewController.swift" startingColumnNumber = "9223372036854775807" endingColumnNumber = "9223372036854775807" - startingLineNumber = "841" - endingLineNumber = "841" + startingLineNumber = "842" + endingLineNumber = "842" landmarkName = "showAllTrails()" landmarkType = "7"> diff --git a/SundayRiver/.DS_Store b/SundayRiver/.DS_Store index cf0ec4d7..be5f85b9 100644 Binary files a/SundayRiver/.DS_Store and b/SundayRiver/.DS_Store differ diff --git a/SundayRiver/AppDelegate.swift b/SundayRiver/AppDelegate.swift index c697ea5e..1e26c464 100644 --- a/SundayRiver/AppDelegate.swift +++ b/SundayRiver/AppDelegate.swift @@ -62,7 +62,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { ) { print("Failed to register: \(error)") } - + private func configureUserNotifications() { UNUserNotificationCenter.current().delegate = self } diff --git a/SundayRiver/TrailDatabaseFiles/Trail.swift b/SundayRiver/TrailDatabaseFiles/Trail.swift index d340d855..307325f5 100644 --- a/SundayRiver/TrailDatabaseFiles/Trail.swift +++ b/SundayRiver/TrailDatabaseFiles/Trail.swift @@ -15,6 +15,7 @@ enum Status{ case scheduled case event } + struct Trail { let name: String let difficulty: Difficulty diff --git a/SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift b/SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift index 879a1b97..f23e7d58 100644 --- a/SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift +++ b/SundayRiver/TrailDatabaseFiles/TrailsDatabase.swift @@ -7,6 +7,7 @@ import Foundation import MapKit +import SwiftUI enum Difficulty { @@ -1550,13 +1551,12 @@ class TrailsDatabase : NSObject { graph.addEdge(direction: .directed, from: endStarW, to: bend3SL, weight: 300) } - - static func createAnnotation(title: String?, latitude: Double, longitude: Double, difficulty: Difficulty) -> ImageAnnotation - { - let point = ImageAnnotation() - point.title = title - point.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude) - point.difficulty = difficulty - return point - } +} +func createAnnotation(title: String?, latitude: Double, longitude: Double, difficulty: Difficulty) -> ImageAnnotation +{ + let point = ImageAnnotation() + point.title = title + point.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude) + point.difficulty = difficulty + return point } diff --git a/SundayRiver/Utils/InteractiveMap.Utils/MapInterpreter.swift b/SundayRiver/Utils/InteractiveMap.Utils/MapInterpreter.swift index 31a012b1..73ee8171 100644 --- a/SundayRiver/Utils/InteractiveMap.Utils/MapInterpreter.swift +++ b/SundayRiver/Utils/InteractiveMap.Utils/MapInterpreter.swift @@ -144,7 +144,7 @@ final class MapInterpreter: NSObject { } collectedIndex += 1 self.map!.mapConnector![index].points = points - print(collectedIndex) + //print(collectedIndex) if collectedIndex == self.map!.mapConnector!.count { completion(.success(true)) @@ -201,7 +201,7 @@ final class MapInterpreter: NSObject { return } - print("test") + //print("test") for trail in trails { var coordinates : [CLLocationCoordinate2D] = [] @@ -240,7 +240,7 @@ final class MapInterpreter: NSObject { let polyline = CustomPolyline(coordinates: coordinates, count: points.count) polyline.title = trail.name polyline.color = color - let initialAnnotation = TrailsDatabase.createAnnotation(title: trail.name, latitude: coordinates[0].latitude, longitude: coordinates[0].longitude, difficulty: difficulty) + let initialAnnotation = createAnnotation(title: trail.name, latitude: coordinates[0].latitude, longitude: coordinates[0].longitude, difficulty: difficulty) polyline.initialAnnotation = initialAnnotation polylines.append(polyline) annotations.append(polyline.initialAnnotation!) @@ -261,7 +261,7 @@ final class MapInterpreter: NSObject { } let polyline = CustomPolyline(coordinates: coordinates, count: points.count) polyline.title = connector.name - let initialAnnotation = TrailsDatabase.createAnnotation(title: connector.name, latitude: coordinates[0].latitude, longitude: coordinates[0].longitude, difficulty: .easy) + let initialAnnotation = createAnnotation(title: connector.name, latitude: coordinates[0].latitude, longitude: coordinates[0].longitude, difficulty: .easy) initialAnnotation.isConnector = true polyline.color = UIColor(red: 0, green: 200, blue: 0, alpha: 1) polyline.initialAnnotation = initialAnnotation @@ -273,20 +273,20 @@ final class MapInterpreter: NSObject { } private func createGraph() { - print("test Graph") + //print("test Graph") let polylines = mapView.overlays.filter({$0 as? CustomPolyline != nil}) as! [CustomPolyline] - print(polylines.count) + //print(polylines.count) for polylineIndex in 0...polylines.count - 1 { let overlay = polylines[polylineIndex] - let initialVertex = Vertex(TrailsDatabase.createAnnotation(title: overlay.title!, latitude: overlay.points()[0].coordinate.latitude, longitude: overlay.points()[0].coordinate.longitude, difficulty: overlay.initialAnnotation!.difficulty!)) + let initialVertex = Vertex(createAnnotation(title: overlay.title!, latitude: overlay.points()[0].coordinate.latitude, longitude: overlay.points()[0].coordinate.longitude, difficulty: overlay.initialAnnotation!.difficulty!)) var prevVertex : Vertex = initialVertex var vertex2 : Vertex graph.addVertex(prevVertex) for index in 1...overlay.pointCount - 1 { - vertex2 = Vertex(TrailsDatabase.createAnnotation(title: overlay.title!, latitude: overlay.points()[index].coordinate.latitude, longitude: overlay.points()[index].coordinate.longitude, difficulty: overlay.initialAnnotation!.difficulty!)) + vertex2 = Vertex(createAnnotation(title: overlay.title!, latitude: overlay.points()[index].coordinate.latitude, longitude: overlay.points()[index].coordinate.longitude, difficulty: overlay.initialAnnotation!.difficulty!)) graph.addVertex(vertex2) var weight : Int switch overlay.initialAnnotation?.difficulty @@ -327,15 +327,15 @@ final class MapInterpreter: NSObject { { if !getIntersectingPoints(vertex: vertex).isEmpty { - print("From: \(vertex.value.title!) with coordinate: \(vertex.value.coordinate)") + //print("From: \(vertex.value.title!) with coordinate: \(vertex.value.coordinate)") for point in getIntersectingPoints(vertex: vertex) { if previousIntersectingEdges.contains(DirectedEdge(source: point, destination: vertex, weight: 1)) || previousIntersectingEdges.contains(DirectedEdge(source: vertex, destination: point, weight: 1)) { - print("test") + //print("test") continue } - print("To: \(point.value.title!) with coordiante: \(vertex.value.coordinate)") + //print("To: \(point.value.title!) with coordiante: \(vertex.value.coordinate)") graph.addEdge(direction: .undirected, from: point, to: vertex, weight: 1) previousIntersectingEdges.append(DirectedEdge(source: vertex, destination: point, weight: 1)) previousIntersectingEdges.append(DirectedEdge(source: point, destination: vertex, weight: 1)) diff --git a/SundayRiver/Utils/InteractiveMap.Utils/Web Analysis.swift b/SundayRiver/Utils/InteractiveMap.Utils/Web Analysis.swift index 45aff98f..723676db 100644 --- a/SundayRiver/Utils/InteractiveMap.Utils/Web Analysis.swift +++ b/SundayRiver/Utils/InteractiveMap.Utils/Web Analysis.swift @@ -17,6 +17,7 @@ import UIKit import UserNotifications import WebKit + struct TrailData{ var lifts: [String] = [] var whiteCapTrails: [String] = [] @@ -48,7 +49,9 @@ final class WebAnalysis: NSObject, WKNavigationDelegate { func makeRequest() { webView.navigationDelegate = self + webView.load(urlRequest) + } func assignStatus(item: [String], items: [[Vertex]]) @@ -88,35 +91,35 @@ final class WebAnalysis: NSObject, WKNavigationDelegate { } func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { - getMountainReport(webView: webView, queryItems: TrailData(lifts: liftNames, whiteCapTrails: whiteCapTrailNames, lockeTrails: lockeTrailNames, barkerTrails: barkerTrailNames, southRidgeTrails: southRidgeNames, spruceTrails: spruceNames, northPeakTrails: northPeakNames, auroraTrails: auroraNames, ozTrails: ozNames, jordantrails: jordanNames), completion: { - value in - switch value{ - case .success(let value): - self.assignStatus(item: value.lifts, items: TrailsDatabase.lifts) - self.assignStatus(item: value.whiteCapTrails, items: TrailsDatabase.whiteCapTrailAnnotations) - self.assignStatus(item: value.lockeTrails, items: TrailsDatabase.lockeTrailAnnotations) - self.assignStatus(item: value.barkerTrails, items: TrailsDatabase.barkerTrailAnnotations) - self.assignStatus(item: value.southRidgeTrails, items: TrailsDatabase.southRidgeTrailAnnotations) - self.assignStatus(item: value.spruceTrails, items: TrailsDatabase.spruceTrailAnnotations) - self.assignStatus(item: value.northPeakTrails, items: TrailsDatabase.northPeakTrailAnnotations) - self.assignStatus(item: value.auroraTrails, items: TrailsDatabase.auroraTrailAnnotations) - self.assignStatus(item: value.ozTrails, items: TrailsDatabase.ozTrailAnnotations) - self.assignStatus(item: value.jordantrails, items: TrailsDatabase.jordanTrailsAnnotations) - for annotation in TrailsDatabase.annotations - { - // print("\(annotation.value.title): \(annotation.value.status)") - if annotation.value.status == .open - { - TrailsDatabase.realTimeGraph.addVertex(annotation) - } - } - //InteractiveMapViewController.selectedGraph = TrailsDatabase.realTimeGraph - //NotificationCenter.default.post(name: Notification.Name(rawValue: "selectGraph"), object: nil) - - case .failure(let error): - print("failed to find data - \(error)") - } - }) +// getMountainReport(webView: webView, queryItems: TrailData(lifts: liftNames, whiteCapTrails: whiteCapTrailNames, lockeTrails: lockeTrailNames, barkerTrails: barkerTrailNames, southRidgeTrails: southRidgeNames, spruceTrails: spruceNames, northPeakTrails: northPeakNames, auroraTrails: auroraNames, ozTrails: ozNames, jordantrails: jordanNames), completion: { +// value in +// switch value{ +// case .success(let value): +// self.assignStatus(item: value.lifts, items: TrailsDatabase.lifts) +// self.assignStatus(item: value.whiteCapTrails, items: TrailsDatabase.whiteCapTrailAnnotations) +// self.assignStatus(item: value.lockeTrails, items: TrailsDatabase.lockeTrailAnnotations) +// self.assignStatus(item: value.barkerTrails, items: TrailsDatabase.barkerTrailAnnotations) +// self.assignStatus(item: value.southRidgeTrails, items: TrailsDatabase.southRidgeTrailAnnotations) +// self.assignStatus(item: value.spruceTrails, items: TrailsDatabase.spruceTrailAnnotations) +// self.assignStatus(item: value.northPeakTrails, items: TrailsDatabase.northPeakTrailAnnotations) +// self.assignStatus(item: value.auroraTrails, items: TrailsDatabase.auroraTrailAnnotations) +// self.assignStatus(item: value.ozTrails, items: TrailsDatabase.ozTrailAnnotations) +// self.assignStatus(item: value.jordantrails, items: TrailsDatabase.jordanTrailsAnnotations) +// for annotation in TrailsDatabase.annotations +// { +// // print("\(annotation.value.title): \(annotation.value.status)") +// if annotation.value.status == .open +// { +// TrailsDatabase.realTimeGraph.addVertex(annotation) +// } +// } +// //InteractiveMapViewController.selectedGraph = TrailsDatabase.realTimeGraph +// //NotificationCenter.default.post(name: Notification.Name(rawValue: "selectGraph"), object: nil) +// +// case .failure(let error): +// print("failed to find data - \(error)") +// } +// }) } } diff --git a/SundayRiver/ViewControllers/InteractiveMapViewController.swift b/SundayRiver/ViewControllers/InteractiveMapViewController.swift index 2f530085..71cc09cf 100644 --- a/SundayRiver/ViewControllers/InteractiveMapViewController.swift +++ b/SundayRiver/ViewControllers/InteractiveMapViewController.swift @@ -502,7 +502,7 @@ class InteractiveMapViewController: UIViewController { let latitude = report.latitude let longitude = report.longitude - let annotation = TrailsDatabase.createAnnotation(title: nil, latitude: latitude, longitude: longitude, difficulty: .easy) + let annotation = createAnnotation(title: nil, latitude: latitude, longitude: longitude, difficulty: .easy) annotation.subtitle = "\(report.type)" annotation.id = report.id let closestTrail = self.getClosestAnnotation(origin: annotation).value @@ -564,7 +564,7 @@ class InteractiveMapViewController: UIViewController guard let latitude = locationManager.locationManager.location?.coordinate.latitude, let longitude = locationManager.locationManager.location?.coordinate.longitude, locationManager.locationManager.authorizationStatus == .authorizedWhenInUse else { return false } - Self.origin = TrailsDatabase.createAnnotation(title: "Your Location", latitude: latitude, longitude: longitude, difficulty: .easy) + Self.origin = createAnnotation(title: "Your Location", latitude: latitude, longitude: longitude, difficulty: .easy) let closestVertex = getClosestAnnotation(origin: Self.origin!) originVertex = Vertex(Self.origin!) if pathCreated.contains(closestVertex) @@ -773,6 +773,7 @@ class InteractiveMapViewController: UIViewController var foundAnnotations : [ImageAnnotation] = [] var routes : [Route] = [] var id = 0 + var foundTrails : [String] = [] for vertex in route{ myPolyLine = CustomPolyline(coordinates: [previousVertex.value.coordinate, vertex.value.coordinate], count: 2) switch previousVertex.value.difficulty @@ -796,11 +797,11 @@ class InteractiveMapViewController: UIViewController { foundAnnotations.append(trailReport) } - if (TrailsDatabase.keyAnnotations.contains(vertex)) + if (!foundTrails.contains(vertex.value.title!)) { - foundAnnotations.append(vertex.value) + foundTrails.append(vertex.value.title!) + routes.append(Route(id: id, annotationName: vertex.value.title!, coordinates: [vertex.value.coordinate.latitude, vertex.value.coordinate.longitude])) } - routes.append(Route(id: id, annotationName: previousVertex.value.title!, coordinates: [previousVertex.value.coordinate.latitude, previousVertex.value.coordinate.longitude])) id += 1 previousVertex = vertex } @@ -947,7 +948,7 @@ class InteractiveMapViewController: UIViewController func createTrailReport(type: TrailReportType) { dismissTrailReportMenu() - let originAnnotation = TrailsDatabase.createAnnotation(title: nil, latitude: self.trailReportAnnotation.coordinate.latitude, longitude: self.trailReportAnnotation.coordinate.longitude, difficulty: .easy) + let originAnnotation = createAnnotation(title: nil, latitude: self.trailReportAnnotation.coordinate.latitude, longitude: self.trailReportAnnotation.coordinate.longitude, difficulty: .easy) let closestTrail = getClosestAnnotation(origin: originAnnotation).value switch type { diff --git a/Trailblazer Watch App/Connectivity.swift b/Trailblazer Watch App/Connectivity.swift deleted file mode 100644 index 78632f16..00000000 --- a/Trailblazer Watch App/Connectivity.swift +++ /dev/null @@ -1,70 +0,0 @@ -// -// Connectivity.swift -// Trailblazer Watch App -// -// Created by Peyton McKee on 11/14/22. -// - -import Foundation - -import WatchConnectivity - -final class Connectivity : NSObject, ObservableObject { - @Published var routeIds: [Int] = [] - static let shared = Connectivity() - - override private init() { - super.init() - #if !os(watchOS) - guard WCSession.isSupported() else { - return - } - #endif - WCSession.default.delegate = self - WCSession.default.activate() - } - public func send(routeIds : [Int]) - { - print("test connectivity \(routeIds)") - #if os(watchOS) - guard WCSession.default.isCompanionAppInstalled else { return } - #else - guard WCSession.default.isWatchAppInstalled else { return } - #endif - guard WCSession.default.activationState == .activated else { return } - let routeInfo: [String: [Int]] = [ConnectivityTypes.route.rawValue : routeIds] - - WCSession.default.transferUserInfo(routeInfo) - } - - private func update(from dictionary: [String: Any]) - { - let key = ConnectivityTypes.route.rawValue - guard let ids = dictionary[key] as? [Int] else { return } - self.routeIds = ids - } -} - -extension Connectivity: WCSessionDelegate -{ - func session(_ sessoin: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) - { - print("test watch: \(userInfo)") - update(from: userInfo) - } - - func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { - } - - #if os(iOS) - func sessionDidBecomeInactive(_ session: WCSession) { - - } - - func sessionDidDeactivate(_ session: WCSession) { - WCSession.default.activate() - } - #endif - - -} diff --git a/Trailblazer Watch App/ContentView.swift b/Trailblazer Watch App/ContentView.swift deleted file mode 100644 index 927c3fb9..00000000 --- a/Trailblazer Watch App/ContentView.swift +++ /dev/null @@ -1,34 +0,0 @@ -// -// ContentView.swift -// Trailblazer Watch App -// -// Created by Peyton McKee on 11/8/22. -// - -import SwiftUI -import MapKit - -struct ContentView: View { - @ObservedObject private var connectivityController = ConnectivityController.shared - - @State private var mapRegion = MKCoordinateRegion( - center: CLLocationCoordinate2D(latitude: 44.46806937533083, longitude: -70.87985973100996), - span: MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.1)) - - var body: some View { - Map(coordinateRegion: $mapRegion, showsUserLocation: true, userTrackingMode: .constant(.follow)) - .frame(width: 200, height: 200) -// List { -// ForEach(connectivityController.route) { -// route in -// Text(verbatim: route.annotationName) -// } -// } - } -} - -struct ContentView_Previews: PreviewProvider { - static var previews: some View { - ContentView() - } -} diff --git a/Trailblazer Watch App/DirectionsDisplayView.swift b/Trailblazer Watch App/DirectionsDisplayView.swift new file mode 100644 index 00000000..e4b50194 --- /dev/null +++ b/Trailblazer Watch App/DirectionsDisplayView.swift @@ -0,0 +1,29 @@ +// +// DirectionsDisplayView.swift +// Trailblazer Watch App +// +// Created by Peyton McKee on 12/1/22. +// + +import Foundation +import SwiftUI + +struct DirectionsDisplayView: View { + //@ObservedObject private var connectivityController = ConnectivityController.shared + @ObservedObject private var connectivity = Connectivity.shared + var body: some View { + List{ + ForEach(connectivity.routeName, id: \.self) { + name in + Text(name) + } + } + } +} + +struct DirectionsDisplayView_Previews: PreviewProvider +{ + static var previews: some View{ + DirectionsDisplayView() + } +} diff --git a/Trailblazer Watch App/HomePageView.swift b/Trailblazer Watch App/HomePageView.swift new file mode 100644 index 00000000..43cb8793 --- /dev/null +++ b/Trailblazer Watch App/HomePageView.swift @@ -0,0 +1,23 @@ +// +// HomePageView.swift +// Trailblazer Watch App +// +// Created by Peyton McKee on 12/1/22. +// + +import Foundation +import SwiftUI +struct HomePageView : View { + var body: some View{ + VStack{ + Text("Welcome To Trailblazer!") + NavigationLink("See Current Route", destination: DirectionsDisplayView()) + } + } +} +struct HomePage_Previews: PreviewProvider +{ + static var previews: some View { + HomePageView() + } +} diff --git a/Trailblazer Watch App/TrailblazerApp.swift b/Trailblazer Watch App/TrailblazerApp.swift index f2c7fdd4..03ddaaf3 100644 --- a/Trailblazer Watch App/TrailblazerApp.swift +++ b/Trailblazer Watch App/TrailblazerApp.swift @@ -11,7 +11,9 @@ import SwiftUI struct Trailblazer_Watch_AppApp: App { var body: some Scene { WindowGroup { - ContentView() + NavigationView{ + HomePageView() + } } } }