diff --git a/IceCubesAppWidgetsExtension/LatestPostsWidget.swift b/IceCubesAppWidgetsExtension/LatestPostsWidget.swift index 1fec4639..551d2588 100644 --- a/IceCubesAppWidgetsExtension/LatestPostsWidget.swift +++ b/IceCubesAppWidgetsExtension/LatestPostsWidget.swift @@ -10,7 +10,7 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider { .init(date: Date(), configuration: IceCubesWidgetConfigurationIntent(), timeline: .home, - statuses: [.placeholder(), .placeholder()], + statuses: [.placeholder()], images: [:]) } @@ -45,17 +45,17 @@ struct LatestPostsWidgetProvider: AppIntentTimelineProvider { offset: nil)) statuses = statuses.filter{ $0.reblog == nil && !$0.content.asRawText.isEmpty } switch context.family { - case .systemMedium: - if statuses.count >= 2 { - statuses = statuses.prefix(upTo: 2).map{ $0 } + case .systemSmall, .systemMedium: + if statuses.count >= 1 { + statuses = statuses.prefix(upTo: 1).map{ $0 } } case .systemLarge: - if statuses.count >= 5 { - statuses = statuses.prefix(upTo: 5).map{ $0 } + if statuses.count >= 4 { + statuses = statuses.prefix(upTo: 4).map{ $0 } } case .systemExtraLarge: - if statuses.count >= 8 { - statuses = statuses.prefix(upTo: 8).map{ $0 } + if statuses.count >= 6 { + statuses = statuses.prefix(upTo: 6).map{ $0 } } default: break @@ -108,11 +108,24 @@ struct LatestPostsWidgetView : View { @Environment(\.widgetFamily) var family @Environment(\.redactionReasons) var redacted + var contentLineLimit: Int { + switch family { + case .systemSmall, .systemMedium: + return 4 + default: + return 2 + } + } var body: some View { VStack(alignment: .leading, spacing: 8) { headerView ForEach(entry.statuses) { status in - makeStatusView(status) + VStack(spacing: 4) { + makeStatusView(status) + if entry.statuses.last?.id != status.id { + Divider() + } + } } Spacer() } @@ -134,11 +147,12 @@ struct LatestPostsWidgetView : View { private func makeStatusView(_ status: Status) -> some View { if let url = URL(string: status.url ?? "") { Link(destination: url, label: { - VStack(alignment: .leading, spacing: 4) { + VStack(alignment: .leading, spacing: 2) { makeStatusHeaderView(status) - Text(status.content.asRawText) + Text(status.content.asSafeMarkdownAttributedString) .font(.body) - .lineLimit(2) + .lineLimit(contentLineLimit) + .fixedSize(horizontal: false, vertical: true) } }) } @@ -157,7 +171,9 @@ struct LatestPostsWidgetView : View { .frame(width: 16, height: 16) } HStack(spacing: 0) { - Text(status.account.safeDisplayName) + if family != .systemSmall { + Text(status.account.safeDisplayName) + } Text(" @") Text(status.account.username) Spacer() @@ -182,7 +198,7 @@ struct LatestPostsWidget: Widget { } .configurationDisplayName("Latest posts") .description("Show the latest post for the selected timeline") - .supportedFamilies([.systemMedium, .systemLarge, .systemExtraLarge]) + .supportedFamilies([.systemSmall, .systemMedium, .systemLarge, .systemExtraLarge]) } }