Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functionality to repeat last callout upon shaking device + RCOS Documentation #94

Merged
merged 12 commits into from
Sep 15, 2024
Merged
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -1596,6 +1596,12 @@
/* Callouts Information, Updates about didtance to the audio beacon when it's set */
"callouts.audio_beacon.info" = "Updates about distance to the audio beacon when it's set";

/* Shake callouts */
"callouts.shake_callouts" = "Repeat Callouts";

/* Shake callouts info */
"callouts.shake_callouts.info" = "Shake the device to repeat the last callout";

/* Callouts Title, Automatic Callouts */
"callouts.automatic_callouts" = "Automatic Callouts";

Expand Down
13 changes: 13 additions & 0 deletions apps/ios/GuideDogs/Code/App/Settings/SettingsContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CoreLocation

extension Notification.Name {
static let automaticCalloutsEnabledChanged = Notification.Name("GDAAutomaticCalloutsChanged")
static let shakeCalloutsEnabledChanged = Notification.Name("GDAShakeCalloutsChanged")
static let autoCalloutCategorySenseChanged = Notification.Name("GDAAutomaticCalloutSenseChanged")
static let beaconVolumeChanged = Notification.Name("GDABeaconVolumeChanged")
static let ttsVolumeChanged = Notification.Name("GDATTSVolumeChanged")
Expand Down Expand Up @@ -42,6 +43,7 @@ class SettingsContext {
fileprivate static let useOldBeacon = "GDASettingsUseOldBeacon"
fileprivate static let playBeaconStartEndMelody = "GDAPlayBeaconStartEndMelody"
fileprivate static let automaticCalloutsEnabled = "GDASettingsAutomaticCalloutsEnabled"
fileprivate static let shakeCalloutsEnabled = "GDASettingsShakeCalloutsEnabled"
fileprivate static let sensePlace = "GDASettingsPlaceSenseEnabled"
fileprivate static let senseLandmark = "GDASettingsLandmarkSenseEnabled"
fileprivate static let senseMobility = "GDASettingsMobilitySenseEnabled"
Expand Down Expand Up @@ -96,6 +98,7 @@ class SettingsContext {
Keys.useOldBeacon: false,
Keys.playBeaconStartEndMelody: false,
Keys.automaticCalloutsEnabled: true,
Keys.shakeCalloutsEnabled: true,
Keys.sensePlace: true,
Keys.senseLandmark: true,
Keys.senseMobility: true,
Expand Down Expand Up @@ -402,6 +405,16 @@ extension SettingsContext: AutoCalloutSettingsProvider {
}
}

var shakeCalloutsEnabled: Bool {
get {
return userDefaults.bool(forKey: Keys.shakeCalloutsEnabled)
}
set(newValue) {
userDefaults.set(newValue, forKey: Keys.shakeCalloutsEnabled)
NotificationCenter.default.post(name: .shakeCalloutsEnabledChanged, object: self, userInfo: [Keys.enabled: newValue])
}
}

var placeSenseEnabled: Bool {
get {
return userDefaults.bool(forKey: Keys.sensePlace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protocol CalloutSettingsCellViewDelegate: AnyObject {
}

internal enum CalloutSettingCellType {
case all, poi, mobility, beacon
case all, poi, mobility, beacon, shake
}

class CalloutSettingsCellView: UITableViewCell {
Expand Down Expand Up @@ -42,6 +42,8 @@ class CalloutSettingsCellView: UITableViewCell {
case .beacon:
settingSwitch.isOn = SettingsContext.shared.destinationSenseEnabled
return
case .shake:
settingSwitch.isOn = SettingsContext.shared.shakeCalloutsEnabled
}
}
}
Expand Down Expand Up @@ -92,6 +94,9 @@ class CalloutSettingsCellView: UITableViewCell {
SettingsContext.shared.destinationSenseEnabled = isOn
log(["destination"])
return
case .shake:
SettingsContext.shared.shakeCalloutsEnabled = isOn
GDATelemetry.track("settings.shake_callouts", value: isOn.description)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ extension UIWindow {
open override func motionEnded(_ motion: UIEvent.EventSubtype, with event: UIEvent?) {
super.motionEnded(motion, with: event)

if(motion == .motionShake && SettingsContext.shared.shakeCalloutsEnabled){

guard let callout = AppContext.shared.calloutHistory.callouts.last else {
return
}

AppContext.process(RepeatCalloutEvent(callout: callout) { (_) in
})

return
}



// We use the shake motion to pause and resume a GPX simulation
guard FeatureFlag.isEnabled(.developerTools),
motion == .motionShake,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SettingsViewController: BaseTableViewController {
case poi = 1
case mobility = 2
case beacon = 3
case shake = 4
}

private static let cellIdentifiers: [IndexPath: String] = [
Expand All @@ -43,6 +44,7 @@ class SettingsViewController: BaseTableViewController {
IndexPath(row: CalloutsRow.poi.rawValue, section: Section.callouts.rawValue): "poiCallouts",
IndexPath(row: CalloutsRow.mobility.rawValue, section: Section.callouts.rawValue): "mobilityCallouts",
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue): "beaconCallouts",
IndexPath(row: CalloutsRow.shake.rawValue, section: Section.callouts.rawValue): "shakeCallouts",

IndexPath(row: 0, section: Section.streetPreview.rawValue): "streetPreview",
IndexPath(row: 0, section: Section.troubleshooting.rawValue): "troubleshooting",
Expand All @@ -53,7 +55,8 @@ class SettingsViewController: BaseTableViewController {
private static let collapsibleCalloutIndexPaths: [IndexPath] = [
IndexPath(row: CalloutsRow.poi.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.mobility.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue)
IndexPath(row: CalloutsRow.beacon.rawValue, section: Section.callouts.rawValue),
IndexPath(row: CalloutsRow.shake.rawValue, section: Section.callouts.rawValue)
]

// MARK: Properties
Expand Down Expand Up @@ -82,7 +85,7 @@ class SettingsViewController: BaseTableViewController {
switch sectionType {
case .general: return 6
case .audio: return 1
case .callouts: return SettingsContext.shared.automaticCalloutsEnabled ? 4 : 1
case .callouts: return SettingsContext.shared.automaticCalloutsEnabled ? 5 : 1
case .streetPreview: return 1
case .troubleshooting: return 1
case .about: return 1
Expand All @@ -108,6 +111,7 @@ class SettingsViewController: BaseTableViewController {
case .poi: cell.type = .poi
case .mobility: cell.type = .mobility
case .beacon: cell.type = .beacon
case .shake: cell.type = .shake
}
}

Expand Down
Loading