mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-21 19:27:30 +08:00
feat: setting refactor
This commit is contained in:
@@ -258,126 +258,218 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
var nameController = TextEditingController(text: indexer.name);
|
var nameController = TextEditingController(text: indexer.name);
|
||||||
var urlController = TextEditingController(text: indexer.url);
|
var urlController = TextEditingController(text: indexer.url);
|
||||||
var apiKeyController = TextEditingController(text: indexer.apiKey);
|
var apiKeyController = TextEditingController(text: indexer.apiKey);
|
||||||
return showDialog<void>(
|
var selectImpl = "torznab";
|
||||||
context: context,
|
final children = <Widget>[
|
||||||
barrierDismissible: true, // user must tap button!
|
DropdownMenu(
|
||||||
builder: (BuildContext context) {
|
label: const Text("类型"),
|
||||||
return AlertDialog(
|
onSelected: (value) {
|
||||||
title: const Text('索引器'),
|
setState(() {
|
||||||
content: SingleChildScrollView(
|
selectImpl = value!;
|
||||||
child: ListBody(
|
});
|
||||||
children: <Widget>[
|
},
|
||||||
TextField(
|
initialSelection: selectImpl,
|
||||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
dropdownMenuEntries: const [
|
||||||
controller: nameController,
|
DropdownMenuEntry(value: "torznab", label: "Torznab"),
|
||||||
),
|
],
|
||||||
TextField(
|
),
|
||||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
TextField(
|
||||||
controller: urlController,
|
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||||
),
|
controller: nameController,
|
||||||
TextField(
|
),
|
||||||
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
TextField(
|
||||||
controller: apiKeyController,
|
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||||
),
|
controller: urlController,
|
||||||
],
|
),
|
||||||
),
|
TextField(
|
||||||
),
|
decoration: Commons.requiredTextFieldStyle(text: "API Key"),
|
||||||
actions: <Widget>[
|
controller: apiKeyController,
|
||||||
indexer.id == null
|
),
|
||||||
? const Text("")
|
];
|
||||||
: TextButton(
|
onDelete() async {
|
||||||
onPressed: () {
|
return ref.read(indexersProvider.notifier).deleteIndexer(indexer.id!);
|
||||||
var f = ref
|
}
|
||||||
.read(indexersProvider.notifier)
|
|
||||||
.deleteIndexer(indexer.id!);
|
onSubmit() async {
|
||||||
f.whenComplete(() {
|
return ref.read(indexersProvider.notifier).addIndexer(Indexer(
|
||||||
Utils.showSnakeBar("操作成功");
|
name: nameController.text,
|
||||||
Navigator.of(context).pop();
|
url: urlController.text,
|
||||||
}).onError((e, s) {
|
apiKey: apiKeyController.text));
|
||||||
Utils.showSnakeBar("操作失败:$e");
|
}
|
||||||
});
|
|
||||||
},
|
return showSettingDialog(
|
||||||
child: const Text(
|
"索引器", indexer.id != null, children, onSubmit, onDelete);
|
||||||
'删除',
|
|
||||||
style: TextStyle(color: Colors.red),
|
|
||||||
)),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
child: const Text('取消')),
|
|
||||||
TextButton(
|
|
||||||
child: const Text('确定'),
|
|
||||||
onPressed: () {
|
|
||||||
var f = ref.read(indexersProvider.notifier).addIndexer(
|
|
||||||
Indexer(
|
|
||||||
name: nameController.text,
|
|
||||||
url: urlController.text,
|
|
||||||
apiKey: apiKeyController.text));
|
|
||||||
f.whenComplete(() {
|
|
||||||
Utils.showSnakeBar("操作成功");
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}).onError((e, s) {
|
|
||||||
Utils.showSnakeBar("操作失败:$e");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showDownloadClientDetails(DownloadClient client) {
|
Future<void> showDownloadClientDetails(DownloadClient client) {
|
||||||
var nameController = TextEditingController(text: client.name);
|
var nameController = TextEditingController(text: client.name);
|
||||||
var urlController = TextEditingController(text: client.url);
|
var urlController = TextEditingController(text: client.url);
|
||||||
|
|
||||||
|
String selectImpl = "transmission";
|
||||||
|
var body = <Widget>[
|
||||||
|
DropdownMenu(
|
||||||
|
label: const Text("类型"),
|
||||||
|
onSelected: (value) {
|
||||||
|
setState(() {
|
||||||
|
selectImpl = value!;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
initialSelection: selectImpl,
|
||||||
|
dropdownMenuEntries: const [
|
||||||
|
DropdownMenuEntry(value: "transmission", label: "Transmission"),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
||||||
|
controller: nameController,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
||||||
|
controller: urlController,
|
||||||
|
),
|
||||||
|
|
||||||
|
];
|
||||||
|
onDelete() async {
|
||||||
|
return ref
|
||||||
|
.read(dwonloadClientsProvider.notifier)
|
||||||
|
.deleteDownloadClients(client.id!);
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit() async {
|
||||||
|
return ref
|
||||||
|
.read(dwonloadClientsProvider.notifier)
|
||||||
|
.addDownloadClients(nameController.text, urlController.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
return showSettingDialog(
|
||||||
|
"下载客户端", client.id != null, body, onSubmit, onDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> showStorageDetails(Storage s) {
|
||||||
|
var nameController = TextEditingController(text: s.name);
|
||||||
|
var tvPathController = TextEditingController();
|
||||||
|
var moviePathController = TextEditingController();
|
||||||
|
var urlController = TextEditingController();
|
||||||
|
var userController = TextEditingController();
|
||||||
|
var passController = TextEditingController();
|
||||||
|
if (s.settings != null) {
|
||||||
|
tvPathController.text = s.settings!["tv_path"] ?? "";
|
||||||
|
moviePathController.text = s.settings!["movie_path"] ?? "";
|
||||||
|
urlController.text = s.settings!["url"] ?? "";
|
||||||
|
userController.text = s.settings!["user"] ?? "";
|
||||||
|
passController.text = s.settings!["password"] ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
String selectImpl = s.implementation == null ? "local" : s.implementation!;
|
||||||
|
final widgets = <Widget>[
|
||||||
|
DropdownMenu(
|
||||||
|
label: const Text("类型"),
|
||||||
|
onSelected: (value) {
|
||||||
|
setState(() {
|
||||||
|
selectImpl = value!;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
initialSelection: selectImpl,
|
||||||
|
dropdownMenuEntries: const [
|
||||||
|
DropdownMenuEntry(value: "local", label: "本地存储"),
|
||||||
|
DropdownMenuEntry(value: "webdav", label: "webdav")
|
||||||
|
],
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "名称"),
|
||||||
|
controller: nameController,
|
||||||
|
),
|
||||||
|
selectImpl != "local"
|
||||||
|
? Column(
|
||||||
|
children: [
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "Webdav地址"),
|
||||||
|
controller: urlController,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "用户"),
|
||||||
|
controller: userController,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "密码"),
|
||||||
|
controller: passController,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "电视剧路径"),
|
||||||
|
controller: tvPathController,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
decoration: const InputDecoration(labelText: "电影路径"),
|
||||||
|
controller: moviePathController,
|
||||||
|
)
|
||||||
|
];
|
||||||
|
onSubmit() async {
|
||||||
|
return ref.read(storageSettingProvider.notifier).addStorage(Storage(
|
||||||
|
name: nameController.text,
|
||||||
|
implementation: selectImpl,
|
||||||
|
settings: {
|
||||||
|
"tv_path": tvPathController.text,
|
||||||
|
"movie_path": moviePathController.text,
|
||||||
|
"url": urlController.text,
|
||||||
|
"user": userController.text,
|
||||||
|
"password": passController.text
|
||||||
|
},
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
onDelete() async {
|
||||||
|
return ref.read(storageSettingProvider.notifier).deleteStorage(s.id!);
|
||||||
|
}
|
||||||
|
|
||||||
|
return showSettingDialog('存储', s.id != null, widgets, onSubmit, onDelete);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> showSettingDialog(
|
||||||
|
String title,
|
||||||
|
bool showDelete,
|
||||||
|
List<Widget> children,
|
||||||
|
Future Function() onSubmit,
|
||||||
|
Future Function() onDelete) {
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true, // user must tap button!
|
barrierDismissible: true,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('下载客户端'),
|
title: Text(title),
|
||||||
content: SingleChildScrollView(
|
content: SingleChildScrollView(
|
||||||
child: ListBody(
|
child: Container(
|
||||||
children: <Widget>[
|
constraints: const BoxConstraints(maxWidth: 200),
|
||||||
TextField(
|
child: ListBody(
|
||||||
decoration: Commons.requiredTextFieldStyle(text: "名称"),
|
children: children,
|
||||||
controller: nameController,
|
),
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration: Commons.requiredTextFieldStyle(text: "地址"),
|
|
||||||
controller: urlController,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
client.id == null
|
showDelete
|
||||||
? const Text("")
|
? TextButton(
|
||||||
: TextButton(
|
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var f = ref
|
final f = onDelete();
|
||||||
.read(dwonloadClientsProvider.notifier)
|
|
||||||
.deleteDownloadClients(client.id!);
|
|
||||||
f.whenComplete(() {
|
f.whenComplete(() {
|
||||||
Utils.showSnakeBar("操作成功");
|
Utils.showSnakeBar("删除成功");
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}).onError((e, s) {
|
}).onError((e, s) {
|
||||||
Utils.showSnakeBar("操作失败:$e");
|
Utils.showSnakeBar("删除失败:$e");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: const Text(
|
child: const Text(
|
||||||
'删除',
|
'删除',
|
||||||
style: TextStyle(color: Colors.red),
|
style: TextStyle(color: Colors.red),
|
||||||
)),
|
))
|
||||||
|
: const Text(""),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('取消')),
|
child: const Text('取消')),
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text('确定'),
|
child: const Text('确定'),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
var f = ref
|
final f = onSubmit();
|
||||||
.read(dwonloadClientsProvider.notifier)
|
|
||||||
.addDownloadClients(
|
|
||||||
nameController.text, urlController.text);
|
|
||||||
f.whenComplete(() {
|
f.whenComplete(() {
|
||||||
Utils.showSnakeBar("操作成功");
|
Utils.showSnakeBar("操作成功");
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
@@ -390,139 +482,4 @@ class _SystemSettingsPageState extends ConsumerState<SystemSettingsPage> {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showStorageDetails(Storage s) {
|
|
||||||
return showDialog<void>(
|
|
||||||
context: context,
|
|
||||||
barrierDismissible: true, // user must tap button!
|
|
||||||
builder: (BuildContext context) {
|
|
||||||
var nameController = TextEditingController(text: s.name);
|
|
||||||
var tvPathController = TextEditingController();
|
|
||||||
var moviePathController = TextEditingController();
|
|
||||||
var urlController = TextEditingController();
|
|
||||||
var userController = TextEditingController();
|
|
||||||
var passController = TextEditingController();
|
|
||||||
if (s.settings != null) {
|
|
||||||
tvPathController.text = s.settings!["tv_path"] ?? "";
|
|
||||||
moviePathController.text = s.settings!["movie_path"] ?? "";
|
|
||||||
urlController.text = s.settings!["url"] ?? "";
|
|
||||||
userController.text = s.settings!["user"] ?? "";
|
|
||||||
passController.text = s.settings!["password"] ?? "";
|
|
||||||
}
|
|
||||||
|
|
||||||
String selectImpl =
|
|
||||||
s.implementation == null ? "local" : s.implementation!;
|
|
||||||
return StatefulBuilder(builder: (context, setState) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('存储'),
|
|
||||||
content: SingleChildScrollView(
|
|
||||||
child: ListBody(
|
|
||||||
children: <Widget>[
|
|
||||||
DropdownMenu(
|
|
||||||
label: const Text("实现"),
|
|
||||||
onSelected: (value) {
|
|
||||||
setState(() {
|
|
||||||
selectImpl = value!;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
initialSelection: selectImpl,
|
|
||||||
dropdownMenuEntries: const [
|
|
||||||
DropdownMenuEntry(value: "local", label: "本地存储"),
|
|
||||||
DropdownMenuEntry(value: "webdav", label: "webdav")
|
|
||||||
],
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "名称"),
|
|
||||||
controller: nameController,
|
|
||||||
),
|
|
||||||
selectImpl != "local"
|
|
||||||
? Column(
|
|
||||||
children: [
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
labelText: "Webdav地址"),
|
|
||||||
controller: urlController,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration:
|
|
||||||
const InputDecoration(labelText: "用户"),
|
|
||||||
controller: userController,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration:
|
|
||||||
const InputDecoration(labelText: "密码"),
|
|
||||||
controller: passController,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: Container(),
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "电视剧路径"),
|
|
||||||
controller: tvPathController,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
decoration: const InputDecoration(labelText: "电影路径"),
|
|
||||||
controller: moviePathController,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: <Widget>[
|
|
||||||
s.id == null
|
|
||||||
? const Text("")
|
|
||||||
: TextButton(
|
|
||||||
onPressed: () {
|
|
||||||
var f = ref
|
|
||||||
.read(storageSettingProvider.notifier)
|
|
||||||
.deleteStorage(s.id!);
|
|
||||||
f.whenComplete(() {
|
|
||||||
Utils.showSnakeBar("操作成功");
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}).onError((e, s) {
|
|
||||||
Utils.showSnakeBar("操作失败:$e");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: const Text('删除')),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
|
||||||
child: const Text('取消')),
|
|
||||||
TextButton(
|
|
||||||
child: const Text('确定'),
|
|
||||||
onPressed: () async {
|
|
||||||
final f = ref
|
|
||||||
.read(storageSettingProvider.notifier)
|
|
||||||
.addStorage(Storage(
|
|
||||||
name: nameController.text,
|
|
||||||
implementation: selectImpl,
|
|
||||||
settings: {
|
|
||||||
"tv_path": tvPathController.text,
|
|
||||||
"movie_path": moviePathController.text,
|
|
||||||
"url": urlController.text,
|
|
||||||
"user": userController.text,
|
|
||||||
"password": passController.text
|
|
||||||
},
|
|
||||||
));
|
|
||||||
f.whenComplete(() {
|
|
||||||
Utils.showSnakeBar("操作成功");
|
|
||||||
Navigator.of(context).pop();
|
|
||||||
}).onError((e, s) {
|
|
||||||
Utils.showSnakeBar("操作失败:$e");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
bool showError(AsyncSnapshot<void> snapshot) {
|
|
||||||
final isErrored = snapshot.hasError &&
|
|
||||||
snapshot.connectionState != ConnectionState.waiting;
|
|
||||||
if (isErrored) {
|
|
||||||
Utils.showSnakeBar("当前操作出错: ${snapshot.error}");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user