Kaynağa Gözat

pull in latest dev and solve merge conflicts

polscm32 2 yıl önce
ebeveyn
işleme
f1bbda6a88

+ 35 - 49
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -23,7 +23,7 @@ extension Home {
         @State var timeButtons: [Buttons] = [
             Buttons(label: "2 hours", number: "2", active: false, hours: 2),
             Buttons(label: "4 hours", number: "4", active: false, hours: 4),
-            Buttons(label: "6 hours", number: "6", active: true, hours: 6),
+            Buttons(label: "6 hours", number: "6", active: false, hours: 6),
             Buttons(label: "12 hours", number: "12", active: false, hours: 12),
             Buttons(label: "24 hours", number: "24", active: false, hours: 24)
         ]
@@ -364,6 +364,31 @@ extension Home {
             .frame(maxWidth: .infinity, maxHeight: 30)
         }
 
+        var timeInterval: some View {
+            HStack {
+                ForEach(timeButtons) { button in
+                    Text(button.active ? NSLocalizedString(button.label, comment: "") : button.number).onTapGesture {
+                        state.hours = button.hours
+                        highlightButtons()
+                    }
+                    .foregroundStyle(button.active ? (colorScheme == .dark ? Color.white : Color.black).opacity(0.9) : .secondary)
+                    .frame(maxHeight: 30).padding(.horizontal, 8)
+                    .background(
+                        button.active ?
+                            // RGB(30, 60, 95)
+                            (
+                                colorScheme == .dark ? Color(red: 0.1176470588, green: 0.2352941176, blue: 0.3725490196) :
+                                    Color.white
+                            ) :
+                            Color
+                            .clear
+                    )
+                    .cornerRadius(20)
+                }
+            }
+            .font(buttonFont)
+        }
+
         var legendPanel: some View {
             ZStack {
                 HStack(alignment: .center) {
@@ -386,13 +411,6 @@ extension Home {
                         Text("ZT")
                             .font(.system(size: 12, weight: .bold)).foregroundColor(.zt)
                     }
-
-//                    Spacer()
-//
-                    ////                    loopView.padding(.top, 16)
-//
-//                    Spacer()
-
                     Group {
                         Circle().fill(Color.loopYellow).frame(width: 8, height: 8)
                         Text("COB")
@@ -419,36 +437,6 @@ extension Home {
             }
         }
 
-        var timeInterval: some View {
-            HStack {
-                ForEach(timeButtons) { button in
-                    Text(button.active ? NSLocalizedString(button.label, comment: "") : button.number).onTapGesture {
-                        let index = timeButtons.firstIndex(where: { $0.label == button.label }) ?? 0
-                        highlightButtons(index)
-                        state.hours = button.hours
-                    }
-                    .foregroundStyle(button.active ? (colorScheme == .dark ? Color.white : Color.black).opacity(0.9) : .secondary)
-                    .frame(maxHeight: 30).padding(.horizontal, 8)
-                    .background(
-                        button.active ?
-                            // RGB(30, 60, 95)
-                            (
-                                colorScheme == .dark ? Color(red: 0.1176470588, green: 0.2352941176, blue: 0.3725490196) :
-                                    Color.white
-                            ) :
-                            Color
-                            .clear
-                    )
-                    .cornerRadius(20)
-                }
-            }
-            .shadow(
-                color: Color.black.opacity(colorScheme == .dark ? 0.75 : 0.33),
-                radius: colorScheme == .dark ? 5 : 3
-            )
-            .font(buttonFont)
-        }
-
         var mainChart: some View {
             ZStack {
                 if state.animatedBackground {
@@ -512,16 +500,10 @@ extension Home {
             return (name: profileString, isOn: display)
         }
 
-        func highlightButtons(_ int: Int) {
-            var index = 0
-            repeat {
-                if index == int {
-                    timeButtons[index].active = true
-                } else {
-                    timeButtons[index].active = false
-                }
-                index += 1
-            } while index < timeButtons.count
+        func highlightButtons() {
+            for i in 0 ..< timeButtons.count {
+                timeButtons[i].active = timeButtons[i].hours == state.hours
+            }
         }
 
         @ViewBuilder private func bottomPanel(_: GeometryProxy) -> some View {
@@ -714,7 +696,11 @@ extension Home {
                 .background(colorBackground)
                 .edgesIgnoringSafeArea(.all)
             }
-            .onAppear(perform: configureView)
+            .onAppear {
+                configureView {
+                    highlightButtons()
+                }
+            }
             .navigationTitle("Home")
             .navigationBarHidden(true)
             .ignoresSafeArea(.keyboard)