From 84ee106ddffc67cb30bbd7ed52961fe61827da25 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Mon, 2 Dec 2024 13:57:48 +0800 Subject: [PATCH] opt: blackMidsList Signed-off-by: bggRGjQaUbCoE --- lib/common/widgets/video_popup_menu.dart | 8 ++------ lib/http/search.dart | 3 +-- lib/http/video.dart | 17 +++++------------ lib/pages/blacklist/index.dart | 10 ++++++---- lib/utils/storage.dart | 8 ++++++++ 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/lib/common/widgets/video_popup_menu.dart b/lib/common/widgets/video_popup_menu.dart index cd77b0b1b..ac7e039f3 100644 --- a/lib/common/widgets/video_popup_menu.dart +++ b/lib/common/widgets/video_popup_menu.dart @@ -240,13 +240,9 @@ class VideoCustomActions { act: 5, reSrc: 11, ); - List blackMidsList = GStorage.localCache - .get(LocalCacheKey.blackMidsList, defaultValue: [-1]) - .map((i) => i as int) - .toList(); + List blackMidsList = GStorage.blackMidsList; blackMidsList.insert(0, videoItem.owner.mid); - GStorage.localCache - .put(LocalCacheKey.blackMidsList, blackMidsList); + GStorage.setBlackMidsList(blackMidsList); Get.back(); SmartDialog.showToast(res['msg'] ?? '成功'); }, diff --git a/lib/http/search.dart b/lib/http/search.dart index f8f37d2c0..76d56229c 100644 --- a/lib/http/search.dart +++ b/lib/http/search.dart @@ -104,8 +104,7 @@ class SearchHttp { try { switch (searchType) { case SearchType.video: - List blackMidsList = localCache - .get(LocalCacheKey.blackMidsList, defaultValue: []); + List blackMidsList = GStorage.blackMidsList; if (res.data['data']['result'] != null) { for (var i in res.data['data']['result']) { // 屏蔽推广和拉黑用户 diff --git a/lib/http/video.dart b/lib/http/video.dart index 89760af1a..4be804144 100644 --- a/lib/http/video.dart +++ b/lib/http/video.dart @@ -53,8 +53,7 @@ class VideoHttp { ); if (res.data['code'] == 0) { List list = []; - List blackMidsList = - localCache.get(LocalCacheKey.blackMidsList, defaultValue: []); + List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['item']) { //过滤掉live与ad,以及拉黑用户 if (i['goto'] == 'av' && @@ -140,8 +139,7 @@ class VideoHttp { ); if (res.data['code'] == 0) { List list = []; - List blackMidsList = - localCache.get(LocalCacheKey.blackMidsList, defaultValue: []); + List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['items']) { // 屏蔽推广和拉黑用户 if (i['card_goto'] != 'ad_av' && @@ -171,10 +169,7 @@ class VideoHttp { ); if (res.data['code'] == 0) { List list = []; - List blackMidsList = localCache - .get(LocalCacheKey.blackMidsList, defaultValue: [-1]) - .map((e) => e as int) - .toList(); + List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['list']) { if (!blackMidsList.contains(i['owner']['mid'])) { list.add(HotVideoItemModel.fromJson(i)); @@ -190,8 +185,7 @@ class VideoHttp { dynamic res = await GrpcRepo.popular(idx); if (res['status']) { List list = []; - List blackMidsList = - localCache.get(LocalCacheKey.blackMidsList, defaultValue: []); + List blackMidsList = GStorage.blackMidsList; for (card.Card item in res['data']) { if (!blackMidsList.contains(item.smallCoverV5.up.id.toInt())) { list.add(item); @@ -977,8 +971,7 @@ class VideoHttp { var res = await Request().get(rankApi); if (res.data['code'] == 0) { List list = []; - List blackMidsList = - localCache.get(LocalCacheKey.blackMidsList, defaultValue: []); + List blackMidsList = GStorage.blackMidsList; for (var i in res.data['data']['list']) { if (!blackMidsList.contains(i['owner']['mid'])) { list.add(HotVideoItemModel.fromJson(i)); diff --git a/lib/pages/blacklist/index.dart b/lib/pages/blacklist/index.dart index b306a0519..ee5c60e3f 100644 --- a/lib/pages/blacklist/index.dart +++ b/lib/pages/blacklist/index.dart @@ -25,8 +25,8 @@ class _BlackListPageState extends State { List list = _blackListController.loadingState.value is Success ? (_blackListController.loadingState.value as Success).response : []; - GStorage.localCache.put(LocalCacheKey.blackMidsList, - list.isNotEmpty ? list.map((e) => e.mid!).toList() : list); + GStorage.setBlackMidsList( + list.isNotEmpty ? list.map((e) => e.mid!).toList() : []); super.dispose(); } @@ -121,7 +121,8 @@ class BlackListController extends CommonController { if (response.response.list.length >= total.value) { isEnd = true; } - loadingState.value = LoadingState.success(response.response.list); + loadingState.value = LoadingState.success( + response.response.list.isNotEmpty ? response.response.list : []); return true; } @@ -131,7 +132,8 @@ class BlackListController extends CommonController { List list = (loadingState.value as Success).response; list.removeWhere((e) => e.mid == mid); total.value = total.value - 1; - loadingState.value = LoadingState.success(list); + loadingState.value = + LoadingState.success(list.isNotEmpty ? list : []); SmartDialog.showToast(result['msg']); } } diff --git a/lib/utils/storage.dart b/lib/utils/storage.dart index 35eb769bc..d7ccf28cf 100644 --- a/lib/utils/storage.dart +++ b/lib/utils/storage.dart @@ -114,6 +114,14 @@ class GStorage { static List get dynamicDetailRatio => setting.get(SettingBoxKey.dynamicDetailRatio, defaultValue: [60.0, 40.0]); + static List get blackMidsList => List.from(GStorage.localCache + .get(LocalCacheKey.blackMidsList, defaultValue: [])); + + static void setBlackMidsList(blackMidsList) { + if (blackMidsList is! List) return; + GStorage.localCache.put(LocalCacheKey.blackMidsList, blackMidsList); + } + static MemberTabType get memberTab => MemberTabType .values[setting.get(SettingBoxKey.memberTab, defaultValue: 0)];