diff --git a/lib/widget/album_viewer_mixin.dart b/lib/widget/album_viewer_mixin.dart index 522bb9f8..20af1782 100644 --- a/lib/widget/album_viewer_mixin.dart +++ b/lib/widget/album_viewer_mixin.dart @@ -9,8 +9,8 @@ import 'package:nc_photos/entity/file.dart'; import 'package:nc_photos/pref.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/widget/album_viewer_app_bar.dart'; -import 'package:nc_photos/widget/popup_menu_zoom.dart'; import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart'; +import 'package:nc_photos/widget/zoom_menu_button.dart'; mixin AlbumViewerMixin on SelectableItemStreamListMixin { @@ -44,22 +44,16 @@ mixin AlbumViewerMixin album: album, coverPreviewUrl: _coverPreviewUrl, actions: [ - PopupMenuButton( - icon: const Icon(Icons.photo_size_select_large), - tooltip: L10n.of(context).zoomTooltip, - itemBuilder: (context) => [ - PopupMenuZoom( - initialValue: _thumbZoomLevel, - minValue: 0, - maxValue: 2, - onChanged: (value) { - setState(() { - _thumbZoomLevel = value.round(); - }); - Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel); - }, - ), - ], + ZoomMenuButton( + initialZoom: _thumbZoomLevel, + minZoom: 0, + maxZoom: 2, + onZoomChanged: (value) { + setState(() { + _thumbZoomLevel = value.round(); + }); + Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel); + }, ), ...(actions ?? []), PopupMenuButton( diff --git a/lib/widget/archive_viewer.dart b/lib/widget/archive_viewer.dart index b9b686e6..72842957 100644 --- a/lib/widget/archive_viewer.dart +++ b/lib/widget/archive_viewer.dart @@ -19,9 +19,9 @@ import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/update_property.dart'; import 'package:nc_photos/widget/photo_list_item.dart'; -import 'package:nc_photos/widget/popup_menu_zoom.dart'; import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart'; import 'package:nc_photos/widget/viewer.dart'; +import 'package:nc_photos/widget/zoom_menu_button.dart'; class ArchiveViewerArguments { ArchiveViewerArguments(this.account); @@ -168,22 +168,16 @@ class _ArchiveViewerState extends State title: Text(L10n.of(context).albumArchiveLabel), floating: true, actions: [ - PopupMenuButton( - icon: const Icon(Icons.photo_size_select_large), - tooltip: L10n.of(context).zoomTooltip, - itemBuilder: (context) => [ - PopupMenuZoom( - initialValue: _thumbZoomLevel, - minValue: 0, - maxValue: 2, - onChanged: (value) { - setState(() { - _thumbZoomLevel = value.round(); - }); - Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel); - }, - ), - ], + ZoomMenuButton( + initialZoom: _thumbZoomLevel, + minZoom: 0, + maxZoom: 2, + onZoomChanged: (value) { + setState(() { + _thumbZoomLevel = value.round(); + }); + Pref.inst().setAlbumViewerZoomLevel(_thumbZoomLevel); + }, ), ], ); diff --git a/lib/widget/home_photos.dart b/lib/widget/home_photos.dart index 95377f3b..8ed6c72e 100644 --- a/lib/widget/home_photos.dart +++ b/lib/widget/home_photos.dart @@ -35,9 +35,9 @@ import 'package:nc_photos/widget/home_app_bar.dart'; import 'package:nc_photos/widget/measure.dart'; import 'package:nc_photos/widget/page_visibility_mixin.dart'; import 'package:nc_photos/widget/photo_list_item.dart'; -import 'package:nc_photos/widget/popup_menu_zoom.dart'; import 'package:nc_photos/widget/selectable_item_stream_list_mixin.dart'; import 'package:nc_photos/widget/viewer.dart'; +import 'package:nc_photos/widget/zoom_menu_button.dart'; class HomePhotos extends StatefulWidget { HomePhotos({ @@ -209,22 +209,16 @@ class _HomePhotosState extends State child: HomeSliverAppBar( account: widget.account, actions: [ - PopupMenuButton( - icon: const Icon(Icons.photo_size_select_large), - tooltip: L10n.of(context).zoomTooltip, - itemBuilder: (context) => [ - PopupMenuZoom( - initialValue: _thumbZoomLevel, - minValue: -1, - maxValue: 2, - onChanged: (value) { - setState(() { - _setThumbZoomLevel(value.round()); - }); - Pref.inst().setHomePhotosZoomLevel(_thumbZoomLevel); - }, - ), - ], + ZoomMenuButton( + initialZoom: _thumbZoomLevel, + minZoom: -1, + maxZoom: 2, + onZoomChanged: (value) { + setState(() { + _setThumbZoomLevel(value.round()); + }); + Pref.inst().setHomePhotosZoomLevel(_thumbZoomLevel); + }, ), ], menuActions: [ diff --git a/lib/widget/popup_menu_zoom.dart b/lib/widget/popup_menu_zoom.dart deleted file mode 100644 index 1b4604ba..00000000 --- a/lib/widget/popup_menu_zoom.dart +++ /dev/null @@ -1,52 +0,0 @@ -import 'package:flutter/material.dart'; - -class PopupMenuZoom extends PopupMenuEntry { - PopupMenuZoom({ - Key? key, - required this.initialValue, - required this.minValue, - required this.maxValue, - this.onChanged, - }) : super(key: key); - - @override - represents(void value) => false; - - @override - createState() => _PopupMenuZoomState(); - - @override - // this value doesn't seems to do anything? - final double height = 48.0; - - final int initialValue; - final double minValue; - final double maxValue; - final void Function(double)? onChanged; -} - -class _PopupMenuZoomState extends State { - @override - initState() { - super.initState(); - _value = widget.initialValue.toDouble(); - } - - @override - build(BuildContext context) { - return Slider( - value: _value, - min: widget.minValue, - max: widget.maxValue, - divisions: (widget.maxValue - widget.minValue).round(), - onChanged: (value) { - setState(() { - _value = value; - }); - widget.onChanged?.call(value); - }, - ); - } - - var _value = 0.0; -} diff --git a/lib/widget/zoom_menu_button.dart b/lib/widget/zoom_menu_button.dart new file mode 100644 index 00000000..251cdd8e --- /dev/null +++ b/lib/widget/zoom_menu_button.dart @@ -0,0 +1,85 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:nc_photos/app_localizations.dart'; + +class ZoomMenuButton extends StatelessWidget { + ZoomMenuButton({ + Key? key, + required this.initialZoom, + required this.minZoom, + required this.maxZoom, + this.onZoomChanged, + }) : super(key: key); + + @override + build(BuildContext context) { + return PopupMenuButton( + icon: const Icon(Icons.photo_size_select_large), + tooltip: L10n.of(context).zoomTooltip, + itemBuilder: (context) => [ + _PopupMenuZoom( + initialValue: initialZoom, + minValue: minZoom, + maxValue: maxZoom, + onChanged: onZoomChanged, + ), + ], + ); + } + + final int initialZoom; + final int minZoom; + final int maxZoom; + final ValueChanged? onZoomChanged; +} + +class _PopupMenuZoom extends PopupMenuEntry { + _PopupMenuZoom({ + Key? key, + required this.initialValue, + required this.minValue, + required this.maxValue, + this.onChanged, + }) : super(key: key); + + @override + represents(void value) => false; + + @override + createState() => _PopupMenuZoomState(); + + @override + // this value doesn't seems to do anything? + final double height = 48.0; + + final int initialValue; + final int minValue; + final int maxValue; + final ValueChanged? onChanged; +} + +class _PopupMenuZoomState extends State<_PopupMenuZoom> { + @override + initState() { + super.initState(); + _value = widget.initialValue; + } + + @override + build(BuildContext context) { + return Slider( + value: _value.toDouble(), + min: widget.minValue.toDouble(), + max: widget.maxValue.toDouble(), + divisions: (widget.maxValue - widget.minValue).round(), + onChanged: (value) { + setState(() { + _value = value.round(); + }); + widget.onChanged?.call(_value); + }, + ); + } + + late int _value; +}