Преглед изворни кода

Working with info display view controller

Jonas Björkert пре 2 година
родитељ
комит
660edf2b3c

+ 1 - 1
LoopFollow/Controllers/Nightscout/Treatments.swift

@@ -97,7 +97,7 @@ extension MainViewController {
                     let newEntry = sageData(created_at: createdAt)
                     cgmSensorStart.append(newEntry)
                 }
-            case "Insulin Cartridge Change":
+            case "Insulin Change":
                 if let createdAt = entry["created_at"] as? String {
                     let newEntry = iageData(created_at: createdAt)
                     insulinCartridge.append(newEntry)

+ 1 - 1
LoopFollow/Helpers/NightscoutUtils.swift

@@ -46,7 +46,7 @@ class NightscoutUtils {
         case profile
         case treatments
         case deviceStatus
-        case iage = "Insulin Cartridge Change"
+        case iage = "Insulin Change"
 
         var endpoint: String {
             switch self {

+ 17 - 11
LoopFollow/ViewControllers/InfoDisplaySettingsViewController.swift

@@ -25,6 +25,7 @@ class InfoDisplaySettingsViewController: FormViewController {
     }
 
     private func createForm() {
+        form.removeAll()  // Clear any existing form to ensure we start fresh
         form
         +++ Section("General")
         <<< SwitchRow("hideInfoTable"){ row in
@@ -40,41 +41,46 @@ class InfoDisplaySettingsViewController: FormViewController {
 
             $0.tag = "InfoDisplay"
 
+            // Iterate through the current infoSort array to set up UI elements
             for i in 0..<UserDefaultsRepository.infoSort.value.count {
                 let sortedIndex = UserDefaultsRepository.infoSort.value[i]
 
-                // Debug print to track the sortedIndex and corresponding InfoType
-                print("Index \(i): sortedIndex = \(sortedIndex)")
-
-                // Check if the sortedIndex maps to a valid InfoType
+                // Ensure sortedIndex is valid and maps to an InfoType
                 if let infoType = InfoType(rawValue: sortedIndex) {
-                    print("InfoType for sortedIndex \(sortedIndex): \(infoType.name)")
-
                     $0 <<< TextRow() { row in
                         if UserDefaultsRepository.infoVisible.value[sortedIndex] {
                             row.title = "\u{2713}\t\(infoType.name)"
                         } else {
                             row.title = "\u{2001}\t\(infoType.name)"
                         }
-                    }.onCellSelection { (cell, row) in
+                    }.onCellSelection { [weak self] (cell, row) in
+                        guard let self = self else { return }
+
                         let i = row.indexPath!.row
                         let sortedIndex = UserDefaultsRepository.infoSort.value[i]
+
+                        // Toggle visibility directly
                         UserDefaultsRepository.infoVisible.value[sortedIndex] = !UserDefaultsRepository.infoVisible.value[sortedIndex]
 
+                        // Reload the entire table to reflect changes
                         self.tableView.reloadData()
                     }.cellSetup { (cell, row) in
                         cell.textField.isUserInteractionEnabled = false
-                    }.cellUpdate { (cell, row) in
+                    }.cellUpdate { [weak self] (cell, row) in
+                        guard let self = self else { return }
+
+                        let i = row.indexPath!.row
                         let sortedIndex = UserDefaultsRepository.infoSort.value[i]
+
                         if UserDefaultsRepository.infoVisible.value[sortedIndex] {
                             row.title = "\u{2713}\t\(infoType.name)"
                         } else {
                             row.title = "\u{2001}\t\(infoType.name)"
                         }
+
                         self.appStateController!.infoDataSettingsChanged = true
                     }
                 } else {
-                    // Handle the case where sortedIndex doesn't map to a valid InfoType
                     print("Warning: sortedIndex \(sortedIndex) does not map to a valid InfoType!")
                 }
             }
@@ -91,8 +97,8 @@ class InfoDisplaySettingsViewController: FormViewController {
         let sourceIndex = sourceIndexPath.row
         let destIndex = destinationIndexPath.row
 
-        // new sort
-        if(destIndex != sourceIndex ) {
+        // Update sort order if there's a move
+        if destIndex != sourceIndex {
             self.appStateController!.infoDataSettingsChanged = true
 
             let tmpVal = UserDefaultsRepository.infoSort.value[sourceIndex]