Skip to content

Commit

Permalink
Rebase fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka committed Feb 20, 2024
1 parent e75062e commit 90a360c
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 45 deletions.
4 changes: 2 additions & 2 deletions Zotero/Controllers/AnnotationConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion Zotero/Scenes/Detail/PDF/AnnotationEditCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 1 addition & 1 deletion Zotero/Scenes/Detail/PDF/Models/PDFReaderAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions Zotero/Scenes/Detail/PDF/PDFCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, userInterfaceStyle: UIUserInterfaceStyle?, picked: @escaping ([Tag]) -> Void)
Expand Down Expand Up @@ -362,7 +361,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate {
self.navigationController?.present(controller, animated: true, completion: nil)
}

func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel<ReaderSettingsActionHandler>
func showSettings(with settings: PDFSettings, sender: UIBarButtonItem) -> ViewModel<ReaderSettingsActionHandler> {
DDLogInfo("PDFCoordinator: show settings")

let state = ReaderSettingsState(settings: settings)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 19 additions & 16 deletions Zotero/Scenes/Detail/PDF/Views/PDFDocumentViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import Combine
import CocoaLumberjackSwift
import PSPDFKit
import PSPDFKitUI
import RxSwift
import RealmSwift
import RxSwift

protocol PDFDocumentDelegate: AnyObject {
func annotationTool(
Expand Down Expand Up @@ -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)
}

Expand Down
6 changes: 6 additions & 0 deletions Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,12 @@ extension AnnotationTool {

case .note:
return .note

case .freeText:
return .freeText

case .underline:
return .underline
}
}
}

0 comments on commit 90a360c

Please sign in to comment.