From a435a238d2b3d1814b87d3b66b1a0e5432723273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Mon, 27 May 2024 15:33:13 +0200 Subject: [PATCH 1/2] Fix Test App using CocoaPods --- TestApp/Integrations/CocoaPods/Podfile | 4 ++-- TestApp/Integrations/CocoaPods/Podfile+lcp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TestApp/Integrations/CocoaPods/Podfile b/TestApp/Integrations/CocoaPods/Podfile index 4e6096387..6d02b2e2f 100644 --- a/TestApp/Integrations/CocoaPods/Podfile +++ b/TestApp/Integrations/CocoaPods/Podfile @@ -1,4 +1,4 @@ -platform :ios, '11.0' +platform :ios, '14.0' target 'TestApp' do # Comment the next line if you don't want to use dynamic frameworks @@ -23,7 +23,7 @@ end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' config.build_settings['ENABLE_BITCODE'] = 'NO' end end diff --git a/TestApp/Integrations/CocoaPods/Podfile+lcp b/TestApp/Integrations/CocoaPods/Podfile+lcp index 73d89db23..be1610358 100644 --- a/TestApp/Integrations/CocoaPods/Podfile+lcp +++ b/TestApp/Integrations/CocoaPods/Podfile+lcp @@ -1,4 +1,4 @@ -platform :ios, '11.0' +platform :ios, '14.0' target 'TestApp' do # Comment the next line if you don't want to use dynamic frameworks @@ -25,7 +25,7 @@ end post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| - config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0' + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '14.0' config.build_settings['ENABLE_BITCODE'] = 'NO' end end From 961959721bf7e367a6a49113fd06c794cb4a13f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Menu?= Date: Tue, 28 May 2024 16:34:30 +0200 Subject: [PATCH 2/2] Fix build when LCP is disabled --- .../LCPManagementTableViewController.swift | 186 +++++++++--------- TestApp/Sources/Reader/ReaderFactory.swift | 24 ++- TestApp/Sources/Reader/ReaderModule.swift | 16 +- 3 files changed, 118 insertions(+), 108 deletions(-) diff --git a/TestApp/Sources/Reader/Common/DRM/LCPManagementTableViewController.swift b/TestApp/Sources/Reader/Common/DRM/LCPManagementTableViewController.swift index c4ba6fa88..6cead4ea7 100644 --- a/TestApp/Sources/Reader/Common/DRM/LCPManagementTableViewController.swift +++ b/TestApp/Sources/Reader/Common/DRM/LCPManagementTableViewController.swift @@ -8,109 +8,113 @@ import ReadiumNavigator import ReadiumShared import UIKit -protocol LCPManagementTableViewControllerFactory { - func make(publication: Publication, delegate: ReaderModuleDelegate?) -> LCPManagementTableViewController? -} +#if LCP -class LCPManagementTableViewController: UITableViewController { - @IBOutlet var stateLabel: UILabel! - @IBOutlet var typeLabel: UILabel! - @IBOutlet var providerLabel: UILabel! - @IBOutlet var issuedLabel: UILabel! - @IBOutlet var updatedLabel: UILabel! + protocol LCPManagementTableViewControllerFactory { + func make(publication: Publication, delegate: ReaderModuleDelegate?) -> LCPManagementTableViewController? + } - @IBOutlet var startLabel: UILabel! - @IBOutlet var endLabel: UILabel! - @IBOutlet var printsLeftLabel: UILabel! - @IBOutlet var copiesLeftLabel: UILabel! + class LCPManagementTableViewController: UITableViewController { + @IBOutlet var stateLabel: UILabel! + @IBOutlet var typeLabel: UILabel! + @IBOutlet var providerLabel: UILabel! + @IBOutlet var issuedLabel: UILabel! + @IBOutlet var updatedLabel: UILabel! - @IBOutlet var renewButton: UIButton! - @IBOutlet var returnButton: UIButton! + @IBOutlet var startLabel: UILabel! + @IBOutlet var endLabel: UILabel! + @IBOutlet var printsLeftLabel: UILabel! + @IBOutlet var copiesLeftLabel: UILabel! - public var viewModel: LCPViewModel! + @IBOutlet var renewButton: UIButton! + @IBOutlet var returnButton: UIButton! - weak var moduleDelegate: ReaderModuleDelegate? + public var viewModel: LCPViewModel! - override func viewWillAppear(_ animated: Bool) { - title = NSLocalizedString("reader_drm_management_title", comment: "Title of the DRM management view") - reload() - } + weak var moduleDelegate: ReaderModuleDelegate? - @IBAction func renewTapped() { - let alert = UIAlertController( - title: NSLocalizedString("reader_drm_renew_title", comment: "Title of the renew confirmation alert"), - message: NSLocalizedString("reader_drm_renew_message", comment: "Message of the renew confirmation alert"), - preferredStyle: .alert - ) - let confirmButton = UIAlertAction(title: NSLocalizedString("confirm_button", comment: "Confirmation button to renew a publication"), style: .default, handler: { _ in - Task { - do { - try await self.viewModel.renewLoan() - self.reload() - self.moduleDelegate?.presentAlert( - NSLocalizedString("success_title", comment: "Title for the success message after renewing a publication"), - message: NSLocalizedString("reader_drm_renew_success_message", comment: "Success message after renewing a publication"), - from: self - ) - - } catch { - self.moduleDelegate?.presentError(error, from: self) + override func viewWillAppear(_ animated: Bool) { + title = NSLocalizedString("reader_drm_management_title", comment: "Title of the DRM management view") + reload() + } + + @IBAction func renewTapped() { + let alert = UIAlertController( + title: NSLocalizedString("reader_drm_renew_title", comment: "Title of the renew confirmation alert"), + message: NSLocalizedString("reader_drm_renew_message", comment: "Message of the renew confirmation alert"), + preferredStyle: .alert + ) + let confirmButton = UIAlertAction(title: NSLocalizedString("confirm_button", comment: "Confirmation button to renew a publication"), style: .default, handler: { _ in + Task { + do { + try await self.viewModel.renewLoan() + self.reload() + self.moduleDelegate?.presentAlert( + NSLocalizedString("success_title", comment: "Title for the success message after renewing a publication"), + message: NSLocalizedString("reader_drm_renew_success_message", comment: "Success message after renewing a publication"), + from: self + ) + + } catch { + self.moduleDelegate?.presentError(error, from: self) + } } - } - }) - let dismissButton = UIAlertAction(title: NSLocalizedString("cancel_button", comment: "Cancel renewing the publication"), style: .cancel) + }) + let dismissButton = UIAlertAction(title: NSLocalizedString("cancel_button", comment: "Cancel renewing the publication"), style: .cancel) - alert.addAction(dismissButton) - alert.addAction(confirmButton) - // Present alert. - present(alert, animated: true) - } + alert.addAction(dismissButton) + alert.addAction(confirmButton) + // Present alert. + present(alert, animated: true) + } - @IBAction func returnTapped() { - let alert = UIAlertController( - title: NSLocalizedString("reader_drm_return_title", comment: "Title of the return confirmation alert"), - message: NSLocalizedString("reader_drm_return_message", comment: "Message of the return confirmation alert"), - preferredStyle: .alert - ) - let confirmButton = UIAlertAction(title: NSLocalizedString("confirm_button", comment: "Confirmation button to return a publication"), style: .destructive, handler: { _ in - Task { - do { - try await self.viewModel.returnPublication() - - self.navigationController?.popToRootViewController(animated: true) - self.moduleDelegate?.presentAlert( - NSLocalizedString("success_title", comment: "Title for the success message after returning a publication"), - message: NSLocalizedString("reader_drm_return_success_message", comment: "Success message after returning a publication"), - from: self - ) - - } catch { - self.moduleDelegate?.presentError(error, from: self) + @IBAction func returnTapped() { + let alert = UIAlertController( + title: NSLocalizedString("reader_drm_return_title", comment: "Title of the return confirmation alert"), + message: NSLocalizedString("reader_drm_return_message", comment: "Message of the return confirmation alert"), + preferredStyle: .alert + ) + let confirmButton = UIAlertAction(title: NSLocalizedString("confirm_button", comment: "Confirmation button to return a publication"), style: .destructive, handler: { _ in + Task { + do { + try await self.viewModel.returnPublication() + + self.navigationController?.popToRootViewController(animated: true) + self.moduleDelegate?.presentAlert( + NSLocalizedString("success_title", comment: "Title for the success message after returning a publication"), + message: NSLocalizedString("reader_drm_return_success_message", comment: "Success message after returning a publication"), + from: self + ) + + } catch { + self.moduleDelegate?.presentError(error, from: self) + } } - } - }) - let dismissButton = UIAlertAction(title: NSLocalizedString("cancel_button", comment: "Cancel returning the publication"), style: .cancel) + }) + let dismissButton = UIAlertAction(title: NSLocalizedString("cancel_button", comment: "Cancel returning the publication"), style: .cancel) - alert.addAction(dismissButton) - alert.addAction(confirmButton) - // Present alert. - present(alert, animated: true) - } + alert.addAction(dismissButton) + alert.addAction(confirmButton) + // Present alert. + present(alert, animated: true) + } - internal func reload() { - typeLabel.text = "Readium LCP" - stateLabel.text = viewModel.state - providerLabel.text = viewModel.provider - issuedLabel.text = viewModel.issued?.description - updatedLabel.text = viewModel.updated?.description - startLabel.text = viewModel.start?.description ?? "-" - endLabel.text = viewModel.end?.description ?? "-" - renewButton.isEnabled = viewModel.canRenewLoan - returnButton.isEnabled = viewModel.canReturnPublication - - Task { - printsLeftLabel.text = await viewModel.printsLeft() - copiesLeftLabel.text = await viewModel.copiesLeft() + internal func reload() { + typeLabel.text = "Readium LCP" + stateLabel.text = viewModel.state + providerLabel.text = viewModel.provider + issuedLabel.text = viewModel.issued?.description + updatedLabel.text = viewModel.updated?.description + startLabel.text = viewModel.start?.description ?? "-" + endLabel.text = viewModel.end?.description ?? "-" + renewButton.isEnabled = viewModel.canRenewLoan + returnButton.isEnabled = viewModel.canReturnPublication + + Task { + printsLeftLabel.text = await viewModel.printsLeft() + copiesLeftLabel.text = await viewModel.copiesLeft() + } } } -} + +#endif diff --git a/TestApp/Sources/Reader/ReaderFactory.swift b/TestApp/Sources/Reader/ReaderFactory.swift index 5bcc92405..11a109495 100644 --- a/TestApp/Sources/Reader/ReaderFactory.swift +++ b/TestApp/Sources/Reader/ReaderFactory.swift @@ -28,18 +28,22 @@ extension ReaderFactory: OutlineTableViewControllerFactory { } } -extension ReaderFactory: LCPManagementTableViewControllerFactory { - func make(publication: Publication, delegate: ReaderModuleDelegate?) -> LCPManagementTableViewController? { - guard let license = publication.lcpLicense else { - return nil +#if LCP + + extension ReaderFactory: LCPManagementTableViewControllerFactory { + func make(publication: Publication, delegate: ReaderModuleDelegate?) -> LCPManagementTableViewController? { + guard let license = publication.lcpLicense else { + return nil + } + + let controller = storyboards.drm.instantiateViewController(withIdentifier: "DRMManagementTableViewController") as! LCPManagementTableViewController + controller.moduleDelegate = delegate + controller.viewModel = LCPViewModel(license: license, presentingViewController: controller) + return controller } - - let controller = storyboards.drm.instantiateViewController(withIdentifier: "DRMManagementTableViewController") as! LCPManagementTableViewController - controller.moduleDelegate = delegate - controller.viewModel = LCPViewModel(license: license, presentingViewController: controller) - return controller } -} + +#endif /// This is a wrapper for the "OutlineTableView" to encapsulate the "Cancel" button behaviour class OutlineHostingController: UIHostingController { diff --git a/TestApp/Sources/Reader/ReaderModule.swift b/TestApp/Sources/Reader/ReaderModule.swift index 8102e990d..1d072fd7d 100644 --- a/TestApp/Sources/Reader/ReaderModule.swift +++ b/TestApp/Sources/Reader/ReaderModule.swift @@ -77,13 +77,15 @@ final class ReaderModule: ReaderModuleAPI { extension ReaderModule: ReaderFormatModuleDelegate { func presentDRM(for publication: Publication, from viewController: UIViewController) { - guard let drmViewController: LCPManagementTableViewController = factory.make(publication: publication, delegate: delegate) else { - return - } - let backItem = UIBarButtonItem() - backItem.title = "" - drmViewController.navigationItem.backBarButtonItem = backItem - viewController.navigationController?.pushViewController(drmViewController, animated: true) + #if LCP + guard let drmViewController: LCPManagementTableViewController = factory.make(publication: publication, delegate: delegate) else { + return + } + let backItem = UIBarButtonItem() + backItem.title = "" + drmViewController.navigationItem.backBarButtonItem = backItem + viewController.navigationController?.pushViewController(drmViewController, animated: true) + #endif } func presentOutline(of publication: Publication, bookId: Book.Id, from viewController: UIViewController) -> AnyPublisher {