mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-20 17:16:29 +08:00
merge mine & media
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
import 'package:PiliPlus/http/fav.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/models/common/account_type.dart';
|
||||
import 'package:PiliPlus/models/common/theme/theme_type.dart';
|
||||
import 'package:PiliPlus/models/user/info.dart';
|
||||
import 'package:PiliPlus/models/user/stat.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/data.dart';
|
||||
import 'package:PiliPlus/pages/common/common_data_controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
import 'package:PiliPlus/utils/accounts/account.dart';
|
||||
@@ -14,14 +18,17 @@ import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
|
||||
|
||||
class MineController extends GetxController {
|
||||
class MineController
|
||||
extends CommonDataController<FavFolderData, FavFolderData> {
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
int? favFoldercount;
|
||||
|
||||
// 用户信息 头像、昵称、lv
|
||||
Rx<UserInfoData> userInfo = UserInfoData().obs;
|
||||
// 用户状态 动态、关注、粉丝
|
||||
Rx<UserStat> userStat = UserStat().obs;
|
||||
|
||||
AccountService accountService = Get.find<AccountService>();
|
||||
|
||||
Rx<ThemeType> themeType = ThemeType.system.obs;
|
||||
static RxBool anonymity =
|
||||
(Accounts.account.isNotEmpty &&
|
||||
@@ -30,33 +37,73 @@ class MineController extends GetxController {
|
||||
ThemeType get nextThemeType =>
|
||||
ThemeType.values[(themeType.value.index + 1) % ThemeType.values.length];
|
||||
|
||||
late final list = <({IconData icon, String title, VoidCallback onTap})>[
|
||||
(
|
||||
icon: Icons.history,
|
||||
title: '观看记录',
|
||||
onTap: () {
|
||||
if (isLogin) {
|
||||
Get.toNamed('/history');
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
icon: Icons.subscriptions_outlined,
|
||||
title: '我的订阅',
|
||||
onTap: () {
|
||||
if (isLogin) {
|
||||
Get.toNamed('/subscription');
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
icon: Icons.watch_later_outlined,
|
||||
title: '稍后再看',
|
||||
onTap: () {
|
||||
if (isLogin) {
|
||||
Get.toNamed('/later');
|
||||
}
|
||||
},
|
||||
),
|
||||
(
|
||||
icon: Icons.create_outlined,
|
||||
title: '创作中心',
|
||||
onTap: () {
|
||||
if (isLogin) {
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
'url': 'https://member.bilibili.com/platform/home',
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
UserInfoData? userInfoCache = GStorage.userInfo.get('userInfoCache');
|
||||
if (userInfoCache != null) {
|
||||
userInfo.value = userInfoCache;
|
||||
queryData();
|
||||
queryUserInfo();
|
||||
}
|
||||
}
|
||||
|
||||
void onLogin([bool longPress = false]) {
|
||||
if (!accountService.isLogin.value || longPress) {
|
||||
Get.toNamed('/loginPage', preventDuplicates: false);
|
||||
} else {
|
||||
Get.toNamed(
|
||||
'/member?mid=${userInfo.value.mid}',
|
||||
preventDuplicates: false,
|
||||
);
|
||||
bool get isLogin {
|
||||
if (!accountService.isLogin.value) {
|
||||
// SmartDialog.showToast('账号未登录');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> queryUserInfo() async {
|
||||
if (!accountService.isLogin.value) {
|
||||
return;
|
||||
}
|
||||
var res = await UserHttp.userInfo();
|
||||
if (res['status']) {
|
||||
UserInfoData data = res['data'];
|
||||
if (res.isSuccess) {
|
||||
UserInfoData data = res.data;
|
||||
if (data.isLogin == true) {
|
||||
userInfo.value = data;
|
||||
GStorage.userInfo.put('userInfoCache', data);
|
||||
@@ -70,8 +117,9 @@ class MineController extends GetxController {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
if (res['msg'] == '账号未登录') {
|
||||
final errMsg = res.toString();
|
||||
SmartDialog.showToast(errMsg);
|
||||
if (errMsg == '账号未登录') {
|
||||
LoginUtils.onLogoutMain();
|
||||
return;
|
||||
}
|
||||
@@ -86,6 +134,22 @@ class MineController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool customHandleResponse(bool isRefresh, Success<FavFolderData> response) {
|
||||
favFoldercount = response.response.count;
|
||||
loadingState.value = response;
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState<FavFolderData>> customGetData() {
|
||||
return FavHttp.userfavFolder(
|
||||
pn: 1,
|
||||
ps: 5,
|
||||
mid: accountService.mid,
|
||||
);
|
||||
}
|
||||
|
||||
static void onChangeAnonymity() {
|
||||
if (Accounts.account.isEmpty) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
@@ -202,37 +266,31 @@ class MineController extends GetxController {
|
||||
void onChangeTheme() {
|
||||
final newVal = nextThemeType;
|
||||
themeType.value = newVal;
|
||||
try {
|
||||
Get.find<MineController>().themeType.value = newVal;
|
||||
} catch (_) {}
|
||||
GStorage.setting.put(SettingBoxKey.themeMode, newVal.index);
|
||||
Get.changeThemeMode(newVal.toThemeMode);
|
||||
}
|
||||
|
||||
void pushFollow() {
|
||||
if (!accountService.isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
void push(String name) {
|
||||
late final mid = userInfo.value.mid;
|
||||
if (isLogin && mid != null) {
|
||||
Get.toNamed('/$name?mid=$mid');
|
||||
}
|
||||
Get.toNamed('/follow?mid=${userInfo.value.mid}', preventDuplicates: false);
|
||||
}
|
||||
|
||||
void pushFans() {
|
||||
if (!accountService.isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
void onLogin([bool longPress = false]) {
|
||||
if (!accountService.isLogin.value || longPress) {
|
||||
Get.toNamed('/loginPage');
|
||||
} else {
|
||||
Get.toNamed('/member?mid=${userInfo.value.mid}');
|
||||
}
|
||||
Get.toNamed('/fan?mid=${userInfo.value.mid}', preventDuplicates: false);
|
||||
}
|
||||
|
||||
void pushDynamic() {
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
if (!accountService.isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
return Future.value();
|
||||
}
|
||||
Get.toNamed(
|
||||
'/memberDynamics?mid=${userInfo.value.mid}',
|
||||
preventDuplicates: false,
|
||||
);
|
||||
queryUserInfo();
|
||||
return super.onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user