mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Extract app bar buttons in viewer
This commit is contained in:
parent
03015e999e
commit
d723a75ce1
3 changed files with 154 additions and 94 deletions
|
@ -52,13 +52,14 @@ import 'package:np_common/unique.dart';
|
||||||
import 'package:np_platform_util/np_platform_util.dart';
|
import 'package:np_platform_util/np_platform_util.dart';
|
||||||
import 'package:to_string/to_string.dart';
|
import 'package:to_string/to_string.dart';
|
||||||
|
|
||||||
|
part 'viewer.g.dart';
|
||||||
part 'viewer/app_bar.dart';
|
part 'viewer/app_bar.dart';
|
||||||
|
part 'viewer/app_bar_buttons.dart';
|
||||||
part 'viewer/bloc.dart';
|
part 'viewer/bloc.dart';
|
||||||
part 'viewer/detail_pane.dart';
|
part 'viewer/detail_pane.dart';
|
||||||
part 'viewer/state_event.dart';
|
part 'viewer/state_event.dart';
|
||||||
part 'viewer/type.dart';
|
part 'viewer/type.dart';
|
||||||
part 'viewer/view.dart';
|
part 'viewer/view.dart';
|
||||||
part 'viewer.g.dart';
|
|
||||||
|
|
||||||
class ViewerArguments {
|
class ViewerArguments {
|
||||||
const ViewerArguments(
|
const ViewerArguments(
|
||||||
|
|
|
@ -29,58 +29,8 @@ class _AppBar extends StatelessWidget {
|
||||||
centerTitle: isTitleCentered,
|
centerTitle: isTitleCentered,
|
||||||
actions: !state.isDetailPaneActive && !state.isZoomed
|
actions: !state.isDetailPaneActive && !state.isZoomed
|
||||||
? [
|
? [
|
||||||
_BlocBuilder(
|
const _AppBarLivePhotoButton(),
|
||||||
buildWhen: (previous, current) =>
|
const _AppBarFavoriteButton(),
|
||||||
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)));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.more_vert),
|
icon: const Icon(Icons.more_vert),
|
||||||
tooltip: L10n.global().detailsTooltip,
|
tooltip: L10n.global().detailsTooltip,
|
||||||
|
@ -155,51 +105,15 @@ class _BottomAppBar extends StatelessWidget {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: [
|
children: [
|
||||||
IconButton(
|
const _AppBarShareButton(),
|
||||||
icon: const Icon(Icons.share_outlined),
|
|
||||||
tooltip: L10n.global().shareTooltip,
|
|
||||||
onPressed: () {
|
|
||||||
context.state.currentFile?.fdId
|
|
||||||
.let((id) => context.addEvent(_Share(id)));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
if (features.isSupportEnhancement &&
|
if (features.isSupportEnhancement &&
|
||||||
state.currentFile?.let(ImageEnhancer.isSupportedFormat) ==
|
state.currentFile?.let(ImageEnhancer.isSupportedFormat) ==
|
||||||
true) ...[
|
true) ...[
|
||||||
IconButton(
|
const _AppBarEditButton(),
|
||||||
icon: const Icon(Icons.tune_outlined),
|
const _AppBarEnhanceButton(),
|
||||||
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)));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
IconButton(
|
const _AppBarDownloadButton(),
|
||||||
icon: const Icon(Icons.download_outlined),
|
if (state.collection == null) const _AppBarDeleteButton(),
|
||||||
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)));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
.map((e) => Expanded(
|
.map((e) => Expanded(
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
|
145
app/lib/widget/viewer/app_bar_buttons.dart
Normal file
145
app/lib/widget/viewer/app_bar_buttons.dart
Normal file
|
@ -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)));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue