From d72baf17750ac6ce8faa30fca772d02d03f55d50 Mon Sep 17 00:00:00 2001 From: oldchen <772565130@qq.com> Date: Thu, 25 Jul 2019 18:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=AE=8C=E6=88=90=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 2 +- android/my-release-key.jks | Bin 2301 -> 2539 bytes lib/config/custom_image_cache_manager.dart | 2 +- lib/config/floating_border.dart | 1 + lib/config/keys.dart | 1 + lib/i10n/localization_intl.dart | 6 ++ lib/i10n/messages_en_US.dart | 3 + lib/i10n/messages_zh_CN.dart | 3 + lib/logic/feedback_page_logic.dart | 1 - lib/logic/global_logic.dart | 6 ++ lib/logic/main_page_logic.dart | 34 +++++++++ lib/model/main_page_model.dart | 4 ++ lib/pages/image_page.dart | 2 +- lib/pages/main_page.dart | 36 +++++++--- lib/pages/setting_page.dart | 77 ++++++++------------- lib/widgets/edit_dialog.dart | 60 ++++++++++++++++ res/intl_en_US.arb | 18 +++++ res/intl_messages.arb | 20 +++++- res/intl_zh_CN.arb | 18 +++++ 19 files changed, 232 insertions(+), 62 deletions(-) create mode 100644 lib/widgets/edit_dialog.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index b74aadc..81c9fad 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -59,7 +59,7 @@ android { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. - signingConfig signingConfigs.debug + signingConfig signingConfigs.release } } } diff --git a/android/my-release-key.jks b/android/my-release-key.jks index 88ba47ea2d0b655ea7935cac774e0e5172e1a59c..e58cbb941dbadd5f2d2eee886f9f4478cd35e15f 100644 GIT binary patch literal 2539 zcmY+EcTf|E5{E+!K|%`fKR*P4c?HOD20>uX2QyzH-XtEdF)%UY z6PQy#1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FOHI>NUyFregk`bq1DYIBg;)3SJ1vRc^Q?cf>>?oq^PPyI z#Yek({|^P%WcvM?IKVrptQ50$ouK4`+0@|%dvReAvh&e~UsG>r9&GGvRd5^jj{Cbx z=jJm(jFFqMz5<2J6#FT7ClCcaZX%)}TAPv2UT Intl.message('Setting your username', name: 'customUserName', desc: '昵称设置',); + String get inputUserName => Intl.message('input your username', name: 'inputUserName', desc: '输入你的昵称吧',); + String get userNameCantBeNull => Intl.message('username can not be empty', name: 'userNameCantBeNull', desc: '昵称不能为空哦!',); + + + String get pink{ return Intl.message( 'pink', diff --git a/lib/i10n/messages_en_US.dart b/lib/i10n/messages_en_US.dart index d72dd63..1e9bb6b 100644 --- a/lib/i10n/messages_en_US.dart +++ b/lib/i10n/messages_en_US.dart @@ -55,6 +55,7 @@ class MessageLookup extends MessageLookupByLibrary { "currentIcons" : MessageLookupByLibrary.simpleMessage("Current Icons"), "customIcon" : MessageLookupByLibrary.simpleMessage("Custom Icon"), "customTheme" : MessageLookupByLibrary.simpleMessage("Custom Theme"), + "customUserName" : MessageLookupByLibrary.simpleMessage("Setting your username"), "cyan" : MessageLookupByLibrary.simpleMessage("cyan"), "dailyPic" : MessageLookupByLibrary.simpleMessage("Daily wallpaper"), "dark" : MessageLookupByLibrary.simpleMessage("dark"), @@ -80,6 +81,7 @@ class MessageLookup extends MessageLookupByLibrary { "hours" : m1, "iconSetting" : MessageLookupByLibrary.simpleMessage("Icon Setting"), "inputCurrentCity" : MessageLookupByLibrary.simpleMessage("input your city"), + "inputUserName" : MessageLookupByLibrary.simpleMessage("input your username"), "itemNumber" : m2, "languageTitle" : MessageLookupByLibrary.simpleMessage("Change Language"), "loading" : MessageLookupByLibrary.simpleMessage("loading..."), @@ -118,6 +120,7 @@ class MessageLookup extends MessageLookupByLibrary { "travel" : MessageLookupByLibrary.simpleMessage("Travel"), "tryToSearch" : MessageLookupByLibrary.simpleMessage("Try searching for the title or content"), "unknownDes" : MessageLookupByLibrary.simpleMessage("Unknown permission"), + "userNameCantBeNull" : MessageLookupByLibrary.simpleMessage("username can not be empty"), "versionDescription" : MessageLookupByLibrary.simpleMessage("Version Description"), "waitAMoment" : MessageLookupByLibrary.simpleMessage("please wait for a moment..."), "weatherGetWrong" : MessageLookupByLibrary.simpleMessage("failed to get the weather,please try again"), diff --git a/lib/i10n/messages_zh_CN.dart b/lib/i10n/messages_zh_CN.dart index 6c42ba4..c248d78 100644 --- a/lib/i10n/messages_zh_CN.dart +++ b/lib/i10n/messages_zh_CN.dart @@ -55,6 +55,7 @@ class MessageLookup extends MessageLookupByLibrary { "currentIcons" : MessageLookupByLibrary.simpleMessage("当前图标"), "customIcon" : MessageLookupByLibrary.simpleMessage("自定义图标"), "customTheme" : MessageLookupByLibrary.simpleMessage("自定义主题"), + "customUserName" : MessageLookupByLibrary.simpleMessage("昵称设置"), "cyan" : MessageLookupByLibrary.simpleMessage("蓝天白云"), "dailyPic" : MessageLookupByLibrary.simpleMessage("每日壁纸"), "dark" : MessageLookupByLibrary.simpleMessage("不见五指"), @@ -80,6 +81,7 @@ class MessageLookup extends MessageLookupByLibrary { "hours" : m1, "iconSetting" : MessageLookupByLibrary.simpleMessage("图标设置"), "inputCurrentCity" : MessageLookupByLibrary.simpleMessage("手动输入你的城市"), + "inputUserName" : MessageLookupByLibrary.simpleMessage("输入你的昵称吧"), "itemNumber" : m2, "languageTitle" : MessageLookupByLibrary.simpleMessage("切换语言"), "loading" : MessageLookupByLibrary.simpleMessage("加载中..."), @@ -118,6 +120,7 @@ class MessageLookup extends MessageLookupByLibrary { "travel" : MessageLookupByLibrary.simpleMessage("旅行"), "tryToSearch" : MessageLookupByLibrary.simpleMessage("试试搜一下标题、内容吧"), "unknownDes" : MessageLookupByLibrary.simpleMessage("未知权限"), + "userNameCantBeNull" : MessageLookupByLibrary.simpleMessage("昵称不能为空哦!"), "versionDescription" : MessageLookupByLibrary.simpleMessage("版本描述"), "waitAMoment" : MessageLookupByLibrary.simpleMessage("请稍后..."), "weatherGetWrong" : MessageLookupByLibrary.simpleMessage("天气获取失败,请重新尝试"), diff --git a/lib/logic/feedback_page_logic.dart b/lib/logic/feedback_page_logic.dart index 7b3299f..67b77e5 100644 --- a/lib/logic/feedback_page_logic.dart +++ b/lib/logic/feedback_page_logic.dart @@ -4,7 +4,6 @@ import 'package:todo_list/config/api_service.dart'; import 'package:todo_list/i10n/localization_intl.dart'; import 'package:todo_list/json/common_bean.dart'; import 'package:todo_list/model/all_model.dart'; -import 'package:todo_list/utils/full_screen_dialog_util.dart'; import 'package:todo_list/utils/shared_util.dart'; import 'package:todo_list/widgets/net_loading_widget.dart'; diff --git a/lib/logic/global_logic.dart b/lib/logic/global_logic.dart index f2958ca..7e9190c 100644 --- a/lib/logic/global_logic.dart +++ b/lib/logic/global_logic.dart @@ -41,6 +41,12 @@ class GlobalLogic{ return themeType == MyTheme.darkTheme ? Colors.grey[800] : Theme.of(context).primaryColor; } + //当为夜间模式时候,黑色替换为白色 + Color getbwInDark(){ + final themeType = _model.currentThemeBean.themeType; + return themeType == MyTheme.darkTheme ? Colors.white : Colors.black; + } + Future getCurrentLanguageCode() async{ final list = await SharedUtil.instance.getStringList(Keys.currentLanguageCode); if (list == null) return; diff --git a/lib/logic/main_page_logic.dart b/lib/logic/main_page_logic.dart index b652d52..2cadf38 100644 --- a/lib/logic/main_page_logic.dart +++ b/lib/logic/main_page_logic.dart @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:todo_list/config/provider_config.dart'; import 'package:todo_list/database/database.dart'; +import 'package:todo_list/i10n/localization_intl.dart'; import 'package:todo_list/items/task_item.dart'; import 'package:todo_list/json/color_bean.dart'; import 'package:todo_list/json/task_bean.dart'; @@ -13,6 +14,7 @@ import 'package:todo_list/pages/search_page.dart'; import 'package:todo_list/utils/file_util.dart'; import 'package:todo_list/utils/shared_util.dart'; import 'package:todo_list/utils/theme_util.dart'; +import 'package:todo_list/widgets/edit_dialog.dart'; import 'package:todo_list/widgets/scale_animation_widget.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -72,6 +74,13 @@ class MainPageLogic { _model.tasks.addAll(tasks); } + Future getCurrentUserName() async{ + final currentUserName = await SharedUtil.instance.getString(Keys.currentUserName); + if (currentUserName == null) return; + if (currentUserName == _model.currentUserName) return; + _model.currentUserName = currentUserName; + } + Decoration getBackground(GlobalModel globalModel) { bool isBgGradient = globalModel.isBgGradient; bool isBgChangeWithCard = globalModel.isBgChangeWithCard; @@ -219,6 +228,31 @@ class MainPageLogic { })); } + void onUserNameTap(){ + final context = _model.context; + showDialog(context: context, builder: (ctx){ + return EditDialog( + title: DemoLocalizations.of(context).customUserName, + hintText: DemoLocalizations.of(context).inputUserName, + onValueChanged: (text){ + _model.currentUserName = text; + }, + initialValue: _model.currentUserName, + onSure: (){ + if(_model.currentUserName.isEmpty){ + showDialog(context: context, builder: (ctx){ + return AlertDialog(content: Text(DemoLocalizations.of(context).userNameCantBeNull),); + }); + return; + } + SharedUtil.instance.saveString(Keys.currentUserName, _model.currentUserName); + _model.refresh(); + }, + + ); + }); + } + void onSearchTap(){ Navigator.of(_model.context).push(new CupertinoPageRoute(builder: (ctx){ return ProviderConfig.getInstance().getSearchPage(); diff --git a/lib/model/main_page_model.dart b/lib/model/main_page_model.dart index f362107..42eadbf 100644 --- a/lib/model/main_page_model.dart +++ b/lib/model/main_page_model.dart @@ -21,6 +21,9 @@ class MainPageModel extends ChangeNotifier { //当前的头像url,比如本地的就是本地路径,网络就是网络地址 String currentAvatarUrl = "images/icon.png"; + //当前的用户名 + String currentUserName = ""; + //是否开启天气 bool enableWeatherShow = false; @@ -39,6 +42,7 @@ class MainPageModel extends ChangeNotifier { [ logic.getTasks(), logic.getCurrentAvatar(), + logic.getCurrentUserName(), ], ).then((value) { refresh(); diff --git a/lib/pages/image_page.dart b/lib/pages/image_page.dart index f0ad39e..76828a2 100644 --- a/lib/pages/image_page.dart +++ b/lib/pages/image_page.dart @@ -63,7 +63,7 @@ class _ImagePageState extends State { builder: (BuildContext context, int index) { final url = widget.imageUrls[index]; return PhotoViewGalleryPageOptions( - imageProvider: url == NavHeadType.dailyPicUrl ? Image.network(url) : CachedNetworkImageProvider(url), + imageProvider: url == NavHeadType.dailyPicUrl ? NetworkImage(url) : CachedNetworkImageProvider(url), initialScale: PhotoViewComputedScale.contained, heroTag: "tag_${index}", ); diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index 2a56c11..8e46ecc 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -82,11 +82,30 @@ class MainPage extends StatelessWidget { margin: EdgeInsets.fromLTRB(50, 0, 50, 0), child: Container( margin: EdgeInsets.only(top: 20, left: 12), - child: Text( - "${DemoLocalizations.of(context).welcomeWord}Old Li.", - style: TextStyle( - fontSize: 30, - color: globalModel.logic.getWhiteInDark()), + child: SingleChildScrollView( + child: Row( + children: [ + Flexible( + child: InkWell( + onTap: model.currentUserName.isEmpty ? null : model.logic.onUserNameTap, + child: Text( + "${DemoLocalizations.of(context).welcomeWord}${model.currentUserName}", + style: TextStyle( + fontSize: 30, + color: globalModel.logic.getWhiteInDark()), + maxLines: 3, + overflow: TextOverflow.ellipsis, + ), + ), + ), + model.currentUserName.isEmpty + ? IconButton( + icon: Icon(Icons.account_circle, color: globalModel.logic.getWhiteInDark(),), + onPressed: model.logic.onUserNameTap, + ) + : SizedBox() + ], + ), ), ), ), @@ -105,12 +124,13 @@ class MainPage extends StatelessWidget { model.tasks.length == 0 ? model.logic.getEmptyWidget(globalModel) : Container( - margin: EdgeInsets.only(top: 40,bottom: 40), + margin: EdgeInsets.only(top: 40, bottom: 40), child: CarouselSlider( items: model.logic.getCards(context), - aspectRatio: 16 / 9, + aspectRatio: 16 / 9, height: min(size.width, size.height) - 100, - viewportFraction: size.height >= size.width ? 0.8 : 0.5, + viewportFraction: + size.height >= size.width ? 0.8 : 0.5, initialPage: 0, enableInfiniteScroll: model.tasks.length >= 3 && globalModel.enableInfiniteScroll, diff --git a/lib/pages/setting_page.dart b/lib/pages/setting_page.dart index c27d943..641cb1a 100644 --- a/lib/pages/setting_page.dart +++ b/lib/pages/setting_page.dart @@ -9,6 +9,7 @@ import 'package:todo_list/i10n/localization_intl.dart'; import 'package:todo_list/model/global_model.dart'; import 'package:todo_list/utils/permission_request_util.dart'; import 'package:todo_list/utils/shared_util.dart'; +import 'package:todo_list/widgets/edit_dialog.dart'; import 'package:todo_list/widgets/net_loading_widget.dart'; import 'all_page.dart'; @@ -154,55 +155,33 @@ class SettingPage extends StatelessWidget { showDialog( context: context, builder: (context) { - return AlertDialog( - title: Text(DemoLocalizations.of(context).enableWeatherShow), - content: Form( - autovalidate: true, - child: TextFormField( - initialValue: globalModel.currentPosition, - validator: (text){ - globalModel.currentPosition = text; - }, - decoration: InputDecoration( - hintText: DemoLocalizations.of(context).inputCurrentCity, - ), - ), - ), - actions: [ - FlatButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text( - DemoLocalizations.of(context).cancel, - style: TextStyle(color: Colors.redAccent), - ), - ), - FlatButton( - onPressed: () { - if(globalModel.currentPosition.isEmpty) return; - CancelToken cancelToken = CancelToken(); - showDialog(context: context, builder: (ctx){ - return NetLoadingWidget( - onRequest: (){ - globalModel.logic.getWeatherNow(globalModel.currentPosition,controller: globalModel.loadingController); - }, - cancelToken: cancelToken, - errorText: DemoLocalizations.of(context).weatherGetWrong, - loadingText: DemoLocalizations.of(context).weatherGetting, - successText: DemoLocalizations.of(context).weatherSuccess, - onSuccess: (){ - Navigator.of(context).pop(); - Navigator.of(context).pop(); - }, - loadingController: globalModel.loadingController, - ); - }); - }, - child: Text(DemoLocalizations.of(context).ok, - style: TextStyle(color: Colors.greenAccent)), - ), - ], + return EditDialog( + title: DemoLocalizations.of(context).enableWeatherShow, + hintText: DemoLocalizations.of(context).inputCurrentCity, + initialValue: globalModel.currentPosition, + onValueChanged: (text){ + globalModel.currentPosition = text; + }, + sureTextStyle: TextStyle(color: globalModel.logic.getbwInDark()), + onSure: (){ + if(globalModel.currentPosition.isEmpty) return; + CancelToken cancelToken = CancelToken(); + showDialog(context: context, builder: (ctx){ + return NetLoadingWidget( + onRequest: (){ + globalModel.logic.getWeatherNow(globalModel.currentPosition,controller: globalModel.loadingController); + }, + cancelToken: cancelToken, + errorText: DemoLocalizations.of(context).weatherGetWrong, + loadingText: DemoLocalizations.of(context).weatherGetting, + successText: DemoLocalizations.of(context).weatherSuccess, + onSuccess: (){ + Navigator.of(context).pop(); + }, + loadingController: globalModel.loadingController, + ); + }); + }, ); },); } else { diff --git a/lib/widgets/edit_dialog.dart b/lib/widgets/edit_dialog.dart new file mode 100644 index 0000000..a08cf01 --- /dev/null +++ b/lib/widgets/edit_dialog.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; +import 'package:todo_list/i10n/localization_intl.dart'; + +class EditDialog extends StatelessWidget { + final VoidCallback onSure; + final String title; + final String hintText; + final String initialValue; + final ValueChanged onValueChanged; + final TextStyle cancelTextStyle; + final TextStyle sureTextStyle; + + const EditDialog({ + Key key, + this.onSure, + this.title, + this.hintText, + this.initialValue, this.onValueChanged, this.cancelTextStyle, this.sureTextStyle, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: Text(title ?? ""), + content: Form( + autovalidate: true, + child: TextFormField( + initialValue: initialValue ?? "", + validator: (text){ + if(onValueChanged != null) + onValueChanged(text); + }, + decoration: InputDecoration( + hintText: hintText ?? "", + ), + ), + ), + actions: [ + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text( + DemoLocalizations.of(context).cancel, + style:cancelTextStyle ?? TextStyle(color: Colors.redAccent), + ), + ), + FlatButton( + onPressed: (){ + if(onSure != null) onSure(); + Navigator.pop(context); + + }, + child: Text(DemoLocalizations.of(context).ok, + style:sureTextStyle ?? TextStyle(color: Colors.black)), + ), + ], + ); + } +} diff --git a/res/intl_en_US.arb b/res/intl_en_US.arb index 2b793a9..0b9d197 100644 --- a/res/intl_en_US.arb +++ b/res/intl_en_US.arb @@ -543,6 +543,24 @@ "type": "text", "placeholders": {} }, + "customUserName": "Setting your username", + "@customUserName": { + "description": "昵称设置", + "type": "text", + "placeholders": {} + }, + "inputUserName": "input your username", + "@inputUserName": { + "description": "输入你的昵称吧", + "type": "text", + "placeholders": {} + }, + "userNameCantBeNull": "username can not be empty", + "@userNameCantBeNull": { + "description": "昵称不能为空哦!", + "type": "text", + "placeholders": {} + }, "taskItems": "{taskNumbers,plural, =0{You have never written a list of tasks.\nLet''s get started soon.}=1{This is your todo-list,\nToday, you have 1 task to complete. }many{This is your todo-list,\nToday, you have {taskNumbers} tasks to complete. }other{This is your todo-list,\nToday, you have {taskNumbers} tasks to complete. }}", "@taskItems": { "type": "text", diff --git a/res/intl_messages.arb b/res/intl_messages.arb index a9711fe..79eacf2 100644 --- a/res/intl_messages.arb +++ b/res/intl_messages.arb @@ -1,5 +1,5 @@ { - "@@last_modified": "2019-07-25T11:08:23.468694", + "@@last_modified": "2019-07-25T17:55:44.478744", "appName": "One Day List", "@appName": { "description": "app的名字", @@ -440,6 +440,24 @@ "type": "text", "placeholders": {} }, + "customUserName": "Setting your username", + "@customUserName": { + "description": "昵称设置", + "type": "text", + "placeholders": {} + }, + "inputUserName": "input your username", + "@inputUserName": { + "description": "输入你的昵称吧", + "type": "text", + "placeholders": {} + }, + "userNameCantBeNull": "username can not be empty", + "@userNameCantBeNull": { + "description": "昵称不能为空哦!", + "type": "text", + "placeholders": {} + }, "pink": "pink", "@pink": { "description": "主题颜色", diff --git a/res/intl_zh_CN.arb b/res/intl_zh_CN.arb index aa01675..540ce48 100644 --- a/res/intl_zh_CN.arb +++ b/res/intl_zh_CN.arb @@ -542,6 +542,24 @@ "type": "text", "placeholders": {} }, + "customUserName": "昵称设置", + "@customUserName": { + "description": "昵称设置", + "type": "text", + "placeholders": {} + }, + "inputUserName": "输入你的昵称吧", + "@inputUserName": { + "description": "输入你的昵称吧", + "type": "text", + "placeholders": {} + }, + "userNameCantBeNull": "昵称不能为空哦!", + "@userNameCantBeNull": { + "description": "昵称不能为空哦!", + "type": "text", + "placeholders": {} + }, "taskItems": "{taskNumbers,plural, =0{你还没有写过任务清单呢.\n快快开始吧.}=1{下面你的任务清单,\n今天, 你有 1 项任务尚未完成. }many{下面是你的任务清单,\n今天, 你有 {taskNumbers} 份任务尚未完成. }other{下面是你的任务清单,\n今天, 你有 {taskNumbers} 份任务尚未完成. }}", "@taskItems": { "type": "text",