From 85f91df70d1e966ece633b04ffab8a804dacfb3f Mon Sep 17 00:00:00 2001 From: Michal Rentka Date: Fri, 14 Jul 2023 10:20:54 +0200 Subject: [PATCH] Added more logs for basic UI actions (#728) --- Zotero/Scenes/Detail/DetailCoordinator.swift | 108 ++++++++++++++---- .../Views/ItemDetailViewController.swift | 16 ++- .../Items/Views/ItemsViewController.swift | 14 ++- .../Detail/Lookup/LookupCoordinator.swift | 30 ++++- Zotero/Scenes/Detail/PDF/PDFCoordinator.swift | 12 ++ .../Scenes/Master/MasterTopCoordinator.swift | 50 ++++++-- 6 files changed, 184 insertions(+), 46 deletions(-) diff --git a/Zotero/Scenes/Detail/DetailCoordinator.swift b/Zotero/Scenes/Detail/DetailCoordinator.swift index 0589cdf17..a675d55dd 100644 --- a/Zotero/Scenes/Detail/DetailCoordinator.swift +++ b/Zotero/Scenes/Detail/DetailCoordinator.swift @@ -25,7 +25,7 @@ protocol DetailItemsCoordinatorDelegate: AnyObject { func showCollectionsPicker(in library: Library, completed: @escaping (Set) -> Void) func showItemDetail(for type: ItemDetailState.DetailType, library: Library, scrolledToKey childKey: String?, animated: Bool) func showAttachmentError(_ error: Error) - func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) + func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, key: String?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) func showAddActions(viewModel: ViewModel, button: UIBarButtonItem) func showSortActions(viewModel: ViewModel, button: UIBarButtonItem) func show(url: URL) @@ -41,7 +41,7 @@ protocol DetailItemsCoordinatorDelegate: AnyObject { } protocol DetailItemDetailCoordinatorDelegate: AnyObject { - func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) + func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, key: String?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) func showAttachmentPicker(save: @escaping ([URL]) -> Void) func showTagPicker(libraryId: LibraryIdentifier, selected: Set, picked: @escaping ([Tag]) -> Void) func showTypePicker(selected: String, picked: @escaping (String) -> Void) @@ -115,6 +115,7 @@ final class DetailCoordinator: Coordinator { func start(animated: Bool) { guard let userControllers = self.controllers.userControllers else { return } + DDLogInfo("DetailCoordinator: show items for \(self.collection.id); \(self.library.id)") let controller = self.createItemsViewController( collection: self.collection, library: self.library, @@ -180,29 +181,39 @@ final class DetailCoordinator: Coordinator { switch contentType { case "application/pdf": + DDLogInfo("DetailCoordinator: show PDF \(attachment.key)") self.showPdf(at: url, key: attachment.key, library: library) + case "text/html": + DDLogInfo("DetailCoordinator: show HTML \(attachment.key)") self.showWebView(for: url) + case "text/plain": let text = try? String(contentsOf: url, encoding: .utf8) if let text = text { + DDLogInfo("DetailCoordinator: show plain text \(attachment.key)") self.show(text: text, title: filename) } else { + DDLogInfo("DetailCoordinator: share plain text \(attachment.key)") self.share(item: url, sourceView: .view(sourceView, rect)) } + case _ where contentType.contains("image"): - let image = (contentType == "image/gif") ? (try? Data(contentsOf: url)).flatMap({ try? UIImage(gifData: $0) }) : - UIImage(contentsOfFile: url.path) + let image = (contentType == "image/gif") ? (try? Data(contentsOf: url)).flatMap({ try? UIImage(gifData: $0) }) : UIImage(contentsOfFile: url.path) if let image = image { + DDLogInfo("DetailCoordinator: show image \(attachment.key)") self.show(image: image, title: filename) } else { - self.share(item: url, sourceView: .view(sourceView, rect)) + DDLogInfo("DetailCoordinator: share image \(attachment.key)") + self.share(item: url, sourceView: .view(sourceView, rect)) } default: if AVURLAsset(url: url).isPlayable { + DDLogInfo("DetailCoordinator: show video \(attachment.key)") self.showVideo(for: url) } else { + DDLogInfo("DetailCoordinator: share attachment \(attachment.key)") self.share(item: file.createUrl(), sourceView: .view(sourceView, rect)) } } @@ -239,6 +250,8 @@ final class DetailCoordinator: Coordinator { func showTagPicker(libraryId: LibraryIdentifier, selected: Set, userInterfaceStyle: UIUserInterfaceStyle?, navigationController: UINavigationController?, picked: @escaping ([Tag]) -> Void) { guard let navigationController, let dbStorage = self.controllers.userControllers?.dbStorage else { return } + DDLogInfo("DetailCoordinator: show tag picker for \(libraryId)") + let state = TagPickerState(libraryId: libraryId, selectedTags: selected) let handler = TagPickerActionHandler(dbStorage: dbStorage) let viewModel = ViewModel(initialState: state, handler: handler) @@ -275,10 +288,13 @@ final class DetailCoordinator: Coordinator { func show(doi: String) { guard let url = URL(string: "https://doi.org/\(doi)") else { return } + DDLogInfo("DetailCoordinator: show DOI \(doi)") self.showWeb(url: url) } func show(url: URL) { + DDLogInfo("DetailCoordinator: show url \(url.absoluteString)") + if let scheme = url.scheme, scheme != "http" && scheme != "https" { UIApplication.shared.open(url) } else { @@ -343,6 +359,8 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { } func showSortActions(viewModel: ViewModel, button: UIBarButtonItem) { + DDLogInfo("DetailCoordinator: show item sort popup") + let navigationController = UINavigationController() navigationController.modalPresentationStyle = UIDevice.current.userInterfaceIdiom == .pad ? .popover : .formSheet navigationController.popoverPresentationController?.barButtonItem = button @@ -394,16 +412,30 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { private func sortButtonTitles(for sortType: ItemsSortType) -> (field: String, order: String) { let sortOrderTitle = sortType.ascending ? L10n.Items.ascending : L10n.Items.descending - return ("\(L10n.Items.sortBy): \(sortType.field.title)", - "\(L10n.Items.sortOrder): \(sortOrderTitle)") + return ("\(L10n.Items.sortBy): \(sortType.field.title)", "\(L10n.Items.sortOrder): \(sortOrderTitle)") } - func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) { + func showNote(with text: String, tags: [Tag], title: NoteEditorState.TitleData?, key: String?, libraryId: LibraryIdentifier, readOnly: Bool, save: @escaping (String, [Tag]) -> Void) { + if let key = key { + DDLogInfo("DetailCoordinator: show note \(key)") + } else { + DDLogInfo("DetailCoordinator: show note creation") + } + let navigationController = NavigationViewController() navigationController.modalPresentationStyle = .fullScreen navigationController.isModalInPresentation = true - let coordinator = NoteEditorCoordinator(text: text, tags: tags, title: title, libraryId: libraryId, readOnly: readOnly, save: save, navigationController: navigationController, controllers: self.controllers) + let coordinator = NoteEditorCoordinator( + text: text, + tags: tags, + title: title, + libraryId: libraryId, + readOnly: readOnly, + save: save, + navigationController: navigationController, + controllers: self.controllers + ) coordinator.parentCoordinator = self self.childCoordinators.append(coordinator) coordinator.start(animated: false) @@ -414,17 +446,31 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { func showItemDetail(for type: ItemDetailState.DetailType, library: Library, scrolledToKey childKey: String?, animated: Bool) { guard let dbStorage = self.controllers.userControllers?.dbStorage, let fileDownloader = self.controllers.userControllers?.fileDownloader, - let fileCleanupController = self.controllers.userControllers?.fileCleanupController else { return } + let fileCleanupController = self.controllers.userControllers?.fileCleanupController + else { return } + + switch type { + case .preview(let key): + DDLogInfo("DetailCoordinator: show item detail \(key)") + + case .duplication(let itemKey, let collectionKey): + DDLogInfo("DetailCoordinator: show item duplication for \(itemKey); \(String(describing: collectionKey))") + + case .creation: + DDLogInfo("DetailCoordinator: show item creation") + } let state = ItemDetailState(type: type, library: library, preScrolledChildKey: childKey, userId: Defaults.shared.userId) - let handler = ItemDetailActionHandler(apiClient: self.controllers.apiClient, - fileStorage: self.controllers.fileStorage, - dbStorage: dbStorage, - schemaController: self.controllers.schemaController, - dateParser: self.controllers.dateParser, - urlDetector: self.controllers.urlDetector, - fileDownloader: fileDownloader, - fileCleanupController: fileCleanupController) + let handler = ItemDetailActionHandler( + apiClient: self.controllers.apiClient, + fileStorage: self.controllers.fileStorage, + dbStorage: dbStorage, + schemaController: self.controllers.schemaController, + dateParser: self.controllers.dateParser, + urlDetector: self.controllers.urlDetector, + fileDownloader: fileDownloader, + fileCleanupController: fileCleanupController + ) let viewModel = ViewModel(initialState: state, handler: handler) let controller = ItemDetailViewController(viewModel: viewModel, controllers: self.controllers) @@ -435,6 +481,8 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { func showCollectionsPicker(in library: Library, completed: @escaping (Set) -> Void) { guard let dbStorage = self.controllers.userControllers?.dbStorage else { return } + DDLogInfo("DetailCoordinator: show collection picker") + let state = CollectionsPickerState(library: library, excludedKeys: [], selected: []) let handler = CollectionsPickerActionHandler(dbStorage: dbStorage) let viewModel = ViewModel(initialState: state, handler: handler) @@ -447,6 +495,8 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { } func showFilters(viewModel: ViewModel, itemsController: ItemsViewController, button: UIBarButtonItem) { + DDLogInfo("DetailCoordinator: show item filters") + let navigationController = NavigationViewController() navigationController.modalPresentationStyle = UIDevice.current.userInterfaceIdiom == .pad ? .popover : .formSheet navigationController.popoverPresentationController?.barButtonItem = button @@ -483,8 +533,15 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { func showCitation(for itemIds: Set, libraryId: LibraryIdentifier) { guard let citationController = self.controllers.userControllers?.citationController else { return } - let state = SingleCitationState(itemIds: itemIds, libraryId: libraryId, styleId: Defaults.shared.quickCopyStyleId, - localeId: Defaults.shared.quickCopyLocaleId, exportAsHtml: Defaults.shared.quickCopyAsHtml) + DDLogInfo("DetailCoordinator: show citation popup for \(itemIds)") + + let state = SingleCitationState( + itemIds: itemIds, + libraryId: libraryId, + styleId: Defaults.shared.quickCopyStyleId, + localeId: Defaults.shared.quickCopyLocaleId, + exportAsHtml: Defaults.shared.quickCopyAsHtml + ) let handler = SingleCitationActionHandler(citationController: citationController) let viewModel = ViewModel(initialState: state, handler: handler) @@ -519,18 +576,18 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { coordinator.parentCoordinator = self self.childCoordinators.append(coordinator) coordinator.start(animated: false) - self.navigationController?.present(containerController, animated: true, completion: nil) } func showCiteExport(for itemIds: Set, libraryId: LibraryIdentifier) { + DDLogInfo("DetailCoordinator: show citation/bibliography export for \(itemIds)") + let navigationController = NavigationViewController() let containerController = ContainerViewController(rootViewController: navigationController) let coordinator = CitationBibliographyExportCoordinator(itemIds: itemIds, libraryId: libraryId, navigationController: navigationController, controllers: self.controllers) coordinator.parentCoordinator = self self.childCoordinators.append(coordinator) coordinator.start(animated: false) - self.navigationController?.present(containerController, animated: true, completion: nil) } @@ -589,7 +646,7 @@ extension DetailCoordinator: DetailItemsCoordinatorDelegate { extension DetailCoordinator: DetailItemActionSheetCoordinatorDelegate { func showNoteCreation(title: NoteEditorState.TitleData?, libraryId: LibraryIdentifier, save: @escaping (String, [Tag]) -> Void) { - self.showNote(with: "", tags: [], title: title, libraryId: libraryId, readOnly: false, save: save) + self.showNote(with: "", tags: [], title: title, key: nil, libraryId: libraryId, readOnly: false, save: save) } func showAttachmentPicker(save: @escaping ([URL]) -> Void) { @@ -679,6 +736,8 @@ extension DetailCoordinator: DetailItemDetailCoordinatorDelegate { } private func _showCreatorEditor(for creator: ItemDetailState.Creator, itemType: String, saved: @escaping CreatorEditSaveAction, deleted: CreatorEditDeleteAction?) { + DDLogInfo("DetailCoordinator: show item detail creator editor for \(creator.type)") + let navigationController = NavigationViewController() navigationController.isModalInPresentation = true navigationController.modalPresentationStyle = .formSheet @@ -692,6 +751,7 @@ extension DetailCoordinator: DetailItemDetailCoordinatorDelegate { } func showTypePicker(selected: String, picked: @escaping (String) -> Void) { + DDLogInfo("DetailCoordinator: show item type picker") let viewModel = ItemTypePickerViewModelCreator.create(selected: selected, schemaController: self.controllers.schemaController) self.presentPicker(viewModel: viewModel, requiresSaveButton: false, saveAction: picked) } @@ -818,6 +878,8 @@ extension DetailCoordinator: DetailNoteEditorCoordinatorDelegate { func pushTagPicker(libraryId: LibraryIdentifier, selected: Set, picked: @escaping ([Tag]) -> Void) { guard let dbStorage = self.controllers.userControllers?.dbStorage else { return } + DDLogInfo("DetailCoordinator: push tag picker for \(libraryId)") + let state = TagPickerState(libraryId: libraryId, selectedTags: selected) let handler = TagPickerActionHandler(dbStorage: dbStorage) let viewModel = ViewModel(initialState: state, handler: handler) diff --git a/Zotero/Scenes/Detail/ItemDetail/Views/ItemDetailViewController.swift b/Zotero/Scenes/Detail/ItemDetail/Views/ItemDetailViewController.swift index a0c6a8072..6ad808e9b 100644 --- a/Zotero/Scenes/Detail/ItemDetail/Views/ItemDetailViewController.swift +++ b/Zotero/Scenes/Detail/ItemDetail/Views/ItemDetailViewController.swift @@ -124,10 +124,17 @@ final class ItemDetailViewController: UIViewController { let library = self.viewModel.state.library let key = note?.key ?? KeyGenerator.newKey let title = NoteEditorState.TitleData(type: self.viewModel.state.data.type, title: self.viewModel.state.data.title) - self.coordinatorDelegate?.showNote(with: (note?.text ?? ""), tags: (note?.tags ?? []), title: title, - libraryId: library.identifier, readOnly: !library.metadataEditable, save: { [weak self] text, tags in - self?.viewModel.process(action: .saveNote(key: key, text: text, tags: tags)) - }) + self.coordinatorDelegate?.showNote( + with: (note?.text ?? ""), + tags: (note?.tags ?? []), + title: title, + key: note?.key, + libraryId: library.identifier, + readOnly: !library.metadataEditable, + save: { [weak self] text, tags in + self?.viewModel.process(action: .saveNote(key: key, text: text, tags: tags)) + } + ) case .openTagPicker: self.coordinatorDelegate?.showTagPicker(libraryId: self.viewModel.state.library.identifier, @@ -195,6 +202,7 @@ final class ItemDetailViewController: UIViewController { if state.changes.contains(.editing) || state.changes.contains(.type) { if state.changes.contains(.editing) { + DDLogInfo("ItemDetailViewController: editing changed to \(state.isEditing)") self.setNavigationBarButtons(to: state) } if state.changes.contains(.type) { diff --git a/Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift b/Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift index ca11d1a36..77d6c09b4 100644 --- a/Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift +++ b/Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift @@ -414,9 +414,17 @@ final class ItemsViewController: UIViewController { guard let note = Note(item: item) else { return } let tags = Array(item.tags.map({ Tag(tag: $0) })) let library = self.viewModel.state.library - self.coordinatorDelegate?.showNote(with: note.text, tags: tags, title: nil, libraryId: library.identifier, readOnly: !library.metadataEditable, save: { [weak self] newText, newTags in - self?.viewModel.process(action: .saveNote(note.key, newText, newTags)) - }) + self.coordinatorDelegate?.showNote( + with: note.text, + tags: tags, + title: nil, + key: note.key, + libraryId: library.identifier, + readOnly: !library.metadataEditable, + save: { [weak self] newText, newTags in + self?.viewModel.process(action: .saveNote(note.key, newText, newTags)) + } + ) default: self.coordinatorDelegate?.showItemDetail(for: .preview(key: item.key), library: self.viewModel.state.library, scrolledToKey: nil, animated: true) diff --git a/Zotero/Scenes/Detail/Lookup/LookupCoordinator.swift b/Zotero/Scenes/Detail/Lookup/LookupCoordinator.swift index b88f0b9ca..1032c1a41 100644 --- a/Zotero/Scenes/Detail/Lookup/LookupCoordinator.swift +++ b/Zotero/Scenes/Detail/Lookup/LookupCoordinator.swift @@ -8,6 +8,7 @@ import UIKit +import CocoaLumberjackSwift import RxSwift enum LookupStartingView { @@ -43,19 +44,38 @@ final class LookupCoordinator: NSObject, Coordinator { } func start(animated: Bool) { - let controller = self.startingView == .manual ? self.manualController : self.scannerController + let controller: UIViewController + switch self.startingView { + case .manual: + DDLogInfo("LookupCoordinator: show manual lookup") + controller = self.manualController + + case .scanner: + DDLogInfo("LookupCoordinator: show scanner lookup") + controller = self.scannerController + } self.navigationController?.setViewControllers([controller], animated: animated) } private func lookupController(multiLookupEnabled: Bool, hasDarkBackground: Bool, userControllers: UserControllers) -> LookupViewController { let collectionKeys = Defaults.shared.selectedCollectionId.key.flatMap({ Set([$0]) }) ?? [] let state = LookupState(multiLookupEnabled: multiLookupEnabled, hasDarkBackground: hasDarkBackground, collectionKeys: collectionKeys, libraryId: Defaults.shared.selectedLibrary) - let handler = LookupActionHandler(dbStorage: userControllers.dbStorage, fileStorage: self.controllers.fileStorage, translatorsController: self.controllers.translatorsAndStylesController, - schemaController: self.controllers.schemaController, dateParser: self.controllers.dateParser, remoteFileDownloader: userControllers.remoteFileDownloader) + let handler = LookupActionHandler( + dbStorage: userControllers.dbStorage, + fileStorage: self.controllers.fileStorage, + translatorsController: self.controllers.translatorsAndStylesController, + schemaController: self.controllers.schemaController, + dateParser: self.controllers.dateParser, + remoteFileDownloader: userControllers.remoteFileDownloader + ) let viewModel = ViewModel(initialState: state, handler: handler) - return LookupViewController(viewModel: viewModel, remoteDownloadObserver: userControllers.remoteFileDownloader.observable, remoteFileDownloader: userControllers.remoteFileDownloader, - schemaController: self.controllers.schemaController) + return LookupViewController( + viewModel: viewModel, + remoteDownloadObserver: userControllers.remoteFileDownloader.observable, + remoteFileDownloader: userControllers.remoteFileDownloader, + schemaController: self.controllers.schemaController + ) } private var scannerController: UIViewController { diff --git a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift index b99671d85..f31af92fb 100644 --- a/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift +++ b/Zotero/Scenes/Detail/PDF/PDFCoordinator.swift @@ -120,6 +120,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { userInterfaceStyle: UIUserInterfaceStyle, valueChanged: @escaping (String?, Float?) -> Void ) { + DDLogInfo("PDFCoordinator: show tool settings for \(tool)") let state = AnnotationToolOptionsState(tool: tool, colorHex: colorHex, size: sizeValue) let handler = AnnotationToolOptionsActionHandler() let controller = AnnotationToolOptionsViewController(viewModel: ViewModel(initialState: state, handler: handler), valueChanged: valueChanged) @@ -148,6 +149,8 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { func showAnnotationPopover(viewModel: ViewModel, sourceRect: CGRect, popoverDelegate: UIPopoverPresentationControllerDelegate, userInterfaceStyle: UIUserInterfaceStyle) { guard let currentNavigationController = self.navigationController else { return } + DDLogInfo("PDFCoordinator: show annotation popover") + if let coordinator = self.childCoordinators.last, coordinator is AnnotationPopoverCoordinator { return } @@ -172,6 +175,8 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { } func showSearch(pdfController: PDFViewController, text: String?, sender: UIBarButtonItem, userInterfaceStyle: UIUserInterfaceStyle, result: @escaping (SearchResult) -> Void) { + DDLogInfo("PDFCoordinator: show search") + if let existing = self.pdfSearchController { if let controller = existing.presentingViewController { controller.dismiss(animated: true) { [weak self] in @@ -206,6 +211,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { } func lookup(text: String, rect: CGRect, view: UIView, userInterfaceStyle: UIUserInterfaceStyle) { + DDLogInfo("PDFCoordinator: show lookup") let controller = UIReferenceLibraryViewController(term: text) controller.overrideUserInterfaceStyle = userInterfaceStyle controller.modalPresentationStyle = .popover @@ -275,6 +281,8 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { } func showSettings(with settings: PDFSettings, sender: UIBarButtonItem, userInterfaceStyle: UIUserInterfaceStyle, completion: @escaping (PDFSettings) -> Void) { + DDLogInfo("PDFCoordinator: show settings") + let state = PDFSettingsState(settings: settings) let viewModel = ViewModel(initialState: state, handler: PDFSettingsActionHandler()) @@ -298,6 +306,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { } func showReader(document: Document, userInterfaceStyle: UIUserInterfaceStyle) { + DDLogInfo("PDFCoordinator: show plain text reader") let controller = PDFPlainReaderViewController(document: document) let navigationController = UINavigationController(rootViewController: controller) navigationController.overrideUserInterfaceStyle = userInterfaceStyle @@ -306,6 +315,7 @@ extension PDFCoordinator: PdfReaderCoordinatorDelegate { } func showPdfExportSettings(sender: UIBarButtonItem, userInterfaceStyle: UIUserInterfaceStyle, completed: @escaping (PDFExportSettings) -> Void) { + DDLogInfo("PDFCoordinator: show PDF export") let view = PDFExportSettingsView(settings: PDFExportSettings(includeAnnotations: true), exportHandler: { [weak self] settings in self?.navigationController?.dismiss(animated: true, completion: { completed(settings) @@ -457,6 +467,8 @@ extension PDFCoordinator: PdfAnnotationsCoordinatorDelegate { userInterfaceStyle: UIUserInterfaceStyle, completed: @escaping (AnnotationsFilter?) -> Void ) { + DDLogInfo("PDFCoordinator: show annotations filter popup") + let navigationController = NavigationViewController() navigationController.overrideUserInterfaceStyle = userInterfaceStyle diff --git a/Zotero/Scenes/Master/MasterTopCoordinator.swift b/Zotero/Scenes/Master/MasterTopCoordinator.swift index fac39c87d..f390127d0 100644 --- a/Zotero/Scenes/Master/MasterTopCoordinator.swift +++ b/Zotero/Scenes/Master/MasterTopCoordinator.swift @@ -9,6 +9,7 @@ import UIKit import SwiftUI +import CocoaLumberjackSwift import RxSwift protocol MasterLibrariesCoordinatorDelegate: AnyObject { @@ -50,8 +51,12 @@ final class MasterTopCoordinator: NSObject, Coordinator { func start(animated: Bool) { guard let userControllers = self.controllers.userControllers else { return } let librariesController = self.createLibrariesViewController(dbStorage: userControllers.dbStorage) - let collectionsController = self.createCollectionsViewController(libraryId: self.visibleLibraryId, selectedCollectionId: Defaults.shared.selectedCollectionId, - dbStorage: userControllers.dbStorage, attachmentDownloader: userControllers.fileDownloader) + let collectionsController = self.createCollectionsViewController( + libraryId: self.visibleLibraryId, + selectedCollectionId: Defaults.shared.selectedCollectionId, + dbStorage: userControllers.dbStorage, + attachmentDownloader: userControllers.fileDownloader + ) self.navigationController?.setViewControllers([librariesController, collectionsController], animated: animated) } @@ -62,7 +67,13 @@ final class MasterTopCoordinator: NSObject, Coordinator { return controller } - private func createCollectionsViewController(libraryId: LibraryIdentifier, selectedCollectionId: CollectionIdentifier, dbStorage: DbStorage, attachmentDownloader: AttachmentDownloader) -> CollectionsViewController { + private func createCollectionsViewController( + libraryId: LibraryIdentifier, + selectedCollectionId: CollectionIdentifier, + dbStorage: DbStorage, + attachmentDownloader: AttachmentDownloader + ) -> CollectionsViewController { + DDLogInfo("MasterTopCoordinator: show collections for \(selectedCollectionId.id); \(libraryId)") let handler = CollectionsActionHandler(dbStorage: dbStorage, fileStorage: self.controllers.fileStorage, attachmentDownloader: attachmentDownloader) let state = CollectionsState(libraryId: libraryId, selectedCollectionId: selectedCollectionId) return CollectionsViewController(viewModel: ViewModel(initialState: state, handler: handler), dragDropController: self.controllers.dragDropController, coordinatorDelegate: self) @@ -91,7 +102,12 @@ extension MasterTopCoordinator: MasterLibrariesCoordinatorDelegate { let libraryId = LibraryIdentifier.custom(.myLibrary) let collectionId = self.storeIfNeeded(libraryId: libraryId) - let controller = self.createCollectionsViewController(libraryId: libraryId, selectedCollectionId: collectionId, dbStorage: userControllers.dbStorage, attachmentDownloader: userControllers.fileDownloader) + let controller = self.createCollectionsViewController( + libraryId: libraryId, + selectedCollectionId: collectionId, + dbStorage: userControllers.dbStorage, + attachmentDownloader: userControllers.fileDownloader + ) let animated: Bool var viewControllers = self.navigationController?.viewControllers ?? [] @@ -138,7 +154,12 @@ extension MasterTopCoordinator: MasterLibrariesCoordinatorDelegate { let collectionId = self.storeIfNeeded(libraryId: libraryId) - let controller = self.createCollectionsViewController(libraryId: libraryId, selectedCollectionId: collectionId, dbStorage: userControllers.dbStorage, attachmentDownloader: userControllers.fileDownloader) + let controller = self.createCollectionsViewController( + libraryId: libraryId, + selectedCollectionId: collectionId, + dbStorage: userControllers.dbStorage, + attachmentDownloader: userControllers.fileDownloader + ) self.navigationController?.pushViewController(controller, animated: true) } @@ -149,11 +170,21 @@ extension MasterTopCoordinator: MasterLibrariesCoordinatorDelegate { if navigationController.viewControllers.count == 1 { // If only "Libraries" screen is visible, push collections - let controller = self.createCollectionsViewController(libraryId: libraryId, selectedCollectionId: collectionId, dbStorage: userControllers.dbStorage, attachmentDownloader: userControllers.fileDownloader) + let controller = self.createCollectionsViewController( + libraryId: libraryId, + selectedCollectionId: collectionId, + dbStorage: userControllers.dbStorage, + attachmentDownloader: userControllers.fileDownloader + ) navigationController.pushViewController(controller, animated: animated) } else if libraryId != self.visibleLibraryId { // If Collections screen is visible, but for different library, switch controllers - let controller = self.createCollectionsViewController(libraryId: libraryId, selectedCollectionId: collectionId, dbStorage: userControllers.dbStorage, attachmentDownloader: userControllers.fileDownloader) + let controller = self.createCollectionsViewController( + libraryId: libraryId, + selectedCollectionId: collectionId, + dbStorage: userControllers.dbStorage, + attachmentDownloader: userControllers.fileDownloader + ) var viewControllers = navigationController.viewControllers _ = viewControllers.popLast() @@ -184,10 +215,7 @@ extension MasterTopCoordinator: MasterCollectionsCoordinatorDelegate { navigationController.isModalInPresentation = true navigationController.modalPresentationStyle = .formSheet - let coordinator = CollectionEditingCoordinator(data: data, - library: library, - navigationController: navigationController, - controllers: self.controllers) + let coordinator = CollectionEditingCoordinator(data: data, library: library, navigationController: navigationController, controllers: self.controllers) coordinator.parentCoordinator = self self.childCoordinators.append(coordinator) coordinator.start(animated: false)