opt: 数据初始化
This commit is contained in:
@ -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;
|
||||
}
|
100
lib/utils/global_data_cache.dart
Normal file
100
lib/utils/global_data_cache.dart
Normal file
@ -0,0 +1,100 @@
|
||||
import 'package:hive/hive.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;
|
||||
|
||||
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;
|
||||
|
||||
// 私有构造函数
|
||||
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);
|
||||
}
|
||||
}
|
@ -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