2020-11-18 03:49:12 +01:00
|
|
|
//
|
|
|
|
// SmartFeedSummaryWidget.swift
|
|
|
|
// NetNewsWire Widget Extension
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 18/11/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import WidgetKit
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
|
|
|
|
struct SmartFeedSummaryWidgetView: View {
|
|
|
|
|
|
|
|
@Environment(\.widgetFamily) var family: WidgetFamily
|
|
|
|
|
|
|
|
var entry: Provider.Entry
|
|
|
|
|
|
|
|
var body: some View {
|
2020-11-30 08:41:15 +01:00
|
|
|
smallWidget
|
|
|
|
.widgetURL(WidgetDeepLink.icon.url)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder
|
|
|
|
var smallWidget: some View {
|
|
|
|
VStack(alignment: .leading) {
|
2020-11-21 10:16:21 +01:00
|
|
|
Spacer()
|
2020-11-18 03:49:12 +01:00
|
|
|
Link(destination: WidgetDeepLink.today.url, label: {
|
|
|
|
HStack {
|
|
|
|
todayImage
|
2020-11-21 10:16:21 +01:00
|
|
|
VStack(alignment: .leading, spacing: nil, content: {
|
|
|
|
Text(formattedCount(entry.widgetData.currentTodayCount)).font(Font.system(.caption, design: .rounded)).bold()
|
|
|
|
Text(L10n.today).bold().font(.caption).textCase(.uppercase)
|
|
|
|
}).foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Link(destination: WidgetDeepLink.unread.url, label: {
|
|
|
|
HStack {
|
|
|
|
unreadImage
|
2020-11-21 10:16:21 +01:00
|
|
|
VStack(alignment: .leading, spacing: nil, content: {
|
|
|
|
Text(formattedCount(entry.widgetData.currentUnreadCount)).font(Font.system(.caption, design: .rounded)).bold()
|
|
|
|
Text(L10n.unread).bold().font(.caption).textCase(.uppercase)
|
|
|
|
}).foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
Link(destination: WidgetDeepLink.starred.url, label: {
|
|
|
|
HStack {
|
|
|
|
starredImage
|
2020-11-21 10:16:21 +01:00
|
|
|
VStack(alignment: .leading, spacing: nil, content: {
|
|
|
|
Text(formattedCount(entry.widgetData.currentStarredCount)).font(Font.system(.caption, design: .rounded)).bold()
|
|
|
|
Text(L10n.starred).bold().font(.caption).textCase(.uppercase)
|
|
|
|
}).foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
Spacer()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
Spacer()
|
|
|
|
}.padding()
|
|
|
|
}
|
|
|
|
|
|
|
|
func formattedCount(_ count: Int) -> String {
|
|
|
|
let formatter = NumberFormatter()
|
|
|
|
formatter.locale = Locale.current
|
|
|
|
formatter.numberStyle = .decimal
|
|
|
|
return formatter.string(from: NSNumber(value: count))!
|
|
|
|
}
|
|
|
|
|
|
|
|
var unreadImage: some View {
|
|
|
|
Image(systemName: "largecircle.fill.circle")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 20, height: 20, alignment: .center)
|
2020-11-21 10:16:21 +01:00
|
|
|
.foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var nnwImage: some View {
|
|
|
|
Image("CornerIcon")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 20, height: 20, alignment: .center)
|
|
|
|
.cornerRadius(4)
|
|
|
|
}
|
|
|
|
|
|
|
|
var starredImage: some View {
|
|
|
|
Image(systemName: "star.fill")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 20, height: 20, alignment: .center)
|
2020-11-21 10:16:21 +01:00
|
|
|
.foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var todayImage: some View {
|
|
|
|
Image(systemName: "sun.max.fill")
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 20, height: 20, alignment: .center)
|
2020-11-21 10:16:21 +01:00
|
|
|
.foregroundColor(.white)
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-11-21 10:16:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct SmartFeedSummaryWidgetView_Previews: PreviewProvider {
|
|
|
|
|
|
|
|
static var previews: some View {
|
|
|
|
SmartFeedSummaryWidgetView(entry: Provider.Entry.init(date: Date(), widgetData: WidgetDataDecoder.sampleData()))
|
|
|
|
}
|
|
|
|
}
|