diff --git a/ios/OTLWidgets/LocationInlineAccessory.swift b/ios/OTLWidgets/LocationInlineAccessory.swift index 02af40af..19508cb8 100644 --- a/ios/OTLWidgets/LocationInlineAccessory.swift +++ b/ios/OTLWidgets/LocationInlineAccessory.swift @@ -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")) diff --git a/ios/OTLWidgets/NextClassAccessory.swift b/ios/OTLWidgets/NextClassAccessory.swift index d1b60598..480915c5 100644 --- a/ios/OTLWidgets/NextClassAccessory.swift +++ b/ios/OTLWidgets/NextClassAccessory.swift @@ -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) @@ -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) @@ -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() @@ -72,7 +73,7 @@ struct NextClassAccessoryEntryView : View { .font(.headline) }.offset(y: 7) .widgetAccentable() - Text(LocalizedStringKey("nextclasswidget.nodata")) + Text("") .font(.headline) .widgetAccentable() Text("") diff --git a/ios/OTLWidgets/NextClassWidget.swift b/ios/OTLWidgets/NextClassWidget.swift index cb0eb4dc..3f4daeff 100644 --- a/ios/OTLWidgets/NextClassWidget.swift +++ b/ios/OTLWidgets/NextClassWidget.swift @@ -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 @@ -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) @@ -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) { @@ -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) @@ -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) @@ -214,7 +239,6 @@ struct NextClassWidget: Widget { .configurationDisplayName(title) .description(description) .supportedFamilies([.systemSmall]) - .contentMarginsDisabledIfAvailable() } } diff --git a/ios/OTLWidgets/TimeInlineAccessory.swift b/ios/OTLWidgets/TimeInlineAccessory.swift index d1ea491c..3e10df68 100644 --- a/ios/OTLWidgets/TimeInlineAccessory.swift +++ b/ios/OTLWidgets/TimeInlineAccessory.swift @@ -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")) diff --git a/ios/OTLWidgets/WidgetBase.swift b/ios/OTLWidgets/WidgetBase.swift index 3eab1c25..295c9624 100644 --- a/ios/OTLWidgets/WidgetBase.swift +++ b/ios/OTLWidgets/WidgetBase.swift @@ -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 } }