Skip to content

Commit

Permalink
[PP-755] Update audiobook sampler (#372)
Browse files Browse the repository at this point in the history
* in progress

* Clean up annotation deletion, switch management and resolve infinite refresh call issue

* Update project.pbxproj

* Update audiobook sampler

* Update project.pbxproj

* Update TPPBookButtonsView.h

* Update TPPBookButtonsView.h
  • Loading branch information
mauricecarrier7 authored Dec 13, 2023
1 parent b4448b9 commit 821b169
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 55 deletions.
14 changes: 4 additions & 10 deletions Palace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@
21E41795292812B700A78606 /* TPPSignInBusinessLogic+CardCreation.swift in Sources */ = {isa = PBXBuildFile; fileRef = E74752F627FF044400F5E7FA /* TPPSignInBusinessLogic+CardCreation.swift */; };
21E417962928136300A78606 /* AudiobookSampleToolbar.swift in Sources */ = {isa = PBXBuildFile; fileRef = E59892EC28AC909000C44A85 /* AudiobookSampleToolbar.swift */; };
21E417972928137E00A78606 /* AudiobookSamplePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52E3C0228C19BAD0073DC4D /* AudiobookSamplePlayer.swift */; };
21E417982928139300A78606 /* ActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB96628AED70E0042907F /* ActivityIndicator.swift */; };
21E41799292813A000A78606 /* AsyncImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB9CA28AFE8AF0042907F /* AsyncImage.swift */; };
21E4179A292813DB00A78606 /* SamplePlayerError.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52E3C0328C19BAD0073DC4D /* SamplePlayerError.swift */; };
21E4179B292813E200A78606 /* EpubSampleFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = E52E3C0128C19BAD0073DC4D /* EpubSampleFactory.swift */; };
Expand Down Expand Up @@ -747,7 +746,6 @@
E5FC133A2A25AC16000BFED5 /* ChapterLocation+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FC12AD2A24EB1C000BFED5 /* ChapterLocation+Extensions.swift */; };
E5FFB96428AED4850042907F /* ImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB96328AED4850042907F /* ImageProvider.swift */; };
E5FFB96528AED4990042907F /* ImageProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB96328AED4850042907F /* ImageProvider.swift */; };
E5FFB96728AED70E0042907F /* ActivityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB96628AED70E0042907F /* ActivityIndicator.swift */; };
E5FFB9CB28AFE8AF0042907F /* AsyncImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E5FFB9CA28AFE8AF0042907F /* AsyncImage.swift */; };
E6202A021DD4E6F300C99553 /* TPPSettingsAccountDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E6202A011DD4E6F300C99553 /* TPPSettingsAccountDetailViewController.m */; };
E6207B652118973800864143 /* TPPAppTheme.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6207B642118973800864143 /* TPPAppTheme.swift */; };
Expand Down Expand Up @@ -1637,7 +1635,6 @@
E5F8A57C28A48B8300A229AE /* BookPreviewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookPreviewTests.swift; sourceTree = "<group>"; };
E5FC12AD2A24EB1C000BFED5 /* ChapterLocation+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ChapterLocation+Extensions.swift"; sourceTree = "<group>"; };
E5FFB96328AED4850042907F /* ImageProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageProvider.swift; sourceTree = "<group>"; };
E5FFB96628AED70E0042907F /* ActivityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityIndicator.swift; sourceTree = "<group>"; };
E5FFB9CA28AFE8AF0042907F /* AsyncImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AsyncImage.swift; sourceTree = "<group>"; };
E61D7F631F6AC78B0091C781 /* SimplyE.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SimplyE.entitlements; sourceTree = "<group>"; };
E6202A001DD4E6F300C99553 /* TPPSettingsAccountDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TPPSettingsAccountDetailViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3024,7 +3021,6 @@
E54DD4C6275C60E70013C200 /* UIViewControllerWrapper.swift */,
E54DD4D4275C7C940013C200 /* View+Extensions.swift */,
E54DD4E5275C8EAA0013C200 /* Font+Extensions.swift */,
E5FFB96628AED70E0042907F /* ActivityIndicator.swift */,
E5FFB9CA28AFE8AF0042907F /* AsyncImage.swift */,
E523A452299FCA5300EF833B /* AlertModel.swift */,
);
Expand Down Expand Up @@ -3867,7 +3863,6 @@
73EB0A6F25821DF4006BC997 /* Log.swift in Sources */,
73EB0A7125821DF4006BC997 /* UILabel+NYPLAppearanceAdditions.m in Sources */,
21399902268F9F4C00B4EB60 /* TPPAccountListDataSource.swift in Sources */,
21E417982928139300A78606 /* ActivityIndicator.swift in Sources */,
73EB0A7325821DF4006BC997 /* TPPJSON.m in Sources */,
21E41789292810F600A78606 /* TPPPDFPreviewThumbnail.swift in Sources */,
73EB0A7425821DF4006BC997 /* TPPMainThreadChecker.swift in Sources */,
Expand Down Expand Up @@ -4475,7 +4470,6 @@
21562CC3276BB52700C03372 /* AdobeDRMAlerts.swift in Sources */,
5D7CF8B922C3FC06007CAA34 /* TPPErrorLogger.swift in Sources */,
E7A9909027EE4EF400D9486F /* LicensesService.swift in Sources */,
E5FFB96728AED70E0042907F /* ActivityIndicator.swift in Sources */,
E7FD4E52286CCF2C00D26A3B /* TPPPDFLocation.swift in Sources */,
0824D44E24B8DFE400C85A7E /* NSString+JSONParse.swift in Sources */,
73CC48AA260C07C200F1E2C3 /* TPPReadiumBookmark+R2.swift in Sources */,
Expand Down Expand Up @@ -4782,7 +4776,7 @@
CODE_SIGN_IDENTITY = "Apple Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 226;
CURRENT_PROJECT_VERSION = 227;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -4840,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 = 226;
CURRENT_PROJECT_VERSION = 227;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5024,7 +5018,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Distribution";
CODE_SIGN_STYLE = Manual;
CURRENT_PROJECT_VERSION = 226;
CURRENT_PROJECT_VERSION = 227;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down Expand Up @@ -5084,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 = 226;
CURRENT_PROJECT_VERSION = 227;
DEVELOPMENT_TEAM = 88CBA74T8K;
"DEVELOPMENT_TEAM[sdk=iphoneos*]" = 88CBA74T8K;
ENABLE_BITCODE = NO;
Expand Down
18 changes: 11 additions & 7 deletions Palace/Book/UI/AudiobookSampleToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ struct AudiobookSampleToolbar: View {
.padding(.trailing)
default:
loadingView
.square(length: playbackButtonLength)
.padding(.trailing)
}
}

