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) {
int defaultImgQuality = 10;
try {
defaultImgQuality = GlobalDataCache().imgQuality;
defaultImgQuality = GlobalDataCache.imgQuality;
} catch (_) {}
if (src == '' || src == null) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -11,48 +11,48 @@ Box videoStorage = GStorage.video;
Box userInfoCache = GStorage.userInfo;
class GlobalDataCache {
late int imgQuality;
late FullScreenGestureMode fullScreenGestureMode;
late bool enablePlayerControlAnimation;
late List<String> actionTypeSort;
late double sheetHeight;
String? wWebid;
static late int imgQuality;
static late FullScreenGestureMode fullScreenGestureMode;
static late bool enablePlayerControlAnimation;
static late List<String> actionTypeSort;
static late double sheetHeight;
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;
//
late bool enableSearchSuggest = true;
static late List historyCacheList;
// 搜索建议
static late bool enableSearchSuggest;
// 简介默认展开
late bool enableAutoExpand = false;
//
late bool enableDynamicSwitch = true;
static late bool enableAutoExpand;
// 动态切换
static late bool enableDynamicSwitch;
// 私有构造函数
GlobalDataCache._();
@ -64,7 +64,7 @@ class GlobalDataCache {
factory GlobalDataCache() => _instance;
// 异步初始化方法
Future<void> initialize() async {
static Future<void> initialize() async {
imgQuality = await setting.get(SettingBoxKey.defaultPicQa,
defaultValue: 10); // 设置全局变量
fullScreenGestureMode = FullScreenGestureMode.values[setting.get(

View File

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