refa: settings model (#1773)

* opt: MediaQuery

* refa: settings model
This commit is contained in:
My-Responsitories
2025-12-10 16:41:31 +08:00
committed by GitHub
parent b12bdf2eb8
commit 890dc58dc3
13 changed files with 406 additions and 579 deletions

View File

@@ -1,6 +1,5 @@
import 'dart:io';
import 'package:PiliPlus/models/common/settings_type.dart';
import 'package:PiliPlus/models/common/video/audio_quality.dart';
import 'package:PiliPlus/models/common/video/cdn_type.dart';
import 'package:PiliPlus/models/common/video/live_quality.dart';
@@ -19,45 +18,43 @@ import 'package:get/get.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
List<SettingsModel> get videoSettings => [
const SettingsModel(
settingsType: SettingsType.sw1tch,
const SwitchModel(
title: '开启硬解',
subtitle: '以较低功耗播放视频,若异常卡死请关闭',
leading: Icon(Icons.flash_on_outlined),
setKey: SettingBoxKey.enableHA,
defaultVal: true,
),
const SettingsModel(
settingsType: SettingsType.sw1tch,
const SwitchModel(
title: '免登录1080P',
subtitle: '免登录查看1080P视频',
leading: Icon(Icons.hd_outlined),
setKey: SettingBoxKey.p1080,
defaultVal: true,
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: 'B站定向流量支持',
subtitle: '若套餐含B站定向流量则会自动使用。可查阅运营商的流量记录确认。',
leading: const Icon(Icons.perm_data_setting_outlined),
getTrailing: () => Transform.scale(
alignment: Alignment.centerRight,
scale: 0.8,
child: Switch(
value: true,
onChanged: (_) {},
getTrailing: () => IgnorePointer(
child: Transform.scale(
alignment: Alignment.centerRight,
scale: 0.8,
child: Switch(
value: true,
onChanged: (_) {},
),
),
),
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: 'CDN 设置',
leading: const Icon(MdiIcons.cloudPlusOutline),
getSubtitle: () =>
'当前使用:${VideoUtils.cdnService.desc},部分 CDN 可能失效,如无法播放请尝试切换',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<CDNService>(
context: Get.context!,
context: context,
builder: (context) {
return const CdnSelectDialog();
},
@@ -69,14 +66,13 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '直播 CDN 设置',
leading: const Icon(MdiIcons.cloudPlusOutline),
getSubtitle: () => '当前使用:${Pref.liveCdnUrl ?? "默认"}',
onTap: (setState) async {
onTap: (context, setState) async {
String? result = await showDialog<String>(
context: Get.context!,
context: context,
builder: (context) {
String host = Pref.liveCdnUrl ?? '';
return AlertDialog(
@@ -119,16 +115,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
const SettingsModel(
settingsType: SettingsType.sw1tch,
const SwitchModel(
title: 'CDN 测速',
leading: Icon(Icons.speed),
subtitle: '测速通过模拟加载视频实现,注意流量消耗,结果仅供参考',
setKey: SettingBoxKey.cdnSpeedTest,
defaultVal: true,
),
SettingsModel(
settingsType: SettingsType.sw1tch,
SwitchModel(
title: '音频不跟随 CDN 设置',
subtitle: '直接采用备用 URL可解决部分视频无声',
leading: const Icon(MdiIcons.musicNotePlus),
@@ -138,15 +132,14 @@ List<SettingsModel> get videoSettings => [
VideoUtils.disableAudioCDN = value;
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '默认画质',
leading: const Icon(Icons.video_settings_outlined),
getSubtitle: () =>
'当前画质:${VideoQuality.fromCode(Pref.defaultVideoQa).desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '默认画质',
@@ -161,15 +154,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '蜂窝网络画质',
leading: const Icon(Icons.video_settings_outlined),
getSubtitle: () =>
'当前画质:${VideoQuality.fromCode(Pref.defaultVideoQaCellular).desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '蜂窝网络画质',
@@ -187,15 +179,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '默认音质',
leading: const Icon(Icons.music_video_outlined),
getSubtitle: () =>
'当前音质:${AudioQuality.fromCode(Pref.defaultAudioQa).desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '默认音质',
@@ -210,15 +201,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '蜂窝网络音质',
leading: const Icon(Icons.music_video_outlined),
getSubtitle: () =>
'当前音质:${AudioQuality.fromCode(Pref.defaultAudioQaCellular).desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '蜂窝网络音质',
@@ -236,14 +226,13 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '直播默认画质',
leading: const Icon(Icons.video_settings_outlined),
getSubtitle: () => '当前画质:${LiveQuality.fromCode(Pref.liveQuality)?.desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '直播默认画质',
@@ -258,15 +247,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '蜂窝网络直播默认画质',
leading: const Icon(Icons.video_settings_outlined),
getSubtitle: () =>
'当前画质:${LiveQuality.fromCode(Pref.liveQualityCellular)?.desc}',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<int>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<int>(
title: '蜂窝网络直播默认画质',
@@ -281,15 +269,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '首选解码格式',
leading: const Icon(Icons.movie_creation_outlined),
getSubtitle: () =>
'首选解码格式:${VideoDecodeFormatType.fromCode(Pref.defaultDecode).description},请根据设备支持情况与需求调整',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<String>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<String>(
title: '默认解码格式',
@@ -306,15 +293,14 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '次选解码格式',
getSubtitle: () =>
'非杜比视频次选:${VideoDecodeFormatType.fromCode(Pref.secondDecode).description},仍无则选择首个提供的解码格式',
leading: const Icon(Icons.swap_horizontal_circle_outlined),
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<String>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<String>(
title: '次选解码格式',
@@ -332,16 +318,14 @@ List<SettingsModel> get videoSettings => [
},
),
if (Platform.isAndroid)
const SettingsModel(
settingsType: SettingsType.sw1tch,
const SwitchModel(
title: '优先使用 OpenSL ES 输出音频',
leading: Icon(Icons.speaker_outlined),
subtitle: '关闭则优先使用AudioTrack输出音频此项即mpv的--ao若遇系统音效丢失、无声、音画不同步等问题请尝试关闭。',
setKey: SettingBoxKey.useOpenSLES,
defaultVal: true,
),
const SettingsModel(
settingsType: SettingsType.sw1tch,
const SwitchModel(
title: '扩大缓冲区',
leading: Icon(Icons.storage_outlined),
subtitle: '默认缓冲区为视频4MB/直播16MB开启后为32MB/64MB加载时间变长',
@@ -349,14 +333,13 @@ List<SettingsModel> get videoSettings => [
defaultVal: false,
),
//video-sync
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '视频同步',
leading: const Icon(Icons.view_timeline_outlined),
getSubtitle: () => '当前:${Pref.videoSync}此项即mpv的--video-sync',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<String>(
context: Get.context!,
context: context,
builder: (context) {
return SelectDialog<String>(
title: '视频同步',
@@ -381,14 +364,13 @@ List<SettingsModel> get videoSettings => [
}
},
),
SettingsModel(
settingsType: SettingsType.normal,
NormalModel(
title: '硬解模式',
leading: const Icon(Icons.memory_outlined),
getSubtitle: () => '当前:${Pref.hardwareDecoding}此项即mpv的--hwdec',
onTap: (setState) async {
onTap: (context, setState) async {
final result = await showDialog<List<String>>(
context: Get.context!,
context: context,
builder: (context) {
return OrderedMultiSelectDialog<String>(
title: '硬解模式',