Merge pull request #2618 from stuartbreckenridge/widget-layout-fix

Widget layout fix
This commit is contained in:
Maurice Parker 2020-11-29 13:19:43 -06:00 committed by GitHub
commit b643efb60c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 16 deletions

View File

@ -16,8 +16,10 @@ import Articles
@available(iOS 14, *) @available(iOS 14, *)
struct WidgetDataEncoder { struct WidgetDataEncoder {
private static var log = OSLog(subsystem: Bundle.main.bundleIdentifier!, category: "Application")
static func encodeWidgetData() { static func encodeWidgetData() {
os_log(.debug, "Starting encoding widget data.") os_log(.debug, log: log, "Starting encoding widget data.")
do { do {
// Unread Articles // Unread Articles
let unreadArticles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished ?? .distantPast > $1.datePublished ?? .distantPast }) let unreadArticles = try SmartFeedsController.shared.unreadFeed.fetchArticles().sorted(by: { $0.datePublished ?? .distantPast > $1.datePublished ?? .distantPast })
@ -30,7 +32,7 @@ struct WidgetDataEncoder {
feedIcon: article.iconImage()?.image.dataRepresentation(), feedIcon: article.iconImage()?.image.dataRepresentation(),
pubDate: article.datePublished!.description) pubDate: article.datePublished!.description)
unread.append(latestArticle) unread.append(latestArticle)
if unread.count == 8 { break } if unread.count == 7 { break }
} }
// Starred Articles // Starred Articles
@ -44,7 +46,7 @@ struct WidgetDataEncoder {
feedIcon: article.iconImage()?.image.dataRepresentation(), feedIcon: article.iconImage()?.image.dataRepresentation(),
pubDate: article.datePublished!.description) pubDate: article.datePublished!.description)
starred.append(latestArticle) starred.append(latestArticle)
if starred.count == 8 { break } if starred.count == 7 { break }
} }
// Today Articles // Today Articles
@ -58,7 +60,7 @@ struct WidgetDataEncoder {
feedIcon: article.iconImage()?.image.dataRepresentation(), feedIcon: article.iconImage()?.image.dataRepresentation(),
pubDate: article.datePublished!.description) pubDate: article.datePublished!.description)
today.append(latestArticle) today.append(latestArticle)
if today.count == 8 { break } if today.count == 7 { break }
} }
let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount, let latestData = WidgetData(currentUnreadCount: SmartFeedsController.shared.unreadFeed.unreadCount,
@ -70,16 +72,16 @@ struct WidgetDataEncoder {
lastUpdateTime: Date()) lastUpdateTime: Date())
let encodedData = try JSONEncoder().encode(latestData) let encodedData = try JSONEncoder().encode(latestData)
os_log(.debug, "Finished encoding widget data.") os_log(.debug, log: log, "Finished encoding widget data.")
let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as! String
let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup) let containerURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: appGroup)
let dataURL = containerURL?.appendingPathComponent("widget-data.json") let dataURL = containerURL?.appendingPathComponent("widget-data.json")
if FileManager.default.fileExists(atPath: dataURL!.path) { if FileManager.default.fileExists(atPath: dataURL!.path) {
try FileManager.default.removeItem(at: dataURL!) try FileManager.default.removeItem(at: dataURL!)
os_log(.debug, "Removed widget data from container.") os_log(.debug, log: log, "Removed widget data from container.")
} }
if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) { if FileManager.default.createFile(atPath: dataURL!.path, contents: encodedData, attributes: nil) {
os_log(.debug, "Wrote widget data to container.") os_log(.debug, log: log, "Wrote widget data to container.")
WidgetCenter.shared.reloadAllTimelines() WidgetCenter.shared.reloadAllTimelines()
} }
} catch { } catch {

View File

@ -25,7 +25,7 @@ struct StarredWidgetView : View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
starredImage starredImage
Spacer() Spacer()
Text(L10n.localizedCount(entry.widgetData.currentStarredCount)).bold().font(Font.system(.footnote, design: .rounded)) Text(L10n.localizedCount(entry.widgetData.currentStarredCount)).bold().font(Font.system(.callout, design: .rounded)).minimumScaleFactor(0.5).lineLimit(1)
Text(L10n.starred.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1) Text(L10n.starred.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1)
} }
.frame(width: metrics.size.width * 0.15) .frame(width: metrics.size.width * 0.15)
@ -37,7 +37,8 @@ struct StarredWidgetView : View {
Divider() Divider()
ArticleItemView(article: entry.widgetData.starredArticles[i], ArticleItemView(article: entry.widgetData.starredArticles[i],
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url) deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
.padding(.vertical, 6) .padding(.top, 8)
.padding(.bottom, 4)
} else { } else {
ArticleItemView(article: entry.widgetData.starredArticles[i], ArticleItemView(article: entry.widgetData.starredArticles[i],
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url) deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
@ -70,7 +71,7 @@ struct StarredWidgetView : View {
func maxCount() -> Int { func maxCount() -> Int {
if family == .systemLarge { if family == .systemLarge {
return entry.widgetData.currentStarredCount > 8 ? 8 : entry.widgetData.currentStarredCount return entry.widgetData.currentStarredCount > 7 ? 7 : entry.widgetData.currentStarredCount
} }
return entry.widgetData.currentStarredCount > 3 ? 3 : entry.widgetData.currentStarredCount return entry.widgetData.currentStarredCount > 3 ? 3 : entry.widgetData.currentStarredCount
} }

View File

@ -25,19 +25,21 @@ struct TodayWidgetView : View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
todayImage todayImage
Spacer() Spacer()
Text(L10n.localizedCount(entry.widgetData.currentTodayCount)).bold().font(Font.system(.footnote, design: .rounded)) Text(L10n.localizedCount(entry.widgetData.currentTodayCount)).bold().font(Font.system(.callout, design: .rounded)).minimumScaleFactor(0.5).lineLimit(1)
Text(L10n.today.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1) Text(L10n.today.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1)
} }
.frame(width: metrics.size.width * 0.15) .frame(width: metrics.size.width * 0.15)
.padding(.trailing, 4) .padding(.trailing, 4)
VStack(alignment:.leading, spacing: 0) { VStack(alignment:.leading, spacing: 0) {
ForEach(0..<maxCount(), content: { i in ForEach(0..<maxCount(), content: { i in
if i != 0 { if i != 0 {
Divider() Divider()
ArticleItemView(article: entry.widgetData.todayArticles[i], ArticleItemView(article: entry.widgetData.todayArticles[i],
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url) deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
.padding(.vertical, 6) .padding(.top, 8)
.padding(.bottom, 4)
} else { } else {
ArticleItemView(article: entry.widgetData.unreadArticles[i], ArticleItemView(article: entry.widgetData.unreadArticles[i],
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url) deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
@ -69,7 +71,7 @@ struct TodayWidgetView : View {
func maxCount() -> Int { func maxCount() -> Int {
if family == .systemLarge { if family == .systemLarge {
return entry.widgetData.todayArticles.count > 8 ? 8 : entry.widgetData.todayArticles.count return entry.widgetData.todayArticles.count > 7 ? 7 : entry.widgetData.todayArticles.count
} }
return entry.widgetData.todayArticles.count > 3 ? 3 : entry.widgetData.todayArticles.count return entry.widgetData.todayArticles.count > 3 ? 3 : entry.widgetData.todayArticles.count
} }

View File

@ -25,7 +25,7 @@ struct UnreadWidgetView : View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
unreadImage unreadImage
Spacer() Spacer()
Text(L10n.localizedCount(entry.widgetData.currentUnreadCount)).bold().font(Font.system(.footnote, design: .rounded)) Text(L10n.localizedCount(entry.widgetData.currentUnreadCount)).bold().font(Font.system(.callout, design: .rounded)).minimumScaleFactor(0.5).lineLimit(1)
Text(L10n.unread.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1) Text(L10n.unread.lowercased()).bold().font(Font.system(.footnote).lowercaseSmallCaps()).minimumScaleFactor(0.5).lineLimit(1)
} }
.frame(width: metrics.size.width * 0.15) .frame(width: metrics.size.width * 0.15)
@ -37,7 +37,8 @@ struct UnreadWidgetView : View {
Divider() Divider()
ArticleItemView(article: entry.widgetData.unreadArticles[i], ArticleItemView(article: entry.widgetData.unreadArticles[i],
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url) deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
.padding(.vertical, 6) .padding(.top, 8)
.padding(.bottom, 4)
} else { } else {
ArticleItemView(article: entry.widgetData.unreadArticles[i], ArticleItemView(article: entry.widgetData.unreadArticles[i],
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url) deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
@ -69,7 +70,7 @@ struct UnreadWidgetView : View {
func maxCount() -> Int { func maxCount() -> Int {
if family == .systemLarge { if family == .systemLarge {
return entry.widgetData.unreadArticles.count > 8 ? 8 : entry.widgetData.unreadArticles.count return entry.widgetData.unreadArticles.count > 7 ? 7 : entry.widgetData.unreadArticles.count
} }
return entry.widgetData.unreadArticles.count > 3 ? 3 : entry.widgetData.unreadArticles.count return entry.widgetData.unreadArticles.count > 3 ? 3 : entry.widgetData.unreadArticles.count
} }