Skip to content

Commit

Permalink
[PP-553] Clean up corrupted audiobook error presentation (#363)
Browse files Browse the repository at this point in the history
* working implementation

* Correct search issues

* Update project.pbxproj

* Prevent alert from being prematurely dismissed and  dismiss loading screen

* Update TPPBookButtonsView.m

* Update TPPBookButtonsView.m

* Update project.pbxproj

* Update project.pbxproj
  • Loading branch information
mauricecarrier7 authored Nov 27, 2023
1 parent fc7b5d6 commit f502d19
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
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

0 comments on commit f502d19

Please sign in to comment.