mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 00:28:18 +08:00
opt: userInfoCache (#968)
This commit is contained in:
committed by
GitHub
parent
c75a68dacc
commit
e77fe2587c
@@ -10,7 +10,6 @@ import 'package:PiliPlus/utils/accounts.dart';
|
|||||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||||
import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
|
import 'package:PiliPlus/utils/accounts/account_manager/account_mgr.dart';
|
||||||
import 'package:PiliPlus/utils/global_data.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/storage_pref.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:archive/archive.dart';
|
import 'package:archive/archive.dart';
|
||||||
@@ -52,7 +51,7 @@ class Request {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (Accounts.main.isLogin) {
|
if (Accounts.main.isLogin) {
|
||||||
final coin = GStorage.userInfo.get('userInfoCache')?.money;
|
final coin = Pref.userInfoCache?.money;
|
||||||
if (coin == null) {
|
if (coin == null) {
|
||||||
setCoin();
|
setCoin();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -111,6 +111,24 @@ class UserInfoData {
|
|||||||
shopUrl = json['shop_url'];
|
shopUrl = json['shop_url'];
|
||||||
isSeniorMember = json['is_senior_member'];
|
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)
|
@HiveType(typeId: 5)
|
||||||
@@ -138,4 +156,13 @@ class LevelInfo {
|
|||||||
? json['current_exp']
|
? json['current_exp']
|
||||||
: json['next_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import 'package:PiliPlus/utils/accounts.dart';
|
|||||||
import 'package:PiliPlus/utils/date_util.dart';
|
import 'package:PiliPlus/utils/date_util.dart';
|
||||||
import 'package:PiliPlus/utils/duration_util.dart';
|
import 'package:PiliPlus/utils/duration_util.dart';
|
||||||
import 'package:PiliPlus/utils/id_utils.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/foundation.dart' show kDebugMode;
|
||||||
import 'package:flutter/material.dart' hide TabBarView;
|
import 'package:flutter/material.dart' hide TabBarView;
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
@@ -385,7 +385,7 @@ class _EpisodePanelState extends CommonSlidePageState<EpisodePanel> {
|
|||||||
child: InkWell(
|
child: InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
if (episode.badge == "会员") {
|
if (episode.badge == "会员") {
|
||||||
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
|
UserInfoData? userInfo = Pref.userInfoCache;
|
||||||
int vipStatus = userInfo?.vipStatus ?? 0;
|
int vipStatus = userInfo?.vipStatus ?? 0;
|
||||||
if (vipStatus != 1) {
|
if (vipStatus != 1) {
|
||||||
SmartDialog.showToast('需要大会员');
|
SmartDialog.showToast('需要大会员');
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import 'package:PiliPlus/utils/extension.dart';
|
|||||||
import 'package:PiliPlus/utils/image_util.dart';
|
import 'package:PiliPlus/utils/image_util.dart';
|
||||||
import 'package:PiliPlus/utils/page_utils.dart';
|
import 'package:PiliPlus/utils/page_utils.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
import 'package:PiliPlus/utils/utils.dart';
|
import 'package:PiliPlus/utils/utils.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
@@ -89,7 +90,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
|
|||||||
..name.value = data.name!
|
..name.value = data.name!
|
||||||
..face.value = data.face!;
|
..face.value = data.face!;
|
||||||
try {
|
try {
|
||||||
UserInfoData userInfo = GStorage.userInfo.get('userInfoCache')
|
UserInfoData userInfo = Pref.userInfoCache!
|
||||||
..uname = data.name
|
..uname = data.name
|
||||||
..face = data.face;
|
..face = data.face;
|
||||||
GStorage.userInfo.put('userInfoCache', userInfo);
|
GStorage.userInfo.put('userInfoCache', userInfo);
|
||||||
@@ -386,7 +387,7 @@ class _EditProfilePageState extends State<EditProfilePage> {
|
|||||||
..coins = data.coins! - 6;
|
..coins = data.coins! - 6;
|
||||||
accountService.name.value = _textController.text;
|
accountService.name.value = _textController.text;
|
||||||
try {
|
try {
|
||||||
UserInfoData userInfo = GStorage.userInfo.get('userInfoCache')
|
UserInfoData userInfo = Pref.userInfoCache!
|
||||||
..uname = _textController.text;
|
..uname = _textController.text;
|
||||||
GStorage.userInfo.put('userInfoCache', userInfo);
|
GStorage.userInfo.put('userInfoCache', userInfo);
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import 'package:PiliPlus/utils/accounts/account.dart';
|
|||||||
import 'package:PiliPlus/utils/login_utils.dart';
|
import 'package:PiliPlus/utils/login_utils.dart';
|
||||||
import 'package:PiliPlus/utils/storage.dart';
|
import 'package:PiliPlus/utils/storage.dart';
|
||||||
import 'package:PiliPlus/utils/storage_key.dart';
|
import 'package:PiliPlus/utils/storage_key.dart';
|
||||||
|
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -82,7 +83,7 @@ class MineController
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
UserInfoData? userInfoCache = GStorage.userInfo.get('userInfoCache');
|
UserInfoData? userInfoCache = Pref.userInfoCache;
|
||||||
if (userInfoCache != null) {
|
if (userInfoCache != null) {
|
||||||
userInfo.value = userInfoCache;
|
userInfo.value = userInfoCache;
|
||||||
queryData();
|
queryData();
|
||||||
@@ -104,7 +105,9 @@ class MineController
|
|||||||
UserInfoData data = res.data;
|
UserInfoData data = res.data;
|
||||||
if (data.isLogin == true) {
|
if (data.isLogin == true) {
|
||||||
userInfo.value = data;
|
userInfo.value = data;
|
||||||
|
if (data != Pref.userInfoCache) {
|
||||||
GStorage.userInfo.put('userInfoCache', data);
|
GStorage.userInfo.put('userInfoCache', data);
|
||||||
|
}
|
||||||
accountService
|
accountService
|
||||||
..mid = data.mid!
|
..mid = data.mid!
|
||||||
..name.value = data.uname!
|
..name.value = data.uname!
|
||||||
|
|||||||
@@ -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'
|
import 'package:PiliPlus/models_new/video/video_detail/episode.dart'
|
||||||
hide EpisodeItem;
|
hide EpisodeItem;
|
||||||
import 'package:PiliPlus/pages/video/controller.dart';
|
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:PiliPlus/utils/utils.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.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);
|
currentIndex = widget.pages.indexWhere((e) => e.cid == cid);
|
||||||
scrollToIndex();
|
scrollToIndex();
|
||||||
|
|
||||||
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
|
UserInfoData? userInfo = Pref.userInfoCache;
|
||||||
vipStatus = userInfo?.vipStatus ?? 0;
|
vipStatus = userInfo?.vipStatus ?? 0;
|
||||||
|
|
||||||
videoDetailCtr = Get.find<VideoDetailController>(tag: widget.heroTag);
|
videoDetailCtr = Get.find<VideoDetailController>(tag: widget.heroTag);
|
||||||
|
|||||||
@@ -4,10 +4,9 @@ import 'package:PiliPlus/common/widgets/button/icon_button.dart';
|
|||||||
import 'package:PiliPlus/http/danmaku.dart';
|
import 'package:PiliPlus/http/danmaku.dart';
|
||||||
import 'package:PiliPlus/main.dart';
|
import 'package:PiliPlus/main.dart';
|
||||||
import 'package:PiliPlus/models/common/publish_panel_type.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/common/publish/common_text_pub_page.dart';
|
||||||
import 'package:PiliPlus/pages/setting/slide_color_picker.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:canvas_danmaku/models/danmaku_content_item.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
import 'package:flutter/services.dart' show LengthLimitingTextInputFormatter;
|
||||||
@@ -72,8 +71,7 @@ class _SendDanmakuPanelState extends CommonTextPubPageState<SendDanmakuPanel> {
|
|||||||
_mode = (widget.dmConfig?.mode ?? 1).obs;
|
_mode = (widget.dmConfig?.mode ?? 1).obs;
|
||||||
_fontsize = (widget.dmConfig?.fontsize ?? 25).obs;
|
_fontsize = (widget.dmConfig?.fontsize ?? 25).obs;
|
||||||
_color = (widget.dmConfig?.color ?? Colors.white).obs;
|
_color = (widget.dmConfig?.color ?? Colors.white).obs;
|
||||||
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
|
if (Pref.userInfoCache?.vipStatus == 1) {
|
||||||
if (userInfo?.vipStatus == 1) {
|
|
||||||
_colorList.add(Colors.transparent);
|
_colorList.add(Colors.transparent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'package:PiliPlus/models/user/info.dart';
|
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';
|
import 'package:get/get.dart';
|
||||||
|
|
||||||
class AccountService extends GetxService {
|
class AccountService extends GetxService {
|
||||||
@@ -11,7 +11,7 @@ class AccountService extends GetxService {
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
UserInfoData? userInfo = GStorage.userInfo.get('userInfoCache');
|
UserInfoData? userInfo = Pref.userInfoCache;
|
||||||
mid = userInfo?.mid ?? 0;
|
mid = userInfo?.mid ?? 0;
|
||||||
name = (userInfo?.uname ?? '').obs;
|
name = (userInfo?.uname ?? '').obs;
|
||||||
face = (userInfo?.face ?? '').obs;
|
face = (userInfo?.face ?? '').obs;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import 'package:PiliPlus/services/account_service.dart';
|
|||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||||
import 'package:PiliPlus/utils/storage.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_inappwebview/flutter_inappwebview.dart' as web;
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
@@ -57,7 +58,9 @@ class LoginUtils {
|
|||||||
..isLogin.value = true;
|
..isLogin.value = true;
|
||||||
|
|
||||||
SmartDialog.showToast('main登录成功');
|
SmartDialog.showToast('main登录成功');
|
||||||
|
if (data != Pref.userInfoCache) {
|
||||||
await GStorage.userInfo.put('userInfoCache', data);
|
await GStorage.userInfo.put('userInfoCache', data);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Get.find<MineController>().onRefresh();
|
Get.find<MineController>().onRefresh();
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
class GStorage {
|
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> historyWord;
|
||||||
static late final Box<dynamic> localCache;
|
static late final Box<dynamic> localCache;
|
||||||
static late final Box<dynamic> setting;
|
static late final Box<dynamic> setting;
|
||||||
@@ -25,7 +25,7 @@ class GStorage {
|
|||||||
await Hive.initFlutter('$path/hive');
|
await Hive.initFlutter('$path/hive');
|
||||||
regAdapter();
|
regAdapter();
|
||||||
// 登录用户信息
|
// 登录用户信息
|
||||||
userInfo = await Hive.openBox(
|
userInfo = await Hive.openBox<UserInfoData>(
|
||||||
'userInfo',
|
'userInfo',
|
||||||
compactionStrategy: (int entries, int deletedEntries) {
|
compactionStrategy: (int entries, int deletedEntries) {
|
||||||
return deletedEntries > 2;
|
return deletedEntries > 2;
|
||||||
|
|||||||
@@ -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_decode_type.dart';
|
||||||
import 'package:PiliPlus/models/common/video/video_quality.dart';
|
import 'package:PiliPlus/models/common/video/video_quality.dart';
|
||||||
import 'package:PiliPlus/models/user/danmaku_rule.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/bottom_progress_behavior.dart';
|
||||||
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
|
import 'package:PiliPlus/plugin/pl_player/models/fullscreen_mode.dart';
|
||||||
import 'package:PiliPlus/plugin/pl_player/models/play_repeat.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 _video = GStorage.video;
|
||||||
static final Box _localCache = GStorage.localCache;
|
static final Box _localCache = GStorage.localCache;
|
||||||
|
|
||||||
|
static UserInfoData? get userInfoCache =>
|
||||||
|
GStorage.userInfo.get('userInfoCache');
|
||||||
|
|
||||||
static List<double> get dynamicDetailRatio => List<double>.from(
|
static List<double> get dynamicDetailRatio => List<double>.from(
|
||||||
_setting.get(
|
_setting.get(
|
||||||
SettingBoxKey.dynamicDetailRatio,
|
SettingBoxKey.dynamicDetailRatio,
|
||||||
|
|||||||
Reference in New Issue
Block a user