mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-03 12:27:32 +01:00
AddWebFeed
Fixes #2184 Adding Web Feeds is working for macOS and iOS. There are some alignment is.
This commit is contained in:
parent
a4f53bc167
commit
d8914510f7
@ -1,5 +1,5 @@
|
||||
//
|
||||
// AddFeedView.swift
|
||||
// AddWebFeedView.swift
|
||||
// NetNewsWire
|
||||
//
|
||||
// Created by Stuart Breckenridge on 3/7/20.
|
||||
@ -10,7 +10,7 @@ import SwiftUI
|
||||
import Account
|
||||
import RSCore
|
||||
|
||||
fileprivate enum AddFeedError: LocalizedError {
|
||||
fileprivate enum AddWebFeedError: LocalizedError {
|
||||
|
||||
case none, alreadySubscribed, initialDownload, noFeeds
|
||||
|
||||
@ -29,12 +29,12 @@ fileprivate enum AddFeedError: LocalizedError {
|
||||
|
||||
}
|
||||
|
||||
fileprivate class AddFeedViewModel: ObservableObject {
|
||||
fileprivate class AddWebFeedViewModel: ObservableObject {
|
||||
|
||||
@Published var providedURL: String = ""
|
||||
@Published var providedName: String = ""
|
||||
@Published var selectedFolderIndex: Int = 0
|
||||
@Published var addFeedError: AddFeedError? {
|
||||
@Published var addFeedError: AddWebFeedError? {
|
||||
didSet {
|
||||
addFeedError != .none ? (showError = true) : (showError = false)
|
||||
}
|
||||
@ -54,10 +54,10 @@ fileprivate class AddFeedViewModel: ObservableObject {
|
||||
|
||||
}
|
||||
|
||||
struct AddFeedView: View {
|
||||
struct AddWebFeedView: View {
|
||||
|
||||
@Environment(\.presentationMode) private var presentationMode
|
||||
@ObservedObject private var viewModel = AddFeedViewModel()
|
||||
@ObservedObject private var viewModel = AddWebFeedViewModel()
|
||||
|
||||
@ViewBuilder var body: some View {
|
||||
#if os(iOS)
|
||||
@ -100,31 +100,48 @@ struct AddFeedView: View {
|
||||
#endif
|
||||
|
||||
#if os(iOS)
|
||||
var iosForm: some View {
|
||||
NavigationLink {
|
||||
List {
|
||||
Text("PLACEHOLDER")
|
||||
}.listStyle(InsetGroupedListStyle())
|
||||
@ViewBuilder var iosForm: some View {
|
||||
NavigationView {
|
||||
Form {
|
||||
urlTextField
|
||||
providedNameTextField
|
||||
folderPicker
|
||||
}
|
||||
.listStyle(InsetGroupedListStyle())
|
||||
.navigationTitle("Add Web Feed")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.navigationBarItems(leading:
|
||||
Button("Cancel", action: {
|
||||
presentationMode.wrappedValue.dismiss()
|
||||
})
|
||||
.help("Cancel Add Feed")
|
||||
, trailing:
|
||||
Button("Add", action: {
|
||||
addWebFeed()
|
||||
})
|
||||
.disabled(!viewModel.providedURL.isValidURL)
|
||||
.help("Add Feed")
|
||||
)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
var urlTextField: some View {
|
||||
HStack {
|
||||
Text("Feed: ").font(.system(.body, design: .monospaced))
|
||||
Text("Feed:")
|
||||
TextField("URL", text: $viewModel.providedURL)
|
||||
}
|
||||
}
|
||||
|
||||
var providedNameTextField: some View {
|
||||
HStack(alignment: .lastTextBaseline) {
|
||||
Text("Name: ").font(.system(.body, design: .monospaced))
|
||||
Text("Name:")
|
||||
TextField("Optional", text: $viewModel.providedName)
|
||||
}
|
||||
}
|
||||
|
||||
var folderPicker: some View {
|
||||
Picker(" ", selection: $viewModel.selectedFolderIndex, content: {
|
||||
Picker("Folder:", selection: $viewModel.selectedFolderIndex, content: {
|
||||
ForEach(0..<viewModel.containers.count, id: \.self, content: { index in
|
||||
if let containerName = (viewModel.containers[index] as? DisplayNameProvider)?.nameForDisplay {
|
||||
if viewModel.containers[index] is Folder {
|
||||
@ -134,7 +151,7 @@ struct AddFeedView: View {
|
||||
}
|
||||
}
|
||||
})
|
||||
}).font(.system(.body, design: .monospaced))
|
||||
})
|
||||
}
|
||||
|
||||
var buttonStack: some View {
|
||||
@ -169,14 +186,23 @@ struct AddFeedView: View {
|
||||
|
||||
}
|
||||
|
||||
private extension AddFeedView {
|
||||
private extension AddWebFeedView {
|
||||
|
||||
#if os(macOS)
|
||||
var urlStringFromPasteboard: String? {
|
||||
if let urlString = NSPasteboard.urlString(from: NSPasteboard.general) {
|
||||
return urlString.normalizedURL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
#else
|
||||
var urlStringFromPasteboard: String? {
|
||||
if let urlString = UIPasteboard.general.url?.absoluteString {
|
||||
return urlString.normalizedURL
|
||||
}
|
||||
return nil
|
||||
}
|
||||
#endif
|
||||
|
||||
struct AccountAndFolderSpecifier {
|
||||
let account: Account
|
||||
@ -232,6 +258,6 @@ private extension AddFeedView {
|
||||
|
||||
struct AddFeedView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
AddFeedView()
|
||||
AddWebFeedView()
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ struct MainApp: App {
|
||||
.environmentObject(sceneModel)
|
||||
.environmentObject(defaults)
|
||||
.sheet(isPresented: $showSheet, onDismiss: { showSheet = false }) {
|
||||
AddFeedView()
|
||||
AddWebFeedView()
|
||||
}
|
||||
.toolbar {
|
||||
|
||||
|
@ -10,8 +10,17 @@ import SwiftUI
|
||||
|
||||
struct SidebarToolbar: View {
|
||||
|
||||
@State private var showSettings: Bool = false
|
||||
@State private var showAddSheet: Bool = false
|
||||
enum ToolbarSheets {
|
||||
case none, web, twitter, reddit, folder, settings
|
||||
}
|
||||
|
||||
@State private var showSheet: Bool = false
|
||||
@State private var sheetToShow: ToolbarSheets = .none {
|
||||
didSet {
|
||||
sheetToShow != .none ? (showSheet = true) : (showSheet = false)
|
||||
}
|
||||
}
|
||||
@State private var showActionSheet: Bool = false
|
||||
|
||||
var addActionSheetButtons = [
|
||||
Button(action: {}, label: { Text("Add Feed") })
|
||||
@ -22,7 +31,7 @@ struct SidebarToolbar: View {
|
||||
Divider()
|
||||
HStack(alignment: .center) {
|
||||
Button(action: {
|
||||
showSettings = true
|
||||
sheetToShow = .settings
|
||||
}, label: {
|
||||
Image(systemName: "gear")
|
||||
.font(.title3)
|
||||
@ -34,30 +43,36 @@ struct SidebarToolbar: View {
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
Button(action: {
|
||||
showAddSheet = true
|
||||
showActionSheet = true
|
||||
}, label: {
|
||||
Image(systemName: "plus")
|
||||
.font(.title3)
|
||||
.foregroundColor(.accentColor)
|
||||
})
|
||||
.help("Add")
|
||||
.actionSheet(isPresented: $showAddSheet) {
|
||||
.actionSheet(isPresented: $showActionSheet) {
|
||||
ActionSheet(title: Text("Add"), buttons: [
|
||||
.cancel(),
|
||||
.default(Text("Add Web Feed")),
|
||||
.default(Text("Add Web Feed"), action: { sheetToShow = .web }),
|
||||
.default(Text("Add Twitter Feed")),
|
||||
.default(Text("Add Reddit Feed")),
|
||||
.default(Text("Add Folder"))
|
||||
])
|
||||
}
|
||||
|
||||
}
|
||||
.padding(.horizontal, 16)
|
||||
.padding(.bottom, 12)
|
||||
.padding(.top, 4)
|
||||
}
|
||||
.background(VisualEffectBlur(blurStyle: .systemChromeMaterial).edgesIgnoringSafeArea(.bottom))
|
||||
.sheet(isPresented: $showSettings, onDismiss: { showSettings = false }) {
|
||||
SettingsView()
|
||||
.sheet(isPresented: $showSheet, onDismiss: { sheetToShow = .none }) {
|
||||
switch sheetToShow {
|
||||
case .web:
|
||||
AddWebFeedView()
|
||||
default:
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,8 +23,8 @@
|
||||
1776E88F24AC5F8A00E78166 /* AppDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1776E88D24AC5F8A00E78166 /* AppDefaults.swift */; };
|
||||
17925E1724AF41D000D3A4F6 /* String+URLChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17925E1624AF41D000D3A4F6 /* String+URLChecker.swift */; };
|
||||
17925E1824AF41D000D3A4F6 /* String+URLChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17925E1624AF41D000D3A4F6 /* String+URLChecker.swift */; };
|
||||
17930ED424AF10EE00A9BA52 /* AddFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddFeedView.swift */; };
|
||||
17930ED524AF10EE00A9BA52 /* AddFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddFeedView.swift */; };
|
||||
17930ED424AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */; };
|
||||
17930ED524AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */; };
|
||||
179DB1DFBCF9177104B12E0F /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
||||
179DB3CE822BFCC2D774D9F4 /* AccountsNewsBlurWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */; };
|
||||
3B3A32A5238B820900314204 /* FeedWranglerAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */; };
|
||||
@ -1722,7 +1722,7 @@
|
||||
172952AF24AA287100D65E66 /* CompactSidebarContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompactSidebarContainerView.swift; sourceTree = "<group>"; };
|
||||
1776E88D24AC5F8A00E78166 /* AppDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDefaults.swift; sourceTree = "<group>"; };
|
||||
17925E1624AF41D000D3A4F6 /* String+URLChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+URLChecker.swift"; sourceTree = "<group>"; };
|
||||
17930ED324AF10EE00A9BA52 /* AddFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddFeedView.swift; sourceTree = "<group>"; };
|
||||
17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddWebFeedView.swift; sourceTree = "<group>"; };
|
||||
179DBBA2B22A659F81EED6F9 /* AccountsNewsBlurWindowController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountsNewsBlurWindowController.swift; sourceTree = "<group>"; };
|
||||
17B223DB24AC24D2001E4592 /* TimelineLayoutView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineLayoutView.swift; sourceTree = "<group>"; };
|
||||
3B3A328B238B820900314204 /* FeedWranglerAccountViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedWranglerAccountViewController.swift; sourceTree = "<group>"; };
|
||||
@ -2403,7 +2403,7 @@
|
||||
17930ED224AF10CD00A9BA52 /* Add */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
17930ED324AF10EE00A9BA52 /* AddFeedView.swift */,
|
||||
17930ED324AF10EE00A9BA52 /* AddWebFeedView.swift */,
|
||||
);
|
||||
path = Add;
|
||||
sourceTree = "<group>";
|
||||
@ -4856,7 +4856,7 @@
|
||||
51E4993C24A8709900B667CB /* AppDelegate.swift in Sources */,
|
||||
51E498F924A8085D00B667CB /* SmartFeed.swift in Sources */,
|
||||
51A576BB24AE621800078888 /* ArticleModel.swift in Sources */,
|
||||
17930ED424AF10EE00A9BA52 /* AddFeedView.swift in Sources */,
|
||||
17930ED424AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */,
|
||||
51E4995124A8734D00B667CB /* ExtensionPointManager.swift in Sources */,
|
||||
51E4990C24A808C500B667CB /* AuthorAvatarDownloader.swift in Sources */,
|
||||
51E4992124A8095000B667CB /* RSImage-Extensions.swift in Sources */,
|
||||
@ -4883,7 +4883,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
17930ED524AF10EE00A9BA52 /* AddFeedView.swift in Sources */,
|
||||
17930ED524AF10EE00A9BA52 /* AddWebFeedView.swift in Sources */,
|
||||
51E4993A24A8708800B667CB /* AppDelegate.swift in Sources */,
|
||||
51E498CE24A8085D00B667CB /* UnreadFeed.swift in Sources */,
|
||||
51E498C724A8085D00B667CB /* StarredFeedDelegate.swift in Sources */,
|
||||
|
Loading…
x
Reference in New Issue
Block a user