add downlaod client setting

This commit is contained in:
Simon Ding
2024-07-09 16:19:19 +08:00
parent a3ac9aeec7
commit 86060cb7be
6 changed files with 216 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
onTap: () {
showIndexerDetails(context, indexer);
},
child: Text(indexer.name!)));
child: Center(child: Text(indexer.name!))));
}
return Card(
margin: const EdgeInsets.all(4),
@@ -115,6 +115,43 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
}),
error: (err, trace) => Text("$err"),
loading: () => const CircularProgressIndicator());
var downloadClients = ref.watch(dwonloadClientsProvider);
var downloadSetting = downloadClients.when(
data: (value) => GridView.builder(
itemCount: value.length + 1,
scrollDirection: Axis.vertical,
shrinkWrap: true,
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 6),
itemBuilder: (context, i) {
if (i < value.length) {
var client = value[i];
return Card(
margin: const EdgeInsets.all(4),
clipBehavior: Clip.hardEdge,
child: InkWell(
//splashColor: Colors.blue.withAlpha(30),
onTap: () {
showDownloadClientDetails(context, client);
},
child: Center(child: Text(client.name!))));
}
return Card(
margin: const EdgeInsets.all(4),
clipBehavior: Clip.hardEdge,
child: InkWell(
//splashColor: Colors.blue.withAlpha(30),
onTap: () {
showDownloadClientDetails(context, DownloadClient());
},
child: const Center(
child: Icon(Icons.add),
)));
}),
error: (err, trace) => Text("$err"),
loading: () => const CircularProgressIndicator());
return ListView(
children: [
ExpansionTile(
@@ -131,6 +168,13 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
title: const Text("索引器设置"),
children: [indexerSetting],
),
ExpansionTile(
tilePadding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
childrenPadding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
initiallyExpanded: true,
title: const Text("下载器设置"),
children: [downloadSetting],
),
],
);
}
@@ -174,11 +218,11 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
),
),
actions: <Widget>[
TextButton(
onPressed: () => {
deleteIndexer(context, indexer.id!)
},
child: const Text('删除')),
indexer.id == null
? Text("")
: TextButton(
onPressed: () => {deleteIndexer(context, indexer.id!)},
child: const Text('删除')),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消')),
@@ -217,6 +261,80 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
return;
}
Navigator.of(context).pop();
ref.refresh(indexersProvider);
ref.refresh(dwonloadClientsProvider);
}
Future<void> showDownloadClientDetails(
BuildContext context, DownloadClient client) {
var nameController = TextEditingController(text: client.name);
var urlController = TextEditingController(text: client.url);
return showDialog<void>(
context: context,
barrierDismissible: true, // user must tap button!
builder: (BuildContext context) {
return AlertDialog(
title: const Text('索引器'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
TextField(
decoration: const InputDecoration(labelText: "名称"),
controller: nameController,
),
TextField(
decoration: const InputDecoration(labelText: "网址"),
controller: urlController,
),
],
),
),
actions: <Widget>[
client.id == null
? Text("")
: TextButton(
onPressed: () =>
{deleteDownloadClients(context, client.id!)},
child: const Text('删除')),
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消')),
TextButton(
child: const Text('确定'),
onPressed: () {
addDownloadClients(
context, nameController.text, urlController.text);
},
),
],
);
});
}
void addDownloadClients(BuildContext context, String name, String url) async {
var dio = Dio();
var resp = await dio.post(APIs.addDownloadClientUrl, data: {
"name": name,
"url": url,
});
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0 && context.mounted) {
Utils.showAlertDialog(context, sp.message);
return;
}
Navigator.of(context).pop();
ref.refresh(dwonloadClientsProvider);
}
void deleteDownloadClients(BuildContext context, int id) async {
var dio = Dio();
var resp = await dio.delete("${APIs.delDownloadClientUrl}$id");
var sp = ServerResponse.fromJson(resp.data);
if (sp.code != 0 && context.mounted) {
Utils.showAlertDialog(context, sp.message);
return;
}
Navigator.of(context).pop();
ref.refresh(dwonloadClientsProvider);
}
}