2020-11-18 03:49:12 +01:00
|
|
|
//
|
|
|
|
// TodayWidget.swift
|
|
|
|
// NetNewsWire Widget Extension
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 18/11/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct TodayWidgetView : View {
|
|
|
|
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
2020-12-24 01:45:07 +01:00
|
|
|
@Environment(\.sizeCategory) var sizeCategory: ContentSizeCategory
|
2020-11-18 03:49:12 +01:00
|
|
|
|
|
|
|
var entry: Provider.Entry
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
if entry.widgetData.todayArticles.count == 0 {
|
|
|
|
inboxZero
|
2020-11-30 08:41:15 +01:00
|
|
|
.widgetURL(WidgetDeepLink.today.url)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
else {
|
2020-11-23 03:35:25 +01:00
|
|
|
GeometryReader { metrics in
|
2021-01-29 15:34:31 +01:00
|
|
|
HStack {
|
|
|
|
VStack {
|
2020-11-18 03:49:12 +01:00
|
|
|
todayImage
|
2021-01-29 15:34:31 +01:00
|
|
|
.padding(.vertical, 12)
|
|
|
|
.padding(.leading, 8)
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
2020-11-23 03:35:25 +01:00
|
|
|
|
2021-01-29 15:34:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.frame(width: metrics.size.width * 0.15)
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
VStack(alignment:.leading, spacing: 0) {
|
2024-11-02 05:10:03 +01:00
|
|
|
ForEach(0..<maxCount(), id: \.self, content: { i in
|
2021-01-29 15:34:31 +01:00
|
|
|
if i != 0 {
|
|
|
|
Divider()
|
|
|
|
ArticleItemView(article: entry.widgetData.todayArticles[i],
|
|
|
|
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
|
|
|
|
.padding(.top, 8)
|
|
|
|
.padding(.bottom, 4)
|
|
|
|
} else {
|
|
|
|
ArticleItemView(article: entry.widgetData.todayArticles[i],
|
|
|
|
deepLink: WidgetDeepLink.todayArticle(id: entry.widgetData.todayArticles[i].id).url)
|
|
|
|
.padding(.bottom, 4)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
.padding(.leading, metrics.size.width * 0.175)
|
|
|
|
.padding([.bottom, .trailing])
|
|
|
|
.padding(.top, 12)
|
|
|
|
.overlay(
|
|
|
|
VStack {
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
2021-01-29 15:34:31 +01:00
|
|
|
HStack {
|
|
|
|
Spacer()
|
2021-01-30 02:02:42 +01:00
|
|
|
if entry.widgetData.currentTodayCount - maxCount() > 0 {
|
|
|
|
Text(L10n.todayCount(entry.widgetData.currentTodayCount - maxCount()))
|
|
|
|
.font(.caption2)
|
|
|
|
.bold()
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
2021-01-29 15:34:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding(.horizontal)
|
|
|
|
.padding(.bottom, 6)
|
|
|
|
)
|
|
|
|
|
2020-11-30 08:41:15 +01:00
|
|
|
}.widgetURL(WidgetDeepLink.today.url)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var todayImage: some View {
|
|
|
|
Image(systemName: "sun.max.fill")
|
|
|
|
.resizable()
|
2020-12-24 01:50:45 +01:00
|
|
|
.frame(width: 30, height: 30, alignment: .center)
|
2020-11-18 03:49:12 +01:00
|
|
|
.cornerRadius(4)
|
|
|
|
.foregroundColor(.orange)
|
|
|
|
}
|
|
|
|
|
|
|
|
func maxCount() -> Int {
|
2020-12-24 01:45:07 +01:00
|
|
|
var reduceAccessibilityCount: Int = 0
|
|
|
|
if SizeCategories().isSizeCategoryLarge(category: sizeCategory) {
|
|
|
|
reduceAccessibilityCount = 1
|
|
|
|
}
|
|
|
|
|
2020-11-18 08:43:14 +01:00
|
|
|
if family == .systemLarge {
|
2020-12-24 01:45:07 +01:00
|
|
|
return entry.widgetData.todayArticles.count >= 7 ? (7 - reduceAccessibilityCount) : entry.widgetData.todayArticles.count
|
2020-11-18 08:43:14 +01:00
|
|
|
}
|
2020-12-24 01:45:07 +01:00
|
|
|
return entry.widgetData.todayArticles.count >= 3 ? (3 - reduceAccessibilityCount) : entry.widgetData.todayArticles.count
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var inboxZero: some View {
|
2020-12-15 12:56:50 +01:00
|
|
|
VStack(alignment: .center) {
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
2020-12-15 12:56:50 +01:00
|
|
|
Image(systemName: "sun.max.fill")
|
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
.frame(width: 30)
|
|
|
|
.foregroundColor(.orange)
|
|
|
|
|
|
|
|
|
|
|
|
Text(L10n.todayWidgetNoItemsTitle)
|
|
|
|
.font(.headline)
|
|
|
|
.foregroundColor(.primary)
|
2020-11-18 03:49:12 +01:00
|
|
|
|
2020-12-15 12:56:50 +01:00
|
|
|
Text(L10n.todayWidgetNoItems)
|
|
|
|
.font(.caption)
|
|
|
|
.foregroundColor(.gray)
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
2020-12-15 12:56:50 +01:00
|
|
|
}
|
|
|
|
.multilineTextAlignment(.center)
|
|
|
|
.padding()
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|