diff --git a/ui/lib/activity.dart b/ui/lib/activity.dart index a3d5bbc..8a233b4 100644 --- a/ui/lib/activity.dart +++ b/ui/lib/activity.dart @@ -20,7 +20,7 @@ class _ActivityPageState extends ConsumerState @override void initState() { super.initState(); - _nestedTabController = new TabController(length: 3, vsync: this); + _nestedTabController = new TabController(length: 4, vsync: this); } @override @@ -33,7 +33,8 @@ class _ActivityPageState extends ConsumerState @override Widget build(BuildContext context) { - return Column( + return SelectionArea( + child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ TabBar( @@ -54,6 +55,9 @@ class _ActivityPageState extends ConsumerState Tab( text: "历史记录", ), + Tab( + text: "黑名单", + ) ], ), Builder(builder: (context) { @@ -68,6 +72,8 @@ class _ActivityPageState extends ConsumerState } else if (selectedTab == 0) { activitiesWatcher = ref.watch(activitiesDataProvider(ActivityStatus.active)); + } else if (selectedTab == 3) { + return showBlacklistTab(); } return activitiesWatcher!.when( @@ -161,7 +167,7 @@ class _ActivityPageState extends ConsumerState loading: () => const MyProgressIndicator()); }) ], - ); + )); } Future showConfirmDialog(BuildContext oriContext, int id) { @@ -205,4 +211,38 @@ class _ActivityPageState extends ConsumerState }, ); } + + Widget showBlacklistTab() { + var blacklistDataWacher = ref.watch(blacklistDataProvider); + + return blacklistDataWacher.when( + data: (blacklists) { + return Flexible( + child: SelectionArea( + child: ListView.builder( + itemCount: blacklists.length, + itemBuilder: (context, index) { + final item = blacklists[index]; + return ListTile( + dense: true, + title: Text(item.torrentName ?? ""), + subtitle: Opacity( opacity: 0.7,child: Text("hash: ${item.torrentHash ?? ""}")), + trailing: IconButton( + onPressed: () { + final f = ref + .read(blacklistDataProvider.notifier) + .deleteBlacklist(item.id!) + .then((value) { + //Navigator.of(context).pop(); + }); + showLoadingWithFuture(f); + }, + icon: const Icon(Icons.delete)), + ); + }))); + }, + error: (err, trace) => PoNetworkError(err: err), + loading: () => const MyProgressIndicator(), + ); + } } diff --git a/ui/lib/providers/APIs.dart b/ui/lib/providers/APIs.dart index 656503a..b5a7f26 100644 --- a/ui/lib/providers/APIs.dart +++ b/ui/lib/providers/APIs.dart @@ -61,6 +61,9 @@ class APIs { static final mediaSizeLimiterUrl = "$_baseUrl/api/v1/setting/limiter"; + static final blacklistUrl = "$_baseUrl/api/v1/activity/blacklist"; + + static const tmdbApiKey = "tmdb_api_key"; static const downloadDirKey = "download_dir"; diff --git a/ui/lib/providers/activity.dart b/ui/lib/providers/activity.dart index cab2c59..81dc759 100644 --- a/ui/lib/providers/activity.dart +++ b/ui/lib/providers/activity.dart @@ -7,6 +7,8 @@ import 'package:ui/providers/server_response.dart'; var activitiesDataProvider = AsyncNotifierProvider.autoDispose .family, ActivityStatus>(ActivityData.new); +var blacklistDataProvider = AsyncNotifierProvider.autoDispose>(BlacklistData.new); + var mediaHistoryDataProvider = FutureProvider.autoDispose.family( (ref, arg) async { final dio = await APIs.getDio(); @@ -82,6 +84,7 @@ class ActivityData } } + class Activity { Activity( {required this.id, @@ -126,3 +129,67 @@ class Activity { uploadProgress: json["upload_progress"]); } } + + +class BlacklistData extends AutoDisposeAsyncNotifier> { + @override + FutureOr> build() async { + final dio = APIs.getDio(); + var resp = await dio.get(APIs.blacklistUrl); + final sp = ServerResponse.fromJson(resp.data); + if (sp.code!= 0) { + throw sp.message; + } + List blaclklists = List.empty(growable: true); + for (final a in sp.data as List) { + blaclklists.add(Blacklist.fromJson(a)); + } + return blaclklists; + } + + Future deleteBlacklist(int id) async { + final dio = APIs.getDio(); + var resp = await dio.delete("${APIs.blacklistUrl}/$id"); + final sp = ServerResponse.fromJson(resp.data); + if (sp.code!= 0) { + throw sp.message; + } + } +} + +class Blacklist { + int? id; + String? type; + String? torrentHash; + String? torrentName; + int? mediaId; + String? createTime; + + Blacklist( + {this.id, + this.type, + this.torrentHash, + this.torrentName, + this.mediaId, + this.createTime}); + + Blacklist.fromJson(Map json) { + id = json['id']; + type = json['type']; + torrentHash = json['torrent_hash']; + torrentName = json['torrent_name']; + mediaId = json['media_id']; + createTime = json['create_time']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['type'] = this.type; + data['torrent_hash'] = this.torrentHash; + data['torrent_name'] = this.torrentName; + data['media_id'] = this.mediaId; + data['create_time'] = this.createTime; + return data; + } +} \ No newline at end of file