Skip to content

Liquid Glass and Apple Music touches for the Spotify iOS app. A GPL-3.0 fork of spoti.pw 0.21.1.

C

feat: an album's track rows drop the artist line that repeats the album's

My-Name-Is-Jeff7f6ed3de7ce2
diff --git a/docs/tweaks.md b/docs/tweaks.md
index bfa7a905..d410ecc7 100644
--- a/docs/tweaks.md
+++ b/docs/tweaks.md
@@ -322,7 +322,10 @@ Redesigned:
is decoded and moving only in front of the app with Reduce Motion and Low Power Mode off and Auto-Play
Video Previews on), the title, the artist and the kind and date centred under it, and the same row of glass
controls -- play and shuffle float over the album page outside its header, so they are concealed
- there and the row carries the Kit's stand-ins, which draw their glyph and fire them. Under the tracks
+ there and the row carries the Kit's stand-ins, which draw their glyph and fire them. A track's artist line
+ goes where it only repeats the album's artist (with the guests the title names after "feat." and the
+ like), its explicit badge drawn after the title instead (AlbumCredits.m decides, checked on the Mac
+ by harness/album-credits/; a switch on the Albums & artists page). Under the tracks
everything the server sends is dropped -- more by the artist, videos, concerts, merch, you might also
like, and whatever it adds next -- but the album's own line and its copyright, each section back
once its switch on the Albums & artists page is off (told apart by its English heading; in another
diff --git a/harness/album-credits/README.md b/harness/album-credits/README.md
new file mode 100644
index 00000000..322a2265
--- /dev/null
+++ b/harness/album-credits/README.md
@@ -0,0 +1,8 @@
+# Album credits check
+
+ ./build.sh && build/album-credits-check
+
+runs `Redesigned/Album/AlbumCredits.m` on the Mac: which track artist lines an album page in the redesign drops
+as repeats of the album's artist, and the cases that keep theirs (another guest, another order, another
+separator, a guest with no featured-artist marker, Ann against Anne, a compilation, no header yet). Each line
+prints ok or FAIL; the exit status is the number of failures. How a dropped line looks is the album harness's.
diff --git a/harness/album-credits/build.sh b/harness/album-credits/build.sh
new file mode 100755
index 00000000..5b15111d
--- /dev/null
+++ b/harness/album-credits/build.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Builds the album credits check for the Mac: Redesigned/Album/AlbumCredits.m as the tweak compiles it.
+set -e
+cd "$(dirname "$0")"
+SRC=../../tweak/Sources
+mkdir -p build
+xcrun clang -fobjc-arc -O0 -g -Wall -Werror -target arm64-apple-macos13.0 \
+ check.m "$SRC"/Redesigned/Album/AlbumCredits.m -framework Foundation -o build/album-credits-check
+echo "built build/album-credits-check"
diff --git a/harness/album-credits/check.m b/harness/album-credits/check.m
new file mode 100644
index 00000000..a754d4d1
--- /dev/null
+++ b/harness/album-credits/check.m
@@ -0,0 +1,53 @@
+// Checks which artist lines an album page drops (Redesigned/Album/AlbumCredits.m) on the Mac: the line that only
+// repeats the album's artist, or the album's artist and the guests the title names after a featured-artist
+// marker, and every case that has to keep its line.
+//
+// ./build.sh && build/album-credits-check
+//
+// Every line prints ok or FAIL; the exit status is the number of failures.
+#import <Foundation/Foundation.h>
+
+// Album.h's, which brings UIKit along.
+BOOL SGRCreditRepeatsAlbum(NSString *albumArtist, NSString *rowArtist, NSString *title);
+
+static int failures;
+
+static void check(BOOL hides, BOOL wanted, NSString *what) {
+ printf("%s %s: %s\n", hides == wanted ? "ok " : "FAIL", wanted ? "hidden" : "kept ", what.UTF8String);
+ failures += hides != wanted;
+}
+
+int main(void) {
+ @autoreleasepool {
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"The Weeknd", @"Cry For Me"), YES, @"the album's artist again");
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"the weeknd ", @"Cry For Me"), YES, @"case and white space");
+ NSString *composed = @"Beyoncé", *decomposed = @"Beyoncé";
+ check(SGRCreditRepeatsAlbum(composed, decomposed, @"Halo"), YES, @"composed and decomposed é");
+ check(SGRCreditRepeatsAlbum(@"Beyoncé", @"Beyonce", @"Halo"), NO, @"accents are not stripped");
+ check(SGRCreditRepeatsAlbum(@"A • B • C", @"A, B, C", @"Song"), YES, @"three co-artists, • against ,");
+ check(SGRCreditRepeatsAlbum(@"A • B", @"B, A", @"Song"), NO, @"co-artists in another order");
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"The Weeknd, Justice", @"Wake Me Up (feat. Justice)"), YES,
+ @"(feat. guest)");
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"The Weeknd, Anitta", @"São Paulo - with Anitta"), YES, @"- with guest");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y", @"Song [ft Y]"), YES, @"[ft guest]");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y", @"Song (Featuring Y)"), YES, @"(Featuring guest)");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y, Z", @"Song (feat. Y, Z)"), YES, @"two guests named the same way");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Tyler, The Creator", @"Song (feat. Tyler, The Creator)"), YES,
+ @"a comma inside one guest's name");
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"The Weeknd, Justice", @"Wake Me Up"), NO, @"a guest the title does not name");
+ check(SGRCreditRepeatsAlbum(@"The Weeknd", @"The Weeknd, Justice", @"Wake Me Up Justice"), NO,
+ @"a guest named with no marker");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Anne", @"Song (feat. Ann)"), NO, @"Ann is not Anne");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y", @"Song (feat. Z)"), NO, @"a different guest");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y, Z", @"Song (feat. Z, Y)"), NO, @"guests in another order");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y, Z", @"Song (feat. Y & Z)"), NO, @"& against ,");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, Y", @"Song (feat. Y) [Remastered]"), NO, @"the marker not at the end");
+ check(SGRCreditRepeatsAlbum(@"X", @"X & Y", @"Song"), NO, @"another separator");
+ check(SGRCreditRepeatsAlbum(@"Various Artists", @"Adele", @"Hello"), NO, @"a compilation");
+ check(SGRCreditRepeatsAlbum(nil, @"Adele", @"Hello"), NO, @"no header artist yet");
+ check(SGRCreditRepeatsAlbum(@"Adele", @"", @"Hello"), NO, @"no row artist");
+ check(SGRCreditRepeatsAlbum(@"X", @"X, ", @"Song (feat. )"), NO, @"an empty guest");
+ }
+ printf("%d failed\n", failures);
+ return failures;
+}
diff --git a/harness/album/build.sh b/harness/album/build.sh
index 45693ce6..79e59b70 100755
--- a/harness/album/build.sh
+++ b/harness/album/build.sh
@@ -20,7 +20,7 @@ xcrun -sdk iphonesimulator clang -target arm64-apple-ios17.0-simulator -fobjc-ar
"$SRC"/Redesigned/Kit/SGRTokens.m "$SRC"/Redesigned/Kit/SGRPalette.m "$SRC"/Redesigned/Kit/SGRField.m "$SRC"/Redesigned/Kit/SGRFlow.m "$SRC"/Redesigned/Kit/SGRFluid.m "$SRC"/Shared/AnimatedArtwork/SGMotionCatalog.m "$SRC"/Shared/AnimatedArtwork/SGMotionStore.m \
"$SRC"/Redesigned/Kit/SGRGlass.m "$SRC"/Redesigned/Kit/SGRGlyph.m "$SRC"/Redesigned/Kit/SGRRestyle.m \
"$SRC"/Redesigned/Kit/SGRActionRow.m "$SRC"/Redesigned/Kit/SGRDownload.m "$SRC"/Redesigned/Kit/SGRHeaderInfo.m \
- "$SRC"/Redesigned/Kit/SGRedesign.m \
+ "$SRC"/Redesigned/Kit/SGRedesign.m "$SRC"/Redesigned/Album/AlbumCredits.m \
-framework UIKit -framework QuartzCore -framework CoreGraphics -framework CoreImage -framework Foundation -framework Symbols -framework AVFoundation -framework CoreMedia \
-o "$OUT/AlbumHarness.app/AlbumHarness"
diff --git a/harness/album/main.m b/harness/album/main.m
index a5473945..5cfd28fa 100644
--- a/harness/album/main.m
+++ b/harness/album/main.m
@@ -65,6 +65,15 @@ static UILabel *label(UIView *parent, CGRect frame, NSString *text, CGFloat size
return inner;
}
+static UIView *byIdentifier(UIView *root, NSString *identifier) {
+ if ([root.accessibilityIdentifier isEqualToString:identifier]) return root;
+ for (UIView *sub in root.subviews) {
+ UIView *found = byIdentifier(sub, identifier);
+ if (found) return found;
+ }
+ return nil;
+}
+
static UIImage *artwork(void) {
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:CGSizeMake(300, 300)];
return [renderer imageWithActions:^(UIGraphicsImageRendererContext *ctx) {
@@ -311,13 +320,20 @@ static NSString *trailingLabel(UIView *root) {
UIView *collection = box(_listView, UIView.class, _listView.bounds, nil);
collection.backgroundColor = [UIColor colorWithWhite:0.07 alpha:1];
- NSArray<NSArray<NSString *> *> *tracks = @[@[@"Wake Me Up (feat. Justice)", @"The Weeknd, Justice"],
- @[@"Cry For Me", @"The Weeknd"],
- @[@"I Can't Fucking Sing", @"The Weeknd"],
- @[@"São Paulo (feat. Anitta)", @"The Weeknd, Anitta"],
- @[@"Until We're Skin & Bones", @"The Weeknd"],
- @[@"Baptized In Fear", @"The Weeknd"]];
+ // The third column: E for a row with Spotify's explicit badge, a label-backed view beside the artist line.
+ // The artists the redesign drops are the ones that only repeat the header's The Weeknd; Justice named with
+ // no "feat." and Playboi Carti with no mention at all keep theirs.
+ NSArray<NSArray<NSString *> *> *tracks = @[@[@"Wake Me Up (feat. Justice)", @"The Weeknd, Justice", @"E"],
+ @[@"Cry For Me", @"The Weeknd", @""],
+ @[@"I Can't Fucking Sing", @"The Weeknd", @"E"],
+ @[@"São Paulo (feat. Anitta)", @"The Weeknd, Anitta", @"E"],
+ @[@"Until We're Skin & Bones", @"The Weeknd", @""],
+ @[@"Timeless Justice", @"The Weeknd, Justice", @""],
+ @[@"Timeless", @"The Weeknd, Playboi Carti", @"E"],
+ @[@"A Title Long Enough To Run Under The Badge And Beyond", @"The Weeknd", @"E"],
+ @[@"Baptized In Fear", @"The Weeknd", @""]];
CGFloat y = 8;
+ NSMutableArray<UICollectionViewCell *> *trackCells = [NSMutableArray array];
for (NSArray<NSString *> *track in tracks) {
UICollectionViewCell *cell = [[_TtC12Element_List18CollectionViewCell alloc] initWithFrame:CGRectMake(0, y, W, 56)];
cell.backgroundColor = [UIColor colorWithWhite:0.07 alpha:1];
@@ -326,12 +342,64 @@ static NSString *trailingLabel(UIView *root) {
UIView *row = box(content, UIView.class, content.bounds, @"Components.UI.RetrievalRowElementUI");
row.backgroundColor = [UIColor colorWithWhite:0.07 alpha:1];
label(row, CGRectMake(16, 8, W - 90, 18), track[0], 13, UIColor.whiteColor, @"EncoreConsumerMobile.View.Granular.Title");
- label(row, CGRectMake(16, 30, W - 90, 15.33), track[1], 11, UIColor.whiteColor, @"EncoreConsumerMobile.View.Granular.Subtitle");
+ CGFloat artistX = 16;
+ if (track[2].length) {
+ UIView *badge = box(row, UIView.class, CGRectMake(16, 31, 13, 13), @"Components.UI.ExplicitIcon");
+ badge.backgroundColor = [UIColor colorWithWhite:0.7 alpha:1];
+ badge.layer.cornerRadius = 2;
+ UILabel *e = [[UILabel alloc] initWithFrame:badge.bounds];
+ e.text = @"E";
+ e.font = [UIFont boldSystemFontOfSize:9];
+ e.textAlignment = NSTextAlignmentCenter;
+ e.textColor = UIColor.blackColor;
+ [badge addSubview:e];
+ artistX = 33;
+ }
+ label(row, CGRectMake(artistX, 30, W - 74 - artistX, 15.33), track[1], 11, UIColor.whiteColor, @"EncoreConsumerMobile.View.Granular.Subtitle");
actionButton(row, CGRectMake(W - 64, 4, 48, 48), @"Components.UI.ContextMenuButton-5673WA8EEUSPx1ir26lhGW", @"ellipsis", @"More options");
+ [trackCells addObject:cell];
y += 56;
}
_tracksBottom = y;
+ // What each row shows once the header has given its artist: the line's alpha, how far the title moved, and
+ // where the badge is drawn against the end of the title's text. Then the first row is prepared for reuse and
+ // has to come back as Spotify drew it, and laid out again has to be dropped again.
+ NSString *(^rowState)(UICollectionViewCell *) = ^NSString *(UICollectionViewCell *cell) {
+ [cell layoutIfNeeded];
+ UIView *subtitle = byIdentifier(cell, @"EncoreConsumerMobile.View.Granular.Subtitle");
+ UIView *badge = byIdentifier(cell, @"Components.UI.ExplicitIcon");
+ UILabel *title = (UILabel *)byIdentifier(cell, @"EncoreConsumerMobile.View.Granular.Title-internal");
+ UIImageView *drawn = nil;
+ for (UIView *v in subtitle.superview.subviews) {
+ if ([v isKindOfClass:UIImageView.class]) drawn = (UIImageView *)v;
+ }
+ NSString *line = subtitle.alpha == 0 ? @"hidden" : @"shown";
+ NSString *badgeState = !badge ? @"" : (drawn ? [NSString stringWithFormat:@", badge drawn %.0fpt after the text (original a=%.0f, a11y %d)",
+ CGRectGetMinX([drawn.superview convertRect:drawn.frame toView:title]) -
+ [title textRectForBounds:title.bounds limitedToNumberOfLines:1].size.width, badge.alpha, drawn.isAccessibilityElement] : @", badge where it was");
+ return [NSString stringWithFormat:@"\"%@\": line %@, title moved %.1fpt, title width %.0f%@", title.text, line,
+ title.transform.ty, title.bounds.size.width, badgeState];
+ };
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ for (UICollectionViewCell *cell in trackCells) NSLog(@"[harness] row %@", rowState(cell));
+ });
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+ [trackCells[0] prepareForReuse];
+ NSLog(@"[harness] reused, before its pass: needs layout %d", trackCells[0].layer.needsLayout);
+ UIView *row = trackCells[0].contentView.subviews.firstObject.subviews.firstObject;
+ __block CGFloat subtitleAlpha = -1, badgeAlpha = -1;
+ __block NSUInteger drawnCount = 0;
+ for (UIView *v in row.subviews) {
+ if ([v.accessibilityIdentifier isEqualToString:@"EncoreConsumerMobile.View.Granular.Subtitle"]) subtitleAlpha = v.alpha;
+ if ([v.accessibilityIdentifier isEqualToString:@"Components.UI.ExplicitIcon"]) badgeAlpha = v.alpha;
+ if ([v isKindOfClass:UIImageView.class]) drawnCount++;
+ }
+ NSLog(@"[harness] reused, restored: line a=%.0f, badge a=%.0f, drawn badges %lu", subtitleAlpha, badgeAlpha,
+ (unsigned long)drawnCount);
+ NSLog(@"[harness] reused, laid out again: row %@", rowState(trackCells[0]));
+ });
+
// and under it the footer Spotify sends: the album's own line, the copyright, and the sections the
// redesign drops -- each with the 16pt spacer Spotify puts between them. Fans also like stands for a
// section no switch names. They sit in a real collection view, which is what AlbumSections.x keeps what
diff --git a/tweak/Sources/Redesigned/Album/Album.h b/tweak/Sources/Redesigned/Album/Album.h
index ed351fd7..54787081 100644
--- a/tweak/Sources/Redesigned/Album/Album.h
+++ b/tweak/Sources/Redesigned/Album/Album.h
@@ -12,7 +12,8 @@
// screen forces
// AlbumHeader.x the header: the cover full bleed at the top dissolving into the field, and the Kit's
// SGRHeaderInfo over it -- title, artist, kind and date, shuffle, a white Play, add
-// AlbumRows.x the track rows on the field with no surface of their own and a hairline between them
+// AlbumRows.x the track rows on the field with no surface of their own and a hairline between them,
+// and no artist line where it only repeats the album's (AlbumCredits.m decides)
// AlbumSections.x everything under the tracks dropped but the album's own line and its copyright: no
// more by the artist, no videos, no concerts, no merch, no you might also like, each
// back once its switch is off
@@ -36,6 +37,16 @@ UIViewController *SGRAlbumSettingsPage(void);
#define SGRKeyAlbumHideYouMightLike @"spotifyglass.redesign.album.hide.youMightLike"
#define SGRKeyAlbumHideOther @"spotifyglass.redesign.album.hide.other"
+// AlbumRows.x. A track row's artist line goes when it only repeats the album's artist, with the explicit badge
+// moved up beside the title; on until switched off (AlbumSettings.m).
+#define SGRKeyAlbumHideTrackArtists @"spotifyglass.redesign.album.hide.trackArtists"
+// The album's artist as the header of the page `view` is on shows it, for the rows to compare theirs with. A
+// change lays the page's track rows out again; the same artist again is a no-op.
+void SGRAlbumSetArtist(UIView *view, NSString *artist);
+// AlbumCredits.m. Whether a row's artist line says nothing the album's header does not: it is the album's
+// artist, or the album's artist and the guests the title names after "feat.", "ft.", "featuring" or "with".
+BOOL SGRCreditRepeatsAlbum(NSString *albumArtist, NSString *rowArtist, NSString *title);
+
// The album page `view` is on, or nil: the CreativeWorkTemplateView that carries the header, the list and
// the two floating controls (trees/clean/album/01.txt:22).
UIView *SGRAlbumPageOf(UIView *view);
diff --git a/tweak/Sources/Redesigned/Album/AlbumCredits.m b/tweak/Sources/Redesigned/Album/AlbumCredits.m
new file mode 100644
index 00000000..026a0c36
--- /dev/null
+++ b/tweak/Sources/Redesigned/Album/AlbumCredits.m
@@ -0,0 +1,51 @@
+// Album redesign: whether a track row's artist line says anything the album's header does not. Foundation only,
+// so the Mac check in harness/album-credits runs it as the tweak does.
+//
+// The line is redundant in two cases only: it is the album's artist again, or it is the album's artist and the
+// guests the title already names after a featured-artist marker. Everything else keeps its line -- a compilation,
+// a different guest, guests in another order, a guest named in the title with no marker -- because a line hidden
+// wrongly takes away who is on the track, and a line kept wrongly costs only the clutter.
+#import <Foundation/Foundation.h>
+
+// Canonical composition, lower case, and any run of white space as one space: what two spellings of the same
+// credit can differ by. Accents stay, and names are never split at "&", "/" or " x ".
+static NSString *normalised(NSString *text) {
+ NSString *folded = text.precomposedStringWithCanonicalMapping.lowercaseString;
+ NSMutableArray<NSString *> *words = [NSMutableArray array];
+ for (NSString *word in [folded componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]) {
+ if (word.length) [words addObject:word];
+ }
+ return [words componentsJoinedByString:@" "];
+}
+
+// The guests a title names at its very end: "(feat. A)", "[ft B]", "- with C", and featuring the same way.
+static NSString *featuredIn(NSString *title) {
+ static NSRegularExpression *suffix;
+ static dispatch_once_t once;
+ dispatch_once(&once, ^{
+ NSString *marker = @"(?:feat\\.?|ft\\.?|featuring|with)\\s+";
+ NSString *pattern = [NSString stringWithFormat:@"(?:\\(\\s*%@([^()]+?)\\s*\\)|\\[\\s*%@([^\\[\\]]+?)\\s*\\]|\\s-\\s%@(.+?))$",
+ marker, marker, marker];
+ suffix = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:NULL];
+ });
+ NSTextCheckingResult *match = [suffix firstMatchInString:title options:0 range:NSMakeRange(0, title.length)];
+ for (NSUInteger i = 1; match && i < match.numberOfRanges; i++) {
+ NSRange range = [match rangeAtIndex:i];
+ if (range.location != NSNotFound) return [title substringWithRange:range];
+ }
+ return nil;
+}
+
+BOOL SGRCreditRepeatsAlbum(NSString *albumArtist, NSString *rowArtist, NSString *title) {
+ if (!albumArtist.length || !rowArtist.length) return NO;
+ // The header joins co-artists with " • ", a row with ", ".
+ NSString *album = [normalised(albumArtist) stringByReplacingOccurrencesOfString:@" • " withString:@", "];
+ NSString *row = normalised(rowArtist);
+ if (!album.length) return NO;
+ if ([row isEqualToString:album]) return YES;
+ NSString *lead = [album stringByAppendingString:@", "];
+ if (![row hasPrefix:lead] || row.length == lead.length || !title.length) return NO;
+ NSString *guests = [row substringFromIndex:lead.length];
+ NSString *featured = featuredIn(normalised(title));
+ return featured && [normalised(featured) isEqualToString:guests];
+}
diff --git a/tweak/Sources/Redesigned/Album/AlbumHeader.x b/tweak/Sources/Redesigned/Album/AlbumHeader.x
index 576d093d..443c77ff 100644
--- a/tweak/Sources/Redesigned/Album/AlbumHeader.x
+++ b/tweak/Sources/Redesigned/Album/AlbumHeader.x
@@ -418,6 +418,8 @@ static SGRHeaderInfo *applyInfo(UIView *header, UIView *page) {
NSString *length = metadataText(metadata);
[info showTitle:firstText(title) creator:firstText(parent) ?: trimmed(parent.accessibilityLabel)
length:length about:nil];
+ // The line as it reads, without the accessibility label to fall back on: no line, no row loses its artist.
+ SGRAlbumSetArtist(page, firstText(parent));
// The kind and the date are cells the metadata row's collection view makes on its own pass, after the
// header's, and nothing lays the header out again when they arrive; the collection is Spotify's own Swift
// class, which cannot be watched. So an empty row is read again a moment later, a few times at most.
diff --git a/tweak/Sources/Redesigned/Album/AlbumRows.x b/tweak/Sources/Redesigned/Album/AlbumRows.x
index 9714baa0..c1d9ccf9 100644
--- a/tweak/Sources/Redesigned/Album/AlbumRows.x
+++ b/tweak/Sources/Redesigned/Album/AlbumRows.x
@@ -13,6 +13,19 @@
//
// Spotify's type and its spacing are left alone: the row is 56pt for a title of 13pt, and a larger font of
// the Kit's would be cut off by the box the element framework measured for it.
+//
+// **The artist line, where it only repeats the album's.** The Music app shows a track's title alone on a
+// standard album, so the line goes where AlbumCredits.m finds it says nothing the header does not. It goes by
+// alpha on the Subtitle wrapper: Encore sets its inner label's alpha again later, `hidden` inside its stacks
+// crashes, and the row keeps the height Spotify measured for it. The title is moved down to the middle of the
+// row by a translation. The explicit badge is a sibling of the line, not inside it, so it is drawn again as a
+// picture after the title's text, 4pt on, and the badge itself goes by alpha; the title is narrowed by the
+// badge's room so a long one cannot run under it or under ⋯. Right to left, all of it the other way round.
+// The row's own accessibility label still names the artists and says explicit; the picture is not an element.
+//
+// Everything changed is put back at the start of the cell's next pass and when the cell is prepared for reuse,
+// which also asks for a pass: Spotify can show a cached row again at the same size without one, and the last
+// row's state would stay on it.
#import "Core/SGCore.h"
#import "Redesigned/Kit/SGRKit.h"
#import "Album.h"
@@ -20,8 +33,10 @@
// Under the text rather than the whole row, as the Music app draws it; the trailing end clears the page
// margin.
static const CGFloat kHairline = 0.5;
+// Between the end of the title's text and the badge drawn after it.
+static const CGFloat kBadgeGap = 4;
-static char kRowKey, kSubtitleKey, kLineKey;
+static char kRowKey, kSubtitleKey, kLineKey, kTitleKey, kBadgeKey, kArtistKey, kChangeKey;
static void clearSurface(UIView *view) {
UIColor *color = view.backgroundColor;
@@ -47,7 +62,152 @@ static void applyHairline(UIView *row) {
[CATransaction commit];
}
-static void applyRow(UIView *cell) {
+#pragma mark - the artist line
+
+// What a row's credit change touched, and what each was before, to be put back.
+@interface SGRCreditChange : NSObject
+@property (nonatomic, weak) UIView *subtitle, *badge;
+@property (nonatomic, weak) UILabel *title;
+@property (nonatomic) CGFloat subtitleAlpha, badgeAlpha;
+@property (nonatomic) CGRect titleFrame, narrowFrame;
+@property (nonatomic) CGAffineTransform shift;
+@property (nonatomic, strong) UIImageView *drawnBadge;
+@end
+
+@implementation SGRCreditChange
+@end
+
+static BOOL hidesCredits(void) {
+ static NSInteger on = -1;
+ if (on < 0) on = SGEnabled(SGRKeyAlbumHideTrackArtists);
+ return on;
+}
+
+// The one label under `view`, itself included, with text in it; nil for none or for more than one.
+static UILabel *onlyLabel(UIView *view) {
+ __block UILabel *found = nil;
+ __block NSUInteger count = 0;
+ SGForEachView(view, ^(UIView *v) {
+ if (![v isKindOfClass:UILabel.class]) return;
+ NSString *text = [((UILabel *)v).text stringByTrimmingCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet];
+ if (!text.length) return;
+ found = (UILabel *)v;
+ count++;
+ });
+ return count == 1 ? found : nil;
+}
+
+// The badge as it draws, rendered the moment before it goes: an unplayable row's is greyed, so it is not cached.
+static UIImage *pictureOf(UIView *badge) {
+ UIGraphicsImageRendererFormat *format = [UIGraphicsImageRendererFormat formatForTraitCollection:badge.traitCollection];
+ UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:badge.bounds.size format:format];
+ return [renderer imageWithActions:^(UIGraphicsImageRendererContext *context) {
+ [badge.layer renderInContext:context.CGContext];
+ }];
+}
+
+// Puts back what the last change took. YES when there was one.
+static BOOL restoreCredit(UIView *cell) {
+ SGRCreditChange *change = objc_getAssociatedObject(cell, &kChangeKey);
+ if (!change) return NO;
+ objc_setAssociatedObject(cell, &kChangeKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+ [change.drawnBadge removeFromSuperview];
+ // The transform before the frame, which is meaningless under one. Each only where it is still this change's:
+ // a pass of Spotify's since may have put its own there.
+ UILabel *title = change.title;
+ if (title && CGAffineTransformEqualToTransform(title.transform, change.shift)) title.transform = CGAffineTransformIdentity;
+ if (title && !CGRectIsNull(change.narrowFrame) && CGRectEqualToRect(title.frame, change.narrowFrame)) title.frame = change.titleFrame;
+ if (change.subtitle.alpha == 0) change.subtitle.alpha = change.subtitleAlpha;
+ if (change.badge.alpha == 0) change.badge.alpha = change.badgeAlpha;
+ return YES;
+}
+
+void SGRAlbumSetArtist(UIView *view, NSString *artist) {
+ UIView *page = SGRAlbumPageOf(view);
+ NSString *known = objc_getAssociatedObject(page, &kArtistKey);
+ if (!page || known == artist || [known isEqualToString:artist]) return;
+ objc_setAssociatedObject(page, &kArtistKey, artist, OBJC_ASSOCIATION_COPY_NONATOMIC);
+ // The rows on screen were laid out against the artist before; the rest are laid out as they come.
+ if (!hidesCredits()) return;
+ SGForEachView(page, ^(UIView *v) {
+ if ([v isKindOfClass:%c(_TtC12Element_List18CollectionViewCell)]) [v setNeedsLayout];
+ });
+}
+
+static void applyCredit(UIView *cell, UIView *row, UIView *page) {
+ NSString *album = objc_getAssociatedObject(page, &kArtistKey);
+ if (!album) return;
+ // The content's own pass first: a new row has no size in its text before it.
+ [((UICollectionViewCell *)cell).contentView layoutIfNeeded];
+ UIView *subtitle = SGRFindByIdentifier(row, @"EncoreConsumerMobile.View.Granular.Subtitle", &kSubtitleKey);
+ UILabel *title = onlyLabel(SGRFindByIdentifier(row, @"EncoreConsumerMobile.View.Granular.Title", &kTitleKey));
+ UILabel *artist = onlyLabel(subtitle);
+ if (!title || !artist || !SGRCreditRepeatsAlbum(album, artist.text, title.text)) return;
+ // Mid animation the title's frame is not where it is going.
+ if (!CGAffineTransformIsIdentity(title.transform) || title.layer.animationKeys.count) return;
+
+ UIView *badge = SGRFindByIdentifier(row, @"Components.UI.ExplicitIcon", &kBadgeKey);
+ if (badge && (badge.hidden || badge.alpha < 0.01 || CGRectIsEmpty(badge.bounds))) badge = nil;
+ CGRect frame = title.frame;
+ CGFloat room = badge ? badge.bounds.size.width + kBadgeGap : 0;
+ if (frame.size.width - room < title.font.lineHeight) return;
+ NSTextAlignment alignment = title.textAlignment;
+ BOOL rtl = title.effectiveUserInterfaceLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft;
+ BOOL textAtRight = alignment == NSTextAlignmentRight || (alignment == NSTextAlignmentNatural && rtl);
+ CGFloat narrowWidth = frame.size.width - room;
+ CGSize text = [title textRectForBounds:CGRectMake(0, 0, narrowWidth, CGFLOAT_MAX) limitedToNumberOfLines:title.numberOfLines].size;
+ // ponytail: one line only. A wrapped title's last line ends somewhere this does not measure, so its badge
+ // would be placed against the widest line; such a row keeps its artist line instead.
+ if (badge && (alignment == NSTextAlignmentCenter || text.height > title.font.lineHeight * 1.5)) return;
+
+ SGRCreditChange *change = [SGRCreditChange new];
+ change.subtitle = subtitle;
+ change.subtitleAlpha = subtitle.alpha;
+ change.title = title;
+ change.titleFrame = frame;
+ change.narrowFrame = CGRectNull;
+ subtitle.alpha = 0;
+ if (badge) {
+ CGRect narrow = frame;
+ narrow.size.width = narrowWidth;
+ if (rtl) narrow.origin.x += room;
+ title.frame = narrow;
+ change.narrowFrame = narrow;
+ }
+ CGFloat scale = row.window.screen.scale ?: UIScreen.mainScreen.scale;
+ CGPoint centre = [title.superview convertPoint:title.center toView:row];
+ CGFloat dy = round((CGRectGetMidY(row.bounds) - centre.y) * scale) / scale;
+ change.shift = CGAffineTransformMakeTranslation(0, dy);
+ title.transform = change.shift;
+
+ if (badge) {
+ UIImageView *drawn = [[UIImageView alloc] initWithImage:pictureOf(badge)];
+ drawn.userInteractionEnabled = NO;
+ drawn.isAccessibilityElement = NO;
+ CGSize size = badge.bounds.size;
+ CGFloat textWidth = MIN(ceil(text.width), narrowWidth);
+ CGFloat x = textAtRight ? narrowWidth - textWidth - kBadgeGap - size.width : textWidth + kBadgeGap;
+ CGRect inTitle = CGRectMake(x, (title.bounds.size.height - size.height) / 2, size.width, size.height);
+ // Through the title, whose transform the conversion takes along.
+ drawn.frame = [title convertRect:inTitle toView:row];
+ [row addSubview:drawn];
+ change.drawnBadge = drawn;
+ change.badge = badge;
+ change.badgeAlpha = badge.alpha;
+ badge.alpha = 0;
+ }
+ objc_setAssociatedObject(cell, &kChangeKey, change, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+
+ static BOOL logged;
+ if (!logged) {
+ logged = YES;
+ SGLog(@"redesign album: a track's artist line hidden as the album's, badge %@", badge ? @"moved up" : @"none");
+ }
+}
+
+#pragma mark - the rows
+
+static void applyRow(UIView *cell, UIView *page) {
clearSurface(cell);
UIView *row = SGRFindByIdentifier(cell, @"Components.UI.RetrievalRow*", &kRowKey);
if (!row) return;
@@ -65,8 +225,11 @@ static void applyRow(UIView *cell) {
});
applyHairline(row);
+ if (hidesCredits()) applyCredit(cell, row, page);
}
+#pragma mark - the cells
+
// Which cells of Element_List belong to an album's track list, answered once per content class: the same
// cell class carries Home's sections and the album's footer too, and a walk up to the page on every pass of
// every cell is what the answer is cached to avoid.
@@ -85,10 +248,18 @@ static BOOL isTrackContent(UIView *content) {
%hook _TtC12Element_List18CollectionViewCell
- (void)layoutSubviews {
+ restoreCredit((UIView *)self);
%orig;
UICollectionViewCell *cell = (UICollectionViewCell *)self;
if (!isTrackContent(cell.contentView.subviews.firstObject)) return;
- if (SGRAlbumPageOf(cell)) applyRow(cell);
+ UIView *page = SGRAlbumPageOf(cell);
+ if (page) applyRow(cell, page);
+}
+
+- (void)prepareForReuse {
+ %orig;
+ UICollectionViewCell *cell = (UICollectionViewCell *)self;
+ if (restoreCredit(cell) || isTrackContent(cell.contentView.subviews.firstObject)) [cell setNeedsLayout];
}
%end
diff --git a/tweak/Sources/Redesigned/Album/AlbumSettings.m b/tweak/Sources/Redesigned/Album/AlbumSettings.m
index 72444f29..6cb4e8ae 100644
--- a/tweak/Sources/Redesigned/Album/AlbumSettings.m
+++ b/tweak/Sources/Redesigned/Album/AlbumSettings.m
@@ -13,6 +13,9 @@ UIViewController *SGRAlbumSettingsPage(void) {
SGSwitchRow(@"Artist logos", @"In place of the name on an artist's page", SGRKeyArtistLogo),
SGOptionRow(@"Download in Low Data Mode", nil, SGKeyMotionLowData),
], @"Only the album's or artist's name is sent to Apple Music."),
+ SGSection(@"Hide on an album's page", @[
+ SGSwitchRow(@"Repeated track artists", @"The artist under a track when it is the album's own", SGRKeyAlbumHideTrackArtists),
+ ]),
SGNotedSection(@"Hide under an album's tracks", @[
SGSwitchRow(@"More by the artist", nil, SGRKeyAlbumHideMoreBy),
SGSwitchRow(@"Related music videos", nil, SGRKeyAlbumHideVideos),