Handle PDFs with new Transimission presentation controllers

This commit is contained in:
Jackson Harper
2023-12-04 12:11:34 +08:00
parent af2759cab0
commit bfd3365f28
10 changed files with 142 additions and 21 deletions

View File

@ -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 = "";

View File

@ -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

View File

@ -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<AnyCancellable>()
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

View File

@ -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:

View File

@ -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)
}
}

View File

@ -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() })
}

View File

@ -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),

View File

@ -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 {

View File

@ -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")

View File

@ -189,6 +189,8 @@
"filesGeneric" = "Files";
"newestGeneric" = "Newest";
"oldestGeneric" = "Oldest";
"longestGeneric" = "Longest";
"shortestGeneric" = "Shortest";
"recentlyReadGeneric" = "Recently Read";
"recentlyPublishedGeneric" = "Recently Published";
"clubsGeneric" = "Clubs";