mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-01 08:38:18 +08:00
opt download (#1755)
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/common/widgets/appbar/appbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
||||
import 'package:PiliPlus/common/widgets/view_sliver_safe_area.dart';
|
||||
import 'package:PiliPlus/models_new/download/bili_download_entry_info.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select/base.dart'
|
||||
show BaseMultiSelectMixin;
|
||||
import 'package:PiliPlus/pages/download/controller.dart';
|
||||
import 'package:PiliPlus/pages/download/detail/widgets/item.dart';
|
||||
import 'package:PiliPlus/services/download/download_service.dart';
|
||||
import 'package:PiliPlus/utils/grid.dart';
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/material.dart'
|
||||
hide SliverGridDelegateWithMaxCrossAxisExtent;
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class DownloadDetailPage extends StatefulWidget {
|
||||
@@ -28,11 +34,15 @@ class DownloadDetailPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _DownloadDetailPageState extends State<DownloadDetailPage>
|
||||
with GridMixin {
|
||||
with BaseMultiSelectMixin<BiliDownloadEntryInfo> {
|
||||
StreamSubscription? _sub;
|
||||
final _downloadItems = RxList<BiliDownloadEntryInfo>();
|
||||
final _controller = Get.find<DownloadPageController>();
|
||||
final _downloadService = Get.find<DownloadService>();
|
||||
@override
|
||||
RxList<BiliDownloadEntryInfo> get list => _downloadItems;
|
||||
@override
|
||||
RxList<BiliDownloadEntryInfo> get state => _downloadItems;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -71,47 +81,125 @@ class _DownloadDetailPageState extends State<DownloadDetailPage>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
ViewSliverSafeArea(
|
||||
sliver: Obx(() {
|
||||
if (_downloadItems.isNotEmpty) {
|
||||
return SliverGrid.builder(
|
||||
gridDelegate: gridDelegate,
|
||||
itemBuilder: (context, index) {
|
||||
final entry = _downloadItems[index];
|
||||
return DetailItem(
|
||||
entry: entry,
|
||||
progress: widget.progress,
|
||||
downloadService: _downloadService,
|
||||
showTitle: false,
|
||||
onDelete: () async {
|
||||
if (_downloadItems.length == 1) {
|
||||
await _closeSub();
|
||||
await _downloadService.deletePage(
|
||||
pageDirPath: entry.pageDirPath,
|
||||
);
|
||||
if (context.mounted) {
|
||||
Get.back();
|
||||
}
|
||||
} else {
|
||||
_downloadService.deleteDownload(entry: entry);
|
||||
}
|
||||
GStorage.watchProgress.delete(entry.cid.toString());
|
||||
},
|
||||
);
|
||||
return Obx(() {
|
||||
final enableMultiSelect = this.enableMultiSelect.value;
|
||||
return PopScope(
|
||||
canPop: !enableMultiSelect,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (enableMultiSelect) {
|
||||
handleSelect();
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: MultiSelectAppBarWidget(
|
||||
ctr: this,
|
||||
child: AppBar(
|
||||
title: Text(widget.title),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '多选',
|
||||
onPressed: () {
|
||||
if (enableMultiSelect) {
|
||||
handleSelect();
|
||||
} else {
|
||||
this.enableMultiSelect.value = true;
|
||||
}
|
||||
},
|
||||
itemCount: _downloadItems.length,
|
||||
);
|
||||
}
|
||||
return const HttpError();
|
||||
}),
|
||||
icon: const Icon(Icons.edit_note),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
ViewSliverSafeArea(
|
||||
sliver: Obx(() {
|
||||
if (_downloadItems.isNotEmpty) {
|
||||
return SliverGrid.builder(
|
||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
||||
mainAxisSpacing: 2,
|
||||
mainAxisExtent: 100,
|
||||
maxCrossAxisExtent: Grid.smallCardWidth * 2,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final entry = _downloadItems[index];
|
||||
return DetailItem(
|
||||
entry: entry,
|
||||
progress: widget.progress,
|
||||
downloadService: _downloadService,
|
||||
showTitle: false,
|
||||
onDelete: () async {
|
||||
if (_downloadItems.length == 1) {
|
||||
await _closeSub();
|
||||
await _downloadService.deletePage(
|
||||
pageDirPath: entry.pageDirPath,
|
||||
);
|
||||
if (mounted) {
|
||||
Get.back();
|
||||
}
|
||||
} else {
|
||||
_downloadService.deleteDownload(
|
||||
entry: entry,
|
||||
removeList: true,
|
||||
);
|
||||
}
|
||||
GStorage.watchProgress.delete(entry.cid.toString());
|
||||
},
|
||||
controller: this,
|
||||
);
|
||||
},
|
||||
itemCount: _downloadItems.length,
|
||||
);
|
||||
}
|
||||
return const HttpError();
|
||||
}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void onRemove() {
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '确定删除选中视频?',
|
||||
onConfirm: () async {
|
||||
SmartDialog.showLoading();
|
||||
final watchProgress = GStorage.watchProgress;
|
||||
final allChecked = this.allChecked.toSet();
|
||||
final isDeleteAll = allChecked.length == _downloadItems.length;
|
||||
if (isDeleteAll) {
|
||||
await _closeSub();
|
||||
}
|
||||
for (var entry in allChecked) {
|
||||
await watchProgress.deleteAll(
|
||||
allChecked.map((e) => e.cid.toString()),
|
||||
);
|
||||
await _downloadService.deleteDownload(
|
||||
entry: entry,
|
||||
removeList: true,
|
||||
refresh: false,
|
||||
);
|
||||
}
|
||||
_downloadService.flagNotifier.refresh();
|
||||
if (isDeleteAll) {
|
||||
SmartDialog.dismiss();
|
||||
if (mounted) {
|
||||
Get.back();
|
||||
}
|
||||
} else {
|
||||
if (enableMultiSelect.value) {
|
||||
rxCount.value = 0;
|
||||
enableMultiSelect.value = false;
|
||||
}
|
||||
SmartDialog.dismiss();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,13 @@ import 'package:PiliPlus/common/widgets/badge.dart';
|
||||
import 'package:PiliPlus/common/widgets/dialog/dialog.dart';
|
||||
import 'package:PiliPlus/common/widgets/image/network_img_layer.dart';
|
||||
import 'package:PiliPlus/common/widgets/progress_bar/video_progress_indicator.dart';
|
||||
import 'package:PiliPlus/common/widgets/select_mask.dart';
|
||||
import 'package:PiliPlus/models/common/badge_type.dart';
|
||||
import 'package:PiliPlus/models/common/video/source_type.dart';
|
||||
import 'package:PiliPlus/models/common/video/video_quality.dart';
|
||||
import 'package:PiliPlus/models_new/download/bili_download_entry_info.dart';
|
||||
import 'package:PiliPlus/pages/common/multi_select/base.dart';
|
||||
import 'package:PiliPlus/pages/download/downloading/view.dart';
|
||||
import 'package:PiliPlus/services/download/download_service.dart';
|
||||
import 'package:PiliPlus/utils/cache_manager.dart';
|
||||
import 'package:PiliPlus/utils/duration_utils.dart';
|
||||
@@ -26,75 +29,97 @@ class DetailItem extends StatelessWidget {
|
||||
const DetailItem({
|
||||
super.key,
|
||||
required this.entry,
|
||||
required this.progress,
|
||||
this.progress,
|
||||
required this.downloadService,
|
||||
required this.onDelete,
|
||||
this.onDelete,
|
||||
required this.showTitle,
|
||||
this.isCurr = false,
|
||||
//
|
||||
required this.controller,
|
||||
this.checked,
|
||||
this.onSelect,
|
||||
});
|
||||
|
||||
final BiliDownloadEntryInfo entry;
|
||||
final ValueNotifier progress;
|
||||
final ValueNotifier? progress;
|
||||
final DownloadService downloadService;
|
||||
final VoidCallback onDelete;
|
||||
final VoidCallback? onDelete;
|
||||
final bool showTitle;
|
||||
final bool isCurr;
|
||||
//
|
||||
final MultiSelectBase controller;
|
||||
final bool? checked;
|
||||
final ValueChanged<BiliDownloadEntryInfo>? onSelect;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final outline = theme.colorScheme.outline;
|
||||
final cid = entry.source?.cid ?? entry.pageData?.cid;
|
||||
void onLongPress() => showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Get.back();
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '确定删除该视频?',
|
||||
onConfirm: onDelete,
|
||||
);
|
||||
},
|
||||
dense: true,
|
||||
title: const Text(
|
||||
'删除',
|
||||
style: TextStyle(fontSize: 14),
|
||||
final canDel = onDelete != null;
|
||||
void onLongPress() => canDel
|
||||
? showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
clipBehavior: Clip.hardEdge,
|
||||
contentPadding: const EdgeInsets.symmetric(vertical: 12),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Get.back();
|
||||
showConfirmDialog(
|
||||
context: context,
|
||||
title: '确定删除该视频?',
|
||||
onConfirm: onDelete,
|
||||
);
|
||||
},
|
||||
dense: true,
|
||||
title: const Text(
|
||||
'删除',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
Get.back();
|
||||
final res = await downloadService.downloadDanmaku(
|
||||
entry: entry,
|
||||
isUpdate: true,
|
||||
);
|
||||
if (res) {
|
||||
SmartDialog.showToast('更新成功');
|
||||
} else {
|
||||
SmartDialog.showToast('更新失败');
|
||||
}
|
||||
},
|
||||
dense: true,
|
||||
title: const Text(
|
||||
'更新弹幕',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
Get.back();
|
||||
final res = await downloadService.downloadDanmaku(
|
||||
entry: entry,
|
||||
isUpdate: true,
|
||||
);
|
||||
if (res) {
|
||||
SmartDialog.showToast('更新成功');
|
||||
} else {
|
||||
SmartDialog.showToast('更新失败');
|
||||
}
|
||||
},
|
||||
dense: true,
|
||||
title: const Text(
|
||||
'更新弹幕',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
);
|
||||
},
|
||||
)
|
||||
: null;
|
||||
|
||||
return Material(
|
||||
type: MaterialType.transparency,
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
if (!canDel) {
|
||||
Get.to(const DownloadingPage());
|
||||
return;
|
||||
}
|
||||
if (controller.enableMultiSelect.value) {
|
||||
(onSelect ?? controller.onSelect).call(entry);
|
||||
return;
|
||||
}
|
||||
if (entry.isCompleted) {
|
||||
await PageUtils.toVideoPage(
|
||||
aid: entry.avid,
|
||||
@@ -111,7 +136,7 @@ class DetailItem extends StatelessWidget {
|
||||
Future.delayed(const Duration(milliseconds: 400), () {
|
||||
if (context.mounted) {
|
||||
// ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member
|
||||
progress.notifyListeners();
|
||||
progress?.notifyListeners();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -125,9 +150,6 @@ class DetailItem extends StatelessWidget {
|
||||
downloadNext: false,
|
||||
);
|
||||
} else {
|
||||
if (entry.status == DownloadStatus.wait) {
|
||||
downloadService.waitDownloadQueue.remove(entry);
|
||||
}
|
||||
downloadService.startDownload(entry);
|
||||
}
|
||||
}
|
||||
@@ -186,49 +208,62 @@ class DetailItem extends StatelessWidget {
|
||||
top: 6.0,
|
||||
type: PBadgeType.gray,
|
||||
),
|
||||
ValueListenableBuilder(
|
||||
valueListenable: progress,
|
||||
builder: (_, _, _) {
|
||||
final progress = GStorage.watchProgress.get(
|
||||
cid.toString(),
|
||||
);
|
||||
if (progress != null) {
|
||||
return Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
videoProgressIndicator(
|
||||
progress / entry.totalTimeMilli,
|
||||
),
|
||||
PBadge(
|
||||
text: progress >= entry.totalTimeMilli - 400
|
||||
? '已看完'
|
||||
: '${DurationUtils.formatDuration(
|
||||
progress ~/ 1000,
|
||||
)}/'
|
||||
'${DurationUtils.formatDuration(
|
||||
entry.totalTimeMilli ~/ 1000,
|
||||
)}',
|
||||
right: 6,
|
||||
bottom: 7,
|
||||
type: PBadgeType.gray,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (progress != null)
|
||||
ValueListenableBuilder(
|
||||
valueListenable: progress!,
|
||||
builder: (_, _, _) {
|
||||
final progress = GStorage.watchProgress.get(
|
||||
cid.toString(),
|
||||
);
|
||||
}
|
||||
return PBadge(
|
||||
text: DurationUtils.formatDuration(
|
||||
entry.totalTimeMilli ~/ 1000,
|
||||
),
|
||||
right: 6.0,
|
||||
bottom: 7.0,
|
||||
type: PBadgeType.gray,
|
||||
);
|
||||
},
|
||||
if (progress != null) {
|
||||
return Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
videoProgressIndicator(
|
||||
progress / entry.totalTimeMilli,
|
||||
),
|
||||
PBadge(
|
||||
text: progress >= entry.totalTimeMilli - 400
|
||||
? '已看完'
|
||||
: '${DurationUtils.formatDuration(
|
||||
progress ~/ 1000,
|
||||
)}/'
|
||||
'${DurationUtils.formatDuration(
|
||||
entry.totalTimeMilli ~/ 1000,
|
||||
)}',
|
||||
right: 6,
|
||||
bottom: 7,
|
||||
type: PBadgeType.gray,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
return PBadge(
|
||||
text: DurationUtils.formatDuration(
|
||||
entry.totalTimeMilli ~/ 1000,
|
||||
),
|
||||
right: 6.0,
|
||||
bottom: 7.0,
|
||||
type: PBadgeType.gray,
|
||||
);
|
||||
},
|
||||
)
|
||||
else if (entry.totalTimeMilli != 0)
|
||||
PBadge(
|
||||
text: DurationUtils.formatDuration(
|
||||
entry.totalTimeMilli ~/ 1000,
|
||||
),
|
||||
right: 6,
|
||||
bottom: 7,
|
||||
type: PBadgeType.gray,
|
||||
),
|
||||
Positioned.fill(
|
||||
child: selectMask(theme, checked ?? entry.checked ?? false),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -303,11 +338,40 @@ class DetailItem extends StatelessWidget {
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: entry.progressWidget(
|
||||
theme: theme,
|
||||
downloadService: downloadService,
|
||||
isPage: false,
|
||||
),
|
||||
child: isCurr
|
||||
? RepaintBoundary(
|
||||
child: Obx(
|
||||
() {
|
||||
final curDownload =
|
||||
downloadService.curDownload.value;
|
||||
if (curDownload != null) {
|
||||
final status = curDownload.status;
|
||||
final color =
|
||||
status != DownloadStatus.pause
|
||||
? theme.colorScheme.primary
|
||||
: theme.colorScheme.outline;
|
||||
return progressWidget(
|
||||
statusMsg: status!.message,
|
||||
progressStr:
|
||||
status ==
|
||||
DownloadStatus
|
||||
.downloading ||
|
||||
status == DownloadStatus.pause
|
||||
? '${CacheManager.formatSize(curDownload.downloadedBytes)}/${CacheManager.formatSize(curDownload.totalBytes)}'
|
||||
: '',
|
||||
progress: curDownload.totalBytes == 0
|
||||
? 0
|
||||
: curDownload.downloadedBytes /
|
||||
curDownload.totalBytes,
|
||||
color: color,
|
||||
highlightColor: theme.highlightColor,
|
||||
);
|
||||
}
|
||||
return entryProgress(theme);
|
||||
},
|
||||
),
|
||||
)
|
||||
: entryProgress(theme),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -318,4 +382,62 @@ class DetailItem extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget entryProgress(ThemeData theme) => progressWidget(
|
||||
statusMsg: entry.status?.message ?? '暂停中',
|
||||
progressStr: entry.totalBytes == 0
|
||||
? ''
|
||||
: '${CacheManager.formatSize(entry.downloadedBytes)}/${CacheManager.formatSize(entry.totalBytes)}',
|
||||
progress: entry.totalBytes == 0
|
||||
? 0
|
||||
: entry.downloadedBytes / entry.totalBytes,
|
||||
color: theme.colorScheme.outline,
|
||||
highlightColor: theme.highlightColor,
|
||||
);
|
||||
|
||||
Widget progressWidget({
|
||||
required String statusMsg,
|
||||
required String progressStr,
|
||||
required double progress,
|
||||
required Color color,
|
||||
required Color highlightColor,
|
||||
}) {
|
||||
return Column(
|
||||
spacing: 6,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
statusMsg,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
progressStr,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1,
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
LinearProgressIndicator(
|
||||
// ignore: deprecated_member_use
|
||||
year2023: true,
|
||||
minHeight: 2.5,
|
||||
borderRadius: StyleString.mdRadius,
|
||||
color: color,
|
||||
backgroundColor: highlightColor,
|
||||
value: progress,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user