mirror of
https://codeberg.org/shroff/phylum.git
synced 2026-01-06 03:31:02 -06:00
[client] Downloads list
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/integrations/download_manager.dart';
|
||||
import 'package:phylum/ui/downloads/downloads_dialog.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class DownloadButton extends StatefulWidget {
|
||||
@@ -65,6 +66,7 @@ class _DownloadButtonState extends State<DownloadButton> {
|
||||
: LinearProgressIndicator(
|
||||
value: total == 0 ? null : (received / total),
|
||||
),
|
||||
onTap: () => DownloadsDialog.show(context),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
41
client/lib/ui/downloads/downloads_dialog.dart
Normal file
41
client/lib/ui/downloads/downloads_dialog.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/ui/downloads/downloads_list.dart';
|
||||
|
||||
class DownloadsDialog extends StatelessWidget {
|
||||
const DownloadsDialog({super.key});
|
||||
|
||||
static void show(BuildContext context) {
|
||||
showDialog(context: context, builder: (context) => const DownloadsDialog());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final size = MediaQuery.sizeOf(context);
|
||||
if (size.width < 600) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Downloads'),
|
||||
),
|
||||
body: const DownloadsList());
|
||||
} else {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: 800,
|
||||
child: Card(
|
||||
margin: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
AppBar(
|
||||
title: const Text('Downloads'),
|
||||
leading: const CloseButton(),
|
||||
backgroundColor: Colors.transparent,
|
||||
),
|
||||
Expanded(child: const DownloadsList()),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,51 +1,17 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/integrations/download_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
const _showedDownloads = 3;
|
||||
|
||||
class DownloadsSliver extends StatefulWidget {
|
||||
const DownloadsSliver({super.key});
|
||||
|
||||
@override
|
||||
State<DownloadsSliver> createState() => _DownloadsSliverState();
|
||||
}
|
||||
|
||||
class _DownloadsSliverState extends State<DownloadsSliver> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
class DownloadsList extends StatelessWidget {
|
||||
const DownloadsList({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final allTasks = context.watch<DownloadManager>().tasks.toList(growable: false);
|
||||
final tasks = allTasks.sublist(max(allTasks.length - _showedDownloads, 0)).toList(growable: false);
|
||||
return SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, i) {
|
||||
if (i == 0) {
|
||||
return const ListTile(dense: true, title: Text('Downloads'));
|
||||
}
|
||||
if (i > tasks.length) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
child: Text('View All (${allTasks.length - _showedDownloads} More)'),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return _DownloadTaskView(notifier: tasks[tasks.length - i]);
|
||||
},
|
||||
childCount: tasks.length + 1 + (allTasks.length >= _showedDownloads ? 1 : 0),
|
||||
),
|
||||
final tasks = context.watch<DownloadManager>().tasks.toList(growable: false);
|
||||
return ListView.builder(
|
||||
itemBuilder: (context, i) => _DownloadTaskView(notifier: tasks[tasks.length - i]),
|
||||
itemCount: tasks.length,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:phylum/ui/sync/sliver_offline.dart';
|
||||
import 'package:phylum/ui/sync/sliver_downloads.dart';
|
||||
|
||||
import 'sliver_actions.dart';
|
||||
|
||||
@@ -29,7 +28,10 @@ class SyncDialog extends StatelessWidget {
|
||||
margin: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
AppBar(title: const Text('Server Status'), leading: const CloseButton(), backgroundColor: Colors.transparent),
|
||||
AppBar(
|
||||
title: const Text('Server Status'),
|
||||
leading: const CloseButton(),
|
||||
backgroundColor: Colors.transparent),
|
||||
Expanded(child: buildContents(context)),
|
||||
],
|
||||
),
|
||||
@@ -42,7 +44,6 @@ class SyncDialog extends StatelessWidget {
|
||||
Widget buildContents(BuildContext context) => const CustomScrollView(
|
||||
slivers: [
|
||||
OfflineSliver(),
|
||||
DownloadsSliver(),
|
||||
ActionsSliver(),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user