Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.
C
feat: Hide the controls can keep the title over the lyrics (#133)
My-Name-Is-Jeff80c6d54fda04
diff --git a/docs/tweaks.md b/docs/tweaks.mdindex 565ed085..a57c4073 100644--- a/docs/tweaks.md+++ b/docs/tweaks.md@@ -588,10 +588,12 @@ Redesigned:a paused song's hills have settled. The spectrum is checked on the Mac against harness/visualiser/,the view in the simulator against harness/player/ (`visualiser`)Lyrics/ the full screen lyrics page on glass with Apple Music style lyrics over it, always on (SGRKaraokeView,- which the player shows in itself too, Player/PlayerLyrics.x, where with Hide the controls on- everything else -- the header row, the thumbnail, the title row and the controls -- fades a few- seconds after the last touch and the lines take the whole safe area until a tap): lines sung over each other lit together,- the stack moving on once the first is sung out; an instrumental break of 7 s or more held by three dots+ which the player shows in itself too, Player/PlayerLyrics.x, where with Hide the controls set to+ Everything, everything else -- the header row, the thumbnail, the title row and the controls --+ fades a few seconds after the last touch and the lines take the whole safe area until a tap; set+ to Keep the title, only the controls under the title row and the lyrics' own button fade and the+ lines grow down into their room): lines sung over each other lit together, the stack moving on+ once the first is sung out; an instrumental break of 7 s or more held by three dotsthat breathe and fill over its length on a Core Animation timeline laid against the song's clock; anda line's pronunciation (under the words it spells) and translation, switched on from a glass button inthe lyrics' corner that shows only for a song that has them, in the order of sizes the Lyrics page setsdiff --git a/tweak/Sources/App/Pages.m b/tweak/Sources/App/Pages.mindex d698a7ab..b63a4858 100644--- a/tweak/Sources/App/Pages.m+++ b/tweak/Sources/App/Pages.m@@ -117,7 +117,7 @@ static UIViewController *lyricsPage(void) {if (redesigned) {[sections addObjectsFromArray:@[SGSection(@"Display", @[SGRLyricsTextSizesRow(), SGLyricsWordTimingRow(), SGLyricsRomanisedRow(),- SGSwitchRow(@"Hide the controls", @"A few seconds after the last touch, the lyrics take the whole player", SGRKeyLyricsAutoHide),+ SGRLyricsHideRow(),SGSwitchRow(@"Landscape lyrics", @"Turn the phone with the lyrics open", SGRKeyLyricsLandscape)]),timing,SGSection(@"Translation", [[[@[SGLyricsTranslationLanguageRow(), SGTranslateEverySongRow()] arrayByAddingObjectsFromArray:SGOnDeviceTranslatorRows()]diff --git a/tweak/Sources/Redesigned/Player/Player.h b/tweak/Sources/Redesigned/Player/Player.hindex 09f1c50e..8ba4944e 100644--- a/tweak/Sources/Redesigned/Player/Player.h+++ b/tweak/Sources/Redesigned/Player/Player.h@@ -101,10 +101,16 @@ static inline Class SGRDJClass(NSString *name) {NSString *mangled = [NSString stringWithFormat:@"_TtC%lu%@%lu%@", (unsigned long)module.length, module, (unsigned long)name.length, name];return NSClassFromString(mangled) ?: NSClassFromString([NSString stringWithFormat:@"%@.%@", module, name]);}-// The controls under the lines fade a few seconds after the last touch while the lyrics play, and the-// lines grow down into their room (PlayerLyrics.x). On until switched off; a scroll through the lines-// hides them either way.+// What fades a few seconds after the last touch while the lyrics play, as the lines grow into the room+// (PlayerLyrics.x): nothing, everything but the lines, or the controls under the title row alone. A scroll+// through the lines hides the same views, everything when the choice is Off. The key was a switch first: its+// NO and YES are the first two indexes, and unset reads as the switch did.#define SGRKeyLyricsAutoHide @"spotifyglass.redesign.lyrics.autoHide"+typedef NS_ENUM(NSInteger, SGRLyricsHide) { SGRLyricsHideOff, SGRLyricsHideAll, SGRLyricsHideControls };+SGRLyricsHide SGRLyricsHideMode(void);+@class SGModRow;+// The Lyrics page's choice of it (PlayerSettings.m).+SGModRow *SGRLyricsHideRow(void);// A volume slider under the controls (PlayerVolume.m), the system's: this iPhone's, or the Connect device's.// On until switched off. Placed by the footer's layout, between the controls (`controls`) and the footer rowdiff --git a/tweak/Sources/Redesigned/Player/PlayerLandscape.x b/tweak/Sources/Redesigned/Player/PlayerLandscape.xindex d5eb3b22..9004dec6 100644--- a/tweak/Sources/Redesigned/Player/PlayerLandscape.x+++ b/tweak/Sources/Redesigned/Player/PlayerLandscape.x@@ -321,7 +321,10 @@ static UIButton *controlButton(NSString *symbol, CGFloat size, NSString *label,// Back at a tap with the Kit's response, from where a fade out is; they go with the slow fade, as the// portrait player's do (PlayerLyrics.x).SGRAnimate(shown ? SGRMotionRespond : SGRMotionFade, ^{- for (UIView *view in @[self->_controls, self->_close, self->_title, self->_artist]) view.alpha = shown ? 1 : 0;+ // Keeping the title (Player.h), the title and the artist stay over the lines.+ NSArray<UIView *> *fading = SGRLyricsHideMode() == SGRLyricsHideControls ? @[self->_controls, self->_close]+ : @[self->_controls, self->_close, self->_title, self->_artist];+ for (UIView *view in fading) view.alpha = shown ? 1 : 0;self->_lyrics.extrasHidden = !shown;}, nil);if (shown) [self restartRest];@@ -330,7 +333,7 @@ static UIButton *controlButton(NSString *symbol, CGFloat size, NSString *label,- (void)restartRest {[_rest invalidate];_rest = nil;- if (_bare || !SGEnabled(SGRKeyLyricsAutoHide) || SGPlayerState().isPaused || UIAccessibilityIsVoiceOverRunning()) return;+ if (_bare || SGRLyricsHideMode() == SGRLyricsHideOff || SGPlayerState().isPaused || UIAccessibilityIsVoiceOverRunning()) return;__weak SGRLandscapeLyricsController *weakSelf = self;_rest = [NSTimer scheduledTimerWithTimeInterval:kLandscapeRest repeats:NO block:^(NSTimer *timer) {// A sheet over the lines (a line's meanings) keeps them up, and the clock runs again behind it.diff --git a/tweak/Sources/Redesigned/Player/PlayerLyrics.x b/tweak/Sources/Redesigned/Player/PlayerLyrics.xindex 5f66a8a7..8b99bc2c 100644--- a/tweak/Sources/Redesigned/Player/PlayerLyrics.x+++ b/tweak/Sources/Redesigned/Player/PlayerLyrics.x@@ -67,6 +67,17 @@ static BOOL sg_touching; // a finger is on the player, whichstatic NSTimer *sg_rest;static __weak UIGestureRecognizer *sg_wake; // on the player, on while alone: the tap that brings the controls back+SGRLyricsHide SGRLyricsHideMode(void) {+ NSInteger stored = SGInt(SGRKeyLyricsAutoHide, -1);+ return stored >= 0 ? stored : SGEnabled(SGRKeyLyricsAutoHide) ? SGRLyricsHideAll : SGRLyricsHideOff;+}++// Alone, the lines leave the header row, the thumbnail and the title row where they are, the way the Music+// app keeps its title over the lyrics.+static BOOL keepsTitle(void) {+ return SGRLyricsHideMode() == SGRLyricsHideControls;+}+#pragma mark - the overlay// The thumbnail and the lines, side by side under one view so the lines' own view has no sibling of@@ -105,7 +116,8 @@ static __weak UIGestureRecognizer *sg_wake; // on the player, on while alone: th}- (void)sgr_thumbTapped {- if (SGRPlayerLyricsOpen() && !sg_moving) SGRPlayerToggleLyrics();+ // Left on screen while the lines are alone (keepsTitle), a tap on it only wakes the controls (SGRPlayerWake).+ if (SGRPlayerLyricsOpen() && !sg_moving && !sg_alone) SGRPlayerToggleLyrics();}- (UIView *)thumb { return _thumb; }@@ -118,12 +130,12 @@ static __weak UIGestureRecognizer *sg_wake; // on the player, on while alone: th// What it hands them to instead is the title row. Translated to the top of the player it is drawn well// outside the stack view it is arranged in, and UIKit stops looking at a view whose bounds the touch is// not in, so the add button and the menu that rode up with it are past Spotify's own reach. Asked here-// directly, the row answers for where it is drawn. Not while the lines are alone: the row is faded then,-// and a tap where its add button was is the player's, which brings everything back.+// directly, the row answers for where it is drawn. Not while the lines are alone, unless the title is kept: the+// row is faded then, and a tap where its add button was is the player's, which brings everything back.- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {UIView *hit = [super hitTest:point withEvent:event];if (hit != self) return hit;- UIView *row = SGRPlayerLyricsOpen() && !sg_alone ? sg_info.viewIfLoaded : nil;+ UIView *row = SGRPlayerLyricsOpen() && (!sg_alone || keepsTitle()) ? sg_info.viewIfLoaded : nil;UIView *inRow = row ? [row hitTest:[row convertPoint:point fromView:self] withEvent:event] : nil;return inRow == row ? nil : inRow;}@@ -327,20 +339,21 @@ static CGFloat thumbRadius(SGRLyricsLayout l, BOOL open) {// title row, the progress bar, the buttons, the footer and a volume row where the phone has one; the header// row's unit; and the thumbnail. Each fades by its alpha and the stack is left alone. Without the stack, the// units by name. Only views on screen are taken, and only the ones faded (sg_faded) come back, so nothing-// Spotify keeps hidden is shown.+// Spotify keeps hidden is shown. Keeping the title, the header row, the thumbnail and the title row stay.static NSHashTable<UIView *> *sg_faded;static NSArray<UIView *> *fadingViews(void) {- UIView *floating = sg_floating.viewIfLoaded;+ BOOL keeps = keepsTitle();+ UIView *floating = sg_floating.viewIfLoaded, *info = keeps ? sg_info.viewIfLoaded : nil;NSMutableArray<UIView *> *views = [NSMutableArray array];SGRPlayerLyricsOverlay *overlay = objc_getAssociatedObject(sg_host, &kOverlayKey);- UIView *header = sg_header.viewIfLoaded, *thumb = overlay.thumb;+ UIView *header = keeps ? nil : sg_header.viewIfLoaded, *thumb = keeps ? nil : overlay.thumb;if (header && !header.hidden && header.alpha > 0.01) [views addObject:header];if (thumb && !thumb.hidden && thumb.alpha > 0.01) [views addObject:thumb];UIView *stack = SGRFindByIdentifier(sg_host, @"npv.bottomStackView", &kStackKey);if (stack) {for (UIView *view in stack.subviews) {- if ([floating isDescendantOfView:view]) continue;+ if ([floating isDescendantOfView:view] || [info isDescendantOfView:view]) continue;if (!view.hidden && view.alpha > 0.01) [views addObject:view];}return views;@@ -354,6 +367,7 @@ static NSArray<UIView *> *fadingViews(void) {SGForEachView(sg_host, ^(UIView *view) {UIResponder *owner = view.nextResponder;if (![owner isKindOfClass:UIViewController.class] || ((UIViewController *)owner).viewIfLoaded != view) return;+ if (view == info) return;NSString *name = NSStringFromClass(owner.class);for (NSString *unit in names) {if ([name hasSuffix:unit] && !view.hidden && view.alpha > 0.01) [views addObject:view];@@ -376,10 +390,11 @@ static void fadeControls(BOOL faded) {}// Where the lines go on their own: the whole safe area, kLyricsBottom in at both ends, over everything that-// faded. The safe area keeps them from under the status bar and the Dynamic Island.+// faded. The safe area keeps them from under the status bar and the Dynamic Island. Keeping the title, they+// start where they did under it and grow down alone.static CGRect aloneStage(UIView *host, SGRLyricsLayout l) {CGRect safe = UIEdgeInsetsInsetRect(host.bounds, host.safeAreaInsets);- CGFloat top = CGRectGetMinY(safe) + kLyricsBottom;+ CGFloat top = keepsTitle() ? CGRectGetMinY(l.stage) : CGRectGetMinY(safe) + kLyricsBottom;return CGRectMake(CGRectGetMinX(l.stage), top, l.stage.size.width, CGRectGetMaxY(safe) - kLyricsBottom - top);}@@ -416,7 +431,7 @@ static BOOL coveredBySheet(void) {static BOOL mayCount(void) {SPTPlayerState *state = SGPlayerState();UIView *host = sg_host;- return SGEnabled(SGRKeyLyricsAutoHide) && sg_open && !sg_alone && !sg_touching && host.window && state && !state.isPaused+ return SGRLyricsHideMode() != SGRLyricsHideOff && sg_open && !sg_alone && !sg_touching && host.window && state && !state.isPaused&& !UIAccessibilityIsVoiceOverRunning()&& UIApplication.sharedApplication.applicationState == UIApplicationStateActive;}diff --git a/tweak/Sources/Redesigned/Player/PlayerSettings.m b/tweak/Sources/Redesigned/Player/PlayerSettings.mindex d21b32e3..5a48c449 100644--- a/tweak/Sources/Redesigned/Player/PlayerSettings.m+++ b/tweak/Sources/Redesigned/Player/PlayerSettings.m@@ -325,6 +325,13 @@ static SGModRow *fluidSlider(NSString *title, SGRFluidSetting setting, NSString^NSString *(double value) { return [NSString stringWithFormat:@"%.0f%@", value, unit]; });}+SGModRow *SGRLyricsHideRow(void) {+ SGModRow *row = SGChoiceRow(@"Hide the controls", @"A few seconds after the last touch, the lyrics take the room",+ SGRKeyLyricsAutoHide, @[@"Off", @"Everything", @"Keep the title"], SGRLyricsHideMode());+ row.choiceNotes = @[@"The controls stay", @"The lyrics take the whole player", @"The cover, the title and the top row stay; in landscape, the title"];+ return row;+}+UIViewController *SGRPlayerSettingsPage(NSArray *more) {SGRPlayerShowcase *showcase = [[SGRPlayerShowcase alloc] initWithFrame:CGRectMake(0, 0, 320, kCardMinHeight)];UISegmentedControl *backgrounds = [[UISegmentedControl alloc] initWithItems:SGRPlayerBackgroundNames()];