Skip to content
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

[PP-553] Clean up corrupted audiobook error presentation #363

Merged
merged 10 commits into from
Nov 27, 2023
2 changes: 1 addition & 1 deletion Palace/Book/UI/TPPBookButtonsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

- (void)didSelectReturnForBook:(TPPBook *)book completion:(void (^ _Nullable)(void))completion;
- (void)didSelectDownloadForBook:(TPPBook *)book;
- (void)didSelectReadForBook:(TPPBook *)book;
- (void)didSelectReadForBook:(TPPBook *)book completion:(void (^ _Nullable)(void))completion;
- (void)didSelectPlaySample:(TPPBook *)book;

@end
Expand Down
6 changes: 3 additions & 3 deletions Palace/Book/UI/TPPBookButtonsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,9 @@ - (void)didSelectRead
{
self.activityIndicator.center = self.readButton.center;
[self updateProcessingState:YES];
[self.delegate didSelectReadForBook:self.book];
[[TPPRootTabBarController sharedController] dismissViewControllerAnimated:YES completion:nil];

[self.delegate didSelectReadForBook:self.book completion:^{
[self updateProcessingState:NO];
}];
}

- (void)didSelectDownload
Expand Down
19 changes: 10 additions & 9 deletions Palace/Book/UI/TPPBookCellDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ - (void)didSelectDownloadForBook:(TPPBook *)book
[[MyBooksDownloadCenter shared] startDownloadFor:book withRequest:nil];
}

- (void)didSelectReadForBook:(TPPBook *)book
- (void)didSelectReadForBook:(TPPBook *)book completion:(void (^ _Nullable)(void))completion
{
#if defined(FEATURE_DRM_CONNECTOR)
// Try to prevent blank books bug

TPPUserAccount *user = [TPPUserAccount sharedAccount];
if ([user hasCredentials]) {
if ([user hasAuthToken]) {
[self openBook:book];
[self openBook:book completion:completion];
} else
if ([AdobeCertificate.defaultCertificate hasExpired] == NO
&& ![[NYPLADEPT sharedInstance] isUserAuthorized:[user userID]
Expand All @@ -103,21 +103,21 @@ - (void)didSelectReadForBook:(TPPBook *)book
usingExistingCredentials:YES
authenticationCompletion:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self openBook:book]; // with successful DRM activation
[self openBook:book completion:completion]; // with successful DRM activation
});
}];
} else {
[self openBook:book];
[self openBook:book completion:completion];
}
} else {
[self openBook:book];
[self openBook:book completion:completion];
}
#else
[self openBook:book];
[self openBook:book completion:completion];
#endif
}

- (void)openBook:(TPPBook *)book
- (void)openBook:(TPPBook *)book completion:(void (^ _Nullable)(void))completion
{
[TPPCirculationAnalytics postEvent:@"open_book" withBook:book];

Expand All @@ -129,7 +129,7 @@ - (void)openBook:(TPPBook *)book
[self openPDF:book];
break;
case TPPBookContentTypeAudiobook:
[self openAudiobook:book];
[self openAudiobook:book completion:completion];
break;
default:
[self presentUnsupportedItemError];
Expand Down Expand Up @@ -199,11 +199,12 @@ - (void)presentPDF:(TPPBook *)book {
[[TPPRootTabBarController sharedController] pushViewController:vc animated:YES];
}

- (void)openAudiobook:(TPPBook *)book {
- (void)openAudiobook:(TPPBook *)book completion:(void (^ _Nullable)(void))completion{
NSURL *const url = [[MyBooksDownloadCenter shared] fileUrlFor:book.identifier];
NSData *const data = [NSData dataWithContentsOfURL:url];
if (data == nil) {
[self presentCorruptedItemErrorForBook:book fromURL:url];
completion();
return;
}

Expand Down
5 changes: 3 additions & 2 deletions Palace/MyBooks/MyBooks/BookCell/BookCellModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ extension BookCellModel {

func didSelectRead() {
isLoading = true
self.buttonDelegate?.didSelectRead(for: book)
TPPRootTabBarController.shared().dismiss(animated: true)
self.buttonDelegate?.didSelectRead(for: book) { [weak self] in
self?.isLoading = false
}
}

func didSelectReturn() {
Expand Down