Skip to content

Commit

Permalink
Minor bug fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
liamcharger committed Mar 23, 2024
1 parent 7a94454 commit 581af98
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 80 deletions.
22 changes: 12 additions & 10 deletions InfiniLink/Core/Home/DeviceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,20 @@ struct DeviceView: View {
})
Spacer()
.frame(height: 6)
NavigationLink(destination: FileSystemView()) {
HStack {
Text(NSLocalizedString("file_system", comment: ""))
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.gray)
if bleManager.blefsTransfer != nil {
NavigationLink(destination: FileSystemView()) {
HStack {
Text(NSLocalizedString("file_system", comment: ""))
.frame(maxWidth: .infinity, alignment: .leading)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.gray)
}
.modifier(RowModifier(style: .capsule))
}
.modifier(RowModifier(style: .capsule))
Spacer()
.frame(height: 6)
}
Spacer()
.frame(height: 6)
VStack {
if bleManager.isConnectedToPinetime {
Toggle(isOn: $bleManager.autoconnectToDevice) {
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 @@ -662,7 +662,7 @@ struct TerminalWF: View {
.foregroundColor(.white)
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 6.9)
.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)
Expand Down Expand Up @@ -713,7 +713,7 @@ struct TerminalWF: View {
.foregroundColor(.white)
.font(.custom("JetBrainsMono-Bold", size: geometry.size.width * 0.085))
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading)
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 1.27)
.position(x: geometry.size.width / 2.0, y: geometry.size.height / 1.28)
}
.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
}
Expand Down Expand Up @@ -789,13 +789,13 @@ struct CasioWF: View {
CustomTextView(text: {
let currentHour = Calendar.current.component(.hour, from: Date())
var hourString = ""

if hour24 {
hourString = String(format: "%02d", currentHour)
hourString = String(format: "%d", currentHour)
} else {
let hour12 = currentHour > 12 ? currentHour - 12 : currentHour
hourString = String(format: "%02d", hour12)
hourString = "\(hour12)"
}

let minuteString = String(format: "%02d", Calendar.current.component(.minute, from: Date()))

return "\(hourString):\(minuteString)"
Expand Down Expand Up @@ -861,7 +861,7 @@ enum InfineatItem {
#Preview {
NavigationView {
GeometryReader { geometry in
WatchFaceView(watchface: .constant(4))
WatchFaceView(watchface: .constant(3))
.padding(22)
.frame(width: geometry.size.width / 1.65, height: geometry.size.width / 1.65, alignment: .center)
.clipped(antialiased: true)
Expand Down
119 changes: 56 additions & 63 deletions InfiniLink/Core/Weather/Views/WeatherDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import SwiftUI
struct WeatherDetailView: View {
@ObservedObject var bleManagerVal = BLEManagerVal.shared

var celsius: Bool {
(UnitTemperature.current == .celsius && deviceData.chosenWeatherMode == "System") || deviceData.chosenWeatherMode == "Metric"
}

func getIcon(icon: Int) -> String {
switch icon {
case 0:
Expand All @@ -30,9 +34,12 @@ struct WeatherDetailView: View {
return "slash.circle"
}
}

var celsius: Bool {
(UnitTemperature.current == .celsius && deviceData.chosenWeatherMode == "System") || deviceData.chosenWeatherMode == "Metric"
func temp(_ temp: Double) -> String {
if self.celsius {
return String(Int(round(temp))) + "°" + "C"
} else {
return String(Int(round(temp * 1.8 + 32))) + "°" + "F"
}
}

let deviceData: DeviceData = DeviceData()
Expand All @@ -45,7 +52,7 @@ struct WeatherDetailView: View {
}

var body: some View {
VStack {
VStack(spacing: 0) {
HStack {
Text(NSLocalizedString("weather", comment: ""))
.font(.title.bold())
Expand All @@ -61,72 +68,56 @@ struct WeatherDetailView: View {
ProgressView(NSLocalizedString("loading_weather", comment: ""))
Spacer()
} else {
VStack(spacing: 8) {
Image(systemName: getIcon(icon: bleManagerVal.weatherInformation.icon))
.font(.system(size: 45).weight(.medium))
HStack {
Group {
if celsius {
Text(String(Int(round(bleManagerVal.weatherInformation.minTemperature))) + "°" + "C")
} else {
Text(String(Int(round(bleManagerVal.weatherInformation.minTemperature * 1.8 + 32))) + "°" + "F")
}
}
.foregroundColor(.gray)
Group {
if celsius {
Text(String(Int(round(bleManagerVal.weatherInformation.temperature))) + "°" + "C")
} else {
Text(String(Int(round(bleManagerVal.weatherInformation.temperature * 1.8 + 32))) + "°" + "F")
}
ScrollView {
VStack(spacing: 8) {
Image(systemName: getIcon(icon: bleManagerVal.weatherInformation.icon))
.font(.system(size: 45).weight(.medium))
HStack {
Text(temp(bleManagerVal.weatherInformation.minTemperature))
.foregroundColor(.gray)
Text(temp(bleManagerVal.weatherInformation.temperature))
.font(.system(size: 35).weight(.semibold))
Text(temp(bleManagerVal.weatherInformation.maxTemperature))
.foregroundColor(.gray)
}
.font(.system(size: 35).weight(.semibold))
Group {
if celsius {
Text(String(Int(round(bleManagerVal.weatherInformation.maxTemperature))) + "°" + "C")
} else {
Text(String(Int(round(bleManagerVal.weatherInformation.maxTemperature * 1.8 + 32))) + "°" + "F")
}
}
.foregroundColor(.gray)
Text(bleManagerVal.weatherInformation.shortDescription)
.foregroundColor(.gray)
.font(.body.weight(.semibold))
}
Text(bleManagerVal.weatherInformation.shortDescription)
.foregroundColor(.gray)
.font(.body.weight(.semibold))
}
.padding()
Divider()
VStack {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 10) {
ForEach(bleManagerVal.weatherForecastDays, id: \.name) { day in
VStack(spacing: 6) {
Text(day.name)
.foregroundColor(.gray)
.font(.system(size: 14).weight(.medium))
Image(systemName: getIcon(icon: Int(day.icon)))
.imageScale(.large)
.font(.system(size: 18).weight(.medium))
VStack {
if celsius {
Text(String(Int(round(day.maxTemperature))) + "°")
Text(String(Int(round(day.minTemperature))) + "°")
} else {
Text(String(Int(round(day.maxTemperature * 1.8 + 32))) + "°")
Text(String(Int(round(day.minTemperature * 1.8 + 32))) + "°")
}
}
.padding()
VStack(spacing: 10) {
ForEach(bleManagerVal.weatherForecastDays, id: \.name) { day in
HStack(spacing: 6) {
Text(day.name)
.font(.body.weight(.medium))
Image(systemName: getIcon(icon: Int(day.icon)))
.imageScale(.large)
.font(.body.weight(.medium))
Spacer()
HStack(spacing: 6) {
Text(temp(day.maxTemperature))
.foregroundColor(.lightGray)
Rectangle()
.frame(height: 3)
.frame(width: {
let temperatureRange = day.maxTemperature - day.minTemperature
let relativeWidth = CGFloat(temperatureRange) / 40.0 * 60
return relativeWidth
}())
.cornerRadius(30)
.background(Material.thin)
Text(temp(day.minTemperature))
.foregroundColor(.lightGray)
}
.padding(12)
.frame(width: 95)
.background(Color.gray.opacity(0.3))
.cornerRadius(12)
}
.frame(maxWidth: .infinity)
.padding()
.background(Color.gray.opacity(0.3))
.cornerRadius(15)
}
.padding()
}
.padding()
}
Spacer()
}
}
}
Expand All @@ -142,5 +133,7 @@ struct WeatherDetailView: View {
BLEManagerVal.shared.weatherInformation.maxTemperature = 3
BLEManagerVal.shared.weatherInformation.maxTemperature = 5
BLEManagerVal.shared.weatherForecastDays.append(WeatherForecastDay(maxTemperature: 3, minTemperature: 2, icon: 2, name: "Sat"))
BLEManagerVal.shared.weatherForecastDays.append(WeatherForecastDay(maxTemperature: 1.6, minTemperature: 1.3, icon: 6, name: "Sun"))
BLEManagerVal.shared.weatherForecastDays.append(WeatherForecastDay(maxTemperature: 2.6, minTemperature: 1.9, icon: 3, name: "Mon"))
}
}
9 changes: 8 additions & 1 deletion InfiniLink/Core/Weather/WeatherController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ class WeatherController: NSObject, ObservableObject, CLLocationManagerDelegate {
let currentDate = Date()

for idx in 1...json["forecast"]["forecastday"][0].count {
bleManagerVal.weatherInformation.forecastIcon = []
bleManagerVal.weatherInformation.forecastMaxTemperature = []
bleManagerVal.weatherInformation.forecastMinTemperature = []
bleManagerVal.weatherForecastDays = []

bleManagerVal.weatherInformation.forecastIcon.append(getIcon_WAPI(description: json["forecast"]["forecastday"][idx]["day"]["condition"]["text"].stringValue))
bleManagerVal.weatherInformation.forecastMaxTemperature.append(json["forecast"]["forecastday"][idx]["day"]["maxtemp_c"].doubleValue)
bleManagerVal.weatherInformation.forecastMinTemperature.append(json["forecast"]["forecastday"][idx]["day"]["mintemp_c"].doubleValue)
Expand Down Expand Up @@ -340,7 +345,7 @@ class WeatherController: NSObject, ObservableObject, CLLocationManagerDelegate {
return 0
case "A Few Clouds", "A Few Clouds with Haze", "A Few Clouds and Breezy", "A Few Clouds and Windy", "Partly Cloudy", "Partly Cloudy with Haze", "Partly Cloudy and Breezy", "Partly Cloudy and Windy":
return 1
case "Cloudy", "Mostly Cloudy", "Mostly Cloudy with Haze", "Mostly Cloudy and Breezy", "Mostly Cloudy and Wind":
case "Cloudy", "Mostly Cloudy", "Mostly Cloudy with Haze", "Mostly Cloudy and Breezy", "Mostly Cloudy and Wind", "Cloudy and Windy":
return 2
case "Overcast", "Overcast with Haze", "Overcast and Breezy", "Overcast and Windy", "Hurricane Watch", "Funnel Cloud", "Funnel Cloud in Vicinity", "Tornado/Water Spout", "Tornado":
return 3
Expand Down Expand Up @@ -389,8 +394,10 @@ class WeatherController: NSObject, ObservableObject, CLLocationManagerDelegate {
bleManagerVal.weatherInformation.maxTemperature = json["properties"]["maxTemperature"]["values"][0]["value"].doubleValue
bleManagerVal.weatherInformation.minTemperature = json["properties"]["minTemperature"]["values"][0]["value"].doubleValue

bleManagerVal.weatherInformation.forecastIcon = []
bleManagerVal.weatherInformation.forecastMaxTemperature = []
bleManagerVal.weatherInformation.forecastMinTemperature = []
bleManagerVal.weatherForecastDays = []

let currentDate = Date()
let calendar = Calendar.current
Expand Down

0 comments on commit 581af98

Please sign in to comment.