mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 16:48:16 +08:00
add split settings model
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -70,19 +70,23 @@ List<SettingsModel> get extraSettings => [
|
|||||||
onTap: _showDownPathDialog,
|
onTap: _showDownPathDialog,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
SwitchModel(
|
SplitModel(
|
||||||
title: '空降助手',
|
normalModel: const NormalModel.split(
|
||||||
subtitle: '点击配置',
|
title: '空降助手',
|
||||||
setKey: SettingBoxKey.enableSponsorBlock,
|
subtitle: '点击配置',
|
||||||
defaultVal: false,
|
leading: Stack(
|
||||||
onTap: (context) => Get.toNamed('/sponsorBlock'),
|
clipBehavior: Clip.none,
|
||||||
leading: const Stack(
|
alignment: Alignment.center,
|
||||||
clipBehavior: Clip.none,
|
children: [
|
||||||
alignment: Alignment.center,
|
Icon(Icons.shield_outlined),
|
||||||
children: [
|
Icon(Icons.play_arrow_rounded, size: 15),
|
||||||
Icon(Icons.shield_outlined),
|
],
|
||||||
Icon(Icons.play_arrow_rounded, size: 15),
|
),
|
||||||
],
|
),
|
||||||
|
switchModel: SwitchModel.split(
|
||||||
|
defaultVal: false,
|
||||||
|
setKey: SettingBoxKey.enableSponsorBlock,
|
||||||
|
onTap: (context) => Get.toNamed('/sponsorBlock'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
PopupModel<SkipType>(
|
PopupModel<SkipType>(
|
||||||
@@ -94,14 +98,18 @@ List<SettingsModel> get extraSettings => [
|
|||||||
.put(SettingBoxKey.pgcSkipType, value.index)
|
.put(SettingBoxKey.pgcSkipType, value.index)
|
||||||
.whenComplete(setState),
|
.whenComplete(setState),
|
||||||
),
|
),
|
||||||
SwitchModel(
|
SplitModel(
|
||||||
title: '检查未读动态',
|
normalModel: const NormalModel.split(
|
||||||
subtitle: '点击设置检查周期(min)',
|
title: '检查未读动态',
|
||||||
leading: const Icon(Icons.notifications_none),
|
subtitle: '点击设置检查周期(min)',
|
||||||
setKey: SettingBoxKey.checkDynamic,
|
leading: Icon(Icons.notifications_none),
|
||||||
defaultVal: true,
|
),
|
||||||
onChanged: (value) => Get.find<MainController>().checkDynamic = value,
|
switchModel: SwitchModel.split(
|
||||||
onTap: _showDynDialog,
|
defaultVal: true,
|
||||||
|
setKey: SettingBoxKey.checkDynamic,
|
||||||
|
onChanged: (value) => Get.find<MainController>().checkDynamic = value,
|
||||||
|
onTap: _showDynDialog,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SwitchModel(
|
SwitchModel(
|
||||||
title: '显示视频分段信息',
|
title: '显示视频分段信息',
|
||||||
@@ -615,12 +623,17 @@ List<SettingsModel> get extraSettings => [
|
|||||||
defaultVal: false,
|
defaultVal: false,
|
||||||
onChanged: (value) => MemberTabType.showMemberShop = value,
|
onChanged: (value) => MemberTabType.showMemberShop = value,
|
||||||
),
|
),
|
||||||
const SwitchModel(
|
const SplitModel(
|
||||||
leading: Icon(Icons.airplane_ticket_outlined),
|
normalModel: NormalModel.split(
|
||||||
title: '设置代理',
|
title: '设置代理',
|
||||||
subtitle: '设置代理 host:port',
|
subtitle: '设置代理 host:port',
|
||||||
setKey: SettingBoxKey.enableSystemProxy,
|
leading: Icon(Icons.airplane_ticket_outlined),
|
||||||
onTap: _showProxyDialog,
|
),
|
||||||
|
switchModel: SwitchModel.split(
|
||||||
|
defaultVal: false,
|
||||||
|
setKey: SettingBoxKey.enableSystemProxy,
|
||||||
|
onTap: _showProxyDialog,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SwitchModel(
|
const SwitchModel(
|
||||||
title: '自动清除缓存',
|
title: '自动清除缓存',
|
||||||
|
|||||||
@@ -30,6 +30,43 @@ sealed class SettingsModel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SplitModel extends SettingsModel {
|
||||||
|
const SplitModel({
|
||||||
|
super.contentPadding,
|
||||||
|
super.titleStyle,
|
||||||
|
required this.normalModel,
|
||||||
|
required this.switchModel,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get effectiveSubtitle => normalModel.effectiveSubtitle;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get effectiveTitle => normalModel.effectiveTitle;
|
||||||
|
|
||||||
|
@override
|
||||||
|
String? get title => normalModel.title;
|
||||||
|
|
||||||
|
final NormalModel normalModel;
|
||||||
|
|
||||||
|
final SwitchModel switchModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget get widget => SetSwitchItem(
|
||||||
|
title: effectiveTitle,
|
||||||
|
subtitle: effectiveSubtitle,
|
||||||
|
setKey: switchModel.setKey,
|
||||||
|
defaultVal: switchModel.defaultVal,
|
||||||
|
onChanged: switchModel.onChanged,
|
||||||
|
needReboot: switchModel.needReboot,
|
||||||
|
leading: normalModel.leading,
|
||||||
|
onTap: switchModel.onTap,
|
||||||
|
contentPadding: contentPadding,
|
||||||
|
titleStyle: titleStyle,
|
||||||
|
isSplit: true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class PopupModel<T extends EnumWithLabel> extends SettingsModel {
|
class PopupModel<T extends EnumWithLabel> extends SettingsModel {
|
||||||
const PopupModel({
|
const PopupModel({
|
||||||
required this.title,
|
required this.title,
|
||||||
@@ -88,6 +125,18 @@ class NormalModel extends SettingsModel {
|
|||||||
this.onTap,
|
this.onTap,
|
||||||
}) : assert(title != null || getTitle != null);
|
}) : assert(title != null || getTitle != null);
|
||||||
|
|
||||||
|
const NormalModel.split({
|
||||||
|
super.subtitle,
|
||||||
|
super.leading,
|
||||||
|
super.contentPadding,
|
||||||
|
super.titleStyle,
|
||||||
|
this.title,
|
||||||
|
this.getTitle,
|
||||||
|
this.getSubtitle,
|
||||||
|
this.getTrailing,
|
||||||
|
}) : onTap = null,
|
||||||
|
assert(title != null || getTitle != null);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get effectiveTitle => title ?? getTitle!();
|
String get effectiveTitle => title ?? getTitle!();
|
||||||
@override
|
@override
|
||||||
@@ -109,7 +158,7 @@ class NormalModel extends SettingsModel {
|
|||||||
|
|
||||||
class SwitchModel extends SettingsModel {
|
class SwitchModel extends SettingsModel {
|
||||||
@override
|
@override
|
||||||
final String title;
|
final String? title;
|
||||||
final String setKey;
|
final String setKey;
|
||||||
final bool defaultVal;
|
final bool defaultVal;
|
||||||
final ValueChanged<bool>? onChanged;
|
final ValueChanged<bool>? onChanged;
|
||||||
@@ -121,7 +170,7 @@ class SwitchModel extends SettingsModel {
|
|||||||
super.leading,
|
super.leading,
|
||||||
super.contentPadding,
|
super.contentPadding,
|
||||||
super.titleStyle,
|
super.titleStyle,
|
||||||
required this.title,
|
required String this.title,
|
||||||
required this.setKey,
|
required this.setKey,
|
||||||
this.defaultVal = false,
|
this.defaultVal = false,
|
||||||
this.onChanged,
|
this.onChanged,
|
||||||
@@ -129,14 +178,22 @@ class SwitchModel extends SettingsModel {
|
|||||||
this.onTap,
|
this.onTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const SwitchModel.split({
|
||||||
|
required this.setKey,
|
||||||
|
this.defaultVal = false,
|
||||||
|
this.needReboot = false,
|
||||||
|
this.onChanged,
|
||||||
|
this.onTap,
|
||||||
|
}) : title = null;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get effectiveTitle => title;
|
String get effectiveTitle => title!;
|
||||||
@override
|
@override
|
||||||
String? get effectiveSubtitle => subtitle;
|
String? get effectiveSubtitle => subtitle;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget get widget => SetSwitchItem(
|
Widget get widget => SetSwitchItem(
|
||||||
title: title,
|
title: title!,
|
||||||
subtitle: subtitle,
|
subtitle: subtitle,
|
||||||
setKey: setKey,
|
setKey: setKey,
|
||||||
defaultVal: defaultVal,
|
defaultVal: defaultVal,
|
||||||
|
|||||||
@@ -82,14 +82,18 @@ List<SettingsModel> get styleSettings => [
|
|||||||
defaultVal: false,
|
defaultVal: false,
|
||||||
needReboot: true,
|
needReboot: true,
|
||||||
),
|
),
|
||||||
SwitchModel(
|
SplitModel(
|
||||||
title: 'App字体字重',
|
normalModel: const NormalModel.split(
|
||||||
subtitle: '点击设置',
|
title: 'App字体字重',
|
||||||
setKey: SettingBoxKey.appFontWeight,
|
subtitle: '点击设置',
|
||||||
defaultVal: false,
|
leading: Icon(Icons.text_fields),
|
||||||
leading: const Icon(Icons.text_fields),
|
),
|
||||||
onChanged: (_) => Get.updateMyAppTheme(),
|
switchModel: SwitchModel.split(
|
||||||
onTap: _showFontWeightDialog,
|
defaultVal: false,
|
||||||
|
setKey: SettingBoxKey.appFontWeight,
|
||||||
|
onChanged: (_) => Get.updateMyAppTheme(),
|
||||||
|
onTap: _showFontWeightDialog,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
NormalModel(
|
NormalModel(
|
||||||
title: '界面缩放',
|
title: '界面缩放',
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ class SetSwitchItem extends StatefulWidget {
|
|||||||
final void Function(BuildContext context)? onTap;
|
final void Function(BuildContext context)? onTap;
|
||||||
final EdgeInsetsGeometry? contentPadding;
|
final EdgeInsetsGeometry? contentPadding;
|
||||||
final TextStyle? titleStyle;
|
final TextStyle? titleStyle;
|
||||||
|
final bool isSplit;
|
||||||
|
|
||||||
const SetSwitchItem({
|
const SetSwitchItem({
|
||||||
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
this.subtitle,
|
this.subtitle,
|
||||||
required this.setKey,
|
required this.setKey,
|
||||||
@@ -29,7 +31,7 @@ class SetSwitchItem extends StatefulWidget {
|
|||||||
this.onTap,
|
this.onTap,
|
||||||
this.contentPadding,
|
this.contentPadding,
|
||||||
this.titleStyle,
|
this.titleStyle,
|
||||||
super.key,
|
this.isSplit = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -103,7 +105,17 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
|
|||||||
final subTitleStyle = theme.textTheme.labelMedium!.copyWith(
|
final subTitleStyle = theme.textTheme.labelMedium!.copyWith(
|
||||||
color: theme.colorScheme.outline,
|
color: theme.colorScheme.outline,
|
||||||
);
|
);
|
||||||
return ListTile(
|
|
||||||
|
final switchBtn = Transform.scale(
|
||||||
|
scale: 0.8,
|
||||||
|
alignment: .centerRight,
|
||||||
|
child: Switch(
|
||||||
|
value: val,
|
||||||
|
onChanged: switchChange,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget child(Widget? trailing) => ListTile(
|
||||||
contentPadding: widget.contentPadding,
|
contentPadding: widget.contentPadding,
|
||||||
enabled: widget.onTap == null ? true : val,
|
enabled: widget.onTap == null ? true : val,
|
||||||
onTap: widget.onTap == null ? switchChange : () => widget.onTap!(context),
|
onTap: widget.onTap == null ? switchChange : () => widget.onTap!(context),
|
||||||
@@ -112,14 +124,28 @@ class _SetSwitchItemState extends State<SetSwitchItem> {
|
|||||||
? Text(widget.subtitle!, style: subTitleStyle)
|
? Text(widget.subtitle!, style: subTitleStyle)
|
||||||
: null,
|
: null,
|
||||||
leading: widget.leading,
|
leading: widget.leading,
|
||||||
trailing: Transform.scale(
|
trailing: trailing,
|
||||||
scale: 0.8,
|
|
||||||
alignment: .centerRight,
|
|
||||||
child: Switch(
|
|
||||||
value: val,
|
|
||||||
onChanged: switchChange,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (widget.isSplit) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Expanded(child: child(null)),
|
||||||
|
SizedBox(
|
||||||
|
height: 25,
|
||||||
|
child: VerticalDivider(
|
||||||
|
width: 1,
|
||||||
|
color: theme.colorScheme.outline.withValues(alpha: .3),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const .only(left: 4, right: 24),
|
||||||
|
child: switchBtn,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return child(switchBtn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user