mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-04-22 19:51:11 +08:00
mod: history: full type
Closes #473 Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:PiliPlus/common/widgets/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/refresh_indicator.dart';
|
||||
import 'package:PiliPlus/http/loading_state.dart';
|
||||
import 'package:PiliPlus/pages/fav_search/view.dart' show SearchType;
|
||||
import 'package:PiliPlus/pages/history/base_controller.dart';
|
||||
import 'package:PiliPlus/utils/extension.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -13,139 +14,252 @@ import '../../utils/grid.dart';
|
||||
import 'widgets/item.dart';
|
||||
|
||||
class HistoryPage extends StatefulWidget {
|
||||
const HistoryPage({super.key});
|
||||
const HistoryPage({super.key, this.type});
|
||||
|
||||
final String? type;
|
||||
|
||||
@override
|
||||
State<HistoryPage> createState() => _HistoryPageState();
|
||||
}
|
||||
|
||||
class _HistoryPageState extends State<HistoryPage> {
|
||||
final _historyController = Get.put(HistoryController());
|
||||
class _HistoryPageState extends State<HistoryPage>
|
||||
with AutomaticKeepAliveClientMixin {
|
||||
late final _historyController = Get.put(
|
||||
HistoryController(widget.type),
|
||||
tag: widget.type ?? 'all',
|
||||
);
|
||||
|
||||
HistoryController get currCtr {
|
||||
try {
|
||||
if (_historyController.tabController != null &&
|
||||
_historyController.tabController!.index != 0) {
|
||||
return Get.find<HistoryController>(
|
||||
tag: _historyController
|
||||
.tabs[_historyController.tabController!.index - 1].type,
|
||||
);
|
||||
}
|
||||
} catch (_) {
|
||||
return _historyController;
|
||||
}
|
||||
return _historyController;
|
||||
}
|
||||
|
||||
bool get enableMultiSelect =>
|
||||
_historyController.baseCtr.enableMultiSelect.value;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
Get.delete<HistoryBaseController>();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(
|
||||
() => PopScope(
|
||||
canPop: _historyController.enableMultiSelect.value.not,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (_historyController.enableMultiSelect.value) {
|
||||
_historyController.handleSelect();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBarWidget(
|
||||
visible: _historyController.enableMultiSelect.value,
|
||||
child1: AppBar(
|
||||
title: const Text('观看记录'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () => Get.toNamed(
|
||||
'/favSearch',
|
||||
arguments: {
|
||||
'searchType': SearchType.history,
|
||||
},
|
||||
),
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (String type) {
|
||||
// 处理菜单项选择的逻辑
|
||||
switch (type) {
|
||||
case 'pause':
|
||||
_historyController.onPauseHistory(context);
|
||||
break;
|
||||
case 'clear':
|
||||
_historyController.onClearHistory(context);
|
||||
break;
|
||||
case 'del':
|
||||
_historyController.onDelHistory();
|
||||
break;
|
||||
case 'multiple':
|
||||
_historyController.enableMultiSelect.value = true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) =>
|
||||
<PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
value: 'pause',
|
||||
child: Obx(
|
||||
() => Text(
|
||||
!_historyController.pauseStatus.value
|
||||
? '暂停观看记录'
|
||||
: '恢复观看记录',
|
||||
super.build(context);
|
||||
return widget.type != null
|
||||
? _buildPage
|
||||
: Obx(
|
||||
() => PopScope(
|
||||
canPop: enableMultiSelect.not,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (enableMultiSelect) {
|
||||
currCtr.handleSelect();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: widget.type != null
|
||||
? null
|
||||
: AppBarWidget(
|
||||
visible: enableMultiSelect,
|
||||
child1: AppBar(
|
||||
title: const Text('观看记录'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '搜索',
|
||||
onPressed: () => Get.toNamed(
|
||||
'/favSearch',
|
||||
arguments: {
|
||||
'searchType': SearchType.history,
|
||||
},
|
||||
),
|
||||
icon: const Icon(Icons.search_outlined),
|
||||
),
|
||||
PopupMenuButton<String>(
|
||||
onSelected: (String type) {
|
||||
// 处理菜单项选择的逻辑
|
||||
switch (type) {
|
||||
case 'pause':
|
||||
_historyController.baseCtr
|
||||
.onPauseHistory(context);
|
||||
break;
|
||||
case 'clear':
|
||||
_historyController.baseCtr
|
||||
.onClearHistory(context, () {
|
||||
_historyController.loadingState.value =
|
||||
LoadingState.success(null);
|
||||
if (_historyController.tabController !=
|
||||
null) {
|
||||
for (final item
|
||||
in _historyController.tabs) {
|
||||
try {
|
||||
Get.find<HistoryController>(
|
||||
tag: item.type)
|
||||
.loadingState
|
||||
.value =
|
||||
LoadingState.success(null);
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
case 'del':
|
||||
currCtr.onDelHistory();
|
||||
break;
|
||||
case 'multiple':
|
||||
_historyController
|
||||
.baseCtr.enableMultiSelect.value = true;
|
||||
break;
|
||||
}
|
||||
},
|
||||
itemBuilder: (BuildContext context) =>
|
||||
<PopupMenuEntry<String>>[
|
||||
PopupMenuItem<String>(
|
||||
value: 'pause',
|
||||
child: Obx(
|
||||
() => Text(
|
||||
!_historyController
|
||||
.baseCtr.pauseStatus.value
|
||||
? '暂停观看记录'
|
||||
: '恢复观看记录',
|
||||
),
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'clear',
|
||||
child: Text('清空观看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'del',
|
||||
child: Text('删除已看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'multiple',
|
||||
child: Text('多选删除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
child2: AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: '取消',
|
||||
onPressed: () {
|
||||
currCtr.handleSelect();
|
||||
},
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
),
|
||||
title: Obx(
|
||||
() => Text(
|
||||
'已选: ${_historyController.baseCtr.checkedCount.value}',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => currCtr.handleSelect(true),
|
||||
child: const Text('全选'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
currCtr.onDelCheckedHistory(context),
|
||||
child: Text(
|
||||
'删除',
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'clear',
|
||||
child: Text('清空观看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'del',
|
||||
child: Text('删除已看记录'),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'multiple',
|
||||
child: Text('多选删除'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
child2: AppBar(
|
||||
leading: IconButton(
|
||||
tooltip: '取消',
|
||||
onPressed: _historyController.handleSelect,
|
||||
icon: const Icon(Icons.close_outlined),
|
||||
),
|
||||
title: Obx(
|
||||
() => Text(
|
||||
'已选: ${_historyController.checkedCount.value}',
|
||||
body: Obx(
|
||||
() => _historyController.tabs.isNotEmpty
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TabBar(
|
||||
controller: _historyController.tabController,
|
||||
onTap: (value) {
|
||||
if (_historyController
|
||||
.tabController!.indexIsChanging.not) {
|
||||
currCtr.scrollController.animToTop();
|
||||
} else {
|
||||
if (enableMultiSelect) {
|
||||
if (_historyController
|
||||
.tabController!.previousIndex ==
|
||||
0) {
|
||||
_historyController.handleSelect();
|
||||
} else {
|
||||
try {
|
||||
Get.find<HistoryController>(
|
||||
tag: _historyController
|
||||
.tabs[_historyController
|
||||
.tabController!
|
||||
.previousIndex -
|
||||
1]
|
||||
.type)
|
||||
.handleSelect();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
tabs: [
|
||||
Tab(text: '全部'),
|
||||
..._historyController.tabs.map(
|
||||
(item) => Tab(text: item.name),
|
||||
),
|
||||
],
|
||||
),
|
||||
Expanded(
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: TabBarView(
|
||||
physics: enableMultiSelect
|
||||
? const NeverScrollableScrollPhysics()
|
||||
: null,
|
||||
controller: _historyController.tabController,
|
||||
children: [
|
||||
_buildPage,
|
||||
..._historyController.tabs.map(
|
||||
(item) => HistoryPage(type: item.type),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: _buildPage,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => _historyController.handleSelect(true),
|
||||
child: const Text('全选'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
_historyController.onDelCheckedHistory(context),
|
||||
child: Text(
|
||||
'删除',
|
||||
style:
|
||||
TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _historyController.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _historyController.scrollController,
|
||||
slivers: [
|
||||
Obx(() => _buildBody(_historyController.loadingState.value)),
|
||||
SliverToBoxAdapter(
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
Widget get _buildPage => refreshIndicator(
|
||||
onRefresh: () async {
|
||||
await _historyController.onRefresh();
|
||||
},
|
||||
child: CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
controller: _historyController.scrollController,
|
||||
slivers: [
|
||||
Obx(() => _buildBody(_historyController.loadingState.value)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _buildBody(LoadingState loadingState) {
|
||||
return switch (loadingState) {
|
||||
Loading() => SliverGrid(
|
||||
@@ -162,24 +276,30 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
),
|
||||
),
|
||||
Success() => (loadingState.response as List?)?.isNotEmpty == true
|
||||
? SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: 2,
|
||||
maxCrossAxisExtent: Grid.mediumCardWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.2,
|
||||
? SliverPadding(
|
||||
padding: EdgeInsets.only(
|
||||
top: StyleString.safeSpace - 5,
|
||||
bottom: MediaQuery.of(context).padding.bottom + 80,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
return HistoryItem(
|
||||
videoItem: loadingState.response[index],
|
||||
ctr: _historyController,
|
||||
onChoose: () => _historyController.onSelect(index),
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
sliver: SliverGrid(
|
||||
gridDelegate: SliverGridDelegateWithExtentAndRatio(
|
||||
mainAxisSpacing: 2,
|
||||
maxCrossAxisExtent: Grid.mediumCardWidth * 2,
|
||||
childAspectRatio: StyleString.aspectRatio * 2.2,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
if (index == loadingState.response.length - 1) {
|
||||
_historyController.onLoadMore();
|
||||
}
|
||||
return HistoryItem(
|
||||
videoItem: loadingState.response[index],
|
||||
ctr: _historyController.baseCtr,
|
||||
onChoose: () => _historyController.onSelect(index),
|
||||
);
|
||||
},
|
||||
childCount: loadingState.response.length,
|
||||
),
|
||||
),
|
||||
)
|
||||
: HttpError(
|
||||
@@ -192,6 +312,9 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
LoadingState() => throw UnimplementedError(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class AppBarWidget extends StatelessWidget implements PreferredSizeWidget {
|
||||
|
||||
Reference in New Issue
Block a user