Skip to content

Commit

Permalink
show meta info in task detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc committed May 25, 2024
1 parent afbda5a commit d2d4579
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/components/rate.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import 'package:flutter/material.dart';

class Rate extends StatelessWidget {
const Rate(this.rate, {super.key, this.fontSize});
const Rate(this.rate, {super.key, this.fontSize, this.selectable = false});
final double rate;
final double? fontSize;
final bool selectable;

@override
Widget build(BuildContext context) {
final cs = Theme.of(context).colorScheme;
final style = TextStyle(color: cs.secondary, fontSize: fontSize);
final t = " $rate";
return Row(
children: [
for (var i = 1; i < 6; i++)
Expand All @@ -20,8 +23,7 @@ class Rate extends StatelessWidget {
color: cs.primary,
size: fontSize,
),
Text(" $rate",
style: TextStyle(color: cs.secondary, fontSize: fontSize)),
selectable ? SelectableText(t, style: style) : Text(t, style: style),
],
);
}
Expand Down
55 changes: 55 additions & 0 deletions lib/dialog/task_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:percent_indicator/linear_percent_indicator.dart';
import '../api/task.dart';
import '../components/rate.dart';
import '../globals.dart';
import '../main.dart';
import '../utils/duration.dart';
import '../utils/filesize.dart';

Expand Down Expand Up @@ -242,6 +245,53 @@ class _TaskPage extends State<TaskPage> {
);
}

bool get haveMetaInfo {
if (!tasks.tasksList.contains(widget.id)) return false;
final task = tasks.tasks[widget.id]!;
return task.base.type == TaskType.download &&
tasks.meta.containsKey(task.base.gid);
}

Widget _buildMetaInfo(BuildContext context) {
if (!haveMetaInfo) return Container();
final task = tasks.tasks[widget.id]!;
final meta = tasks.meta[task.base.gid]!;
final i18n = AppLocalizations.of(context)!;
final locale = MainApp.of(context).lang.toLocale().toString();
DateTime? posted;
final r = int.tryParse(meta.posted);
if (r != null) {
posted = DateTime.fromMillisecondsSinceEpoch(r! * 1000);
}
final cs = Theme.of(context).colorScheme;
double? rating = double.tryParse(meta.rating);
return Column(key: ValueKey("task_detail_meta_${widget.id}"), children: [
_KeyValue(i18n.title2, meta.title, fontSize: 16),
_KeyValue(i18n.titleJpn, meta.titleJpn, fontSize: 16),
_KeyValue(i18n.category, meta.category, fontSize: 16),
_KeyValue(i18n.uploader, meta.uploader, fontSize: 16),
posted != null
? _KeyValue(
i18n.posted, DateFormat.yMd(locale).add_jms().format(posted),
fontSize: 16)
: Container(),
_KeyValue(i18n.pageLength, meta.filecount, fontSize: 16),
_KeyValue(i18n.fileSize, getFileSize(meta.filesize), fontSize: 16),
_KeyValue(i18n.visible, meta.expunged ? i18n.no : i18n.yes, fontSize: 16),
rating != null
? Row(children: [
SizedBox(
width: 80,
child: Center(
child: Text(i18n.rating,
textAlign: TextAlign.center,
style: TextStyle(color: cs.primary, fontSize: 16)))),
Expanded(child: Rate(rating!, fontSize: 16, selectable: true)),
])
: Container(),
]);
}

@override
Widget build(BuildContext context) {
tryInitApi(context);
Expand Down Expand Up @@ -282,6 +332,11 @@ class _TaskPage extends State<TaskPage> {
: Container()),
SliverToBoxAdapter(child: _buildProgress(context)),
_buildMoreProgress(context),
SliverToBoxAdapter(
child: haveMetaInfo
? Divider(indent: indent, endIndent: indent)
: Container()),
SliverToBoxAdapter(child: _buildMetaInfo(context)),
],
),
);
Expand Down
4 changes: 3 additions & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,7 @@
"type": "int"
}
}
}
},
"category": "Category",
"uploader": "Uploader"
}
4 changes: 3 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,7 @@
"type": "int"
}
}
}
},
"category": "分类",
"uploader": "上传者"
}

0 comments on commit d2d4579

Please sign in to comment.