Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: the Player page previews backgrounds and changes them in one tap
My-Name-Is-Jeff5fd267cd3031
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 09ddaec2..504a7c08 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -453,11 +453,13 @@ flags stay in All flags), which work with either look;in the native look also Now playing bar (its device button and its flags), Queue & devices, andSpotify's own player screen (artwork background, glass header buttons, Disable Canvas and the sheet,header, slider and sticky header flags, the cards under the player and the lyrics preview and player-buttons to hide); in the redesign the page instead leads with a showcase of the player (Redesigned/Player/-PlayerSettings.m): a small copy of it over the background chosen, the cover, title and artist, and a glass sheet over-the artwork with its progress and volume sliders and the transport between them; under it the Background pull-down-(Still, Colours, Fluid, Animated, changing the showcase at once), Download in Low Data Mode while Animated is-chosen, and the now playing bar's device button, checked in the simulator against harness/player/ (`settings`). Vibrations, a page of its own under either+buttons to hide); in the redesign the page instead leads with a card of the player (Redesigned/Player/+PlayerSettings.m): the background chosen edge to edge, and over its foot the cover, title, artist and progress;+under it a segmented control of the four backgrounds (Still, Colours, Fluid, Animated, changing the card at once)+with a note on what the one picked does, Artwork sources and Download in Low Data Mode while Animated is chosen,+and Mini player: Apple Music style (the tab bar's minimize on scroll), Device button (the now playing bar keeps+Spotify's device button in that minimized row, off by default) and the device button hidden on the full bar,+checked in the simulator against harness/player/ (`settings`). Vibrations, a page of its own under eitherlook, leads with a preview (Shared/Haptics/SGVibrationsPreview.m): rings of dots that a tap sends a crest across, outfrom the middle in the accent colour, higher and further the stronger the Strength, while the first of Controls andGenerated that is on plays its own tap through its own path (Controls' add tap, or one kick of Generated's with itsdiff --git a/harness/player/README.md b/harness/player/README.mdindex 5b8a7d8e..a7dd654c 100644--- a/harness/player/README.md+++ b/harness/player/README.md@@ -63,10 +63,11 @@ come late, out of order, or not at all.`motion checks: n of 11 right -- PASS` or `FAIL`.- `settings` opens the redesign's Player page (`PlayerSettings.m`, with the real `Settings/` framework) over the- player at 3 s, with the clip of `motion` in. It checks the showcase leads the page in the window's shape, the- background and device button rows are on the page, and then, as the Background pull-down picks each in turn,- that the showcase shows Animated (the clip, the cover gone, Low Data Mode's row in), Fluid, Colours, Still and- Animated again. The log ends with `settings checks: n of 7 right -- PASS` or `FAIL`.+ player at 3 s, with the clip of `motion` in. It checks the card leads the page with the four backgrounds'+ segmented control under it, the Mini player section's three rows are on the page, and then, as the control+ picks each in turn, that the card shows Animated (the clip, the sources and Low Data Mode's rows in), Fluid,+ Colours, Still and Animated again, with a note for each and the header the same height throughout. The log+ ends with `settings checks: n of 7 right -- PASS` or `FAIL`.`HARNESS_VOLUME=0` leaves out the volume row that the phone has and the tree does not.diff --git a/harness/player/main.m b/harness/player/main.mindex 38a7a42f..461a4999 100644--- a/harness/player/main.m+++ b/harness/player/main.m@@ -20,8 +20,9 @@// laid out, then the field, the lyrics, a field built again, the menu's switch and the player// closed, each step checked; the log ends with motion checks n of m right -- PASS or FAIL// settings the redesign's Player page (PlayerSettings.m) over the player with the clip of `motion`: the-// showcase over Animated, then Fluid, Colours and Still as the Background menu picks them, and-// Animated again; each step checked, the log ends with settings checks n of m right -- PASS or FAIL+// card over Animated, then Fluid, Colours and Still as the segmented control picks them, and+// Animated again, the note under it changing and the rows under the header holding still;+// each step checked, the log ends with settings checks n of m right -- PASS or FAIL// HARNESS_VOLUME=0 leaves out the volume row the phone has (trees/clean/player/01.txt has none).#import <UIKit/UIKit.h>#import <objc/runtime.h>@@ -919,28 +920,33 @@ static UIView *firstOfClass(UIView *root, NSString *name) {return nil;}-// The Player page over the player, its showcase checked for each background the Background menu picks.+// The Player page over the player, its card checked for each background the segmented control picks.- (void)runSettingsChecks {__block UINavigationController *nav;+ __block CGFloat headerHeight = 0;UITableView *(^table)(void) = ^{ return ((UITableViewController *)nav.topViewController).tableView; };UIView *(^showcase)(void) = ^{ return firstOfClass(table().tableHeaderView, @"SGRPlayerShowcase"); };- // The Background row's pull-down, picked as a tap on its item does.+ UISegmentedControl *(^control)(void) = ^{ return (UISegmentedControl *)firstOfClass(table().tableHeaderView, @"UISegmentedControl"); };+ // A segment picked as a tap on it does.void (^pick)(NSUInteger) = ^(NSUInteger index) {- UIButton *button = (UIButton *)[table() cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].accessoryView;- UIAction *item = (UIAction *)button.menu.children[index];- NSLog(@"[harness] Background menu offers %@, picking %@", [[button.menu.children valueForKey:@"title"] componentsJoinedByString:@" / "], item.title);- [item performWithSender:button target:nil];+ UISegmentedControl *segments = control();+ segments.selectedSegmentIndex = (NSInteger)index;+ [segments sendActionsForControlEvents:UIControlEventValueChanged];};void (^expectBackground)(NSString *, BOOL, BOOL, BOOL) = ^(NSString *step, BOOL fluid, BOOL flows, BOOL clip) {UIView *view = showcase();SGRArtworkField *field = (SGRArtworkField *)firstOfClass(view, @"SGRArtworkField");UIView *motion = firstOfClass(view, @"SGRPlayerMotionView");UIView *cover = [view valueForKey:@"_cover"];- NSInteger lowData = [table() numberOfRowsInSection:0];- BOOL ok = field && field.fluid == fluid && field.flows == flows && (motion != nil) == clip && cover.hidden == clip && lowData == (clip ? 2 : 1);- [self expect:ok step:step detail:[NSString stringWithFormat:@"field %@ fluid %d flows %d, clip %@, cover %@, %ld rows over the device button (%@)",+ UILabel *note = [nav.topViewController valueForKey:@"_note"];+ NSInteger rows = [table() numberOfRowsInSection:0];+ CGFloat height = table().tableHeaderView.bounds.size.height;+ BOOL ok = field && field.fluid == fluid && field.flows == flows && (motion != nil) == clip && !cover.hidden && rows == (clip ? 2 : 0)+ && note.text.length && (headerHeight == 0 || fabs(height - headerHeight) < 0.5);+ headerHeight = height;+ [self expect:ok step:step detail:[NSString stringWithFormat:@"field %@ fluid %d flows %d, clip %@, cover %@, %ld rows over the Mini player (%@), header %.0f, note \"%@\"",field ? @"in" : @"missing", field.fluid, field.flows, motion ? @"on" : @"off", cover.hidden ? @"hidden" : @"shown",- (long)lowData, view.accessibilityValue]];+ (long)rows, view.accessibilityValue, height, note.text]];};// The clip is in by 3 s (the motion scenario's first step), and the page opens over the player then.after(3, ^{@@ -950,13 +956,16 @@ static UIView *firstOfClass(UIView *root, NSString *name) {});after(4, ^{UIView *view = showcase();- CGSize window = self.window.bounds.size;- BOOL shaped = view.window && fabs(view.bounds.size.width / view.bounds.size.height - window.width / window.height) < 0.01;- [self expect:shaped step:@"the showcase leads the page"- detail:[NSString stringWithFormat:@"%@ in a header of %@", NSStringFromCGRect(view.frame), NSStringFromCGRect(table().tableHeaderView.frame)]];+ UISegmentedControl *segments = control();+ CGRect card = view.frame, header = table().tableHeaderView.frame;+ BOOL shaped = view.window && card.size.width > card.size.height && card.size.width > header.size.width - 48;+ [self expect:shaped && segments.numberOfSegments == 4 && CGRectGetMinY(segments.frame) > CGRectGetMaxY(card)+ step:@"the card leads the page, the four backgrounds under it"+ detail:[NSString stringWithFormat:@"card %@ in a header of %@, control %@ with %ld segments", NSStringFromCGRect(card),+ NSStringFromCGRect(header), NSStringFromCGRect(segments.frame), (long)segments.numberOfSegments]];NSInteger sections = table().numberOfSections;- [self expect:sections == 2 && [table() numberOfRowsInSection:1] == 1 step:@"the background and device button rows on the page"- detail:[NSString stringWithFormat:@"%ld sections", (long)sections]];+ [self expect:sections == 2 && [table() numberOfRowsInSection:1] == 3 step:@"the Mini player section on the page"+ detail:[NSString stringWithFormat:@"%ld sections, %ld rows in the second", (long)sections, (long)[table() numberOfRowsInSection:1]]];expectBackground(@"Animated", YES, NO, YES);pick(2);});diff --git a/harness/player/stubs.m b/harness/player/stubs.mindex 699e66af..9dd299de 100644--- a/harness/player/stubs.m+++ b/harness/player/stubs.m@@ -174,5 +174,11 @@ void SGMotionClipFor(NSURL *canvas, NSString *artist, NSString *album, SGMotionSif (!canvas) { apple(); return; }SGMotionFile(canvas, ^(NSURL *file) { if (file) done(file); else apple(); });}-SGModRow *SGMotionSourcesRow(void) { return nil; }+// The Artwork sources row as a link to nowhere, so the Player page's rows under the card can be counted.+#import "Settings/SGModPage.h"+SGModRow *SGMotionSourcesRow(void) { return SGPageRow(@"Artwork sources", ^UIViewController *{ return nil; }); }BOOL SGMotionAppleMusicOn(void) { return YES; }++// TabBar.x: the Mini player section's Apple Music style switch lays the tab bar out again; there is none here.+void SGRSetTabBarMinimized(BOOL minimized, BOOL animated) {}+void SGRRefreshTabBar(void) {}diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.hindex 76efa73e..336f6f7c 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.h@@ -8,8 +8,14 @@@class SGModRow;#define SGRHideBarConnect @"spotifyglass.redesign.hide.barConnect" // the device button on the card+// The device button kept on the card in the minimized tab bar's row (NowPlayingBar.x), off unless set: by+// default the row has the cover, the title and play alone, as the Music app's. Read each time the card goes+// into the row, so a change shows the next time the bar minimizes.+#define SGRKeyBarInlineConnect @"spotifyglass.redesign.nowPlayingBar.inlineConnect"-// The bar's rows, on the Player page under its showcase (Redesigned/Player/PlayerSettings.m).+// The bar's rows, the Mini player section of the Player page (Redesigned/Player/PlayerSettings.m): Apple+// Music style (the tab bar's Minimize on scroll, Redesigned/Navbar/Navbar.h), the device button in that+// row, and the device button hidden on the full card.NSArray<SGModRow *> *SGRNowPlayingBarRows(void);// The bar's glass card in `host`'s coordinates, with its corner radius; CGRectNull before the bar hasdiff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.xindex 8dc97d0b..1cf05056 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBar.x@@ -230,7 +230,8 @@ static BOOL setEdges(UIView *bar, CGFloat left, CGFloat right) {}// In the row the card keeps the cover, the title and play, as the Music app's does: the device and add-// buttons stand aside while it is there and come back with the full card. Only what this hid is shown again.+// buttons stand aside while it is there and come back with the full card, the device button staying when the+// Player page's Device button asks for it (SGRKeyBarInlineConnect). Only what this hid is shown again.static NSHashTable<UIView *> *sg_tucked;static void tuckExtras(UIView *bar, BOOL tuck) {@@ -240,9 +241,11 @@ static void tuckExtras(UIView *bar, BOOL tuck) {[sg_tucked removeAllObjects];return;}+ BOOL keepConnect = SGHidden(SGRKeyBarInlineConnect);SGForEachView(bar, ^(UIView *v) {NSString *name = v.accessibilityIdentifier;- if (![name isEqualToString:@"Components.ConnectButtonOutputSwitcher"] && ![name isEqualToString:@"Components.UI.AddToButton"]) return;+ BOOL connect = [name isEqualToString:@"Components.ConnectButtonOutputSwitcher"];+ if ((!connect || keepConnect) && ![name isEqualToString:@"Components.UI.AddToButton"]) return;// The stack's own item, so the stack closes the gap.UIView *item = v;while (item.superview && item.superview != bar && ![item.superview isKindOfClass:UIStackView.class]) item = item.superview;diff --git a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.mindex 04bf2c49..d4d2852a 100644--- a/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m+++ b/tweak/Sources/Redesigned/NowPlayingBar/NowPlayingBarSettings.m@@ -1,11 +1,22 @@-// The now playing bar's rows of the redesign, on the Player page under its showcase+// The now playing bar's rows of the redesign, the Mini player section of the Player page// (Redesigned/Player/PlayerSettings.m puts them there).#import "Core/SGCore.h"#import "Settings/SGModPage.h"+#import "Redesigned/Navbar/Navbar.h"#import "NowPlayingBar.h"NSArray<SGModRow *> *SGRNowPlayingBarRows(void) {+ // The tab bar reads the switch as each scroll goes; a bar minimized when it goes off grows back at once.+ SGModRow *minimize = SGSwitchRow(@"Apple Music style", @"Between two tabs as a page scrolls down", SGRKeyNavbarMinimize);+ minimize.changed = ^(BOOL on) {+ if (!on) SGRSetTabBarMinimized(NO, NO);+ SGRRefreshTabBar();+ };+ SGModRow *inlineConnect = SGOptionRow(@"Device button", @"Kept on the bar between the tabs", SGRKeyBarInlineConnect);+ inlineConnect.waitsOn = SGRKeyNavbarMinimize;return @[- SGHideRow(@"Hide the device button", @"On the now playing bar", SGRHideBarConnect),+ minimize,+ inlineConnect,+ SGHideRow(@"Hide the device button", @"On the full now playing bar", SGRHideBarConnect),];}diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 17e93b5f..3f7b8984 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -100,8 +100,9 @@ UIView *SGRPlayerMotionPreview(void);#pragma mark - Mod Settings (PlayerSettings.m)-// The redesign's Player page: a showcase of the player over the background chosen, the background's and-// the now playing bar's rows under it, then `more`, the sections either look shares (App/Pages.m).+// The redesign's Player page: a card of the player over the background chosen and the control that picks+// it, the background's rows and the Mini player section under it, then `more`, the sections either look+// shares (App/Pages.m).UIViewController *SGRPlayerSettingsPage(NSArray *more);// Alpha 0, no touches, hidden from accessibility, set again on every call: for Spotify's Swift views,diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex 7b629e3f..183bd0bd 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -1,21 +1,22 @@// The redesign's Player page in Mod Settings (App/Pages.m opens it in place of the native look's).//-// It leads with a showcase of the player: a small copy of it in the player's own proportions, over the-// background chosen on the page, with the playing track's cover, title and artist, and above the artwork a-// glass sheet carrying the player's sliders, progress and volume, with previous, play and next between-// them. The progress is where the track was when the page appeared and the volume is the phone's.+// It leads with a card of the player as the now playing track shows on it: the background chosen on the+// page edge to edge, and over its foot the cover, the title, the artist and how far the track has played.+// The progress is where the track was when the page appeared.//// The background is the player's own: a field of the same kind (Still, Colours, Fluid), and for Animated-// the clip the player is playing (SGRPlayerMotionPreview) in place of the cover, or Fluid and the cover-// while there is none, as in the player. It moves under the field's own conditions (in a window, Spotify-// in front, Reduce Motion and Low Power Mode off). Picking another background changes the showcase at-// once; the player takes it after a restart, as the note under the showcase says.+// the clip the player is playing (SGRPlayerMotionPreview) in place of the field, or Fluid while there is+// none, as in the player. It moves under the field's own conditions (in a window, Spotify in front, Reduce+// Motion and Low Power Mode off). Under the card a segmented control picks the background, all four of+// them: the names are one short word each, so they fit side by side at the narrowest iPhone width, and+// every choice stays one tap away with the card showing it at once. A note under the control says what the+// choice does; it is given the room of the longest note, so the rows under it hold still as it changes.//-// Under the showcase: the background and its Low Data Mode switch, the now playing bar's device button-// (Redesigned/NowPlayingBar/NowPlayingBarSettings.m), then the sections either look shares.+// Under the header: the rows that follow the choice (Animated's sources and its Low Data Mode switch;+// Fluid has no settings of its own), the Mini player section (Redesigned/NowPlayingBar/+// NowPlayingBarSettings.m), then the sections either look shares.//// Threading: main thread only.-#import <AVFoundation/AVFoundation.h>#import "Core/SGCore.h"#import "Settings/SGModPage.h"#import "Settings/SGPageStyle.h"@@ -24,12 +25,20 @@#import "Shared/AnimatedArtwork/AnimatedArtwork.h"#import "Player.h"-// The showcase's height on the page; its width follows the window's shape.-static const CGFloat kShowcaseHeight = 340;-// The player's layout on a 402 x 874 screen, as shares of the showcase's width (w) and height (h).-static const CGFloat kCoverTop = 0.14; // h, the cover's top under the header-static const CGFloat kCoverSide = 0.88; // w, 354 of 402-static const CGFloat kScreenRadius = 0.063; // h, a 55pt display corner+// The card's height as a share of its width, kept between the two bounds.+static const CGFloat kCardAspect = 0.5, kCardMinHeight = 168, kCardMaxHeight = 220;+static const CGFloat kCardRadius = 26; // continuous, the radius of the page's own cards and then some+static const CGFloat kCardPadding = 16, kCoverSide = 64;++// What each background does, in SGRPlayerBackgroundKind's order.+static NSArray<NSString *> *backgroundNotes(void) {+ return @[+ @"The cover, blurred and held still.",+ @"The cover's colours, drifting slowly.",+ @"The cover itself, blurred and slowly turning. It rests while a song is paused.",+ @"The song's Canvas or the album's moving cover, else Fluid. The player's ⋯ menu switches between the two.",+ ];+}@interface SGRPlayerShowcase : UIView <SGPlayerStateObserver>- (void)reloadTrack;@@ -41,37 +50,15 @@ static const CGFloat kScreenRadius = 0.063; // h, a 55pt display cornerUIView *_motion;UIImageView *_cover;UILabel *_title, *_artist;- UIVisualEffectView *_sheet;- UIView *_progress, *_progressFill, *_volume, *_volumeFill;- UIImageView *_previous, *_play, *_next, *_quiet, *_loud;- CGFloat _position, _level;-}--// A slider of the player as it is drawn at rest: a track, and in it a fill up to the value (its only subview).-static UIView *bar(UIView *host) {- UIView *track = [UIView new];- track.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];- track.layer.cornerCurve = kCACornerCurveContinuous;- track.clipsToBounds = YES;- UIView *fill = [UIView new];- fill.backgroundColor = SGRPrimary();- [track addSubview:fill];- [host addSubview:track];- return track;-}--static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {- UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage systemImageNamed:symbol]];- view.tintColor = color;- view.contentMode = UIViewContentModeCenter;- [host addSubview:view];- return view;+ UIView *_progress, *_progressFill;+ CGFloat _position;}- (instancetype)initWithFrame:(CGRect)frame {if (!(self = [super initWithFrame:frame])) return nil;self.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;self.clipsToBounds = YES;+ self.layer.cornerRadius = kCardRadius;self.layer.cornerCurve = kCACornerCurveContinuous;self.backgroundColor = SGRNeutralField();self.userInteractionEnabled = NO;@@ -86,33 +73,30 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {_cover = [UIImageView new];_cover.contentMode = UIViewContentModeScaleAspectFill;_cover.clipsToBounds = YES;+ _cover.layer.cornerRadius = 8;_cover.layer.cornerCurve = kCACornerCurveContinuous;_cover.tintColor = SGRTertiary();_cover.backgroundColor = SGRSolidGlassFill();+ _cover.preferredSymbolConfiguration = [UIImageSymbolConfiguration configurationWithPointSize:22 weight:UIImageSymbolWeightRegular];[self addSubview:_cover];_title = [UILabel new];_title.textColor = SGRPrimary();+ _title.font = [UIFont systemFontOfSize:17 weight:UIFontWeightSemibold];[self addSubview:_title];_artist = [UILabel new];_artist.textColor = SGRSecondary();+ _artist.font = [UIFont systemFontOfSize:15];[self addSubview:_artist];- // The sheet is the control layer, so it is glass; the artwork under it is content.- _sheet = [[UIVisualEffectView alloc] initWithEffect:SGRReduceTransparency() ? nil : SGGlassEffect()];- if (SGRReduceTransparency()) _sheet.backgroundColor = SGRSolidGlassFill();- _sheet.overrideUserInterfaceStyle = UIUserInterfaceStyleDark;- [self addSubview:_sheet];- UIView *content = _sheet.contentView;- _progress = bar(content);- _progressFill = _progress.subviews.firstObject;- _volume = bar(content);- _volumeFill = _volume.subviews.firstObject;- _previous = glyph(content, @"backward.fill", SGRPrimary());- _play = glyph(content, @"play.fill", SGRPrimary());- _next = glyph(content, @"forward.fill", SGRPrimary());- _quiet = glyph(content, @"speaker.fill", SGRSecondary());- _loud = glyph(content, @"speaker.wave.3.fill", SGRSecondary());+ // The player's slider as it is drawn at rest: a track, and in it a fill up to where the song is.+ _progress = [UIView new];+ _progress.backgroundColor = [UIColor colorWithWhite:1 alpha:0.2];+ _progress.clipsToBounds = YES;+ _progressFill = [UIView new];+ _progressFill.backgroundColor = SGRPrimary();+ [_progress addSubview:_progressFill];+ [self addSubview:_progress];SGAddPlayerStateObserver(self);[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(artworkChanged) name:SGRNowPlayingArtworkDidChangeNotification object:nil];@@ -138,15 +122,13 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {[_field setArtwork:image identity:identity animated:self.window != nil];}-// The track, where it is, whether it plays, and the volume, read again.+// The track, where it is and whether it plays, read again.- (void)reloadTrack {SPTPlayerState *state = SGPlayerState();SPTPlayerTrack *track = state.track;_title.text = track.trackTitle.length ? track.trackTitle : @"Not Playing";_artist.text = track.artistName ?: @"";_position = state.duration > 0 ? MIN(1, MAX(0, state.position / state.duration)) : 0;- _level = AVAudioSession.sharedInstance.outputVolume;- _play.image = [UIImage systemImageNamed:state.isPlaying && !state.isPaused ? @"pause.fill" : @"play.fill"];// The clip covers the field, which then holds still, as in the player (PlayerMotion.x)._field.motionHeld = state.isPaused || _motion != nil;if (SGRNowPlayingArtwork(NULL, NULL)) {@@ -168,7 +150,6 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {[self->_motion removeFromSuperview];self->_motion = kind == SGRPlayerBackgroundAnimated ? SGRPlayerMotionPreview() : nil;if (self->_motion) [self insertSubview:self->_motion aboveSubview:self->_field];- self->_cover.hidden = self->_motion != nil;self->_field.motionHeld = SGPlayerState().isPaused || self->_motion != nil;};self.accessibilityValue = [SGRPlayerBackgroundNames()[(NSUInteger)kind] stringByAppendingString:@" background"];@@ -182,60 +163,26 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {[self setNeedsLayout];}+// The clip runs from the card's top at its width, as in the player, and its blur comes in from the+// seam under the controls, which on a card this short is over its foot, under the words.- (void)layoutSubviews {[super layoutSubviews];CGRect bounds = self.bounds;CGFloat w = bounds.size.width, h = bounds.size.height;- self.layer.cornerRadius = round(h * kScreenRadius);_field.frame = bounds;_field.backdropHeight = h;_motion.frame = bounds;- CGFloat side = round(w * kCoverSide), x = round((w - side) / 2);- _cover.frame = CGRectMake(x, round(h * kCoverTop), side, side);- _cover.layer.cornerRadius = side * SGRRadiusArtwork / 354;- _cover.preferredSymbolConfiguration = [UIImageSymbolConfiguration configurationWithPointSize:side * 0.3 weight:UIImageSymbolWeightRegular];-- _title.font = [UIFont systemFontOfSize:w * 0.055 weight:UIFontWeightBold];- _artist.font = [UIFont systemFontOfSize:w * 0.045];- CGFloat y = CGRectGetMaxY(_cover.frame) + round(h * 0.035);- _title.frame = CGRectMake(x, y, side, ceil(_title.font.lineHeight));- _artist.frame = CGRectMake(x, CGRectGetMaxY(_title.frame), side, ceil(_artist.font.lineHeight));-- CGFloat inset = round(w * 0.035), top = CGRectGetMaxY(_artist.frame) + round(h * 0.025);- _sheet.frame = CGRectMake(inset, top, w - 2 * inset, h - inset - top);- SGShapeGlass(_sheet, round(w * 0.075), NO);- if (!_sheet.effect) {- _sheet.layer.cornerRadius = round(w * 0.075);- _sheet.layer.cornerCurve = kCACornerCurveContinuous;- _sheet.clipsToBounds = YES;- }-- CGSize sheet = _sheet.bounds.size;- CGFloat pad = round(sheet.width * 0.07), line = MAX(2, round(w * 0.012));- CGFloat width = sheet.width - 2 * pad;- _progress.frame = CGRectMake(pad, round(sheet.height * 0.17), width, line);+ _cover.frame = CGRectMake(kCardPadding, h - kCardPadding - kCoverSide, kCoverSide, kCoverSide);+ CGFloat x = CGRectGetMaxX(_cover.frame) + 12, width = w - kCardPadding - x;+ CGFloat line = 4, titleHeight = ceil(_title.font.lineHeight), artistHeight = ceil(_artist.font.lineHeight);+ CGFloat bottom = CGRectGetMaxY(_cover.frame);+ _progress.frame = CGRectMake(x, bottom - line - 2, width, line);+ _progress.layer.cornerRadius = line / 2;_progressFill.frame = CGRectMake(0, 0, round(width * _position), line);-- CGFloat speaker = round(w * 0.06), gap = round(w * 0.02);- CGFloat volumeY = round(sheet.height * 0.83);- _quiet.frame = CGRectMake(pad, volumeY - speaker / 2, speaker, speaker);- _loud.frame = CGRectMake(sheet.width - pad - speaker, volumeY - speaker / 2, speaker, speaker);- CGFloat volumeX = CGRectGetMaxX(_quiet.frame) + gap, volumeWidth = CGRectGetMinX(_loud.frame) - gap - volumeX;- _volume.frame = CGRectMake(volumeX, volumeY - line / 2, volumeWidth, line);- _volumeFill.frame = CGRectMake(0, 0, round(volumeWidth * _level), line);- _progress.layer.cornerRadius = _volume.layer.cornerRadius = line / 2;-- CGFloat middle = round(sheet.height * 0.5), button = round(w * 0.16);- _play.frame = CGRectMake(round((sheet.width - button) / 2), middle - button / 2, button, button);- _previous.frame = CGRectOffset(_play.frame, -round(sheet.width * 0.28), 0);- _next.frame = CGRectOffset(_play.frame, round(sheet.width * 0.28), 0);- UIImageSymbolConfiguration *large = [UIImageSymbolConfiguration configurationWithPointSize:w * 0.1 weight:UIImageSymbolWeightBold];- UIImageSymbolConfiguration *small = [UIImageSymbolConfiguration configurationWithPointSize:w * 0.07 weight:UIImageSymbolWeightBold];- _play.preferredSymbolConfiguration = large;- _previous.preferredSymbolConfiguration = _next.preferredSymbolConfiguration = small;- _quiet.preferredSymbolConfiguration = _loud.preferredSymbolConfiguration =- [UIImageSymbolConfiguration configurationWithPointSize:w * 0.032 weight:UIImageSymbolWeightSemibold];+ CGFloat textBottom = CGRectGetMinY(_progress.frame) - 10;+ _artist.frame = CGRectMake(x, textBottom - artistHeight, width, artistHeight);+ _title.frame = CGRectMake(x, CGRectGetMinY(_artist.frame) - titleHeight, width, titleHeight);}@end@@ -244,6 +191,7 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {@interface SGRPlayerPage : SGModPage@property (nonatomic, strong) SGRPlayerShowcase *showcase;+@property (nonatomic, strong) UISegmentedControl *backgrounds;@end@implementation SGRPlayerPage {@@ -255,29 +203,46 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {[super viewDidLoad];_header = [UIView new];[_header addSubview:self.showcase];+ [_header addSubview:self.backgrounds];_note = [UILabel new];- _note.text = SGRestartNote;_note.font = SGSubtitleFont();_note.textColor = SGGrey();_note.numberOfLines = 0;[_header addSubview:_note];+ [self showNote];self.tableView.tableHeaderView = _header;}+- (void)showNote {+ _note.text = backgroundNotes()[(NSUInteger)SGRPlayerBackground()];+ [self.view setNeedsLayout];+}+// The header keeps the height it is given, so it is sized here and given back to the table only when that-// changes (a table header set on every pass lays the table out again forever).+// changes (a table header set on every pass lays the table out again forever). The note's room is that of+// the longest note at this width, so picking a background never moves the rows.- (void)viewWillLayoutSubviews {[super viewWillLayoutSubviews];UITableView *table = self.tableView;CGFloat width = table.bounds.size.width, inset = table.layoutMargins.left;- CGSize window = table.window.bounds.size;- CGFloat aspect = window.height > 0 ? window.width / window.height : 402.0 / 874.0;- CGFloat showcaseWidth = round(kShowcaseHeight * aspect);- self.showcase.frame = CGRectMake(round((width - showcaseWidth) / 2), 16, showcaseWidth, kShowcaseHeight);- CGFloat noteWidth = width - 2 * inset;+ CGFloat cardWidth = width - 2 * inset;+ CGFloat cardHeight = round(MIN(kCardMaxHeight, MAX(kCardMinHeight, cardWidth * kCardAspect)));+ self.showcase.frame = CGRectMake(inset, 16, cardWidth, cardHeight);+ CGFloat controlHeight = MAX(32, ceil([self.backgrounds sizeThatFits:CGSizeMake(cardWidth, CGFLOAT_MAX)].height));+ self.backgrounds.frame = CGRectMake(inset, CGRectGetMaxY(self.showcase.frame) + 12, cardWidth, controlHeight);++ CGFloat noteWidth = cardWidth - 2 * 4, room = 0;+ UILabel *measure = [UILabel new];+ measure.font = _note.font;+ measure.numberOfLines = 0;+ for (NSString *text in backgroundNotes()) {+ measure.text = text;+ room = MAX(room, ceil([measure sizeThatFits:CGSizeMake(noteWidth, CGFLOAT_MAX)].height));+ }CGFloat noteHeight = ceil([_note sizeThatFits:CGSizeMake(noteWidth, CGFLOAT_MAX)].height);- _note.frame = CGRectMake(inset, CGRectGetMaxY(self.showcase.frame) + 16, noteWidth, noteHeight);- CGSize size = CGSizeMake(width, CGRectGetMaxY(_note.frame));+ CGFloat noteTop = CGRectGetMaxY(self.backgrounds.frame) + 8;+ _note.frame = CGRectMake(inset + 4, noteTop, noteWidth, noteHeight);+ CGSize size = CGSizeMake(width, noteTop + room);if (CGSizeEqualToSize(_header.bounds.size, size)) return;_header.frame = (CGRect){CGPointZero, size};table.tableHeaderView = _header;@@ -285,34 +250,43 @@ static UIImageView *glyph(UIView *host, NSString *symbol, UIColor *color) {- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated];+ // The player's ⋯ menu can switch Animated and Fluid while the page is away.+ self.backgrounds.selectedSegmentIndex = SGRPlayerBackground();+ [self showNote];[self.showcase reloadTrack];[self.showcase reloadBackgroundAnimated:NO];}+- (void)backgroundPicked {+ SGSetInt(SGRKeyPlayerBackground, self.backgrounds.selectedSegmentIndex);+ [self.showcase reloadBackgroundAnimated:YES];+ [self showNote];+ [self refreshVisibility];+}+@endUIViewController *SGRPlayerSettingsPage(NSArray *more) {- SGRPlayerShowcase *showcase = [[SGRPlayerShowcase alloc] initWithFrame:CGRectMake(0, 0, 160, kShowcaseHeight)];- __block __weak SGRPlayerPage *weakPage;- NSArray<NSString *> *names = SGRPlayerBackgroundNames();- // A pull-down rather than a list of its own, so the showcase changes in front of you.- SGModRow *background = SGMenuRow(@"Background", names, ^NSString *{ return names[(NSUInteger)SGRPlayerBackground()]; }, ^(NSInteger index) {- SGSetInt(SGRKeyPlayerBackground, index);- [showcase reloadBackgroundAnimated:YES];- [weakPage refreshVisibility];- });- SGModRow *lowData = SGOptionRow(@"Download in Low Data Mode", @"Animated artwork, up to about 7 MB a song", SGKeyMotionLowData);+ SGRPlayerShowcase *showcase = [[SGRPlayerShowcase alloc] initWithFrame:CGRectMake(0, 0, 320, kCardMinHeight)];+ UISegmentedControl *backgrounds = [[UISegmentedControl alloc] initWithItems:SGRPlayerBackgroundNames()];+ backgrounds.selectedSegmentIndex = SGRPlayerBackground();+ backgrounds.accessibilityLabel = @"Background";++ SGModRow *lowData = SGOptionRow(@"Download in Low Data Mode", @"Up to about 7 MB a song", SGKeyMotionLowData);lowData.visible = ^BOOL { return SGRPlayerBackground() == SGRPlayerBackgroundAnimated; };SGModRow *sources = SGMotionSourcesRow();sources.visible = lowData.visible;NSMutableArray<SGModSection *> *sections = [NSMutableArray arrayWithObjects:- SGNotedSection(nil, @[background, sources, lowData],- @"Animated plays the first clip its sources have, over Fluid, and the player's ⋯ menu switches between the two."),- SGSection(nil, SGRNowPlayingBarRows()), nil];+ SGSection(nil, @[sources, lowData]),+ SGNotedSection(@"Mini player", SGRNowPlayingBarRows(),+ @"Apple Music style shrinks the tab bar to two tabs as a page scrolls down and puts the now "+ "playing bar between them; scrolling back up undoes it. There the bar keeps its cover, title "+ "and play button, and the device button too when it is on."), nil];[sections addObjectsFromArray:more];- SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:nil];+ SGRPlayerPage *page = [[SGRPlayerPage alloc] initWithTitle:@"Player" intro:nil sections:sections footer:SGRestartNote];page.showcase = showcase;- weakPage = page;+ page.backgrounds = backgrounds;+ [backgrounds addTarget:page action:@selector(backgroundPicked) forControlEvents:UIControlEventValueChanged];return page;}