mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
mod: 侧边栏、动态重构,排行改为首页分区,平板、折叠屏、竖屏视频新适配,播放页可隐藏黑边、截图、点踩,弹幕粗细调整,默认关闭后台播放,弹窗接受返回
This commit is contained in:
76
lib/pages/dynamics/tab/controller.dart
Normal file
76
lib/pages/dynamics/tab/controller.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
// import 'package:hive/hive.dart';
|
||||
|
||||
import '../../../http/dynamics.dart';
|
||||
import '../../../models/dynamics/result.dart';
|
||||
// import '../../../utils/storage.dart';
|
||||
|
||||
class DynamicsTabController extends GetxController {
|
||||
String offset = '';
|
||||
ScrollController scrollController = ScrollController();
|
||||
RxList<DynamicItemModel> dynamicsList = <DynamicItemModel>[].obs;
|
||||
RxBool isLoadingMore = false.obs;
|
||||
String dynamicsType = 'all';
|
||||
// Box userInfoCache = GStrorage.userInfo;
|
||||
// bool userLogin = false;
|
||||
int mid = -1;
|
||||
|
||||
Future queryFollowDynamic(String type, String dynamicsType, int? mid) async {
|
||||
this.dynamicsType = dynamicsType;
|
||||
if (mid != null) this.mid = mid;
|
||||
if (type != 'onLoad') {
|
||||
dynamicsList.clear();
|
||||
offset = '';
|
||||
}
|
||||
// // 下拉刷新数据渲染时会触发onLoad
|
||||
// if (type == 'onLoad' && page == 1) {
|
||||
// return;
|
||||
// }
|
||||
isLoadingMore.value = true;
|
||||
var res = await DynamicsHttp.followDynamic(
|
||||
type: dynamicsType == "up" ? "all" : dynamicsType,
|
||||
offset: offset,
|
||||
mid: dynamicsType == "up" ? mid : -1,
|
||||
);
|
||||
isLoadingMore.value = false;
|
||||
if (res['status']) {
|
||||
if (type == 'onLoad' && res['data'].items.isEmpty) {
|
||||
SmartDialog.showToast('没有更多了');
|
||||
return;
|
||||
}
|
||||
if (type == 'onLoad') {
|
||||
dynamicsList.addAll(res['data'].items);
|
||||
} else {
|
||||
dynamicsList.value = res['data'].items;
|
||||
}
|
||||
// print('dynamicsList: $dynamicsList');
|
||||
dynamicsList.refresh();
|
||||
offset = res['data'].offset;
|
||||
// print("page: $page[dynamicsType]!");
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// 下拉刷新
|
||||
Future onRefresh() async {
|
||||
await queryFollowDynamic('onRefresh', dynamicsType, mid);
|
||||
}
|
||||
|
||||
// 上拉加载
|
||||
Future onLoad() async {
|
||||
await queryFollowDynamic('onLoad', dynamicsType, mid);
|
||||
}
|
||||
|
||||
// 返回顶部并刷新
|
||||
void animateToTop() async {
|
||||
if (scrollController.offset >=
|
||||
MediaQuery.of(Get.context!).size.height * 5) {
|
||||
scrollController.jumpTo(0);
|
||||
} else {
|
||||
await scrollController.animateTo(0,
|
||||
duration: const Duration(milliseconds: 500), curve: Curves.easeInOut);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user