二次开发源码提交
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
import 'package:cloudreve4_flutter/presentation/providers/auth_provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/user_setting_provider.dart';
|
||||
import 'package:cloudreve4_flutter/services/avatar_cache_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'widgets/storage_usage_card.dart';
|
||||
import 'widgets/quick_access_grid.dart';
|
||||
import 'widgets/recent_activity_list.dart';
|
||||
import 'widgets/search_entry_card.dart';
|
||||
|
||||
class OverviewPage extends StatefulWidget {
|
||||
const OverviewPage({super.key});
|
||||
|
||||
@override
|
||||
State<OverviewPage> createState() => _OverviewPageState();
|
||||
}
|
||||
|
||||
class _OverviewPageState extends State<OverviewPage> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.microtask(() {
|
||||
if (mounted) {
|
||||
final userSetting = Provider.of<UserSettingProvider>(
|
||||
context, listen: false);
|
||||
userSetting.loadCapacity();
|
||||
|
||||
// 初始化/更新当前用户头像
|
||||
final auth = Provider.of<AuthProvider>(context, listen: false);
|
||||
final userId = auth.user?.id ?? '';
|
||||
if (userId.isNotEmpty) {
|
||||
final service = AvatarCacheService.instance;
|
||||
if (service.avatarIsExist(userId)) {
|
||||
service.avatarIsUpdated(
|
||||
userId,
|
||||
auth.currentServer?.baseUrl ?? '',
|
||||
auth.token?.accessToken ?? '',
|
||||
);
|
||||
} else {
|
||||
service.getAvatar(
|
||||
userId,
|
||||
baseUrl: auth.currentServer?.baseUrl,
|
||||
token: auth.token?.accessToken,
|
||||
email: auth.user?.email,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final isWide = MediaQuery
|
||||
.of(context)
|
||||
.size
|
||||
.width >= 720;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('概览'),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: isWide ? _buildWideLayout() : _buildNarrowLayout(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 宽屏:存储+快捷入口左右并排
|
||||
Widget _buildWideLayout() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
SearchEntryCard(),
|
||||
SizedBox(height: 16),
|
||||
_WideStorageAndShortcuts(),
|
||||
SizedBox(height: 16),
|
||||
RecentActivityList(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 窄屏:上下堆叠
|
||||
Widget _buildNarrowLayout() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
SearchEntryCard(),
|
||||
SizedBox(height: 16),
|
||||
StorageUsageCard(),
|
||||
SizedBox(height: 16),
|
||||
Card(child: Padding(
|
||||
padding: EdgeInsets.all(16), child: QuickAccessGrid())),
|
||||
SizedBox(height: 16),
|
||||
RecentActivityList(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 宽屏端:左侧存储卡片 + 右侧快捷入口胶囊
|
||||
class _WideStorageAndShortcuts extends StatelessWidget {
|
||||
const _WideStorageAndShortcuts();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: const [
|
||||
Expanded(flex: 5, child: StorageUsageCard()),
|
||||
SizedBox(width: 16),
|
||||
Expanded(
|
||||
flex: 7,
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: QuickAccessGrid(fillHeight: true),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
import 'package:cloudreve4_flutter/core/constants/quick_access_defaults.dart';
|
||||
import 'package:cloudreve4_flutter/main.dart' show routeObserver;
|
||||
import 'package:cloudreve4_flutter/presentation/providers/file_manager_provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/navigation_provider.dart';
|
||||
import 'package:cloudreve4_flutter/services/storage_service.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class QuickAccessGrid extends StatefulWidget {
|
||||
final bool fillHeight;
|
||||
const QuickAccessGrid({super.key, this.fillHeight = false});
|
||||
|
||||
@override
|
||||
State<QuickAccessGrid> createState() => _QuickAccessGridState();
|
||||
}
|
||||
|
||||
class _QuickAccessGridState extends State<QuickAccessGrid> with RouteAware {
|
||||
List<QuickAccessConfig> _items = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadShortcuts();
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
routeObserver.subscribe(this, ModalRoute.of(context) as PageRoute);
|
||||
}
|
||||
|
||||
@override
|
||||
void didPopNext() {
|
||||
_loadShortcuts();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
routeObserver.unsubscribe(this);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _loadShortcuts() async {
|
||||
// 先尝试 v2 格式
|
||||
var saved = await StorageService.instance.getString(QuickAccessConfig.storageKey);
|
||||
if (saved != null && saved.isNotEmpty) {
|
||||
try {
|
||||
if (mounted) setState(() => _items = QuickAccessConfig.parseSaved(saved));
|
||||
return;
|
||||
} catch (_) {}
|
||||
}
|
||||
// 迁移 v1 格式
|
||||
final v1 = await StorageService.instance.getString('quick_access_shortcuts');
|
||||
if (v1 != null && v1.isNotEmpty) {
|
||||
final migrated = QuickAccessConfig.migrateV1(v1);
|
||||
if (mounted) {
|
||||
setState(() => _items = migrated);
|
||||
await StorageService.instance.setString(
|
||||
QuickAccessConfig.storageKey,
|
||||
QuickAccessConfig.serialize(migrated),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (mounted) setState(() => _items = List.from(QuickAccessConfig.defaults));
|
||||
}
|
||||
|
||||
void _navigateTo(String path) {
|
||||
final navProvider = Provider.of<NavigationProvider>(context, listen: false);
|
||||
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
|
||||
navProvider.setIndex(1);
|
||||
fileManager.enterFolder(path);
|
||||
}
|
||||
|
||||
Future<void> _editShortcut(int index) async {
|
||||
final item = _items[index];
|
||||
final labelController = TextEditingController(text: item.label);
|
||||
final pathController = TextEditingController(text: item.path);
|
||||
|
||||
final result = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Text('编辑 "${item.label}"'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: labelController,
|
||||
decoration: const InputDecoration(labelText: '名称'),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: pathController,
|
||||
decoration: const InputDecoration(labelText: '目录路径', hintText: '例如: /Images'),
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(ctx).pop(), child: const Text('取消')),
|
||||
FilledButton(onPressed: () => Navigator.of(ctx).pop(pathController.text), child: const Text('确定')),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (result != null && result.isNotEmpty) {
|
||||
setState(() {
|
||||
_items[index] = item.copyWith(path: result);
|
||||
});
|
||||
await _save();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _save() async {
|
||||
await StorageService.instance.setString(
|
||||
QuickAccessConfig.storageKey,
|
||||
QuickAccessConfig.serialize(_items),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: widget.fillHeight ? MainAxisSize.max : MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(LucideIcons.zap, size: 18, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text('快捷入口', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
..._buildRows(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildRows() {
|
||||
final total = _items.length;
|
||||
if (total == 0) return [];
|
||||
|
||||
final maxCols = total > 6 ? 3 : 2;
|
||||
const gap = 10.0;
|
||||
final rows = <Widget>[];
|
||||
|
||||
for (int i = 0; i < total; i += maxCols) {
|
||||
final rowItems = <Widget>[];
|
||||
final remaining = total - i;
|
||||
final colsInRow = remaining < maxCols ? remaining : maxCols;
|
||||
|
||||
for (int j = 0; j < colsInRow; j++) {
|
||||
final index = i + j;
|
||||
if (j > 0) rowItems.add(const SizedBox(width: gap));
|
||||
rowItems.add(
|
||||
Expanded(
|
||||
child: _AccessChip(
|
||||
item: _items[index],
|
||||
onTap: () => _navigateTo(_items[index].path),
|
||||
onLongPress: () => _editShortcut(index),
|
||||
expanded: true,
|
||||
fillHeight: widget.fillHeight,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final row = Row(children: rowItems);
|
||||
rows.add(widget.fillHeight ? Expanded(child: row) : row);
|
||||
if (i + maxCols < total) {
|
||||
rows.add(const SizedBox(height: gap));
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
/// 渐变胶囊
|
||||
class _AccessChip extends StatefulWidget {
|
||||
final QuickAccessConfig item;
|
||||
final VoidCallback onTap;
|
||||
final VoidCallback onLongPress;
|
||||
final bool expanded;
|
||||
final bool fillHeight;
|
||||
|
||||
const _AccessChip({
|
||||
required this.item,
|
||||
required this.onTap,
|
||||
required this.onLongPress,
|
||||
this.expanded = false,
|
||||
this.fillHeight = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_AccessChip> createState() => _AccessChipState();
|
||||
}
|
||||
|
||||
class _AccessChipState extends State<_AccessChip> with SingleTickerProviderStateMixin {
|
||||
bool _hovered = false;
|
||||
late final AnimationController _controller;
|
||||
late final Animation<double> _scaleAnim;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 120),
|
||||
lowerBound: 0.94,
|
||||
upperBound: 1.0,
|
||||
)..value = 1.0;
|
||||
_scaleAnim = _controller.view;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final item = widget.item;
|
||||
final gradient = LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [item.color, item.color.darken(0.12)],
|
||||
);
|
||||
|
||||
final child = AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
width: widget.expanded ? double.infinity : null,
|
||||
height: widget.fillHeight ? double.infinity : null,
|
||||
alignment: widget.expanded ? Alignment.center : null,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: widget.expanded ? 0 : 18,
|
||||
vertical: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
gradient: gradient,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: item.color.withValues(alpha: _hovered ? 0.4 : 0.18),
|
||||
blurRadius: _hovered ? 16 : 8,
|
||||
offset: Offset(0, _hovered ? 6 : 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: widget.expanded ? MainAxisSize.max : MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(item.icon, size: 18, color: Colors.white),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
item.label,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 13,
|
||||
letterSpacing: 0.2,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return MouseRegion(
|
||||
onEnter: (_) => setState(() => _hovered = true),
|
||||
onExit: (_) => setState(() => _hovered = false),
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) => _controller.reverse(),
|
||||
onTapUp: (_) {
|
||||
_controller.forward();
|
||||
widget.onTap();
|
||||
},
|
||||
onTapCancel: () => _controller.forward(),
|
||||
onLongPress: widget.onLongPress,
|
||||
child: AnimatedBuilder(
|
||||
animation: _scaleAnim,
|
||||
builder: (context, _) => Transform.scale(scale: _scaleAnim.value, child: child),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,282 @@
|
||||
import 'dart:io';
|
||||
import 'package:cloudreve4_flutter/data/models/download_task_model.dart';
|
||||
import 'package:cloudreve4_flutter/data/models/upload_task_model.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/download_manager_provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/file_manager_provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/navigation_provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/upload_manager_provider.dart';
|
||||
import 'package:cloudreve4_flutter/core/utils/app_logger.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:open_file/open_file.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class RecentActivityList extends StatelessWidget {
|
||||
const RecentActivityList({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 4, bottom: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(LucideIcons.activity, size: 18, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text('最近活动', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Consumer2<UploadManagerProvider, DownloadManagerProvider>(
|
||||
builder: (context, uploadProvider, downloadProvider, _) {
|
||||
final activities = _mergeActivities(uploadProvider.allTasks, downloadProvider.tasks);
|
||||
|
||||
if (activities.isEmpty) {
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(LucideIcons.activity, size: 40, color: theme.hintColor.withValues(alpha: 0.5)),
|
||||
const SizedBox(height: 12),
|
||||
Text('暂无活动记录', style: TextStyle(color: theme.hintColor)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Column(
|
||||
children: activities.take(10).map((item) => _buildActivityItem(context, item)).toList(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
List<_ActivityItem> _mergeActivities(
|
||||
List<UploadTaskModel> uploads,
|
||||
List<DownloadTaskModel> downloads,
|
||||
) {
|
||||
final items = <_ActivityItem>[];
|
||||
|
||||
for (final u in uploads) {
|
||||
items.add(_ActivityItem(
|
||||
name: u.fileName,
|
||||
type: _ActivityType.upload,
|
||||
status: _mapUploadStatus(u.status),
|
||||
createdAt: DateTime.now(),
|
||||
path: u.targetPath.replaceFirst('cloudreve://my', ''),
|
||||
));
|
||||
}
|
||||
|
||||
for (final d in downloads) {
|
||||
items.add(_ActivityItem(
|
||||
name: d.fileName,
|
||||
type: _ActivityType.download,
|
||||
status: _mapDownloadStatus(d.status),
|
||||
createdAt: d.createdAt,
|
||||
path: d.fileUri,
|
||||
savePath: d.savePath,
|
||||
));
|
||||
}
|
||||
|
||||
items.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return items;
|
||||
}
|
||||
|
||||
_ActivityStatus _mapUploadStatus(UploadStatus status) {
|
||||
switch (status) {
|
||||
case UploadStatus.completed:
|
||||
return _ActivityStatus.completed;
|
||||
case UploadStatus.failed:
|
||||
return _ActivityStatus.failed;
|
||||
case UploadStatus.uploading:
|
||||
return _ActivityStatus.active;
|
||||
default:
|
||||
return _ActivityStatus.pending;
|
||||
}
|
||||
}
|
||||
|
||||
_ActivityStatus _mapDownloadStatus(DownloadStatus status) {
|
||||
switch (status) {
|
||||
case DownloadStatus.completed:
|
||||
return _ActivityStatus.completed;
|
||||
case DownloadStatus.failed:
|
||||
return _ActivityStatus.failed;
|
||||
case DownloadStatus.downloading:
|
||||
return _ActivityStatus.active;
|
||||
default:
|
||||
return _ActivityStatus.pending;
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildActivityItem(BuildContext context, _ActivityItem item) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
final isUpload = item.type == _ActivityType.upload;
|
||||
final icon = isUpload ? LucideIcons.upload : LucideIcons.download;
|
||||
final statusColor = _statusColor(item.status, colorScheme);
|
||||
|
||||
// 判断点击行为
|
||||
final bool canTap;
|
||||
if (item.status == _ActivityStatus.completed) {
|
||||
if (isUpload) {
|
||||
canTap = true; // 上传完成 → 跳转目录
|
||||
} else {
|
||||
// 下载完成 → 仅桌面端可打开文件夹
|
||||
canTap = Platform.isWindows || Platform.isLinux;
|
||||
}
|
||||
} else {
|
||||
canTap = false;
|
||||
}
|
||||
|
||||
return InkWell(
|
||||
onTap: canTap ? () => _handleTap(context, item) : null,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: statusColor.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icon, size: 18, color: statusColor),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
item.name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
_statusLabel(item),
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: statusColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (canTap) ...[
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
isUpload ? LucideIcons.folderOpen : LucideIcons.externalLink,
|
||||
size: 16,
|
||||
color: theme.hintColor,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleTap(BuildContext context, _ActivityItem item) {
|
||||
if (item.type == _ActivityType.upload) {
|
||||
_navigateToFolder(context, item.path);
|
||||
} else {
|
||||
_openLocalFolder(item.savePath);
|
||||
}
|
||||
}
|
||||
|
||||
void _navigateToFolder(BuildContext context, String path) {
|
||||
final parentPath = _getParentPath(path);
|
||||
final navProvider = Provider.of<NavigationProvider>(context, listen: false);
|
||||
final fileManager = Provider.of<FileManagerProvider>(context, listen: false);
|
||||
|
||||
// 构造高亮路径:还原为 cloudreve:// 格式
|
||||
final highlightPath = path.startsWith('cloudreve://')
|
||||
? path
|
||||
: 'cloudreve://my$path';
|
||||
|
||||
fileManager.navigateAndHighlight(parentPath, highlightPath);
|
||||
navProvider.setIndex(1);
|
||||
}
|
||||
|
||||
Future<void> _openLocalFolder(String? savePath) async {
|
||||
if (savePath == null || savePath.isEmpty) return;
|
||||
try {
|
||||
final dir = File(savePath).parent.path;
|
||||
final result = await OpenFile.open(dir);
|
||||
if (result.type != ResultType.done) {
|
||||
AppLogger.d('打开文件夹失败: ${result.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
AppLogger.d('打开文件夹失败: $e');
|
||||
}
|
||||
}
|
||||
|
||||
String _getParentPath(String path) {
|
||||
if (path.isEmpty || path == '/') return '/';
|
||||
final parts = path.split('/')..removeLast();
|
||||
final result = parts.join('/');
|
||||
return result.isEmpty ? '/' : result;
|
||||
}
|
||||
|
||||
Color _statusColor(_ActivityStatus status, ColorScheme colorScheme) {
|
||||
switch (status) {
|
||||
case _ActivityStatus.completed:
|
||||
return Colors.green;
|
||||
case _ActivityStatus.failed:
|
||||
return colorScheme.error;
|
||||
case _ActivityStatus.active:
|
||||
return colorScheme.primary;
|
||||
case _ActivityStatus.pending:
|
||||
return colorScheme.tertiary;
|
||||
}
|
||||
}
|
||||
|
||||
String _statusLabel(_ActivityItem item) {
|
||||
final prefix = item.type == _ActivityType.upload ? '上传' : '下载';
|
||||
switch (item.status) {
|
||||
case _ActivityStatus.completed:
|
||||
return '$prefix完成';
|
||||
case _ActivityStatus.failed:
|
||||
return '$prefix失败';
|
||||
case _ActivityStatus.active:
|
||||
return '$prefix中...';
|
||||
case _ActivityStatus.pending:
|
||||
return '等待$prefix...';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum _ActivityType { upload, download }
|
||||
|
||||
enum _ActivityStatus { completed, failed, active, pending }
|
||||
|
||||
class _ActivityItem {
|
||||
final String name;
|
||||
final _ActivityType type;
|
||||
final _ActivityStatus status;
|
||||
final DateTime createdAt;
|
||||
final String path;
|
||||
final String? savePath;
|
||||
|
||||
_ActivityItem({
|
||||
required this.name,
|
||||
required this.type,
|
||||
required this.status,
|
||||
required this.createdAt,
|
||||
required this.path,
|
||||
this.savePath,
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import '../../../widgets/search_dialog.dart';
|
||||
|
||||
class SearchEntryCard extends StatelessWidget {
|
||||
const SearchEntryCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
child: InkWell(
|
||||
onTap: () => SearchDialog.show(context),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(LucideIcons.search, size: 22, color: theme.hintColor),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'搜索文件...',
|
||||
style: theme.textTheme.bodyLarge?.copyWith(color: theme.hintColor),
|
||||
),
|
||||
const Spacer(),
|
||||
Icon(LucideIcons.arrowRight, size: 18, color: theme.hintColor.withValues(alpha: 0.5)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:lucide_icons/lucide_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:cloudreve4_flutter/presentation/providers/user_setting_provider.dart';
|
||||
|
||||
class StorageUsageCard extends StatelessWidget {
|
||||
const StorageUsageCard({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
return Consumer<UserSettingProvider>(
|
||||
builder: (context, userSetting, _) {
|
||||
final capacity = userSetting.capacity;
|
||||
final used = capacity?.used ?? 0;
|
||||
final total = capacity?.total ?? 0;
|
||||
final percentage = capacity?.usagePercentage ?? 0;
|
||||
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(LucideIcons.hardDrive, size: 20, color: colorScheme.primary),
|
||||
const SizedBox(width: 8),
|
||||
Text('存储空间', style: theme.textTheme.titleMedium?.copyWith(fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Center(
|
||||
child: SizedBox(
|
||||
width: 160,
|
||||
height: 90,
|
||||
child: CustomPaint(
|
||||
painter: _SemiCircleProgressPainter(
|
||||
progress: percentage / 100,
|
||||
color: colorScheme.primary,
|
||||
backgroundColor: colorScheme.primary.withValues(alpha: 0.12),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Center(
|
||||
child: Text(
|
||||
'${_formatBytes(used)} / ${_formatBytes(total)}',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.hintColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Center(
|
||||
child: Text(
|
||||
'已使用 ${percentage.toStringAsFixed(1)}%',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.hintColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
String _formatBytes(int bytes) {
|
||||
if (bytes < 1024) return '$bytes B';
|
||||
if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)} KB';
|
||||
if (bytes < 1024 * 1024 * 1024) return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
|
||||
return '${(bytes / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
|
||||
}
|
||||
}
|
||||
|
||||
class _SemiCircleProgressPainter extends CustomPainter {
|
||||
final double progress;
|
||||
final Color color;
|
||||
final Color backgroundColor;
|
||||
|
||||
_SemiCircleProgressPainter({
|
||||
required this.progress,
|
||||
required this.color,
|
||||
required this.backgroundColor,
|
||||
});
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final strokeWidth = 14.0;
|
||||
final center = Offset(size.width / 2, size.height);
|
||||
final radius = min(size.width / 2, size.height) - strokeWidth / 2;
|
||||
|
||||
final bgPaint = Paint()
|
||||
..color = backgroundColor
|
||||
..strokeWidth = strokeWidth
|
||||
..strokeCap = StrokeCap.round
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: center, radius: radius),
|
||||
pi,
|
||||
pi,
|
||||
false,
|
||||
bgPaint,
|
||||
);
|
||||
|
||||
final fgPaint = Paint()
|
||||
..color = color
|
||||
..strokeWidth = strokeWidth
|
||||
..strokeCap = StrokeCap.round
|
||||
..style = PaintingStyle.stroke;
|
||||
|
||||
final sweepAngle = pi * progress.clamp(0.0, 1.0);
|
||||
if (sweepAngle > 0) {
|
||||
canvas.drawArc(
|
||||
Rect.fromCircle(center: center, radius: radius),
|
||||
pi,
|
||||
sweepAngle,
|
||||
false,
|
||||
fgPaint,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(covariant _SemiCircleProgressPainter oldDelegate) {
|
||||
return oldDelegate.progress != progress || oldDelegate.color != color;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user