Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnuravi committed Apr 3, 2024
1 parent d0275d1 commit 8292004
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 84 deletions.
64 changes: 7 additions & 57 deletions StrokeCog/Location/LocationModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Spezi

public class LocationModule: NSObject, CLLocationManagerDelegate, Module, DefaultInitializable, EnvironmentAccessible {
private(set) var manager = CLLocationManager()

public var allLocations = [CLLocationCoordinate2D]()
public var onLocationsUpdated: (([CLLocationCoordinate2D]) -> Void)?

Expand All @@ -30,12 +29,10 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
}
}

required public override init() {
override public required init() {
super.init()
manager.delegate = self

calculateIfCanShowRequestMessage()

// If user doesn't have a tracking preference, default to true
if UserDefaults.standard.value(forKey: Constants.prefTrackingStatus) == nil {
UserDefaults.standard.set(true, forKey: Constants.prefTrackingStatus)
Expand All @@ -45,6 +42,9 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
if UserDefaults.standard.bool(forKey: Constants.prefTrackingStatus) {
self.startTracking()
}

// Disable Mapbox telemetry
UserDefaults.standard.set(false, forKey: "MGLMapboxMetricsEnabled")
}

public func startTracking() {
Expand All @@ -66,30 +66,6 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
print("[LIFESPACE] Stopping tracking...")
}

public func calculateIfCanShowRequestMessage() {
let previousState = authorizationStatus
authorizationStatus = self.manager.authorizationStatus

let first = UserDefaults.standard.bool(forKey: Constants.JHFirstLocationRequest)

if authorizationStatus == .authorizedWhenInUse && !first && previousState != authorizationStatus {
UserDefaults.standard.set(true, forKey: Constants.JHFirstLocationRequest)
} else {
UserDefaults.standard.set(false, forKey: Constants.JHFirstLocationRequest)
}

if authorizationStatus == .authorizedAlways {
// LaunchModel.sharedinstance.showPermissionView = false
}

if self.manager.authorizationStatus == .notDetermined ||
(self.manager.authorizationStatus == .authorizedWhenInUse && UserDefaults.standard.bool(forKey: Constants.JHFirstLocationRequest)) {
canShowRequestMessage = true
} else {
canShowRequestMessage = false
}
}

public func requestAuthorizationLocation() {
self.manager.requestWhenInUseAuthorization()
self.manager.requestAlwaysAuthorization()
Expand All @@ -98,12 +74,7 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
/// Get all the points for a particular date from the database
/// - Parameter date: the date for which to fetch all points
func fetchPoints(date: Date = Date()) {
// JHMapDataManager.shared.getAllMapPoints(date: date, onCompletion: {(results) in
// if let results = results as? [CLLocationCoordinate2D] {
// self.allLocations = results
// self.onLocationsUpdated?(self.allLocations)
// }
// })
// TODO: Fetch from Firestore

Check failure on line 77 in StrokeCog/Location/LocationModule.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (Fetch from Firestore) (todo)
}

/// Adds a new point to the map and saves the location to the database,
Expand Down Expand Up @@ -134,28 +105,7 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
previousLocation = point
previousDate = Date()

// // write this location to the database
// if let mapPointsCollection = CKStudyUser.shared.mapPointsCollection,
// let user = CKStudyUser.shared.currentUser,
// let studyID = CKStudyUser.shared.studyID {
// let db = Firestore.firestore()
// db.collection(mapPointsCollection)
// .document(UUID().uuidString)
// .setData([
// "currentdate": NSDate(),
// "time": NSDate().timeIntervalSince1970,
// "latitude": point.latitude,
// "longitude": point.longitude,
// "studyID": studyID,
// "UpdatedBy": user.uid
// ]) { err in
// if let err = err {
// print("[LIFESPACE] Error writing location to database: \(err)")
// }
// }
// } else {
// print("[LIFESPACE] Unable to save point due to missing metadata.")
// }
// TODO: Save to Firestore

Check failure on line 108 in StrokeCog/Location/LocationModule.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (Save to Firestore) (todo)
}
}

Expand All @@ -173,6 +123,6 @@ public class LocationModule: NSObject, CLLocationManagerDelegate, Module, Defaul
}

public func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
self.calculateIfCanShowRequestMessage()
// TODO: Handle authorization change

Check failure on line 126 in StrokeCog/Location/LocationModule.swift

View workflow job for this annotation

GitHub Actions / SwiftLint / SwiftLint

