mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-11 00:46:38 +01:00
ef8035bcdf
• Feed favicons now sized to match the height of the article row • Rounded font removed in lieu of default font • accentColor corrected for dark mode • Fixes an ~3pt alignment issue on the Today widget’s left VStack • No content views have been updated with bigger text and explainers • The small summary widget has been disabled
96 lines
2.5 KiB
Swift
96 lines
2.5 KiB
Swift
//
|
|
// UnreadWidget.swift
|
|
// NetNewsWire Widget Extension
|
|
//
|
|
// Created by Stuart Breckenridge on 18/11/20.
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
//
|
|
|
|
import WidgetKit
|
|
import SwiftUI
|
|
|
|
struct UnreadWidgetView : View {
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
|
|
|
var entry: Provider.Entry
|
|
|
|
var body: some View {
|
|
if entry.widgetData.currentUnreadCount == 0 {
|
|
inboxZero
|
|
.widgetURL(WidgetDeepLink.unread.url)
|
|
}
|
|
else {
|
|
GeometryReader { metrics in
|
|
HStack(alignment: .top, spacing: 4) {
|
|
VStack(alignment: .leading) {
|
|
unreadImage
|
|
Spacer()
|
|
Text(L10n.localizedCount(entry.widgetData.currentUnreadCount)).bold().font(.callout).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)
|
|
.padding(.trailing, 4)
|
|
|
|
VStack(alignment:.leading, spacing: 0) {
|
|
ForEach(0..<maxCount(), content: { i in
|
|
if i != 0 {
|
|
Divider()
|
|
ArticleItemView(article: entry.widgetData.unreadArticles[i],
|
|
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
|
|
.padding(.top, 8)
|
|
.padding(.bottom, 4)
|
|
} else {
|
|
ArticleItemView(article: entry.widgetData.unreadArticles[i],
|
|
deepLink: WidgetDeepLink.unreadArticle(id: entry.widgetData.unreadArticles[i].id).url)
|
|
.padding(.bottom, 4)
|
|
}
|
|
|
|
})
|
|
Spacer()
|
|
}.padding(.leading, 4)
|
|
}.padding()
|
|
}.widgetURL(WidgetDeepLink.unread.url)
|
|
}
|
|
}
|
|
|
|
var unreadImage: some View {
|
|
Image(systemName: "largecircle.fill.circle")
|
|
.resizable()
|
|
.frame(width: 25, height: 25, alignment: .center)
|
|
.cornerRadius(4)
|
|
.foregroundColor(.accentColor)
|
|
}
|
|
|
|
func maxCount() -> Int {
|
|
if family == .systemLarge {
|
|
return entry.widgetData.unreadArticles.count > 7 ? 7 : entry.widgetData.unreadArticles.count
|
|
}
|
|
return entry.widgetData.unreadArticles.count > 3 ? 3 : entry.widgetData.unreadArticles.count
|
|
}
|
|
|
|
var inboxZero: some View {
|
|
VStack(alignment: .center) {
|
|
Spacer()
|
|
Image(systemName: "largecircle.fill.circle")
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fit)
|
|
.foregroundColor(.accentColor)
|
|
.frame(width: 30)
|
|
|
|
Text(L10n.unreadWidgetNoItemsTitle)
|
|
.font(.headline)
|
|
.foregroundColor(.primary)
|
|
|
|
Text(L10n.unreadWidgetNoItems)
|
|
.font(.caption)
|
|
.foregroundColor(.gray)
|
|
Spacer()
|
|
}
|
|
.multilineTextAlignment(.center)
|
|
.padding()
|
|
}
|
|
|
|
}
|
|
|