Skip to content

Fix Test App using CocoaPods #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions TestApp/Integrations/CocoaPods/Podfile+lcp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 14 additions & 10 deletions TestApp/Sources/Reader/ReaderFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<OutlineTableView> {
Expand Down
16 changes: 9 additions & 7 deletions TestApp/Sources/Reader/ReaderModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Locator, Never> {
Expand Down
Loading