mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
80 lines
2.4 KiB
Dart
80 lines
2.4 KiB
Dart
import 'package:PiliPlus/http/loading_state.dart';
|
|
import 'package:PiliPlus/http/live.dart';
|
|
import 'package:PiliPlus/models/live/follow.dart';
|
|
import 'package:PiliPlus/models/live/item.dart';
|
|
import 'package:PiliPlus/pages/common/common_list_controller.dart';
|
|
import 'package:PiliPlus/utils/extension.dart';
|
|
import 'package:PiliPlus/utils/storage.dart';
|
|
import 'package:get/get_rx/src/rx_types/rx_types.dart';
|
|
|
|
class LiveController
|
|
extends CommonListController<List<LiveItemModel>?, LiveItemModel> {
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
queryData();
|
|
if (isLogin.value) {
|
|
fetchLiveFollowing();
|
|
}
|
|
}
|
|
|
|
@override
|
|
Future<LoadingState<List<LiveItemModel>?>> customGetData() =>
|
|
LiveHttp.liveList(pn: currentPage);
|
|
|
|
@override
|
|
Future onRefresh() {
|
|
fetchLiveFollowing();
|
|
return super.onRefresh();
|
|
}
|
|
|
|
late RxBool isLogin = Accounts.main.isLogin.obs;
|
|
late Rx<LoadingState> followListState = LoadingState.loading().obs;
|
|
late int followPage = 1;
|
|
late bool followEnd = false;
|
|
late RxInt liveCount = 0.obs;
|
|
|
|
Future fetchLiveFollowing([bool isRefresh = true]) async {
|
|
if (isRefresh.not && followEnd) {
|
|
return;
|
|
}
|
|
if (isRefresh) {
|
|
followPage = 1;
|
|
followEnd = false;
|
|
}
|
|
dynamic res = await LiveHttp.liveFollowing(pn: followPage, ps: 20);
|
|
if (res['status']) {
|
|
LiveFollowingModel data = res['data'];
|
|
liveCount.value = data.liveCount ?? 0;
|
|
List<LiveFollowingItemModel>? dataList = data.list
|
|
?.where((LiveFollowingItemModel item) =>
|
|
item.liveStatus == 1 && item.recordLiveTime == 0)
|
|
.toList();
|
|
if (dataList.isNullOrEmpty) {
|
|
followEnd = true;
|
|
if (isRefresh) {
|
|
followListState.value = LoadingState.success(dataList);
|
|
}
|
|
return;
|
|
}
|
|
if (isRefresh) {
|
|
if (dataList!.length >= liveCount.value) {
|
|
followEnd = true;
|
|
}
|
|
followListState.value = LoadingState.success(dataList);
|
|
} else if (followListState.value is Success) {
|
|
List<LiveFollowingItemModel> list =
|
|
(followListState.value as Success).response;
|
|
list.addAll(dataList!);
|
|
if (list.length >= liveCount.value) {
|
|
followEnd = true;
|
|
}
|
|
followListState.refresh();
|
|
}
|
|
followPage++;
|
|
} else if (isRefresh) {
|
|
followListState.value = LoadingState.error(res['msg']);
|
|
}
|
|
}
|
|
}
|