mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Fix battery level and expanded view for live activity
This commit is contained in:
parent
62d02aefc2
commit
9fc6609cec
2 changed files with 76 additions and 30 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue