Skip to content

Commit

Permalink
IOS-631 Fix neverending spinner after book opening errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ettore committed Feb 3, 2024
1 parent 082b32c commit c988f1d
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 26 deletions.
3 changes: 2 additions & 1 deletion Simplified/Book/UI/NYPLBookButtonsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

- (void)didSelectReturnForBook:(NYPLBook *)book;
- (void)didSelectDownloadForBook:(NYPLBook *)book;
- (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))completion;
- (void)didSelectReadForBook:(NYPLBook *)book
completion:(void(^)(BOOL success))completion;

@end

Expand Down
2 changes: 1 addition & 1 deletion Simplified/Book/UI/NYPLBookButtonsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ - (void)didSelectRead
self.activityIndicator.center = self.readButton.center;
[self updateProcessingState:YES];
[self.delegate didSelectReadForBook:self.book
successCompletion:^{
completion:^(__unused BOOL success) {
[self updateProcessingState];
}];
}
Expand Down
24 changes: 14 additions & 10 deletions Simplified/Book/UI/NYPLBookCellDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ - (void)didSelectDownloadForBook:(NYPLBook *)book
[[NYPLMyBooksDownloadCenter sharedDownloadCenter] startDownloadForBook:book];
}

- (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))successCompletion
- (void)didSelectReadForBook:(NYPLBook *)book
completion:(void(^)(BOOL success))completion
{
#if FEATURE_DRM_CONNECTOR
// Try to prevent blank books bug
Expand All @@ -81,37 +82,40 @@ - (void)didSelectReadForBook:(NYPLBook *)book successCompletion:(void(^)(void))s
completion:^(BOOL isSignedIn) {
if (isSignedIn) {
dispatch_async(dispatch_get_main_queue(), ^{
[self openBook:book successCompletion:successCompletion];
[self openBook:book completion:completion];
// with ARC, retain the reauthenticator until we're done, then release it
reauthenticator = nil;
});
}
}];
} else {
[self openBook:book successCompletion:successCompletion];
[self openBook:book completion:completion];
}
#else
[self openBook:book successCompletion:successCompletion];
[self openBook:book completion:completion];
#endif//FEATURE_DRM_CONNECTOR
}

- (void)openBook:(NYPLBook *)book successCompletion:(void(^)(void))successCompletion
- (void)openBook:(NYPLBook *)book completion:(void(^)(BOOL success))completion
{
[NYPLCirculationAnalytics postEvent:@"open_book" withBook:book];

switch (book.defaultBookContentType) {
case NYPLBookContentTypeEPUB:
[[[NYPLEPUBOpener alloc] init] open:book successCompletion:successCompletion];
[[[NYPLEPUBOpener alloc] init] open:book completion:completion];
break;
case NYPLBookContentTypePDF:
[self openPDF:book];
break;
#if FEATURE_AUDIOBOOKS
case NYPLBookContentTypeAudiobook:
[self openAudiobook:book successCompletion:successCompletion];
case NYPLBookContentTypeAudiobook: {
[self openAudiobook:book successCompletion:^{
completion(YES);
}];
break;
}
#endif
default:
case NYPLBookContentTypeUnsupported:
[self presentUnsupportedItemError];
break;
}
Expand Down Expand Up @@ -181,7 +185,7 @@ - (void)didSelectCancelForBookDownloadingCell:(NYPLBookDownloadingCell *const)ce

- (void)didSelectListenForBookDownloadingCell:(NYPLBookDownloadingCell *)cell
{
[self didSelectReadForBook:cell.book successCompletion:nil];
[self didSelectReadForBook:cell.book completion:nil];
}

@end
10 changes: 6 additions & 4 deletions Simplified/Book/UI/NYPLBookDetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ - (void)didSelectDownloadForBook:(NYPLBook *)book
}

- (void)didSelectReadForBook:(NYPLBook *)book
successCompletion:(__unused void(^)(void))successCompletion
completion:(void(^)(BOOL success))completion
{
[[NYPLBookCellDelegate sharedDelegate] didSelectReadForBook:book
successCompletion:^{
completion:^(BOOL success) {
// dismiss ourselves if we were presented, since we want to show the ereader
if (self.modalPresentationStyle == UIModalPresentationFormSheet) {
[self dismissViewControllerAnimated:true completion:successCompletion];
[self dismissViewControllerAnimated:true completion:^{
completion(success);
}];
} else {
successCompletion();
completion(success);
}
}];
}
Expand Down
6 changes: 3 additions & 3 deletions Simplified/Book/UI/NYPLEPUBOpener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

class NYPLEPUBOpener: NSObject {
@objc
func open(_ book: NYPLBook, successCompletion: @escaping () -> Void) {
func open(_ book: NYPLBook, completion: @escaping (_ success: Bool) -> Void) {

let url = NYPLMyBooksDownloadCenter.shared()?
.fileURL(forBookIndentifier: book.identifier)
Expand All @@ -21,8 +21,8 @@ class NYPLEPUBOpener: NSObject {
rootTabController?.presentBook(book,
fromFileURL: url,
syncPermission: syncPermission,
successCompletion: successCompletion)
completion: completion)

rootTabController?.annotationsSynchronizer?
.checkServerSyncStatus(settings: NYPLSettings.shared,
syncPermissionGranted: syncPermission) { enableSync, error in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
func presentBook(_ book: NYPLBook,
fromFileURL fileURL: URL?,
syncPermission: Bool,
successCompletion: (() -> Void)?) {
completion: ((_ success: Bool) -> Void)?) {
guard let libraryService = r2Owner?.libraryService, let readerModule = r2Owner?.readerModule else {
return
}
Expand All @@ -30,7 +30,7 @@ import Foundation
syncPermission: syncPermission,
deviceID: drmDeviceID,
in: navVC,
successCompletion: successCompletion)
completion: completion)
case .cancelled:
// .cancelled is returned when publication has restricted access to its resources and can't be rendered
NYPLErrorLogger.logError(nil, summary: "Error accessing book resources", metadata: [
Expand Down
11 changes: 6 additions & 5 deletions Simplified/Reader2/ReaderPresentation/ReaderModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protocol ReaderModuleAPI {
syncPermission: Bool,
deviceID: String?,
in navigationController: UINavigationController,
successCompletion: (() -> Void)?)
completion: ((_ success: Bool) -> Void)?)

}

Expand Down Expand Up @@ -82,7 +82,7 @@ final class ReaderModule: ReaderModuleAPI {
syncPermission: Bool,
deviceID: String?,
in navigationController: UINavigationController,
successCompletion: (() -> Void)?) {
completion: ((_ success: Bool) -> Void)?) {
if delegate == nil {
NYPLErrorLogger.logError(nil, summary: "ReaderModule delegate is not set")
}
Expand All @@ -102,7 +102,7 @@ final class ReaderModule: ReaderModuleAPI {
formatModule: formatModule,
positioningAt: initialLocator,
in: navigationController,
successCompletion: successCompletion)
completion: completion)
}
}

Expand All @@ -112,7 +112,7 @@ final class ReaderModule: ReaderModuleAPI {
formatModule: ReaderFormatModule,
positioningAt initialLocator: Locator?,
in navigationController: UINavigationController,
successCompletion: (() -> Void)?) {
completion: ((_ success: Bool) -> Void)?) {
do {
let readerVC = try formatModule.makeReaderViewController(
for: publication,
Expand All @@ -126,9 +126,10 @@ final class ReaderModule: ReaderModuleAPI {
readerVC.hidesBottomBarWhenPushed = true
navigationController.pushViewController(readerVC, animated: true)

successCompletion?()
completion?(true)
} catch {
delegate?.presentError(error, from: navigationController)
completion?(false)
}
}
}

0 comments on commit c988f1d

Please sign in to comment.