private func togglePlay() {
switch player.state {
case .paused:
Expand All @@ -107,8 +109,9 @@ struct AudiobookSampleToolbar: View {
player.pauseAudiobook()
default:
return
} }

}
}

private var playbackButton: some View {
Button {
player.goBack()
Expand All @@ -121,10 +124,11 @@ struct AudiobookSampleToolbar: View {
}

@ViewBuilder private var loadingView: some View {
AnyView {
ActivityIndicator(isAnimating: $player.isLoading, style: .medium)
.foregroundColor(.black)
}
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.scaleEffect(1.25)
.transition(.opacity)
.animation(.easeInOut)
}
}

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 @@ -15,7 +15,7 @@

@protocol TPPBookButtonsSampleDelegate

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

@end

Expand Down
4 changes: 3 additions & 1 deletion Palace/Book/UI/TPPBookButtonsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,9 @@ - (void)didSelectSample
{
self.activityIndicator.center = self.sampleButton.center;
[self updateProcessingState:YES];
[self.sampleDelegate didSelectPlaySample:self.book];
[self.sampleDelegate didSelectPlaySample:self.book completion:^{
[self updateProcessingState:NO];
}];
}

@end
34 changes: 22 additions & 12 deletions Palace/Book/UI/TPPBookDetailView.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ @interface TPPBookDetailView () <TPPBookDownloadCancellationDelegate, TPPBookBut
@property (nonatomic) UIView *topFootnoteSeparater;
@property (nonatomic) UIView *bottomFootnoteSeparator;

@property (nonatomic) BOOL isShowingSample;

@end

static CGFloat const SubtitleBaselineOffset = 10;
Expand Down Expand Up @@ -121,11 +123,6 @@ - (instancetype)initWithBook:(TPPBook *const)book
[self addSubview:self.scrollView];
[self.scrollView addSubview:self.containerView];

if (self.book.showAudiobookToolbar) {
self.audiobookSampleToolbar = [[AudiobookSampleToolbarWrapper createWithBook:self.book] view];
[self addSubview: self.audiobookSampleToolbar];
}

[self.containerView addSubview:self.blurCoverImageView];
[self.containerView addSubview:self.visualEffectView];
[self.containerView addSubview:self.coverImageView];
Expand Down Expand Up @@ -180,6 +177,15 @@ - (instancetype)initWithBook:(TPPBook *const)book
return self;
}

