From f92bedef05824003d33ffb80fd6c34edef048d11 Mon Sep 17 00:00:00 2001 From: niuhuan Date: Thu, 23 Mar 2023 17:44:42 +0800 Subject: [PATCH] :bug: Fix switch (un)fullscreen shark --- ci/version.info.txt | 3 +- lib/basic/Method.dart | 5 ++ lib/basic/config/Address.dart | 99 ++++++++++++++++++++++++- lib/basic/config/DownloadCachePath.dart | 3 +- lib/basic/config/FullScreenUI.dart | 25 ++++++- lib/basic/config/ImageAddress.dart | 81 +++++++++++++++++++- lib/screens/InitScreen.dart | 3 +- 7 files changed, 208 insertions(+), 11 deletions(-) diff --git a/ci/version.info.txt b/ci/version.info.txt index cd43a18..a5a49ba 100644 --- a/ci/version.info.txt +++ b/ci/version.info.txt @@ -1,5 +1,6 @@ v1.6.8 -- [x] ✨测速(界面还未实现) +- [x] ✨选择API分流以及图片分流时进行测速 - [x] ♻️优化安卓文件关联 - [x] ♻️优化安卓URL匹配 +- [x] 🐛修复切换全屏时的屏幕抖动 diff --git a/lib/basic/Method.dart b/lib/basic/Method.dart index 0033d99..308ff48 100644 --- a/lib/basic/Method.dart +++ b/lib/basic/Method.dart @@ -973,6 +973,11 @@ class Method { return int.parse(ms); } + Future pingImg(String idx) async { + String ms = await _flatInvoke("pingImg", idx); + return int.parse(ms); + } + Future androidStorageRoot() async { return await _channel.invokeMethod("androidStorageRoot"); } diff --git a/lib/basic/config/Address.dart b/lib/basic/config/Address.dart index 19fb59f..87b3cc9 100644 --- a/lib/basic/config/Address.dart +++ b/lib/basic/config/Address.dart @@ -13,7 +13,7 @@ var _addresses = { "0": "不分流", "1": "分流1", "2": "分流2", - "3": "分流3 (推荐)", + "3": "分流3", "4": "分流4", "5": "分流5", "6": "分流6", @@ -27,6 +27,8 @@ Future initAddress() async { _currentAddress = await method.getSwitchAddress(); } +String currentAddress() => _currentAddress; + String currentAddressName() => _addresses[_currentAddress] ?? ""; Future chooseAddress(BuildContext context) async { @@ -38,7 +40,11 @@ Future chooseAddress(BuildContext context) async { children: [ ..._addresses.entries.map( (e) => SimpleDialogOption( - child: Text(e.value), + child: ApiOptionRow( + e.value, + e.key, + key: Key("API:${e.key}"), + ), onPressed: () { Navigator.of(context).pop(e.key); }, @@ -153,3 +159,92 @@ Widget addressActionButton(BuildContext context) { icon: const Icon(Icons.network_ping), ); } + +class ApiOptionRow extends StatefulWidget { + final String title; + final String value; + + const ApiOptionRow(this.title, this.value, {Key? key}) : super(key: key); + + @override + State createState() => _ApiOptionRowState(); +} + +class _ApiOptionRowState extends State { + late Future _feature; + + @override + void initState() { + super.initState(); + _feature = method.ping(widget.value); + } + + @override + Widget build(BuildContext context) { + return Row( + children: [ + Text(widget.title), + Expanded(child: Container()), + FutureBuilder( + future: _feature, + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + if (snapshot.connectionState != ConnectionState.done) { + return const PingStatus( + "测速中", + Colors.blue, + ); + } + if (snapshot.hasError) { + return const PingStatus( + "失败", + Colors.red, + ); + } + int ping = snapshot.requireData; + if (ping <= 200) { + return PingStatus( + "${ping}ms", + Colors.green, + ); + } + if (ping <= 500) { + return PingStatus( + "${ping}ms", + Colors.yellow, + ); + } + return PingStatus( + "${ping}ms", + Colors.orange, + ); + }, + ), + ], + ); + } +} + +class PingStatus extends StatelessWidget { + final String title; + final Color color; + + const PingStatus(this.title, this.color, {Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + children: [ + Text( + '\u2022', + style: TextStyle( + color: color, + ), + ), + Text(" $title"), + ], + ); + } +} diff --git a/lib/basic/config/DownloadCachePath.dart b/lib/basic/config/DownloadCachePath.dart index ef57e6b..dbf6eb2 100644 --- a/lib/basic/config/DownloadCachePath.dart +++ b/lib/basic/config/DownloadCachePath.dart @@ -1,5 +1,6 @@ /// 下载的同时导出到文件系统 +import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; @@ -34,7 +35,7 @@ Widget downloadCachePathSetting() { bool b = await confirmDialog( context, "使用其他软件的下载内容加速", - "您即将选择一个目录, 作为下载加速使用, 这个目录名字通常叫files", + "您即将选择一个目录, 这个目录拷贝自 ${base64Decode("L0FuZHJvaWQvZGF0YS9jb20ucGljYWNvbWljLmZyZWdhdGEvZmlsZXMv")}", ); if (b) { late String? folder; diff --git a/lib/basic/config/FullScreenUI.dart b/lib/basic/config/FullScreenUI.dart index 6b95f34..ff1fae5 100644 --- a/lib/basic/config/FullScreenUI.dart +++ b/lib/basic/config/FullScreenUI.dart @@ -22,6 +22,15 @@ Future initFullScreenUI() async { _propertyName, FullScreenUI.NO.toString(), )); + SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle( + systemStatusBarContrastEnforced: true, + systemNavigationBarContrastEnforced: true, + )); + SystemChrome.setEnabledSystemUIMode( + SystemUiMode.edgeToEdge, + overlays: SystemUiOverlay.values, + ); + switchFullScreenUI(); } FullScreenUI _fullScreenUIFromString(String string) { @@ -62,17 +71,27 @@ void switchFullScreenUI() { List list = [...SystemUiOverlay.values]; switch (fullScreenUI) { case FullScreenUI.HIDDEN_BOTTOM: - list.remove(SystemUiOverlay.bottom); + SystemChrome.setEnabledSystemUIMode( + SystemUiMode.manual, + overlays: [SystemUiOverlay.top], + ); break; case FullScreenUI.ALL: - list.clear(); + SystemChrome.setEnabledSystemUIMode( + SystemUiMode.manual, + overlays: [], + ); break; case FullScreenUI.NO: + SystemChrome.setEnabledSystemUIMode( + SystemUiMode.edgeToEdge, + overlays: SystemUiOverlay.values, + ); break; } if (Platform.isAndroid || Platform.isIOS) { SystemChrome.setEnabledSystemUIMode( - SystemUiMode.manual, + SystemUiMode.edgeToEdge, overlays: list, ); } diff --git a/lib/basic/config/ImageAddress.dart b/lib/basic/config/ImageAddress.dart index af15398..70d1942 100644 --- a/lib/basic/config/ImageAddress.dart +++ b/lib/basic/config/ImageAddress.dart @@ -1,10 +1,12 @@ import 'package:flutter/material.dart'; +import 'package:path/path.dart'; import '../Method.dart'; +import 'Address.dart'; var _imageAddresses = { "0": "不分流", - "1": "分流1 (推荐)", + "1": "分流1", "2": "分流2", "3": "分流3", "4": "分流4", @@ -33,7 +35,11 @@ Future chooseImageAddress(BuildContext context) async { children: [ ..._imageAddresses.entries.map( (e) => SimpleDialogOption( - child: Text(e.value), + child: ApiOptionRowImg( + e.value, + e.key, + key: Key("API:${e.key}"), + ), onPressed: () { Navigator.of(context).pop(e.key); }, @@ -63,3 +69,74 @@ Widget imageSwitchAddressSetting() { }, ); } + +class ApiOptionRowImg extends StatefulWidget { + final String title; + final String value; + + const ApiOptionRowImg(this.title, this.value, {Key? key}) : super(key: key); + + @override + State createState() => _ApiOptionRowImgState(); +} + +class _ApiOptionRowImgState extends State { + late Future _feature; + + @override + void initState() { + super.initState(); + if ("0" != widget.value) { + _feature = method.pingImg(widget.value); + }else{ + _feature = method.ping(currentAddress()); + } + } + + @override + Widget build(BuildContext context) { + return Row( + children: [ + Text(widget.title), + Expanded(child: Container()), + FutureBuilder( + future: _feature, + builder: ( + BuildContext context, + AsyncSnapshot snapshot, + ) { + if (snapshot.connectionState != ConnectionState.done) { + return const PingStatus( + "测速中", + Colors.blue, + ); + } + if (snapshot.hasError) { + return const PingStatus( + "失败", + Colors.red, + ); + } + int ping = snapshot.requireData; + if (ping <= 200) { + return PingStatus( + "${ping}ms", + Colors.green, + ); + } + if (ping <= 500) { + return PingStatus( + "${ping}ms", + Colors.yellow, + ); + } + return PingStatus( + "${ping}ms", + Colors.orange, + ); + }, + ), + ], + ); + } +} diff --git a/lib/screens/InitScreen.dart b/lib/screens/InitScreen.dart index 4556131..bf89b80 100644 --- a/lib/screens/InitScreen.dart +++ b/lib/screens/InitScreen.dart @@ -77,6 +77,7 @@ class _InitScreenState extends State { await initQuality(); await initFont(); await initTheme(); + await initFullScreenUI(); await initListLayout(); await initReaderType(); await initReaderDirection(); @@ -86,10 +87,8 @@ class _InitScreenState extends State { await initPagerAction(); await initShadowCategoriesMode(); await initShadowCategories(); - await initFullScreenUI(); await initIconLoading(); await initCategoriesColumnCount(); - switchFullScreenUI(); await initContentFailedReloadAction(); await initVolumeController(); await initKeyboardController();