mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 19:47:47 +08:00
refactor ui resource list
This commit is contained in:
@@ -3,9 +3,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||||||
import 'package:ui/providers/activity.dart';
|
import 'package:ui/providers/activity.dart';
|
||||||
import 'package:ui/providers/series_details.dart';
|
import 'package:ui/providers/series_details.dart';
|
||||||
import 'package:ui/widgets/detail_card.dart';
|
import 'package:ui/widgets/detail_card.dart';
|
||||||
import 'package:ui/widgets/utils.dart';
|
import 'package:ui/widgets/resource_list.dart';
|
||||||
import 'package:ui/widgets/progress_indicator.dart';
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
import 'package:ui/widgets/widgets.dart';
|
|
||||||
|
|
||||||
class MovieDetailsPage extends ConsumerStatefulWidget {
|
class MovieDetailsPage extends ConsumerStatefulWidget {
|
||||||
static const route = "/movie/:id";
|
static const route = "/movie/:id";
|
||||||
@@ -125,59 +124,7 @@ class _NestedTabBarState extends ConsumerState<NestedTabBar>
|
|||||||
error: (error, trace) => Text("$error"),
|
error: (error, trace) => Text("$error"),
|
||||||
loading: () => const MyProgressIndicator());
|
loading: () => const MyProgressIndicator());
|
||||||
} else {
|
} else {
|
||||||
return Consumer(
|
return ResourceList(mediaId: widget.id);
|
||||||
builder: (context, ref, child) {
|
|
||||||
var torrents = ref.watch(mediaTorrentsDataProvider(
|
|
||||||
(mediaId: widget.id, seasonNumber: 0, episodeNumber: 0)));
|
|
||||||
return torrents.when(
|
|
||||||
data: (v) {
|
|
||||||
if (v.isEmpty) {
|
|
||||||
return const Center(
|
|
||||||
child: Text("无可用资源"),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return DataTable(
|
|
||||||
columns: const [
|
|
||||||
DataColumn(label: Text("名称")),
|
|
||||||
DataColumn(label: Text("大小")),
|
|
||||||
DataColumn(label: Text("seeders")),
|
|
||||||
DataColumn(label: Text("peers")),
|
|
||||||
DataColumn(label: Text("操作"))
|
|
||||||
],
|
|
||||||
rows: List.generate(v.length, (i) {
|
|
||||||
final torrent = v[i];
|
|
||||||
return DataRow(cells: [
|
|
||||||
DataCell(Text("${torrent.name}")),
|
|
||||||
DataCell(
|
|
||||||
Text("${torrent.size?.readableFileSize()}")),
|
|
||||||
DataCell(Text("${torrent.seeders}")),
|
|
||||||
DataCell(Text("${torrent.peers}")),
|
|
||||||
DataCell(IconButton(
|
|
||||||
icon: const Icon(Icons.download),
|
|
||||||
onPressed: () {
|
|
||||||
final f = ref
|
|
||||||
.read(mediaTorrentsDataProvider((
|
|
||||||
mediaId: widget.id,
|
|
||||||
seasonNumber: 0,
|
|
||||||
episodeNumber: 0
|
|
||||||
)).notifier)
|
|
||||||
.download(torrent)
|
|
||||||
.then((v) => showSnakeBar(
|
|
||||||
"开始下载:${torrent.name}"));
|
|
||||||
// .onError((error, trace) =>
|
|
||||||
// Utils.showSnakeBar("操作失败: $error"));
|
|
||||||
showLoadingWithFuture(f);
|
|
||||||
},
|
|
||||||
))
|
|
||||||
]);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
error: (error, trace) => Text("$error"),
|
|
||||||
loading: () => const MyProgressIndicator());
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:ui/providers/series_details.dart';
|
import 'package:ui/providers/series_details.dart';
|
||||||
import 'package:ui/widgets/detail_card.dart';
|
import 'package:ui/widgets/detail_card.dart';
|
||||||
|
import 'package:ui/widgets/resource_list.dart';
|
||||||
import 'package:ui/widgets/utils.dart';
|
import 'package:ui/widgets/utils.dart';
|
||||||
import 'package:ui/widgets/progress_indicator.dart';
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
import 'package:ui/widgets/widgets.dart';
|
import 'package:ui/widgets/widgets.dart';
|
||||||
@@ -106,10 +107,13 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 10,
|
width: 10,
|
||||||
),
|
),
|
||||||
Tooltip(message: "查看可用资源",child: IconButton(
|
Tooltip(
|
||||||
onPressed: () => showAvailableTorrents(widget.seriesId,
|
message: "查看可用资源",
|
||||||
ep.seasonNumber ?? 0, ep.episodeNumber ?? 0),
|
child: IconButton(
|
||||||
icon: const Icon(Icons.manage_search)),)
|
onPressed: () => showAvailableTorrents(widget.seriesId,
|
||||||
|
ep.seasonNumber ?? 0, ep.episodeNumber ?? 0),
|
||||||
|
icon: const Icon(Icons.manage_search)),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
]);
|
]);
|
||||||
@@ -154,10 +158,13 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
const SizedBox(
|
const SizedBox(
|
||||||
width: 10,
|
width: 10,
|
||||||
),
|
),
|
||||||
Tooltip(message: "查看可用资源",child: IconButton(
|
Tooltip(
|
||||||
onPressed: () =>
|
message: "查看可用资源",
|
||||||
showAvailableTorrents(widget.seriesId, k, 0),
|
child: IconButton(
|
||||||
icon: const Icon(Icons.manage_search)),)
|
onPressed: () =>
|
||||||
|
showAvailableTorrents(widget.seriesId, k, 0),
|
||||||
|
icon: const Icon(Icons.manage_search)),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
))
|
))
|
||||||
], rows: m[k]!),
|
], rows: m[k]!),
|
||||||
@@ -185,84 +192,21 @@ class _TvDetailsPageState extends ConsumerState<TvDetailsPage> {
|
|||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return Consumer(builder: (context, ref, _) {
|
return AlertDialog(
|
||||||
final torrents = ref.watch(mediaTorrentsDataProvider(
|
//title: Text("资源"),
|
||||||
(mediaId: id, seasonNumber: season, episodeNumber: episode)));
|
content: SelectionArea(
|
||||||
|
child: SizedBox(
|
||||||
return AlertDialog(
|
width: MediaQuery.of(context).size.width * 0.7,
|
||||||
//title: Text("资源"),
|
height: MediaQuery.of(context).size.height * 0.6,
|
||||||
content: SelectionArea(
|
child: SingleChildScrollView(
|
||||||
child: SizedBox(
|
child: ResourceList(
|
||||||
width: MediaQuery.of(context).size.width * 0.7,
|
mediaId: id,
|
||||||
height: MediaQuery.of(context).size.height * 0.6,
|
seasonNum: season,
|
||||||
child: torrents.when(
|
episodeNum: episode,
|
||||||
data: (v) {
|
),
|
||||||
bool hasPrivate = false;
|
|
||||||
for (final item in v) {
|
|
||||||
if (item.isPrivate == true) {
|
|
||||||
hasPrivate = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final columns = [
|
|
||||||
const DataColumn(label: Text("名称")),
|
|
||||||
const DataColumn(label: Text("大小")),
|
|
||||||
const DataColumn(label: Text("S/P")),
|
|
||||||
const DataColumn(label: Text("来源")),
|
|
||||||
];
|
|
||||||
if (hasPrivate) {
|
|
||||||
columns.add(const DataColumn(label: Text("消耗")));
|
|
||||||
}
|
|
||||||
columns.add(const DataColumn(label: Text("下载")));
|
|
||||||
|
|
||||||
return SingleChildScrollView(
|
|
||||||
child: DataTable(
|
|
||||||
dataTextStyle: const TextStyle(fontSize: 12),
|
|
||||||
columns: columns,
|
|
||||||
rows: List.generate(v.length, (i) {
|
|
||||||
final torrent = v[i];
|
|
||||||
final rows = [
|
|
||||||
DataCell(Text("${torrent.name}")),
|
|
||||||
DataCell(Text(
|
|
||||||
"${torrent.size?.readableFileSize()}")),
|
|
||||||
DataCell(Text(
|
|
||||||
"${torrent.seeders}/${torrent.peers}")),
|
|
||||||
DataCell(Text(torrent.source ?? "-")),
|
|
||||||
];
|
|
||||||
if (hasPrivate) {
|
|
||||||
rows.add(DataCell(Text(torrent.isPrivate == true
|
|
||||||
? "${torrent.downloadFactor}dl/${torrent.uploadFactor}up"
|
|
||||||
: "-")));
|
|
||||||
}
|
|
||||||
|
|
||||||
rows.add(DataCell(IconButton(
|
|
||||||
icon: const Icon(Icons.download),
|
|
||||||
onPressed: () async {
|
|
||||||
var f = ref
|
|
||||||
.read(mediaTorrentsDataProvider((
|
|
||||||
mediaId: id,
|
|
||||||
seasonNumber: season,
|
|
||||||
episodeNumber: episode
|
|
||||||
)).notifier)
|
|
||||||
.download(torrent)
|
|
||||||
.then((v) =>
|
|
||||||
showSnakeBar("开始下载:${torrent.name}"));
|
|
||||||
showLoadingWithFuture(f);
|
|
||||||
},
|
|
||||||
)));
|
|
||||||
return DataRow(cells: rows);
|
|
||||||
})));
|
|
||||||
},
|
|
||||||
error: (err, trace) {
|
|
||||||
return "$err".contains("no resource found")
|
|
||||||
? const Center(
|
|
||||||
child: Text("没有资源"),
|
|
||||||
)
|
|
||||||
: Text("$err");
|
|
||||||
},
|
|
||||||
loading: () => const MyProgressIndicator()),
|
|
||||||
),
|
),
|
||||||
));
|
),
|
||||||
});
|
));
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
88
ui/lib/widgets/resource_list.dart
Normal file
88
ui/lib/widgets/resource_list.dart
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:ui/providers/series_details.dart';
|
||||||
|
import 'package:ui/widgets/progress_indicator.dart';
|
||||||
|
import 'package:ui/widgets/utils.dart';
|
||||||
|
import 'package:ui/widgets/widgets.dart';
|
||||||
|
|
||||||
|
class ResourceList extends ConsumerWidget {
|
||||||
|
final String mediaId;
|
||||||
|
final int seasonNum;
|
||||||
|
final int episodeNum;
|
||||||
|
|
||||||
|
const ResourceList(
|
||||||
|
{super.key,
|
||||||
|
required this.mediaId,
|
||||||
|
this.seasonNum = 0,
|
||||||
|
this.episodeNum = 0});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final torrents = ref.watch(mediaTorrentsDataProvider((
|
||||||
|
mediaId: mediaId,
|
||||||
|
seasonNumber: seasonNum,
|
||||||
|
episodeNumber: episodeNum
|
||||||
|
)));
|
||||||
|
return torrents.when(
|
||||||
|
data: (v) {
|
||||||
|
bool hasPrivate = false;
|
||||||
|
for (final item in v) {
|
||||||
|
if (item.isPrivate == true) {
|
||||||
|
hasPrivate = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final columns = [
|
||||||
|
const DataColumn(label: Text("名称")),
|
||||||
|
const DataColumn(label: Text("大小")),
|
||||||
|
const DataColumn(label: Text("S/P")),
|
||||||
|
const DataColumn(label: Text("来源")),
|
||||||
|
];
|
||||||
|
if (hasPrivate) {
|
||||||
|
columns.add(const DataColumn(label: Text("消耗")));
|
||||||
|
}
|
||||||
|
columns.add(const DataColumn(label: Text("下载")));
|
||||||
|
|
||||||
|
return DataTable(
|
||||||
|
dataTextStyle: const TextStyle(fontSize: 12),
|
||||||
|
columns: columns,
|
||||||
|
rows: List.generate(v.length, (i) {
|
||||||
|
final torrent = v[i];
|
||||||
|
final rows = [
|
||||||
|
DataCell(Text("${torrent.name}")),
|
||||||
|
DataCell(Text("${torrent.size?.readableFileSize()}")),
|
||||||
|
DataCell(Text("${torrent.seeders}/${torrent.peers}")),
|
||||||
|
DataCell(Text(torrent.source ?? "-")),
|
||||||
|
];
|
||||||
|
if (hasPrivate) {
|
||||||
|
rows.add(DataCell(Text(torrent.isPrivate == true
|
||||||
|
? "${torrent.downloadFactor}dl/${torrent.uploadFactor}up"
|
||||||
|
: "-")));
|
||||||
|
}
|
||||||
|
|
||||||
|
rows.add(DataCell(IconButton(
|
||||||
|
icon: const Icon(Icons.download),
|
||||||
|
onPressed: () async {
|
||||||
|
var f = ref
|
||||||
|
.read(mediaTorrentsDataProvider((
|
||||||
|
mediaId: mediaId,
|
||||||
|
seasonNumber: seasonNum,
|
||||||
|
episodeNumber: episodeNum
|
||||||
|
)).notifier)
|
||||||
|
.download(torrent)
|
||||||
|
.then((v) => showSnakeBar("开始下载:${torrent.name}"));
|
||||||
|
showLoadingWithFuture(f);
|
||||||
|
},
|
||||||
|
)));
|
||||||
|
return DataRow(cells: rows);
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
error: (err, trace) {
|
||||||
|
return "$err".contains("no resource found")
|
||||||
|
? const Center(
|
||||||
|
child: Text("没有资源"),
|
||||||
|
)
|
||||||
|
: Text("$err");
|
||||||
|
},
|
||||||
|
loading: () => const MyProgressIndicator());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user