Todo Violation: TODOs should be resolved (Handle authorization change) (todo)
}
}
9 changes: 5 additions & 4 deletions StrokeCog/Map/MapboxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import Spezi
import SwiftUI

struct MapManagerViewWrapper: UIViewControllerRepresentable {
@Environment(LocationModule.self) private var locationModule
typealias UIViewControllerType = MapManagerView


@Environment(LocationModule.self) private var locationModule

func makeUIViewController(context: Context) -> MapManagerView {
MapManagerView(locationModule: locationModule)
}
Expand All @@ -21,15 +22,15 @@ struct MapManagerViewWrapper: UIViewControllerRepresentable {
}

public class MapManagerView: UIViewController {
private var locationModule: LocationModule?

private enum Constants {
static let geoSourceId = "GEOSOURCE"
static let circleLayerId = "CIRCLELAYER"
static let zoomLevel: Double = 14.0
static let countryLabelLayerId = "country-label"
}

private var locationModule: LocationModule?

private lazy var mapView: MapView = {
let map = MapView(frame: view.bounds)
map.autoresizingMask = [.flexibleWidth, .flexibleHeight]
Expand Down
6 changes: 1 addition & 5 deletions StrokeCog/Map/StrokeCogMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2024 StrokeCog. All rights reserved.
//

@_spi(Experimental) import MapboxMaps
import MapboxMaps
import SwiftUI

struct StrokeCogMapView: View {
Expand All @@ -22,10 +22,6 @@ struct StrokeCogMapView: View {
MapManagerViewWrapper()
}
}

init() {
MapboxOptions.accessToken = ""
}
}

struct StrokeCogMapView_Previews: PreviewProvider {
Expand Down
10 changes: 5 additions & 5 deletions StrokeCog/Onboarding/StudyIDView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct StudyIDView: View {
OnboardingView(
titleView: {
OnboardingTitleView(
title: "Study ID",
subtitle: "Welcome to the StrokeCog study. To get started, please enter your study ID."
title: "STUDYID_TITLE",
subtitle: "STUDYID_SUBTITLE"
)
},
contentView: {
Expand Down Expand Up @@ -50,7 +50,7 @@ struct StudyIDView: View {

@ViewBuilder private var studyIDEntryView: some View {
VerifiableTextField(
LocalizedStringResource("Tap here and enter your Study ID"),
LocalizedStringResource("STUDYID_TEXT_FIELD_LABEL"),
text: $studyID
)
.autocorrectionDisabled()
Expand All @@ -62,8 +62,8 @@ struct StudyIDView: View {
"Error",
isPresented: $showInvalidIDAlert
) {
Text("You've entered an invalid study ID.")
Button("Try Again") { }
Text("INVALID_STUDYID_MESSAGE")
Button("RETRY_BUTTON_LABEL") { }
}
}

Expand Down
61 changes: 48 additions & 13 deletions StrokeCog/Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@
}
}
},
"INVALID_STUDYID_MESSAGE" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "You entered an invalid Study ID."
}
}
}
},
"LELAND_STANFORD_BIO" : {
"localizations" : {
"en" : {
Expand Down Expand Up @@ -390,6 +400,16 @@
}
}
},
"RETRY_BUTTON_LABEL" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Try Again"
}
}
}
},
"SCHEDULE_LIST_TITLE" : {
"localizations" : {
"en" : {
Expand All @@ -411,11 +431,35 @@
}
}
},
"Study ID" : {

"STUDYID_SUBTITLE" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Welcome to the StrokeCog study. Please enter your study ID below."
}
}
}
},
"Tap here and enter your Study ID" : {

"STUDYID_TEXT_FIELD_LABEL" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Tap here and enter your Study ID"
}
}
}
},
"STUDYID_TITLE" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Study ID"
}
}
}
},
"TASK_CONTEXT_ACTION_QUESTIONNAIRE" : {
"localizations" : {
Expand Down Expand Up @@ -466,12 +510,6 @@
}
}
}
},
"Try Again" : {

},
"Welcome to the StrokeCog study. To get started, please enter your study ID." : {

},
"WELCOME_AREA1_DESCRIPTION" : {
"localizations" : {
Expand Down Expand Up @@ -563,9 +601,6 @@
}
}
}
},
"You've entered an invalid study ID." : {

}
},
"version" : "1.0"
Expand Down
4 changes: 4 additions & 0 deletions StrokeCog/Supporting Files/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<true/>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>MBXAccessToken</key>
<string>TOKEN</string>
<key>MGLMapboxMetricsEnabledSettingShownInApp</key>
<true/>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down

0 comments on commit 8292004

Please sign in to comment.