2019-09-28 02:45:09 +02:00
|
|
|
//
|
|
|
|
// FeedInspector.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 9/27/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import Combine
|
|
|
|
import Account
|
|
|
|
|
|
|
|
struct FeedInspectorView : View {
|
|
|
|
|
|
|
|
@ObservedObject var viewModel: ViewModel
|
2019-09-30 09:45:33 +02:00
|
|
|
@Environment(\.colorScheme) private var colorScheme: ColorScheme
|
2019-09-28 02:45:09 +02:00
|
|
|
@Environment(\.viewController) private var viewController: UIViewController?
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationView {
|
|
|
|
Form {
|
|
|
|
Section(header:
|
|
|
|
HStack {
|
|
|
|
Spacer()
|
2019-09-28 02:49:54 +02:00
|
|
|
if self.viewModel.image.size.width < 32 || self.viewModel.image.size.height < 32 {
|
2019-09-30 09:45:33 +02:00
|
|
|
if colorScheme == .dark && self.viewModel.image.isDark() {
|
2019-09-30 09:48:51 +02:00
|
|
|
Image(uiImage: self.viewModel.image)
|
|
|
|
.resizable()
|
|
|
|
.background(Color(AppAssets.avatarBackgroundColor))
|
2019-09-30 09:45:33 +02:00
|
|
|
.frame(width: 24.0, height: 24.0)
|
|
|
|
.cornerRadius(2.0)
|
|
|
|
} else {
|
|
|
|
Image(uiImage: self.viewModel.image)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 24.0, height: 24.0)
|
|
|
|
.cornerRadius(2.0)
|
|
|
|
}
|
2019-09-28 02:49:54 +02:00
|
|
|
} else {
|
2019-09-30 09:48:51 +02:00
|
|
|
if colorScheme == .dark && self.viewModel.image.isDark() {
|
|
|
|
Image(uiImage: self.viewModel.image)
|
|
|
|
.resizable()
|
|
|
|
.background(Color(AppAssets.avatarBackgroundColor))
|
|
|
|
.frame(width: 48.0, height: 48.0)
|
|
|
|
.cornerRadius(5.0)
|
|
|
|
} else {
|
|
|
|
Image(uiImage: self.viewModel.image)
|
|
|
|
.resizable()
|
|
|
|
.frame(width: 48.0, height: 48.0)
|
|
|
|
.cornerRadius(5.0)
|
|
|
|
}
|
2019-09-28 02:49:54 +02:00
|
|
|
}
|
2019-09-28 02:45:09 +02:00
|
|
|
Spacer()
|
|
|
|
}) {
|
|
|
|
TextField("Feed Name", text: $viewModel.name)
|
2019-10-03 02:42:16 +02:00
|
|
|
Toggle(isOn: $viewModel.isNotifyAboutNewArticles) {
|
|
|
|
Text("Notify About New Articles")
|
|
|
|
}
|
2019-09-28 02:45:09 +02:00
|
|
|
Toggle(isOn: $viewModel.isArticleExtractorAlwaysOn) {
|
2019-09-28 13:35:21 +02:00
|
|
|
Text("Always Show Reader View")
|
2019-09-28 02:45:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Section(header: Text("HOME PAGE")) {
|
|
|
|
Text(verbatim: self.viewModel.homePageURL)
|
|
|
|
}
|
|
|
|
Section(header: Text("FEED URL")) {
|
|
|
|
Text(verbatim: self.viewModel.feedLinkURL)
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 19:30:10 +02:00
|
|
|
.onDisappear { self.viewModel.save() }
|
2019-09-28 02:45:09 +02:00
|
|
|
.navigationBarTitle(Text(verbatim: self.viewModel.nameForDisplay), displayMode: .inline)
|
2019-10-24 19:30:10 +02:00
|
|
|
.navigationBarItems(leading: Button(action: {
|
|
|
|
self.viewModel.save()
|
|
|
|
self.viewController?.dismiss(animated: true)
|
|
|
|
}) { Text("Done") } )
|
2019-09-28 02:45:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: ViewModel
|
|
|
|
|
|
|
|
class ViewModel: ObservableObject {
|
|
|
|
|
|
|
|
let objectWillChange = ObservableObjectPublisher()
|
|
|
|
let feed: Feed
|
2019-10-24 19:30:10 +02:00
|
|
|
@Published var name: String
|
2019-09-28 02:45:09 +02:00
|
|
|
|
|
|
|
init(feed: Feed) {
|
|
|
|
self.feed = feed
|
2019-10-24 19:30:10 +02:00
|
|
|
self.name = feed.nameForDisplay
|
2019-09-28 13:35:21 +02:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(feedIconDidBecomeAvailable(_:)), name: .FeedIconDidBecomeAvailable, object: nil)
|
2019-09-28 02:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var image: UIImage {
|
|
|
|
if let feedIcon = appDelegate.feedIconDownloader.icon(for: feed) {
|
|
|
|
return feedIcon
|
|
|
|
}
|
|
|
|
if let favicon = appDelegate.faviconDownloader.favicon(for: feed) {
|
|
|
|
return favicon
|
|
|
|
}
|
|
|
|
return FaviconGenerator.favicon(feed)
|
|
|
|
}
|
|
|
|
|
|
|
|
var nameForDisplay: String {
|
|
|
|
return feed.nameForDisplay
|
|
|
|
}
|
|
|
|
|
2019-10-03 02:42:16 +02:00
|
|
|
var isNotifyAboutNewArticles: Bool {
|
|
|
|
get {
|
|
|
|
return feed.isNotifyAboutNewArticles ?? false
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
objectWillChange.send()
|
|
|
|
feed.isNotifyAboutNewArticles = newValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 02:45:09 +02:00
|
|
|
var isArticleExtractorAlwaysOn: Bool {
|
|
|
|
get {
|
|
|
|
return feed.isArticleExtractorAlwaysOn ?? false
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
objectWillChange.send()
|
|
|
|
feed.isArticleExtractorAlwaysOn = newValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var homePageURL: String {
|
|
|
|
return feed.homePageURL ?? ""
|
|
|
|
}
|
|
|
|
|
|
|
|
var feedLinkURL: String {
|
|
|
|
return feed.url
|
|
|
|
}
|
2019-09-28 13:35:21 +02:00
|
|
|
|
|
|
|
@objc func feedIconDidBecomeAvailable(_ notification: Notification) {
|
|
|
|
objectWillChange.send()
|
|
|
|
}
|
|
|
|
|
2019-10-24 19:30:10 +02:00
|
|
|
func save() {
|
|
|
|
if name != nameForDisplay {
|
|
|
|
feed.editedName = name.isEmpty ? nil : name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-28 02:45:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|