Skip to content

Commit

Permalink
v4.3.3 support g-translate; UI optmize (#29)
Browse files Browse the repository at this point in the history
* v4.3.3 support g-translate; UI optmize

* remove useless import
  • Loading branch information
vito-go authored Nov 27, 2024
1 parent 2916bcc commit 21c7951
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 57 deletions.
Empty file.
37 changes: 13 additions & 24 deletions mywords-flutter/lib/pages/article_list_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -147,28 +146,18 @@ class _State extends State<ArticleListPage> 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,
),
);
}

Expand Down Expand Up @@ -209,7 +198,7 @@ class _State extends State<ArticleListPage> with AutomaticKeepAliveClientMixin {
onPressed: () {
pushTo(context, const ToadyKnownWords());
},
icon: const Icon(Icons.wordpress)),
icon: const Icon(Icons.local_library)),
title: RichText(
text: TextSpan(
// text: "今日学习单词总数: ",
Expand Down
24 changes: 18 additions & 6 deletions mywords-flutter/lib/pages/home.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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';
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';
Expand Down Expand Up @@ -53,7 +56,7 @@ class _State extends State<Home> {
const BottomNavigationBarItem(label: ("Tool"), icon: Icon(Icons.settings)),
];

Widget themeIconButton() {
Widget get themeIconButton {
return IconButton(
onPressed: () {
if (prefs.themeMode == ThemeMode.light) {
Expand Down Expand Up @@ -139,11 +142,20 @@ class _State extends State<Home> {
icon: const Icon(Icons.refresh));

List<Widget> get actions {
return [
refreshAllButton,
IconButton(onPressed: aboutOnTap, icon: const Icon(Icons.help_outline)),
themeIconButton(),
];
final List<Widget> 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(
Expand Down
8 changes: 6 additions & 2 deletions mywords-flutter/lib/pages/sources.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ class _State extends State<Sources> {
List<String> allSourcesFromDB = [];

Future<void> 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(() {});
}
Expand Down Expand Up @@ -72,7 +77,6 @@ class _State extends State<Sources> {
// SliverGridDelegateWithMaxCrossAxisExtent
// SliverGridDelegateWithFixedCrossAxisCount
Widget buildGridView() {
myPrint(MediaQuery.of(context).size.width);
return GridView.builder(
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 150, childAspectRatio: 1.15),
Expand Down
6 changes: 3 additions & 3 deletions mywords-flutter/lib/widgets/sources_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ class _State extends State<SourcesWebView> {
"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;
}
myToast(context, "success");
produceEvent(EventType.updateArticleList);
}());

},
),
];
Expand Down
30 changes: 14 additions & 16 deletions mywords-flutter/lib/widgets/tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -370,12 +369,22 @@ class MyToolState extends State<MyTool> with AutomaticKeepAliveClientMixin {
Widget build(BuildContext context) {
super.build(context);
myPrint("build MyTool");
final List<Widget> children = [];
// children.add(buildInfo());
children.addAll([
final List<Widget> 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"),
Expand Down Expand Up @@ -429,21 +438,11 @@ class MyToolState extends State<MyTool> 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());
}
Expand All @@ -463,7 +462,6 @@ class MyToolState extends State<MyTool> with AutomaticKeepAliveClientMixin {
},
));


return ListView(children: children);
}

Expand Down
16 changes: 12 additions & 4 deletions mywords-flutter/lib/widgets/translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion mywords-flutter/linux-deb/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: mywords
Version: 4.3.1
Version: 4.3.3
Section: Education
Priority: optional
Architecture: amd64
Expand Down
2 changes: 1 addition & 1 deletion mywords-flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 21c7951

Please sign in to comment.