Skip to content

Commit

Permalink
Improve UX/UI when offline, fix some watch face display issues
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcharger committed Apr 22, 2024
1 parent 6260467 commit a490674
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 120 deletions.
7 changes: 4 additions & 3 deletions InfiniLink/BLE/BLEUpdateHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import CoreData
import SwiftUI

struct BLEUpdatedCharacteristicHandler {
@ObservedObject var healthKitManager = HealthKitManager()
@ObservedObject var healthKitManager = HealthKitManager.shared

let bleManager = BLEManager.shared
let bleManagerVal = BLEManagerVal.shared
Expand All @@ -36,8 +36,9 @@ struct BLEUpdatedCharacteristicHandler {
}

func handleUpdates(characteristic: CBCharacteristic, peripheral: CBPeripheral) {
// TODO: Fix hang
weatherController.updateWeatherData(ignoreTimeLimits: false)
if NetworkManager.shared.getNetworkState() {
weatherController.updateWeatherData(ignoreTimeLimits: false)
}

switch characteristic.uuid {
case bleManagerVal.cbuuidList.musicControl:
Expand Down
3 changes: 3 additions & 0 deletions InfiniLink/Core/Home/DFU/DFUDownloadView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import SwiftUI
struct DownloadView: View {
@ObservedObject var downloadManager = DownloadManager.shared
@ObservedObject var dfuUpdater = DFU_Updater.shared
@ObservedObject var networkManager = NetworkManager.shared

@Environment(\.presentationMode) var presentation
@Environment(\.colorScheme) var colorScheme
Expand Down Expand Up @@ -140,6 +141,8 @@ struct DownloadView: View {
.foregroundColor(.primary)
.clipShape(Capsule())
}
.disabled(!networkManager.getNetworkState())
.opacity(!networkManager.getNetworkState() ? 0.5 : 1.0)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion InfiniLink/Core/Home/DFU/DFUWithBLE.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ struct DFUWithBLE: View {
.opacity(lockNavigation ? 0.5 : 1.0)
}
.padding()
.frame(maxWidth: .infinity, alignment: .center)
Divider()
VStack {
if externalResources && !(dfuUpdater.resourceFilename.isEmpty) {
Expand Down
70 changes: 46 additions & 24 deletions InfiniLink/Core/Home/DeviceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct DeviceView: View {
@ObservedObject var bleManagerVal = BLEManagerVal.shared
@ObservedObject var deviceInfo = BLEDeviceInfo.shared
@ObservedObject var uptimeManager = UptimeManager.shared
@ObservedObject var networkManager = NetworkManager.shared

@AppStorage("watchNotifications") var watchNotifications: Bool = true
@AppStorage("batteryNotification") var batteryNotification: Bool = false
Expand Down Expand Up @@ -137,40 +138,48 @@ struct DeviceView: View {
SheetManager.shared.sheetSelection = .weather
SheetManager.shared.showSheet = true
}) {
VStack {
HStack {
VStack(alignment: .leading) {
Text(NSLocalizedString("weather", comment: ""))
.font(.headline)
if bleManagerVal.loadingWeather {
Text(NSLocalizedString("loading", comment: "Loading..."))
HStack {
VStack(alignment: .leading) {
Text(NSLocalizedString("weather", comment: ""))
.font(.headline)
if bleManagerVal.loadingWeather {
Text(NSLocalizedString("loading", comment: "Loading..."))
} else {
if (UnitTemperature.current == .celsius && deviceData.chosenWeatherMode == "System") || deviceData.chosenWeatherMode == "Metric" {
Text(String(Int(round(bleManagerVal.weatherInformation.temperature))) + "°" + "C")
.font(.title.weight(.semibold))
} else {
if (UnitTemperature.current == .celsius && deviceData.chosenWeatherMode == "System") || deviceData.chosenWeatherMode == "Metric" {
Text(String(Int(round(bleManagerVal.weatherInformation.temperature))) + "°" + "C")
.font(.title.weight(.semibold))
} else {
Text(String(Int(round(bleManagerVal.weatherInformation.temperature * 1.8 + 32))) + "°" + "F")
.font(.title.weight(.semibold))
}
Text(String(Int(round(bleManagerVal.weatherInformation.temperature * 1.8 + 32))) + "°" + "F")
.font(.title.weight(.semibold))
}
}
.font(.title.weight(.semibold))
Spacer()
VStack {
if bleManagerVal.loadingWeather {
Image(systemName: "circle.slash")
} else {
Image(systemName: icon)
}
}
.font(.title.weight(.semibold))
Spacer()
VStack {
if bleManagerVal.loadingWeather {
Image(systemName: "circle.slash")
} else {
Image(systemName: icon)
}
.font(.title.weight(.medium))
}
.font(.title.weight(.medium))
}
.padding()
.background(LinearGradient(colors: [.blue, .yellow], startPoint: .leading, endPoint: .trailing))
.foregroundColor(.white)
.cornerRadius(15)
}
.disabled(!networkManager.getNetworkState())
.opacity(!networkManager.getNetworkState() ? 0.4 : 1.0)
.overlay {
if !networkManager.getNetworkState() {
Image(systemName: "wifi.slash")
.foregroundColor(.white)
.font(.system(size: 35).weight(.semibold))
.frame(maxWidth: .infinity, alignment: .center)
}
}
Spacer()
.frame(height: 6)
}
Expand Down Expand Up @@ -413,6 +422,20 @@ struct CustomScrollView<Content: View>: View {
.padding(22)
.frame(width: geometry.size.width / 1.65, height: geometry.size.width / 1.65, alignment: .center)
.clipped(antialiased: true)
if !NetworkManager.shared.getNetworkState() {
HStack(spacing: 6) {
Image(systemName: "wifi.slash")
.font(.system(size: 17).weight(.medium))
Text(NSLocalizedString("youre_offline", comment: "You're offline"))
.font(.system(size: 16))
}
.padding(13)
.foregroundColor(.gray)
.background(Material.regular)
.clipShape(Capsule())
.frame(height: geometry.size.width / 1.40, alignment: .bottom)
.padding(.bottom, 12)
}
}
content
}
Expand All @@ -426,7 +449,6 @@ struct CustomScrollView<Content: View>: View {
if bleManager.blefsTransfer != nil {
BLEFSHandler.shared.readSettings { settings in
self.settings = settings
print(settings)
self.stepCountGoal = Int(settings.stepsGoal)
self.bleManagerVal.watchFace = Int(settings.watchFace)
self.bleManagerVal.pineTimeStyleData = settings.pineTimeStyle
Expand Down
12 changes: 6 additions & 6 deletions InfiniLink/Core/Home/WatchFace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ struct AnalogWF: View {
var body: some View {
ZStack {
let hour = Calendar.current.component(.hour, from: Date())
let hour12 = Double(hour >= 12 ? hour - 12 : hour)
let hour12 = Double(hour % 12 == 0 ? 12 : hour % 12)
let minute = Double(Calendar.current.component(.minute, from: Date()))
Image("AnalogFace")
.resizable()
Expand Down Expand Up @@ -306,13 +306,13 @@ struct DigitalWF: View {
if hour24 {
hourString = String(format: "%d", currentHour)
} else {
let hour12 = currentHour > 12 ? currentHour - 12 : currentHour
let hour12 = currentHour % 12 == 0 ? 12 : currentHour % 12
hourString = "\(hour12)"
}
let minuteString = String(format: "%02d", Calendar.current.component(.minute, from: Date()))

return "\(hourString):\(minuteString)"
}(), font: .custom("JetBrainsMono-ExtraBold", size: geometry.size.width * 0.33), lineSpacing: 0)
}(), font: .custom("7-Segment", size: geometry.size.width * 0.48), lineSpacing: 0)
.foregroundColor(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 1.9)
Expand Down Expand Up @@ -533,7 +533,7 @@ struct InfineatWF: View {
}
if Calendar.current.component(.hour, from: Date()) >= 12 && !hour24 {
let currentHour = Calendar.current.component(.hour, from: Date())
let hour12 = currentHour > 12 ? currentHour - 12 : (currentHour == 0 ? 12 : currentHour) // Adjust 12 PM to 12
let hour12 = currentHour % 12 == 0 ? 12 : currentHour % 12
let hourString = String(format: "%02d", hour12)
let minuteString = String(format: "%02d", Calendar.current.component(.minute, from: Date()))

Expand Down Expand Up @@ -671,7 +671,7 @@ struct TerminalWF: View {
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 6.5)
if !hour24 {
Group {
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", (currentHour % 12 == 0) ? 12 : currentHour % 12)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond)) \(currentHour >= 12 ? "PM" : "AM")").foregroundColor(.green)
Text("[TIME]").foregroundColor(.white) + Text("\(String(format: "%02d", currentHour % 12 == 0 ? 12 : currentHour % 12)):\(String(format: "%02d", currentMinute)):\(String(format: "%02d", currentSecond)) \(currentHour >= 12 ? "PM" : "AM")").foregroundColor(.green)
}
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
Expand Down Expand Up @@ -799,7 +799,7 @@ struct CasioWF: View {
if hour24 {
hourString = String(format: "%d", currentHour)
} else {
let hour12 = currentHour > 12 ? currentHour - 12 : currentHour
let hour12 = currentHour % 12 == 0 ? 12 : currentHour
hourString = "\(hour12)"
}
let minuteString = String(format: "%02d", Calendar.current.component(.minute, from: Date()))
Expand Down
Loading

0 comments on commit a490674

Please sign in to comment.