Skip to content

Commit

Permalink
Overview widget updates
Browse files Browse the repository at this point in the history
  • Loading branch information
daneden committed Sep 23, 2023
1 parent 5c033ea commit 061ca3a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 43 deletions.
6 changes: 6 additions & 0 deletions Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"sourceLanguage" : "en",
"strings" : {
"-" : {
"comment" : "Less daylight middle of sentence"
},
"—" : {
"localizations" : {
"it" : {
Expand Down Expand Up @@ -284,6 +287,9 @@
}
}
},
"+" : {
"comment" : "More daylight middle of sentence"
},
"a specific time" : {
"localizations" : {
"it" : {
Expand Down
10 changes: 10 additions & 0 deletions Solstice/Extensions/Solar++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ extension Solar {
return Solar(for: yesterdayDate, coordinate: coordinate)!
}

var compactDifferenceString: LocalizedStringKey {
let comparator = date.isToday ? yesterday : Solar(coordinate: self.coordinate)!
let difference = daylightDuration - comparator.daylightDuration
let differenceString = Duration.seconds(abs(difference)).formatted(.units(maximumUnitCount: 2))

let moreOrLess = difference >= 0 ? NSLocalizedString("+", comment: "More daylight middle of sentence") : NSLocalizedString("-", comment: "Less daylight middle of sentence")

return LocalizedStringKey("\(moreOrLess)\(differenceString)")
}

var differenceString: LocalizedStringKey {
let formatter = DateFormatter()
formatter.doesRelativeDateFormatting = true
Expand Down
81 changes: 38 additions & 43 deletions Widget/Overview Widget/OverviewWidgetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,26 @@ struct OverviewWidgetView: View {
ZStack(alignment: .bottomLeading) {
#if !os(watchOS)
GeometryReader { geom in
if family != .systemSmall {
DaylightChart(solar: solar,
timeZone: location.timeZone,
eventTypes: [.sunrise, .sunset],
includesSummaryTitle: false,
hideXAxis: true,
markSize: 5)
.padding(.horizontal, -20)
.frame(maxHeight: 200)
if family == .systemMedium {
VStack {
Spacer()
Rectangle()
.fill(.clear)
.background(.background)
.frame(width: geom.size.width, height: min(geom.size.height / 1.25, 100))
.padding(.leading, geom.size.width * -0.5)
.blur(radius: 20)
}
DaylightChart(
solar: solar,
timeZone: location.timeZone,
eventTypes: [.sunrise, .sunset],
includesSummaryTitle: false,
hideXAxis: true,
markSize: family == .systemSmall ? 3 : 5
)
.padding(.horizontal, -20)
.frame(maxHeight: 200)

if family == .systemMedium || family == .systemSmall {
VStack {
Spacer()
Rectangle()
.fill(.clear)
.background(.background)
.frame(width: geom.size.width, height: min(geom.size.height / 1.25, 100))
.padding(.leading, geom.size.width * -0.5)
.blur(radius: 20)
}
}
}
Expand Down Expand Up @@ -123,32 +123,27 @@ struct OverviewWidgetView: View {
Group {
if let begins = relevantSolar?.safeSunrise.withTimeZoneAdjustment(for: location.timeZone),
let ends = relevantSolar?.safeSunset.withTimeZoneAdjustment(for: location.timeZone) {
if family == .systemSmall {
Text(begins...ends)
if let differenceString = relevantSolar?.compactDifferenceString {
Text(differenceString)
.lineLimit(4)
.font(.footnote)
.foregroundStyle(.secondary)
} else {
if let differenceString = relevantSolar?.differenceString {
Text(differenceString)
.lineLimit(4)
.font(.footnote)
.foregroundStyle(.secondary)
.fixedSize(horizontal: false, vertical: true)
.fixedSize(horizontal: false, vertical: true)
}

HStack {
Label {
Text(begins, style: .time)
} icon: {
Image(systemName: "sunrise.fill")
}

HStack {
Label {
Text(begins, style: .time)
} icon: {
Image(systemName: "sunrise.fill")
}

Spacer()

Label {
Text(ends, style: .time)
} icon: {
Image(systemName: "sunset.fill")
}
Spacer()

Label {
Text(ends, style: .time)
} icon: {
Image(systemName: "sunset.fill")
}
}
}
Expand Down

0 comments on commit 061ca3a

Please sign in to comment.