Skip to content

Commit 0f484e0

Browse files
authored
Merge pull request #45 from GregTaoo/dev
fix. QQ音乐用户歌单页面概率无法渲染
2 parents 668e898 + 9000c0a commit 0f484e0

File tree

7 files changed

+26
-15
lines changed

7 files changed

+26
-15
lines changed

src/main/java/top/gregtao/concerto/api/WithMetaData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
public interface WithMetaData {
66

77
MetaData getMeta();
8+
9+
boolean isMetaLoaded();
810
}

src/main/java/top/gregtao/concerto/music/Music.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public boolean isLoaded() {
5656
return this.isMetaLoaded;
5757
}
5858

59+
public boolean isMetaLoaded() {
60+
return this.isMetaLoaded;
61+
}
62+
5963
public abstract InputStream getMusicSource() throws MusicSourceNotFoundException;
6064

6165
public abstract String getLink();

src/main/java/top/gregtao/concerto/music/list/Playlist.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public boolean isLoaded() {
3535
return this.loaded;
3636
}
3737

38+
public boolean isMetaLoaded() {
39+
return this.loaded;
40+
}
41+
3842
public boolean isAlbum() {
3943
return this.isAlbum;
4044
}

src/main/java/top/gregtao/concerto/screen/netease/NeteaseCloudUserScreen.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected void init() {
5555
this.playlistList = this.initWidget();
5656

5757
this.onPageTurned(0);
58+
this.addDrawableChild(this.playlistList);
5859
this.addSelectableChild(this.playlistList);
5960

6061
this.addDrawableChild(ButtonWidget.builder(Text.translatable("concerto.screen.daily_recommendation"),
@@ -84,9 +85,7 @@ protected void init() {
8485
@Override
8586
public void render(DrawContext matrices, int mouseX, int mouseY, float delta) {
8687
super.render(matrices, mouseX, mouseY, delta);
87-
if (this.loggedIn()) {
88-
this.playlistList.render(matrices, mouseX, mouseY, delta);
89-
} else {
88+
if (!this.loggedIn()) {
9089
matrices.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("concerto.screen.163.not_login"),
9190
this.width / 2, this.height / 2, 0xffffffff);
9291
}

src/main/java/top/gregtao/concerto/screen/qq/QQMusicUserScreen.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import top.gregtao.concerto.screen.widget.ConcertoListWidget;
1616
import top.gregtao.concerto.screen.widget.MetadataListWidget;
1717

18-
import java.util.ListIterator;
19-
2018
public class QQMusicUserScreen extends PageScreen {
2119
private MetadataListWidget<QQMusicPlaylist> playlistList;
2220

@@ -54,6 +52,7 @@ protected void init() {
5452
this.playlistList = this.initWidget();
5553

5654
this.onPageTurned(0);
55+
this.addDrawableChild(this.playlistList);
5756
this.addSelectableChild(this.playlistList);
5857

5958
this.addDrawableChild(ButtonWidget.builder(Text.translatable("concerto.screen.play"), button -> {
@@ -72,12 +71,7 @@ protected void init() {
7271
@Override
7372
public void render(DrawContext matrices, int mouseX, int mouseY, float delta) {
7473
super.render(matrices, mouseX, mouseY, delta);
75-
if (this.loggedIn()) {
76-
ListIterator<ConcertoListWidget<QQMusicPlaylist>.Entry> iterator = this.playlistList.children().listIterator();
77-
while (iterator.hasNext() && iterator.next().item.isLoaded()) {
78-
if (!iterator.hasNext()) this.playlistList.render(matrices, mouseX, mouseY, delta);
79-
}
80-
} else {
74+
if (!this.loggedIn()) {
8175
matrices.drawCenteredTextWithShadow(this.textRenderer, Text.translatable("concerto.screen.qq.not_login"),
8276
this.width / 2, this.height / 2, 0xffffffff);
8377
}

src/main/java/top/gregtao/concerto/screen/widget/MetadataListWidget.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ public MetadataListWidget(int width, int height, int top, int itemHeight, int co
1717

1818
@Override
1919
public Text getNarration(int index, T t) {
20-
MetaData meta = t.getMeta();
21-
return Text.literal(meta.title()).append(" ").append(Text.literal(meta.author()).formatted(Formatting.BOLD, Formatting.GRAY));
20+
if (t.isMetaLoaded()) {
21+
MetaData meta = t.getMeta();
22+
return Text.literal(meta.title()).append(" ").append(Text.literal(meta.author()).formatted(Formatting.BOLD, Formatting.GRAY));
23+
} else {
24+
return Text.translatable("concerto.loading");
25+
}
2226
}
2327
}

src/main/java/top/gregtao/concerto/screen/widget/MusicWithUUIDListWidget.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ public MusicWithUUIDListWidget(int width, int height, int top, int itemHeight) {
1515

1616
@Override
1717
public Text getNarration(int index, Pair<Music, UUID> t) {
18-
MusicMetaData meta = t.getFirst().getMeta();
19-
return Text.literal(meta.title() + " - " + meta.getSource());
18+
if (t.getFirst().isMetaLoaded()) {
19+
MusicMetaData meta = t.getFirst().getMeta();
20+
return Text.literal(meta.title() + " - " + meta.getSource());
21+
} else {
22+
return Text.translatable("concerto.loading");
23+
}
2024
}
2125

2226
public MusicWithUUIDListWidget(int width, int height, int top, int itemHeight, int color) {

0 commit comments

Comments
 (0)