diff --git a/Widgets/BatteryLevel.swift b/Widgets/BatteryLevel.swift index f20d03aa..c9bfdccd 100644 --- a/Widgets/BatteryLevel.swift +++ b/Widgets/BatteryLevel.swift @@ -37,8 +37,15 @@ struct BatteryIcon: View { .font(font) .foregroundColor(color) .symbolRenderingMode(.hierarchical) - } else if batteryLevel! < 15 && batteryLevel! >= 0 { + } else if batteryLevel! < 15 && batteryLevel! > 0 { + Image(systemName: "battery.0") + .font(font) + .foregroundColor(color) + .symbolRenderingMode(.hierarchical) + + } else if batteryLevel! == 0 { + Image(systemName: "battery.0") .font(font) .foregroundColor(.red) @@ -50,18 +57,13 @@ struct BatteryIcon: View { .foregroundColor(color) .symbolRenderingMode(.hierarchical) } - else { - - Image(systemName: "battery.0") - .font(font) - .foregroundColor(color) - .symbolRenderingMode(.hierarchical) - } } } struct BatteryIcon_Previews: PreviewProvider { static var previews: some View { + BatteryIcon(batteryLevel: 111, font: .title2, color: Color.accentColor) + .previewLayout(.fixed(width: 75, height: 75)) BatteryIcon(batteryLevel: 100, font: .title2, color: Color.accentColor) .previewLayout(.fixed(width: 75, height: 75)) BatteryIcon(batteryLevel: 99, font: .title2, color: Color.accentColor) diff --git a/Widgets/WidgetsLiveActivity.swift b/Widgets/WidgetsLiveActivity.swift index 92f246fa..b6f1adfd 100644 --- a/Widgets/WidgetsLiveActivity.swift +++ b/Widgets/WidgetsLiveActivity.swift @@ -41,10 +41,21 @@ struct WidgetsLiveActivity: Widget { DynamicIslandExpandedRegion(.center) { VStack(alignment: .center, spacing: 0) { BatteryIcon(batteryLevel: Int32(context.state.batteryLevel), font: .title, color: .accentColor) - Text(String(context.state.batteryLevel) + "%") - .font(.title3) - .foregroundColor(.gray) - .fixedSize() + if context.state.batteryLevel == 0 { + Text("< 1%") + .font(.title3) + .foregroundColor(.gray) + .fixedSize() + } else if context.state.batteryLevel < 101 { + Text(String(context.state.batteryLevel) + "%") + .font(.title3) + .foregroundColor(.gray) + .fixedSize() + } else { + Text("Plugged In") + .font(.title3) + .foregroundColor(.gray) + } } } DynamicIslandExpandedRegion(.trailing, priority: 1) { @@ -135,7 +146,31 @@ struct LiveActivityView: View { Spacer() NodeInfoView(nodeName: nodeName, timerRange: timerRange, channelUtilization: channelUtilization, airtime: airtime, batteryLevel: batteryLevel) Spacer() - TimerView(timerRange: timerRange) + VStack { + BatteryIcon(batteryLevel: Int32(batteryLevel), font: .title, color: .secondary) + if batteryLevel == 0 { + Text("< 1%") + .font(.headline) + .fontWeight(.medium) + .foregroundStyle(.secondary) + .opacity(isLuminanceReduced ? 0.8 : 1.0) + .fixedSize() + } else if batteryLevel < 101 { + Text(String(batteryLevel) + "%") + .font(.headline) + .fontWeight(.medium) + .foregroundStyle(.secondary) + .opacity(isLuminanceReduced ? 0.8 : 1.0) + .fixedSize() + } else { + Text("Plugged In") + .font(.headline) + .fontWeight(.medium) + .foregroundStyle(.secondary) + .opacity(isLuminanceReduced ? 0.8 : 1.0) + .fixedSize() + } + } } .tint(.primary) .padding([.leading, .top, .bottom]) @@ -172,27 +207,36 @@ struct NodeInfoView: View { .foregroundStyle(.secondary) .opacity(isLuminanceReduced ? 0.8 : 1.0) .fixedSize() - if batteryLevel < 101 { - Text("Battery Level: \(batteryLevel > 0 ? String(batteryLevel) : "< 1")%") - .font(.headline) - .fontWeight(.medium) - .foregroundStyle(.secondary) - .opacity(isLuminanceReduced ? 0.8 : 1.0) - .fixedSize() - } else { - Text("Plugged In") - .font(.headline) - .fontWeight(.medium) - .foregroundStyle(.secondary) - .opacity(isLuminanceReduced ? 0.8 : 1.0) - .fixedSize() - } - Text(Date().formatted()) - .font(.headline) + let now = Date() + Text("Last Heard: \(now.formatted())") + .font(.caption) .fontWeight(.medium) .foregroundStyle(.secondary) .opacity(isLuminanceReduced ? 0.8 : 1.0) .fixedSize() + HStack { + + if timerRange.upperBound >= now { + Text("Next Update:") + .font(.caption) + .fontWeight(.medium) + .foregroundStyle(.secondary) + .opacity(isLuminanceReduced ? 0.8 : 1.0) + .fixedSize() + Text(timerInterval: timerRange, countsDown: true) + .monospacedDigit() + .multilineTextAlignment(.leading) + .font(.caption) + .fontWeight(.medium) + .foregroundStyle(.tint) + } else { + Text("Not Connected") + .multilineTextAlignment(.leading) + .font(.callout) + .fontWeight(.semibold) + .foregroundStyle(.tint) + } + } } } }