From 971d0335125575d0e98a617eccd9b90c0c41f5b0 Mon Sep 17 00:00:00 2001 From: Michal Rentka Date: Mon, 29 Jan 2024 15:40:22 +0100 Subject: [PATCH] Rebase fixes --- Zotero/Controllers/AnnotationConverter.swift | 4 +-- .../Views/AnnotationEditViewController.swift | 8 ++--- .../AnnotationPopoverViewController.swift | 3 +- .../Views/AnnotationViewController.swift | 17 +-------- .../PDF/AnnotationEditCoordinator.swift | 2 +- .../Detail/PDF/Models/PDFReaderAction.swift | 2 +- Zotero/Scenes/Detail/PDF/PDFCoordinator.swift | 3 +- .../AnnotationToolbarViewController.swift | 2 +- .../Views/PDFAnnotationsViewController.swift | 2 +- .../PDF/Views/PDFDocumentViewController.swift | 35 ++++++++++--------- .../PDF/Views/PDFReaderViewController.swift | 6 ++++ 11 files changed, 39 insertions(+), 45 deletions(-) diff --git a/Zotero/Controllers/AnnotationConverter.swift b/Zotero/Controllers/AnnotationConverter.swift index 899f5c056..dcccf279b 100644 --- a/Zotero/Controllers/AnnotationConverter.swift +++ b/Zotero/Controllers/AnnotationConverter.swift @@ -360,7 +360,7 @@ struct AnnotationConverter { return ink } - private static func underlineAnnotation(from annotation: Annotation, type: Kind, boundingBoxConverter: AnnotationBoundingBoxConverter) -> PSPDFKit.UnderlineAnnotation { + private static func underlineAnnotation(from annotation: PDFAnnotation, type: Kind, boundingBoxConverter: AnnotationBoundingBoxConverter) -> PSPDFKit.UnderlineAnnotation { let underline: PSPDFKit.UnderlineAnnotation switch type { case .export: @@ -376,7 +376,7 @@ struct AnnotationConverter { return underline } - private static func freeTextAnnotation(from annotation: Annotation, color: UIColor, boundingBoxConverter: AnnotationBoundingBoxConverter) -> PSPDFKit.FreeTextAnnotation { + private static func freeTextAnnotation(from annotation: PDFAnnotation, color: UIColor, boundingBoxConverter: AnnotationBoundingBoxConverter) -> PSPDFKit.FreeTextAnnotation { let text = PSPDFKit.FreeTextAnnotation(contents: annotation.comment) text.color = color text.fontSize = CGFloat(annotation.fontSize ?? 0) diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift index abdb81d96..a8ae7975e 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationEditViewController.swift @@ -11,8 +11,8 @@ import UIKit import RxSwift // key, color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText -typealias AnnotationEditSaveAction = (PDFReaderState.AnnotationKey, String, CGFloat, UInt, String, Bool, String) -> Void -typealias AnnotationEditDeleteAction = (PDFReaderState.AnnotationKey) -> Void +typealias AnnotationEditSaveAction = (String, CGFloat, UInt, String, Bool, String) -> Void +typealias AnnotationEditDeleteAction = () -> Void final class AnnotationEditViewController: UIViewController { private enum Section { @@ -174,8 +174,8 @@ final class AnnotationEditViewController: UIViewController { .subscribe(onNext: { [weak self] in guard let self else { return } let state = viewModel.state - saveAction(state.key, state.color, state.lineWidth, state.fontSize, state.pageLabel, state.updateSubsequentLabels, state.highlightText) - cancel() + saveAction(state.color, state.lineWidth, state.fontSize, state.pageLabel, state.updateSubsequentLabels, state.highlightText) + self.cancel() }) .disposed(by: self.disposeBag) diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationPopoverViewController.swift b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationPopoverViewController.swift index 809407816..76d8ebf3d 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationPopoverViewController.swift +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationPopoverViewController.swift @@ -121,9 +121,10 @@ final class AnnotationPopoverViewController: UIViewController { } private func showSettings() { + // key, color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText coordinatorDelegate?.showEdit( state: viewModel.state, - saveAction: { [weak self] _, _, pageLabel, updateSubsequentLabels, highlightText in + saveAction: { [weak self] _, _, _, pageLabel, updateSubsequentLabels, highlightText in self?.viewModel.process(action: .setProperties(pageLabel: pageLabel, updateSubsequentLabels: updateSubsequentLabels, highlightText: highlightText)) }, deleteAction: { [weak self] in diff --git a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationViewController.swift b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationViewController.swift index 8087e9b37..ebcb9225c 100644 --- a/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationViewController.swift +++ b/Zotero/Scenes/Detail/Annotation Popover/Views/AnnotationViewController.swift @@ -134,41 +134,26 @@ final class AnnotationViewController: UIViewController { private func showSettings() { guard let annotation = self.viewModel.state.selectedAnnotation else { return } -<<<<<<< HEAD let key = annotation.readerKey -======= ->>>>>>> 74e1d1e3 (Font size picker added, annotation popup updated with font options) self.coordinatorDelegate?.showEdit( annotation: annotation, userId: self.viewModel.state.userId, library: self.viewModel.state.library, -<<<<<<< HEAD - saveAction: { [weak self] color, lineWidth, pageLabel, updateSubsequentLabels, highlightText in -======= - saveAction: { [weak self] key, color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText in ->>>>>>> 74e1d1e3 (Font size picker added, annotation popup updated with font options) + saveAction: { [weak self] color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText in self?.viewModel.process( action: .updateAnnotationProperties( key: key.key, color: color, lineWidth: lineWidth, -<<<<<<< HEAD -======= fontSize: fontSize, ->>>>>>> 74e1d1e3 (Font size picker added, annotation popup updated with font options) pageLabel: pageLabel, updateSubsequentLabels: updateSubsequentLabels, highlightText: highlightText ) ) }, -<<<<<<< HEAD deleteAction: { [weak self] in self?.viewModel.process(action: .removeAnnotation(key)) -======= - deleteAction: { [weak self] key in - self?.viewModel.process(action: .removeAnnotation(key)) ->>>>>>> 74e1d1e3 (Font size picker added, annotation popup updated with font options) } ) } diff --git a/Zotero/Scenes/Detail/PDF/AnnotationEditCoordinator.swift b/Zotero/Scenes/Detail/PDF/AnnotationEditCoordinator.swift index 5c96c1ffe..200ef56a9 100644 --- a/Zotero/Scenes/Detail/PDF/AnnotationEditCoordinator.swift +++ b/Zotero/Scenes/Detail/PDF/AnnotationEditCoordinator.swift @@ -53,7 +53,7 @@ final class AnnotationEditCoordinator: Coordinator { let controller = AnnotationEditViewController( viewModel: viewModel, includeColorPicker: true, - includeFontPicker: annotation.type == .freeText, + includeFontPicker: data.type == .freeText, saveAction: self.saveAction, deleteAction: self.deleteAction ) diff --git a/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift b/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift index 8b03093ec..3291bc480 100644 --- a/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift +++ b/Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift @@ -41,7 +41,7 @@ enum PDFReaderAction { case setCommentActive(Bool) case setVisiblePage(page: Int, userActionFromDocument: Bool, fromThumbnailList: Bool) case setFontSize(key: String, size: UInt) - case export(PDFExportSettings) + case export(includeAnnotations: Bool) case clearTmpData case setSidebarEditingEnabled(Bool) case setSettings(settings: PDFSettings, parentUserInterfaceStyle: UIUserInterfaceStyle) diff --git a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift index 524a36470..673a80049 100644 --- a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift +++ b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift @@ -33,7 +33,6 @@ protocol PdfReaderCoordinatorDelegate: AnyObject { func showReader(document: Document, userInterfaceStyle: UIUserInterfaceStyle) func showCitation(for itemId: String, libraryId: LibraryIdentifier) func copyBibliography(using presenter: UIViewController, for itemId: String, libraryId: LibraryIdentifier) - func showPdfExportSettings(sender: UIBarButtonItem, userInterfaceStyle: UIUserInterfaceStyle, completed: @escaping (PDFExportSettings) -> Void) func showFontSizePicker(sender: UIView, picked: @escaping (UInt) -> Void) func showDeleteAlertForAnnotation(sender: UIView, delete: @escaping () -> Void) func showTagPicker(libraryId: LibraryIdentifier, selected: Set, userInterfaceStyle: UIUserInterfaceStyle?, picked: @escaping ([Tag]) -> Void) @@ -362,7 +361,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { self.navigationController?.present(controller, animated: true, completion: nil) } - func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel + func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel { DDLogInfo("PDFCoordinator: show settings") let state = ReaderSettingsState(settings: settings) diff --git a/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift b/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift index 57106210d..bf9ac0b88 100644 --- a/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift @@ -274,7 +274,7 @@ class AnnotationToolbarViewController: UIViewController { let imageName: String switch tool { - case .ink, .square, .highlight, .note, .freeText, .underline: + case .ink, .image, .highlight, .note, .freeText, .underline: imageName = "circle.fill" default: diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFAnnotationsViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFAnnotationsViewController.swift index b1b53d237..0f32734c7 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFAnnotationsViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFAnnotationsViewController.swift @@ -126,7 +126,7 @@ final class PDFAnnotationsViewController: UIViewController { library: self.viewModel.state.library, sender: sender, userInterfaceStyle: self.viewModel.state.interfaceStyle, - saveAction: { [weak self] key, color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText in + saveAction: { [weak self] color, lineWidth, fontSize, pageLabel, updateSubsequentLabels, highlightText in self?.viewModel.process( action: .updateAnnotationProperties( key: key.key, diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift index ca935c698..295ff77b5 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift @@ -12,8 +12,8 @@ import Combine import CocoaLumberjackSwift import PSPDFKit import PSPDFKitUI -import RxSwift import RealmSwift +import RxSwift protocol PDFDocumentDelegate: AnyObject { func annotationTool( @@ -354,50 +354,53 @@ final class PDFDocumentViewController: UIViewController { } private func showPopupAnnotationIfNeeded(state: PDFReaderState) { - guard !(self.parentDelegate?.isSidebarVisible ?? false), + guard !(parentDelegate?.isSidebarVisible ?? false), let annotation = state.selectedAnnotation, annotation.type != .freeText, - let pageView = self.pdfController?.pageViewForPage(at: UInt(annotation.page)) else { return } + let pageView = pdfController?.pageViewForPage(at: UInt(annotation.page)) else { return } let key = annotation.readerKey - var frame = self.view.convert(annotation.boundingBox(boundingBoxConverter: self), from: pageView.pdfCoordinateSpace) - frame.origin.y += (self.parentDelegate?.statusBarHeight ?? 0) + (self.parentDelegate?.navigationBarHeight ?? 0) - let observable = self.coordinatorDelegate?.showAnnotationPopover( - viewModel: self.viewModel, + var frame = view.convert(annotation.boundingBox(boundingBoxConverter: self), from: pageView.pdfCoordinateSpace) + frame.origin.y += (parentDelegate?.statusBarHeight ?? 0) + (parentDelegate?.navigationBarHeight ?? 0) + let observable = coordinatorDelegate?.showAnnotationPopover( + viewModel: viewModel, sourceRect: frame, popoverDelegate: self, - userInterfaceStyle: self.viewModel.state.settings.appearanceMode.userInterfaceStyle + userInterfaceStyle: viewModel.state.settings.appearanceMode.userInterfaceStyle ) guard let observable else { return } - observable.subscribe(with: self) { `self`, state in + observable.subscribe(onNext: { [weak self] state in + guard let self else { return } if state.changes.contains(.color) { - self.viewModel.process(action: .setColor(key: key.key, color: state.color)) + viewModel.process(action: .setColor(key: key.key, color: state.color)) } if state.changes.contains(.comment) { - self.viewModel.process(action: .setComment(key: key.key, comment: state.comment)) + viewModel.process(action: .setComment(key: key.key, comment: state.comment)) } if state.changes.contains(.deletion) { - self.viewModel.process(action: .removeAnnotation(key)) + viewModel.process(action: .removeAnnotation(key)) } if state.changes.contains(.lineWidth) { - self.viewModel.process(action: .setLineWidth(key: key.key, width: state.lineWidth)) + viewModel.process(action: .setLineWidth(key: key.key, width: state.lineWidth)) } if state.changes.contains(.tags) { - self.viewModel.process(action: .setTags(key: key.key, tags: state.tags)) + viewModel.process(action: .setTags(key: key.key, tags: state.tags)) } if state.changes.contains(.pageLabel) || state.changes.contains(.highlight) { - self.viewModel.process(action: + // TODO: - fix font size + viewModel.process(action: .updateAnnotationProperties( key: key.key, color: state.color, lineWidth: state.lineWidth, + fontSize: 0, pageLabel: state.pageLabel, updateSubsequentLabels: state.updateSubsequentLabels, highlightText: state.highlightText) ) } - } + }) .disposed(by: disposeBag) } diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift index 36b4b8ac6..fb2b5346c 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift @@ -916,6 +916,12 @@ extension AnnotationTool { case .note: return .note + + case .freeText: + return .freeText + + case .underline: + return .underline } } }