mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-24 11:06:51 +08:00
mod: bangumi: load more followlist
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/pages/common/common_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/http/bangumi.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
@@ -7,33 +10,76 @@ import 'package:PiliPlus/utils/storage.dart';
|
||||
class BangumiController extends CommonController {
|
||||
bool isLoadingMore = true;
|
||||
RxBool isLogin = false.obs;
|
||||
late int mid;
|
||||
int? mid;
|
||||
dynamic userInfo;
|
||||
|
||||
Rx<LoadingState> followState = LoadingState.loading().obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
userInfo = GStorage.userInfo.get('userInfoCache');
|
||||
if (userInfo != null) {
|
||||
mid = userInfo.mid;
|
||||
}
|
||||
mid = userInfo?.mid;
|
||||
isLogin.value = userInfo != null;
|
||||
|
||||
queryData();
|
||||
queryBangumiFollow();
|
||||
}
|
||||
|
||||
// 我的订阅
|
||||
Future queryBangumiFollow() async {
|
||||
userInfo = userInfo ?? GStorage.userInfo.get('userInfoCache');
|
||||
if (userInfo != null) {
|
||||
followState.value = await BangumiHttp.bangumiFollow(mid: userInfo.mid);
|
||||
if (isLogin.value) {
|
||||
followController = ScrollController();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() =>
|
||||
BangumiHttp.bangumiList(page: currentPage);
|
||||
Future onRefresh() {
|
||||
if (isLogin.value) {
|
||||
followPage = 1;
|
||||
followEnd = false;
|
||||
}
|
||||
return super.onRefresh();
|
||||
}
|
||||
|
||||
late int followPage = 1;
|
||||
late RxInt followCount = (-1).obs;
|
||||
late bool followLoading = false;
|
||||
late bool followEnd = false;
|
||||
late Rx<LoadingState> followState = LoadingState.loading().obs;
|
||||
ScrollController? followController;
|
||||
|
||||
// 我的订阅
|
||||
Future queryBangumiFollow([bool isRefresh = true]) async {
|
||||
if (isLogin.value.not || followLoading || (isRefresh.not && followEnd)) {
|
||||
return;
|
||||
}
|
||||
followLoading = true;
|
||||
dynamic res = await BangumiHttp.bangumiFollow(
|
||||
mid: mid,
|
||||
type: 1,
|
||||
pn: followPage,
|
||||
);
|
||||
if (res is Success) {
|
||||
BangumiListDataModel data = res.response;
|
||||
followPage++;
|
||||
followEnd = data.hasNext == 0 || data.list.isNullOrEmpty;
|
||||
followCount.value = data.total ?? -1;
|
||||
if (isRefresh.not && followState.value is Success) {
|
||||
data.list?.insertAll(0, (followState.value as Success).response);
|
||||
}
|
||||
followState.value = LoadingState.success(data.list);
|
||||
if (isRefresh) {
|
||||
followController?.animToTop();
|
||||
}
|
||||
} else {
|
||||
followState.value = res;
|
||||
}
|
||||
followLoading = false;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => BangumiHttp.bangumiList(
|
||||
page: currentPage,
|
||||
);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
followController?.dispose();
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user