Merge branch 'opt-dataInt'

This commit is contained in:
guozhigq
2024-11-20 22:46:20 +08:00
22 changed files with 79 additions and 84 deletions

View File

@ -48,7 +48,7 @@ class NetworkImgLayer extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
int defaultImgQuality = 10; int defaultImgQuality = 10;
try { try {
defaultImgQuality = GlobalDataCache().imgQuality; defaultImgQuality = GlobalDataCache.imgQuality;
} catch (_) {} } catch (_) {}
if (src == '' || src == null) { if (src == '' || src == null) {

View File

@ -26,7 +26,7 @@ class MemberHttp {
}) async { }) async {
String? wWebid; String? wWebid;
if ((await getWWebid(mid: mid))['status']) { if ((await getWWebid(mid: mid))['status']) {
wWebid = GlobalDataCache().wWebid; wWebid = GlobalDataCache.wWebid;
} }
Map params = await WbiSign().makSign({ Map params = await WbiSign().makSign({
@ -574,7 +574,7 @@ class MemberHttp {
} }
static Future getWWebid({required int mid}) async { static Future getWWebid({required int mid}) async {
String? wWebid = GlobalDataCache().wWebid; String? wWebid = GlobalDataCache.wWebid;
if (wWebid != null) { if (wWebid != null) {
return {'status': true, 'data': wWebid}; return {'status': true, 'data': wWebid};
} }
@ -588,7 +588,7 @@ class MemberHttp {
final content = match.group(1); final content = match.group(1);
String decodedString = Uri.decodeComponent(content!); String decodedString = Uri.decodeComponent(content!);
Map<String, dynamic> map = jsonDecode(decodedString); Map<String, dynamic> map = jsonDecode(decodedString);
GlobalDataCache().wWebid = map['access_id']; GlobalDataCache.wWebid = map['access_id'];
return {'status': true, 'data': map['access_id']}; return {'status': true, 'data': map['access_id']};
} else { } else {
return {'status': false, 'data': '请检查登录状态'}; return {'status': false, 'data': '请检查登录状态'};
@ -605,7 +605,7 @@ class MemberHttp {
}) async { }) async {
String? wWebid; String? wWebid;
if ((await getWWebid(mid: mid))['status']) { if ((await getWWebid(mid: mid))['status']) {
wWebid = GlobalDataCache().wWebid; wWebid = GlobalDataCache.wWebid;
} }
Map params = await WbiSign().makSign({ Map params = await WbiSign().makSign({
'host_mid': mid, 'host_mid': mid,

View File

@ -65,7 +65,7 @@ void main() async {
} }
PiliSchame.init(); PiliSchame.init();
await GlobalDataCache().initialize(); await GlobalDataCache.initialize();
} }
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {

View File

@ -173,7 +173,7 @@ class _UpPanelState extends State<UpPanel> {
if (data.type == 'up') { if (data.type == 'up') {
EasyThrottle.throttle('follow', const Duration(milliseconds: 300), EasyThrottle.throttle('follow', const Duration(milliseconds: 300),
() { () {
if (GlobalDataCache().enableDynamicSwitch) { if (GlobalDataCache.enableDynamicSwitch) {
onClickUp(data, i); onClickUp(data, i);
} else { } else {
onClickUpAni(data, i); onClickUpAni(data, i);

View File

@ -125,7 +125,7 @@ class _MainAppState extends State<MainApp> with SingleTickerProviderStateMixin {
double sheetHeight = MediaQuery.sizeOf(context).height - double sheetHeight = MediaQuery.sizeOf(context).height -
MediaQuery.of(context).padding.top - MediaQuery.of(context).padding.top -
MediaQuery.sizeOf(context).width * 9 / 16; MediaQuery.sizeOf(context).width * 9 / 16;
GlobalDataCache().sheetHeight = sheetHeight; GlobalDataCache.sheetHeight = sheetHeight;
localCache.put('sheetHeight', sheetHeight); localCache.put('sheetHeight', sheetHeight);
localCache.put('statusBarHeight', statusBarHeight); localCache.put('statusBarHeight', statusBarHeight);

View File

@ -28,9 +28,8 @@ class MemberArchiveController extends GetxController {
super.onInit(); super.onInit();
mid = int.parse(Get.parameters['mid']!); mid = int.parse(Get.parameters['mid']!);
currentOrder.value = orderList.first; currentOrder.value = orderList.first;
ownerMid = GlobalDataCache().userInfo != null ownerMid =
? GlobalDataCache().userInfo!.mid! GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1;
: -1;
isOwner.value = mid == -1 || mid == ownerMid; isOwner.value = mid == -1 || mid == ownerMid;
} }

View File

@ -20,9 +20,8 @@ class MemberArticleController extends GetxController {
void onInit() { void onInit() {
super.onInit(); super.onInit();
mid = int.parse(Get.parameters['mid']!); mid = int.parse(Get.parameters['mid']!);
ownerMid = GlobalDataCache().userInfo != null ownerMid =
? GlobalDataCache().userInfo!.mid! GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1;
: -1;
isOwner.value = mid == -1 || mid == ownerMid; isOwner.value = mid == -1 || mid == ownerMid;
} }

View File

@ -18,9 +18,8 @@ class MemberDynamicsController extends GetxController {
void onInit() { void onInit() {
super.onInit(); super.onInit();
mid = int.parse(Get.parameters['mid']!); mid = int.parse(Get.parameters['mid']!);
ownerMid = GlobalDataCache().userInfo != null ownerMid =
? GlobalDataCache().userInfo!.mid! GlobalDataCache.userInfo != null ? GlobalDataCache.userInfo!.mid! : -1;
: -1;
isOwner.value = mid == -1 || mid == ownerMid; isOwner.value = mid == -1 || mid == ownerMid;
} }

View File

@ -59,7 +59,7 @@ class MemberSeasonsController extends GetxController {
mid: mid, mid: mid,
seriesId: seriesId!, seriesId: seriesId!,
pn: pn, pn: pn,
currentMid: GlobalDataCache().userInfo?.mid ?? -1, currentMid: GlobalDataCache.userInfo?.mid ?? -1,
); );
if (res['status']) { if (res['status']) {
seasonsList.addAll(res['data'].seriesList); seasonsList.addAll(res['data'].seriesList);

View File

@ -43,10 +43,10 @@ class SSearchController extends GetxController {
hintText = hint; hintText = hint;
} }
} }
historyCacheList = GlobalDataCache().historyCacheList; historyCacheList = GlobalDataCache.historyCacheList;
historyList.value = historyCacheList; historyList.value = historyCacheList;
enableHotKey = setting.get(SettingBoxKey.enableHotKey, defaultValue: true); enableHotKey = setting.get(SettingBoxKey.enableHotKey, defaultValue: true);
enableSearchSuggest = GlobalDataCache().enableSearchSuggest; enableSearchSuggest = GlobalDataCache.enableSearchSuggest;
} }
void onChange(value) { void onChange(value) {
@ -128,7 +128,7 @@ class SSearchController extends GetxController {
historyCacheList = []; historyCacheList = [];
historyList.refresh(); historyList.refresh();
localCache.put('cacheList', []); localCache.put('cacheList', []);
GlobalDataCache().historyCacheList = []; GlobalDataCache.historyCacheList = [];
SmartDialog.showToast('搜索历史已清空'); SmartDialog.showToast('搜索历史已清空');
} }
@ -139,7 +139,7 @@ class SSearchController extends GetxController {
historyList.value = historyCacheList; historyList.value = historyCacheList;
historyList.refresh(); historyList.refresh();
localCache.put('cacheList', historyCacheList); localCache.put('cacheList', historyCacheList);
GlobalDataCache().historyCacheList = historyCacheList; GlobalDataCache.historyCacheList = historyCacheList;
searchFocusNode.unfocus(); searchFocusNode.unfocus();
} }
} }

View File

@ -146,7 +146,7 @@ class _ExtraSettingState extends State<ExtraSetting> {
setKey: SettingBoxKey.enableSearchSuggest, setKey: SettingBoxKey.enableSearchSuggest,
defaultVal: true, defaultVal: true,
callFn: (val) { callFn: (val) {
GlobalDataCache().enableSearchSuggest = val; GlobalDataCache.enableSearchSuggest = val;
}, },
), ),
SetSwitchItem( SetSwitchItem(
@ -181,7 +181,7 @@ class _ExtraSettingState extends State<ExtraSetting> {
setKey: SettingBoxKey.enableAutoExpand, setKey: SettingBoxKey.enableAutoExpand,
defaultVal: false, defaultVal: false,
callFn: (val) { callFn: (val) {
GlobalDataCache().enableAutoExpand = val; GlobalDataCache.enableAutoExpand = val;
}, },
), ),
const SetSwitchItem( const SetSwitchItem(

View File

@ -38,7 +38,7 @@ class _ActionMenuSetPageState extends State<ActionMenuSetPage> {
.map<String>((i) => (i['value'] as ActionType).value) .map<String>((i) => (i['value'] as ActionType).value)
.toList(); .toList();
setting.put(SettingBoxKey.actionTypeSort, sortedTabbar); setting.put(SettingBoxKey.actionTypeSort, sortedTabbar);
GlobalDataCache().actionTypeSort = sortedTabbar; GlobalDataCache.actionTypeSort = sortedTabbar;
SmartDialog.showToast('操作成功'); SmartDialog.showToast('操作成功');
} }

View File

@ -58,11 +58,11 @@ class _PlayGesturePageState extends State<PlayGesturePage> {
}, },
); );
if (result != null) { if (result != null) {
GlobalDataCache().fullScreenGestureMode = FullScreenGestureMode GlobalDataCache.fullScreenGestureMode = FullScreenGestureMode
.values .values
.firstWhere((element) => element.values == result); .firstWhere((element) => element.values == result);
fullScreenGestureMode = fullScreenGestureMode =
GlobalDataCache().fullScreenGestureMode.index; GlobalDataCache.fullScreenGestureMode.index;
setting.put( setting.put(
SettingBoxKey.fullScreenGestureMode, fullScreenGestureMode); SettingBoxKey.fullScreenGestureMode, fullScreenGestureMode);
SmartDialog.showToast('设置成功'); SmartDialog.showToast('设置成功');

View File

@ -155,7 +155,7 @@ class _PlaySettingState extends State<PlaySetting> {
setKey: SettingBoxKey.enablePlayerControlAnimation, setKey: SettingBoxKey.enablePlayerControlAnimation,
defaultVal: true, defaultVal: true,
callFn: (bool val) { callFn: (bool val) {
GlobalDataCache().enablePlayerControlAnimation = val; GlobalDataCache.enablePlayerControlAnimation = val;
}), }),
SetSwitchItem( SetSwitchItem(
title: '港澳台模式', title: '港澳台模式',

View File

@ -175,7 +175,7 @@ class _StyleSettingState extends State<StyleSetting> {
SettingBoxKey.defaultPicQa, picQuality); SettingBoxKey.defaultPicQa, picQuality);
Get.back(); Get.back();
settingController.picQuality.value = picQuality; settingController.picQuality.value = picQuality;
GlobalDataCache().imgQuality = picQuality; GlobalDataCache.imgQuality = picQuality;
SmartDialog.showToast('设置成功'); SmartDialog.showToast('设置成功');
}, },
child: const Text('确定'), child: const Text('确定'),

View File

@ -169,8 +169,8 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
owner = widget.videoDetail!.owner; owner = widget.videoDetail!.owner;
enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true); enableAi = setting.get(SettingBoxKey.enableAi, defaultValue: true);
_expandableCtr = ExpandableController( _expandableCtr =
initialExpanded: GlobalDataCache().enableAutoExpand); ExpandableController(initialExpanded: GlobalDataCache.enableAutoExpand);
} }
// 收藏 // 收藏
@ -556,7 +556,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
} }
Widget actionGrid(BuildContext context, videoIntroController) { Widget actionGrid(BuildContext context, videoIntroController) {
final actionTypeSort = GlobalDataCache().actionTypeSort; final actionTypeSort = GlobalDataCache.actionTypeSort;
Map<String, Widget> menuListWidgets = { Map<String, Widget> menuListWidgets = {
'like': Obx( 'like': Obx(

View File

@ -52,7 +52,7 @@ class ReplyItem extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final bool isOwner = int.parse(replyItem!.member!.mid!) == final bool isOwner = int.parse(replyItem!.member!.mid!) ==
(GlobalDataCache().userInfo?.mid ?? -1); (GlobalDataCache.userInfo?.mid ?? -1);
return Material( return Material(
child: InkWell( child: InkWell(
// 点击整个评论区 评论详情/回复 // 点击整个评论区 评论详情/回复
@ -415,7 +415,7 @@ class ReplyItemRow extends StatelessWidget {
onLongPress: () { onLongPress: () {
feedBack(); feedBack();
final bool isOwner = int.parse(replyItem!.member!.mid!) == final bool isOwner = int.parse(replyItem!.member!.mid!) ==
(GlobalDataCache().userInfo?.mid ?? -1); (GlobalDataCache.userInfo?.mid ?? -1);
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
useRootNavigator: true, useRootNavigator: true,

View File

@ -18,7 +18,7 @@ class AiDetail extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: const EdgeInsets.only(left: 16, right: 16), padding: const EdgeInsets.only(left: 16, right: 16),
height: GlobalDataCache().sheetHeight, height: GlobalDataCache.sheetHeight,
child: Column( child: Column(
children: [ children: [
_buildHeader(context), _buildHeader(context),

View File

@ -278,19 +278,18 @@ class PlPlayerController {
// 添加一个私有构造函数 // 添加一个私有构造函数
PlPlayerController._internal(this.videoType) { PlPlayerController._internal(this.videoType) {
final cache = GlobalDataCache(); isOpenDanmu.value = GlobalDataCache.isOpenDanmu;
isOpenDanmu.value = cache.isOpenDanmu; blockTypes = GlobalDataCache.blockTypes;
blockTypes = cache.blockTypes; showArea = GlobalDataCache.showArea;
showArea = cache.showArea; opacityVal = GlobalDataCache.opacityVal;
opacityVal = cache.opacityVal; fontSizeVal = GlobalDataCache.fontSizeVal;
fontSizeVal = cache.fontSizeVal; danmakuDurationVal = GlobalDataCache.danmakuDurationVal;
danmakuDurationVal = cache.danmakuDurationVal; strokeWidth = GlobalDataCache.strokeWidth;
strokeWidth = cache.strokeWidth; playRepeat = GlobalDataCache.playRepeat;
playRepeat = cache.playRepeat; _playbackSpeed.value = GlobalDataCache.playbackSpeed;
_playbackSpeed.value = cache.playbackSpeed; enableAutoLongPressSpeed = GlobalDataCache.enableAutoLongPressSpeed;
enableAutoLongPressSpeed = cache.enableAutoLongPressSpeed; _longPressSpeed.value = GlobalDataCache.longPressSpeed;
_longPressSpeed.value = cache.longPressSpeed; speedsList = GlobalDataCache.speedsList;
speedsList = cache.speedsList;
// _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) { // _playerEventSubs = onPlayerStatusChanged.listen((PlayerStatus status) {
// if (status == PlayerStatus.playing) { // if (status == PlayerStatus.playing) {
// WakelockPlus.enable(); // WakelockPlus.enable();
@ -1047,13 +1046,12 @@ class PlPlayerController {
/// 缓存本次弹幕选项 /// 缓存本次弹幕选项
cacheDanmakuOption() { cacheDanmakuOption() {
final cache = GlobalDataCache(); GlobalDataCache.blockTypes = blockTypes;
cache.blockTypes = blockTypes; GlobalDataCache.showArea = showArea;
cache.showArea = showArea; GlobalDataCache.opacityVal = opacityVal;
cache.opacityVal = opacityVal; GlobalDataCache.fontSizeVal = fontSizeVal;
cache.fontSizeVal = fontSizeVal; GlobalDataCache.danmakuDurationVal = danmakuDurationVal;
cache.danmakuDurationVal = danmakuDurationVal; GlobalDataCache.strokeWidth = strokeWidth;
cache.strokeWidth = strokeWidth;
localCache.put(LocalCacheKey.danmakuBlockType, blockTypes); localCache.put(LocalCacheKey.danmakuBlockType, blockTypes);
localCache.put(LocalCacheKey.danmakuShowArea, showArea); localCache.put(LocalCacheKey.danmakuShowArea, showArea);

View File

@ -89,7 +89,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
late bool enableBackgroundPlay; late bool enableBackgroundPlay;
late double screenWidth; late double screenWidth;
final FullScreenGestureMode fullScreenGestureMode = final FullScreenGestureMode fullScreenGestureMode =
GlobalDataCache().fullScreenGestureMode; GlobalDataCache.fullScreenGestureMode;
// 用于记录上一次全屏切换手势触发时间,避免误触 // 用于记录上一次全屏切换手势触发时间,避免误触
DateTime? lastFullScreenToggleTime; DateTime? lastFullScreenToggleTime;
@ -136,7 +136,7 @@ class _PLVideoPlayerState extends State<PLVideoPlayer>
screenWidth = Get.size.width; screenWidth = Get.size.width;
animationController = AnimationController( animationController = AnimationController(
vsync: this, vsync: this,
duration: GlobalDataCache().enablePlayerControlAnimation duration: GlobalDataCache.enablePlayerControlAnimation
? const Duration(milliseconds: 150) ? const Duration(milliseconds: 150)
: const Duration(milliseconds: 10), : const Duration(milliseconds: 10),
); );

View File

@ -11,48 +11,48 @@ Box videoStorage = GStorage.video;
Box userInfoCache = GStorage.userInfo; Box userInfoCache = GStorage.userInfo;
class GlobalDataCache { class GlobalDataCache {
late int imgQuality; static late int imgQuality;
late FullScreenGestureMode fullScreenGestureMode; static late FullScreenGestureMode fullScreenGestureMode;
late bool enablePlayerControlAnimation; static late bool enablePlayerControlAnimation;
late List<String> actionTypeSort; static late List<String> actionTypeSort;
late double sheetHeight; static late double sheetHeight;
String? wWebid; static String? wWebid;
/// 播放器相关 /// 播放器相关
// 弹幕开关 // 弹幕开关
late bool isOpenDanmu; static late bool isOpenDanmu;
// 弹幕屏蔽类型 // 弹幕屏蔽类型
late List<dynamic> blockTypes; static late List<dynamic> blockTypes;
// 弹幕展示区域 // 弹幕展示区域
late double showArea; static late double showArea;
// 弹幕透明度 // 弹幕透明度
late double opacityVal; static late double opacityVal;
// 弹幕字体大小 // 弹幕字体大小
late double fontSizeVal; static late double fontSizeVal;
// 弹幕显示时间 // 弹幕显示时间
late double danmakuDurationVal; static late double danmakuDurationVal;
// 弹幕描边宽度 // 弹幕描边宽度
late double strokeWidth; static late double strokeWidth;
// 播放器循环模式 // 播放器循环模式
late PlayRepeat playRepeat; static late PlayRepeat playRepeat;
// 播放器默认播放速度 // 播放器默认播放速度
late double playbackSpeed; static late double playbackSpeed;
// 播放器自动长按速度 // 播放器自动长按速度
late bool enableAutoLongPressSpeed; static late bool enableAutoLongPressSpeed;
// 播放器长按速度 // 播放器长按速度
late double longPressSpeed; static late double longPressSpeed;
// 播放器速度列表 // 播放器速度列表
late List<double> speedsList; static late List<double> speedsList;
// 用户信息 // 用户信息
UserInfoData? userInfo; static UserInfoData? userInfo;
// 搜索历史 // 搜索历史
late List historyCacheList; static late List historyCacheList;
// // 搜索建议
late bool enableSearchSuggest = true; static late bool enableSearchSuggest;
// 简介默认展开 // 简介默认展开
late bool enableAutoExpand = false; static late bool enableAutoExpand;
// // 动态切换
late bool enableDynamicSwitch = true; static late bool enableDynamicSwitch;
// 私有构造函数 // 私有构造函数
GlobalDataCache._(); GlobalDataCache._();
@ -64,7 +64,7 @@ class GlobalDataCache {
factory GlobalDataCache() => _instance; factory GlobalDataCache() => _instance;
// 异步初始化方法 // 异步初始化方法
Future<void> initialize() async { static Future<void> initialize() async {
imgQuality = await setting.get(SettingBoxKey.defaultPicQa, imgQuality = await setting.get(SettingBoxKey.defaultPicQa,
defaultValue: 10); // 设置全局变量 defaultValue: 10); // 设置全局变量
fullScreenGestureMode = FullScreenGestureMode.values[setting.get( fullScreenGestureMode = FullScreenGestureMode.values[setting.get(

View File

@ -118,7 +118,7 @@ class LoginUtils {
Request.dio.options.headers['cookie'] = ''; Request.dio.options.headers['cookie'] = '';
userInfoCache.put('userInfoCache', null); userInfoCache.put('userInfoCache', null);
localCache.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''}); localCache.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''});
GlobalDataCache().userInfo = null; GlobalDataCache.userInfo = null;
await refreshLoginStatus(false); await refreshLoginStatus(false);
} }
} }