From 2534c55ffbf5aa43b6f2670c73d1707839a7e897 Mon Sep 17 00:00:00 2001 From: nyne Date: Sun, 26 Jan 2025 12:35:49 +0800 Subject: [PATCH] Improve UI of empty Explore and Category pages. --- assets/translation.json | 10 +++++---- lib/components/loading.dart | 5 ++++- lib/pages/categories_page.dart | 37 +++++++++++++++++++++------------- lib/pages/explore_page.dart | 11 ++++++++-- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/assets/translation.json b/assets/translation.json index 8ad6a72..4362b1b 100644 --- a/assets/translation.json +++ b/assets/translation.json @@ -229,7 +229,7 @@ "Clear History": "清除历史", "Are you sure you want to clear your history?": "确定要清除您的历史记录吗?", "No Explore Pages": "没有探索页面", - "Add a comic source in home page": "在主页添加一个漫画源", + "Please add some sources": "请添加一些源", "Please check your settings": "请检查您的设置", "No Category Pages": "没有分类页面", "Chapter @ep": "第 @ep 章", @@ -317,7 +317,8 @@ "Set comic source list url": "设置漫画源列表URL", "Deselect All": "取消全选", "Add keyword": "添加关键词", - "Keyword": "关键词" + "Keyword": "关键词", + "Manage": "管理" }, "zh_TW": { "Home": "首頁", @@ -549,7 +550,7 @@ "Clear History": "清除歷史", "Are you sure you want to clear your history?": "確定要清除您的歷史記錄嗎?", "No Explore Pages": "沒有探索頁面", - "Add a comic source in home page": "在主頁添加一個漫畫源", + "Please add some sources": "請添加一些源", "Please check your settings": "請檢查您的設定", "No Category Pages": "沒有分類頁面", "Chapter @ep": "第 @ep 章", @@ -637,6 +638,7 @@ "Set comic source list url": "設置漫畫源列表URL", "Deselect All": "取消全選", "Add keyword": "添加關鍵詞", - "Keyword": "關鍵詞" + "Keyword": "關鍵詞", + "Manage": "管理" } } \ No newline at end of file diff --git a/lib/components/loading.dart b/lib/components/loading.dart index 161bf8f..10f8224 100644 --- a/lib/components/loading.dart +++ b/lib/components/loading.dart @@ -6,6 +6,7 @@ class NetworkError extends StatelessWidget { required this.message, this.retry, this.withAppbar = true, + this.buttonText, }); final String message; @@ -14,6 +15,8 @@ class NetworkError extends StatelessWidget { final bool withAppbar; + final String? buttonText; + @override Widget build(BuildContext context) { var cfe = CloudflareException.fromString(message); @@ -60,7 +63,7 @@ class NetworkError extends StatelessWidget { else FilledButton( onPressed: retry, - child: Text('Retry'.tl), + child: Text(buttonText ?? 'Retry'.tl), ), ], ), diff --git a/lib/pages/categories_page.dart b/lib/pages/categories_page.dart index c47192f..78f46c3 100644 --- a/lib/pages/categories_page.dart +++ b/lib/pages/categories_page.dart @@ -10,6 +10,7 @@ import 'package:venera/utils/ext.dart'; import 'package:venera/utils/translations.dart'; import 'category_comics_page.dart'; +import 'comic_source_page.dart'; class CategoriesPage extends StatefulWidget { const CategoriesPage({super.key}); @@ -63,23 +64,31 @@ class _CategoriesPageState extends State { appdata.settings.removeListener(onSettingsChanged); } + Widget buildEmpty() { + var msg = "No Category Pages".tl; + msg += '\n'; + VoidCallback onTap; + if (ComicSource.isEmpty) { + msg += "Please add some sources".tl; + onTap = () { + context.to(() => ComicSourcePage()); + }; + } else { + msg += "Please check your settings".tl; + onTap = addPage; + } + return NetworkError( + message: msg, + retry: onTap, + withAppbar: false, + buttonText: "Manage".tl, + ); + } + @override Widget build(BuildContext context) { if (categories.isEmpty) { - var msg = "No Category Pages".tl; - msg += '\n'; - if (ComicSource.isEmpty) { - msg += "Add a comic source in home page".tl; - } else { - msg += "Please check your settings".tl; - } - return NetworkError( - message: msg, - retry: () { - setState(() {}); - }, - withAppbar: false, - ); + return buildEmpty(); } return Material( diff --git a/lib/pages/explore_page.dart b/lib/pages/explore_page.dart index 6821c6f..421be80 100644 --- a/lib/pages/explore_page.dart +++ b/lib/pages/explore_page.dart @@ -5,6 +5,7 @@ import 'package:venera/foundation/appdata.dart'; import 'package:venera/foundation/comic_source/comic_source.dart'; import 'package:venera/foundation/res.dart'; import 'package:venera/foundation/state_controller.dart'; +import 'package:venera/pages/comic_source_page.dart'; import 'package:venera/pages/search_result_page.dart'; import 'package:venera/pages/settings/settings_page.dart'; import 'package:venera/utils/ext.dart'; @@ -122,15 +123,21 @@ class _ExplorePageState extends State Widget buildEmpty() { var msg = "No Explore Pages".tl; msg += '\n'; + VoidCallback onTap; if (ComicSource.isEmpty) { - msg += "Add a comic source in home page".tl; + msg += "Please add some sources".tl; + onTap = () { + context.to(() => ComicSourcePage()); + }; } else { msg += "Please check your settings".tl; + onTap = addPage; } return NetworkError( message: msg, - retry: onSettingsChanged, + retry: onTap, withAppbar: false, + buttonText: "Manage".tl, ); }