diff --git a/lib/common_comps/explore/playlist_tag_collection.dart b/lib/common_comps/explore/playlist_tag_collection.dart index 446d049..e64c114 100644 --- a/lib/common_comps/explore/playlist_tag_collection.dart +++ b/lib/common_comps/explore/playlist_tag_collection.dart @@ -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 playlists) async { return await ServerPlaylistTagCollection .getPlaylistsFromTag( server: server, diff --git a/lib/common_comps/paged/paged_music_agg_listview.dart b/lib/common_comps/paged/paged_music_agg_listview.dart index 83d7211..2635d6c 100644 --- a/lib/common_comps/paged/paged_music_agg_listview.dart +++ b/lib/common_comps/paged/paged_music_agg_listview.dart @@ -39,7 +39,7 @@ class PagedMusicAggregatorListState extends State { 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( diff --git a/lib/common_pages/online_music_agg_listview_page.dart b/lib/common_pages/online_music_agg_listview_page.dart index 4035560..11d84f6 100644 --- a/lib/common_pages/online_music_agg_listview_page.dart +++ b/lib/common_pages/online_music_agg_listview_page.dart @@ -46,7 +46,7 @@ class OnlineMusicAggregatorListViewPageState PagingController(firstPageKey: 1); Future> _fetchMusicAggregators( - int page, int pageSize) async { + int page, int pageSize, List aggs) async { if (widget.playlist != null) { return await widget.playlist!.fetchMusicsOnline(page: page, limit: 30); } else if (widget.fetchMusicAggregators != null) { @@ -77,9 +77,12 @@ class OnlineMusicAggregatorListViewPageState Future _fetchAllMusicAggregators() async { await fetchAllItemsWithPagingController( - _fetchMusicAggregators, - _pagingController, - "音乐", + fetchItems: _fetchMusicAggregators, + pagingController: _pagingController, + itemName: "音乐", + shouldEnd: (pagingController, lastItemLen, newResult) { + return newResult.length <= lastItemLen; + }, ); } diff --git a/lib/common_pages/online_playlist_gridview_page.dart b/lib/common_pages/online_playlist_gridview_page.dart index 58cd15a..49257e5 100644 --- a/lib/common_pages/online_playlist_gridview_page.dart +++ b/lib/common_pages/online_playlist_gridview_page.dart @@ -17,7 +17,8 @@ class OnlinePlaylistGridViewPage extends StatefulWidget { required this.fetchPlaylists, this.title = "在线歌单"}); final String title; - final Future> Function(int page, int limit) fetchPlaylists; + final Future> Function( + int page, int limit, List playlists) fetchPlaylists; final bool isDesktop; @override @@ -36,7 +37,7 @@ class SearchMusicListState extends State _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) { @@ -60,9 +61,9 @@ class SearchMusicListState extends State Future _fetchAllPlaylists() async { await fetchAllItemsWithPagingController( - widget.fetchPlaylists, - _pagingController, - "歌单", + fetchItems: widget.fetchPlaylists, + pagingController: _pagingController, + itemName: "歌单", ); } diff --git a/lib/desktop/comps/music_agg_comp/music_agg_list_item.dart b/lib/desktop/comps/music_agg_comp/music_agg_list_item.dart index 77455af..6e2d324 100644 --- a/lib/desktop/comps/music_agg_comp/music_agg_list_item.dart +++ b/lib/desktop/comps/music_agg_comp/music_agg_list_item.dart @@ -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, + )), + )), ], ); } diff --git a/lib/desktop/pages/search_page/music_aggregator.dart b/lib/desktop/pages/search_page/music_aggregator.dart index 7b4a228..1f0a988 100644 --- a/lib/desktop/pages/search_page/music_aggregator.dart +++ b/lib/desktop/pages/search_page/music_aggregator.dart @@ -24,23 +24,24 @@ class MusicAggregatorSearchPageState extends State 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 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; + }, + ); }); } @@ -56,15 +57,22 @@ class MusicAggregatorSearchPageState extends State } Future _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 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 diff --git a/lib/desktop/pages/search_page/playlist.dart b/lib/desktop/pages/search_page/playlist.dart index 1bbad8d..b3a1ba0 100644 --- a/lib/desktop/pages/search_page/playlist.dart +++ b/lib/desktop/pages/search_page/playlist.dart @@ -30,6 +30,7 @@ class SearchMusicListState extends State int page, int pageSize, String content, + List playlists, ) async { return await Playlist.searchOnline( servers: MusicServer.all(), @@ -55,13 +56,16 @@ class SearchMusicListState extends State } Future _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 playlists) async { + return await Playlist.searchOnline( + servers: [MusicServer.kuwo, MusicServer.netease], + content: inputContentController.value.text, + page: page, + size: limit); + }, + pagingController: pagingControllerPlaylist, + itemName: "歌单"); } @override diff --git a/lib/mobile/pages/search_page.dart b/lib/mobile/pages/search_page.dart index 604cfe9..390b690 100644 --- a/lib/mobile/pages/search_page.dart +++ b/lib/mobile/pages/search_page.dart @@ -42,13 +42,10 @@ class _SearchPageMobileState extends State { fetchItemWithInputPagingController( inputController: inputContentController, pagingController: pagingControllerMusicAggregator, - fetchFunction: ( - int page, - int pageSize, - String content, - ) async { + fetchFunction: (int page, int pageSize, String content, + List aggs) async { return await MusicAggregator.searchOnline( - aggs: pagingControllerMusicAggregator.itemList ?? [], + aggs: aggs, servers: MusicServer.all(), content: content, page: pageKey, @@ -56,6 +53,9 @@ class _SearchPageMobileState extends State { ); }, pageKey: pageKey, + shouldEnd: (pagingController, lastItemLen, newResult) { + return newResult.length <= lastItemLen; + }, itemName: "歌曲"); }); pagingControllerPlaylist.addPageRequestListener((pageKey) { @@ -66,6 +66,7 @@ class _SearchPageMobileState extends State { int page, int pageSize, String content, + List playlists, ) async { return await Playlist.searchOnline( servers: MusicServer.all(), @@ -80,26 +81,36 @@ class _SearchPageMobileState extends State { } Future _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 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 _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 playlists) async { + return await Playlist.searchOnline( + servers: [MusicServer.kuwo, MusicServer.netease], + content: inputContentController.value.text, + page: page, + size: limit, + ); + }, + pagingController: pagingControllerPlaylist, + itemName: "歌单"); } @override diff --git a/lib/types/extern_api.dart b/lib/types/extern_api.dart index c87c29f..a8df6da 100644 --- a/lib/types/extern_api.dart +++ b/lib/types/extern_api.dart @@ -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 ""; diff --git a/lib/utils/cache_helper.dart b/lib/utils/cache_helper.dart index 7f1c92f..1ba73fd 100644 --- a/lib/utils/cache_helper.dart +++ b/lib/utils/cache_helper.dart @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/lib/utils/music_api_helper.dart b/lib/utils/music_api_helper.dart index 1b77b91..147a498 100644 --- a/lib/utils/music_api_helper.dart +++ b/lib/utils/music_api_helper.dart @@ -37,18 +37,24 @@ Music? getMusicAggregatorDefaultMusic(MusicAggregator musicAggregator) { return null; } -const int fetchAllPageSize = 500; +const int fetchAllPageSize = 2333; const int fetchOnePageSize = 30; Future fetchItemWithInputPagingController({ required TextEditingController inputController, required PagingController pagingController, - required Future> Function(int page, int pageSize, String content) + required Future> Function( + int page, int pageSize, String content, List items) fetchFunction, required int pageKey, required String itemName, + bool Function(PagingController pagingController, int lastItemLen, + List newResult)? + shouldEnd, }) async { try { + int lastItemLen = pagingController.itemList?.length ?? 0; + if (inputController.value.text.isEmpty) { pagingController.appendLastPage([]); return; @@ -58,12 +64,20 @@ Future fetchItemWithInputPagingController({ pageKey, fetchOnePageSize, inputController.value.text, + pagingController.itemList ?? [], ); - - if (results.isEmpty) { - pagingController.appendLastPage([]); + if (shouldEnd != null) { + if (shouldEnd(pagingController, lastItemLen, results)) { + pagingController.appendLastPage(results); + } else { + pagingController.appendPage(results, pageKey + 1); + } } else { - pagingController.appendPage(results, pageKey + 1); + if (results.isEmpty) { + pagingController.appendLastPage([]); + } else { + pagingController.appendPage(results, pageKey + 1); + } } } catch (error) { LogToast.error( @@ -77,12 +91,14 @@ Future fetchItemWithInputPagingController({ Future fetchItemWithPagingController({ required PagingController pagingController, - required Future> Function(int page, int pageSize) fetchFunction, + required Future> Function(int page, int pageSize, List items) + fetchFunction, required int pageKey, required String itemName, }) async { try { - var results = await fetchFunction(pageKey, fetchOnePageSize); + var results = await fetchFunction( + pageKey, fetchOnePageSize, pagingController.itemList ?? []); if (results.isEmpty) { pagingController.appendLastPage([]); @@ -130,25 +146,38 @@ Future?> fetchAllItems( // safe Future?> fetchAllItemsWithPagingController( - Future> Function(int page, int limit) fetchItems, - PagingController pagingController, - String itemName) async { + {required Future> Function(int page, int limit, List items) + fetchItems, + required PagingController pagingController, + required String itemName, + bool Function(PagingController pagingController, int lastItemLen, + List newResult)? + shouldEnd}) async { if (pagingController.nextPageKey == null) return null; LogToast.info("获取所有$itemName", "正在获取所有$itemName,请稍等", "[fetchAllItemsWithPagingController] fetching all $itemName, please wait."); try { - var fetchedItems = await fetchItems(1, fetchAllPageSize); + var fetchedItems = + await fetchItems(1, fetchAllPageSize, pagingController.itemList ?? []); pagingController.value = PagingState( nextPageKey: 2, itemList: fetchedItems, error: null); while (pagingController.nextPageKey != null) { - var fetchedItems = - await fetchItems(pagingController.nextPageKey!, fetchAllPageSize); - - if (fetchedItems.isEmpty) { - pagingController.appendLastPage([]); - break; + var fetchedItems = await fetchItems(pagingController.nextPageKey!, + fetchAllPageSize, pagingController.itemList ?? []); + + if (shouldEnd != null) { + if (shouldEnd(pagingController, pagingController.itemList!.length, + fetchedItems)) { + pagingController.appendLastPage(fetchedItems); + break; + } + } else { + if (fetchedItems.isEmpty) { + pagingController.appendLastPage([]); + break; + } } pagingController.appendPage( @@ -790,7 +819,7 @@ Future viewArtistAlbums( OnlinePlaylistGridViewPage( title: artist.name, isDesktop: isDesktop, - fetchPlaylists: (int page, int limit) async { + fetchPlaylists: (int page, int limit, List playlists) async { return await Playlist.fetchArtistAlbums( server: music.server, artistId: artist!.id!,