Skip to content

Commit

Permalink
[Fix] Disable image for music item, fix fetch music agg for search page
Browse files Browse the repository at this point in the history
  • Loading branch information
canxin121 committed Nov 5, 2024
1 parent fb20852 commit 8b5761f
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 109 deletions.
3 changes: 2 additions & 1 deletion lib/common_comps/explore/playlist_tag_collection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ class PlaylistTagCollectionSlider extends StatelessWidget {
OnlinePlaylistGridViewPage(
title: tag.name,
isDesktop: isDesktop,
fetchPlaylists: (int page, int limit) async {
fetchPlaylists: (int page, int limit,
List<Playlist> playlists) async {
return await ServerPlaylistTagCollection
.getPlaylistsFromTag(
server: server,
Expand Down
2 changes: 1 addition & 1 deletion lib/common_comps/paged/paged_music_agg_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PagedMusicAggregatorListState extends State<PagedMusicAggregatorList> {
if (widget.pagingController.itemList != null &&
widget.pagingController.itemList!.isNotEmpty)
const Padding(
padding: EdgeInsets.only(left: 16, right: 16),
padding: EdgeInsets.only(left: 16, right: 16, bottom: 16),
child: MusicAggregatorListHeaderRow(),
),
Expanded(
Expand Down
11 changes: 7 additions & 4 deletions lib/common_pages/online_music_agg_listview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class OnlineMusicAggregatorListViewPageState
PagingController(firstPageKey: 1);

Future<List<MusicAggregator>> _fetchMusicAggregators(
int page, int pageSize) async {
int page, int pageSize, List<MusicAggregator> aggs) async {
if (widget.playlist != null) {
return await widget.playlist!.fetchMusicsOnline(page: page, limit: 30);
} else if (widget.fetchMusicAggregators != null) {
Expand Down Expand Up @@ -77,9 +77,12 @@ class OnlineMusicAggregatorListViewPageState

Future<void> _fetchAllMusicAggregators() async {
await fetchAllItemsWithPagingController(
_fetchMusicAggregators,
_pagingController,
"音乐",
fetchItems: _fetchMusicAggregators,
pagingController: _pagingController,
itemName: "音乐",
shouldEnd: (pagingController, lastItemLen, newResult) {
return newResult.length <= lastItemLen;
},
);
}

Expand Down
11 changes: 6 additions & 5 deletions lib/common_pages/online_playlist_gridview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class OnlinePlaylistGridViewPage extends StatefulWidget {
required this.fetchPlaylists,
this.title = "在线歌单"});
final String title;
final Future<List<Playlist>> Function(int page, int limit) fetchPlaylists;
final Future<List<Playlist>> Function(
int page, int limit, List<Playlist> playlists) fetchPlaylists;
final bool isDesktop;

@override
Expand All @@ -36,7 +37,7 @@ class SearchMusicListState extends State<OnlinePlaylistGridViewPage>
_pagingController.addPageRequestListener((pageKey) async {
if (_pagingController.nextPageKey == null) return;
try {
var fetchedPlaylists = await widget.fetchPlaylists(pageKey, 30);
var fetchedPlaylists = await widget.fetchPlaylists(pageKey, 30, []);
_pagingController.appendPage(
fetchedPlaylists, _pagingController.nextPageKey! + 1);
} catch (e) {
Expand All @@ -60,9 +61,9 @@ class SearchMusicListState extends State<OnlinePlaylistGridViewPage>

Future<void> _fetchAllPlaylists() async {
await fetchAllItemsWithPagingController(
widget.fetchPlaylists,
_pagingController,
"歌单",
fetchItems: widget.fetchPlaylists,
pagingController: _pagingController,
itemName: "歌单",
);
}

Expand Down
34 changes: 20 additions & 14 deletions lib/desktop/comps/music_agg_comp/music_agg_list_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -243,21 +243,27 @@ class MusicCell extends StatelessWidget {
Widget build(BuildContext context) {
return Row(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(2.0),
child: imageWithCache(music.getCover(size: 250),
width: 40, height: 40, enableCache: cacheCover),
),
const SizedBox(width: 8),
// ClipRRect(
// borderRadius: BorderRadius.circular(2.0),
// child: imageWithCache(music.getCover(size: 250),
// width: 40, height: 40, enableCache: cacheCover),
// ),
// const SizedBox(width: 8),
Expanded(
child: Text(
music.name,
style: TextStyle(
color: isDarkMode ? CupertinoColors.white : CupertinoColors.black,
).useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
),
),
child: SizedBox(
height: 40,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
music.name,
style: TextStyle(
color: isDarkMode
? CupertinoColors.white
: CupertinoColors.black,
).useSystemChineseFont(),
overflow: TextOverflow.ellipsis,
)),
)),
],
);
}
Expand Down
60 changes: 34 additions & 26 deletions lib/desktop/pages/search_page/music_aggregator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@ class MusicAggregatorSearchPageState extends State<MusicAggregatorSearchPage>
WidgetsBinding.instance.addObserver(this);
pagingControllerMusicAggregator.addPageRequestListener((pageKey) {
fetchItemWithInputPagingController(
inputController: inputContentController,
pagingController: pagingControllerMusicAggregator,
fetchFunction: (
int page,
int pageSize,
String content,
) async {
return await MusicAggregator.searchOnline(
aggs: pagingControllerMusicAggregator.itemList ?? [],
servers: MusicServer.all(),
content: content,
page: pageKey,
size: pageSize,
);
},
pageKey: pageKey,
itemName: '歌曲');
inputController: inputContentController,
pagingController: pagingControllerMusicAggregator,
fetchFunction: (int page, int pageSize, String content,
List<MusicAggregator> aggs) async {
return await MusicAggregator.searchOnline(
aggs: aggs,
servers: MusicServer.all(),
content: content,
page: pageKey,
size: pageSize,
);
},
pageKey: pageKey,
itemName: '歌曲',
shouldEnd: (pagingController, lastItemLen, newResult) {
return newResult.length <= lastItemLen;
},
);
});
}

Expand All @@ -56,15 +57,22 @@ class MusicAggregatorSearchPageState extends State<MusicAggregatorSearchPage>
}

Future<void> _fetchAllMusicAggregators() async {
await fetchAllItemsWithPagingController((int page, int limit) async {
return await MusicAggregator.searchOnline(
aggs: pagingControllerMusicAggregator.itemList ?? [],
servers: MusicServer.all(),
content: inputContentController.value.text,
page: page,
size: limit,
);
}, pagingControllerMusicAggregator, "歌曲");
await fetchAllItemsWithPagingController(
fetchItems: (int page, int limit, List<MusicAggregator> aggs) async {
return await MusicAggregator.searchOnline(
aggs: aggs,
servers: MusicServer.all(),
content: inputContentController.value.text,
page: page,
size: limit,
);
},
pagingController: pagingControllerMusicAggregator,
itemName: "歌曲",
shouldEnd: (pagingController, lastItemLen, newResult) {
return newResult.length <= lastItemLen;
},
);
}

@override
Expand Down
18 changes: 11 additions & 7 deletions lib/desktop/pages/search_page/playlist.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SearchMusicListState extends State<PlaylistSearchPage>
int page,
int pageSize,
String content,
List<Playlist> playlists,
) async {
return await Playlist.searchOnline(
servers: MusicServer.all(),
Expand All @@ -55,13 +56,16 @@ class SearchMusicListState extends State<PlaylistSearchPage>
}

Future<void> _fetchAllMusicLists() async {
await fetchAllItemsWithPagingController((int page, int limit) async {
return await Playlist.searchOnline(
servers: [MusicServer.kuwo, MusicServer.netease],
content: inputContentController.value.text,
page: page,
size: limit);
}, pagingControllerPlaylist, "歌单");
await fetchAllItemsWithPagingController(
fetchItems: (int page, int limit, List<Playlist> playlists) async {
return await Playlist.searchOnline(
servers: [MusicServer.kuwo, MusicServer.netease],
content: inputContentController.value.text,
page: page,
size: limit);
},
pagingController: pagingControllerPlaylist,
itemName: "歌单");
}

@override
Expand Down
57 changes: 34 additions & 23 deletions lib/mobile/pages/search_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ class _SearchPageMobileState extends State<SearchPageMobile> {
fetchItemWithInputPagingController(
inputController: inputContentController,
pagingController: pagingControllerMusicAggregator,
fetchFunction: (
int page,
int pageSize,
String content,
) async {
fetchFunction: (int page, int pageSize, String content,
List<MusicAggregator> aggs) async {
return await MusicAggregator.searchOnline(
aggs: pagingControllerMusicAggregator.itemList ?? [],
aggs: aggs,
servers: MusicServer.all(),
content: content,
page: pageKey,
size: pageSize,
);
},
pageKey: pageKey,
shouldEnd: (pagingController, lastItemLen, newResult) {
return newResult.length <= lastItemLen;
},
itemName: "歌曲");
});
pagingControllerPlaylist.addPageRequestListener((pageKey) {
Expand All @@ -66,6 +66,7 @@ class _SearchPageMobileState extends State<SearchPageMobile> {
int page,
int pageSize,
String content,
List<Playlist> playlists,
) async {
return await Playlist.searchOnline(
servers: MusicServer.all(),
Expand All @@ -80,26 +81,36 @@ class _SearchPageMobileState extends State<SearchPageMobile> {
}

Future<void> _fetchAllMusicAggregators() async {
await fetchAllItemsWithPagingController((int page, int limit) async {
return await MusicAggregator.searchOnline(
aggs: pagingControllerMusicAggregator.itemList ?? [],
servers: MusicServer.all(),
content: inputContentController.value.text,
page: page,
size: limit,
);
}, pagingControllerMusicAggregator, "歌曲");
await fetchAllItemsWithPagingController(
fetchItems: (int page, int limit, List<MusicAggregator> aggs) async {
return await MusicAggregator.searchOnline(
aggs: aggs,
servers: MusicServer.all(),
content: inputContentController.value.text,
page: page,
size: limit,
);
},
pagingController: pagingControllerMusicAggregator,
itemName: "歌曲",
shouldEnd: (pagingController, lastItemLen, newResult) {
return newResult.length <= lastItemLen;
},
);
}

Future<void> _fetchAllPlaylists() async {
await fetchAllItemsWithPagingController((int page, int limit) async {
return await Playlist.searchOnline(
servers: [MusicServer.kuwo, MusicServer.netease],
content: inputContentController.value.text,
page: page,
size: limit,
);
}, pagingControllerPlaylist, "歌单");
await fetchAllItemsWithPagingController(
fetchItems: (int page, int limit, List<Playlist> playlists) async {
return await Playlist.searchOnline(
servers: [MusicServer.kuwo, MusicServer.netease],
content: inputContentController.value.text,
page: page,
size: limit,
);
},
pagingController: pagingControllerPlaylist,
itemName: "歌单");
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/types/extern_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Crypto {
try {
// TODO: secret
return await crypto.rc4DecryptFromBase64(
key: "512388e3-c321-47b1-be50-641f75738cb2", input: input);
key: "rhyme666", input: input);
} catch (e) {
globalTalker.error("[Crypto] $e");
return "";
Expand Down
16 changes: 8 additions & 8 deletions lib/utils/cache_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ ExtendedImage imageWithCache(
uri,
width: width,
height: height,
cacheWidth: width?.toInt(),
cacheHeight: height?.toInt(),
cacheWidth: cacheWidth?.toInt() ?? width?.toInt(),
cacheHeight: cacheHeight?.toInt() ?? height?.toInt(),
fit: BoxFit.cover,
scale: scale ?? 1.0,
borderRadius: borderRadius,
Expand All @@ -102,8 +102,8 @@ ExtendedImage imageWithCache(
defaultCoverPath,
width: width,
height: height,
cacheWidth: width?.toInt(),
cacheHeight: height?.toInt(),
cacheWidth: cacheWidth?.toInt() ?? width?.toInt(),
cacheHeight: cacheHeight?.toInt() ?? height?.toInt(),
fit: BoxFit.cover,
scale: scale,
borderRadius: borderRadius,
Expand All @@ -119,8 +119,8 @@ ExtendedImage imageWithCache(
File(uri),
width: width,
height: height,
cacheWidth: width?.toInt(),
cacheHeight: height?.toInt(),
cacheWidth: cacheWidth?.toInt() ?? width?.toInt(),
cacheHeight: cacheHeight?.toInt() ?? height?.toInt(),
fit: BoxFit.cover,
scale: scale ?? 1.0,
borderRadius: borderRadius,
Expand All @@ -136,8 +136,8 @@ ExtendedImage imageWithCache(
defaultCoverPath,
width: width,
height: height,
cacheWidth: width?.toInt(),
cacheHeight: height?.toInt(),
cacheWidth: cacheWidth?.toInt() ?? width?.toInt(),
cacheHeight: cacheHeight?.toInt() ?? height?.toInt(),
fit: BoxFit.cover,
scale: scale,
borderRadius: borderRadius,
Expand Down
Loading

0 comments on commit 8b5761f

Please sign in to comment.