mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
@@ -1,143 +0,0 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/user.dart';
|
||||
import 'package:PiliPlus/models/user/fav_folder.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/widgets/item.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavFolderSortPage extends StatefulWidget {
|
||||
const FavFolderSortPage({super.key, required this.favController});
|
||||
|
||||
final FavController favController;
|
||||
|
||||
@override
|
||||
State<FavFolderSortPage> createState() => _FavFolderSortPageState();
|
||||
}
|
||||
|
||||
class _FavFolderSortPageState extends State<FavFolderSortPage> {
|
||||
FavController get _favController => widget.favController;
|
||||
|
||||
final GlobalKey _key = GlobalKey();
|
||||
late List<FavFolderItemData> sortList = List<FavFolderItemData>.from(
|
||||
(_favController.loadingState.value as Success).response);
|
||||
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
void listener() {
|
||||
if (_favController.isEnd) {
|
||||
return;
|
||||
}
|
||||
if (_scrollController.position.pixels >=
|
||||
_scrollController.position.maxScrollExtent - 200) {
|
||||
_favController.onLoadMore().then((_) {
|
||||
try {
|
||||
if (_favController.loadingState.value is Success) {
|
||||
List<FavFolderItemData> list =
|
||||
(_favController.loadingState.value as Success).response;
|
||||
sortList.addAll(list.sublist(sortList.length));
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
} catch (_) {}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (_favController.isEnd.not) {
|
||||
_scrollController.addListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.removeListener(listener);
|
||||
_scrollController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text('收藏夹排序'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
dynamic res = await UserHttp.sortFavFolder(
|
||||
sort: sortList.map((item) => item.id).toList(),
|
||||
);
|
||||
if (res['status']) {
|
||||
SmartDialog.showToast('排序完成');
|
||||
_favController.loadingState.value =
|
||||
LoadingState.success(sortList);
|
||||
Get.back();
|
||||
} else {
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
},
|
||||
child: const Text('完成'),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
bottom: false,
|
||||
child: _buildBody,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void onReorder(int oldIndex, int newIndex) {
|
||||
if (oldIndex == 0 || newIndex == 0) {
|
||||
SmartDialog.showToast('默认收藏夹不支持排序');
|
||||
return;
|
||||
}
|
||||
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
|
||||
final tabsItem = sortList.removeAt(oldIndex);
|
||||
sortList.insert(newIndex, tabsItem);
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
Widget get _buildBody {
|
||||
return ReorderableListView.builder(
|
||||
key: _key,
|
||||
scrollController: _scrollController,
|
||||
onReorder: onReorder,
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
footer: SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
itemCount: sortList.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = sortList[index];
|
||||
final key = item.id.toString();
|
||||
return SizedBox(
|
||||
key: Key(key),
|
||||
height: 98,
|
||||
child: FavItem(
|
||||
heroTag: key,
|
||||
favFolderItem: item,
|
||||
onLongPress: index == 0
|
||||
? () {
|
||||
SmartDialog.showToast('默认收藏夹不支持排序');
|
||||
}
|
||||
: null,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
library fav;
|
||||
|
||||
export 'controller.dart';
|
||||
export 'view.dart';
|
||||
@@ -1,17 +1,16 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models/user/fav_folder.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/controller.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/index.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/widgets/item.dart';
|
||||
|
||||
import '../../../common/constants.dart';
|
||||
import '../../../utils/grid.dart';
|
||||
|
||||
class FavVideoPage extends StatefulWidget {
|
||||
const FavVideoPage({super.key});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user