Procházet zdrojové kódy

fix padding in lockscreenwidget
fix incorrect timelabels in main chart
fix xGridLines that disappeared after last dev merge

polscm32 před 2 roky
rodič
revize
ecee9dab0a

+ 29 - 34
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -345,14 +345,16 @@ struct MainChartView: View {
         return ZStack {
             Path { path in
                 for hour in 0 ..< hours + hours {
-                    if screenHours < 12 || hour % 2 == 0 {
-                        // only show every second line if screenHours is too big
-                        let x = firstHourPosition(viewWidth: fullSize.width) +
+                    if screenHours >= 12 && hour % 2 == 1 {
+                        continue
+                    }
+                    let x = (
+                        firstHourPosition(viewWidth: fullSize.width) +
                             oneSecondStep(viewWidth: fullSize.width) *
                             CGFloat(hour) * CGFloat(1.hours.timeInterval)
-                        path.move(to: CGPoint(x: x, y: 0))
-                        path.addLine(to: CGPoint(x: x, y: fullSize.height - 20))
-                    }
+                    ) * zoomScale
+                    path.move(to: CGPoint(x: x, y: 0))
+                    path.addLine(to: CGPoint(x: x, y: fullSize.height - 20))
                 }
             }
             .stroke(useColour, lineWidth: 0.15)
@@ -369,41 +371,34 @@ struct MainChartView: View {
         }
     }
 
-    // MARK: TO DO: CHANGE TIME LABELS TO ONLY DISPLAY EVERY SECOND LABEL WHEN SCREENHOURS IS TOO BIG
-
-//    private func timeLabelsView(fullSize: CGSize) -> some View {
-//        let format = screenHours > 6 ? date24Formatter : dateFormatter
-//        return ZStack {
-//            // X time labels
-//            ForEach(0 ..< hours + hours) { hour in
-//                Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
-//                    .font(.caption)
-//                    .position(
-//                        x: firstHourPosition(viewWidth: fullSize.width) +
-//                            oneSecondStep(viewWidth: fullSize.width) *
-//                            CGFloat(hour) * CGFloat(1.hours.timeInterval),
-//                        y: 10.0
-//                    )
-//                    .foregroundColor(.secondary)
-//            }
-//        }.frame(maxHeight: 20)
-//    }
-
     private func timeLabelsView(fullSize: CGSize) -> some View {
         let format = screenHours > 6 ? date24Formatter : dateFormatter
         return ZStack {
             // X time labels
-            ForEach(0 ..< hours + hours) { hour in
-                if screenHours >= 12 && hour % 2 == 1 {
-                    // only show every second time label if screenHours is too big
-                    EmptyView()
-                } else {
+            ForEach(0 ..< hours + hours, id: \.self) { hour in
+                // show every other label
+                if screenHours >= 12 && hour % 2 == 0 {
+                    Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
+                        .font(.caption)
+                        .position(
+                            x: (
+                                firstHourPosition(viewWidth: fullSize.width) +
+                                    oneSecondStep(viewWidth: fullSize.width) *
+                                    CGFloat(hour) * CGFloat(1.hours.timeInterval)
+                            ) * zoomScale,
+                            y: 10.0
+                        )
+                        .foregroundColor(.secondary)
+                } else if screenHours < 12 {
+                    // show every label
                     Text(format.string(from: firstHourDate().addingTimeInterval(hour.hours.timeInterval)))
                         .font(.caption)
                         .position(
-                            x: firstHourPosition(viewWidth: fullSize.width) +
-                                oneSecondStep(viewWidth: fullSize.width) *
-                                CGFloat(hour) * CGFloat(1.hours.timeInterval),
+                            x: (
+                                firstHourPosition(viewWidth: fullSize.width) +
+                                    oneSecondStep(viewWidth: fullSize.width) *
+                                    CGFloat(hour) * CGFloat(1.hours.timeInterval)
+                            ) * zoomScale,
                             y: 10.0
                         )
                         .foregroundColor(.secondary)

+ 1 - 1
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: false, hours: 6),
+            Buttons(label: "6 hours", number: "6", active: true, hours: 6),
             Buttons(label: "12 hours", number: "12", active: false, hours: 12),
             Buttons(label: "24 hours", number: "24", active: false, hours: 24)
         ]

+ 9 - 11
LiveActivity/LiveActivity.swift

@@ -20,7 +20,7 @@ struct LiveActivity: Widget {
     }
 
     func updatedLabel(context: ActivityViewContext<LiveActivityAttributes>) -> Text {
-        Text(dateFormatter.string(from: context.state.date))
+        Text("Updated: \(dateFormatter.string(from: context.state.date))")
     }
 
     func bgLabel(context: ActivityViewContext<LiveActivityAttributes>) -> Text {
@@ -77,7 +77,7 @@ struct LiveActivity: Widget {
                 ForEach(context.state.chart.indices, id: \.self) { index in
                     LineMark(
                         x: .value("Time", context.state.chartDate[index] ?? Date()),
-                        y: .value("Value", context.state.chart[index] ?? 0)
+                        y: .value("Value", context.state.chart[index])
                     ).foregroundStyle(Color.green.gradient).symbolSize(12)
                 }
             }.chartPlotStyle { plotContent in
@@ -86,9 +86,6 @@ struct LiveActivity: Widget {
             .chartYAxis {
                 AxisMarks(position: .leading)
             }
-            .chartXAxis {
-                AxisMarks(position: .automatic)
-            }
         }
     }
 
@@ -98,9 +95,9 @@ struct LiveActivity: Widget {
 
             HStack(spacing: 2) {
                 VStack {
-                    chart(context: context).frame(width: UIScreen.main.bounds.width / 1.7)
+                    chart(context: context).frame(width: UIScreen.main.bounds.width / 1.8)
                 }.padding(.vertical, 5).padding(.horizontal, 15)
-                Divider()
+                Divider().foregroundStyle(Color.white)
                 VStack {
                     ZStack {
                         bobble(context: context)
@@ -111,8 +108,8 @@ struct LiveActivity: Widget {
                             bgLabel(context: context).font(.title2).imageScale(.small)
                             changeLabel(context: context).font(.callout)
                         }
-                    }.padding(.trailing, 5).padding(.top, 5)
-                    updatedLabel(context: context).font(.caption).padding(.bottom)
+                    }.padding(.trailing, 10).padding(.top, 5)
+                    updatedLabel(context: context).font(.caption).padding(.bottom).padding(.trailing, 5)
                 }
             }
             .privacySensitive()
@@ -136,9 +133,10 @@ struct LiveActivity: Widget {
                     changeLabel(context: context).font(.title).padding(.trailing, 5)
                 }
                 DynamicIslandExpandedRegion(.bottom) {
+                    chart(context: context)
+                }
+                DynamicIslandExpandedRegion(.center) {
                     updatedLabel(context: context).font(.caption).foregroundStyle(Color.secondary)
-                        .padding(.bottom, 5)
-                    chart(context: context).frame(height: 70)
                 }
             } compactLeading: {
                 HStack(spacing: 1) {

+ 7 - 7
LiveActivity/WidgetBobble.swift

@@ -10,16 +10,16 @@ struct WidgetBobble: View {
         HStack(alignment: .center) {
             ZStack {
                 Group {
-                    CircleShape(gradient: gradient)
-                    TriangleShape(color: color)
+                    CircleShapeWidget(gradient: gradient)
+                    TriangleShapeWidget(color: color)
                 }
-                CircleShape(gradient: gradient)
+                CircleShapeWidget(gradient: gradient)
             }
         }
     }
 }
 
-struct CircleShape: View {
+struct CircleShapeWidget: View {
     @Environment(\.colorScheme) var colorScheme
 
     let gradient: AngularGradient
@@ -38,11 +38,11 @@ struct CircleShape: View {
     }
 }
 
-struct TriangleShape: View {
+struct TriangleShapeWidget: View {
     let color: Color
 
     var body: some View {
-        Triangle()
+        TriangleWidget()
             .fill(color)
             .frame(width: 35, height: 35)
             .rotationEffect(.degrees(90))
@@ -50,7 +50,7 @@ struct TriangleShape: View {
     }
 }
 
-struct Triangle: Shape {
+struct TriangleWidget: Shape {
     func path(in rect: CGRect) -> Path {
         var path = Path()