Skip to content

Commit

Permalink
Merge pull request #149 from sparcs-kaist/feat@ios-standby
Browse files Browse the repository at this point in the history
Resolve #148, Add supports StandBy for iOS 17
  • Loading branch information
sboh1214 authored Sep 19, 2023
2 parents e040abd + aae315e commit 72accc6
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 34 deletions.
2 changes: 1 addition & 1 deletion ios/OTLWidgets/LocationInlineAccessory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct LocationInlineAccessoryEntryView : View {
case .accessoryInline:
HStack {
Image(systemName: "tablecells")
if (entry.timetableData != nil) {
if (entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) {
Text("\(getPlace(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date)) \(getName(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))")
} else {
Text(LocalizedStringKey("nextclasswidget.nodata"))
Expand Down
9 changes: 5 additions & 4 deletions ios/OTLWidgets/NextClassAccessory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct NextClassAccessoryEntryView : View {
case .accessoryCircular:
ZStack {
AccessoryWidgetBackground()
if (entry.timetableData != nil) {
if (entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) {
VStack {
Image(systemName: "tablecells")
.font(.caption2)
Expand All @@ -38,8 +38,9 @@ struct NextClassAccessoryEntryView : View {
.font(.caption2)
.widgetAccentable()
Text(LocalizedStringKey("nextclasswidget.nodata"))
.font(.system(size: 15))
.font(.system(size: 10))
.fontWeight(.medium)
.padding(.top, 2)
Text("")
.font(.system(size: 9))
.fontWeight(.medium)
Expand All @@ -48,7 +49,7 @@ struct NextClassAccessoryEntryView : View {
}
case .accessoryRectangular:
HStack {
if (entry.timetableData != nil) {
if (entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) {
VStack(alignment: .leading) {
HStack(alignment: .center, spacing: 4) {
Circle()
Expand All @@ -72,7 +73,7 @@ struct NextClassAccessoryEntryView : View {
.font(.headline)
}.offset(y: 7)
.widgetAccentable()
Text(LocalizedStringKey("nextclasswidget.nodata"))
Text("")
.font(.headline)
.widgetAccentable()
Text("")
Expand Down
62 changes: 43 additions & 19 deletions ios/OTLWidgets/NextClassWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import Intents

struct NextClassWidgetEntryView : View {
@Environment(\.colorScheme) var colorScheme
@Environment(\.showsWidgetContainerBackground) var showsWidgetBackground
@Environment(\.widgetRenderingMode) var renderingMode

var entry: Provider.Entry

Expand All @@ -20,14 +22,14 @@ struct NextClassWidgetEntryView : View {
}

var body: some View {
if (entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) {
if #available(iOSApplicationExtension 17.0, *) {
ZStack(alignment: .leading) {
widgetBackground
VStack(alignment: .leading) {
Text(LocalizedStringKey("nextclasswidget.nextlecture"))
.font(.custom("NotoSansKR-Bold", size: 12))
.foregroundColor(Color(red: 229.0/255, green: 76.0/255, blue: 100.0/255))
Text(getTimeLeft(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
.font(.custom("NotoSansKR-Bold", size: showsWidgetBackground ? 12 : 16))
.foregroundColor((renderingMode == .vibrant) ? Color.white : Color(red: 229.0/255, green: 76.0/255, blue: 100.0/255))
.frame(maxWidth: .infinity, alignment: .leading)
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getTimeLeft(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Bold", size: 20))
.offset(y: -2)
.minimumScaleFactor(0.5)
Expand All @@ -37,22 +39,45 @@ struct NextClassWidgetEntryView : View {

HStack {
Circle()
.fill(getColour(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
.fill((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getColour(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : getColourForCourse(course: 1))
.frame(width: 12, height: 12)
Text(getName(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
.font(.custom("NotoSansKR-Bold", size: 16))
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getName(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Bold", size: showsWidgetBackground ? 16 : 20))
.minimumScaleFactor(0.5)
.lineLimit(2)
}.offset(y: 8)
Text(getPlace(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
}.offset(y: 6)
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getPlace(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Regular", size: 12))
.minimumScaleFactor(0.5)
.lineLimit(1)
Text(getProfessor(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getProfessor(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Medium", size: 12))
.minimumScaleFactor(0.5)
.foregroundColor(.gray)
}.padding()
}.padding(.horizontal, showsWidgetBackground ? 0 : 3)
if (entry.timetableData == nil) {
ZStack {
if showsWidgetBackground {
Color.clear
.background(.ultraThinMaterial)
} else {
Color.black
}
VStack {
Image("lock")
.resizable()
.frame(width: 44, height: 44)
Text(LocalizedStringKey("widget.login"))
.font(.custom("NotoSansKR-Bold", size: 12))
.padding(.horizontal, 10.0)
.padding(.vertical, 4)
.foregroundColor(.white)
.background(RoundedRectangle(cornerRadius: 30).foregroundColor(Color(red: 229.0/255, green: 76.0/255, blue: 100.0/255)))
}
}
}
} .containerBackground(for: .widget) {
widgetBackground
}
} else {
ZStack(alignment: .leading) {
Expand All @@ -61,7 +86,7 @@ struct NextClassWidgetEntryView : View {
Text(LocalizedStringKey("nextclasswidget.nextlecture"))
.font(.custom("NotoSansKR-Bold", size: 12))
.foregroundColor(Color(red: 229.0/255, green: 76.0/255, blue: 100.0/255))
Text(LocalizedStringKey("nextclasswidget.nodata"))
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getTimeLeft(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Bold", size: 20))
.offset(y: -2)
.minimumScaleFactor(0.5)
Expand All @@ -71,18 +96,18 @@ struct NextClassWidgetEntryView : View {

HStack {
Circle()
.fill(getColourForCourse(course: 1))
.fill((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getColour(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : getColourForCourse(course: 1))
.frame(width: 12, height: 12)
Text(LocalizedStringKey("nextclasswidget.nodata"))
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getName(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Bold", size: 16))
.minimumScaleFactor(0.5)
.lineLimit(2)
}.offset(y: 8)
Text(LocalizedStringKey("nextclasswidget.nodata"))
}.offset(y: 6)
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getPlace(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Regular", size: 12))
.minimumScaleFactor(0.5)
.lineLimit(1)
Text(LocalizedStringKey("nextclasswidget.nodata"))
Text((entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) ? getProfessor(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date) : String(localized: "nextclasswidget.nodata"))
.font(.custom("NotoSansKR-Medium", size: 12))
.minimumScaleFactor(0.5)
.foregroundColor(.gray)
Expand Down Expand Up @@ -214,7 +239,6 @@ struct NextClassWidget: Widget {
.configurationDisplayName(title)
.description(description)
.supportedFamilies([.systemSmall])
.contentMarginsDisabledIfAvailable()
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/OTLWidgets/TimeInlineAccessory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct TimeInlineAccessoryEntryView : View {
case .accessoryInline:
HStack {
Image(systemName: "tablecells")
if (entry.timetableData != nil) {
if (entry.timetableData != nil && entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0].lectures.count > 0) {
Text("\(getBegin(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date)) \(getName(timetable: entry.timetableData![Int(entry.configuration.nextClassTimetable?.identifier ?? "0") ?? 0], date: entry.date))")
} else {
Text(LocalizedStringKey("nextclasswidget.nodata"))
Expand Down
13 changes: 4 additions & 9 deletions ios/OTLWidgets/WidgetBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,11 @@ func getLecturesForDay(timetable: Timetable?, day: Int) -> [(Int, Lecture)] {
return tmp
}

extension WidgetConfiguration
{
func contentMarginsDisabledIfAvailable() -> some WidgetConfiguration
{
if #available(iOSApplicationExtension 17.0, *)
{
extension WidgetConfiguration {
func contentMarginsDisabledIfAvailable() -> some WidgetConfiguration {
if #available(iOSApplicationExtension 17.0, *) {
return self.contentMarginsDisabled()
}
else
{
} else {
return self
}
}
Expand Down

0 comments on commit 72accc6

Please sign in to comment.