- (void)showAudiobookSampleToolbar
{
self.audiobookSampleToolbar = [[AudiobookSampleToolbarWrapper createWithBook:self.book] view];
[self addSubview: self.audiobookSampleToolbar];
self.isShowingSample = true;
self.didSetupConstraints = false;
[self setupAutolayoutConstraints];
}

- (void)updateFonts
{
self.titleLabel.font = [UIFont customFontForTextStyle:UIFontTextStyleHeadline];
Expand Down Expand Up @@ -431,17 +437,15 @@ - (NSString *) displayStringForDuration: (NSString *) durationInSeconds {
- (void)setupAutolayoutConstraints
{
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeBottom];

if ([self.book showAudiobookToolbar]) {
if ([self.book showAudiobookToolbar] && self.isShowingSample) {
[self.audiobookSampleToolbar autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[self.audiobookSampleToolbar autoPinEdgeToSuperviewEdge:ALEdgeRight];
[self.audiobookSampleToolbar autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:TabBarHeight];
[self.audiobookSampleToolbar autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[self.audiobookSampleToolbar autoSetDimension:ALDimensionHeight toSize:SampleToolbarHeight relation:NSLayoutRelationLessThanOrEqual];
[self.audiobookSampleToolbar autoMatchDimension:ALDimensionWidth toDimension:ALDimensionWidth ofView:self];

[self.scrollView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView: self.audiobookSampleToolbar];
} else {
[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeBottom];
self.scrollView.contentInset = UIEdgeInsetsMake(0, 0, SampleToolbarHeight, 0);
}

[self.scrollView autoPinEdgeToSuperviewEdge:ALEdgeLeft];
Expand Down Expand Up @@ -664,11 +668,15 @@ - (void)didSelectCancelForBookDetailDownloadFailedView:

NSString *PlaySampleNotification = @"ToggleSampleNotification";

- (void)didSelectPlaySample:(TPPBook *)book {
- (void)didSelectPlaySample:(TPPBook *)book completion:(void (^ _Nullable)(void))completion {
if ([self.book defaultBookContentType] == TPPBookContentTypeAudiobook) {
if ([self.book.sampleAcquisition.type isEqualToString: @"text/html"]) {
[self presentWebView: self.book.sampleAcquisition.hrefURL];
} else {
if (!self.isShowingSample) {
self.isShowingSample = YES;
[self showAudiobookSampleToolbar];
}
[[NSNotificationCenter defaultCenter] postNotificationName:PlaySampleNotification object:self];
}
} else {
Expand All @@ -683,6 +691,8 @@ - (void)didSelectPlaySample:(TPPBook *)book {
}
}];
}

completion();
}

- (void)presentWebView:(NSURL *)url {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class AudiobookSamplePlayer: NSObject, ObservableObject {
player?.delegate = self
player?.volume = 1.0
startTimer()
player?.play()
state = .playing
}

func pauseAudiobook() {
Expand Down Expand Up @@ -106,7 +108,6 @@ class AudiobookSamplePlayer: NSObject, ObservableObject {
return
case let .success(result, _):
DispatchQueue.main.async {
self?.state = .paused
try? self?.setupPlayer(data: result)
}
}
Expand Down
23 changes: 0 additions & 23 deletions Palace/Utilities/SwiftUI/ActivityIndicator.swift

This file was deleted.

0 comments on commit 821b169

Please sign in to comment.