From 48f63752a2f49933b50677aad19490b77b808eff Mon Sep 17 00:00:00 2001 From: eduardopietre Date: Mon, 27 Dec 2021 10:59:44 -0300 Subject: [PATCH] Improved UI. Now upload requires pressing upload. --- .../NightScout/NightScoutUploadManager.swift | 9 +++++---- xdrip/Storyboards/ar.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/de.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/en.lproj/Treatments.strings | 2 ++ xdrip/Storyboards/es.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/fi.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/fr.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/it.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/nl.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/pl-PL.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/pt.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/ru.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/sl.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/sv.lproj/Treatments.strings | 4 +++- xdrip/Storyboards/zh.lproj/Treatments.strings | 4 +++- xdrip/Texts/TextsTreatmentsView.swift | 8 ++++++++ .../Treatments/TreatmentsViewController.swift | 12 ++++++++---- 17 files changed, 62 insertions(+), 21 deletions(-) diff --git a/xdrip/Managers/NightScout/NightScoutUploadManager.swift b/xdrip/Managers/NightScout/NightScoutUploadManager.swift index 4b80786b..41540db9 100644 --- a/xdrip/Managers/NightScout/NightScoutUploadManager.swift +++ b/xdrip/Managers/NightScout/NightScoutUploadManager.swift @@ -112,9 +112,6 @@ public class NightScoutUploadManager:NSObject { // upload calibrations uploadCalibrationsToNightScout() - - // upload treatments - uploadTreatmentsToNightScout() // upload activeSensor if needed if UserDefaults.standard.uploadSensorStartTimeToNS, let activeSensor = sensorsAccessor.fetchActiveSensor() { @@ -358,7 +355,7 @@ public class NightScoutUploadManager:NSObject { /// upload treatments to nightscout /// Only checks recents ones - public func uploadTreatmentsToNightScout() { + public func uploadTreatmentsToNightScout(sucessHandler: (() -> Void)?) { trace("in uploadTreatmentsToNightScout", log: self.oslog, category: ConstantsLog.categoryNightScoutUploadManager, type: .info) // get the latest treatments from the last maxDaysToUpload days @@ -387,6 +384,10 @@ public class NightScoutUploadManager:NSObject { self.coreDataManager.saveChanges() } + + if let sucessHandler = sucessHandler { + sucessHandler() + } }) } diff --git a/xdrip/Storyboards/ar.lproj/Treatments.strings b/xdrip/Storyboards/ar.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/ar.lproj/Treatments.strings +++ b/xdrip/Storyboards/ar.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/de.lproj/Treatments.strings b/xdrip/Storyboards/de.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/de.lproj/Treatments.strings +++ b/xdrip/Storyboards/de.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/en.lproj/Treatments.strings b/xdrip/Storyboards/en.lproj/Treatments.strings index 4e8e229e..ded1aedb 100644 --- a/xdrip/Storyboards/en.lproj/Treatments.strings +++ b/xdrip/Storyboards/en.lproj/Treatments.strings @@ -4,3 +4,5 @@ "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; "treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/es.lproj/Treatments.strings b/xdrip/Storyboards/es.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/es.lproj/Treatments.strings +++ b/xdrip/Storyboards/es.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/fi.lproj/Treatments.strings b/xdrip/Storyboards/fi.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/fi.lproj/Treatments.strings +++ b/xdrip/Storyboards/fi.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/fr.lproj/Treatments.strings b/xdrip/Storyboards/fr.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/fr.lproj/Treatments.strings +++ b/xdrip/Storyboards/fr.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/it.lproj/Treatments.strings b/xdrip/Storyboards/it.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/it.lproj/Treatments.strings +++ b/xdrip/Storyboards/it.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/nl.lproj/Treatments.strings b/xdrip/Storyboards/nl.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/nl.lproj/Treatments.strings +++ b/xdrip/Storyboards/nl.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/pl-PL.lproj/Treatments.strings b/xdrip/Storyboards/pl-PL.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/pl-PL.lproj/Treatments.strings +++ b/xdrip/Storyboards/pl-PL.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/pt.lproj/Treatments.strings b/xdrip/Storyboards/pt.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/pt.lproj/Treatments.strings +++ b/xdrip/Storyboards/pt.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/ru.lproj/Treatments.strings b/xdrip/Storyboards/ru.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/ru.lproj/Treatments.strings +++ b/xdrip/Storyboards/ru.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/sl.lproj/Treatments.strings b/xdrip/Storyboards/sl.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/sl.lproj/Treatments.strings +++ b/xdrip/Storyboards/sl.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/sv.lproj/Treatments.strings b/xdrip/Storyboards/sv.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/sv.lproj/Treatments.strings +++ b/xdrip/Storyboards/sv.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Storyboards/zh.lproj/Treatments.strings b/xdrip/Storyboards/zh.lproj/Treatments.strings index 13ebf01e..8446cda6 100644 --- a/xdrip/Storyboards/zh.lproj/Treatments.strings +++ b/xdrip/Storyboards/zh.lproj/Treatments.strings @@ -7,4 +7,6 @@ "treatments_new_entry" = "New Entry"; "treatments_carbs_with_unit" = "Carbs (g):"; "treatments_insulin_with_unit" = "Insulin (U):"; -"treatments_exercise_with_unit" = "Exercise (min):"; \ No newline at end of file +"treatments_exercise_with_unit" = "Exercise (min):"; +"treatments_success" = "Success"; +"treatments_upload_complete" = "Upload complete."; \ No newline at end of file diff --git a/xdrip/Texts/TextsTreatmentsView.swift b/xdrip/Texts/TextsTreatmentsView.swift index f4384dff..dd0dc5c1 100644 --- a/xdrip/Texts/TextsTreatmentsView.swift +++ b/xdrip/Texts/TextsTreatmentsView.swift @@ -27,5 +27,13 @@ enum Texts_TreatmentsView { static let exerciseWithUnit:String = { return NSLocalizedString("treatments_exercise_with_unit", tableName: filename, bundle: Bundle.main, value: "Exercise (min):", comment: "Exercise with unit.") }() + + static let success:String = { + return NSLocalizedString("treatments_success", tableName: filename, bundle: Bundle.main, value: "Success", comment: "Success.") + }() + + static let uploadCompleted:String = { + return NSLocalizedString("treatments_upload_complete", tableName: filename, bundle: Bundle.main, value: "Upload completed.", comment: "Upload completed.") + }() } diff --git a/xdrip/View Controllers/Treatments/TreatmentsViewController.swift b/xdrip/View Controllers/Treatments/TreatmentsViewController.swift index c99ca5c9..451f907b 100644 --- a/xdrip/View Controllers/Treatments/TreatmentsViewController.swift +++ b/xdrip/View Controllers/Treatments/TreatmentsViewController.swift @@ -35,10 +35,14 @@ class TreatmentsViewController : UIViewController { } @IBAction func uploadButtonTapped(_ sender: UIButton) { - nightScoutUploadManager?.uploadTreatmentsToNightScout() - let alert = UIAlertController(title: Texts_Common.Ok, message: Texts_Common.Ok, actionHandler: nil) - - self.present(alert, animated: true, completion: nil) + nightScoutUploadManager?.uploadTreatmentsToNightScout(sucessHandler: { + // Make sure to run alert in the correct thread. + DispatchQueue.main.async { + let alert = UIAlertController(title: Texts_TreatmentsView.success, message: Texts_TreatmentsView.uploadCompleted, actionHandler: nil) + + self.present(alert, animated: true, completion: nil) + } + }) }