feat: 暂停/恢复历史记录、清空历史记录
This commit is contained in:
@ -148,6 +148,15 @@ class Api {
|
|||||||
// 获取历史记录
|
// 获取历史记录
|
||||||
static const String historyList = '/x/web-interface/history/cursor';
|
static const String historyList = '/x/web-interface/history/cursor';
|
||||||
|
|
||||||
|
// 暂停历史记录
|
||||||
|
static const String pauseHistory = '/x/v2/history/shadow/set';
|
||||||
|
|
||||||
|
// 查询历史记录暂停状态
|
||||||
|
static const String historyStatus = '/x/v2/history/shadow?jsonp=jsonp';
|
||||||
|
|
||||||
|
// 清空历史记录
|
||||||
|
static const String clearHistory = '/x/v2/history/clear';
|
||||||
|
|
||||||
// 热搜
|
// 热搜
|
||||||
static const String hotSearchList =
|
static const String hotSearchList =
|
||||||
'https://s.search.bilibili.com/main/hotword';
|
'https://s.search.bilibili.com/main/hotword';
|
||||||
|
@ -112,4 +112,36 @@ class UserHttp {
|
|||||||
return {'status': false, 'data': [], 'msg': res.data['message']};
|
return {'status': false, 'data': [], 'msg': res.data['message']};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 暂停观看历史
|
||||||
|
static Future pauseHistory(bool switchStatus) async {
|
||||||
|
// 暂停switchStatus传true 否则false
|
||||||
|
var res = await Request().post(
|
||||||
|
Api.pauseHistory,
|
||||||
|
queryParameters: {
|
||||||
|
'switch': switchStatus,
|
||||||
|
'jsonp': 'jsonp',
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 观看历史暂停状态
|
||||||
|
static Future historyStatus() async {
|
||||||
|
var res = await Request().get(Api.historyStatus);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空历史记录
|
||||||
|
static Future clearHistory() async {
|
||||||
|
var res = await Request().post(
|
||||||
|
Api.clearHistory,
|
||||||
|
queryParameters: {
|
||||||
|
'jsonp': 'jsonp',
|
||||||
|
'csrf': await Request.getCsrf(),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:pilipala/http/user.dart';
|
import 'package:pilipala/http/user.dart';
|
||||||
import 'package:pilipala/models/user/history.dart';
|
import 'package:pilipala/models/user/history.dart';
|
||||||
@ -7,10 +8,12 @@ class HistoryController extends GetxController {
|
|||||||
final ScrollController scrollController = ScrollController();
|
final ScrollController scrollController = ScrollController();
|
||||||
RxList<HisListItem> historyList = [HisListItem()].obs;
|
RxList<HisListItem> historyList = [HisListItem()].obs;
|
||||||
bool isLoadingMore = false;
|
bool isLoadingMore = false;
|
||||||
|
RxBool pauseStatus = false.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
historyStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryHistoryList({type = 'init'}) async {
|
Future queryHistoryList({type = 'init'}) async {
|
||||||
@ -40,4 +43,76 @@ class HistoryController extends GetxController {
|
|||||||
Future onRefresh() async {
|
Future onRefresh() async {
|
||||||
queryHistoryList(type: 'onRefresh');
|
queryHistoryList(type: 'onRefresh');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 暂停观看历史
|
||||||
|
Future onPauseHistory() async {
|
||||||
|
SmartDialog.show(
|
||||||
|
useSystem: true,
|
||||||
|
animationType: SmartAnimationType.centerFade_otherSlide,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('提示'),
|
||||||
|
content:
|
||||||
|
Text(!pauseStatus.value ? '啊叻?你要暂停历史记录功能吗?' : '啊叻?要恢复历史记录功能吗?'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => SmartDialog.dismiss(),
|
||||||
|
child: const Text('取消')),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () async {
|
||||||
|
SmartDialog.showLoading(msg: '请求中');
|
||||||
|
var res = await UserHttp.pauseHistory(!pauseStatus.value);
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
SmartDialog.showToast(
|
||||||
|
!pauseStatus.value ? '暂停观看历史' : '恢复观看历史');
|
||||||
|
pauseStatus.value = !pauseStatus.value;
|
||||||
|
}
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
},
|
||||||
|
child: Text(!pauseStatus.value ? '确认暂停' : '确认恢复'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 观看历史暂停状态
|
||||||
|
Future historyStatus() async {
|
||||||
|
var res = await UserHttp.historyStatus();
|
||||||
|
pauseStatus.value = res.data['data'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清空观看历史
|
||||||
|
Future onClearHistory() 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 {
|
||||||
|
SmartDialog.showLoading(msg: '请求中');
|
||||||
|
var res = await UserHttp.clearHistory();
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
SmartDialog.showToast('清空观看历史');
|
||||||
|
}
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
historyList.clear();
|
||||||
|
},
|
||||||
|
child: const Text('确认清空'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,43 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text('观看记录'),
|
titleSpacing: 0,
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
|
title: Text(
|
||||||
|
'观看记录',
|
||||||
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
PopupMenuButton<String>(
|
||||||
|
onSelected: (String type) {
|
||||||
|
// 处理菜单项选择的逻辑
|
||||||
|
switch (type) {
|
||||||
|
case 'pause':
|
||||||
|
_historyController.onPauseHistory();
|
||||||
|
break;
|
||||||
|
case 'clear':
|
||||||
|
_historyController.onClearHistory();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
},
|
||||||
|
itemBuilder: (BuildContext context) => <PopupMenuEntry<String>>[
|
||||||
|
PopupMenuItem<String>(
|
||||||
|
value: 'pause',
|
||||||
|
child: Obx(
|
||||||
|
() => Text(!_historyController.pauseStatus.value
|
||||||
|
? '暂停观看记录'
|
||||||
|
: '恢复观看记录'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const PopupMenuItem<String>(
|
||||||
|
value: 'clear',
|
||||||
|
child: Text('清空观看记录'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
body: RefreshIndicator(
|
body: RefreshIndicator(
|
||||||
onRefresh: () async {
|
onRefresh: () async {
|
||||||
@ -57,13 +92,23 @@ class _HistoryPageState extends State<HistoryPage> {
|
|||||||
Map data = snapshot.data;
|
Map data = snapshot.data;
|
||||||
if (data['status']) {
|
if (data['status']) {
|
||||||
return Obx(
|
return Obx(
|
||||||
() => SliverList(
|
() => _historyController.historyList.isEmpty
|
||||||
delegate: SliverChildBuilderDelegate((context, index) {
|
? const SliverToBoxAdapter(
|
||||||
return HistoryItem(
|
child: Center(
|
||||||
videoItem: _historyController.historyList[index],
|
child: Text('没数据'),
|
||||||
);
|
),
|
||||||
}, childCount: _historyController.historyList.length),
|
)
|
||||||
),
|
: SliverList(
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, index) {
|
||||||
|
return HistoryItem(
|
||||||
|
videoItem:
|
||||||
|
_historyController.historyList[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
childCount:
|
||||||
|
_historyController.historyList.length),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return HttpError(
|
return HttpError(
|
||||||
|
Reference in New Issue
Block a user