Skip to content

Commit

Permalink
PR bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka committed Jan 14, 2025
1 parent 37f89ef commit a0c47ee
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 39 deletions.
4 changes: 4 additions & 0 deletions Zotero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@
B3A17D1927FC33B800322CAD /* LowPowerModeController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A17D1827FC33B800322CAD /* LowPowerModeController.swift */; };
B3A27ACD25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A27ACC25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift */; };
B3A27AD125BEE93400DE0BB2 /* FilenameFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A27AD025BEE93400DE0BB2 /* FilenameFormatter.swift */; };
B3A297B72D366B23008AD19D /* SegmentedControlCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */; };
B3A2AECC26552248004BF3A4 /* SettingsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AECB26552248004BF3A4 /* SettingsCoordinator.swift */; };
B3A2AECE26553DD8004BF3A4 /* NavigationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AECD26553DD8004BF3A4 /* NavigationViewController.swift */; };
B3A2AEDC2656511D004BF3A4 /* StylesRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3A2AEDB2656511D004BF3A4 /* StylesRequest.swift */; };
Expand Down Expand Up @@ -1911,6 +1912,7 @@
B3A17D1827FC33B800322CAD /* LowPowerModeController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LowPowerModeController.swift; sourceTree = "<group>"; };
B3A27ACC25BEE91A00DE0BB2 /* TranslationWebViewHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TranslationWebViewHandler.swift; sourceTree = "<group>"; };
B3A27AD025BEE93400DE0BB2 /* FilenameFormatter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FilenameFormatter.swift; sourceTree = "<group>"; };
B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SegmentedControlCell.swift; sourceTree = "<group>"; };
B3A2AECB26552248004BF3A4 /* SettingsCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCoordinator.swift; sourceTree = "<group>"; };
B3A2AECD26553DD8004BF3A4 /* NavigationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationViewController.swift; sourceTree = "<group>"; };
B3A2AEDB2656511D004BF3A4 /* StylesRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StylesRequest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3134,6 +3136,7 @@
B398D6BF2A77F9C60049A296 /* FontSizeView.swift */,
B34A4B7126E65FC200B3E993 /* LineWidthCell.swift */,
B34A4B6F26E63C9900B3E993 /* LineWidthView.swift */,
B3A297B62D366B23008AD19D /* SegmentedControlCell.swift */,
B34DF1BB2576956F0019CCD1 /* SwitchCell.swift */,
B34DF1BC2576956F0019CCD1 /* SwitchCell.xib */,
B398142C257A649D002C755C /* TextContentEditCell.swift */,
Expand Down Expand Up @@ -4968,6 +4971,7 @@
B30566AF23FC051F003304F2 /* LibraryResponse.swift in Sources */,
B33F47732CA1656E00278240 /* BaseItemsActionHandler.swift in Sources */,
B3868537270D90640068A022 /* RawDataEncoding.swift in Sources */,
B3A297B72D366B23008AD19D /* SegmentedControlCell.swift in Sources */,
B37C5B6D26453C58009A37E5 /* NoteEditorAction.swift in Sources */,
B30566C223FC051F003304F2 /* LibraryData.swift in Sources */,
B391480726D9093E0016B7B2 /* UIPasteboard+Extensions.swift in Sources */,
Expand Down
2 changes: 0 additions & 2 deletions Zotero/Assets/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@
"pdf.annotation_popover.no_comment" = "No comment";
"pdf.annotation_popover.line_width" = "Width";
"pdf.annotation_popover.size" = "Size";
"pdf.annotation_popover.convert_to_underline" = "Convert to Underline";
"pdf.annotation_popover.convert_to_highlight" = "Convert to Highlight";
"pdf.deleted_title" = "Deleted";
"pdf.deleted_message" = "This document has been deleted. Do you want to restore it?";
"pdf.line_width_point" = "%0.1f pt";
Expand Down
4 changes: 0 additions & 4 deletions Zotero/Extensions/Localizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -956,10 +956,6 @@ internal enum L10n {
/// Underline
internal static let underline = L10n.tr("Localizable", "pdf.underline", fallback: "Underline")
internal enum AnnotationPopover {
/// Convert to Highlight
internal static let convertToHighlight = L10n.tr("Localizable", "pdf.annotation_popover.convert_to_highlight", fallback: "Convert to Highlight")
/// Convert to Underline
internal static let convertToUnderline = L10n.tr("Localizable", "pdf.annotation_popover.convert_to_underline", fallback: "Convert to Underline")
/// Delete Annotation
internal static let delete = L10n.tr("Localizable", "pdf.annotation_popover.delete", fallback: "Delete Annotation")
/// Width
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ enum AnnotationEditAction {
case setPageLabel(String, Bool)
case setHighlight(NSAttributedString)
case setFontSize(CGFloat)
case convertBetweenHighlightAndUnderline
case setAnnotationType(AnnotationType)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,10 @@ struct AnnotationEditActionHandler: ViewModelActionHandler {
state.fontSize = size
}

case .convertBetweenHighlightAndUnderline:
case .setAnnotationType(let type):
update(viewModel: viewModel) { state in
switch state.type {
case .highlight:
state.type = .underline
state.changes = .type

case .underline:
state.type = .highlight
state.changes = .type

case .freeText, .image, .ink, .note:
break
}
state.type = type
state.changes = .type
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ final class AnnotationEditViewController: UIViewController {
tableView.register(ColorPickerCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0, propertyRows: [.colorPicker]))
tableView.register(LineWidthCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0, propertyRows: [.lineWidth]))
tableView.register(FontSizeCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0, propertyRows: [.fontSize]))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0, propertyRows: [.highlightUnderlineSwitch]))
tableView.register(SegmentedControlCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0, propertyRows: [.highlightUnderlineSwitch]))
tableView.register(TextContentEditCell.self, forCellReuseIdentifier: Section.textContent.cellId(index: 0, propertyRows: []))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.actions.cellId(index: 0, propertyRows: []))
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.pageLabel.cellId(index: 0, propertyRows: []))
Expand All @@ -174,9 +174,6 @@ final class AnnotationEditViewController: UIViewController {
if state.changes.contains(.color) {
reload(sections: [.properties, .textContent])
}
if state.changes.contains(.type) {
reload(sections: [.properties])
}
if state.changes.contains(.pageLabel) {
reload(sections: [.pageLabel])
}
Expand Down Expand Up @@ -257,18 +254,15 @@ extension AnnotationEditViewController: UITableViewDataSource {
.disposed(by: cell.disposeBag)
} else if let cell = cell as? LineWidthCell {
cell.set(value: Float(viewModel.state.lineWidth))
cell.valueObservable.subscribe(onNext: { value in self.viewModel.process(action: .setLineWidth(CGFloat(value))) }).disposed(by: cell.disposeBag)
cell.valueObservable.subscribe(onNext: { [weak viewModel] value in viewModel?.process(action: .setLineWidth(CGFloat(value))) }).disposed(by: cell.disposeBag)
} else if let cell = cell as? FontSizeCell {
cell.set(value: viewModel.state.fontSize)
cell.valueObservable.subscribe(onNext: { value in self.viewModel.process(action: .setFontSize(value)) }).disposed(by: cell.disposeBag)
} else {
if viewModel.state.type == .highlight {
cell.textLabel?.text = L10n.Pdf.AnnotationPopover.convertToUnderline
} else {
cell.textLabel?.text = L10n.Pdf.AnnotationPopover.convertToHighlight
cell.valueObservable.subscribe(onNext: { [weak viewModel] value in viewModel?.process(action: .setFontSize(value)) }).disposed(by: cell.disposeBag)
} else if let cell = cell as? SegmentedControlCell {
let selected = viewModel.state.type == .highlight ? 0 : 1
cell.setup(selected: selected, segments: [L10n.Pdf.highlight, L10n.Pdf.underline]) { [weak viewModel] selected in
viewModel?.process(action: .setAnnotationType(selected == 0 ? .highlight : .underline))
}
cell.textLabel?.textColor = Asset.Colors.zoteroBlueWithDarkMode.color
cell.accessoryType = .none
}

case .textContent:
Expand Down Expand Up @@ -329,18 +323,14 @@ extension AnnotationEditViewController: UITableViewDelegate {
case .properties:
guard indexPath.row < propertyRows.count else { return }
switch propertyRows[indexPath.row] {
case .colorPicker, .lineWidth:
case .colorPicker, .lineWidth, .highlightUnderlineSwitch:
break

case .fontSize:
coordinatorDelegate?.showFontSizePicker(picked: { [weak self, weak tableView] newSize in
self?.viewModel.process(action: .setFontSize(newSize))
tableView?.reloadRows(at: [indexPath], with: .none)
})

case .highlightUnderlineSwitch:
guard viewModel.state.isEditable else { return }
viewModel.process(action: .convertBetweenHighlightAndUnderline)
}

case .actions:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// SegmentedControlCell.swift
// Zotero
//
// Created by Michal Rentka on 14.01.2025.
// Copyright © 2025 Corporation for Digital Scholarship. All rights reserved.
//

import UIKit

class SegmentedControlCell: UITableViewCell {
private weak var segmentedControl: UISegmentedControl?

private var selectionChanged: ((Int) -> Void)?

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
selectionStyle = .none

func setup() {
let segmentedControl = UISegmentedControl()
segmentedControl.addAction(UIAction(handler: { [weak self] _ in
self?.selectionChanged?(self?.segmentedControl?.selectedSegmentIndex ?? 0)
}), for: .valueChanged)
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(segmentedControl)
self.segmentedControl = segmentedControl

NSLayoutConstraint.activate([
segmentedControl.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 8),
contentView.bottomAnchor.constraint(equalTo: segmentedControl.bottomAnchor, constant: 8),
segmentedControl.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 15),
contentView.trailingAnchor.constraint(equalTo: segmentedControl.trailingAnchor, constant: 15)
])
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
super.prepareForReuse()
selectionChanged = nil
}

func setup(selected: Int, segments: [String], selectionChanged: @escaping (Int) -> Void) {
self.selectionChanged = selectionChanged
segmentedControl?.removeAllSegments()
for (idx, segment) in segments.enumerated() {
segmentedControl?.insertSegment(withTitle: segment, at: idx, animated: false)
}
segmentedControl?.selectedSegmentIndex = selected < segments.count ? selected : 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class PDFReaderViewController: UIViewController {

if state.changes.contains(.selectionDeletion) {
// Hide popover if annotation has been deleted
if (presentedViewController as? UINavigationController)?.viewControllers.first is AnnotationPopover {
if let navigationController = presentedViewController as? UINavigationController, navigationController.viewControllers.first is AnnotationPopover, !navigationController.isBeingDismissed {
dismiss(animated: true, completion: nil)
}
}
Expand Down

0 comments on commit a0c47ee

Please sign in to comment.