torrent list

This commit is contained in:
royalcat 2024-04-27 14:00:34 +03:00
parent d8ee8a3a24
commit 0d7aac068c
23 changed files with 1285 additions and 698 deletions

View file

@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:tstor_ui/api/client.dart';
import 'package:tstor_ui/api/torrent.graphql.dart';
import 'package:tstor_ui/components/download.dart';
import 'package:tstor_ui/components/sliver_header.dart';
class DownloadsScreen extends StatefulWidget {
const DownloadsScreen({super.key});
@ -11,45 +12,98 @@ class DownloadsScreen extends StatefulWidget {
}
class _DownloadsScreenState extends State<DownloadsScreen> {
bool filterDownloading = false;
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: client.query$ListTorrents(),
key: GlobalKey(),
future: client.query$ListTorrents(Options$Query$ListTorrents(
variables: Variables$Query$ListTorrents(downloading: filterDownloading),
)),
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == null) {
return const Center(child: CircularProgressIndicator());
}
final torrents = snapshot.data?.parsedData?.torrents;
final torrents = snapshot.data!.parsedData!.torrents;
return ListView.builder(
itemCount: torrents.length,
itemBuilder: (context, index) {
final torrent = torrents[index];
return ListTile(
title: Text(torrent.name),
subtitle: DownloadProgress(
torrent.bytesCompleted, torrent.bytesCompleted + torrent.bytesMissing),
trailing: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => client.mutate$MarkTorrentDownload(
Options$Mutation$MarkTorrentDownload(
variables: Variables$Mutation$MarkTorrentDownload(
infohash: torrent.infohash,
),
),
return NestedScrollView(
floatHeaderSlivers: true,
headerSliverBuilder: (context, innerBoxIsScrolled) => [
HideableHeaderSliver(
height: 80,
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Wrap(
spacing: 8,
runSpacing: 8,
children: [
FilterChip(
label: const Text("Downloading"),
selected: filterDownloading,
onSelected: (value) => setState(() {
filterDownloading = value;
}),
),
icon: const Icon(Icons.download),
)
],
],
),
),
);
},
actions: [
IconButton(
icon: const Icon(Icons.refresh),
onPressed: () => setState(() {}),
),
],
),
],
body: snapshot.hasData && torrents != null
? ListView.builder(
itemCount: torrents.length,
itemBuilder: (context, index) => TorrentTile(torrent: torrents[index]),
)
: const Center(child: CircularProgressIndicator()),
);
},
);
}
}
class TorrentTile extends StatelessWidget {
final Query$ListTorrents$torrents torrent;
const TorrentTile({super.key, required this.torrent});
@override
Widget build(BuildContext context) {
return ListTile(
title: Text(torrent.name),
isThreeLine: true,
subtitle: Column(
children: [
DownloadProgress(
torrent.bytesCompleted,
torrent.bytesCompleted + torrent.bytesMissing,
),
Row(
children: [
Text("Peers: ${torrent.peers.length}"),
],
),
],
),
trailing: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
IconButton(
onPressed: () => client.mutate$MarkTorrentDownload(
Options$Mutation$MarkTorrentDownload(
variables: Variables$Mutation$MarkTorrentDownload(
infohash: torrent.infohash,
),
),
),
icon: const Icon(Icons.download),
)
],
),
);
}
}

View file

@ -5,6 +5,7 @@ import 'package:tstor_ui/api/client.dart';
import 'package:tstor_ui/api/fs_entry.graphql.dart';
import 'package:tstor_ui/api/torrent.graphql.dart';
import 'package:tstor_ui/components/download.dart';
import 'package:tstor_ui/components/sliver_header.dart';
import 'package:tstor_ui/font/t_icons_icons.dart';
import 'package:path/path.dart' as p;
@ -116,7 +117,7 @@ class _FileViewScreenState extends State<FileViewScreen> {
return CustomScrollView(
slivers: [
EntryInfoSliver(entry: entry),
EntryHeaderSliver(entry: entry),
SliverList.builder(
itemCount: entries.length,
itemBuilder: (context, index) {
@ -214,20 +215,18 @@ class DirEntry extends StatelessWidget {
}
}
class EntryInfoSliver extends StatelessWidget {
class EntryHeaderSliver extends StatelessWidget {
final Query$ListDir$fsEntry entry;
const EntryInfoSliver({super.key, required this.entry});
const EntryHeaderSliver({super.key, required this.entry});
@override
Widget build(BuildContext context) {
switch (entry) {
case Query$ListDir$fsEntry$$TorrentFS entry:
final total = entry.torrent.bytesCompleted + entry.torrent.bytesMissing;
return EntryInfoHeader(
icon: TIcons.bittorrent_bttold_logo,
title: Text(entry.torrent.name),
return HideableHeaderSliver(
leading: const Icon(TIcons.bittorrent_bttold_logo),
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -252,101 +251,10 @@ class EntryInfoSliver extends StatelessWidget {
);
default:
return EntryInfoHeader(
icon: Icons.folder,
title: Text(entry.name),
return HideableHeaderSliver(
leading: const Icon(Icons.folder),
body: Text(entry.name),
);
}
}
}
class EntryInfoHeader extends StatelessWidget {
final IconData icon;
final Widget title;
final Widget body;
final List<Widget>? actions;
const EntryInfoHeader({
super.key,
required this.icon,
required this.title,
required this.body,
this.actions,
});
@override
Widget build(BuildContext context) {
return SliverPersistentHeader(
floating: true,
pinned: false,
delegate: EntryInfoSliverHeaderDelegate(icon: icon, title: title, body: body),
);
}
}
class EntryInfoSliverHeaderDelegate extends SliverPersistentHeaderDelegate {
final IconData icon;
final Widget title;
final Widget body;
final List<Widget>? actions;
final double size;
const EntryInfoSliverHeaderDelegate({
required this.icon,
required this.title,
required this.body,
this.actions,
this.size = 150,
});
@override
double get maxExtent => size;
@override
double get minExtent => size;
@override
bool shouldRebuild(covariant SliverPersistentHeaderDelegate oldDelegate) => true;
@override
Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) {
final content = [
Icon(icon, size: 50),
Expanded(child: body),
];
if (actions != null && actions!.isNotEmpty) {
content.add(ButtonBar(children: actions!));
}
final appBarTheme = AppBarTheme.of(context);
final colorScheme = Theme.of(context).colorScheme;
final onTop = (shrinkOffset == 0);
return Material(
color:
onTop ? appBarTheme.backgroundColor ?? colorScheme.surface : colorScheme.surfaceContainer,
elevation: onTop ? 0 : appBarTheme.elevation ?? 3,
surfaceTintColor: appBarTheme.surfaceTintColor ?? colorScheme.surfaceTint,
child: ClipRect(
child: SizedBox(
height: maxExtent,
child: Column(
children: [
const Spacer(),
Row(
children: content,
),
const Spacer(),
const Divider(
height: 1,
thickness: 1,
),
],
),
),
),
);
}
}