2020-11-18 03:49:12 +01:00
|
|
|
//
|
|
|
|
// ArticleItemView.swift
|
|
|
|
// NetNewsWire Widget Extension
|
|
|
|
//
|
|
|
|
// Created by Stuart Breckenridge on 18/11/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ArticleItemView: View {
|
|
|
|
|
|
|
|
var article: LatestArticle
|
|
|
|
var deepLink: URL
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Link(destination: deepLink, label: {
|
|
|
|
HStack(alignment: .top, spacing: nil, content: {
|
|
|
|
// Feed Icon
|
|
|
|
Image(uiImage: thumbnail(article.feedIcon))
|
|
|
|
.resizable()
|
2020-12-15 12:56:50 +01:00
|
|
|
.frame(width: 30, height: 30)
|
2020-11-18 03:49:12 +01:00
|
|
|
.cornerRadius(4)
|
|
|
|
|
|
|
|
// Title and Feed Name
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(article.articleTitle ?? "Untitled")
|
2020-11-19 09:32:44 +01:00
|
|
|
.font(.footnote)
|
2020-11-18 03:49:12 +01:00
|
|
|
.bold()
|
|
|
|
.lineLimit(1)
|
|
|
|
.foregroundColor(.primary)
|
2020-11-19 09:32:44 +01:00
|
|
|
.padding(.top, -3)
|
2020-11-18 03:49:12 +01:00
|
|
|
|
|
|
|
HStack {
|
|
|
|
Text(article.feedTitle)
|
|
|
|
.font(.caption)
|
|
|
|
.lineLimit(1)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
Spacer()
|
|
|
|
Text(pubDate(article.pubDate))
|
|
|
|
.font(.caption)
|
|
|
|
.lineLimit(1)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2020-11-23 03:35:25 +01:00
|
|
|
})
|
2020-11-18 03:49:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func thumbnail(_ data: Data?) -> UIImage {
|
|
|
|
if data == nil {
|
|
|
|
return UIImage(systemName: "globe")!
|
|
|
|
} else {
|
|
|
|
return UIImage(data: data!)!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pubDate(_ dateString: String) -> String {
|
|
|
|
let dateFormatter = DateFormatter()
|
|
|
|
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
|
|
|
|
let date = dateFormatter.date(from: dateString)
|
|
|
|
|
|
|
|
let displayFormatter = DateFormatter()
|
|
|
|
displayFormatter.dateStyle = .medium
|
|
|
|
displayFormatter.timeStyle = .none
|
|
|
|
|
|
|
|
return displayFormatter.string(from: date!)
|
|
|
|
}
|
|
|
|
}
|