mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Improve the UI of comic source list.
This commit is contained in:
@@ -387,9 +387,10 @@
|
||||
"Screen center": "屏幕中心",
|
||||
"Suggestions": "建议",
|
||||
"Do not report any issues related to sources to App repo.": "请不要向App仓库报告任何与源相关的问题",
|
||||
"Click the setting icon to change the source list url.": "点击设置图标更改源列表URL",
|
||||
"Show single image on first page": "在首页显示单张图片",
|
||||
"Click to select an image": "点击选择一张图片"
|
||||
"Click to select an image": "点击选择一张图片",
|
||||
"Source URL": "源地址",
|
||||
"The URL should point to a 'index.json' file": "该URL应指向一个'index.json'文件"
|
||||
},
|
||||
"zh_TW": {
|
||||
"Home": "首頁",
|
||||
@@ -779,8 +780,9 @@
|
||||
"Screen center": "螢幕中心",
|
||||
"Suggestions": "建議",
|
||||
"Do not report any issues related to sources to App repo.": "請不要向App倉庫報告任何與源相關的問題",
|
||||
"Click the setting icon to change the source list url.": "點擊設定圖示更改源列表URL",
|
||||
"Show single image on first page": "在首頁顯示單張圖片",
|
||||
"Click to select an image": "點擊選擇一張圖片"
|
||||
"Click to select an image": "點擊選擇一張圖片",
|
||||
"Source URL": "源地址",
|
||||
"The URL should point to a 'index.json' file": "該URL應指向一個'index.json'文件"
|
||||
}
|
||||
}
|
||||
|
@@ -178,8 +178,7 @@ class Settings with ChangeNotifier {
|
||||
'customImageProcessing': defaultCustomImageProcessing,
|
||||
'sni': true,
|
||||
'autoAddLanguageFilter': 'none', // none, chinese, english, japanese
|
||||
'comicSourceListUrl':
|
||||
"https://cdn.jsdelivr.net/gh/venera-app/venera-configs@latest/index.json",
|
||||
'comicSourceListUrl': defaultComicSourceUrl,
|
||||
'preloadImageCount': 4,
|
||||
'followUpdatesFolder': null,
|
||||
'initialPage': '0',
|
||||
@@ -220,3 +219,5 @@ function processImage(image, cid, eid, page, sourceKey) {
|
||||
return futureImage;
|
||||
}
|
||||
''';
|
||||
|
||||
const defaultComicSourceUrl = "https://cdn.jsdelivr.net/gh/venera-app/venera-configs@latest/index.json";
|
||||
|
@@ -322,85 +322,127 @@ class _ComicSourceList extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ComicSourceListState extends State<_ComicSourceList> {
|
||||
bool loading = true;
|
||||
List? json;
|
||||
bool changed = false;
|
||||
var controller = TextEditingController();
|
||||
|
||||
void load() async {
|
||||
var dio = AppDio();
|
||||
var res = await dio.get<String>(appdata.settings['comicSourceListUrl']);
|
||||
if (res.statusCode != 200) {
|
||||
context.showMessage(message: "Network error".tl);
|
||||
return;
|
||||
if (json != null) {
|
||||
setState(() {
|
||||
json = null;
|
||||
});
|
||||
}
|
||||
var dio = AppDio();
|
||||
try {
|
||||
var res = await dio.get<String>(controller.text);
|
||||
if (res.statusCode != 200) {
|
||||
throw "error";
|
||||
}
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
json = jsonDecode(res.data!);
|
||||
loading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
catch(e) {
|
||||
context.showMessage(message: "Network error".tl);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
json = [];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
controller.text = appdata.settings['comicSourceListUrl'];
|
||||
load();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
if (changed) {
|
||||
appdata.settings['comicSourceListUrl'] = controller.text;
|
||||
appdata.saveData();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopUpWidgetScaffold(
|
||||
title: "Comic Source".tl,
|
||||
tailing: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.settings),
|
||||
onPressed: () async {
|
||||
await showInputDialog(
|
||||
context: context,
|
||||
title: "Set comic source list url".tl,
|
||||
initialValue: appdata.settings['comicSourceListUrl'],
|
||||
onConfirm: (value) {
|
||||
appdata.settings['comicSourceListUrl'] = value;
|
||||
appdata.saveData();
|
||||
setState(() {
|
||||
loading = true;
|
||||
json = null;
|
||||
});
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
body: buildBody(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget buildBody() {
|
||||
if (loading) {
|
||||
load();
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else {
|
||||
var currentKey = ComicSource.all().map((e) => e.key).toList();
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: json!.length + 1,
|
||||
itemCount: (json?.length ?? 1) + 1,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
padding: const EdgeInsets.all(8),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: context.colorScheme.primaryContainer,
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.outlineVariant,
|
||||
width: 0.6,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Do not report any issues related to sources to App repo.".tl),
|
||||
Text("Click the setting icon to change the source list url.".tl),
|
||||
ListTile(
|
||||
leading: Icon(Icons.source_outlined),
|
||||
title: Text("Source URL".tl),
|
||||
),
|
||||
TextField(
|
||||
controller: controller,
|
||||
decoration: InputDecoration(
|
||||
hintText: "URL",
|
||||
border: const UnderlineInputBorder(),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 12),
|
||||
),
|
||||
onChanged: (value) {
|
||||
changed = true;
|
||||
},
|
||||
).paddingHorizontal(16).paddingBottom(8),
|
||||
Text("The URL should point to a 'index.json' file".tl).paddingLeft(16),
|
||||
Text("Do not report any issues related to sources to App repo.".tl).paddingLeft(16),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
controller.text = defaultComicSourceUrl;
|
||||
changed = true;
|
||||
},
|
||||
child: Text("Reset".tl),
|
||||
),
|
||||
FilledButton.tonal(
|
||||
onPressed: load,
|
||||
child: Text("Refresh".tl),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (index == 1 && json == null) {
|
||||
return Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
index--;
|
||||
|
||||
var key = json![index]["key"];
|
||||
@@ -443,7 +485,6 @@ class _ComicSourceListState extends State<_ComicSourceList> {
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _validatePages() {
|
||||
|
@@ -1100,4 +1100,4 @@ packages:
|
||||
version: "0.0.12"
|
||||
sdks:
|
||||
dart: ">=3.7.0 <4.0.0"
|
||||
flutter: ">=3.29.2"
|
||||
flutter: ">=3.29.3"
|
||||
|
Reference in New Issue
Block a user