Skip to content

Commit

Permalink
Use better way to handle gallery with no images and page with no images
Browse files Browse the repository at this point in the history
  • Loading branch information
lifegpc authored Jun 2, 2024
1 parent 9e0aa9c commit f5666a8
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ RUN apt-get clean

RUN git clone https://github.com/flutter/flutter.git -b stable --depth 1 /flutter
ENV PATH="/flutter/bin:$PATH"
RUN flutter doctor
RUN flutter doctor && dart --disable-analytics && flutter --disable-analytics
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"vscode": {
"extensions": [
"Dart-Code.dart-code",
"Dart-Code.flutter"
"Dart-Code.flutter",
"Google.arb-editor"
]
}
}
Expand Down
6 changes: 4 additions & 2 deletions lib/components/gallery_basic_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class GalleryBasicInfo extends StatelessWidget {
const GalleryBasicInfo(this.gMeta, this.firstPage,
{super.key, this.fileId, this.gData, this.files});
final GMeta gMeta;
final ExtendedPMeta firstPage;
final ExtendedPMeta? firstPage;
final int? fileId;
final GalleryData? gData;
final EhFiles? files;
Expand All @@ -27,7 +27,9 @@ class GalleryBasicInfo extends StatelessWidget {
flex: 2,
child: Container(
margin: const EdgeInsets.only(right: 8),
child: Thumbnail(firstPage, fileId: fileId, gid: gMeta.gid),
child: firstPage != null
? Thumbnail(firstPage!, fileId: fileId, gid: gMeta.gid)
: Container(),
)),
Expanded(
flex: 3,
Expand Down
6 changes: 3 additions & 3 deletions lib/components/gallery_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class _GalleryInfo extends State<GalleryInfo> with ThemeModeWidget {
@override
Widget build(BuildContext context) {
bool useMobile = MediaQuery.of(context).size.width <= 810;
final firstPage = widget.gData.pages.first;
final int? firstFileId = widget.files != null
? widget.files!.files[firstPage.token]!.first.id
final firstPage = widget.gData.pages.firstOrNull;
final int? firstFileId = widget.files != null && firstPage != null
? widget.files!.files[firstPage!.token]!.firstOrNull?.id
: null;
return CustomScrollView(
controller: controller,
Expand Down
9 changes: 6 additions & 3 deletions lib/components/gallery_info_desktop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ class GalleryInfoDesktop extends StatelessWidget {
child: Row(children: [
Expanded(
flex: 3,
child: Padding(padding: const EdgeInsets.only(right: 8.0),
child: Thumbnail(gData.pages.first,
fileId: fileId, gid: gData.meta.gid))),
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: gData.pages.isNotEmpty
? Thumbnail(gData.pages.first,
fileId: fileId, gid: gData.meta.gid)
: Container())),
Expanded(
flex: 7,
child: Column(
Expand Down
2 changes: 1 addition & 1 deletion lib/components/thumbnail_gridview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ThumbnailGridView extends StatelessWidget {
itemBuilder: (context, index) {
final page = npages[index]!;
final fileId =
files != null ? files!.files[page.token]!.first.id : null;
files != null ? files!.files[page.token]!.firstOrNull?.id : null;
final key = Key("thumbnail$gid-${page.index}");
return Container(
padding: const EdgeInsets.all(4),
Expand Down
40 changes: 37 additions & 3 deletions lib/dialog/task_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
Expand Down Expand Up @@ -89,13 +90,42 @@ class _TaskPage extends State<TaskPage> {
final maxWidth = MediaQuery.of(context).size.width;
final endIndent = maxWidth < 400 ? 5.0 : 10.0;
final indent = endIndent + 70;
final allowLink = task.base.gid != 0 &&
(typ != TaskType.download ||
task.status == TaskStatus.running ||
task.status == TaskStatus.finished);
String? title;
if (typ == TaskType.download && tasks.meta.containsKey(task.base.gid)) {
title = tasks.meta[task.base.gid]!.preferredTitle;
}
final cs = Theme.of(context).colorScheme;
return Column(
children: [
_KeyValue(i18n.taskId, widget.id.toString(), fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.taskType, typ.text(context), fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.gid, gid, fontSize: 16),
Row(children: [
SizedBox(
width: 80,
child: Center(
child: Text(i18n.gid,
textAlign: TextAlign.center,
style: TextStyle(color: cs.primary, fontSize: 16)))),
Expanded(
child: allowLink
? SelectableText.rich(TextSpan(
text: gid,
style: TextStyle(color: cs.secondary, fontSize: 16),
mouseCursor: SystemMouseCursors.click,
recognizer: TapGestureRecognizer()
..onTap = () {
context.push("/gallery/${task.base.gid}",
extra: GalleryPageExtra(title: title));
}))
: SelectableText(gid,
style: TextStyle(color: cs.secondary, fontSize: 16))),
]),
task.base.token.isEmpty
? Container()
: Divider(indent: indent, endIndent: endIndent),
Expand Down Expand Up @@ -324,8 +354,12 @@ class _TaskPage extends State<TaskPage> {
final indent = endIndent + 70;
return Column(key: ValueKey("task_detail_meta_${widget.id}"), children: [
_KeyValue(i18n.title2, meta.title, fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.titleJpn, meta.titleJpn, fontSize: 16),
meta.titleJpn.isNotEmpty
? Divider(indent: indent, endIndent: endIndent)
: Container(),
meta.titleJpn.isNotEmpty
? _KeyValue(i18n.titleJpn, meta.titleJpn, fontSize: 16)
: Container(),
Divider(indent: indent, endIndent: endIndent),
_KeyValue(i18n.category, meta.category, fontSize: 16),
Divider(indent: indent, endIndent: endIndent),
Expand Down

0 comments on commit f5666a8

Please sign in to comment.