mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-06 09:13:48 +08:00
feat: fav pgc page
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -149,6 +149,9 @@ class _FavNoteChildPageState extends State<FavNoteChildPage>
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
_favNoteController.onLoadMore();
|
||||
}
|
||||
return FavNoteItem(
|
||||
item: loadingState.response[index],
|
||||
ctr: _favNoteController,
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/child_view.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/controller.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavNotePage extends StatefulWidget {
|
||||
const FavNotePage({super.key});
|
||||
@@ -62,30 +59,30 @@ class _FavNotePageState extends State<FavNotePage>
|
||||
],
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
onPressed: () async {
|
||||
final favNoteController = Get.find<FavNoteController>(
|
||||
tag: _tabController.index == 0 ? 'false' : 'true');
|
||||
if (favNoteController.enableMultiSelect.value) {
|
||||
favNoteController.onDisable();
|
||||
} else {
|
||||
if (favNoteController.loadingState.value is Success &&
|
||||
((favNoteController.loadingState.value as Success)
|
||||
.response as List?)
|
||||
?.isNotEmpty ==
|
||||
true) {
|
||||
favNoteController.enableMultiSelect.value = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('管理'),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// TextButton(
|
||||
// style: TextButton.styleFrom(
|
||||
// foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
// visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
// tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
// ),
|
||||
// onPressed: () async {
|
||||
// final favNoteController = Get.find<FavNoteController>(
|
||||
// tag: _tabController.index == 0 ? 'false' : 'true');
|
||||
// if (favNoteController.enableMultiSelect.value) {
|
||||
// favNoteController.onDisable();
|
||||
// } else {
|
||||
// if (favNoteController.loadingState.value is Success &&
|
||||
// ((favNoteController.loadingState.value as Success)
|
||||
// .response as List?)
|
||||
// ?.isNotEmpty ==
|
||||
// true) {
|
||||
// favNoteController.enableMultiSelect.value = true;
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// child: const Text('管理'),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
|
||||
@@ -18,123 +18,126 @@ class FavNoteItem extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
if (ctr.enableMultiSelect.value) {
|
||||
onSelect();
|
||||
return;
|
||||
}
|
||||
Utils.handleWebview(item['web_url'], inApp: true);
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
ctr.enableMultiSelect.value = true;
|
||||
onSelect();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: StyleString.safeSpace,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item['title'],
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
height: 1.4,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
if (ctr.enableMultiSelect.value) {
|
||||
onSelect();
|
||||
return;
|
||||
}
|
||||
Utils.handleWebview(item['web_url'], inApp: true);
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
ctr.enableMultiSelect.value = true;
|
||||
onSelect();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: StyleString.safeSpace,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
item['title'],
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
height: 1.4,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
item['summary'],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
Text(
|
||||
item['summary'],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
item['message'],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
Text(
|
||||
item['message'],
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (item['arc']?['pic'] != null) ...[
|
||||
const SizedBox(width: 10),
|
||||
AspectRatio(
|
||||
aspectRatio: StyleString.aspectRatio,
|
||||
child: LayoutBuilder(
|
||||
builder:
|
||||
(BuildContext context, BoxConstraints boxConstraints) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
src: item['arc']?['pic'],
|
||||
width: boxConstraints.maxWidth,
|
||||
height: boxConstraints.maxHeight,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item['checked'] == true ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: constraints.maxHeight,
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item['checked'] == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
if (item['arc']?['pic'] != null) ...[
|
||||
const SizedBox(width: 10),
|
||||
AspectRatio(
|
||||
aspectRatio: StyleString.aspectRatio,
|
||||
child: LayoutBuilder(
|
||||
builder:
|
||||
(BuildContext context, BoxConstraints boxConstraints) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
src: item['arc']?['pic'],
|
||||
width: boxConstraints.maxWidth,
|
||||
height: boxConstraints.maxHeight,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item['checked'] == true ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: constraints.maxHeight,
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item['checked'] == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -143,14 +146,14 @@ class FavNoteItem extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
217
lib/pages/fav/pgc/child_view.dart
Normal file
217
lib/pages/fav/pgc/child_view.dart
Normal file
@@ -0,0 +1,217 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/skeleton/video_card_h.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/controller.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/widget/item.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavPgcChildPage extends StatefulWidget {
|
||||
const FavPgcChildPage({
|
||||
super.key,
|
||||
required this.type,
|
||||
required this.followStatus,
|
||||
});
|
||||
|
||||
final int type;
|
||||
final int followStatus;
|
||||
|
||||
@override
|
||||
State<FavPgcChildPage> createState() => _FavPgcChildPageState();
|
||||
}
|
||||
|
||||
class _FavPgcChildPageState extends State<FavPgcChildPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late final FavPgcController _favPgcController = Get.put(
|
||||
FavPgcController(widget.type, widget.followStatus),
|
||||
tag: '${widget.type}${widget.followStatus}',
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) => Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _favPgcController.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
Obx(() => _buildBody(_favPgcController.loadingState.value)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: constraints.maxHeight,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: Obx(
|
||||
() => AnimatedSlide(
|
||||
offset: _favPgcController.enableMultiSelect.value
|
||||
? Offset(0, -1)
|
||||
: Offset.zero,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: Container(
|
||||
padding: MediaQuery.paddingOf(context),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
width: 0.5,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.outline
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
),
|
||||
),
|
||||
width: double.infinity,
|
||||
child: Row(
|
||||
children: [
|
||||
const SizedBox(width: 16),
|
||||
iconButton(
|
||||
size: 32,
|
||||
tooltip: '取消',
|
||||
context: context,
|
||||
icon: Icons.clear,
|
||||
onPressed: _favPgcController.onDisable,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Obx(
|
||||
() => Checkbox(
|
||||
value: _favPgcController.allSelected.value,
|
||||
onChanged: (value) {
|
||||
_favPgcController.handleSelect(
|
||||
!_favPgcController.allSelected.value);
|
||||
},
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
_favPgcController.handleSelect(
|
||||
!_favPgcController.allSelected.value);
|
||||
},
|
||||
child: const Text('全选'),
|
||||
),
|
||||
const Spacer(),
|
||||
...[
|
||||
{'followStatus': 1, 'title': '想看'},
|
||||
{'followStatus': 2, 'title': '在看'},
|
||||
{'followStatus': 3, 'title': '看过'},
|
||||
]
|
||||
.where((item) =>
|
||||
item['followStatus'] != widget.followStatus)
|
||||
.map(
|
||||
(Map item) => Padding(
|
||||
padding: const EdgeInsets.only(left: 25),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
_favPgcController
|
||||
.onUpdate(item['followStatus']);
|
||||
},
|
||||
child: Text(
|
||||
'标记为${item['title']}',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
mainAxisSpacing: 2,
|
||||
maxCrossAxisExtent: Grid.mediumCardWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.2,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
return const VideoCardHSkeleton();
|
||||
},
|
||||
childCount: 10,
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.paddingOf(context).bottom + 80),
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
mainAxisSpacing: 2,
|
||||
maxCrossAxisExtent: Grid.mediumCardWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.6,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
_favPgcController.onLoadMore();
|
||||
}
|
||||
return FavPgcItem(
|
||||
item: loadingState.response[index],
|
||||
ctr: _favPgcController,
|
||||
onSelect: () {
|
||||
_favPgcController.onSelect(index);
|
||||
},
|
||||
onUpdateStatus: () {
|
||||
showPgcFollowDialog(
|
||||
context: context,
|
||||
type: widget.type == 0 ? '追番' : '追剧',
|
||||
followStatus: widget.followStatus,
|
||||
onUpdateStatus: (followStatus) {
|
||||
if (followStatus == -1) {
|
||||
_favPgcController.bangumiDel(
|
||||
index,
|
||||
loadingState.response[index].seasonId,
|
||||
);
|
||||
} else {
|
||||
_favPgcController.bangumiUpdate(
|
||||
index,
|
||||
followStatus,
|
||||
loadingState.response[index].seasonId,
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
: HttpError(callback: _favPgcController.onReload),
|
||||
Error() => HttpError(
|
||||
errMsg: loadingState.errMsg,
|
||||
callback: _favPgcController.onReload,
|
||||
),
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
134
lib/pages/fav/pgc/controller.dart
Normal file
134
lib/pages/fav/pgc/controller.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
import 'package:PiliPlus/http/bangumi.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/http/video.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class FavPgcController extends MultiSelectController {
|
||||
final int type;
|
||||
final int followStatus;
|
||||
|
||||
FavPgcController(this.type, this.followStatus);
|
||||
|
||||
late final allSelected = false.obs;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
queryData();
|
||||
}
|
||||
|
||||
@override
|
||||
onSelect(int index) {
|
||||
List<BangumiListItemModel> list = (loadingState.value as Success).response;
|
||||
list[index].checked = !(list[index].checked ?? false);
|
||||
checkedCount.value = list.where((item) => item.checked == true).length;
|
||||
loadingState.value = LoadingState.success(list);
|
||||
allSelected.value = checkedCount.value == list.length;
|
||||
if (checkedCount.value == 0) {
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void handleSelect([bool checked = false]) {
|
||||
allSelected.value = checked;
|
||||
if (loadingState.value is Success) {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
if (list.isNotEmpty) {
|
||||
loadingState.value = LoadingState.success(list
|
||||
.map<BangumiListItemModel>((item) => item..checked = checked)
|
||||
.toList());
|
||||
checkedCount.value = checked ? list.length : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<LoadingState> customGetData() => BangumiHttp.bangumiFollowList(
|
||||
mid: Accounts.main.mid,
|
||||
type: type,
|
||||
followStatus: followStatus,
|
||||
pn: currentPage,
|
||||
);
|
||||
|
||||
void onDisable() {
|
||||
if (checkedCount.value != 0) {
|
||||
handleSelect();
|
||||
}
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
|
||||
// 取消追番
|
||||
Future bangumiDel(index, seasonId) async {
|
||||
var result = await VideoHttp.bangumiDel(seasonId: seasonId);
|
||||
if (result['status']) {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
}
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
|
||||
Future onUpdate(followStatus) async {
|
||||
List<BangumiListItemModel> dataList =
|
||||
(loadingState.value as Success).response as List<BangumiListItemModel>;
|
||||
Set<BangumiListItemModel> updateList =
|
||||
dataList.where((item) => item.checked == true).toSet();
|
||||
final res = await VideoHttp.bangumiUpdate(
|
||||
seasonId: updateList.map((item) => item.seasonId).toList(),
|
||||
status: followStatus,
|
||||
);
|
||||
if (res['status']) {
|
||||
List<BangumiListItemModel> remainList =
|
||||
dataList.toSet().difference(updateList).toList();
|
||||
loadingState.value = LoadingState.success(remainList);
|
||||
enableMultiSelect.value = false;
|
||||
try {
|
||||
final ctr = Get.find<FavPgcController>(tag: '$type$followStatus');
|
||||
if (ctr.loadingState.value is Success) {
|
||||
List<BangumiListItemModel> list =
|
||||
(ctr.loadingState.value as Success).response;
|
||||
list.insertAll(0, updateList.map((item) => item..checked = null));
|
||||
ctr.loadingState.value = LoadingState.success(list);
|
||||
ctr.allSelected.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('fav pgc onUpdate: $e');
|
||||
}
|
||||
}
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
|
||||
Future bangumiUpdate(index, followStatus, seasonId) async {
|
||||
var result = await VideoHttp.bangumiUpdate(
|
||||
seasonId: [seasonId],
|
||||
status: followStatus,
|
||||
);
|
||||
if (result['status']) {
|
||||
List<BangumiListItemModel> list =
|
||||
(loadingState.value as Success).response;
|
||||
final item = list.removeAt(index);
|
||||
loadingState.value = LoadingState.success(list);
|
||||
try {
|
||||
final ctr = Get.find<FavPgcController>(tag: '$type$followStatus');
|
||||
if (ctr.loadingState.value is Success) {
|
||||
List<BangumiListItemModel> list =
|
||||
(ctr.loadingState.value as Success).response;
|
||||
list.insert(0, item);
|
||||
ctr.loadingState.value = LoadingState.success(list);
|
||||
ctr.allSelected.value = false;
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('fav pgc bangumiUpdate: $e');
|
||||
}
|
||||
}
|
||||
SmartDialog.showToast(result['msg']);
|
||||
}
|
||||
}
|
||||
93
lib/pages/fav/pgc/view.dart
Normal file
93
lib/pages/fav/pgc/view.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:PiliPlus/pages/fav/pgc/child_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FavPgcPage extends StatefulWidget {
|
||||
const FavPgcPage({super.key, required this.type});
|
||||
|
||||
final int type;
|
||||
|
||||
@override
|
||||
State<FavPgcPage> createState() => _FavPgcPageState();
|
||||
}
|
||||
|
||||
class _FavPgcPageState extends State<FavPgcPage>
|
||||
with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
|
||||
late final TabController _tabController =
|
||||
TabController(length: 3, vsync: this, initialIndex: 1);
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TabBar(
|
||||
overlayColor: WidgetStateProperty.all(Colors.transparent),
|
||||
splashFactory: NoSplash.splashFactory,
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
controller: _tabController,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
dividerHeight: 0,
|
||||
indicatorWeight: 0,
|
||||
indicatorPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 3, vertical: 8),
|
||||
indicator: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
labelStyle: TabBarTheme.of(context)
|
||||
.labelStyle
|
||||
?.copyWith(fontSize: 14) ??
|
||||
const TextStyle(fontSize: 14),
|
||||
labelColor: Theme.of(context).colorScheme.onSecondaryContainer,
|
||||
unselectedLabelColor: Theme.of(context).colorScheme.outline,
|
||||
tabs: const [
|
||||
Tab(text: '想看'),
|
||||
Tab(text: '在看'),
|
||||
Tab(text: '看过'),
|
||||
],
|
||||
),
|
||||
),
|
||||
// TextButton(
|
||||
// style: TextButton.styleFrom(
|
||||
// foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
// visualDensity: VisualDensity(horizontal: -2, vertical: -2),
|
||||
// tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// child: const Text('管理'),
|
||||
// ),
|
||||
// const SizedBox(width: 12),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: List.generate(
|
||||
3,
|
||||
(index) => FavPgcChildPage(
|
||||
type: widget.type,
|
||||
followStatus: index + 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
186
lib/pages/fav/pgc/widget/item.dart
Normal file
186
lib/pages/fav/pgc/widget/item.dart
Normal file
@@ -0,0 +1,186 @@
|
||||
import 'package:PiliPlus/common/constants.dart';
|
||||
import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/icon_button.dart';
|
||||
import 'package:PiliPlus/common/widgets/network_img_layer.dart';
|
||||
import 'package:PiliPlus/models/bangumi/list.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select_controller.dart';
|
||||
import 'package:PiliPlus/utils/utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class FavPgcItem extends StatelessWidget {
|
||||
const FavPgcItem({
|
||||
super.key,
|
||||
required this.item,
|
||||
required this.ctr,
|
||||
required this.onSelect,
|
||||
required this.onUpdateStatus,
|
||||
});
|
||||
|
||||
final BangumiListItemModel item;
|
||||
final MultiSelectController ctr;
|
||||
final VoidCallback onSelect;
|
||||
final VoidCallback onUpdateStatus;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: Colors.transparent,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
if (ctr.enableMultiSelect.value) {
|
||||
onSelect();
|
||||
return;
|
||||
}
|
||||
Utils.viewBangumi(seasonId: item.seasonId);
|
||||
},
|
||||
onLongPress: () {
|
||||
if (!ctr.enableMultiSelect.value) {
|
||||
ctr.enableMultiSelect.value = true;
|
||||
onSelect();
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: StyleString.safeSpace,
|
||||
vertical: 5,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 3 / 4,
|
||||
child: LayoutBuilder(
|
||||
builder: (BuildContext context,
|
||||
BoxConstraints boxConstraints) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
NetworkImgLayer(
|
||||
radius: 4,
|
||||
src: item.cover,
|
||||
width: boxConstraints.maxWidth,
|
||||
height: boxConstraints.maxHeight,
|
||||
),
|
||||
if (item.badge?.isNotEmpty == true)
|
||||
PBadge(
|
||||
right: 4,
|
||||
top: 4,
|
||||
text: item.badge,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) =>
|
||||
AnimatedOpacity(
|
||||
opacity: item.checked == true ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
height: constraints.maxHeight,
|
||||
width: constraints.maxHeight *
|
||||
StyleString.aspectRatio,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: Colors.black.withOpacity(0.6),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 34,
|
||||
height: 34,
|
||||
child: AnimatedScale(
|
||||
scale: item.checked == true ? 1 : 0,
|
||||
duration:
|
||||
const Duration(milliseconds: 250),
|
||||
curve: Curves.easeInOut,
|
||||
child: IconButton(
|
||||
tooltip: '取消选择',
|
||||
style: ButtonStyle(
|
||||
padding: WidgetStateProperty.all(
|
||||
EdgeInsets.zero),
|
||||
backgroundColor:
|
||||
WidgetStateProperty
|
||||
.resolveWith(
|
||||
(states) {
|
||||
return Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.8);
|
||||
},
|
||||
),
|
||||
),
|
||||
onPressed: null,
|
||||
icon: Icon(
|
||||
Icons.done_all_outlined,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.title!),
|
||||
if (item.newEp?['index_show'] != null) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'${item.newEp?['index_show']}',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (item.progress != null) ...[
|
||||
SizedBox(
|
||||
height:
|
||||
item.newEp?['index_show'] != null ? 2 : 6),
|
||||
Text(
|
||||
item.progress!,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Theme.of(context).colorScheme.outline,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
right: 12,
|
||||
bottom: 0,
|
||||
child: iconButton(
|
||||
iconSize: 22,
|
||||
context: context,
|
||||
onPressed: onUpdateStatus,
|
||||
icon: Icons.more_vert,
|
||||
iconColor: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
bgColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/fav/note/view.dart';
|
||||
import 'package:PiliPlus/pages/fav/pgc/view.dart';
|
||||
import 'package:PiliPlus/pages/fav/video/index.dart';
|
||||
import 'package:PiliPlus/pages/fav_search/view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -93,8 +94,8 @@ class _FavPageState extends State<FavPage> with SingleTickerProviderStateMixin {
|
||||
.map(
|
||||
(item) => switch (item) {
|
||||
_FavType.video => const FavVideoPage(),
|
||||
_FavType.bangumi => Center(child: Text(item.title)),
|
||||
_FavType.cinema => Center(child: Text(item.title)),
|
||||
_FavType.bangumi => const FavPgcPage(type: 1),
|
||||
_FavType.cinema => const FavPgcPage(type: 2),
|
||||
_FavType.article => Center(child: Text(item.title)),
|
||||
_FavType.note => const FavNotePage(),
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user