From bfd3365f28e9418570c33cc97392824dbb455482 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 4 Dec 2023 12:11:34 +0800 Subject: [PATCH] Handle PDFs with new Transimission presentation controllers --- apple/Omnivore.xcodeproj/project.pbxproj | 8 ++-- .../App/PDFSupport/PDFSettingsView.swift | 40 +++++++++++++++++ .../Sources/App/PDFSupport/PDFViewer.swift | 45 ++++++++++++++----- .../App/Views/Home/HomeFeedDisplayText.swift | 4 ++ .../Sources/App/Views/LibraryTabView.swift | 4 +- .../App/Views/LinkItemDetailView.swift | 5 ++- .../Sources/Models/LinkedItemSort.swift | 10 +++++ .../Views/FeedItem/LibraryItemCard.swift | 43 +++++++++++++++--- .../OmnivoreKit/Sources/Views/LocalText.swift | 2 + .../Resources/en.lproj/Localizable.strings | 2 + 10 files changed, 142 insertions(+), 21 deletions(-) create mode 100644 apple/OmnivoreKit/Sources/App/PDFSupport/PDFSettingsView.swift diff --git a/apple/Omnivore.xcodeproj/project.pbxproj b/apple/Omnivore.xcodeproj/project.pbxproj index 33a580418..0e2288668 100644 --- a/apple/Omnivore.xcodeproj/project.pbxproj +++ b/apple/Omnivore.xcodeproj/project.pbxproj @@ -1384,7 +1384,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.39.0; + MARKETING_VERSION = 1.40.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; @@ -1419,7 +1419,7 @@ "@executable_path/../Frameworks", ); MACOSX_DEPLOYMENT_TARGET = 12.0; - MARKETING_VERSION = 1.39.0; + MARKETING_VERSION = 1.40.0; MTL_FAST_MATH = YES; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -1474,7 +1474,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.39.0; + MARKETING_VERSION = 1.40.0; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -1815,7 +1815,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.39.0; + MARKETING_VERSION = 1.40.0; PRODUCT_BUNDLE_IDENTIFIER = app.omnivore.app; PRODUCT_NAME = Omnivore; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFSettingsView.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFSettingsView.swift new file mode 100644 index 000000000..779a748bb --- /dev/null +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFSettingsView.swift @@ -0,0 +1,40 @@ +#if os(iOS) + import Models + import PSPDFKit + import PSPDFKitUI + import SwiftUI + import Utils + import WebKit + + struct PDFSettingsView: UIViewControllerRepresentable { + @Environment(\.presentationMode) var presentationMode + + let pdfViewController: PDFViewController? + + func makeCoordinator() -> PDFSettingsViewCoordinator { + PDFSettingsViewCoordinator(self) + } + + func makeUIViewController(context _: Context) -> some UIViewController { + let settingsViewcontroller = PSPDFKitUI.PDFSettingsViewController() + settingsViewcontroller.pdfViewController = pdfViewController + + let nav = UINavigationController(rootViewController: settingsViewcontroller) + return nav + } + + func updateUIViewController(_: UIViewControllerType, context _: Context) {} + } + + class PDFSettingsViewCoordinator: NSObject, UINavigationControllerDelegate { + var parent: PDFSettingsView + + init(_ parent: PDFSettingsView) { + self.parent = parent + } + + @objc func dismiss() { + parent.presentationMode.wrappedValue.dismiss() + } + } +#endif diff --git a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift index 2eb80d27a..356a4635d 100644 --- a/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift +++ b/apple/OmnivoreKit/Sources/App/PDFSupport/PDFViewer.swift @@ -51,6 +51,9 @@ import Utils @State private var annotation = "" @State private var addNoteHighlight: Highlight? @State private var showAnnotationModal = false + @State private var showSettingsModal = false + + @Environment(\.dismiss) private var dismiss init(viewModel: PDFViewerViewModel) { self.viewModel = viewModel @@ -103,19 +106,13 @@ import Utils guard pdfStateObject.controllerNeedsConfig else { return } coordinator.setController(controller: controller, dataService: dataService) - // Disable the Document Editor - controller.navigationItem.setRightBarButtonItems( - [controller.thumbnailsButtonItem], - for: .thumbnails, - animated: false - ) - let barButtonItems = [ UIBarButtonItem( image: UIImage(systemName: "textformat"), style: .plain, - target: controller.settingsButtonItem.target, - action: controller.settingsButtonItem.action + target: coordinator, + action: #selector(PDFViewCoordinator.displaySettingsSheet) + ), UIBarButtonItem( image: UIImage(systemName: "book"), @@ -137,6 +134,15 @@ import Utils ) ] + let leftButtonItems = [ + UIBarButtonItem( + image: UIImage(named: "chevron-right", in: Bundle(url: ViewsPackage.bundleURL), with: nil), + style: .plain, + target: coordinator, + action: #selector(PDFViewCoordinator.pop) + ) + ] + document.areAnnotationsEnabled = true coordinator.viewer = self @@ -146,6 +152,7 @@ import Utils controller.setPageIndex(pageIndex, animated: false) } + controller.navigationItem.setLeftBarButtonItems(leftButtonItems, for: .document, animated: false) controller.navigationItem.setRightBarButtonItems(barButtonItems, for: .document, animated: false) pdfStateObject.controllerNeedsConfig = false } @@ -215,6 +222,12 @@ import Utils } .navigationViewStyle(StackNavigationViewStyle()) } + .formSheet(isPresented: $showSettingsModal, modalSize: CGSize(width: 400, height: 475)) { + NavigationView { + PDFSettingsView(pdfViewController: coordinator.controller) + } + .navigationViewStyle(StackNavigationViewStyle()) + } .fullScreenCover(isPresented: $readerView, content: { PDFReaderViewController(document: document) }) @@ -263,7 +276,7 @@ import Utils var subscriptions = Set() public var viewer: PDFViewer? - var controller: PDFViewController? + public var controller: PDFViewController? init(document: Document, viewModel: PDFViewerViewModel) { self.document = document @@ -446,12 +459,24 @@ import Utils } } + @objc public func pop() { + if let viewer = self.viewer { + viewer.dismiss() + } + } + @objc public func toggleReaderView() { if let viewer = self.viewer { viewer.readerView = !viewer.readerView } } + @objc public func displaySettingsSheet() { + if let viewer = self.viewer { + viewer.showSettingsModal = true + } + } + @objc public func toggleNotebookView() { if let viewer = self.viewer { viewer.showNotebookView = !viewer.showNotebookView diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedDisplayText.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedDisplayText.swift index 285c020fd..6d71255b0 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedDisplayText.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedDisplayText.swift @@ -38,6 +38,10 @@ public extension LinkedItemSort { return LocalText.newestGeneric case .oldest: return LocalText.oldestGeneric + case .longest: + return LocalText.longestGeneric + case .shortest: + return LocalText.shortestGeneric case .recentlyRead: return LocalText.recentlyReadGeneric case .recentlyPublished: diff --git a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift index 0d3ac6ef4..f3f5eb256 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LibraryTabView.swift @@ -10,6 +10,7 @@ import Models import PopupView import Services import SwiftUI +import Transmission import Utils import Views @@ -46,7 +47,7 @@ struct LibraryTabView: View { ) var body: some View { - VStack(spacing: 0) { + VStack { TabView(selection: $selectedTab) { NavigationView { HomeFeedContainerView(viewModel: followingViewModel) @@ -66,5 +67,6 @@ struct LibraryTabView: View { CustomTabBar(selectedTab: $selectedTab) } .ignoresSafeArea() + .navigationBarHidden(true) } } diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index 8b0a1f010..8fa4a26bf 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -87,7 +87,10 @@ struct LinkItemDetailView: View { var body: some View { Group { if isPDF { - pdfContainerView + NavigationView { + pdfContainerView + .navigationBarBackButtonHidden(false) + } } else if let item = viewModel.item { WebReaderContainerView(item: item, pop: { dismiss() }) } diff --git a/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift b/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift index 4759b3a2d..5b0ced288 100644 --- a/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift +++ b/apple/OmnivoreKit/Sources/Models/LinkedItemSort.swift @@ -3,6 +3,8 @@ import Foundation public enum LinkedItemSort: String, CaseIterable { case newest case oldest + case shortest + case longest case recentlyRead case recentlyPublished } @@ -14,6 +16,10 @@ public extension LinkedItemSort { return "sort:saved" case .oldest: return "sort:saved-ASC" + case .longest: + return "sort:wordsCount-desc" + case .shortest: + return "sort:wordsCount-asc" case .recentlyRead: return "sort:read" case .recentlyPublished: @@ -27,6 +33,10 @@ public extension LinkedItemSort { return [NSSortDescriptor(keyPath: \LibraryItem.savedAt, ascending: false)] case .oldest: return [NSSortDescriptor(keyPath: \LibraryItem.savedAt, ascending: true)] + case .shortest: + return [NSSortDescriptor(keyPath: \LibraryItem.wordsCount, ascending: true)] + case .longest: + return [NSSortDescriptor(keyPath: \LibraryItem.wordsCount, ascending: false)] case .recentlyRead: return [ NSSortDescriptor(keyPath: \LibraryItem.readAt, ascending: false), diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift index 1797ac986..af4885352 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift @@ -289,12 +289,45 @@ public struct LibraryItemCard: View { return "" } + func shouldHideUrl(_ url: String?) -> Bool { + if let url = url, let origin = URL(string: url)?.host { + let hideHosts = ["storage.googleapis.com", "omnivore.app"] + if hideHosts.contains(origin) { + return true + } + } + + return false + } + + func siteName(_ originalArticleUrl: String?) -> String? { + if shouldHideUrl(originalArticleUrl) { + return nil + } + + if let url = originalArticleUrl, + let originalHost = URL(string: url)?.host?.replacingOccurrences(of: "^www\\.", with: "", options: .regularExpression) + { + return originalHost + } + + return nil + } + var byLine: some View { - Text(bylineStr) - .font(.caption2) - .foregroundColor(Color.themeLibraryItemSubtle) - .frame(maxWidth: .infinity, alignment: .leading) - .lineLimit(1) + if let origin = siteName(item.pageURLString) { + Text(bylineStr + " | " + origin) + .font(.caption2) + .foregroundColor(Color.themeLibraryItemSubtle) + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) + } else { + Text(bylineStr) + .font(.caption2) + .foregroundColor(Color.themeLibraryItemSubtle) + .frame(maxWidth: .infinity, alignment: .leading) + .lineLimit(1) + } } public var articleInfo: some View { diff --git a/apple/OmnivoreKit/Sources/Views/LocalText.swift b/apple/OmnivoreKit/Sources/Views/LocalText.swift index 2fc984a17..42625397e 100644 --- a/apple/OmnivoreKit/Sources/Views/LocalText.swift +++ b/apple/OmnivoreKit/Sources/Views/LocalText.swift @@ -190,6 +190,8 @@ public enum LocalText { public static let filesGeneric = localText(key: "filesGeneric") public static let newestGeneric = localText(key: "newestGeneric") public static let oldestGeneric = localText(key: "oldestGeneric") + public static let longestGeneric = localText(key: "longestGeneric") + public static let shortestGeneric = localText(key: "shortestGeneric") public static let recentlyReadGeneric = localText(key: "recentlyReadGeneric") public static let recentlyPublishedGeneric = localText(key: "recentlyPublishedGeneric") public static let clubsGeneric = localText(key: "clubsGeneric") diff --git a/apple/OmnivoreKit/Sources/Views/Resources/en.lproj/Localizable.strings b/apple/OmnivoreKit/Sources/Views/Resources/en.lproj/Localizable.strings index d69e034ce..78b678a32 100644 --- a/apple/OmnivoreKit/Sources/Views/Resources/en.lproj/Localizable.strings +++ b/apple/OmnivoreKit/Sources/Views/Resources/en.lproj/Localizable.strings @@ -189,6 +189,8 @@ "filesGeneric" = "Files"; "newestGeneric" = "Newest"; "oldestGeneric" = "Oldest"; +"longestGeneric" = "Longest"; +"shortestGeneric" = "Shortest"; "recentlyReadGeneric" = "Recently Read"; "recentlyPublishedGeneric" = "Recently Published"; "clubsGeneric" = "Clubs";