mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-10 03:00:13 +08:00
@@ -2,27 +2,36 @@ import 'package:PiliPlus/http/fav.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/pgc.dart';
|
||||
import 'package:PiliPlus/models/common/home_tab_type.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_pgc/data.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_pgc/list.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_index_result/list.dart';
|
||||
import 'package:PiliPlus/models_new/pgc/pgc_timeline/result.dart';
|
||||
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
||||
import 'package:PiliPlus/services/account_service.dart';
|
||||
import 'package:PiliPlus/utils/extension/scroll_controller_ext.dart';
|
||||
import 'package:PiliPlus/utils/storage_pref.dart';
|
||||
import 'package:flutter/widgets.dart' show ScrollController;
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class PgcController
|
||||
extends CommonListController<List<PgcIndexItem>?, PgcIndexItem>
|
||||
class PgcController extends CommonListController<FavPgcData, FavPgcItemModel>
|
||||
with AccountMixin {
|
||||
PgcController({required this.tabType})
|
||||
: indexType = tabType == HomeTabType.cinema ? 102 : null;
|
||||
PgcController({required HomeTabType tabType}) {
|
||||
switch (tabType) {
|
||||
case .bangumi:
|
||||
type = 1;
|
||||
showPgcTimeline = Pref.showPgcTimeline;
|
||||
case .cinema:
|
||||
type = 2;
|
||||
indexType = 102;
|
||||
showPgcTimeline = false;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
final HomeTabType tabType;
|
||||
final int? indexType;
|
||||
|
||||
late final showPgcTimeline =
|
||||
tabType == HomeTabType.bangumi && Pref.showPgcTimeline;
|
||||
int? indexType;
|
||||
late final int type;
|
||||
late final int tabType;
|
||||
late final bool showPgcTimeline;
|
||||
// follow
|
||||
late final RxInt followCount = (-1).obs;
|
||||
|
||||
@override
|
||||
final accountService = Get.find<AccountService>();
|
||||
@@ -32,7 +41,6 @@ class PgcController
|
||||
super.onInit();
|
||||
|
||||
queryData();
|
||||
queryPgcFollow();
|
||||
if (showPgcTimeline) {
|
||||
queryPgcTimeline();
|
||||
}
|
||||
@@ -40,30 +48,12 @@ class PgcController
|
||||
|
||||
@override
|
||||
Future<void> onRefresh() {
|
||||
if (accountService.isLogin.value) {
|
||||
_refreshPgcFollow();
|
||||
}
|
||||
if (showPgcTimeline) {
|
||||
queryPgcTimeline();
|
||||
}
|
||||
return super.onRefresh();
|
||||
return super.onRefresh().whenComplete(scrollController.jumpToTop);
|
||||
}
|
||||
|
||||
void _refreshPgcFollow() {
|
||||
followPage = 1;
|
||||
followEnd = false;
|
||||
queryPgcFollow();
|
||||
}
|
||||
|
||||
// follow
|
||||
late int followPage = 1;
|
||||
late RxInt followCount = (-1).obs;
|
||||
late bool followLoading = false;
|
||||
late bool followEnd = false;
|
||||
late Rx<LoadingState<List<FavPgcItemModel>?>> followState =
|
||||
LoadingState<List<FavPgcItemModel>?>.loading().obs;
|
||||
final followController = ScrollController();
|
||||
|
||||
// timeline
|
||||
late Rx<LoadingState<List<TimelineResult>?>> timelineState =
|
||||
LoadingState<List<TimelineResult>?>.loading().obs;
|
||||
@@ -86,70 +76,22 @@ class PgcController
|
||||
timelineState.value = Success(list1 ?? list2);
|
||||
}
|
||||
|
||||
// 我的订阅
|
||||
Future<void> queryPgcFollow([bool isRefresh = true]) async {
|
||||
if (!accountService.isLogin.value ||
|
||||
followLoading ||
|
||||
(!isRefresh && followEnd)) {
|
||||
return;
|
||||
}
|
||||
followLoading = true;
|
||||
final res = await FavHttp.favPgc(
|
||||
type: tabType == HomeTabType.bangumi ? 1 : 2,
|
||||
pn: followPage,
|
||||
);
|
||||
|
||||
if (res case Success(:final response)) {
|
||||
final list = response.list;
|
||||
followCount.value = response.total ?? -1;
|
||||
|
||||
if (list == null || list.isEmpty) {
|
||||
followEnd = true;
|
||||
if (isRefresh) {
|
||||
followState.value = Success(list);
|
||||
}
|
||||
followLoading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (isRefresh) {
|
||||
if (list.length >= followCount.value) {
|
||||
followEnd = true;
|
||||
}
|
||||
followState.value = Success(list);
|
||||
followController.jumpToTop();
|
||||
} else if (followState.value case Success(:final response)) {
|
||||
final currentList = response!..addAll(list);
|
||||
if (currentList.length >= followCount.value) {
|
||||
followEnd = true;
|
||||
}
|
||||
followState.refresh();
|
||||
}
|
||||
followPage++;
|
||||
} else if (isRefresh) {
|
||||
followState.value = res as Error;
|
||||
}
|
||||
followLoading = false;
|
||||
}
|
||||
@override
|
||||
Future<LoadingState<FavPgcData>> customGetData() =>
|
||||
FavHttp.favPgc(type: type, pn: page);
|
||||
|
||||
@override
|
||||
Future<LoadingState<List<PgcIndexItem>?>> customGetData() => PgcHttp.pgcIndex(
|
||||
page: page,
|
||||
indexType: indexType,
|
||||
);
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
followController.dispose();
|
||||
super.onClose();
|
||||
List<FavPgcItemModel>? getDataList(FavPgcData response) {
|
||||
followCount.value = response.total ?? 0;
|
||||
return response.list;
|
||||
}
|
||||
|
||||
@override
|
||||
void onChangeAccount(bool isLogin) {
|
||||
if (isLogin) {
|
||||
_refreshPgcFollow();
|
||||
onRefresh();
|
||||
} else {
|
||||
followState.value = LoadingState.loading();
|
||||
loadingState.value = LoadingState.loading();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user