mirror of
https://github.com/simon-ding/polaris.git
synced 2026-05-29 22:18:08 +08:00
feat(ui): show blacklist
This commit is contained in:
@@ -20,7 +20,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_nestedTabController = new TabController(length: 3, vsync: this);
|
_nestedTabController = new TabController(length: 4, vsync: this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -33,7 +33,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return SelectionArea(
|
||||||
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: [
|
children: [
|
||||||
TabBar(
|
TabBar(
|
||||||
@@ -54,6 +55,9 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
Tab(
|
Tab(
|
||||||
text: "历史记录",
|
text: "历史记录",
|
||||||
),
|
),
|
||||||
|
Tab(
|
||||||
|
text: "黑名单",
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Builder(builder: (context) {
|
Builder(builder: (context) {
|
||||||
@@ -68,6 +72,8 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
} else if (selectedTab == 0) {
|
} else if (selectedTab == 0) {
|
||||||
activitiesWatcher =
|
activitiesWatcher =
|
||||||
ref.watch(activitiesDataProvider(ActivityStatus.active));
|
ref.watch(activitiesDataProvider(ActivityStatus.active));
|
||||||
|
} else if (selectedTab == 3) {
|
||||||
|
return showBlacklistTab();
|
||||||
}
|
}
|
||||||
|
|
||||||
return activitiesWatcher!.when(
|
return activitiesWatcher!.when(
|
||||||
@@ -161,7 +167,7 @@ class _ActivityPageState extends ConsumerState<ActivityPage>
|
|||||||
loading: () => const MyProgressIndicator());
|
loading: () => const MyProgressIndicator());
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showConfirmDialog(BuildContext oriContext, int id) {
|
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(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ class APIs {
|
|||||||
|
|
||||||
static final mediaSizeLimiterUrl = "$_baseUrl/api/v1/setting/limiter";
|
static final mediaSizeLimiterUrl = "$_baseUrl/api/v1/setting/limiter";
|
||||||
|
|
||||||
|
static final blacklistUrl = "$_baseUrl/api/v1/activity/blacklist";
|
||||||
|
|
||||||
|
|
||||||
static const tmdbApiKey = "tmdb_api_key";
|
static const tmdbApiKey = "tmdb_api_key";
|
||||||
static const downloadDirKey = "download_dir";
|
static const downloadDirKey = "download_dir";
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import 'package:ui/providers/server_response.dart';
|
|||||||
var activitiesDataProvider = AsyncNotifierProvider.autoDispose
|
var activitiesDataProvider = AsyncNotifierProvider.autoDispose
|
||||||
.family<ActivityData, List<Activity>, ActivityStatus>(ActivityData.new);
|
.family<ActivityData, List<Activity>, ActivityStatus>(ActivityData.new);
|
||||||
|
|
||||||
|
var blacklistDataProvider = AsyncNotifierProvider.autoDispose<BlacklistData,List<Blacklist>>(BlacklistData.new);
|
||||||
|
|
||||||
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
var mediaHistoryDataProvider = FutureProvider.autoDispose.family(
|
||||||
(ref, arg) async {
|
(ref, arg) async {
|
||||||
final dio = await APIs.getDio();
|
final dio = await APIs.getDio();
|
||||||
@@ -82,6 +84,7 @@ class ActivityData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class Activity {
|
class Activity {
|
||||||
Activity(
|
Activity(
|
||||||
{required this.id,
|
{required this.id,
|
||||||
@@ -126,3 +129,67 @@ class Activity {
|
|||||||
uploadProgress: json["upload_progress"]);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user