diff --git a/lib/common/widgets/video_card_h.dart b/lib/common/widgets/video_card_h.dart index 8c4faeec..d5bbfa0a 100644 --- a/lib/common/widgets/video_card_h.dart +++ b/lib/common/widgets/video_card_h.dart @@ -6,6 +6,7 @@ import 'package:pilipala/common/widgets/badge.dart'; import 'package:pilipala/common/widgets/stat/danmu.dart'; import 'package:pilipala/common/widgets/stat/view.dart'; import 'package:pilipala/http/search.dart'; +import 'package:pilipala/http/user.dart'; import 'package:pilipala/utils/utils.dart'; import 'package:pilipala/common/widgets/network_img_layer.dart'; @@ -39,6 +40,11 @@ class VideoCardH extends StatelessWidget { longPressEnd!(); } }, + // 双击 稍后再看 + onDoubleTap: () async { + var res = await UserHttp.toViewLater(bvid: videoItem.bvid); + SmartDialog.showToast(res['msg']); + }, child: InkWell( onTap: () async { try { diff --git a/lib/common/widgets/video_card_v.dart b/lib/common/widgets/video_card_v.dart index b4fa449d..3a1c4f73 100644 --- a/lib/common/widgets/video_card_v.dart +++ b/lib/common/widgets/video_card_v.dart @@ -1,8 +1,10 @@ +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:flutter/material.dart'; import 'package:pilipala/common/constants.dart'; import 'package:pilipala/common/widgets/stat/danmu.dart'; import 'package:pilipala/common/widgets/stat/view.dart'; +import 'package:pilipala/http/user.dart'; import 'package:pilipala/pages/rcmd/index.dart'; import 'package:pilipala/utils/id_utils.dart'; import 'package:pilipala/utils/utils.dart'; @@ -43,6 +45,11 @@ class VideoCardV extends StatelessWidget { longPressEnd!(); } }, + // 双击 稍后再看 + onDoubleTap: () async { + var res = await UserHttp.toViewLater(bvid: videoItem.bvid); + SmartDialog.showToast(res['msg']); + }, child: InkWell( onTap: () async { String bvid = videoItem.bvid ?? IdUtils.av2bv(videoItem.aid); diff --git a/lib/http/api.dart b/lib/http/api.dart index 72d1ddef..f6168bf0 100644 --- a/lib/http/api.dart +++ b/lib/http/api.dart @@ -237,4 +237,10 @@ class Api { // 用户动态 static const String memberDynamic = '/x/polymer/web-dynamic/v1/feed/space'; + + // 稍后再看 + static const String toViewLater = '/x/v2/history/toview/add'; + + // 移除已观看 + static const String toViewDel = '/x/v2/history/toview/del'; } diff --git a/lib/http/user.dart b/lib/http/user.dart index 14292e73..8cefb209 100644 --- a/lib/http/user.dart +++ b/lib/http/user.dart @@ -143,4 +143,40 @@ class UserHttp { ); return res; } + + // 稍后再看 + static Future toViewLater({String? bvid, dynamic aid}) async { + var data = {'csrf': await Request.getCsrf()}; + if (bvid != null) { + data['bvid'] = bvid; + } else if (aid != null) { + data['aid'] = aid; + } + var res = await Request().post( + Api.toViewLater, + queryParameters: data, + ); + if (res.data['code'] == 0) { + return {'status': true, 'msg': 'yeah!稍后再看'}; + } else { + return {'status': false, 'msg': res.data['message']}; + } + } + + // 移除已观看 + static Future toViewDel() async { + var res = await Request().post( + Api.toViewDel, + queryParameters: { + 'jsonp': 'jsonp', + 'viewed': true, + 'csrf': await Request.getCsrf(), + }, + ); + if (res.data['code'] == 0) { + return {'status': true, 'msg': 'yeah!成功移除'}; + } else { + return {'status': false, 'msg': res.data['message']}; + } + } } diff --git a/lib/pages/later/controller.dart b/lib/pages/later/controller.dart index 6f6c376c..960e7891 100644 --- a/lib/pages/later/controller.dart +++ b/lib/pages/later/controller.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:pilipala/http/user.dart'; import 'package:pilipala/models/model_hot_video_item.dart'; @@ -16,4 +17,34 @@ class LaterController extends GetxController { } return res; } + + Future toViewDel() async { + SmartDialog.show( + useSystem: true, + animationType: SmartAnimationType.centerFade_otherSlide, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('提示'), + content: const Text('即将删除所有已观看视频,此操作不可恢复。确定是否删除?'), + actions: [ + TextButton( + onPressed: () => SmartDialog.dismiss(), + child: const Text('取消')), + TextButton( + onPressed: () async { + var res = await UserHttp.toViewDel(); + if (res['status']) { + laterList.clear(); + queryLaterList(); + } + SmartDialog.dismiss(); + SmartDialog.showToast(res['msg']); + }, + child: const Text('确认删除'), + ) + ], + ); + }, + ); + } } diff --git a/lib/pages/later/view.dart b/lib/pages/later/view.dart index d02c9d0d..a3389334 100644 --- a/lib/pages/later/view.dart +++ b/lib/pages/later/view.dart @@ -28,10 +28,28 @@ class _LaterPageState extends State { appBar: AppBar( titleSpacing: 0, centerTitle: false, - title: Text( - '稍后再看', - style: Theme.of(context).textTheme.titleMedium, + title: Obx( + () => Text( + '稍后再看 (${_laterController.laterList.length}/100)', + style: Theme.of(context).textTheme.titleMedium, + ), ), + actions: [ + TextButton( + onPressed: () => _laterController.toViewDel(), + child: const Text('移除已看'), + ), + // IconButton( + // tooltip: '一键清空', + // onPressed: () {}, + // icon: Icon( + // Icons.clear_all_outlined, + // size: 21, + // color: Theme.of(context).colorScheme.primary, + // ), + // ), + const SizedBox(width: 8), + ], ), body: CustomScrollView( controller: _laterController.scrollController,