Skip to content

Commit

Permalink
Redesign and add even more lock screen widget views
Browse files Browse the repository at this point in the history
  • Loading branch information
vinhnx committed Sep 2, 2022
1 parent 0f1d47d commit d0dcef8
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 91 deletions.
8 changes: 4 additions & 4 deletions Clendar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
A337CFB425D2F8A400FAB76A /* AppPermissions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A337CFB325D2F8A400FAB76A /* AppPermissions.swift */; };
A33B6D6A25C6EF3000E0C4FA /* MailComposer.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33B6D6925C6EF3000E0C4FA /* MailComposer.swift */; };
A33DDEAE28C1103E000E79B6 /* LockScreenWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33DDEAD28C1103E000E79B6 /* LockScreenWidget.swift */; };
A33DDEB028C112A6000E79B6 /* SmallCircularWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33DDEAF28C112A6000E79B6 /* SmallCircularWidgetView.swift */; };
A33DDEB028C112A6000E79B6 /* LockScreenWidgetView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33DDEAF28C112A6000E79B6 /* LockScreenWidgetView.swift */; };
A33F80D122467A85009CC46A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A33F80D022467A85009CC46A /* Assets.xcassets */; };
A33F80DF22467A85009CC46A /* ClendarTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33F80DE22467A85009CC46A /* ClendarTests.swift */; };
A33F80EA22467A85009CC46A /* ClendarUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A33F80E922467A85009CC46A /* ClendarUITests.swift */; };
Expand Down Expand Up @@ -367,7 +367,7 @@
A337CFB325D2F8A400FAB76A /* AppPermissions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPermissions.swift; sourceTree = "<group>"; };
A33B6D6925C6EF3000E0C4FA /* MailComposer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailComposer.swift; sourceTree = "<group>"; };
A33DDEAD28C1103E000E79B6 /* LockScreenWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenWidget.swift; sourceTree = "<group>"; };
A33DDEAF28C112A6000E79B6 /* SmallCircularWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SmallCircularWidgetView.swift; sourceTree = "<group>"; };
A33DDEAF28C112A6000E79B6 /* LockScreenWidgetView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockScreenWidgetView.swift; sourceTree = "<group>"; };
A33EE21425C6E3D900BE80F1 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/ClendarWidget.strings"; sourceTree = "<group>"; };
A33EE22025C6E46D00BE80F1 /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/ClendarWidget.strings; sourceTree = "<group>"; };
A33EE22C25C6E8B600BE80F1 /* ko */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ko; path = ko.lproj/ClendarWidget.strings; sourceTree = "<group>"; };
Expand Down Expand Up @@ -746,7 +746,7 @@
isa = PBXGroup;
children = (
A33DDEAD28C1103E000E79B6 /* LockScreenWidget.swift */,
A33DDEAF28C112A6000E79B6 /* SmallCircularWidgetView.swift */,
A33DDEAF28C112A6000E79B6 /* LockScreenWidgetView.swift */,
);
path = "Lock Screen";
sourceTree = "<group>";
Expand Down Expand Up @@ -1549,7 +1549,7 @@
A307DAA925ACBA9C00B5CE11 /* LunarDateInfoWidget.swift in Sources */,
A342117B254CF7E7008D9B8E /* DateInfoWidgetEntryView.swift in Sources */,
A38A4DC6254D751C00B35F98 /* AppInfo.swift in Sources */,
A33DDEB028C112A6000E79B6 /* SmallCircularWidgetView.swift in Sources */,
A33DDEB028C112A6000E79B6 /* LockScreenWidgetView.swift in Sources */,
A38A4DCA254D752200B35F98 /* ClendarEvent.swift in Sources */,
A38A4DAF254D743100B35F98 /* UserDefaultsWrapper.swift in Sources */,
A307DAAE25ACBAD700B5CE11 /* LunarSmallDateWidgetView.swift in Sources */,
Expand Down
14 changes: 12 additions & 2 deletions Clendar/Helper/Utils/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,17 @@ struct Constants {
case dateInfoWidget = "DateInfoWidget"
case lunarDateInfoWidget = "LunarDateInfoWidget"
case eventListWidget = "EventListWidget"
case lockScreenWidgetCounter = "LockScreenWidgetCounter"
case lockScreenWidgetNextEvent = "LockScreenWidgetNextEvent"

// TODO: is there a better way?
case lockScreenWidgetIconNextEvent = "LockScreenWidgetIconNextEvent"
case lockScreenWidgetIconCounter = "LockScreenWidgetIconCounter"
case lockScreenWidgetTranslucentAllNextEvent = "LockScreenWidgetTranslucentAllNextEvent"
case lockScreenWidgetTranslucentAllCounter = "LockScreenWidgetTranslucentAllCounter"
case lockScreenWidgetTranslucentContentNextEvent = "LockScreenWidgetTranslucentContentNextEvent"
case lockScreenWidgetTranslucentContentCounter = "LockScreenWidgetTranslucentContentCounter"
case lockScreenWidgetMinimalLeadingNextEvent = "LockScreenWidgetMinimalLeadingNextEvent"
case lockScreenWidgetMinimalTrailingNextEvent = "LockScreenWidgetMinimalTrailingNextEvent"
case lockScreenWidgetLeadingLineNextEvent = "LockScreenWidgetLeadingLineNextEvent"
case lockScreenWidgetTrailingLineNextEvent = "LockScreenWidgetTrailingLineNextEvent"
}
}
236 changes: 224 additions & 12 deletions ClendarWidget/Widget/Lock Screen/LockScreenWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,250 @@
import SwiftUI
import WidgetKit

