mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-24 10:08:41 +00:00
refa fav/group panel
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/data.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/models_new/fav/fav_folder/list.dart';
|
||||
import 'package:PiliPlus/pages/common/common_intro_controller.dart';
|
||||
import 'package:PiliPlus/utils/fav_util.dart';
|
||||
import 'package:PiliPlus/utils/feed_back.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -8,11 +10,11 @@ import 'package:get/get.dart';
|
||||
class FavPanel extends StatefulWidget {
|
||||
const FavPanel({
|
||||
super.key,
|
||||
this.ctr,
|
||||
required this.ctr,
|
||||
this.scrollController,
|
||||
});
|
||||
|
||||
final dynamic ctr;
|
||||
final CommonIntroController ctr;
|
||||
final ScrollController? scrollController;
|
||||
|
||||
@override
|
||||
@@ -20,12 +22,66 @@ class FavPanel extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FavPanelState extends State<FavPanel> {
|
||||
late Future _futureBuilderFuture;
|
||||
LoadingState loadingState = LoadingState.loading();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilderFuture = widget.ctr.queryVideoInFolder();
|
||||
_query();
|
||||
}
|
||||
|
||||
Future<void> _query() async {
|
||||
var res = await widget.ctr.queryVideoInFolder();
|
||||
if (mounted) {
|
||||
if (res['status']) {
|
||||
loadingState = const Success(null);
|
||||
} else {
|
||||
loadingState = Error(res['msg']);
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
Widget get _buildBody {
|
||||
return switch (loadingState) {
|
||||
Loading() => loadingWidget,
|
||||
Success() => ListView.builder(
|
||||
controller: widget.scrollController,
|
||||
itemCount: widget.ctr.favFolderData.value.list!.length,
|
||||
itemBuilder: (context, index) {
|
||||
FavFolderInfo item = widget.ctr.favFolderData.value.list![index];
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: ListTile(
|
||||
onTap: () => setState(
|
||||
() => widget.ctr.onChoose(item.favState != 1, index)),
|
||||
dense: true,
|
||||
leading: FavUtil.isPublicFav(item.attr)
|
||||
? const Icon(Icons.folder_outlined)
|
||||
: const Icon(Icons.lock_outline),
|
||||
minLeadingWidth: 0,
|
||||
title: Text(item.title),
|
||||
subtitle: Text(
|
||||
'${item.mediaCount}个内容 . ${FavUtil.isPublicFavText(item.attr)}',
|
||||
),
|
||||
trailing: Transform.scale(
|
||||
scale: 0.9,
|
||||
child: Checkbox(
|
||||
value: item.favState == 1,
|
||||
onChanged: (bool? checkValue) =>
|
||||
setState(() => widget.ctr.onChoose(checkValue!, index)),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Error(:var errMsg) => scrollErrorWidget(
|
||||
controller: widget.scrollController,
|
||||
errMsg: errMsg,
|
||||
onReload: _query,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -45,7 +101,7 @@ class _FavPanelState extends State<FavPanel> {
|
||||
TextButton.icon(
|
||||
onPressed: () => Get.toNamed('/createFav')?.then((data) {
|
||||
if (data != null) {
|
||||
(widget.ctr?.favFolderData as Rx<FavFolderData>)
|
||||
widget.ctr.favFolderData
|
||||
..value.list?.insert(1, data)
|
||||
..refresh();
|
||||
}
|
||||
@@ -64,83 +120,7 @@ class _FavPanelState extends State<FavPanel> {
|
||||
const SizedBox(width: 16),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (BuildContext context, AsyncSnapshot snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
// TODO: refactor
|
||||
if (snapshot.data is! Map) {
|
||||
return HttpError(
|
||||
isSliver: false,
|
||||
onReload: () => setState(() {
|
||||
_futureBuilderFuture = widget.ctr.queryVideoInFolder();
|
||||
}),
|
||||
);
|
||||
}
|
||||
Map data = snapshot.data as Map;
|
||||
if (data['status']) {
|
||||
return Obx(
|
||||
() => ListView.builder(
|
||||
controller: widget.scrollController,
|
||||
itemCount: widget.ctr.favFolderData.value.list.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: ListTile(
|
||||
onTap: () => widget.ctr.onChoose(
|
||||
widget.ctr.favFolderData.value.list[index]
|
||||
.favState !=
|
||||
1,
|
||||
index),
|
||||
dense: true,
|
||||
leading: FavUtil.isPublicFav(widget
|
||||
.ctr.favFolderData.value.list[index].attr)
|
||||
? const Icon(Icons.folder_outlined)
|
||||
: const Icon(Icons.lock_outline),
|
||||
minLeadingWidth: 0,
|
||||
title: Text(widget
|
||||
.ctr.favFolderData.value.list[index].title!),
|
||||
subtitle: Text(
|
||||
'${widget.ctr.favFolderData.value.list[index].mediaCount}个内容 . ${FavUtil.isPublicFavText(widget.ctr.favFolderData.value.list[index].attr)}',
|
||||
),
|
||||
trailing: Transform.scale(
|
||||
scale: 0.9,
|
||||
child: Checkbox(
|
||||
value: widget.ctr.favFolderData.value
|
||||
.list[index].favState ==
|
||||
1,
|
||||
onChanged: (bool? checkValue) =>
|
||||
widget.ctr.onChoose(checkValue!, index),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return CustomScrollView(
|
||||
controller: widget.scrollController,
|
||||
slivers: [
|
||||
HttpError(
|
||||
errMsg: data['msg'],
|
||||
onReload: () => setState(() {
|
||||
_futureBuilderFuture =
|
||||
widget.ctr.queryVideoInFolder();
|
||||
}),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(child: _buildBody),
|
||||
Divider(
|
||||
height: 1,
|
||||
color: theme.disabledColor.withValues(alpha: 0.08),
|
||||
|
||||
Reference in New Issue
Block a user