diff --git a/app/lib/widget/viewer.dart b/app/lib/widget/viewer.dart index 9424a584..ee5f9ccb 100644 --- a/app/lib/widget/viewer.dart +++ b/app/lib/widget/viewer.dart @@ -52,13 +52,14 @@ import 'package:np_common/unique.dart'; import 'package:np_platform_util/np_platform_util.dart'; import 'package:to_string/to_string.dart'; +part 'viewer.g.dart'; part 'viewer/app_bar.dart'; +part 'viewer/app_bar_buttons.dart'; part 'viewer/bloc.dart'; part 'viewer/detail_pane.dart'; part 'viewer/state_event.dart'; part 'viewer/type.dart'; part 'viewer/view.dart'; -part 'viewer.g.dart'; class ViewerArguments { const ViewerArguments( diff --git a/app/lib/widget/viewer/app_bar.dart b/app/lib/widget/viewer/app_bar.dart index a4140bf1..199ea5aa 100644 --- a/app/lib/widget/viewer/app_bar.dart +++ b/app/lib/widget/viewer/app_bar.dart @@ -29,58 +29,8 @@ class _AppBar extends StatelessWidget { centerTitle: isTitleCentered, actions: !state.isDetailPaneActive && !state.isZoomed ? [ - _BlocBuilder( - buildWhen: (previous, current) => - previous.currentFile != current.currentFile || - previous.currentFileState != current.currentFileState, - builder: (context, state) { - if (state.currentFile?.let(getLivePhotoTypeFromFile) != - null) { - if (state.currentFileState?.shouldPlayLivePhoto ?? - false) { - return IconButton( - icon: const Icon(Icons.motion_photos_pause_outlined), - onPressed: () { - context.state.currentFile?.fdId.let( - (id) => context.addEvent(_PauseLivePhoto(id))); - }, - ); - } else { - return IconButton( - icon: const PngIcon(icMotionPhotosPlay24dp), - onPressed: () { - context.state.currentFile?.fdId.let( - (id) => context.addEvent(_PlayLivePhoto(id))); - }, - ); - } - } else { - return const SizedBox.shrink(); - } - }, - ), - _BlocSelector( - selector: (state) => state.currentFile, - builder: (context, currentFile) => currentFile - ?.fdIsFavorite == - true - ? IconButton( - icon: const Icon(Icons.star), - tooltip: L10n.global().unfavoriteTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Unfavorite(id))); - }, - ) - : IconButton( - icon: const Icon(Icons.star_border), - tooltip: L10n.global().favoriteTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Favorite(id))); - }, - ), - ), + const _AppBarLivePhotoButton(), + const _AppBarFavoriteButton(), IconButton( icon: const Icon(Icons.more_vert), tooltip: L10n.global().detailsTooltip, @@ -155,51 +105,15 @@ class _BottomAppBar extends StatelessWidget { mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, children: [ - IconButton( - icon: const Icon(Icons.share_outlined), - tooltip: L10n.global().shareTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Share(id))); - }, - ), + const _AppBarShareButton(), if (features.isSupportEnhancement && state.currentFile?.let(ImageEnhancer.isSupportedFormat) == true) ...[ - IconButton( - icon: const Icon(Icons.tune_outlined), - tooltip: L10n.global().editTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Edit(id))); - }, - ), - IconButton( - icon: const Icon(Icons.auto_fix_high_outlined), - tooltip: L10n.global().enhanceTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Enhance(id))); - }, - ), + const _AppBarEditButton(), + const _AppBarEnhanceButton(), ], - IconButton( - icon: const Icon(Icons.download_outlined), - tooltip: L10n.global().downloadTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Download(id))); - }, - ), - if (state.collection == null) - IconButton( - icon: const Icon(Icons.delete_outlined), - tooltip: L10n.global().deleteTooltip, - onPressed: () { - context.state.currentFile?.fdId - .let((id) => context.addEvent(_Delete(id))); - }, - ), + const _AppBarDownloadButton(), + if (state.collection == null) const _AppBarDeleteButton(), ] .map((e) => Expanded( flex: 1, diff --git a/app/lib/widget/viewer/app_bar_buttons.dart b/app/lib/widget/viewer/app_bar_buttons.dart new file mode 100644 index 00000000..716da687 --- /dev/null +++ b/app/lib/widget/viewer/app_bar_buttons.dart @@ -0,0 +1,145 @@ +part of '../viewer.dart'; + +class _AppBarLivePhotoButton extends StatelessWidget { + const _AppBarLivePhotoButton(); + + @override + Widget build(BuildContext context) { + return _BlocBuilder( + buildWhen: (previous, current) => + previous.currentFile != current.currentFile || + previous.currentFileState != current.currentFileState, + builder: (context, state) { + if (state.currentFile?.let(getLivePhotoTypeFromFile) != null) { + if (state.currentFileState?.shouldPlayLivePhoto ?? false) { + return IconButton( + icon: const Icon(Icons.motion_photos_pause_outlined), + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_PauseLivePhoto(id))); + }, + ); + } else { + return IconButton( + icon: const PngIcon(icMotionPhotosPlay24dp), + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_PlayLivePhoto(id))); + }, + ); + } + } else { + return const SizedBox.shrink(); + } + }, + ); + } +} + +class _AppBarFavoriteButton extends StatelessWidget { + const _AppBarFavoriteButton(); + + @override + Widget build(BuildContext context) { + return _BlocSelector( + selector: (state) => state.currentFile, + builder: (context, currentFile) => currentFile?.fdIsFavorite == true + ? IconButton( + icon: const Icon(Icons.star), + tooltip: L10n.global().unfavoriteTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Unfavorite(id))); + }, + ) + : IconButton( + icon: const Icon(Icons.star_border), + tooltip: L10n.global().favoriteTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Favorite(id))); + }, + ), + ); + } +} + +class _AppBarShareButton extends StatelessWidget { + const _AppBarShareButton(); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: const Icon(Icons.share_outlined), + tooltip: L10n.global().shareTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Share(id))); + }, + ); + } +} + +class _AppBarEditButton extends StatelessWidget { + const _AppBarEditButton(); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: const Icon(Icons.tune_outlined), + tooltip: L10n.global().editTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Edit(id))); + }, + ); + } +} + +class _AppBarEnhanceButton extends StatelessWidget { + const _AppBarEnhanceButton(); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: const Icon(Icons.auto_fix_high_outlined), + tooltip: L10n.global().enhanceTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Enhance(id))); + }, + ); + } +} + +class _AppBarDownloadButton extends StatelessWidget { + const _AppBarDownloadButton(); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: const Icon(Icons.download_outlined), + tooltip: L10n.global().downloadTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Download(id))); + }, + ); + } +} + +class _AppBarDeleteButton extends StatelessWidget { + const _AppBarDeleteButton(); + + @override + Widget build(BuildContext context) { + return IconButton( + icon: const Icon(Icons.delete_outlined), + tooltip: L10n.global().deleteTooltip, + onPressed: () { + context.state.currentFile?.fdId + .let((id) => context.addEvent(_Delete(id))); + }, + ); + } +}