🐛 Fix switch (un)fullscreen shark

This commit is contained in:
niuhuan 2023-03-23 17:44:42 +08:00
parent b5c4837076
commit f92bedef05
7 changed files with 208 additions and 11 deletions

View File

@ -1,5 +1,6 @@
v1.6.8 v1.6.8
- [x] ✨测速(界面还未实现) - [x] ✨选择API分流以及图片分流时进行测速
- [x] ♻️优化安卓文件关联 - [x] ♻️优化安卓文件关联
- [x] ♻优化安卓URL匹配 - [x] ♻优化安卓URL匹配
- [x] 🐛修复切换全屏时的屏幕抖动

View File

@ -973,6 +973,11 @@ class Method {
return int.parse(ms); return int.parse(ms);
} }
Future<int> pingImg(String idx) async {
String ms = await _flatInvoke("pingImg", idx);
return int.parse(ms);
}
Future<String> androidStorageRoot() async { Future<String> androidStorageRoot() async {
return await _channel.invokeMethod("androidStorageRoot"); return await _channel.invokeMethod("androidStorageRoot");
} }

View File

@ -13,7 +13,7 @@ var _addresses = {
"0": "不分流", "0": "不分流",
"1": "分流1", "1": "分流1",
"2": "分流2", "2": "分流2",
"3": "分流3 (推荐)", "3": "分流3",
"4": "分流4", "4": "分流4",
"5": "分流5", "5": "分流5",
"6": "分流6", "6": "分流6",
@ -27,6 +27,8 @@ Future<void> initAddress() async {
_currentAddress = await method.getSwitchAddress(); _currentAddress = await method.getSwitchAddress();
} }
String currentAddress() => _currentAddress;
String currentAddressName() => _addresses[_currentAddress] ?? ""; String currentAddressName() => _addresses[_currentAddress] ?? "";
Future<void> chooseAddress(BuildContext context) async { Future<void> chooseAddress(BuildContext context) async {
@ -38,7 +40,11 @@ Future<void> chooseAddress(BuildContext context) async {
children: <Widget>[ children: <Widget>[
..._addresses.entries.map( ..._addresses.entries.map(
(e) => SimpleDialogOption( (e) => SimpleDialogOption(
child: Text(e.value), child: ApiOptionRow(
e.value,
e.key,
key: Key("API:${e.key}"),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(e.key); Navigator.of(context).pop(e.key);
}, },
@ -153,3 +159,92 @@ Widget addressActionButton(BuildContext context) {
icon: const Icon(Icons.network_ping), 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<StatefulWidget> createState() => _ApiOptionRowState();
}
class _ApiOptionRowState extends State<ApiOptionRow> {
late Future<int> _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<int> 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"),
],
);
}
}

View File

@ -1,5 +1,6 @@
/// ///
import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -34,7 +35,7 @@ Widget downloadCachePathSetting() {
bool b = await confirmDialog( bool b = await confirmDialog(
context, context,
"使用其他软件的下载内容加速", "使用其他软件的下载内容加速",
"您即将选择一个目录, 作为下载加速使用, 这个目录名字通常叫files", "您即将选择一个目录, 这个目录拷贝自 ${base64Decode("L0FuZHJvaWQvZGF0YS9jb20ucGljYWNvbWljLmZyZWdhdGEvZmlsZXMv")}",
); );
if (b) { if (b) {
late String? folder; late String? folder;

View File

@ -22,6 +22,15 @@ Future<void> initFullScreenUI() async {
_propertyName, _propertyName,
FullScreenUI.NO.toString(), FullScreenUI.NO.toString(),
)); ));
SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
systemStatusBarContrastEnforced: true,
systemNavigationBarContrastEnforced: true,
));
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
overlays: SystemUiOverlay.values,
);
switchFullScreenUI();
} }
FullScreenUI _fullScreenUIFromString(String string) { FullScreenUI _fullScreenUIFromString(String string) {
@ -62,17 +71,27 @@ void switchFullScreenUI() {
List<SystemUiOverlay> list = [...SystemUiOverlay.values]; List<SystemUiOverlay> list = [...SystemUiOverlay.values];
switch (fullScreenUI) { switch (fullScreenUI) {
case FullScreenUI.HIDDEN_BOTTOM: case FullScreenUI.HIDDEN_BOTTOM:
list.remove(SystemUiOverlay.bottom); SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [SystemUiOverlay.top],
);
break; break;
case FullScreenUI.ALL: case FullScreenUI.ALL:
list.clear(); SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual,
overlays: [],
);
break; break;
case FullScreenUI.NO: case FullScreenUI.NO:
SystemChrome.setEnabledSystemUIMode(
SystemUiMode.edgeToEdge,
overlays: SystemUiOverlay.values,
);
break; break;
} }
if (Platform.isAndroid || Platform.isIOS) { if (Platform.isAndroid || Platform.isIOS) {
SystemChrome.setEnabledSystemUIMode( SystemChrome.setEnabledSystemUIMode(
SystemUiMode.manual, SystemUiMode.edgeToEdge,
overlays: list, overlays: list,
); );
} }

View File

@ -1,10 +1,12 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:path/path.dart';
import '../Method.dart'; import '../Method.dart';
import 'Address.dart';
var _imageAddresses = { var _imageAddresses = {
"0": "不分流", "0": "不分流",
"1": "分流1 (推荐)", "1": "分流1",
"2": "分流2", "2": "分流2",
"3": "分流3", "3": "分流3",
"4": "分流4", "4": "分流4",
@ -33,7 +35,11 @@ Future<void> chooseImageAddress(BuildContext context) async {
children: <Widget>[ children: <Widget>[
..._imageAddresses.entries.map( ..._imageAddresses.entries.map(
(e) => SimpleDialogOption( (e) => SimpleDialogOption(
child: Text(e.value), child: ApiOptionRowImg(
e.value,
e.key,
key: Key("API:${e.key}"),
),
onPressed: () { onPressed: () {
Navigator.of(context).pop(e.key); 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<StatefulWidget> createState() => _ApiOptionRowImgState();
}
class _ApiOptionRowImgState extends State<ApiOptionRowImg> {
late Future<int> _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<int> 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,
);
},
),
],
);
}
}

View File

@ -77,6 +77,7 @@ class _InitScreenState extends State<InitScreen> {
await initQuality(); await initQuality();
await initFont(); await initFont();
await initTheme(); await initTheme();
await initFullScreenUI();
await initListLayout(); await initListLayout();
await initReaderType(); await initReaderType();
await initReaderDirection(); await initReaderDirection();
@ -86,10 +87,8 @@ class _InitScreenState extends State<InitScreen> {
await initPagerAction(); await initPagerAction();
await initShadowCategoriesMode(); await initShadowCategoriesMode();
await initShadowCategories(); await initShadowCategories();
await initFullScreenUI();
await initIconLoading(); await initIconLoading();
await initCategoriesColumnCount(); await initCategoriesColumnCount();
switchFullScreenUI();
await initContentFailedReloadAction(); await initContentFailedReloadAction();
await initVolumeController(); await initVolumeController();
await initKeyboardController(); await initKeyboardController();