feat(ui): show blacklist

This commit is contained in:
Simon Ding
2025-04-23 09:53:44 +08:00
parent 0dea185077
commit 0d527c22e5
3 changed files with 113 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
@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<ActivityPage>
@override
Widget build(BuildContext context) {
return Column(
return SelectionArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TabBar(
@@ -54,6 +55,9 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
Tab(
text: "历史记录",
),
Tab(
text: "黑名单",
)
],
),
Builder(builder: (context) {
@@ -68,6 +72,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
} 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<ActivityPage>
loading: () => const MyProgressIndicator());
})
],
);
));
}
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
@@ -205,4 +211,38 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
},
);
}
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(),
);
}
}

View File

@@ -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";

View File

@@ -7,6 +7,8 @@ import 'package:ui/providers/server_response.dart';
var activitiesDataProvider = AsyncNotifierProvider.autoDispose
.family<ActivityData, List<Activity>, ActivityStatus>(ActivityData.new);
var blacklistDataProvider = AsyncNotifierProvider.autoDispose<BlacklistData,List<Blacklist>>(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<List<Blacklist>> {
@override
FutureOr<List<Blacklist>> 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<Blacklist> blaclklists = List.empty(growable: true);
for (final a in sp.data as List) {
blaclklists.add(Blacklist.fromJson(a));
}
return blaclklists;
}
Future<void> 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<String, dynamic> json) {
id = json['id'];
type = json['type'];
torrentHash = json['torrent_hash'];
torrentName = json['torrent_name'];
mediaId = json['media_id'];
createTime = json['create_time'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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;
}
}