From 89b7fe2bee20c35c3430ad380bbd05f662f8cac4 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 8 Mar 2022 10:41:45 -0800 Subject: [PATCH 1/3] drop 'link' from 'Delete link' menu option --- .../App/Views/Home/HomeFeedViewIOS.swift | 2 +- .../App/Views/Home/HomeFeedViewMac.swift | 2 +- .../App/Views/LinkItemDetailView.swift | 38 +++++++++---------- .../Sources/Utils/FeatureFlags.swift | 1 - .../Sources/Views/FeedItem/GridCard.swift | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift index cacd54ce8..b74242259 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewIOS.swift @@ -195,7 +195,7 @@ import Views itemToRemove = item confirmationShown = true }, - label: { Label("Delete Link", systemImage: "trash") } + label: { Label("Delete", systemImage: "trash") } ) if FeatureFlag.enableSnooze { Button { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift index ae02dc4ff..bd4849c14 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift @@ -51,7 +51,7 @@ import Views itemToRemove = item confirmationShown = true }, - label: { Label("Delete Link", systemImage: "trash") } + label: { Label("Delete", systemImage: "trash") } ) if FeatureFlag.enableSnooze { Button { diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index d6f276e69..780a62eb3 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -169,27 +169,25 @@ struct LinkItemDetailView: View { ) .padding(.horizontal) .scaleEffect(navBarVisibilityRatio) - if FeatureFlag.showLinkOptionsOnReaderView { - Menu( - content: { - Group { - Button( - action: {}, - label: { Label("Archive", systemImage: "archivebox") } - ) - Button( - action: {}, - label: { Label("Delete Link", systemImage: "trash") } - ) - } - }, - label: { - Image.profile - .padding(.horizontal) - .scaleEffect(navBarVisibilityRatio) + Menu( + content: { + Group { + Button( + action: {}, + label: { Label("Archive", systemImage: "archivebox") } + ) + Button( + action: {}, + label: { Label("Delete", systemImage: "trash") } + ) } - ) - } + }, + label: { + Image.profile + .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) + } + ) } .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) .opacity(navBarVisibilityRatio) diff --git a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift index a5a911bd4..67a1faf37 100644 --- a/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift +++ b/apple/OmnivoreKit/Sources/Utils/FeatureFlags.swift @@ -15,5 +15,4 @@ public enum FeatureFlag { public static let enableShareButton = false public static let enableSnooze = false public static let showFeedItemTags = false - public static let showLinkOptionsOnReaderView = false } diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift index 9049024b1..17f1c1c49 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/GridCard.swift @@ -53,7 +53,7 @@ public struct GridCard: View { ) Button( action: { menuActionHandler(.delete) }, - label: { Label("Delete Link", systemImage: "trash") } + label: { Label("Delete", systemImage: "trash") } ) } } From e5a3fdc2d3910cca1a3f62a82973a257f2adabf3 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 8 Mar 2022 11:13:28 -0800 Subject: [PATCH 2/3] update styling and position of font size popover --- .../Sources/App/Views/LinkItemDetailView.swift | 5 ++++- .../Sources/Views/Article/WebAppViewCoordinator.swift | 6 ++++-- apple/OmnivoreKit/Sources/Views/Colors/Colors.swift | 9 +++++++++ .../Sources/Views/FontSizeAdjustmentPopoverView.swift | 8 +++++--- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 780a62eb3..521c82c5d 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -192,6 +192,9 @@ struct LinkItemDetailView: View { .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) .opacity(navBarVisibilityRatio) .background(Color.systemBackground) + .onTapGesture { + showFontSizePopover = false + } } #if os(iOS) @@ -217,7 +220,7 @@ struct LinkItemDetailView: View { fontAdjustmentPopoverView .background(Color.appButtonBackground) .cornerRadius(8) - .padding(.trailing, 5) + .padding(.trailing, 44) } Spacer() } diff --git a/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift b/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift index 09305f8c3..430d17591 100644 --- a/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift +++ b/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift @@ -44,8 +44,10 @@ extension WebAppViewCoordinator: WKNavigationDelegate { } func webView(_ webView: WKWebView, didFinish _: WKNavigation!) { - webView.isOpaque = true - webView.backgroundColor = .systemBackground + #if os(iOS) + webView.isOpaque = true + webView.backgroundColor = .systemBackground + #endif } } diff --git a/apple/OmnivoreKit/Sources/Views/Colors/Colors.swift b/apple/OmnivoreKit/Sources/Views/Colors/Colors.swift index e3270b61c..03c20e65d 100644 --- a/apple/OmnivoreKit/Sources/Views/Colors/Colors.swift +++ b/apple/OmnivoreKit/Sources/Views/Colors/Colors.swift @@ -22,9 +22,18 @@ public extension Color { static var systemBackground: Color { Color(.systemBackground) } static var systemPlaceholder: Color { Color(.placeholderText) } static var secondarySystemGroupedBackground: Color { Color(.secondarySystemGroupedBackground) } + static var systemLabel: Color { + if #available(iOS 15.0, *) { + return Color(uiColor: .label) + } else { + return Color.appGrayTextContrast + } + } + #elseif os(macOS) static var systemBackground: Color { Color(.windowBackgroundColor) } static var systemPlaceholder: Color { Color(.placeholderTextColor) } + static var systemLabel: Color { Color(.labelColor) } // Just for compilation. secondarySystemGroupedBackground shouldn't be used on macOS static var secondarySystemGroupedBackground: Color { Color(.windowBackgroundColor) } diff --git a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift index 76ec5520e..11f5131d5 100644 --- a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift +++ b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift @@ -30,13 +30,15 @@ public struct FontSizeAdjustmentPopoverView: View { label: { Image(systemName: "minus") #if os(iOS) - .foregroundColor(.appGraySolid) + .foregroundColor(.systemLabel) .padding() #endif } ) .frame(width: 55, height: 40, alignment: .center) - Divider().frame(height: 30) + Divider() + .frame(height: 30) + .background(Color.systemLabel) Button( action: { storedFontSize = min(storedFontSize + 2, 28) @@ -45,7 +47,7 @@ public struct FontSizeAdjustmentPopoverView: View { label: { Image(systemName: "plus") #if os(iOS) - .foregroundColor(.appGraySolid) + .foregroundColor(.systemLabel) .padding() #endif } From 97cc4db30eca10d521291bdc1199615a199e14ba Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Tue, 8 Mar 2022 12:44:03 -0800 Subject: [PATCH 3/3] handle reader context menu actions --- .../Components/FeedCardNavigationLink.swift | 4 +- .../App/Views/LinkItemDetailView.swift | 116 ++++++++++++++---- 2 files changed, 96 insertions(+), 24 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift index 3d60094ff..fc530d3f1 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/Components/FeedCardNavigationLink.swift @@ -15,7 +15,7 @@ struct FeedCardNavigationLink: View { var body: some View { NavigationLink( - destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)), + destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, homeFeedViewModel: viewModel)), tag: item, selection: $selectedLinkItem ) { @@ -48,7 +48,7 @@ struct GridCardNavigationLink: View { var body: some View { ZStack { NavigationLink( - destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item)), + destination: LinkItemDetailView(viewModel: LinkItemDetailViewModel(item: item, homeFeedViewModel: viewModel)), isActive: $isActive ) { EmptyView() diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 521c82c5d..3f0d9cead 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -10,18 +10,23 @@ enum PDFProvider { } final class LinkItemDetailViewModel: ObservableObject { + let homeFeedViewModel: HomeFeedViewModel @Published var item: FeedItem @Published var webAppWrapperViewModel: WebAppWrapperViewModel? - enum Action { - case load - case updateReadStatus(markAsRead: Bool) - } - var subscriptions = Set() - init(item: FeedItem) { + init(item: FeedItem, homeFeedViewModel: HomeFeedViewModel) { self.item = item + self.homeFeedViewModel = homeFeedViewModel + } + + func handleArchiveAction(dataService: DataService) { + homeFeedViewModel.setLinkArchived(dataService: dataService, linkId: item.id, archived: !item.isArchived) + } + + func handleDeleteAction(dataService: DataService) { + homeFeedViewModel.removeLink(dataService: dataService, linkId: item.id) } func updateItemReadStatus(dataService: DataService) { @@ -103,6 +108,7 @@ struct LinkItemDetailView: View { @ObservedObject private var viewModel: LinkItemDetailViewModel @State private var showFontSizePopover = false @State private var navBarVisibilityRatio = 1.0 + @State private var showDeleteConfirmation = false init(viewModel: LinkItemDetailViewModel) { self.viewModel = viewModel @@ -147,6 +153,38 @@ struct LinkItemDetailView: View { #endif } + var navBariOS14: some View { + HStack(alignment: .center) { + Button( + action: { self.presentationMode.wrappedValue.dismiss() }, + label: { + Image(systemName: "chevron.backward") + .font(.appTitleTwo) + .foregroundColor(.appGrayTextContrast) + .padding(.horizontal) + } + ) + .scaleEffect(navBarVisibilityRatio) + Spacer() + Button( + action: { showFontSizePopover.toggle() }, + label: { + Image(systemName: "textformat.size") + .font(.appTitleTwo) + } + ) + .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) + } + .frame(height: readerViewNavBarHeight * navBarVisibilityRatio) + .opacity(navBarVisibilityRatio) + .background(Color.systemBackground) + .onTapGesture { + showFontSizePopover = false + } + } + + @available(iOS 15.0, *) var navBar: some View { HStack(alignment: .center) { Button( @@ -173,11 +211,16 @@ struct LinkItemDetailView: View { content: { Group { Button( - action: {}, - label: { Label("Archive", systemImage: "archivebox") } + action: { viewModel.handleArchiveAction(dataService: dataService) }, + label: { + Label( + viewModel.item.isArchived ? "Unarchive" : "Archive", + systemImage: viewModel.item.isArchived ? "tray.and.arrow.down.fill" : "archivebox" + ) + } ) Button( - action: {}, + action: { showDeleteConfirmation = true }, label: { Label("Delete", systemImage: "trash") } ) } @@ -195,6 +238,12 @@ struct LinkItemDetailView: View { .onTapGesture { showFontSizePopover = false } + .alert("Are you sure?", isPresented: $showDeleteConfirmation) { + Button("Remove Link", role: .destructive) { + viewModel.handleDeleteAction(dataService: dataService) + } + Button("Cancel", role: .cancel, action: {}) + } } #if os(iOS) @@ -232,24 +281,47 @@ struct LinkItemDetailView: View { } ) } + if #available(iOS 15.0, *) { + VStack(spacing: 0) { + navBar + Spacer() + } + .navigationBarHidden(true) + } else { + VStack(spacing: 0) { + navBariOS14 + Spacer() + } + .navigationBarHidden(true) + } + } + + } else { + if #available(iOS 15.0, *) { VStack(spacing: 0) { navBar Spacer() } + .onAppear { + viewModel.loadWebAppWrapper( + dataService: dataService, + rawAuthCookie: authenticator.omnivoreAuthCookieString + ) + } + .navigationBarHidden(true) + } else { + VStack(spacing: 0) { + navBariOS14 + Spacer() + } + .onAppear { + viewModel.loadWebAppWrapper( + dataService: dataService, + rawAuthCookie: authenticator.omnivoreAuthCookieString + ) + } + .navigationBarHidden(true) } - .navigationBarHidden(true) - } else { - VStack(spacing: 0) { - navBar - Spacer() - } - .onAppear { - viewModel.loadWebAppWrapper( - dataService: dataService, - rawAuthCookie: authenticator.omnivoreAuthCookieString - ) - } - .navigationBarHidden(true) } } #endif