diff --git a/xdrip/Constants/ConstantsNotifications.swift b/xdrip/Constants/ConstantsNotifications.swift index e01e7a12..44d4dab7 100644 --- a/xdrip/Constants/ConstantsNotifications.swift +++ b/xdrip/Constants/ConstantsNotifications.swift @@ -54,7 +54,4 @@ enum ConstantsNotifications { /// notification identifier for xDripErrors received in RootViewController's cgmTransmitterDelegate static let notificationIdentifierForxCGMTransmitterDelegatexDripError = "notificationIdentifierForxCGMTransmitterDelegatexDripError" - /// if the time between the last and last but one reading is less than minimiumTimeBetweenTwoReadingsInMinutes, then there will bd no notification created - except if there's been a disconnect in between these two readings - static let minimiumTimeBetweenTwoReadingsInMinutes = 4.75 - } diff --git a/xdrip/Constants/ConstantsSpeakReading.swift b/xdrip/Constants/ConstantsSpeakReading.swift index 44767f66..5ec62953 100644 --- a/xdrip/Constants/ConstantsSpeakReading.swift +++ b/xdrip/Constants/ConstantsSpeakReading.swift @@ -3,6 +3,8 @@ import Foundation enum ConstantsSpeakReading { /// if the time between the last and last but one reading is less than minimiumTimeBetweenTwoReadingsInMinutes, then the reading will not be spoken - except if there's been a disconnect in between these two readings + /// + /// UserDefaults.standard.speakInterval overrules this value static let minimiumTimeBetweenTwoReadingsInMinutes = 4.75 } diff --git a/xdrip/Constants/ConstantsWatch.swift b/xdrip/Constants/ConstantsWatch.swift index b25e7811..ecfc6d04 100644 --- a/xdrip/Constants/ConstantsWatch.swift +++ b/xdrip/Constants/ConstantsWatch.swift @@ -5,7 +5,4 @@ enum ConstantsWatch { /// text to add as notes in glucose events static let textInCreatedEvent = "created by xdrip" - /// if the time between the last and last but one reading is less than minimiumTimeBetweenTwoReadingsInMinutes, then no new event will be created - except if there's been a disconnect in between these two readings - static let minimiumTimeBetweenTwoReadingsInMinutes = 4.75 - } diff --git a/xdrip/Extensions/UserDefaults.swift b/xdrip/Extensions/UserDefaults.swift index 64ecad1b..607e35e6 100644 --- a/xdrip/Extensions/UserDefaults.swift +++ b/xdrip/Extensions/UserDefaults.swift @@ -32,6 +32,9 @@ extension UserDefaults { /// should reading by multiplied by 10 case multipleAppBadgeValueWith10 = "multipleAppBadgeValueWith10" + /// minimum time between two notifications, set by user + case notificationInterval = "notificationInterval" + // Home Screen and graph settings /// show the objectives and make them display on the graph? Or just hide it all because it's too complicated to waste time with? @@ -162,6 +165,9 @@ extension UserDefaults { /// should units be displayed yes or no case displayUnitInCalendarEvent = "displayUnits" + /// calendar interval + case calendarInterval = "calendarInterval" + // Other Settings (not user configurable) /// - in case missed reading alert settings are changed by user, this value will be set to true @@ -302,6 +308,16 @@ extension UserDefaults { set(!newValue, forKey: Key.showReadingInNotification.rawValue) } } + + /// speak readings interval in minutes + @objc dynamic var notificationInterval: Int { + get { + return integer(forKey: Key.notificationInterval.rawValue) + } + set { + set(newValue, forKey: Key.notificationInterval.rawValue) + } + } /// should reading be shown in app badge yes or no @objc dynamic var showReadingInAppBadge: Bool { @@ -1009,6 +1025,18 @@ extension UserDefaults { } } + /// speak readings interval in minutes + @objc dynamic var calendarInterval: Int { + get { + return integer(forKey: Key.calendarInterval.rawValue) + } + set { + set(newValue, forKey: Key.calendarInterval.rawValue) + } + } + + + // MARK: - ===== Other Settings ====== /// - in case missed reading alert settings are changed by user, this value will be set to true diff --git a/xdrip/Managers/Watch/WatchManager.swift b/xdrip/Managers/Watch/WatchManager.swift index 5d4fc136..13d87704 100644 --- a/xdrip/Managers/Watch/WatchManager.swift +++ b/xdrip/Managers/Watch/WatchManager.swift @@ -59,6 +59,17 @@ class WatchManager: NSObject { return } + // if an interval is defined, and if time since last created event is less than interval, then don't create a new event + // substract 10 seconds, because user will probably select a multiple of 5, and also readings usually arrive every 5 minutes + // example user selects 10 minutes interval, next reading will arrive in exactly 10 minutes, time interval to be checked will be 590 seconds + if Int(Date().timeIntervalSince(timeStampLastProcessedReading)) < (UserDefaults.standard.calendarInterval * 60 - 10) { + + trace("in createCalendarEvent, less than %{public}@ minutes since last event, will not create a new event", log: log, category: ConstantsLog.categoryWatchManager, type: .info, UserDefaults.standard.calendarInterval.description) + + return + + } + // get 2 last Readings, with a calculatedValue let lastReading = bgReadingsAccessor.get2LatestBgReadings(minimumTimeIntervalInMinutes: 4.0) @@ -68,15 +79,6 @@ class WatchManager: NSObject { return } - // check if timeStampLastProcessedReading is at least minimiumTimeBetweenTwoReadingsInMinutes earlier than now (or it's at least minimiumTimeBetweenTwoReadingsInMinutes minutes ago that event was created for reading) - otherwise don't create event - // exception : there's been a disconnect/reconnect after the last processed reading (if lastConnectionStatusChangeTimeStamp != nil) - if (abs(timeStampLastProcessedReading.timeIntervalSince(Date())) < ConstantsWatch.minimiumTimeBetweenTwoReadingsInMinutes * 60.0 && (lastConnectionStatusChangeTimeStamp != nil ? lastConnectionStatusChangeTimeStamp! : Date(timeIntervalSince1970: 0)).timeIntervalSince(timeStampLastProcessedReading) < 0) { - - trace("in createCalendarEvent, no new calendar event will be created because it's too close to previous event", log: log, category: ConstantsLog.categoryWatchManager, type: .info) - return - - } - // latest reading should be less than 5 minutes old guard abs(lastReading[0].timeStamp.timeIntervalSinceNow) < 5 * 60 else { trace("in createCalendarEvent, the latest reading is older than 5 minutes", log: log, category: ConstantsLog.categoryWatchManager, type: .info) diff --git a/xdrip/Storyboards/ar.lproj/SettingsViews.strings b/xdrip/Storyboards/ar.lproj/SettingsViews.strings index 513ad4d8..8e37a9fe 100644 --- a/xdrip/Storyboards/ar.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/ar.lproj/SettingsViews.strings @@ -47,8 +47,8 @@ "settingsviews_speakreadingslanguageselection" = "اختر اللغة"; "settingsviews_speakTrend" = "نطق الاتجاه؟"; "settingsviews_speakDelta" = "نطق الفرق؟"; -"settingsviews_speakInterval" = "الفاصل الزمني:"; -"settingsviews_speakIntervalMessage" = "الفاصل الزمني الأدنى بين قراءتين بالدقائق"; +"settingsviews_IntervalTitle" = "الفاصل الزمني:"; +"settingsviews_IntervalMessage" = "الفاصل الزمني الأدنى بين قراءتين بالدقائق"; "settingsviews_Version" = "الإصدار:"; "settingsviews_license" = "رخصة"; "settingsviews_build" = "رقم الإصدار:"; diff --git a/xdrip/Storyboards/de.lproj/SettingsViews.strings b/xdrip/Storyboards/de.lproj/SettingsViews.strings index 139572f0..a52a01c6 100644 --- a/xdrip/Storyboards/de.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/de.lproj/SettingsViews.strings @@ -131,8 +131,8 @@ /// nightscout settings, port to use "nightScoutPort" = "Port (Optional):"; -/// speak settings, where user can set the speak interval, speak each reading, each two readings ... -"settingsviews_speakInterval" = "Intervall:"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalTitle" = "Intervall:"; /// general settings, literally follower "settingsviews_follower" = "Follower"; @@ -212,8 +212,8 @@ /// dexcom share settings, where user can set the dexcom share account name "settingsviews_dexcomShareAccountName" = "Benutzer Name:"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Mindestabstand zwischen zwei vorgelesenen Werten in Minuten"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Mindestabstand zwischen zwei Werten in Minuten"; /// shown on top of the first settings screen "m5stack_settingsviews_settingstitle" = "M5 Stack Einstellungen"; diff --git a/xdrip/Storyboards/en.lproj/SettingsViews.strings b/xdrip/Storyboards/en.lproj/SettingsViews.strings index fff6dc8f..79ab5ed8 100644 --- a/xdrip/Storyboards/en.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/en.lproj/SettingsViews.strings @@ -57,8 +57,8 @@ "settingsviews_speakreadingslanguageselection" = "Select Language"; "settingsviews_speakTrend" = "Speak Trend?"; "settingsviews_speakDelta" = "Speak Delta?"; -"settingsviews_speakInterval" = "Interval:"; -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +"settingsviews_IntervalTitle" = "Interval:"; +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; "settingsviews_sectiontitleAbout" = "About %@"; "settingsviews_Version" = "Version:"; "settingsviews_license" = "License"; diff --git a/xdrip/Storyboards/es.lproj/SettingsViews.strings b/xdrip/Storyboards/es.lproj/SettingsViews.strings index 2d5d4f7a..16880da6 100644 --- a/xdrip/Storyboards/es.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/es.lproj/SettingsViews.strings @@ -55,8 +55,8 @@ "settingsviews_speakreadingslanguageselection" = "Seleccionar Idioma"; "settingsviews_speakTrend" = "Anunciar Tendencia"; "settingsviews_speakDelta" = "Anunciar Delta"; -"settingsviews_speakInterval" = "Intervalo"; -"settingsviews_speakIntervalMessage" = "Intervalo mínimo entre dos lecturas (mins)"; +"settingsviews_IntervalTitle" = "Intervalo"; +"settingsviews_IntervalMessage" = "Intervalo mínimo entre dos lecturas (mins)"; "settingsviews_Version" = "Versión:"; "settingsviews_license" = "Licencia"; "settingsviews_build" = "Compilación:"; diff --git a/xdrip/Storyboards/fi.lproj/SettingsViews.strings b/xdrip/Storyboards/fi.lproj/SettingsViews.strings index 7d009251..56e50f47 100644 --- a/xdrip/Storyboards/fi.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/fi.lproj/SettingsViews.strings @@ -54,8 +54,8 @@ "settingsviews_speakreadingslanguageselection" = "Valitse kieli"; "settingsviews_speakTrend" = "Puhu suunta?"; "settingsviews_speakDelta" = "Puhu erotus?"; -"settingsviews_speakInterval" = "Intervalli:"; -"settingsviews_speakIntervalMessage" = "Kahden lukeman välinen vähimmäisväli minuutteina"; +"settingsviews_IntervalTitle" = "Intervalli:"; +"settingsviews_IntervalMessage" = "Kahden lukeman välinen vähimmäisväli minuutteina"; "settingsviews_sectiontitleAbout" = "%@ info"; "settingsviews_Version" = "Versio:"; "settingsviews_license" = "Lisenssi"; diff --git a/xdrip/Storyboards/fr.lproj/SettingsViews.strings b/xdrip/Storyboards/fr.lproj/SettingsViews.strings index dc3b69b5..8d5f0533 100644 --- a/xdrip/Storyboards/fr.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/fr.lproj/SettingsViews.strings @@ -49,8 +49,8 @@ "settingsviews_speakreadingslanguageselection" = "Sélectionner la langue"; "settingsviews_speakTrend" = "Lire la tendance?"; "settingsviews_speakDelta" = "Lire la variation?"; -"settingsviews_speakInterval" = "Intervalle"; -"settingsviews_speakIntervalMessage" = "Intervalle minimum entre deux lectures, en minutes"; +"settingsviews_IntervalTitle" = "Intervalle"; +"settingsviews_IntervalMessage" = "Intervalle minimum entre deux lectures, en minutes"; "settingsviews_Version" = "Version"; "settingsviews_license" = "License"; "settingsviews_build" = "Build"; diff --git a/xdrip/Storyboards/it.lproj/SettingsViews.strings b/xdrip/Storyboards/it.lproj/SettingsViews.strings index 354efd12..637d00e9 100644 --- a/xdrip/Storyboards/it.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/it.lproj/SettingsViews.strings @@ -12,8 +12,8 @@ /// nightscout settings, port to use "nightScoutPort" = "Port (optional):"; -/// speak settings, where user can set the speak interval, speak each reading, each two readings ... -"settingsviews_speakInterval" = "Interval:"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up title - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalTitle" = "Interval:"; /// home screen settings, urgent high value "settingsviews_urgentHighValue" = "Urgent High Value:"; @@ -45,8 +45,8 @@ /// shown on top of the first settings screen, literally 'Settings' "settingsviews_settingstitle" = "Settings"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; /// Apple Watch Settings - text in row where create event is enabled or disabled "createCalendarEvent" = "Create Calendar Events?"; diff --git a/xdrip/Storyboards/nl.lproj/SettingsViews.strings b/xdrip/Storyboards/nl.lproj/SettingsViews.strings index b721adba..663ea0cc 100644 --- a/xdrip/Storyboards/nl.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/nl.lproj/SettingsViews.strings @@ -58,8 +58,8 @@ "settingsviews_speakreadingslanguageselection" = "Selecteer Taal"; "settingsviews_speakTrend" = "Spreek Trend Uit?"; "settingsviews_speakDelta" = "Spreek Delta Uit?"; -"settingsviews_speakInterval" = "Interval:"; -"settingsviews_speakIntervalMessage" = "Minimum interval tussen twee metingen, in minuten"; +"settingsviews_IntervalTitle" = "Interval:"; +"settingsviews_IntervalMessage" = "Minimum interval tussen twee metingen, in minuten"; "settingsviews_sectiontitleAbout" = "Over %@"; "settingsviews_Version" = "Versie:"; "settingsviews_license" = "Licentie"; diff --git a/xdrip/Storyboards/pl-PL.lproj/SettingsViews.strings b/xdrip/Storyboards/pl-PL.lproj/SettingsViews.strings index 354efd12..637d00e9 100644 --- a/xdrip/Storyboards/pl-PL.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/pl-PL.lproj/SettingsViews.strings @@ -12,8 +12,8 @@ /// nightscout settings, port to use "nightScoutPort" = "Port (optional):"; -/// speak settings, where user can set the speak interval, speak each reading, each two readings ... -"settingsviews_speakInterval" = "Interval:"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up title - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalTitle" = "Interval:"; /// home screen settings, urgent high value "settingsviews_urgentHighValue" = "Urgent High Value:"; @@ -45,8 +45,8 @@ /// shown on top of the first settings screen, literally 'Settings' "settingsviews_settingstitle" = "Settings"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; /// Apple Watch Settings - text in row where create event is enabled or disabled "createCalendarEvent" = "Create Calendar Events?"; diff --git a/xdrip/Storyboards/pt.lproj/SettingsViews.strings b/xdrip/Storyboards/pt.lproj/SettingsViews.strings index 223de306..a96ed667 100644 --- a/xdrip/Storyboards/pt.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/pt.lproj/SettingsViews.strings @@ -57,8 +57,8 @@ "settingsviews_speakreadingslanguageselection" = "Escolher Idioma"; "settingsviews_speakTrend" = "Falar Tendência?"; "settingsviews_speakDelta" = "Falar Delta?"; -"settingsviews_speakInterval" = "Intervalo:"; -"settingsviews_speakIntervalMessage" = "Intervalo minímo entre duas leituras, em minutos"; +"settingsviews_IntervalTitle" = "Intervalo:"; +"settingsviews_IntervalMessage" = "Intervalo minímo entre duas leituras, em minutos"; "settingsviews_sectiontitleAbout" = "Sobre %@"; "settingsviews_Version" = "Versão:"; "settingsviews_license" = "Licença"; diff --git a/xdrip/Storyboards/ru.lproj/SettingsViews.strings b/xdrip/Storyboards/ru.lproj/SettingsViews.strings index 354efd12..637d00e9 100644 --- a/xdrip/Storyboards/ru.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/ru.lproj/SettingsViews.strings @@ -12,8 +12,8 @@ /// nightscout settings, port to use "nightScoutPort" = "Port (optional):"; -/// speak settings, where user can set the speak interval, speak each reading, each two readings ... -"settingsviews_speakInterval" = "Interval:"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up title - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalTitle" = "Interval:"; /// home screen settings, urgent high value "settingsviews_urgentHighValue" = "Urgent High Value:"; @@ -45,8 +45,8 @@ /// shown on top of the first settings screen, literally 'Settings' "settingsviews_settingstitle" = "Settings"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; /// Apple Watch Settings - text in row where create event is enabled or disabled "createCalendarEvent" = "Create Calendar Events?"; diff --git a/xdrip/Storyboards/sl.lproj/SettingsViews.strings b/xdrip/Storyboards/sl.lproj/SettingsViews.strings index 354efd12..0e731dff 100644 --- a/xdrip/Storyboards/sl.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/sl.lproj/SettingsViews.strings @@ -12,8 +12,8 @@ /// nightscout settings, port to use "nightScoutPort" = "Port (optional):"; -/// speak settings, where user can set the speak interval, speak each reading, each two readings ... -"settingsviews_speakInterval" = "Interval:"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalTitle" = "Interval:"; /// home screen settings, urgent high value "settingsviews_urgentHighValue" = "Urgent High Value:"; @@ -45,8 +45,8 @@ /// shown on top of the first settings screen, literally 'Settings' "settingsviews_settingstitle" = "Settings"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; /// Apple Watch Settings - text in row where create event is enabled or disabled "createCalendarEvent" = "Create Calendar Events?"; diff --git a/xdrip/Storyboards/sv.lproj/SettingsViews.strings b/xdrip/Storyboards/sv.lproj/SettingsViews.strings index 25537319..77080511 100644 --- a/xdrip/Storyboards/sv.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/sv.lproj/SettingsViews.strings @@ -57,8 +57,8 @@ "settingsviews_speakreadingslanguageselection" = "Välj språk"; "settingsviews_speakTrend" = "Läs upp trend?"; "settingsviews_speakDelta" = "Läs upp delta?"; -"settingsviews_speakInterval" = "Intervall:"; -"settingsviews_speakIntervalMessage" = "Minsta intervall mellan två avläsningar, i minuter"; +"settingsviews_IntervalTitle" = "Intervall:"; +"settingsviews_IntervalMessage" = "Minsta intervall mellan två avläsningar, i minuter"; "settingsviews_sectiontitleAbout" = "Om %@"; "settingsviews_Version" = "Version:"; "settingsviews_license" = "Licens"; diff --git a/xdrip/Storyboards/zh.lproj/SettingsViews.strings b/xdrip/Storyboards/zh.lproj/SettingsViews.strings index 720e3346..9d589ad3 100644 --- a/xdrip/Storyboards/zh.lproj/SettingsViews.strings +++ b/xdrip/Storyboards/zh.lproj/SettingsViews.strings @@ -30,7 +30,7 @@ "settingsviews_speakBgReadings" = "语音播报血糖值"; "settingsviews_speakTrend" = "语音播报趋势"; "settingsviews_speakDelta" = "语音播报偏移量"; -"settingsviews_speakInterval" = "间隔时间"; +"settingsviews_IntervalTitle" = "间隔时间"; "settingsviews_masterorfollower" = "主控端或者关注者 ?"; "settingsviews_master" = "主控端"; "settingsviews_follower" = "关注者"; @@ -63,8 +63,8 @@ /// Apple Watch Settings - text in row where user needs to say if unit should be displayed or not "displayUnitInCalendarEvent" = "Display Unit?"; -/// When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up -"settingsviews_speakIntervalMessage" = "Minimum interval between two readings, in minutes"; +/// When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch +"settingsviews_IntervalMessage" = "Minimum interval between two readings, in minutes"; /// Apple Watch Settings - text in row where create event is enabled or disabled "createCalendarEvent" = "Create Calendar Events?"; diff --git a/xdrip/Texts/TextsSettingsView.swift b/xdrip/Texts/TextsSettingsView.swift index 0ad2b8b0..ad9c4e2d 100644 --- a/xdrip/Texts/TextsSettingsView.swift +++ b/xdrip/Texts/TextsSettingsView.swift @@ -267,12 +267,12 @@ class Texts_SettingsView { return NSLocalizedString("settingsviews_speakDelta", tableName: filename, bundle: Bundle.main, value: "Speak Delta?", comment: "speak settings, where user can enable or disable speak delta") }() - static let labelSpeakInterval = { - return NSLocalizedString("settingsviews_speakInterval", tableName: filename, bundle: Bundle.main, value: "Interval:", comment: "speak settings, where user can set the speak interval, speak each reading, each two readings ...") + static let settingsviews_IntervalTitle = { + return NSLocalizedString("settingsviews_IntervalTitle", tableName: filename, bundle: Bundle.main, value: "Interval:", comment: "When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch") }() - static let speakIntervalMessage = { - return NSLocalizedString("settingsviews_speakIntervalMessage", tableName: filename, bundle: Bundle.main, value: "Minimum interval between two readings (mins)", comment: "When clicking the interval setting, a pop up asks for number of minutes between two spoken readings, this is the message displayed in the pop up") + static let settingsviews_IntervalMessage = { + return NSLocalizedString("settingsviews_IntervalMessage", tableName: filename, bundle: Bundle.main, value: "Minimum interval between two readings (mins)", comment: "When clicking the interval setting, a pop up asks for minimum number of minutes between two readings, this is the pop up message - this is used for setting the interval between two readings in BG notifications, Speak readings, Apple Watch") }() // MARK: - Section About Info diff --git a/xdrip/View Controllers/Root View Controller/RootViewController.swift b/xdrip/View Controllers/Root View Controller/RootViewController.swift index e97fbd8f..215a9ee5 100644 --- a/xdrip/View Controllers/Root View Controller/RootViewController.swift +++ b/xdrip/View Controllers/Root View Controller/RootViewController.swift @@ -1242,8 +1242,8 @@ final class RootViewController: UIViewController { if readingValueForBadge <= 40.0 {readingValueForBadge = 40.0} // check if notification on home screen is enabled in the settings - // and also if last notification was long enough ago (longer than ConstantsNotifications.minimiumTimeBetweenTwoReadingsInMinutes), except if there would have been a disconnect since previous notification (simply because I like getting a new reading with a notification by disabling/reenabling bluetooth - if UserDefaults.standard.showReadingInNotification && !overrideShowReadingInNotification && (abs(timeStampLastBGNotification.timeIntervalSince(Date())) > ConstantsNotifications.minimiumTimeBetweenTwoReadingsInMinutes * 60.0 || lastConnectionStatusChangeTimeStamp().timeIntervalSince(timeStampLastBGNotification) > 0) { + // and also if last notification was long enough ago (longer than UserDefaults.standard.notificationInterval), except if there would have been a disconnect since previous notification (simply because I like getting a new reading with a notification by disabling/reenabling bluetooth + if UserDefaults.standard.showReadingInNotification && !overrideShowReadingInNotification && (abs(timeStampLastBGNotification.timeIntervalSince(Date())) > Double(UserDefaults.standard.notificationInterval) * 60.0 || lastConnectionStatusChangeTimeStamp().timeIntervalSince(timeStampLastBGNotification) > 0) { // Create Notification Content let notificationContent = UNMutableNotificationContent() diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAppleWatchSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAppleWatchSettingsViewModel.swift index 0b63e3b9..0113ec09 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAppleWatchSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewAppleWatchSettingsViewModel.swift @@ -20,6 +20,9 @@ fileprivate enum Setting:Int, CaseIterable { /// should units be displayed yes or no case displayUnits = 4 + /// minimum time between two readings, for which event should be created (in minutes) + case calendarInterval = 5 + } class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { @@ -62,6 +65,9 @@ class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { case .displayUnits: return Texts_SettingsView.displayUnitInCalendarEvent + + case .calendarInterval: + return Texts_SettingsView.settingsviews_IntervalTitle } @@ -104,6 +110,9 @@ class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { case .displayTrend, .displayDelta, .displayUnits: return UITableViewCell.AccessoryType.none + case .calendarInterval: + return UITableViewCell.AccessoryType.disclosureIndicator + } } @@ -118,6 +127,9 @@ class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { case .createCalendarEvent, .displayTrend, .displayDelta, .displayUnits: return nil + + case .calendarInterval: + return UserDefaults.standard.calendarInterval.description } } @@ -194,6 +206,9 @@ class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { case .displayUnits: return UISwitch(isOn: UserDefaults.standard.displayUnitInCalendarEvent, action: {(isOn:Bool) in UserDefaults.standard.displayUnitInCalendarEvent = isOn}) + case .calendarInterval: + return nil + } } @@ -284,6 +299,10 @@ class SettingsViewAppleWatchSettingsViewModel: SettingsViewModelProtocol { } }, cancelHandler: nil, didSelectRowHandler: nil) + case .calendarInterval: + + return SettingsSelectedRowAction.askText(title: Texts_SettingsView.settingsviews_IntervalTitle, message: Texts_SettingsView.settingsviews_IntervalMessage, keyboardType: .numberPad, text: UserDefaults.standard.calendarInterval.description, placeHolder: "0", actionTitle: nil, cancelTitle: nil, actionHandler: {(interval:String) in if let interval = Int(interval) {UserDefaults.standard.calendarInterval = Int(interval)}}, cancelHandler: nil, inputValidator: nil) + } } diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewGeneralSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewGeneralSettingsViewModel.swift index 8856c6a5..4cfc486f 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewGeneralSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewGeneralSettingsViewModel.swift @@ -2,20 +2,24 @@ import UIKit fileprivate enum Setting:Int, CaseIterable { - //blood glucose unit + /// blood glucose unit case bloodGlucoseUnit = 0 - // choose between master and follower + /// choose between master and follower case masterFollower = 1 - // should reading be shown in notification + /// should reading be shown in notification case showReadingInNotification = 2 - // show reading in app badge - case showReadingInAppBadge = 3 + /// - minimum time between two readings, for which notification should be created (in minutes) + /// - except if there's been a disconnect, in that case this value is not taken into account + case notificationInterval = 3 - // if reading is shown in app badge, should value be multiplied with 10 yes or no - case multipleAppBadgeValueWith10 = 4 + /// show reading in app badge + case showReadingInAppBadge = 4 + + /// if reading is shown in app badge, should value be multiplied with 10 yes or no + case multipleAppBadgeValueWith10 = 5 } @@ -111,6 +115,10 @@ class SettingsViewGeneralSettingsViewModel: SettingsViewModelProtocol { case .showReadingInNotification, .showReadingInAppBadge, .multipleAppBadgeValueWith10: return SettingsSelectedRowAction.nothing + case .notificationInterval: + + return SettingsSelectedRowAction.askText(title: Texts_SettingsView.settingsviews_IntervalTitle, message: Texts_SettingsView.settingsviews_IntervalMessage, keyboardType: .numberPad, text: UserDefaults.standard.notificationInterval.description, placeHolder: "0", actionTitle: nil, cancelTitle: nil, actionHandler: {(interval:String) in if let interval = Int(interval) {UserDefaults.standard.notificationInterval = Int(interval)}}, cancelHandler: nil, inputValidator: nil) + } } @@ -150,6 +158,9 @@ class SettingsViewGeneralSettingsViewModel: SettingsViewModelProtocol { case .multipleAppBadgeValueWith10: return Texts_SettingsView.multipleAppBadgeValueWith10 + case .notificationInterval: + return Texts_SettingsView.settingsviews_IntervalTitle + } } @@ -167,6 +178,9 @@ class SettingsViewGeneralSettingsViewModel: SettingsViewModelProtocol { case .showReadingInNotification, .showReadingInAppBadge, .multipleAppBadgeValueWith10: return UITableViewCell.AccessoryType.none + case .notificationInterval: + return UITableViewCell.AccessoryType.disclosureIndicator + } } @@ -184,6 +198,8 @@ class SettingsViewGeneralSettingsViewModel: SettingsViewModelProtocol { case .showReadingInNotification, .showReadingInAppBadge, .multipleAppBadgeValueWith10: return nil + case .notificationInterval: + return UserDefaults.standard.notificationInterval.description } } @@ -208,6 +224,9 @@ class SettingsViewGeneralSettingsViewModel: SettingsViewModelProtocol { case .bloodGlucoseUnit, .masterFollower: return nil + case .notificationInterval: + return nil + } } diff --git a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewSpeakSettingsViewModel.swift b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewSpeakSettingsViewModel.swift index 29650dab..3775ba78 100644 --- a/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewSpeakSettingsViewModel.swift +++ b/xdrip/View Controllers/SettingsNavigationController/SettingsViewController/SettingsViewModels/SettingsViewSpeakSettingsViewModel.swift @@ -49,7 +49,7 @@ class SettingsViewSpeakSettingsViewModel:SettingsViewModelProtocol { case .speakDelta: return .nothing case .speakInterval: - return SettingsSelectedRowAction.askText(title: Texts_SettingsView.labelSpeakInterval, message: Texts_SettingsView.speakIntervalMessage, keyboardType: .numberPad, text: UserDefaults.standard.speakInterval.description, placeHolder: "0", actionTitle: nil, cancelTitle: nil, actionHandler: {(interval:String) in if let interval = Int(interval) {UserDefaults.standard.speakInterval = Int(interval)}}, cancelHandler: nil, inputValidator: nil) + return SettingsSelectedRowAction.askText(title: Texts_SettingsView.settingsviews_IntervalTitle, message: Texts_SettingsView.settingsviews_IntervalMessage, keyboardType: .numberPad, text: UserDefaults.standard.speakInterval.description, placeHolder: "0", actionTitle: nil, cancelTitle: nil, actionHandler: {(interval:String) in if let interval = Int(interval) {UserDefaults.standard.speakInterval = Int(interval)}}, cancelHandler: nil, inputValidator: nil) case .speakBgReadingLanguage: //find index for languageCode type currently stored in userdefaults @@ -95,7 +95,7 @@ class SettingsViewSpeakSettingsViewModel:SettingsViewModelProtocol { case .speakDelta: return Texts_SettingsView.labelSpeakDelta case .speakInterval: - return Texts_SettingsView.labelSpeakInterval + return Texts_SettingsView.settingsviews_IntervalTitle } }