From 807a0f9a7ac1b86c10d53102495585045dc6d1db Mon Sep 17 00:00:00 2001 From: "Rocky.Zhang" <122086517@qq.com> Date: Mon, 23 Sep 2019 18:27:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=B7=9F=E9=9A=8F=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E6=9A=97=E9=BB=91=E6=A8=A1=E5=BC=8F=20=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=E5=88=B00.1.7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 8 ++ README.md | 11 ++- lib/generated/i18n.dart | 17 +++- lib/main.dart | 4 +- lib/ui/page/tab/user_page.dart | 26 ++++-- lib/ui/widget/app_update.dart | 150 ++++++++++++++++---------------- lib/view_model/theme_model.dart | 52 +++++------ pubspec.yaml | 2 +- res/values/strings_en.arb | 9 +- res/values/strings_zh_CN.arb | 7 +- 10 files changed, 162 insertions(+), 124 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 573cef1..d82694a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ # 最近更新 +## V0.1.7 `2019-09-23` + +- DarkMode自动跟随系统设置 +- App更新UI调整 +- 适配Dio3.0版本 +- pull_to_refresh更新:加入国际化 + + ## V0.1.6 `2019-09-20` - 修复收藏列表进入详情时,页面报错的bug diff --git a/README.md b/README.md index acff0ee..734fd40 100644 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ Language: [English](https://github.com/phoenixsky/fun_android_flutter/blob/maste # 下载地址: * Android: - * [国内云](http://app.cdn.meetingplus.cn/FunAndroid_0.1.6.apk) | [Github DownLoad](https://github.com/phoenixsky/fun_android_flutter/releases) + * [国内云](http://app.cdn.meetingplus.cn/FunAndroid_0.1.7.apk) | [Github DownLoad](https://github.com/phoenixsky/fun_android_flutter/releases) - ![二维码](https://qr.api.cli.im/qr?data=http%3A%2F%2Fqr61.cn%2Fodempq%2FquS5fYM&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=2&logourl=http%3A%2F%2Falicliimg.clewm.net%2F020%2F802%2F5802020%2F1566638421597ff5250edab885fcb669e8344a12f03ea1566638376.png&size=260&kid=bizcliim&time=1568947308&key=1ef7092d2d39ddcb84bdb8460fe11e7d) + ![二维码](https://qr.api.cli.im/qr?data=http%3A%2F%2Fqr61.cn%2Fodempq%2FquS5fYM&level=H&transparent=false&bgcolor=%23ffffff&forecolor=%23000000&blockpixel=12&marginblock=2&logourl=http%3A%2F%2Falicliimg.clewm.net%2F020%2F802%2F5802020%2F1566638421597ff5250edab885fcb669e8344a12f03ea1566638376.png&size=260&kid=cliim&time=1569234435&key=0636728dfe3f111dc7074c2b44a1d8d4) * iOS: @@ -53,6 +53,13 @@ Language: [English](https://github.com/phoenixsky/fun_android_flutter/blob/maste # 更新 +## V0.1.7 `2019-09-23` + +- DarkMode自动跟随系统设置 +- App更新组件调整 +- 适配Dio3.0版本 +- pull_to_refresh更新:加入国际化 + ## V0.1.6 `2019-09-20` - 修复收藏列表进入详情时,页面报错的bug diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 8bf5c79..c41f259 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -30,9 +30,12 @@ class S implements WidgetsLocalizations { String get appUpdateActionInstallApk => "Install"; String get appUpdateActionUpdate => "Update"; String get appUpdateCheckUpdate => "Check Update"; - String get appUpdateDownloading => "downloading..."; + String get appUpdateDoubleBackTips => "Press back again, cancel download"; + String get appUpdateDownloadCanceled => "Download canceled"; + String get appUpdateDownloadFailed => "Download failed"; + String get appUpdateDownloading => "Downloading..."; String get appUpdateLeastVersion => "Least version now "; - String get appUpdateReDownloadContent => "It has been detected that it has been downloaded, whether it is installed"; + String get appUpdateReDownloadContent => "It has been detected that it has been downloaded, whether it is installed?"; String get appUpdateUpdate => "Version Update"; String get article_tag_top => "Top"; String get autoBySystem => "Auto"; @@ -142,13 +145,17 @@ class $zh_CN extends S { @override String get viewStateButtonRefresh => "刷新一下"; @override + String get appUpdateDoubleBackTips => "再次点击返回键,取消下载"; + @override String get loadFailed => "加载失败,请稍后重试"; @override String get refreshTwoLevel => "欢迎光临,我的空中楼阁"; @override String get article_tag_top => "置顶"; @override - String get appUpdateReDownloadContent => "检测到本地已下载过该版本,是否直接安装"; + String get appUpdateDownloadFailed => "下载失败"; + @override + String get appUpdateReDownloadContent => "检测到本地已下载过该版本,是否直接安装?"; @override String get noAccount => "还没账号? "; @override @@ -212,6 +219,8 @@ class $zh_CN extends S { @override String get userName => "用户名"; @override + String get appUpdateDownloadCanceled => "下载已取消"; + @override String get tabHome => "首页"; @override String get tabProject => "项目"; @@ -230,7 +239,7 @@ class $zh_CN extends S { @override String get searchHistory => "历史搜索"; @override - String appUpdateFoundNewVersion(String version) => "发现新版本$version,是否更新"; + String appUpdateFoundNewVersion(String version) => "发现新版本$version,是否更新?"; } class GeneratedLocalizationsDelegate extends LocalizationsDelegate { diff --git a/lib/main.dart b/lib/main.dart index d073f54..95a03fa 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -37,8 +37,8 @@ class App extends StatelessWidget { hideFooterWhenNotFull: true, //列表数据不满一页,不触发加载更多 child: MaterialApp( debugShowCheckedModeBanner: false, - theme: themeModel.themeData, - darkTheme: themeModel.darkTheme, + theme: themeModel.themeData(), + darkTheme: themeModel.themeData(platformDarkMode:true), locale: localeModel.locale, localizationsDelegates: const [ S.delegate, diff --git a/lib/ui/page/tab/user_page.dart b/lib/ui/page/tab/user_page.dart index 9adaea0..2526ba7 100644 --- a/lib/ui/page/tab/user_page.dart +++ b/lib/ui/page/tab/user_page.dart @@ -6,6 +6,7 @@ import 'package:fun_android/generated/i18n.dart'; import 'package:fun_android/ui/page/change_log_page.dart'; import 'package:fun_android/ui/widget/app_bar.dart'; import 'package:fun_android/view_model/coin_model.dart'; +import 'package:oktoast/oktoast.dart'; import 'package:provider/provider.dart'; import 'package:fun_android/config/resource_mananger.dart'; import 'package:fun_android/config/router_manger.dart'; @@ -177,17 +178,14 @@ class UserListWidget extends StatelessWidget { ListTile( title: Text(S.of(context).darkMode), onTap: () { - Provider.of(context).switchTheme( - brightness: Theme.of(context).brightness == Brightness.light - ? Brightness.dark - : Brightness.light); + switchDarkMode(context); }, leading: Transform.rotate( angle: -pi, child: Icon( Theme.of(context).brightness == Brightness.light - ? Icons.brightness_2 - : Icons.brightness_5, + ? Icons.brightness_5 + : Icons.brightness_2, color: iconColor, ), ), @@ -195,8 +193,7 @@ class UserListWidget extends StatelessWidget { activeColor: Theme.of(context).accentColor, value: Theme.of(context).brightness == Brightness.dark, onChanged: (value) { - Provider.of(context).switchTheme( - brightness: value ? Brightness.dark : Brightness.light); + switchDarkMode(context); }), ), SettingThemeWidget(), @@ -235,6 +232,17 @@ class UserListWidget extends StatelessWidget { ), ); } + + void switchDarkMode(BuildContext context) { + if (MediaQuery.of(context).platformBrightness == + Brightness.dark) { + showToast("检测到系统为暗黑模式,已为你自动切换",position: ToastPosition.bottom); + } else { + Provider.of(context).switchTheme( + userDarkMode: + Theme.of(context).brightness == Brightness.light); + } + } } class SettingThemeWidget extends StatelessWidget { @@ -262,7 +270,7 @@ class SettingThemeWidget extends StatelessWidget { onTap: () { var model = Provider.of(context); var brightness = Theme.of(context).brightness; - model.switchTheme(brightness: brightness, color: color); + model.switchTheme(color: color); }, child: Container( width: 40, diff --git a/lib/ui/widget/app_update.dart b/lib/ui/widget/app_update.dart index 17ec569..11ceaf0 100644 --- a/lib/ui/widget/app_update.dart +++ b/lib/ui/widget/app_update.dart @@ -13,7 +13,6 @@ import 'package:path_provider/path_provider.dart'; import 'button_progress_indicator.dart'; - class AppUpdateButton extends StatelessWidget { Widget build(BuildContext context) { return ProviderWidget( @@ -26,14 +25,15 @@ class AppUpdateButton extends StatelessWidget { onPressed: model.busy ? null : () async { - String url = await model.checkUpdate(); - if (url?.isNotEmpty ?? false) { - bool result = await showUpdateAlertDialog(context,url.split('/').last); - if (result == true) downloadApp(context, url); - } else { - showToast(S.of(context).appUpdateLeastVersion); - } - }, + String url = await model.checkUpdate(); + if (url?.isNotEmpty ?? false) { + bool result = + await showUpdateAlertDialog(context, url.split('/').last); + if (result == true) downloadApp(context, url); + } else { + showToast(S.of(context).appUpdateLeastVersion); + } + }, ), ); } @@ -55,25 +55,24 @@ showUpdateAlertDialog(context, version) async { return await showDialog( context: context, builder: (context) => AlertDialog( - content: Text(S.of(context).appUpdateFoundNewVersion(version)), - actions: [ - FlatButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: new Text( - S.of(context).actionCancel, - style: TextStyle(color: Colors.black.withOpacity(0.5)), - ), - ), - FlatButton( - onPressed: () async { - Navigator.of(context).pop(true); - }, - child: new Text(S.of(context).appUpdateActionUpdate), - ), - ], - )); + content: Text(S.of(context).appUpdateFoundNewVersion(version)), + actions: [ + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: new Text( + S.of(context).actionCancel + ), + ), + FlatButton( + onPressed: () async { + Navigator.of(context).pop(true); + }, + child: new Text(S.of(context).appUpdateActionUpdate), + ), + ], + )); } Future downloadApp(BuildContext context, String url) async { @@ -87,7 +86,7 @@ Future downloadApp(BuildContext context, String url) async { OpenFile.open(apkPath); } } else { - var reDownload = await showReDownloadDialog(context); + var reDownload = await showReDownloadAlertDialog(context); //因为点击android的返回键,关闭dialog时的返回值为null if (reDownload != null) { if (reDownload) { @@ -104,8 +103,9 @@ Future downloadApp(BuildContext context, String url) async { } showDownloadDialog(context, url, path) async { - CancelToken cancelToken = CancelToken(); DateTime lastBackPressed; + CancelToken cancelToken = CancelToken(); + bool downloading = false; return await showCupertinoDialog( context: context, builder: (context) { @@ -116,26 +116,31 @@ showDownloadDialog(context, url, path) async { Duration(seconds: 1)) { //两次点击间隔超过1秒则重新计时 lastBackPressed = DateTime.now(); - showToast('再次点击返回键,取消下载', position: ToastPosition.bottom); + showToast(S.of(context).appUpdateDoubleBackTips, position: ToastPosition.bottom); return false; } cancelToken.cancel(); - showToast('下载已取消', position: ToastPosition.bottom); + showToast(S.of(context).appUpdateDownloadCanceled, position: ToastPosition.bottom); return true; }, child: CupertinoAlertDialog( - title: Text('正在下载'), + title: Text(S.of(context).appUpdateDownloading), content: Builder( builder: (context) { + debugPrint('Downloader Builder'); ValueNotifier notifier = ValueNotifier(0.0); - Dio().download(url, path, cancelToken: cancelToken, - onReceiveProgress: (progress, total) { - debugPrint('value--${progress / total}'); - notifier.value = progress / total; - if (notifier.value == 1) { - Navigator.pop(context, true); - } - }); + if (!downloading) { + downloading = true; + Dio().download(url, path, cancelToken: cancelToken, + onReceiveProgress: (progress, total) { + debugPrint('value--${progress / total}'); + notifier.value = progress / total; + }).then((Response response) { + Navigator.pop(context, true); + }).catchError((onError){ + showToast(S.of(context).appUpdateDownloadFailed); + }); + } return ValueListenableBuilder( valueListenable: notifier, builder: (context, value, child) { @@ -154,39 +159,38 @@ showDownloadDialog(context, url, path) async { }); } -showReDownloadDialog(context) async { + +showReDownloadAlertDialog(context) async { return await showDialog( context: context, builder: (context) => AlertDialog( - content: Text(S.of(context).appUpdateReDownloadContent), - actions: [ - FlatButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: Text( - S.of(context).actionCancel, - style: TextStyle(color: Colors.black.withOpacity(0.5)), - ), - ), - SizedBox( - width: 20, - ), - FlatButton( - onPressed: () { - Navigator.of(context).pop(true); - }, - child: Text( - S.of(context).appUpdateActionDownloadAgain, - style: TextStyle(color: Colors.black), - ), - ), - FlatButton( - onPressed: () async { - Navigator.of(context).pop(false); - }, - child: Text(S.of(context).appUpdateActionInstallApk), - ), - ], - )); + content: Text(S.of(context).appUpdateReDownloadContent), + actions: [ + FlatButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: Text( + S.of(context).actionCancel, + ), + ), + SizedBox( + width: 20, + ), + FlatButton( + onPressed: () { + Navigator.of(context).pop(true); + }, + child: Text( + S.of(context).appUpdateActionDownloadAgain, + ), + ), + FlatButton( + onPressed: () async { + Navigator.of(context).pop(false); + }, + child: Text(S.of(context).appUpdateActionInstallApk), + ), + ], + )); } diff --git a/lib/view_model/theme_model.dart b/lib/view_model/theme_model.dart index e37af1b..b47546e 100644 --- a/lib/view_model/theme_model.dart +++ b/lib/view_model/theme_model.dart @@ -10,15 +10,13 @@ import 'package:fun_android/config/storage_manager.dart'; class ThemeModel with ChangeNotifier { static const kThemeColorIndex = 'kThemeColorIndex'; - static const kThemeBrightnessIndex = 'kThemeBrightnessIndex'; + static const kThemeUserDarkMode = 'kThemeUserDarkMode'; static const kFontIndex = 'kFontIndex'; static const fontValueList = ['system', 'kuaile']; - ThemeData _themeData; - - /// 明暗模式 - Brightness _brightness; + /// 用户选择的明暗模式 + bool _userDarkMode; /// 当前主题颜色 MaterialColor _themeColor; @@ -27,9 +25,9 @@ class ThemeModel with ChangeNotifier { int _fontIndex; ThemeModel() { - /// 明暗模式 - _brightness = Brightness.values[ - StorageManager.sharedPreferences.getInt(kThemeBrightnessIndex) ?? 1]; + /// 用户选择的明暗模式 + _userDarkMode = + StorageManager.sharedPreferences.getBool(kThemeUserDarkMode) ?? false; /// 获取主题色 _themeColor = Colors.primaries[ @@ -37,33 +35,29 @@ class ThemeModel with ChangeNotifier { /// 获取字体 _fontIndex = StorageManager.sharedPreferences.getInt(kFontIndex) ?? 0; - _generateThemeData(); } - ThemeData get themeData => _themeData; - - ThemeData get darkTheme => _themeData.copyWith(brightness: Brightness.dark); - int get fontIndex => _fontIndex; /// 切换指定色彩 /// /// 没有传[brightness]就不改变brightness,color同理 - void switchTheme({Brightness brightness, MaterialColor color}) { - _brightness = brightness ?? _brightness; + void switchTheme({bool userDarkMode, MaterialColor color}) { + _userDarkMode = userDarkMode ?? _userDarkMode; _themeColor = color ?? _themeColor; - _generateThemeData(); notifyListeners(); - saveTheme2Storage(_brightness, _themeColor); + saveTheme2Storage(userDarkMode, _themeColor); } /// 随机一个主题色彩 /// /// 可以指定明暗模式,不指定则保持不变 void switchRandomTheme({Brightness brightness}) { - brightness ??= (Random().nextBool() ? Brightness.dark : Brightness.light); int colorIndex = Random().nextInt(Colors.primaries.length - 1); - switchTheme(brightness: brightness, color: Colors.primaries[colorIndex]); + switchTheme( + userDarkMode: Random().nextBool(), + color: Colors.primaries[colorIndex], + ); } /// 切换字体 @@ -74,12 +68,15 @@ class ThemeModel with ChangeNotifier { } /// 根据主题 明暗 和 颜色 生成对应的主题 - _generateThemeData() { - var isDark = Brightness.dark == _brightness; + /// [dark]系统的Dark Mode + themeData({bool platformDarkMode: false}) { + var isDark = platformDarkMode || _userDarkMode; + Brightness brightness = isDark ? Brightness.dark : Brightness.light; + var themeColor = _themeColor; var accentColor = isDark ? themeColor[700] : _themeColor; var themeData = ThemeData( - brightness: _brightness, + brightness: brightness, // 主题颜色属于亮色系还是属于暗色系(eg:dark时,AppBarTitle文字及状态栏文字的颜色为白色,反之为黑色) primaryColorBrightness: Brightness.dark, accentColorBrightness: Brightness.dark, @@ -88,11 +85,11 @@ class ThemeModel with ChangeNotifier { fontFamily: fontValueList[fontIndex]); themeData = themeData.copyWith( - brightness: _brightness, + brightness: brightness, accentColor: accentColor, cupertinoOverrideTheme: CupertinoThemeData( primaryColor: themeColor, - brightness: _brightness, + brightness: brightness, ), appBarTheme: themeData.appBarTheme.copyWith(elevation: 0), splashColor: themeColor.withAlpha(50), @@ -111,16 +108,15 @@ class ThemeModel with ChangeNotifier { // textTheme: CupertinoTextThemeData(brightness: Brightness.light) inputDecorationTheme: ThemeHelper.inputDecorationTheme(themeData), ); - - _themeData = themeData; + return themeData; } /// 数据持久化到shared preferences - saveTheme2Storage(Brightness brightness, MaterialColor themeColor) async { + saveTheme2Storage(bool userDarkMode, MaterialColor themeColor) async { var index = Colors.primaries.indexOf(themeColor); await Future.wait([ StorageManager.sharedPreferences - .setInt(kThemeBrightnessIndex, brightness.index), + .setBool(kThemeUserDarkMode, userDarkMode), StorageManager.sharedPreferences.setInt(kThemeColorIndex, index) ]); } diff --git a/pubspec.yaml b/pubspec.yaml index 1e0542d..d7da27b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: fun_android description: Fun or Flutter for Android -version: 0.1.6+2 +version: 0.1.7+1 environment: sdk: ">=2.4.0 <3.0.0" diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index dd08b24..e0f0e4d 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -59,10 +59,13 @@ "appUpdateCheckUpdate": "Check Update", "appUpdateActionUpdate": "Update", "appUpdateLeastVersion": "Least version now ", - "appUpdateDownloading": "downloading...", - "appUpdateReDownloadContent": "It has been detected that it has been downloaded, whether it is installed", + "appUpdateDownloading": "Downloading...", + "appUpdateDownloadFailed": "Download failed", + "appUpdateReDownloadContent": "It has been detected that it has been downloaded, whether it is installed?", "appUpdateActionDownloadAgain": "Download", "appUpdateActionInstallApk": "Install", "appUpdateUpdate": "Version Update", - "appUpdateFoundNewVersion": "New version $version" + "appUpdateFoundNewVersion": "New version $version", + "appUpdateDownloadCanceled": "Download canceled", + "appUpdateDoubleBackTips": "Press back again, cancel download" } \ No newline at end of file diff --git a/res/values/strings_zh_CN.arb b/res/values/strings_zh_CN.arb index 9d0bb76..3f49fdc 100644 --- a/res/values/strings_zh_CN.arb +++ b/res/values/strings_zh_CN.arb @@ -60,9 +60,12 @@ "appUpdateActionUpdate": "更新", "appUpdateLeastVersion": "已是最新版本", "appUpdateDownloading": "下载中,请稍后...", - "appUpdateReDownloadContent": "检测到本地已下载过该版本,是否直接安装", + "appUpdateDownloadFailed": "下载失败", + "appUpdateReDownloadContent": "检测到本地已下载过该版本,是否直接安装?", "appUpdateActionDownloadAgain": "重新下载", "appUpdateActionInstallApk": "直接安装", "appUpdateUpdate": "版本更新", - "appUpdateFoundNewVersion": "发现新版本$version,是否更新" + "appUpdateFoundNewVersion": "发现新版本$version,是否更新?", + "appUpdateDownloadCanceled": "下载已取消", + "appUpdateDoubleBackTips": "再次点击返回键,取消下载" } \ No newline at end of file