Skip to content

Commit

Permalink
Merge pull request JohanDegraeve#279 from pvavolas/Add-enddate-in-status
Browse files Browse the repository at this point in the history
Add Sensor end date information in Status info box
  • Loading branch information
JohanDegraeve authored Dec 20, 2021
2 parents 82643b9 + ed493da commit 9a52966
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions xdrip/Storyboards/en.lproj/HomeView.strings
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"bluetoothIsNotAuthorized" = "You did not give bluetooth permission for %@. Go to the settings, find the %@ app, and enable Bluetooth.";
"startScanningInfo" = "Scanning Started.\n\nKeep %@ open in the foreground until a connection is made.\n\n(There's no need to turn off Auto-Lock. Just don't press the home button and don't lock your iPhone)";
"sensorstart" = "Sensor Started";
"sensorend" = "Sensor Ends";
"notstarted" = "Not Started";
"notknown" = "Not Known";
"lastconnection" = "Last Connection";
Expand Down
4 changes: 4 additions & 0 deletions xdrip/Texts/TextsHomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ enum Texts_HomeView {
static let sensorStart:String = {
return NSLocalizedString("sensorstart", tableName: filename, bundle: Bundle.main, value: "Sensor Start", comment: "status info : literally 'Sensor Start'")
}()

static let sensorEnd:String = {
return NSLocalizedString("sensorend", tableName: filename, bundle: Bundle.main, value: "Sensor End", comment: "status info : literally 'Sensor End'")
}()

static let notStarted:String = {
return NSLocalizedString("notstarted", tableName: filename, bundle: Bundle.main, value: "Not Started", comment: "status info : literally 'not started', used if sensor is not started")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1888,13 +1888,29 @@ final class RootViewController: UIViewController {
self.present(actionSheet, animated: true)
}

private func appendEndDateInformation(_ activeSensor: Sensor, _ textToShow: String) -> String {
var result = "\r\n\r\n" + Texts_HomeView.sensorEnd + " : "
if activeSensor.endDate != nil {
result += (activeSensor.endDate?.description(with: .current))!
}
else if UserDefaults.standard.maxSensorAgeInDays > 0 {
result += activeSensor.startDate.addingTimeInterval(TimeInterval(hours: Double(UserDefaults.standard.maxSensorAgeInDays * 24))).description(with: .current)
}
else { //No end date information could be retrieved, return nothing
return ""
}

return result
}

/// will show the status
private func showStatus() {

// first sensor status
var textToShow = Texts_HomeView.sensorStart + " : "
if let activeSensor = activeSensor {
textToShow += activeSensor.startDate.description(with: .current)
textToShow += appendEndDateInformation(activeSensor, textToShow)
} else {
textToShow += Texts_HomeView.notStarted
}
Expand Down

0 comments on commit 9a52966

Please sign in to comment.