opt: userInfoCache (#968)

This commit is contained in:
My-Responsitories
2025-08-09 13:36:48 +08:00
committed by GitHub
parent c75a68dacc
commit e77fe2587c
11 changed files with 54 additions and 19 deletions

View File

@@ -10,7 +10,6 @@ import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/accounts/account.dart';
import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
import 'package:PiliPlus/utils/global_data.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:archive/archive.dart';
@@ -52,7 +51,7 @@ class Request {
);
if (Accounts.main.isLogin) {
final coin = GStorage.userInfo.get('userInfoCache')?.money;
final coin = Pref.userInfoCache?.money;
if (coin == null) {
setCoin();
} else {

View File

@@ -111,6 +111,24 @@ class UserInfoData {
shopUrl = json['shop_url'];
isSeniorMember = json['is_senior_member'];
}
@override
int get hashCode => Object.hash(mid, uname, face, money, vipStatus);
@override
bool operator ==(Object other) {
return identical(this, other) ||
other is UserInfoData &&
isLogin == other.isLogin &&
face == other.face &&
levelInfo == other.levelInfo &&
mid == other.mid &&
money == other.money &&
uname == other.uname &&
vipDueDate == other.vipDueDate &&
vipStatus == other.vipStatus &&
isSeniorMember == other.isSeniorMember;
}
}
@HiveType(typeId: 5)
@@ -138,4 +156,13 @@ class LevelInfo {
? json['current_exp']
: json['next_exp'];
}
@override
int get hashCode => currentExp.hashCode;
@override
bool operator ==(Object other) {
return identical(this, other) ||
other is LevelInfo && currentExp == other.currentExp;
}
}

View File

@@ -28,7 +28,7 @@ import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/date_util.dart';
import 'package:PiliPlus/utils/duration_util.dart';
import 'package:PiliPlus/utils/id_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flutter/foundation.dart' show kDebugMode;
import 'package:flutter/material.dart' hide TabBarView;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@@ -385,7 +385,7 @@ class _EpisodePanelState extends CommonSlidePageState<EpisodePanel> {
child: InkWell(
onTap: () {
if (episode.badge == "会员") {
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
UserInfoData? userInfo = Pref.userInfoCache;
int vipStatus = userInfo?.vipStatus ?? 0;
if (vipStatus != 1) {
SmartDialog.showToast('需要大会员');

View File

@@ -15,6 +15,7 @@ import 'package:PiliPlus/utils/extension.dart';
import 'package:PiliPlus/utils/image_util.dart';
import 'package:PiliPlus/utils/page_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:dio/dio.dart';
@@ -89,7 +90,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
..name.value = data.name!
..face.value = data.face!;
try {
UserInfoData userInfo = GStorage.userInfo.get('userInfoCache')
UserInfoData userInfo = Pref.userInfoCache!
..uname = data.name
..face = data.face;
GStorage.userInfo.put('userInfoCache', userInfo);
@@ -386,7 +387,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
..coins = data.coins! - 6;
accountService.name.value = _textController.text;
try {
UserInfoData userInfo = GStorage.userInfo.get('userInfoCache')
UserInfoData userInfo = Pref.userInfoCache!
..uname = _textController.text;
GStorage.userInfo.put('userInfoCache', userInfo);
} catch (_) {}

View File

@@ -13,6 +13,7 @@ import 'package:PiliPlus/utils/accounts/account.dart';
import 'package:PiliPlus/utils/login_utils.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_key.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -82,7 +83,7 @@ class MineController
@override
void onInit() {
super.onInit();
UserInfoData? userInfoCache = GStorage.userInfo.get('userInfoCache');
UserInfoData? userInfoCache = Pref.userInfoCache;
if (userInfoCache != null) {
userInfo.value = userInfoCache;
queryData();
@@ -104,7 +105,9 @@ class MineController
UserInfoData data = res.data;
if (data.isLogin == true) {
userInfo.value = data;
GStorage.userInfo.put('userInfoCache', data);
if (data != Pref.userInfoCache) {
GStorage.userInfo.put('userInfoCache', data);
}
accountService
..mid = data.mid!
..name.value = data.uname!

View File

@@ -6,7 +6,7 @@ import 'package:PiliPlus/models_new/pgc/pgc_info_model/new_ep.dart';
import 'package:PiliPlus/models_new/video/video_detail/episode.dart'
hide EpisodeItem;
import 'package:PiliPlus/pages/video/controller.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:PiliPlus/utils/utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
@@ -50,7 +50,7 @@ class _PgcPanelState extends State<PgcPanel> {
currentIndex = widget.pages.indexWhere((e) => e.cid == cid);
scrollToIndex();
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
UserInfoData? userInfo = Pref.userInfoCache;
vipStatus = userInfo?.vipStatus ?? 0;
videoDetailCtr = Get.find<VideoDetailController>(tag: widget.heroTag);

View File

@@ -4,10 +4,9 @@ import 'package:PiliPlus/common/widgets/button/icon_button.dart';
import 'package:PiliPlus/http/danmaku.dart';
import 'package:PiliPlus/main.dart';
import 'package:PiliPlus/models/common/publish_panel_type.dart';
import 'package:PiliPlus/models/user/info.dart';
import 'package:PiliPlus/pages/common/publish/common_text_pub_page.dart';
import 'package:PiliPlus/pages/setting/slide_color_picker.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:canvas_danmaku/models/danmaku_content_item.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
@@ -72,8 +71,7 @@ class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
_mode = (widget.dmConfig?.mode ?? 1).obs;
_fontsize = (widget.dmConfig?.fontsize ?? 25).obs;
_color = (widget.dmConfig?.color ?? Colors.white).obs;
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
if (userInfo?.vipStatus == 1) {
if (Pref.userInfoCache?.vipStatus == 1) {
_colorList.add(Colors.transparent);
}
}

View File

@@ -1,5 +1,5 @@
import 'package:PiliPlus/models/user/info.dart';
import 'package:PiliPlus/utils/storage.dart' show GStorage;
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:get/get.dart';
class AccountService extends GetxService {
@@ -11,7 +11,7 @@ class AccountService extends GetxService {
@override
void onInit() {
super.onInit();
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
UserInfoData? userInfo = Pref.userInfoCache;
mid = userInfo?.mid ?? 0;
name = (userInfo?.uname ?? '').obs;
face = (userInfo?.face ?? '').obs;

View File

@@ -17,6 +17,7 @@ import 'package:PiliPlus/services/account_service.dart';
import 'package:PiliPlus/utils/accounts.dart';
import 'package:PiliPlus/utils/accounts/account.dart';
import 'package:PiliPlus/utils/storage.dart';
import 'package:PiliPlus/utils/storage_pref.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart' as web;
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
@@ -57,7 +58,9 @@ class LoginUtils {
..isLogin.value = true;
SmartDialog.showToast('main登录成功');
await GStorage.userInfo.put('userInfoCache', data);
if (data != Pref.userInfoCache) {
await GStorage.userInfo.put('userInfoCache', data);
}
try {
Get.find<MineController>().onRefresh();

View File

@@ -13,7 +13,7 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:path_provider/path_provider.dart';
class GStorage {
static late final Box<dynamic> userInfo;
static late final Box<UserInfoData> userInfo;
static late final Box<dynamic> historyWord;
static late final Box<dynamic> localCache;
static late final Box<dynamic> setting;
@@ -25,7 +25,7 @@ class GStorage {
await Hive.initFlutter('$path/hive');
regAdapter();
// 登录用户信息
userInfo = await Hive.openBox(
userInfo = await Hive.openBox<UserInfoData>(
'userInfo',
compactionStrategy: (int entries, int deletedEntries) {
return deletedEntries > 2;

View File

@@ -17,6 +17,7 @@ import 'package:PiliPlus/models/common/video/subtitle_pref_type.dart';
import 'package:PiliPlus/models/common/video/video_decode_type.dart';
import 'package:PiliPlus/models/common/video/video_quality.dart';
import 'package:PiliPlus/models/user/danmaku_rule.dart';
import 'package:PiliPlus/models/user/info.dart';
import 'package:PiliPlus/plugin/pl_player/models/bottom_progress_behavior.dart';
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.dart';
@@ -34,6 +35,9 @@ class Pref {
static final Box _video = GStorage.video;
static final Box _localCache = GStorage.localCache;
static UserInfoData? get userInfoCache =>
GStorage.userInfo.get('userInfoCache');
static List<double> get dynamicDetailRatio => List<double>.from(
_setting.get(
SettingBoxKey.dynamicDetailRatio,