diff --git a/lib/components/gallery_basic_info.dart b/lib/components/gallery_basic_info.dart index fa343f1..8435e3f 100644 --- a/lib/components/gallery_basic_info.dart +++ b/lib/components/gallery_basic_info.dart @@ -1,18 +1,24 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:go_router/go_router.dart'; +import '../api/file.dart'; import '../api/gallery.dart'; import 'thumbnail.dart'; +import '../viewer/single.dart'; class GalleryBasicInfo extends StatelessWidget { - const GalleryBasicInfo(this.gMeta, this.firstPage, {Key? key, this.fileId}) + const GalleryBasicInfo(this.gMeta, this.firstPage, + {Key? key, this.fileId, this.gData, this.files}) : super(key: key); final GMeta gMeta; final ExtendedPMeta firstPage; final int? fileId; + final GalleryData? gData; + final EhFiles? files; @override Widget build(BuildContext context) { + final cs = Theme.of(context).colorScheme; return SizedBox( height: 300, child: Column(children: [ @@ -26,8 +32,11 @@ class GalleryBasicInfo extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - SelectableText(gMeta.preferredTitle), - SelectableText(gMeta.uploader), + SelectableText(gMeta.preferredTitle, + style: TextStyle( + fontWeight: FontWeight.bold, color: cs.primary)), + SelectableText(gMeta.uploader, + style: TextStyle(color: cs.secondary)), SelectableText(gMeta.category), ], )) @@ -39,7 +48,9 @@ class GalleryBasicInfo extends StatelessWidget { children: [ ElevatedButton( onPressed: () { - context.push('/gallery/${gMeta.gid}/page/1'); + context.push('/gallery/${gMeta.gid}/page/1', + extra: SinglePageViewerExtra( + data: gData, files: files)); }, child: Text(AppLocalizations.of(context)!.read)), ElevatedButton( diff --git a/lib/components/gallery_info.dart b/lib/components/gallery_info.dart index 2b5f128..67705bf 100644 --- a/lib/components/gallery_info.dart +++ b/lib/components/gallery_info.dart @@ -5,6 +5,7 @@ import '../api/file.dart'; import '../api/gallery.dart'; import 'gallery_basic_info.dart'; import 'gallery_info_desktop.dart'; +import 'tags.dart'; import 'thumbnail_gridview.dart'; class GalleryInfo extends StatefulWidget { @@ -46,8 +47,8 @@ class _GalleryInfo extends State with ThemeModeWidget { context.canPop() ? context.pop() : context.go("/"); }, ), - title: SelectableText( - maxLines: 2, minLines: 1, widget.gData.meta.preferredTitle), + title: SelectableText(widget.gData.meta.preferredTitle, + maxLines: 1, minLines: 1), actions: [ buildThemeModeIcon(context), buildMoreVertSettingsButon(context), @@ -58,15 +59,29 @@ class _GalleryInfo extends State with ThemeModeWidget { ? SliverList( delegate: SliverChildListDelegate([ GalleryBasicInfo(widget.gData.meta, firstPage, - fileId: firstFileId), + fileId: firstFileId, + gData: widget.gData, + files: widget.files), + const Divider(indent: 20, endIndent: 20), ]), ) : SliverList( delegate: SliverChildListDelegate([ GalleryInfoDesktop(widget.gData, - fileId: firstFileId, controller: controller), + fileId: firstFileId, + controller: controller, + files: widget.files), ]), ), + useMobile + ? TagsPanel(widget.gData.tags, + sliver: true, + margin: const EdgeInsets.symmetric(horizontal: 20.0)) + : SliverToBoxAdapter(child: Container()), + useMobile + ? const SliverToBoxAdapter( + child: Divider(indent: 20, endIndent: 20)) + : SliverToBoxAdapter(child: Container()), ThumbnailGridView( widget.gData, SliverGridDelegateWithFixedCrossAxisCount( diff --git a/lib/components/gallery_info_desktop.dart b/lib/components/gallery_info_desktop.dart index 9219177..17ae0de 100644 --- a/lib/components/gallery_info_desktop.dart +++ b/lib/components/gallery_info_desktop.dart @@ -2,12 +2,14 @@ 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 '../api/file.dart'; import '../api/gallery.dart'; import '../main.dart'; import '../utils/filesize.dart'; import 'rate.dart'; import 'tags.dart'; import 'thumbnail.dart'; +import '../viewer/single.dart'; class _KeyValue extends StatelessWidget { const _KeyValue(this.name, this.value, @@ -38,11 +40,13 @@ class _KeyValue extends StatelessWidget { } class GalleryInfoDesktop extends StatelessWidget { - const GalleryInfoDesktop(this.gData, {Key? key, this.fileId, this.controller}) + const GalleryInfoDesktop(this.gData, + {Key? key, this.fileId, this.controller, this.files}) : super(key: key); final GalleryData gData; final int? fileId; final ScrollController? controller; + final EhFiles? files; @override Widget build(BuildContext context) { @@ -130,22 +134,27 @@ class GalleryInfoDesktop extends StatelessWidget { const VerticalDivider(indent: 10, endIndent: 10), SizedBox( width: 150, - child: Column(children: [ - ElevatedButton( - onPressed: () { - context.push( - '/gallery/${gData.meta.gid}/page/1'); - }, - child: - Text(AppLocalizations.of(context)!.read)), - ElevatedButton( - onPressed: () { - context.push( - '/dialog/download/zip/${gData.meta.gid}'); - }, - child: Text( - AppLocalizations.of(context)!.download)), - ])), + child: Column( + mainAxisAlignment: + MainAxisAlignment.spaceAround, + children: [ + ElevatedButton( + onPressed: () { + context.push( + '/gallery/${gData.meta.gid}/page/1', + extra: SinglePageViewerExtra( + data: gData, files: files)); + }, + child: Text( + AppLocalizations.of(context)!.read)), + ElevatedButton( + onPressed: () { + context.push( + '/dialog/download/zip/${gData.meta.gid}'); + }, + child: Text(AppLocalizations.of(context)! + .download)), + ])), ])), ], )) diff --git a/lib/components/tags.dart b/lib/components/tags.dart index 8432c26..e7e3eea 100644 --- a/lib/components/tags.dart +++ b/lib/components/tags.dart @@ -10,9 +10,13 @@ import 'tag_tooltip.dart'; import 'scroll_parent.dart'; class TagsPanel extends StatefulWidget { - const TagsPanel(this.tags, {Key? key, this.controller}) : super(key: key); + const TagsPanel(this.tags, + {Key? key, this.controller, this.sliver, this.margin}) + : super(key: key); final List tags; final ScrollController? controller; + final bool? sliver; + final EdgeInsetsGeometry? margin; @override State createState() => _TagsPanel(); @@ -53,18 +57,14 @@ class _TagsPanel extends State { final cs = Theme.of(context).colorScheme; final stt = prefs.getBool("showTranslatedTag") ?? MainApp.of(context).lang.toLocale().languageCode == "zh"; - final re = ListView.builder( - physics: isIOS || ua.isSafari - ? const ClampingScrollPhysics() - : null, - padding: const EdgeInsets.all(8), - itemCount: data!.length, - itemBuilder: (context, index) { - final t = data![index].$1; - final ta = data![index].$2; - final namespace = - "${stt ? (tags.getTagTranslate(t) ?? t) : t}${AppLocalizations.of(context)!.colon}"; - return Wrap( + Widget itemBuilder(BuildContext context, int index) { + final t = data![index].$1; + final ta = data![index].$2; + final namespace = + "${stt ? (tags.getTagTranslate(t) ?? t) : t}${AppLocalizations.of(context)!.colon}"; + return Container( + margin: widget.margin, + child: Wrap( children: List.generate(ta.length + 1, (index) { if (index == 0) { return Container( @@ -81,8 +81,20 @@ class _TagsPanel extends State { ? TagTooltip(ta[index - 1]!) : TagWidget(ta[index - 1]!)); } - })); - }); + }))); + } + + final re = widget.sliver == true + ? SliverList.builder( + itemBuilder: itemBuilder, + itemCount: data!.length, + ) + : ListView.builder( + physics: + isIOS || ua.isSafari ? const ClampingScrollPhysics() : null, + padding: const EdgeInsets.all(8), + itemCount: data!.length, + itemBuilder: itemBuilder); return widget.controller != null ? ScrollParent(controller: widget.controller!, child: re) : re; diff --git a/lib/gallery.dart b/lib/gallery.dart index d3ea169..7f05829 100644 --- a/lib/gallery.dart +++ b/lib/gallery.dart @@ -102,7 +102,7 @@ class _GalleryPage extends State leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () { - context.canPop() ? context.pop() : context.go("/"); + context.canPop() ? context.pop() : context.go("/gallery"); }, ), title: Text(title), diff --git a/lib/settings.dart b/lib/settings.dart index 290bb0b..2846e95 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart'; import 'package:logging/logging.dart'; import 'globals.dart'; import 'main.dart'; +import 'utils.dart'; final _log = Logger("SettingsPage"); @@ -278,21 +279,24 @@ class _SettingsPage extends State with ThemeModeWidget { .showTranslatedTag), ), ), - Container( - padding: const EdgeInsets.symmetric(vertical: 8), - child: CheckboxMenuButton( - value: _preventScreenCapture, - onChanged: (bool? value) { - if (value != null) { - setState(() { - _preventScreenCapture = value; - }); - } - }, - child: Text(AppLocalizations.of(context)! - .preventScreenCapture), - ), - ), + isAndroid || isWindows + ? Container( + padding: + const EdgeInsets.symmetric(vertical: 8), + child: CheckboxMenuButton( + value: _preventScreenCapture, + onChanged: (bool? value) { + if (value != null) { + setState(() { + _preventScreenCapture = value; + }); + } + }, + child: Text(AppLocalizations.of(context)! + .preventScreenCapture), + ), + ) + : Container(), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ diff --git a/lib/viewer/single.dart b/lib/viewer/single.dart index 9296098..20c56f6 100644 --- a/lib/viewer/single.dart +++ b/lib/viewer/single.dart @@ -40,9 +40,10 @@ class _SinglePageViewer extends State with ThemeModeWidget { late int _index; late GalleryData? _data; late EhFiles? _files; + late String _back; CancelToken? _cancel; bool _isLoading = false; - bool _page_changed = false; + bool _pageChanged = false; Object? _error; @override void initState() { @@ -50,6 +51,7 @@ class _SinglePageViewer extends State with ThemeModeWidget { _pageController = PageController(initialPage: _index); _data = widget.data; _files = widget.files; + _back = "/gallery/${widget.gid}"; super.initState(); } @@ -76,11 +78,11 @@ class _SinglePageViewer extends State with ThemeModeWidget { if (_index < 0) { _index = 0; _pageController.jumpToPage(_index); - _page_changed = true; + _pageChanged = true; } else if (_index >= _data!.pages.length) { _index = _data!.pages.length - 1; _pageController.jumpToPage(_index); - _page_changed = true; + _pageChanged = true; } setState(() { _files = fileData; @@ -102,7 +104,7 @@ class _SinglePageViewer extends State with ThemeModeWidget { void _onPageChanged(BuildContext context) { context.replace("/gallery/${widget.gid}/page/${_index + 1}", extra: SinglePageViewerExtra(data: _data, files: _files)); - _page_changed = false; + _pageChanged = false; } @override @@ -116,7 +118,7 @@ class _SinglePageViewer extends State with ThemeModeWidget { leading: IconButton( icon: const Icon(Icons.arrow_back), onPressed: () { - context.canPop() ? context.pop() : context.go("/"); + context.canPop() ? context.pop() : context.go(_back); }, ), title: Text(AppLocalizations.of(context)!.loading), @@ -143,7 +145,7 @@ class _SinglePageViewer extends State with ThemeModeWidget { label: Text(AppLocalizations.of(context)!.retry)) ]))); } - if (_page_changed) { + if (_pageChanged) { _onPageChanged(context); } return Scaffold( @@ -167,7 +169,7 @@ class _SinglePageViewer extends State with ThemeModeWidget { } }), KeyAction(LogicalKeyboardKey.backspace, "back", () { - context.canPop() ? context.pop() : context.go("/"); + context.canPop() ? context.pop() : context.go(_back); }), ], child: PhotoViewGallery.builder(