2020-11-18 03:49:12 +01:00
|
|
|
//
|
|
|
|
// StarredWidget.swift
|
|
|
|
// NetNewsWire Widget Extension
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 18/11/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct StarredWidgetView : View {
|
|
|
|
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
|
|
|
|
|
|
|
var entry: Provider.Entry
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
if entry.widgetData.starredArticles.count == 0 {
|
|
|
|
inboxZero
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
HStack(alignment: .top, spacing: 8) {
|
|
|
|
VStack {
|
|
|
|
starredImage
|
|
|
|
Spacer()
|
|
|
|
nnwImage
|
|
|
|
}
|
2020-11-19 09:32:44 +01:00
|
|
|
VStack(alignment:.leading, spacing: 2) {
|
2020-11-18 03:49:12 +01:00
|
|
|
ForEach(0..<maxCount(), content: { i in
|
|
|
|
ArticleItemView(article: entry.widgetData.starredArticles[i],
|
|
|
|
deepLink: WidgetDeepLink.starredArticle(id: entry.widgetData.starredArticles[i].id).url)
|
|
|
|
})
|
|
|
|
Spacer()
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2020-11-18 08:43:14 +01:00
|
|
|
countText
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.widgetURL(WidgetDeepLink.starred.url)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var starredImage: some View {
|
|
|
|
Image(systemName: "star.fill")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25, alignment: .center)
|
|
|
|
.cornerRadius(4)
|
|
|
|
.foregroundColor(.yellow)
|
|
|
|
}
|
|
|
|
|
|
|
|
var nnwImage: some View {
|
|
|
|
Image("CornerIcon")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 25, height: 25, alignment: .center)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
|
|
|
|
2020-11-18 08:43:14 +01:00
|
|
|
var countText: some View {
|
|
|
|
var count = entry.widgetData.currentStarredCount
|
|
|
|
if family == .systemLarge {
|
|
|
|
count = count - 8
|
2020-11-18 03:49:12 +01:00
|
|
|
} else {
|
2020-11-18 08:43:14 +01:00
|
|
|
count = count - 3
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
2020-11-18 08:43:14 +01:00
|
|
|
if count < 0 { count = 0 }
|
2020-11-21 02:54:03 +01:00
|
|
|
let str = L10n.starredCount(count)
|
2020-11-18 08:43:14 +01:00
|
|
|
return Text(str)
|
|
|
|
.font(.caption2)
|
|
|
|
.bold()
|
|
|
|
.foregroundColor(.accentColor)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func maxCount() -> Int {
|
2020-11-18 08:43:14 +01:00
|
|
|
if family == .systemLarge {
|
|
|
|
return entry.widgetData.currentStarredCount > 8 ? 8 : entry.widgetData.currentStarredCount
|
|
|
|
}
|
|
|
|
return entry.widgetData.currentStarredCount > 3 ? 3 : entry.widgetData.currentStarredCount
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var inboxZero: some View {
|
|
|
|
VStack {
|
|
|
|
Spacer()
|
2020-11-21 08:47:53 +01:00
|
|
|
Image(systemName: "checkmark.circle")
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
.font(.title)
|
2020-11-18 03:49:12 +01:00
|
|
|
|
|
|
|
Spacer()
|
|
|
|
HStack {
|
|
|
|
Image("CornerIcon")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 15, height: 15, alignment: .center)
|
|
|
|
.cornerRadius(4)
|
|
|
|
|
2020-11-21 08:47:53 +01:00
|
|
|
Text(L10n.starredWidgetNoItems)
|
2020-11-18 03:49:12 +01:00
|
|
|
.font(.caption2)
|
|
|
|
.foregroundColor(.gray)
|
2020-11-18 08:43:14 +01:00
|
|
|
}
|
2020-11-18 03:49:12 +01:00
|
|
|
}.padding()
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|