new: setting of default collapse

This commit is contained in:
lollipopkit
2024-01-05 21:58:43 +08:00
parent 43fb481aee
commit b442e0f914
20 changed files with 125 additions and 53 deletions

View File

@@ -16,9 +16,7 @@ import 'package:toolbox/data/res/logger.dart';
import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/data/res/store.dart';
import '../../core/analysis.dart';
import '../../core/route.dart';
import '../../core/update.dart';
import '../../core/utils/ui.dart';
import '../../data/model/app/github_id.dart';
import '../../data/model/app/tab.dart';
@@ -87,7 +85,7 @@ class _HomePageState extends State<HomePage>
if (!Pros.server.isAutoRefreshOn) {
Pros.server.startAutoRefresh();
}
updateHomeWidget();
HomeWidgetMC.update();
break;
case AppLifecycleState.paused:
// Keep running in background on Android device
@@ -323,22 +321,10 @@ class _HomePageState extends State<HomePage>
Future<void> afterFirstLayout(BuildContext context) async {
// Auth required for first launch
_auth();
if (Stores.setting.autoCheckAppUpdate.fetch()) {
doUpdate(context);
}
updateHomeWidget();
HomeWidgetMC.update();
await GetIt.I.allReady();
await Pros.server.load();
await Pros.server.refreshData();
if (!Analysis.enabled) {
Analysis.init();
}
}
void updateHomeWidget() {
if (Stores.setting.autoUpdateHomeWidget.fetch()) {
HomeWidgetMC.update();
}
}
Future<void> _onLongPressSetting() async {

View File

@@ -38,11 +38,6 @@ class ServerDetailPage extends StatefulWidget {
class _ServerDetailPageState extends State<ServerDetailPage>
with SingleTickerProviderStateMixin {
late MediaQueryData _media;
final Order<String> _cardsOrder = [];
late final _textFactor = TextScaler.linear(Stores.setting.textFactor.fetch());
late final _cardBuildMap = Map.fromIterables(
Defaults.detailCardOrder,
[
@@ -58,7 +53,12 @@ class _ServerDetailPageState extends State<ServerDetailPage>
],
);
var _netSortType = _NetSortType.device;
late MediaQueryData _media;
final Order<String> _cardsOrder = [];
final _netSortType = ValueNotifier(_NetSortType.device);
late final _collapse = Stores.setting.collapseUIDefault.fetch();
late final _textFactor = TextScaler.linear(Stores.setting.textFactor.fetch());
@override
void didChangeDependencies() {
@@ -127,7 +127,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
return CardX(
child: ExpandTile(
leading: const Icon(Icons.computer),
initiallyExpanded: ss.more.entries.length < 7,
initiallyExpanded: _getInitExpand(ss.more.entries.length),
title: Text(l10n.about),
childrenPadding: const EdgeInsets.symmetric(
horizontal: 17,
@@ -175,7 +175,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
),
),
childrenPadding: const EdgeInsets.symmetric(vertical: 13),
initiallyExpanded: ss.cpu.coresCount <= 8,
initiallyExpanded: _getInitExpand(ss.cpu.coresCount),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: details,
@@ -319,7 +319,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
child: ExpandTile(
title: const Text('GPU'),
leading: const Icon(Icons.memory, size: 17),
initiallyExpanded: children.length <= 3,
initiallyExpanded: _getInitExpand(children.length, 3),
children: children,
),
);
@@ -453,7 +453,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
title: Text(l10n.disk),
childrenPadding: const EdgeInsets.only(bottom: 7),
leading: const Icon(Icons.storage, size: 17),
initiallyExpanded: children.length <= 7,
initiallyExpanded: _getInitExpand(children.length),
children: children,
),
);
@@ -518,7 +518,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
));
} else {
final devices = ns.devices;
devices.sort(_netSortType.getSortFunc(ns));
devices.sort(_netSortType.value.getSortFunc(ns));
children.addAll(devices.map((e) => _buildNetSpeedItem(ns, e)));
}
return CardX(
@@ -527,36 +527,31 @@ class _ServerDetailPageState extends State<ServerDetailPage>
children: [
Text(l10n.net),
UIs.width13,
IconButton(
onPressed: () {
setState(() {
_netSortType = _netSortType.next;
});
},
icon: AnimatedSwitcher(
ValueListenableBuilder(
valueListenable: _netSortType,
builder: (_, val, __) => AnimatedSwitcher(
duration: const Duration(milliseconds: 377),
transitionBuilder: (child, animation) => FadeTransition(
opacity: animation,
child: child,
),
child: Row(
key: ValueKey(_netSortType),
children: [
const Icon(Icons.sort, size: 17),
UIs.width7,
Text(
_netSortType.name,
val.name,
style: UIs.text13Grey,
),
],
),
),
)
).tap(onTap: () => _netSortType.value = val.next),
),
],
),
childrenPadding: const EdgeInsets.only(bottom: 11),
leading: const Icon(Icons.device_hub, size: 17),
initiallyExpanded: children.length <= 7,
initiallyExpanded: _getInitExpand(children.length),
children: children,
),
);
@@ -589,7 +584,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
SizedBox(
width: 170,
child: Text(
'${ns.speedOut(device: device)}\n${ns.speedIn(device: device)}',
'${ns.speedOut(device: device)}\n${ns.speedIn(device: device)}',
textAlign: TextAlign.end,
style: UIs.text13Grey,
),
@@ -607,7 +602,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
child: ExpandTile(
title: Text(l10n.temperature),
leading: const Icon(Icons.ac_unit, size: 17),
initiallyExpanded: ss.temps.devices.length <= 7,
initiallyExpanded: _getInitExpand(ss.temps.devices.length),
childrenPadding: const EdgeInsets.only(bottom: 7),
children: ss.temps.devices
.map((key) => _buildTemperatureItem(key, ss.temps.get(key)))
@@ -638,6 +633,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
title: Text(l10n.battery),
leading: const Icon(Icons.battery_charging_full, size: 17),
childrenPadding: const EdgeInsets.only(bottom: 7),
initiallyExpanded: _getInitExpand(ss.batteries.length),
children: ss.batteries.map(_buildBatteryItem).toList(),
),
);
@@ -684,6 +680,11 @@ class _ServerDetailPageState extends State<ServerDetailPage>
),
);
}
bool _getInitExpand(int len, [int? max]) {
if (_collapse && len <= (max ?? 7)) return true;
return false;
}
}
enum _NetSortType {

View File

@@ -139,6 +139,7 @@ class _SettingPageState extends State<SettingPage> {
body: ListView(
padding: const EdgeInsets.symmetric(horizontal: 17),
children: [
/// TODO: Remember add new items in front of the each list, so the user can easily find the new items
_buildTitle('App'),
_buildApp(),
_buildTitle(l10n.server),
@@ -203,6 +204,7 @@ class _SettingPageState extends State<SettingPage> {
Widget _buildServer() {
return Column(
children: [
_buildCollapseUI(),
_buildServerFuncBtns(),
_buildSequence(),
_buildNetViewType(),
@@ -1104,4 +1106,12 @@ class _SettingPageState extends State<SettingPage> {
trailing: StoreSwitch(prop: _setting.editorHighlight),
);
}
Widget _buildCollapseUI() {
return ListTile(
title: Text(l10n.collapseUI),
subtitle: Text(l10n.collapseUITip, style: UIs.textGrey),
trailing: StoreSwitch(prop: _setting.collapseUIDefault),
);
}
}

View File

@@ -59,7 +59,7 @@ class _InputState extends State<Input> {
Widget build(BuildContext context) {
return CardX(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 17),
padding: const EdgeInsets.symmetric(horizontal: 7),
child: TextField(
controller: widget.controller,
maxLines: widget.maxLines,