Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:ThePalaceProject/ios-core into f…
Browse files Browse the repository at this point in the history
…eature/PP-247-ui-kit

* 'develop' of github.com:ThePalaceProject/ios-core:
  Update project.pbxproj (#364)
  [PP-553] Clean up corrupted audiobook error presentation (#363)
  [PP-725] Improve epub search (#360)
  Uncheck Run script: For install builds only
  Update project.pbxproj (#359)
  [PP-459] Display audiobook duration (#357)
  • Loading branch information
vladimirfedorov committed Nov 28, 2023
2 parents d1f5c2f + 33ab5d2 commit e2d948d
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 79 deletions.
20 changes: 10 additions & 10 deletions Palace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,7 @@
};
73DA43AD2404CA9500985482 /* Crashlytics */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 8;
buildActionMask = 12;
files = (
);
inputFileListPaths = (
Expand All @@ -3749,7 +3749,7 @@
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 1;
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${BUILD_DIR%/Build/*}/SourcePackages/checkouts/firebase-ios-sdk/Crashlytics/run\"\n";
};
Expand Down Expand Up @@ -4776,7 +4776,7 @@
CODE_SIGN_IDENTITY = "Apple Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 218;
CURRENT_PROJECT_VERSION = 220;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand All @@ -4798,7 +4798,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.35;
MARKETING_VERSION = 1.0.36;
PRODUCT_BUNDLE_IDENTIFIER = org.thepalaceproject.palace;
PRODUCT_MODULE_NAME = Palace;
PRODUCT_NAME = "Palace-noDRM";
Expand Down Expand Up @@ -4834,7 +4834,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Palace/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 218;
CURRENT_PROJECT_VERSION = 220;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand All @@ -4856,7 +4856,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.35;
MARKETING_VERSION = 1.0.36;
PRODUCT_BUNDLE_IDENTIFIER = org.thepalaceproject.palace;
PRODUCT_MODULE_NAME = Palace;
PRODUCT_NAME = "Palace-noDRM";
Expand Down Expand Up @@ -5018,7 +5018,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 218;
CURRENT_PROJECT_VERSION = 220;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand All @@ -5045,7 +5045,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.35;
MARKETING_VERSION = 1.0.36;
PRODUCT_BUNDLE_IDENTIFIER = org.thepalaceproject.palace;
PROVISIONING_PROFILE_SPECIFIER = "Ad Hoc";
RUN_CLANG_STATIC_ANALYZER = YES;
Expand Down Expand Up @@ -5078,7 +5078,7 @@
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES_ERROR;
CODE_SIGN_ENTITLEMENTS = Palace/SimplyE.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CURRENT_PROJECT_VERSION = 218;
CURRENT_PROJECT_VERSION = 220;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand All @@ -5105,7 +5105,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.35;
MARKETING_VERSION = 1.0.36;
PRODUCT_BUNDLE_IDENTIFIER = org.thepalaceproject.palace;
PROVISIONING_PROFILE_SPECIFIER = "App Store";
RUN_CLANG_STATIC_ANALYZER = YES;
Expand Down
21 changes: 16 additions & 5 deletions Palace/Book/Models/TPPBook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
@objc var timeTrackingURL: URL?
@objc var contributors: [String: Any]?
@objc var bookTokenLock: NSRecursiveLock

@objc var bookDuration: String?

static let SimplifiedScheme = "http://librarysimplified.org/terms/genres/Simplified/"

static func categoryStringsFromCategories(categories: [TPPOPDSCategory]) -> [String] {
Expand All @@ -74,6 +75,10 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
@objc var isAudiobook: Bool {
defaultBookContentType == .audiobook
}

@objc var hasDuration: Bool {
(bookDuration ?? "").count > 0
}

init(
acquisitions: [TPPOPDSAcquisition],
Expand All @@ -98,10 +103,12 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
revokeURL: URL?,
reportURL: URL?,
timeTrackingURL: URL?,
contributors: [String: Any]?
contributors: [String: Any]?,
bookDuration: String?
) {
self.acquisitions = acquisitions
self.bookAuthors = authors
self.bookAuthors = authors
self.categoryStrings = categoryStrings
self.distributor = distributor
self.identifier = identifier
Expand All @@ -124,6 +131,7 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
self.timeTrackingURL = timeTrackingURL
self.contributors = contributors
self.bookTokenLock = NSRecursiveLock()
self.bookDuration = bookDuration
}

/// @brief Factory method to build a TPPBook object from an OPDS feed entry.
Expand Down Expand Up @@ -185,7 +193,8 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
revokeURL: revoke,
reportURL: report,
timeTrackingURL: entry.timeTrackingLink?.href,
contributors: entry.contributors
contributors: entry.contributors,
bookDuration: entry.duration
)
}

Expand Down Expand Up @@ -373,7 +382,8 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
revokeURL: revokeURL,
reportURL: reportURL,
timeTrackingURL: URL(string: dictionary[TimeTrackingURLURLKey] as? String ?? ""),
contributors: nil
contributors: nil,
bookDuration: nil
)
}

Expand Down Expand Up @@ -401,7 +411,8 @@ let TimeTrackingURLURLKey: String = "time-tracking-url"
revokeURL: self.revokeURL,
reportURL: self.reportURL,
timeTrackingURL: self.timeTrackingURL,
contributors: book.contributors
contributors: book.contributors,
bookDuration: book.bookDuration
)
}

Expand Down
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
51 changes: 47 additions & 4 deletions Palace/Book/UI/TPPBookDetailView.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ @interface TPPBookDetailView () <TPPBookDownloadCancellationDelegate, TPPBookBut
@property (nonatomic) UILabel *distributorLabelKey;
@property (nonatomic) UILabel *bookFormatLabelKey;
@property (nonatomic) UILabel *narratorsLabelKey;
@property (nonatomic) UILabel *bookDurationLabelKey;
@property (nonatomic) UILabel *publishedLabelValue;
@property (nonatomic) UILabel *publisherLabelValue;
@property (nonatomic) UILabel *categoriesLabelValue;
@property (nonatomic) UILabel *distributorLabelValue;
@property (nonatomic) UILabel *bookFormatLabelValue;
@property (nonatomic) UILabel *narratorsLabelValue;
@property (nonatomic) UILabel *bookDurationLabelValue;

@property (nonatomic) TPPBookDetailTableView *footerTableView;

Expand Down Expand Up @@ -145,12 +147,22 @@ - (instancetype)initWithBook:(TPPBook *const)book
[self.containerView addSubview:self.distributorLabelKey];
[self.containerView addSubview:self.bookFormatLabelKey];
[self.containerView addSubview:self.narratorsLabelKey];

if (self.book.isAudiobook) {
[self.containerView addSubview:self.bookDurationLabelKey];
}

[self.containerView addSubview:self.publishedLabelValue];
[self.containerView addSubview:self.publisherLabelValue];
[self.containerView addSubview:self.categoriesLabelValue];
[self.containerView addSubview:self.distributorLabelValue];
[self.containerView addSubview:self.bookFormatLabelValue];
[self.containerView addSubview:self.narratorsLabelValue];

if (self.book.isAudiobook) {
[self.containerView addSubview:self.bookDurationLabelValue];
}

[self.containerView addSubview:self.footerTableView];
[self.containerView addSubview:self.bottomFootnoteSeparator];

Expand Down Expand Up @@ -348,8 +360,10 @@ - (void)createFooterLabels
NSString *const bookFormatKeyString = NSLocalizedString(@"Book format:", nil);

NSString *const narratorsKeyString =
self.book.narrators ? [NSString stringWithFormat:@"%@: ", NSLocalizedString(@"Narrators:", nil)] : nil;
self.book.narrators ? [NSString stringWithFormat:@"%@: ", NSLocalizedString(@"Narrators", nil)] : nil;

NSString *const bookDurationKeyString = [NSString stringWithFormat:@"%@:", NSLocalizedString(@"Duration", nil)];

NSString *const categoriesValueString = self.book.categories;
NSString *const publishedValueString = self.book.published ? [dateFormatter stringFromDate:self.book.published] : nil;
NSString *const publisherValueString = self.book.publisher;
Expand All @@ -368,7 +382,8 @@ - (void)createFooterLabels
self.distributorLabelKey = [self createFooterLabelWithString:distributorKeyString alignment:NSTextAlignmentRight];
self.bookFormatLabelKey = [self createFooterLabelWithString:bookFormatKeyString alignment:NSTextAlignmentRight];
self.narratorsLabelKey = [self createFooterLabelWithString:narratorsKeyString alignment:NSTextAlignmentRight];

self.bookDurationLabelKey = [self createFooterLabelWithString:bookDurationKeyString alignment:NSTextAlignmentRight];

self.categoriesLabelValue = [self createFooterLabelWithString:categoriesValueString alignment:NSTextAlignmentLeft];
self.categoriesLabelValue.numberOfLines = 2;
self.publisherLabelValue = [self createFooterLabelWithString:publisherValueString alignment:NSTextAlignmentLeft];
Expand All @@ -377,6 +392,8 @@ - (void)createFooterLabels
self.distributorLabelValue = [self createFooterLabelWithString:self.book.distributor alignment:NSTextAlignmentLeft];
self.bookFormatLabelValue = [self createFooterLabelWithString:bookFormatValueString alignment:NSTextAlignmentLeft];
self.narratorsLabelValue = [self createFooterLabelWithString:narratorsValueString alignment:NSTextAlignmentLeft];
self.bookDurationLabelValue = [self createFooterLabelWithString:[self displayStringForDuration: self.book.bookDuration] alignment:NSTextAlignmentLeft];

self.narratorsLabelValue.numberOfLines = 0;

self.topFootnoteSeparater = [[UIView alloc] init];
Expand All @@ -403,6 +420,14 @@ - (UILabel *)createFooterLabelWithString:(NSString *)string alignment:(NSTextAli
return label;
}

- (NSString *) displayStringForDuration: (NSString *) durationInSeconds {
double totalSeconds = [durationInSeconds doubleValue];
int hours = (int)(totalSeconds / 3600);
int minutes = (int)((totalSeconds - (hours * 3600)) / 60);

return [NSString stringWithFormat:@"%d hours, %d minutes", hours, minutes];
}

- (void)setupAutolayoutConstraints
{
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeTop];
Expand Down Expand Up @@ -527,6 +552,13 @@ - (void)setupAutolayoutConstraints
[self.narratorsLabelValue autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.bookFormatLabelValue];
[self.narratorsLabelValue autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.narratorsLabelKey withOffset:MainTextPaddingLeft];

if (self.book.hasDuration) {
[self.bookDurationLabelValue autoPinEdgeToSuperviewMargin:ALEdgeTrailing relation:NSLayoutRelationGreaterThanOrEqual];
[self.bookDurationLabelValue autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.narratorsLabelValue];
[self.bookDurationLabelValue autoPinEdge:ALEdgeLeading toEdge:ALEdgeTrailing ofView:self.bookDurationLabelKey withOffset:MainTextPaddingLeft];
}

[self.publishedLabelKey autoPinEdgeToSuperviewMargin:ALEdgeLeading];
[self.publishedLabelKey autoPinEdgeToSuperviewMargin:ALEdgeLeading];
[self.publishedLabelKey autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:self.publisherLabelKey];
[self.publishedLabelKey autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.publishedLabelValue];
Expand Down Expand Up @@ -556,7 +588,13 @@ - (void)setupAutolayoutConstraints
[self.narratorsLabelKey autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.narratorsLabelValue];
[self.narratorsLabelKey setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];


if (self.book.hasDuration) {
[self.bookDurationLabelKey autoPinEdgeToSuperviewMargin:ALEdgeLeading];
[self.bookDurationLabelKey autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.bookDurationLabelValue];
[self.bookDurationLabelKey autoPinEdge:ALEdgeTrailing toEdge:ALEdgeTrailing ofView:self.narratorsLabelKey];
[self.bookDurationLabelKey setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
}

if (self.closeButton) {
[self.closeButton autoPinEdgeToSuperviewMargin:ALEdgeTrailing];
[self.closeButton autoPinEdge:ALEdgeTop toEdge:ALEdgeTop ofView:self.titleLabel];
Expand All @@ -574,7 +612,12 @@ - (void)setupAutolayoutConstraints
[self.bottomFootnoteSeparator autoSetDimension:ALDimensionHeight toSize: 1.0f / [UIScreen mainScreen].scale];
[self.bottomFootnoteSeparator autoPinEdgeToSuperviewEdge:ALEdgeRight];
[self.bottomFootnoteSeparator autoPinEdgeToSuperviewMargin:ALEdgeLeft];
[self.bottomFootnoteSeparator autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.narratorsLabelValue withOffset:VerticalPadding];

if (self.book.hasDuration) {
[self.bottomFootnoteSeparator autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.bookDurationLabelKey withOffset:VerticalPadding];
} else {
[self.bottomFootnoteSeparator autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.narratorsLabelValue withOffset:VerticalPadding];
}

[self.footerTableView autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero excludingEdge:ALEdgeTop];
[self.footerTableView autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.narratorsLabelValue withOffset:VerticalPadding];
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
1 change: 1 addition & 0 deletions Palace/OPDS/TPPOPDSEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
@property (nonatomic, readonly) NSDate *updated;
@property (nonatomic, readonly) NSDictionary<NSString *, NSArray<NSString *>*> *contributors;
@property (nonatomic, readonly) TPPOPDSLink *timeTrackingLink;
@property (nonatomic, readonly) NSString *duration;

+ (id)new NS_UNAVAILABLE;
- (id)init NS_UNAVAILABLE;
Expand Down
Loading

0 comments on commit e2d948d

Please sign in to comment.