mod: 修改取消收藏的逻辑 issues#60
This commit is contained in:
@ -14,7 +14,7 @@ class FavDetailController extends GetxController {
|
|||||||
int currentPage = 1;
|
int currentPage = 1;
|
||||||
bool isLoadingMore = false;
|
bool isLoadingMore = false;
|
||||||
RxMap favInfo = {}.obs;
|
RxMap favInfo = {}.obs;
|
||||||
RxList<FavDetailItemData> favList = [FavDetailItemData()].obs;
|
RxList favList = [].obs;
|
||||||
RxString loadingText = '加载中...'.obs;
|
RxString loadingText = '加载中...'.obs;
|
||||||
int mediaCount = 0;
|
int mediaCount = 0;
|
||||||
|
|
||||||
@ -61,15 +61,13 @@ class FavDetailController extends GetxController {
|
|||||||
aid: id, addIds: '', delIds: mediaId.toString());
|
aid: id, addIds: '', delIds: mediaId.toString());
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
if (result['data']['prompt']) {
|
if (result['data']['prompt']) {
|
||||||
List<FavDetailItemData> dataList = favDetailData.value.medias!;
|
List dataList = favList;
|
||||||
for (var i in dataList) {
|
for (var i in dataList) {
|
||||||
if (i.id == id) {
|
if (i.id == id) {
|
||||||
dataList.remove(i);
|
dataList.remove(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
favDetailData.value.medias = dataList;
|
|
||||||
favDetailData.refresh();
|
|
||||||
SmartDialog.showToast('取消收藏');
|
SmartDialog.showToast('取消收藏');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -168,7 +168,7 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
|||||||
padding: const EdgeInsets.only(top: 15, bottom: 8, left: 14),
|
padding: const EdgeInsets.only(top: 15, bottom: 8, left: 14),
|
||||||
child: Obx(
|
child: Obx(
|
||||||
() => Text(
|
() => Text(
|
||||||
'共${_favDetailController.favInfo['media_count'] ?? '-'}条视频',
|
'共${_favDetailController.favList.length}条视频',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize:
|
fontSize:
|
||||||
Theme.of(context).textTheme.labelMedium!.fontSize,
|
Theme.of(context).textTheme.labelMedium!.fontSize,
|
||||||
@ -187,13 +187,19 @@ class _FavDetailPageState extends State<FavDetailPage> {
|
|||||||
if (_favDetailController.item!.mediaCount == 0) {
|
if (_favDetailController.item!.mediaCount == 0) {
|
||||||
return const NoData();
|
return const NoData();
|
||||||
} else {
|
} else {
|
||||||
|
List favList = _favDetailController.favList;
|
||||||
return Obx(
|
return Obx(
|
||||||
() => SliverList(
|
() => favList.isEmpty
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
? const SliverToBoxAdapter(child: SizedBox())
|
||||||
|
: SliverList(
|
||||||
|
delegate:
|
||||||
|
SliverChildBuilderDelegate((context, index) {
|
||||||
return FavVideoCardH(
|
return FavVideoCardH(
|
||||||
videoItem: _favDetailController.favList[index],
|
videoItem: favList[index],
|
||||||
|
callFn: () => _favDetailController
|
||||||
|
.onCancelFav(favList[index].id),
|
||||||
);
|
);
|
||||||
}, childCount: _favDetailController.favList.length),
|
}, childCount: favList.length),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,42 +10,20 @@ import 'package:pilipala/utils/id_utils.dart';
|
|||||||
import 'package:pilipala/utils/utils.dart';
|
import 'package:pilipala/utils/utils.dart';
|
||||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||||
|
|
||||||
import '../controller.dart';
|
|
||||||
|
|
||||||
// 收藏视频卡片 - 水平布局
|
// 收藏视频卡片 - 水平布局
|
||||||
class FavVideoCardH extends StatelessWidget {
|
class FavVideoCardH extends StatelessWidget {
|
||||||
final dynamic videoItem;
|
final dynamic videoItem;
|
||||||
final FavDetailController _favDetailController =
|
final Function? callFn;
|
||||||
Get.put(FavDetailController());
|
|
||||||
|
|
||||||
FavVideoCardH({Key? key, required this.videoItem}) : super(key: key);
|
const FavVideoCardH({Key? key, required this.videoItem, this.callFn})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
int id = videoItem.id;
|
int id = videoItem.id;
|
||||||
String bvid = videoItem.bvid ?? IdUtils.av2bv(id);
|
String bvid = videoItem.bvid ?? IdUtils.av2bv(id);
|
||||||
String heroTag = Utils.makeHeroTag(id);
|
String heroTag = Utils.makeHeroTag(id);
|
||||||
return Dismissible(
|
return InkWell(
|
||||||
movementDuration: const Duration(milliseconds: 300),
|
|
||||||
background: Container(
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context).colorScheme.errorContainer,
|
|
||||||
),
|
|
||||||
child: const Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.clear_all_rounded),
|
|
||||||
SizedBox(width: 6),
|
|
||||||
Text('取消收藏')
|
|
||||||
],
|
|
||||||
)),
|
|
||||||
direction: DismissDirection.endToStart,
|
|
||||||
key: ValueKey<int>(videoItem.id),
|
|
||||||
onDismissed: (DismissDirection direction) {
|
|
||||||
_favDetailController.onCancelFav(videoItem.id);
|
|
||||||
// widget.onDeleteNotice();
|
|
||||||
},
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () async {
|
onTap: () async {
|
||||||
// int? seasonId;
|
// int? seasonId;
|
||||||
String? epId;
|
String? epId;
|
||||||
@ -113,10 +91,8 @@ class FavVideoCardH extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
vertical: 1, horizontal: 6),
|
vertical: 1, horizontal: 6),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(4),
|
||||||
BorderRadius.circular(4),
|
color: Colors.black54.withOpacity(0.4)),
|
||||||
color:
|
|
||||||
Colors.black54.withOpacity(0.4)),
|
|
||||||
child: Text(
|
child: Text(
|
||||||
Utils.timeFormat(videoItem.duration!),
|
Utils.timeFormat(videoItem.duration!),
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
@ -129,7 +105,7 @@ class FavVideoCardH extends StatelessWidget {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
VideoContent(videoItem: videoItem)
|
VideoContent(videoItem: videoItem, callFn: callFn)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -138,14 +114,14 @@ class FavVideoCardH extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VideoContent extends StatelessWidget {
|
class VideoContent extends StatelessWidget {
|
||||||
final dynamic videoItem;
|
final dynamic videoItem;
|
||||||
const VideoContent({super.key, required this.videoItem});
|
final Function? callFn;
|
||||||
|
const VideoContent({super.key, required this.videoItem, this.callFn});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -173,7 +149,6 @@ class VideoContent extends StatelessWidget {
|
|||||||
color: Theme.of(context).colorScheme.outline,
|
color: Theme.of(context).colorScheme.outline,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
StatView(
|
StatView(
|
||||||
@ -181,7 +156,51 @@ class VideoContent extends StatelessWidget {
|
|||||||
view: videoItem.cntInfo['play'],
|
view: videoItem.cntInfo['play'],
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
StatDanMu(theme: 'gray', danmu: videoItem.cntInfo['danmaku'])
|
StatDanMu(theme: 'gray', danmu: videoItem.cntInfo['danmaku']),
|
||||||
|
const Spacer(),
|
||||||
|
SizedBox(
|
||||||
|
width: 26,
|
||||||
|
height: 26,
|
||||||
|
child: IconButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(EdgeInsets.zero),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: Get.context!,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('提示'),
|
||||||
|
content: const Text('要取消收藏吗?'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Get.back(),
|
||||||
|
child: Text(
|
||||||
|
'取消',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.colorScheme
|
||||||
|
.outline),
|
||||||
|
)),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
await callFn!();
|
||||||
|
Get.back();
|
||||||
|
},
|
||||||
|
child: const Text('确定取消'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
icon: Icon(
|
||||||
|
Icons.clear_outlined,
|
||||||
|
color: Theme.of(context).colorScheme.outline,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user