Skip to content

Commit

Permalink
Finalize the layout of the Music Screen
Browse files Browse the repository at this point in the history
Signed-off-by: Rina Mary Shaw <[email protected]>
  • Loading branch information
Pixaurora committed Dec 13, 2024
1 parent cab436f commit 87aebc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public static <T> TileRow fromIndex(List<T> elements, int index) {
int first = 0;
int last = elements.size() - 1;

if (index == first) {
return TileRow.TOP;
} else if (index == last) {
if (index == last) {
return TileRow.BOTTOM;
} else if (index == first) {
return TileRow.TOP;
} else {
return TileRow.MIDDLE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,16 @@ private static ProgressBarTileSet tileSet(ResourcePath texturePath) {
public DisplayMode createMusicDisplay(PlayingSong song) {
WidgetContainer<ProgressBar> progressBar = this.configProgressBar(song, PLAYING_SONG_TILE_SET);

WidgetContainer<Timer> timer = this.addWidget(new Timer(song))
.align(progressBar.relativeTo(WidgetAnchor.BOTTOM_MIDDLE))
.anchor(WidgetAnchor.TOP_MIDDLE);
WidgetContainer<Timer> timer = this.configTimer(song, progressBar);

Optional<Album> album = song.track().flatMap(Track::album);

ResourcePath albumArtTexture = album
.flatMap(Album::albumArtPath)
.orElse(DEFAULT_ALBUM_ART);
Size iconSize = Size.of(128, 128);
WidgetContainer<StaticTexture> albumArt = this
.addWidget(
new StaticTexture(Texture.of(albumArtTexture, iconSize)))
new StaticTexture(Texture.of(albumArtTexture, Size.of(128, 128))))
.anchor(WidgetAnchor.MIDDLE_RIGHT)
.at(Point.of(-10, 0));

Expand All @@ -126,7 +123,8 @@ public DisplayMode createMusicDisplay(PlayingSong song) {
controls.pause();
}
}))
.align(progressBar.relativeTo(WidgetAnchor.BOTTOM_LEFT));
.align(progressBar.relativeTo(WidgetAnchor.BOTTOM_LEFT))
.at(Point.of(0, 1));

return new MusicDisplayMode(song, Arrays.asList(progressBar, timer, albumArt, pauseButton));
}
Expand All @@ -136,16 +134,25 @@ public DisplayMode createWaitingDisplay() {

WidgetContainer<ProgressBar> progressBar = this.configProgressBar(progress, PLAYING_SONG_TILE_SET);

return new WaitingDisplayMode(Arrays.asList(progressBar));
WidgetContainer<Timer> timer = this.configTimer(progress, progressBar);

return new WaitingDisplayMode(Arrays.asList(progressBar, timer));
}

private WidgetContainer<ProgressBar> configProgressBar(ProgressProvider progress, ProgressBarTileSets tileSets) {
return this.addWidget(new ProgressBar(progress, tileSets))
.align(Alignment.CENTER_BOTTOM)
.at(Point.of(0, -24))
.at(Point.of(0, -27))
.anchor(WidgetAnchor.TOP_MIDDLE);
}

private WidgetContainer<Timer> configTimer(ProgressProvider progress, WidgetContainer<?> anchoredWidget) {
return this.addWidget(new Timer(progress))
.align(anchoredWidget.relativeTo(WidgetAnchor.BOTTOM_MIDDLE))
.anchor(WidgetAnchor.TOP_MIDDLE)
.at(Point.of(0, 3));
}

private abstract class DisplayMode {
private final List<WidgetContainer<?>> widgets;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ private View initView(List<ListenRecord> recentMusic) {
List<PositionedInnerTile> tiles = new ArrayList<>();
Size size = Size.ZERO.withX(this.tileSet.width());

// If only 1 song has been played recently, we add an extra tile so the shape
// isn't cut off.
if (recentMusic.size() == 1) {
Row rowType = this.tileSet.get(TileRow.TOP);

Point pos = size.toPoint().withX(0);

tiles.add(rowType.tile().atPos(pos));

size = size.offset(0, rowType.tile().height());
}

for (int i = 0; i < recentMusic.size(); i++) {
ListenRecord record = recentMusic.get(recentMusic.size() - 1 - i);
Row rowType = this.tileSet.get(TileRow.fromIndex(recentMusic, i));
Expand Down

0 comments on commit 87aebc8

Please sign in to comment.