Skip to content

Commit 0d527c2

Browse files
committed
feat(ui): show blacklist
1 parent 0dea185 commit 0d527c2

File tree

3 files changed

+113
-3
lines changed

3 files changed

+113
-3
lines changed

ui/lib/activity.dart

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
2020
@override
2121
void initState() {
2222
super.initState();
23-
_nestedTabController = new TabController(length: 3, vsync: this);
23+
_nestedTabController = new TabController(length: 4, vsync: this);
2424
}
2525

2626
@override
@@ -33,7 +33,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
3333

3434
@override
3535
Widget build(BuildContext context) {
36-
return Column(
36+
return SelectionArea(
37+
child: Column(
3738
crossAxisAlignment: CrossAxisAlignment.stretch,
3839
children: [
3940
TabBar(
@@ -54,6 +55,9 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
5455
Tab(
5556
text: "历史记录",
5657
),
58+
Tab(
59+
text: "黑名单",
60+
)
5761
],
5862
),
5963
Builder(builder: (context) {
@@ -68,6 +72,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
6872
} else if (selectedTab == 0) {
6973
activitiesWatcher =
7074
ref.watch(activitiesDataProvider(ActivityStatus.active));
75+
} else if (selectedTab == 3) {
76+
return showBlacklistTab();
7177
}
7278

7379
return activitiesWatcher!.when(
@@ -161,7 +167,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
161167
loading: () => const MyProgressIndicator());
162168
})
163169
],
164-
);
170+
));
165171
}
166172

167173
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
@@ -205,4 +211,38 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
205211
},
206212
);
207213
}
214+
215+
Widget showBlacklistTab() {
216+
var blacklistDataWacher = ref.watch(blacklistDataProvider);
217+
218+
return blacklistDataWacher.when(
219+
data: (blacklists) {
220+
return Flexible(
221+
child: SelectionArea(
222+
child: ListView.builder(
223+
itemCount: blacklists.length,
224+
itemBuilder: (context, index) {
225+
final item = blacklists[index];
226+
return ListTile(
227+
dense: true,
228+
title: Text(item.torrentName ?? ""),
229+
subtitle: Opacity( opacity: 0.7,child: Text("hash: ${item.torrentHash ?? ""}")),
230+
trailing: IconButton(
231+
onPressed: () {
232+
final f = ref
233+
.read(blacklistDataProvider.notifier)
234+
.deleteBlacklist(item.id!)
235+
.then((value) {
236+
//Navigator.of(context).pop();
237+
});
238+
showLoadingWithFuture(f);
239+
},
240+
icon: const Icon(Icons.delete)),
241+
);
242+
})));
243+
},
244+
error: (err, trace) => PoNetworkError(err: err),
245+
loading: () => const MyProgressIndicator(),
246+
);
247+
}
208248
}

ui/lib/providers/APIs.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class APIs {
6161

6262
static final mediaSizeLimiterUrl = "$_baseUrl/api/v1/setting/limiter";
6363

64+
static final blacklistUrl = "$_baseUrl/api/v1/activity/blacklist";
65+
66+
6467
static const tmdbApiKey = "tmdb_api_key";
6568
static const downloadDirKey = "download_dir";
6669

ui/lib/providers/activity.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:ui/providers/server_response.dart';
77
var activitiesDataProvider = AsyncNotifierProvider.autoDispose
88
.family<ActivityData, List<Activity>, ActivityStatus>(ActivityData.new);
99

10+
var blacklistDataProvider = AsyncNotifierProvider.autoDispose<BlacklistData,List<Blacklist>>(BlacklistData.new);
11+
1012
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
1113
(ref, arg) async {
1214
final dio = await APIs.getDio();
@@ -82,6 +84,7 @@ class ActivityData
8284
}
8385
}
8486

87+
8588
class Activity {
8689
Activity(
8790
{required this.id,
@@ -126,3 +129,67 @@ class Activity {
126129
uploadProgress: json["upload_progress"]);
127130
}
128131
}
132+
133+
134+
class BlacklistData extends AutoDisposeAsyncNotifier<List<Blacklist>> {
135+
@override
136+
FutureOr<List<Blacklist>> build() async {
137+
final dio = APIs.getDio();
138+
var resp = await dio.get(APIs.blacklistUrl);
139+
final sp = ServerResponse.fromJson(resp.data);
140+
if (sp.code!= 0) {
141+
throw sp.message;
142+
}
143+
List<Blacklist> blaclklists = List.empty(growable: true);
144+
for (final a in sp.data as List) {
145+
blaclklists.add(Blacklist.fromJson(a));
146+
}
147+
return blaclklists;
148+
}
149+
150+
Future<void> deleteBlacklist(int id) async {
151+
final dio = APIs.getDio();
152+
var resp = await dio.delete("${APIs.blacklistUrl}/$id");
153+
final sp = ServerResponse.fromJson(resp.data);
154+
if (sp.code!= 0) {
155+
throw sp.message;
156+
}
157+
}
158+
}
159+
160+
class Blacklist {
161+
int? id;
162+
String? type;
163+
String? torrentHash;
164+
String? torrentName;
165+
int? mediaId;
166+
String? createTime;
167+
168+
Blacklist(
169+
{this.id,
170+
this.type,
171+
this.torrentHash,
172+
this.torrentName,
173+
this.mediaId,
174+
this.createTime});
175+
176+
Blacklist.fromJson(Map<String, dynamic> json) {
177+
id = json['id'];
178+
type = json['type'];
179+
torrentHash = json['torrent_hash'];
180+
torrentName = json['torrent_name'];
181+
mediaId = json['media_id'];
182+
createTime = json['create_time'];
183+
}
184+
185+
Map<String, dynamic> toJson() {
186+
final Map<String, dynamic> data = new Map<String, dynamic>();
187+
data['id'] = this.id;
188+
data['type'] = this.type;
189+
data['torrent_hash'] = this.torrentHash;
190+
data['torrent_name'] = this.torrentName;
191+
data['media_id'] = this.mediaId;
192+
data['create_time'] = this.createTime;
193+
return data;
194+
}
195+
}

0 commit comments

Comments
 (0)