From 21c795153e91f8825d4d51fa007171c87aa01c34 Mon Sep 17 00:00:00 2001 From: Vito <56462631+vito-go@users.noreply.github.com> Date: Wed, 27 Nov 2024 15:34:59 +0800 Subject: [PATCH] v4.3.3 support g-translate; UI optmize (#29) * v4.3.3 support g-translate; UI optmize * remove useless import --- ...otlin-compiler-12494452778444265579.salive | 0 .../lib/pages/article_list_page.dart | 37 +++++++------------ mywords-flutter/lib/pages/home.dart | 24 +++++++++--- mywords-flutter/lib/pages/sources.dart | 8 +++- .../lib/widgets/sources_native.dart | 6 +-- mywords-flutter/lib/widgets/tool.dart | 30 +++++++-------- mywords-flutter/lib/widgets/translator.dart | 16 ++++++-- mywords-flutter/linux-deb/DEBIAN/control | 2 +- mywords-flutter/pubspec.yaml | 2 +- 9 files changed, 68 insertions(+), 57 deletions(-) delete mode 100644 mywords-flutter/android/.kotlin/sessions/kotlin-compiler-12494452778444265579.salive diff --git a/mywords-flutter/android/.kotlin/sessions/kotlin-compiler-12494452778444265579.salive b/mywords-flutter/android/.kotlin/sessions/kotlin-compiler-12494452778444265579.salive deleted file mode 100644 index e69de29..0000000 diff --git a/mywords-flutter/lib/pages/article_list_page.dart b/mywords-flutter/lib/pages/article_list_page.dart index 5617498..eb40211 100644 --- a/mywords-flutter/lib/pages/article_list_page.dart +++ b/mywords-flutter/lib/pages/article_list_page.dart @@ -5,7 +5,6 @@ import 'package:flutter/material.dart'; import 'package:mywords/libso/handler.dart'; import 'package:mywords/pages/article_page.dart'; -import 'package:mywords/pages/sources.dart'; import 'package:mywords/pages/statistic_chart.dart'; import 'package:mywords/pages/today_known_words.dart'; import 'package:mywords/util/navigator.dart'; @@ -147,28 +146,18 @@ class _State extends State with AutomaticKeepAliveClientMixin { controller: controller, focusNode: focus, decoration: InputDecoration( - // hintText: "请输入一个英语文章页面网址", - hintText: "Please enter a web page URL", - prefixIcon: IconButton( - onPressed: () { - controller.text = ''; - }, - icon: const Icon( - Icons.clear, - color: Colors.red, - )), - suffixIcon: Row( - mainAxisSize: MainAxisSize.min, - children: [ - searchIcon, - IconButton( - icon: const Icon(Icons.web), - onPressed: () { - pushTo(context, Sources()); - }, - ), - ], - )), + // hintText: "请输入一个英语文章页面网址", + hintText: "Please enter a web page URL", + prefixIcon: IconButton( + onPressed: () { + controller.text = ''; + }, + icon: const Icon( + Icons.clear, + color: Colors.red, + )), + suffixIcon: searchIcon, + ), ); } @@ -209,7 +198,7 @@ class _State extends State with AutomaticKeepAliveClientMixin { onPressed: () { pushTo(context, const ToadyKnownWords()); }, - icon: const Icon(Icons.wordpress)), + icon: const Icon(Icons.local_library)), title: RichText( text: TextSpan( // text: "今日学习单词总数: ", diff --git a/mywords-flutter/lib/pages/home.dart b/mywords-flutter/lib/pages/home.dart index 1fd10a0..f90daf7 100644 --- a/mywords-flutter/lib/pages/home.dart +++ b/mywords-flutter/lib/pages/home.dart @@ -1,6 +1,8 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:mywords/common/prefs/prefs.dart'; import 'package:mywords/common/queue.dart'; +import 'package:mywords/pages/sources.dart'; import 'package:mywords/util/get_scaffold.dart'; import 'package:mywords/util/util_native.dart' if (dart.library.html) 'package:mywords/util/util_web.dart'; @@ -8,6 +10,7 @@ import 'package:mywords/widgets/tool.dart'; import 'package:url_launcher/url_launcher_string.dart'; import '../common/global.dart'; import '../libso/handler.dart'; +import '../util/navigator.dart'; import '../util/util.dart'; import 'article_list_page.dart'; import 'lookup_word.dart'; @@ -53,7 +56,7 @@ class _State extends State { const BottomNavigationBarItem(label: ("Tool"), icon: Icon(Icons.settings)), ]; - Widget themeIconButton() { + Widget get themeIconButton { return IconButton( onPressed: () { if (prefs.themeMode == ThemeMode.light) { @@ -139,11 +142,20 @@ class _State extends State { icon: const Icon(Icons.refresh)); List get actions { - return [ - refreshAllButton, - IconButton(onPressed: aboutOnTap, icon: const Icon(Icons.help_outline)), - themeIconButton(), - ]; + final List result = []; + if (platformIsMobileClient()) { + result.add(IconButton( + icon: const Icon(Icons.web), + onPressed: () { + pushTo(context, Sources()); + }, + )); + } + result.add(refreshAllButton); + result.add(IconButton( + onPressed: aboutOnTap, icon: const Icon(Icons.help_outline))); + result.add(themeIconButton); + return result; } BottomNavigationBar get bottomBar => BottomNavigationBar( diff --git a/mywords-flutter/lib/pages/sources.dart b/mywords-flutter/lib/pages/sources.dart index b0572de..c46f503 100644 --- a/mywords-flutter/lib/pages/sources.dart +++ b/mywords-flutter/lib/pages/sources.dart @@ -25,8 +25,13 @@ class _State extends State { List allSourcesFromDB = []; Future updateSources() async { - sourceURLs = await handler.getAllSources(); + // sourceURLs = await handler.getAllSources(); allSourcesFromDB = await handler.allSourcesFromDB(); + setState(() {}); + sourceURLs = await compute((_) async { + return await handler.getAllSources(); + }, null); + // allSourcesFromDB = await handler.allSourcesFromDB(); init = true; setState(() {}); } @@ -72,7 +77,6 @@ class _State extends State { // SliverGridDelegateWithMaxCrossAxisExtent // SliverGridDelegateWithFixedCrossAxisCount Widget buildGridView() { - myPrint(MediaQuery.of(context).size.width); return GridView.builder( gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( maxCrossAxisExtent: 150, childAspectRatio: 1.15), diff --git a/mywords-flutter/lib/widgets/sources_native.dart b/mywords-flutter/lib/widgets/sources_native.dart index 6b0aeef..92088c1 100644 --- a/mywords-flutter/lib/widgets/sources_native.dart +++ b/mywords-flutter/lib/widgets/sources_native.dart @@ -148,9 +148,10 @@ class _State extends State { "You have already parsed this URL\n$url\n${fInfo.title}"); return; } - blockShowDialog(context, ()async{ + blockShowDialog(context, () async { // newArticleFileInfoBySourceURL - final respData = await compute(handler.newArticleFileInfoBySourceURL, url); + final respData = + await compute(handler.newArticleFileInfoBySourceURL, url); if (respData.code != 0) { myToast(context, respData.message); return; @@ -158,7 +159,6 @@ class _State extends State { myToast(context, "success"); produceEvent(EventType.updateArticleList); }()); - }, ), ]; diff --git a/mywords-flutter/lib/widgets/tool.dart b/mywords-flutter/lib/widgets/tool.dart index 78a0f69..6e85166 100644 --- a/mywords-flutter/lib/widgets/tool.dart +++ b/mywords-flutter/lib/widgets/tool.dart @@ -12,7 +12,6 @@ import 'package:mywords/pages/known_words.dart'; import 'package:mywords/pages/proxy.dart'; import 'package:mywords/pages/statistic_chart.dart'; import 'package:mywords/util/navigator.dart'; -import 'package:mywords/util/util_native.dart'; import 'package:mywords/widgets/private_ip.dart'; import 'package:url_launcher/url_launcher_string.dart'; @@ -370,12 +369,22 @@ class MyToolState extends State with AutomaticKeepAliveClientMixin { Widget build(BuildContext context) { super.build(context); myPrint("build MyTool"); - final List children = []; - // children.add(buildInfo()); - children.addAll([ + final List children = [ header, const Divider(), + ]; + if (platformIsMobileClient()) { + children.add(ListTile( + title: const Text("Sources"), + leading: const Icon(Icons.web), + trailing: const Icon(Icons.navigate_next), + onTap: () { + pushTo(context, const Sources()); + }, + )); + } + children.addAll([ ListTile( // title: const Text("学习统计"), title: const Text("Learning Statistics"), @@ -429,21 +438,11 @@ class MyToolState extends State with AutomaticKeepAliveClientMixin { ), // buildListTileVacuumDB(), ]); - if (platformIsMobileClient()){ - children.add(ListTile( - title: const Text("Sources"), - leading: const Icon(Icons.web), - trailing: const Icon(Icons.navigate_next), - onTap: () { - pushTo(context, const Sources()); - }, - )); - } if (!kIsWeb) { children.add(webOnlineListTile); } - children.add(const PrivateIP()); + // children.add(const PrivateIP()); if (false) { children.add(buildListTileRestoreFromOld()); } @@ -463,7 +462,6 @@ class MyToolState extends State with AutomaticKeepAliveClientMixin { }, )); - return ListView(children: children); } diff --git a/mywords-flutter/lib/widgets/translator.dart b/mywords-flutter/lib/widgets/translator.dart index 917402e..7b8d9a1 100644 --- a/mywords-flutter/lib/widgets/translator.dart +++ b/mywords-flutter/lib/widgets/translator.dart @@ -4,6 +4,7 @@ import 'package:mywords/common/prefs/prefs.dart'; import 'package:mywords/util/util.dart'; import 'package:mywords/util/util_native.dart' if (dart.library.html) 'package:mywords/util/util_web.dart'; +import 'package:url_launcher/url_launcher_string.dart'; import '../libso/handler.dart'; import '../libso/types.dart'; @@ -52,7 +53,8 @@ void showTranslation(BuildContext context, String text) async { children: [ Flexible(child: original), const Divider(), - Flexible(child: Row( + Flexible( + child: Row( children: [ Icon( Icons.error, @@ -78,9 +80,12 @@ void showTranslation(BuildContext context, String text) async { children: [ original, const Divider(), - Flexible(child: Row( + Flexible( + child: Row( children: [ - Flexible(child: SingleChildScrollView(child: SelectableText(translation.result))), + Flexible( + child: SingleChildScrollView( + child: SelectableText(translation.result))), IconButton( onPressed: () { copyToClipBoard(context, translation.result); @@ -115,7 +120,10 @@ WidgetSpan buildTranslateWidgetSpan(BuildContext context, String text) { child: Icon(Icons.g_translate, color: prefs.isDark ? null : Theme.of(context).primaryColor), onTap: () { - showTranslation(context, text); + final url = Uri.encodeFull( + 'https://translate.google.com/?sl=auto&tl=zh-CN&text=$text'); + launchUrlString(url); + // showTranslation(context, text); }, )); return trans; diff --git a/mywords-flutter/linux-deb/DEBIAN/control b/mywords-flutter/linux-deb/DEBIAN/control index d96cd28..7746e15 100644 --- a/mywords-flutter/linux-deb/DEBIAN/control +++ b/mywords-flutter/linux-deb/DEBIAN/control @@ -1,5 +1,5 @@ Package: mywords -Version: 4.3.1 +Version: 4.3.3 Section: Education Priority: optional Architecture: amd64 diff --git a/mywords-flutter/pubspec.yaml b/mywords-flutter/pubspec.yaml index c8f940d..4c85cfc 100644 --- a/mywords-flutter/pubspec.yaml +++ b/mywords-flutter/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. # version number is versionName; build number is versionCode; -version: 4.3.2+4 +version: 4.3.3+4 environment: sdk: '>=3.2.3 <4.0.0'