Merge branch 'opt-dataInt'
This commit is contained in:
@ -2,7 +2,7 @@ import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/utils/extension.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import '../../utils/storage.dart';
|
||||
import '../constants.dart';
|
||||
|
||||
@ -33,7 +33,7 @@ class NetworkImgLayer extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final int defaultImgQuality = GlobalData().imgQuality;
|
||||
final int defaultImgQuality = GlobalDataCache().imgQuality;
|
||||
if (src == '' || src == null) {
|
||||
return placeholder(context);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ import 'package:pilipala/pages/main/view.dart';
|
||||
import 'package:pilipala/services/service_locator.dart';
|
||||
import 'package:pilipala/utils/app_scheme.dart';
|
||||
import 'package:pilipala/utils/data.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
import 'package:pilipala/utils/recommend_filter.dart';
|
||||
@ -33,7 +33,6 @@ void main() async {
|
||||
await SystemChrome.setPreferredOrientations(
|
||||
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
|
||||
await GStrorage.init();
|
||||
await setupServiceLocator();
|
||||
clearLogs();
|
||||
Request();
|
||||
await Request.setCookie();
|
||||
@ -65,6 +64,7 @@ void main() async {
|
||||
}
|
||||
|
||||
PiliSchame.init();
|
||||
await GlobalDataCache().initialize();
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@ -266,10 +266,10 @@ class BuildMainApp extends StatelessWidget {
|
||||
VideoDetailPage.routeObserver,
|
||||
SearchPage.routeObserver,
|
||||
],
|
||||
onInit: () {
|
||||
onReady: () async {
|
||||
RecommendFilter();
|
||||
Data.init();
|
||||
GlobalData();
|
||||
setupServiceLocator();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import 'package:pilipala/pages/media/index.dart';
|
||||
import 'package:pilipala/pages/rank/index.dart';
|
||||
import 'package:pilipala/utils/event_bus.dart';
|
||||
import 'package:pilipala/utils/feed_back.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import './controller.dart';
|
||||
|
||||
@ -30,6 +29,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
|
||||
int? _lastSelectTime; //上次点击时间
|
||||
Box setting = GStrorage.setting;
|
||||
late bool enableMYBar;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -37,6 +37,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
_lastSelectTime = DateTime.now().millisecondsSinceEpoch;
|
||||
_mainController.pageController =
|
||||
PageController(initialPage: _mainController.selectedIndex);
|
||||
enableMYBar = setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
|
||||
}
|
||||
|
||||
void setIndex(int value) async {
|
||||
@ -171,7 +172,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
|
||||
curve: Curves.easeInOutCubicEmphasized,
|
||||
duration: const Duration(milliseconds: 500),
|
||||
offset: Offset(0, snapshot.data ? 0 : 1),
|
||||
child: GlobalData().enableMYBar
|
||||
child: enableMYBar
|
||||
? Obx(
|
||||
() => NavigationBar(
|
||||
onDestinationSelected: (value) => setIndex(value),
|
||||
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/models/common/action_type.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import '../../../utils/storage.dart';
|
||||
|
||||
class ActionMenuSetPage extends StatefulWidget {
|
||||
@ -38,7 +38,7 @@ class _ActionMenuSetPageState extends State<ActionMenuSetPage> {
|
||||
.map<String>((i) => (i['value'] as ActionType).value)
|
||||
.toList();
|
||||
setting.put(SettingBoxKey.actionTypeSort, sortedTabbar);
|
||||
GlobalData().actionTypeSort = sortedTabbar;
|
||||
GlobalDataCache().actionTypeSort = sortedTabbar;
|
||||
SmartDialog.showToast('操作成功');
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
|
||||
import '../../../models/common/gesture_mode.dart';
|
||||
import '../../../utils/storage.dart';
|
||||
@ -64,11 +64,11 @@ class _PlayGesturePageState extends State<PlayGesturePage> {
|
||||
},
|
||||
);
|
||||
if (result != null) {
|
||||
GlobalData().fullScreenGestureMode = FullScreenGestureMode
|
||||
GlobalDataCache().fullScreenGestureMode = FullScreenGestureMode
|
||||
.values
|
||||
.firstWhere((element) => element.values == result);
|
||||
fullScreenGestureMode =
|
||||
GlobalData().fullScreenGestureMode.index;
|
||||
GlobalDataCache().fullScreenGestureMode.index;
|
||||
setting.put(
|
||||
SettingBoxKey.fullScreenGestureMode, fullScreenGestureMode);
|
||||
setState(() {});
|
||||
|
@ -9,7 +9,7 @@ import 'package:pilipala/models/video/play/quality.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
import 'package:pilipala/services/service_locator.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
import '../../models/live/quality.dart';
|
||||
@ -162,7 +162,7 @@ class _PlaySettingState extends State<PlaySetting> {
|
||||
setKey: SettingBoxKey.enablePlayerControlAnimation,
|
||||
defaultVal: true,
|
||||
callFn: (bool val) {
|
||||
GlobalData().enablePlayerControlAnimation = val;
|
||||
GlobalDataCache().enablePlayerControlAnimation = val;
|
||||
}),
|
||||
SetSwitchItem(
|
||||
title: '港澳台模式',
|
||||
|
@ -8,7 +8,7 @@ import 'package:pilipala/models/common/theme_type.dart';
|
||||
import 'package:pilipala/pages/setting/pages/color_select.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/select_dialog.dart';
|
||||
import 'package:pilipala/pages/setting/widgets/slide_dialog.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
import '../../models/common/dynamic_badge_mode.dart';
|
||||
@ -176,7 +176,7 @@ class _StyleSettingState extends State<StyleSetting> {
|
||||
SettingBoxKey.defaultPicQa, picQuality);
|
||||
Get.back();
|
||||
settingController.picQuality.value = picQuality;
|
||||
GlobalData().imgQuality = picQuality;
|
||||
GlobalDataCache().imgQuality = picQuality;
|
||||
SmartDialog.showToast('设置成功');
|
||||
},
|
||||
child: const Text('确定'),
|
||||
|
@ -20,7 +20,7 @@ import 'package:pilipala/models/video_detail_res.dart';
|
||||
import 'package:pilipala/pages/video/detail/introduction/controller.dart';
|
||||
import 'package:pilipala/pages/video/detail/widgets/ai_detail.dart';
|
||||
import 'package:pilipala/utils/feed_back.dart';
|
||||
import 'package:pilipala/utils/global_data.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:pilipala/utils/utils.dart';
|
||||
import '../../../../http/user.dart';
|
||||
@ -569,7 +569,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
Widget actionGrid(BuildContext context, videoIntroController) {
|
||||
final actionTypeSort = GlobalData().actionTypeSort;
|
||||
final actionTypeSort = GlobalDataCache().actionTypeSort;
|
||||
|
||||
Widget progressWidget(progress) {
|
||||
return SizedBox(
|
||||
|
@ -18,6 +18,7 @@ import 'package:pilipala/plugin/pl_player/index.dart';
|
||||
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
|
||||
import 'package:pilipala/services/service_locator.dart';
|
||||
import 'package:pilipala/utils/feed_back.dart';
|
||||
import 'package:pilipala/utils/global_data_cache.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:screen_brightness/screen_brightness.dart';
|
||||
import 'package:status_bar_control/status_bar_control.dart';
|
||||
@ -277,50 +278,19 @@ class PlPlayerController {
|
||||
|
||||
// 添加一个私有构造函数
|
||||
PlPlayerController._internal(this.videoType) {
|
||||
isOpenDanmu.value =
|
||||
setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
blockTypes =
|
||||
localCache.get(LocalCacheKey.danmakuBlockType, defaultValue: []);
|
||||
showArea = localCache.get(LocalCacheKey.danmakuShowArea, defaultValue: 0.5);
|
||||
// 不透明度
|
||||
opacityVal =
|
||||
localCache.get(LocalCacheKey.danmakuOpacity, defaultValue: 1.0);
|
||||
// 字体大小
|
||||
fontSizeVal =
|
||||
localCache.get(LocalCacheKey.danmakuFontScale, defaultValue: 1.0);
|
||||
// 弹幕时间
|
||||
danmakuDurationVal =
|
||||
localCache.get(LocalCacheKey.danmakuDuration, defaultValue: 4.0);
|
||||
// 描边粗细
|
||||
strokeWidth = localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
|
||||
playRepeat = PlayRepeat.values.toList().firstWhere(
|
||||
(e) =>
|
||||
e.value ==
|
||||
videoStorage.get(VideoBoxKey.playRepeat,
|
||||
defaultValue: PlayRepeat.pause.value),
|
||||
);
|
||||
_playbackSpeed.value =
|
||||
videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
|
||||
enableAutoLongPressSpeed = setting
|
||||
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
|
||||
if (!enableAutoLongPressSpeed) {
|
||||
_longPressSpeed.value = videoStorage
|
||||
.get(VideoBoxKey.longPressSpeedDefault, defaultValue: 2.0);
|
||||
}
|
||||
// 自定义倍速集合
|
||||
speedsList = List<double>.from(videoStorage
|
||||
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
||||
// 默认倍速
|
||||
speedsList = List<double>.from(videoStorage
|
||||
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
||||
//playSpeedSystem
|
||||
final List<double> playSpeedSystem =
|
||||
videoStorage.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
|
||||
|
||||
// for (final PlaySpeed i in PlaySpeed.values) {
|
||||
speedsList.addAll(playSpeedSystem);
|
||||
// }
|
||||
|
||||
final cache = GlobalDataCache();
|
||||
isOpenDanmu.value = cache.isOpenDanmu;
|
||||
blockTypes = cache.blockTypes;
|
||||
showArea = cache.showArea;
|
||||
opacityVal = cache.opacityVal;
|
||||
fontSizeVal = cache.fontSizeVal;
|
||||
danmakuDurationVal = cache.danmakuDurationVal;
|
||||
strokeWidth = cache.strokeWidth;
|
||||
playRepeat = cache.playRepeat;
|
||||
_playbackSpeed.value = cache.playbackSpeed;
|
||||
enableAutoLongPressSpeed = cache.enableAutoLongPressSpeed;
|
||||
_longPressSpeed.value = cache.longPressSpeed;
|
||||
speedsList = cache.speedsList;
|
||||
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
|
||||
// if (status == PlayerStatus.playing) {
|
||||
// WakelockPlus.enable();
|
||||
|
@ -19,7 +19,7 @@ import 'package:pilipala/utils/feed_back.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:screen_brightness/screen_brightness.dart';
|
||||
|
||||
import '../../utils/global_data.dart';
|
||||
import '../../utils/global_data_cache.dart';
|
||||
import 'models/bottom_control_type.dart';
|
||||
import 'models/bottom_progress_behavior.dart';
|
||||
import 'widgets/app_bar_ani.dart';
|
||||
@ -87,7 +87,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
late bool enableBackgroundPlay;
|
||||
late double screenWidth;
|
||||
final FullScreenGestureMode fullScreenGestureMode =
|
||||
GlobalData().fullScreenGestureMode;
|
||||
GlobalDataCache().fullScreenGestureMode;
|
||||
|
||||
// 用于记录上一次全屏切换手势触发时间,避免误触
|
||||
DateTime? lastFullScreenToggleTime;
|
||||
@ -132,7 +132,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
|
||||
screenWidth = Get.size.width;
|
||||
animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: GlobalData().enablePlayerControlAnimation
|
||||
duration: GlobalDataCache().enablePlayerControlAnimation
|
||||
? const Duration(milliseconds: 150)
|
||||
: const Duration(milliseconds: 10),
|
||||
);
|
||||
|
@ -1,24 +0,0 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import '../models/common/index.dart';
|
||||
|
||||
Box setting = GStrorage.setting;
|
||||
|
||||
class GlobalData {
|
||||
int imgQuality = 10;
|
||||
FullScreenGestureMode fullScreenGestureMode =
|
||||
FullScreenGestureMode.values.last;
|
||||
bool enablePlayerControlAnimation = true;
|
||||
final bool enableMYBar =
|
||||
setting.get(SettingBoxKey.enableMYBar, defaultValue: true);
|
||||
List<String> actionTypeSort = setting.get(SettingBoxKey.actionTypeSort,
|
||||
defaultValue: ['like', 'coin', 'collect', 'watchLater', 'share']);
|
||||
// 私有构造函数
|
||||
GlobalData._();
|
||||
|
||||
// 单例实例
|
||||
static final GlobalData _instance = GlobalData._();
|
||||
|
||||
// 获取全局实例
|
||||
factory GlobalData() => _instance;
|
||||
}
|
106
lib/utils/global_data_cache.dart
Normal file
106
lib/utils/global_data_cache.dart
Normal file
@ -0,0 +1,106 @@
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/models/user/info.dart';
|
||||
import 'package:pilipala/plugin/pl_player/models/play_repeat.dart';
|
||||
import 'package:pilipala/plugin/pl_player/models/play_speed.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import '../models/common/index.dart';
|
||||
|
||||
Box setting = GStrorage.setting;
|
||||
Box localCache = GStrorage.localCache;
|
||||
Box videoStorage = GStrorage.video;
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
|
||||
class GlobalDataCache {
|
||||
late int imgQuality;
|
||||
late FullScreenGestureMode fullScreenGestureMode;
|
||||
late bool enablePlayerControlAnimation;
|
||||
late List<String> actionTypeSort;
|
||||
|
||||
/// 播放器相关
|
||||
// 弹幕开关
|
||||
late bool isOpenDanmu;
|
||||
// 弹幕屏蔽类型
|
||||
late List<dynamic> blockTypes;
|
||||
// 弹幕展示区域
|
||||
late double showArea;
|
||||
// 弹幕透明度
|
||||
late double opacityVal;
|
||||
// 弹幕字体大小
|
||||
late double fontSizeVal;
|
||||
// 弹幕显示时间
|
||||
late double danmakuDurationVal;
|
||||
// 弹幕描边宽度
|
||||
late double strokeWidth;
|
||||
// 播放器循环模式
|
||||
late PlayRepeat playRepeat;
|
||||
// 播放器默认播放速度
|
||||
late double playbackSpeed;
|
||||
// 播放器自动长按速度
|
||||
late bool enableAutoLongPressSpeed;
|
||||
// 播放器长按速度
|
||||
late double longPressSpeed;
|
||||
// 播放器速度列表
|
||||
late List<double> speedsList;
|
||||
// 用户信息
|
||||
UserInfoData? userInfo;
|
||||
|
||||
// 私有构造函数
|
||||
GlobalDataCache._();
|
||||
|
||||
// 单例实例
|
||||
static final GlobalDataCache _instance = GlobalDataCache._();
|
||||
|
||||
// 获取全局实例
|
||||
factory GlobalDataCache() => _instance;
|
||||
|
||||
// 异步初始化方法
|
||||
Future<void> initialize() async {
|
||||
imgQuality = await setting.get(SettingBoxKey.defaultPicQa,
|
||||
defaultValue: 10); // 设置全局变量
|
||||
fullScreenGestureMode = FullScreenGestureMode.values[setting.get(
|
||||
SettingBoxKey.fullScreenGestureMode,
|
||||
defaultValue: FullScreenGestureMode.values.last.index) as int];
|
||||
enablePlayerControlAnimation = setting
|
||||
.get(SettingBoxKey.enablePlayerControlAnimation, defaultValue: true);
|
||||
actionTypeSort = await setting.get(SettingBoxKey.actionTypeSort,
|
||||
defaultValue: ['like', 'coin', 'collect', 'watchLater', 'share']);
|
||||
|
||||
isOpenDanmu =
|
||||
await setting.get(SettingBoxKey.enableShowDanmaku, defaultValue: false);
|
||||
blockTypes =
|
||||
await localCache.get(LocalCacheKey.danmakuBlockType, defaultValue: []);
|
||||
showArea =
|
||||
await localCache.get(LocalCacheKey.danmakuShowArea, defaultValue: 0.5);
|
||||
opacityVal =
|
||||
await localCache.get(LocalCacheKey.danmakuOpacity, defaultValue: 1.0);
|
||||
fontSizeVal =
|
||||
await localCache.get(LocalCacheKey.danmakuFontScale, defaultValue: 1.0);
|
||||
danmakuDurationVal =
|
||||
await localCache.get(LocalCacheKey.danmakuDuration, defaultValue: 4.0);
|
||||
strokeWidth =
|
||||
await localCache.get(LocalCacheKey.strokeWidth, defaultValue: 1.5);
|
||||
|
||||
var defaultPlayRepeat = await videoStorage.get(VideoBoxKey.playRepeat,
|
||||
defaultValue: PlayRepeat.pause.value);
|
||||
playRepeat = PlayRepeat.values
|
||||
.toList()
|
||||
.firstWhere((e) => e.value == defaultPlayRepeat);
|
||||
playbackSpeed =
|
||||
await videoStorage.get(VideoBoxKey.playSpeedDefault, defaultValue: 1.0);
|
||||
enableAutoLongPressSpeed = await setting
|
||||
.get(SettingBoxKey.enableAutoLongPressSpeed, defaultValue: false);
|
||||
if (!enableAutoLongPressSpeed) {
|
||||
longPressSpeed = await videoStorage.get(VideoBoxKey.longPressSpeedDefault,
|
||||
defaultValue: 2.0);
|
||||
} else {
|
||||
longPressSpeed = 2.0;
|
||||
}
|
||||
speedsList = List<double>.from(await videoStorage
|
||||
.get(VideoBoxKey.customSpeedsList, defaultValue: <double>[]));
|
||||
final List<double> playSpeedSystem = await videoStorage
|
||||
.get(VideoBoxKey.playSpeedSystem, defaultValue: playSpeed);
|
||||
speedsList.addAll(playSpeedSystem);
|
||||
|
||||
userInfo = userInfoCache.get('userInfoCache');
|
||||
}
|
||||
}
|
@ -2,8 +2,6 @@ import 'dart:io';
|
||||
import 'package:hive_flutter/hive_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:pilipala/models/user/info.dart';
|
||||
import '../models/common/gesture_mode.dart';
|
||||
import 'global_data.dart';
|
||||
|
||||
class GStrorage {
|
||||
static late final Box<dynamic> userInfo;
|
||||
@ -42,13 +40,6 @@ class GStrorage {
|
||||
);
|
||||
// 视频设置
|
||||
video = await Hive.openBox('video');
|
||||
GlobalData().imgQuality =
|
||||
setting.get(SettingBoxKey.defaultPicQa, defaultValue: 10); // 设置全局变量
|
||||
GlobalData().fullScreenGestureMode = FullScreenGestureMode.values[
|
||||
setting.get(SettingBoxKey.fullScreenGestureMode,
|
||||
defaultValue: FullScreenGestureMode.values.last.index) as int];
|
||||
GlobalData().enablePlayerControlAnimation = setting
|
||||
.get(SettingBoxKey.enablePlayerControlAnimation, defaultValue: true);
|
||||
}
|
||||
|
||||
static void regAdapter() {
|
||||
|
Reference in New Issue
Block a user