struct LockScreenWidgetCounter: Widget {
// Icon Next
struct LockScreenWidgetIconNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetCounter.rawValue,
kind: Constants.WidgetKind.lockScreenWidgetIconNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }
.supportedFamilies(widgetFamilies)
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Icon", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(entry: entry, style: .counter)
.widgetAccentable()
return LockScreenWidgetView(
entry: entry,
generalStyle: .icon,
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

struct LockScreenWidgetNextEvent: Widget {
// Icon Counter
struct LockScreenWidgetIconCounter: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetNextEvent.rawValue,
kind: Constants.WidgetKind.lockScreenWidgetIconCounter.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }
.supportedFamilies(widgetFamilies)
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Icon", comment: ""))
.description(NSLocalizedString("With total events counter for the day", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(entry: entry, style: .nextEvent)
.widgetAccentable()
return LockScreenWidgetView(
entry: entry,
generalStyle: .icon,
contentStyle: .counter
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// TranslucentAllNextEvent
struct LockScreenWidgetTranslucentAllNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetTranslucentAllNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Blur", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .translucent(.all),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// TranslucentAllCounter
struct LockScreenWidgetTranslucentAllCounter: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetTranslucentAllCounter.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Blur", comment: ""))
.description(NSLocalizedString("With total events counter for the day", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .translucent(.all),
contentStyle: .counter
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// TranslucentContentNextEvent
struct LockScreenWidgetTranslucentContentNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetTranslucentContentNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Blur", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .translucent(.content),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// TranslucentContentCounter
struct LockScreenWidgetTranslucentContentCounter: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetTranslucentContentCounter.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Blur", comment: ""))
.description(NSLocalizedString("With total events counter for the day", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .translucent(.content),
contentStyle: .counter
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// MinimalLeadingNextEvent
struct LockScreenWidgetMinimalLeadingNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetMinimalLeadingNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Minimal", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .minimal(.leading),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// MinimalTrailingNextEvent
struct LockScreenWidgetMinimalTrailingNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetMinimalTrailingNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Minimal", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .minimal(.trailing),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// LeadingLineNextEvent
struct LockScreenWidgetLeadingLineNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetLeadingLineNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Line", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .line(.leading),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
}
}

// TrailingLineNextEvent
struct LockScreenWidgetTrailingLineNextEvent: Widget {
var body: some WidgetConfiguration {
StaticConfiguration(
kind: Constants.WidgetKind.lockScreenWidgetTrailingLineNextEvent.rawValue,
provider: DateInfoWidgetTimelineProvider()
) { entry in buildContentView(entry) }.supportedFamilies(widgetFamilies)
.configurationDisplayName(NSLocalizedString("Line", comment: ""))
.description(NSLocalizedString("With upcoming event", comment: ""))
}

private func buildContentView(_ entry: WidgetEntry) -> some View {
if #available(iOSApplicationExtension 16.0, *) {
return LockScreenWidgetView(
entry: entry,
generalStyle: .line(.trailing),
contentStyle: .nextEvent
)
.widgetAccentable()
} else {
return EmptyView()
}
Expand Down
Loading

0 comments on commit d0dcef8

Please sign in to comment.