mirror of
https://github.com/immich-app/immich.git
synced 2025-12-17 17:23:20 +03:00
Compare commits
10 Commits
renovate/m
...
feature/bo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de36f9a215 | ||
|
|
8ceb68e240 | ||
|
|
75734b45a0 | ||
|
|
a9bee498c4 | ||
|
|
6b4cc4e65e | ||
|
|
e49239e7e9 | ||
|
|
939c222728 | ||
|
|
c38ecab1a6 | ||
|
|
76fd68957c | ||
|
|
7d4de5f2e2 |
@@ -7,3 +7,5 @@ enum AssetVisibilityEnum { timeline, hidden, archive, locked }
|
|||||||
enum SortUserBy { id }
|
enum SortUserBy { id }
|
||||||
|
|
||||||
enum ActionSource { timeline, viewer }
|
enum ActionSource { timeline, viewer }
|
||||||
|
|
||||||
|
enum ButtonPosition { bottomBar, kebabMenu, other }
|
||||||
|
|||||||
@@ -8,7 +8,10 @@ import 'package:immich_mobile/providers/infrastructure/asset_viewer/current_asse
|
|||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
|
||||||
class EditImageActionButton extends ConsumerWidget {
|
class EditImageActionButton extends ConsumerWidget {
|
||||||
const EditImageActionButton({super.key});
|
final bool iconOnly;
|
||||||
|
final bool menuItem;
|
||||||
|
|
||||||
|
const EditImageActionButton({super.key, this.iconOnly = false, this.menuItem = false});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
@@ -27,6 +30,8 @@ class EditImageActionButton extends ConsumerWidget {
|
|||||||
iconData: Icons.tune,
|
iconData: Icons.tune,
|
||||||
label: "edit".t(context: context),
|
label: "edit".t(context: context),
|
||||||
onPressed: onPress,
|
onPressed: onPress,
|
||||||
|
iconOnly: iconOnly,
|
||||||
|
menuItem: menuItem,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/events.model.dart';
|
||||||
|
import 'package:immich_mobile/domain/utils/event_stream.dart';
|
||||||
|
import 'package:immich_mobile/extensions/translate_extensions.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/action_buttons/base_action_button.widget.dart';
|
||||||
|
|
||||||
|
class OpenActivityActionButton extends ConsumerWidget {
|
||||||
|
const OpenActivityActionButton({super.key, this.iconOnly = false, this.menuItem = false});
|
||||||
|
|
||||||
|
final bool iconOnly;
|
||||||
|
final bool menuItem;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
return BaseActionButton(
|
||||||
|
iconData: Icons.chat_outlined,
|
||||||
|
label: "activity".t(context: context),
|
||||||
|
onPressed: () => EventStream.shared.emit(const ViewerOpenBottomSheetEvent(activitiesMode: true)),
|
||||||
|
iconOnly: iconOnly,
|
||||||
|
menuItem: menuItem,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,18 +2,18 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/constants/enums.dart';
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
|
import 'package:immich_mobile/domain/models/setting.model.dart';
|
||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/delete_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/delete_local_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/edit_image_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/share_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/add_action_button.widget.dart';
|
|
||||||
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.state.dart';
|
import 'package:immich_mobile/presentation/widgets/asset_viewer/asset_viewer.state.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/asset_viewer/current_asset.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/asset_viewer/current_asset.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/current_album.provider.dart';
|
||||||
import 'package:immich_mobile/providers/infrastructure/readonly_mode.provider.dart';
|
import 'package:immich_mobile/providers/infrastructure/readonly_mode.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/setting.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/infrastructure/timeline.provider.dart';
|
||||||
import 'package:immich_mobile/providers/routes.provider.dart';
|
import 'package:immich_mobile/providers/routes.provider.dart';
|
||||||
|
import 'package:immich_mobile/providers/server_info.provider.dart';
|
||||||
import 'package:immich_mobile/providers/user.provider.dart';
|
import 'package:immich_mobile/providers/user.provider.dart';
|
||||||
|
import 'package:immich_mobile/utils/action_button.utils.dart';
|
||||||
import 'package:immich_mobile/widgets/asset_viewer/video_controls.dart';
|
import 'package:immich_mobile/widgets/asset_viewer/video_controls.dart';
|
||||||
|
|
||||||
class ViewerBottomBar extends ConsumerWidget {
|
class ViewerBottomBar extends ConsumerWidget {
|
||||||
@@ -33,6 +33,11 @@ class ViewerBottomBar extends ConsumerWidget {
|
|||||||
int opacity = ref.watch(assetViewerProvider.select((state) => state.backgroundOpacity));
|
int opacity = ref.watch(assetViewerProvider.select((state) => state.backgroundOpacity));
|
||||||
final showControls = ref.watch(assetViewerProvider.select((s) => s.showingControls));
|
final showControls = ref.watch(assetViewerProvider.select((s) => s.showingControls));
|
||||||
final isInLockedView = ref.watch(inLockedViewProvider);
|
final isInLockedView = ref.watch(inLockedViewProvider);
|
||||||
|
final album = ref.watch(currentRemoteAlbumProvider);
|
||||||
|
final isArchived = asset is RemoteAsset && asset.visibility == AssetVisibility.archive;
|
||||||
|
final advancedTroubleshooting = ref.watch(settingsProvider.notifier).get(Setting.advancedTroubleshooting);
|
||||||
|
final timelineOrigin = ref.read(timelineServiceProvider).origin;
|
||||||
|
final isTrashEnable = ref.watch(serverInfoProvider.select((state) => state.serverFeatures.trash));
|
||||||
|
|
||||||
if (!showControls) {
|
if (!showControls) {
|
||||||
opacity = 0;
|
opacity = 0;
|
||||||
@@ -40,21 +45,22 @@ class ViewerBottomBar extends ConsumerWidget {
|
|||||||
|
|
||||||
final originalTheme = context.themeData;
|
final originalTheme = context.themeData;
|
||||||
|
|
||||||
final actions = <Widget>[
|
final buttonContext = ActionButtonContext(
|
||||||
const ShareActionButton(source: ActionSource.viewer),
|
asset: asset,
|
||||||
|
isOwner: isOwner,
|
||||||
|
isArchived: isArchived,
|
||||||
|
isTrashEnabled: isTrashEnable,
|
||||||
|
isStacked: asset is RemoteAsset && asset.stackId != null,
|
||||||
|
isInLockedView: isInLockedView,
|
||||||
|
currentAlbum: album,
|
||||||
|
advancedTroubleshooting: advancedTroubleshooting,
|
||||||
|
source: ActionSource.viewer,
|
||||||
|
timelineOrigin: timelineOrigin,
|
||||||
|
originalTheme: originalTheme,
|
||||||
|
buttonPosition: ButtonPosition.bottomBar,
|
||||||
|
);
|
||||||
|
|
||||||
if (!isInLockedView) ...[
|
final actions = ActionButtonBuilder.buildViewerBottomBar(buttonContext, context, ref);
|
||||||
if (asset.isLocalOnly) const UploadActionButton(source: ActionSource.viewer),
|
|
||||||
if (asset.type == AssetType.image) const EditImageActionButton(),
|
|
||||||
if (asset.hasRemote) AddActionButton(originalTheme: originalTheme),
|
|
||||||
|
|
||||||
if (isOwner) ...[
|
|
||||||
asset.isLocalOnly
|
|
||||||
? const DeleteLocalActionButton(source: ActionSource.viewer)
|
|
||||||
: const DeleteActionButton(source: ActionSource.viewer, showConfirmation: true),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return IgnorePointer(
|
return IgnorePointer(
|
||||||
ignoring: opacity < 255,
|
ignoring: opacity < 255,
|
||||||
@@ -80,7 +86,11 @@ class ViewerBottomBar extends ConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
if (asset.isVideo) const VideoControls(),
|
if (asset.isVideo) const VideoControls(),
|
||||||
if (!isReadonlyModeEnabled)
|
if (!isReadonlyModeEnabled)
|
||||||
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: actions),
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: actions.map((action) => Expanded(child: action)).toList(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -3,8 +3,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/constants/enums.dart';
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
||||||
import 'package:immich_mobile/domain/models/events.model.dart';
|
|
||||||
import 'package:immich_mobile/domain/utils/event_stream.dart';
|
|
||||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/favorite_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/favorite_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/motion_photo_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/motion_photo_action_button.widget.dart';
|
||||||
@@ -51,13 +49,6 @@ class ViewerTopAppBar extends ConsumerWidget implements PreferredSizeWidget {
|
|||||||
|
|
||||||
final actions = <Widget>[
|
final actions = <Widget>[
|
||||||
if (asset.isMotionPhoto) const MotionPhotoActionButton(iconOnly: true),
|
if (asset.isMotionPhoto) const MotionPhotoActionButton(iconOnly: true),
|
||||||
if (album != null && album.isActivityEnabled && album.isShared)
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.chat_outlined),
|
|
||||||
onPressed: () {
|
|
||||||
EventStream.shared.emit(const ViewerOpenBottomSheetEvent(activitiesMode: true));
|
|
||||||
},
|
|
||||||
),
|
|
||||||
|
|
||||||
if (asset.hasRemote && isOwner && !asset.isFavorite)
|
if (asset.hasRemote && isOwner && !asset.isFavorite)
|
||||||
const FavoriteActionButton(source: ActionSource.viewer, iconOnly: true),
|
const FavoriteActionButton(source: ActionSource.viewer, iconOnly: true),
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/delete_local_a
|
|||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/delete_permanent_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/delete_permanent_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/download_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/download_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/like_activity_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/like_activity_action_button.widget.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/action_buttons/open_activity_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/move_to_lock_folder_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/remove_from_album_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/remove_from_album_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/remove_from_lock_folder_action_button.widget.dart';
|
||||||
@@ -27,6 +28,8 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/trash_action_b
|
|||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/unarchive_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/unarchive_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/unstack_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/unstack_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart';
|
import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/action_buttons/edit_image_action_button.widget.dart';
|
||||||
|
import 'package:immich_mobile/presentation/widgets/action_buttons/add_action_button.widget.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
|
||||||
class ActionButtonContext {
|
class ActionButtonContext {
|
||||||
@@ -42,6 +45,7 @@ class ActionButtonContext {
|
|||||||
final bool isCasting;
|
final bool isCasting;
|
||||||
final TimelineOrigin timelineOrigin;
|
final TimelineOrigin timelineOrigin;
|
||||||
final ThemeData? originalTheme;
|
final ThemeData? originalTheme;
|
||||||
|
final ButtonPosition buttonPosition;
|
||||||
|
|
||||||
const ActionButtonContext({
|
const ActionButtonContext({
|
||||||
required this.asset,
|
required this.asset,
|
||||||
@@ -56,13 +60,48 @@ class ActionButtonContext {
|
|||||||
this.isCasting = false,
|
this.isCasting = false,
|
||||||
this.timelineOrigin = TimelineOrigin.main,
|
this.timelineOrigin = TimelineOrigin.main,
|
||||||
this.originalTheme,
|
this.originalTheme,
|
||||||
|
this.buttonPosition = ButtonPosition.other,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
ActionButtonContext copyWith({
|
||||||
|
BaseAsset? asset,
|
||||||
|
bool? isOwner,
|
||||||
|
bool? isArchived,
|
||||||
|
bool? isTrashEnabled,
|
||||||
|
bool? isStacked,
|
||||||
|
bool? isInLockedView,
|
||||||
|
RemoteAlbum? currentAlbum,
|
||||||
|
bool? advancedTroubleshooting,
|
||||||
|
ActionSource? source,
|
||||||
|
bool? isCasting,
|
||||||
|
TimelineOrigin? timelineOrigin,
|
||||||
|
ThemeData? originalTheme,
|
||||||
|
ButtonPosition? buttonPosition,
|
||||||
|
}) {
|
||||||
|
return ActionButtonContext(
|
||||||
|
asset: asset ?? this.asset,
|
||||||
|
isOwner: isOwner ?? this.isOwner,
|
||||||
|
isArchived: isArchived ?? this.isArchived,
|
||||||
|
isTrashEnabled: isTrashEnabled ?? this.isTrashEnabled,
|
||||||
|
isStacked: isStacked ?? this.isStacked,
|
||||||
|
isInLockedView: isInLockedView ?? this.isInLockedView,
|
||||||
|
currentAlbum: currentAlbum ?? this.currentAlbum,
|
||||||
|
advancedTroubleshooting: advancedTroubleshooting ?? this.advancedTroubleshooting,
|
||||||
|
source: source ?? this.source,
|
||||||
|
isCasting: isCasting ?? this.isCasting,
|
||||||
|
timelineOrigin: timelineOrigin ?? this.timelineOrigin,
|
||||||
|
originalTheme: originalTheme ?? this.originalTheme,
|
||||||
|
buttonPosition: buttonPosition ?? this.buttonPosition,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ActionButtonType {
|
enum ActionButtonType {
|
||||||
openInfo,
|
openInfo,
|
||||||
|
openActivity,
|
||||||
likeActivity,
|
likeActivity,
|
||||||
share,
|
share,
|
||||||
|
editImage,
|
||||||
shareLink,
|
shareLink,
|
||||||
cast,
|
cast,
|
||||||
similarPhotos,
|
similarPhotos,
|
||||||
@@ -79,6 +118,7 @@ enum ActionButtonType {
|
|||||||
deleteLocal,
|
deleteLocal,
|
||||||
deletePermanent,
|
deletePermanent,
|
||||||
delete,
|
delete,
|
||||||
|
addTo,
|
||||||
advancedInfo;
|
advancedInfo;
|
||||||
|
|
||||||
bool shouldShow(ActionButtonContext context) {
|
bool shouldShow(ActionButtonContext context) {
|
||||||
@@ -156,10 +196,22 @@ enum ActionButtonType {
|
|||||||
context.timelineOrigin != TimelineOrigin.localAlbum &&
|
context.timelineOrigin != TimelineOrigin.localAlbum &&
|
||||||
context.isOwner,
|
context.isOwner,
|
||||||
ActionButtonType.cast => context.isCasting || context.asset.hasRemote,
|
ActionButtonType.cast => context.isCasting || context.asset.hasRemote,
|
||||||
|
ActionButtonType.editImage =>
|
||||||
|
!context.isInLockedView && //
|
||||||
|
context.asset.type == AssetType.image &&
|
||||||
|
!(context.buttonPosition == ButtonPosition.bottomBar && context.currentAlbum?.isShared == true),
|
||||||
|
ActionButtonType.addTo =>
|
||||||
|
!context.isInLockedView && //
|
||||||
|
context.asset.hasRemote,
|
||||||
|
ActionButtonType.openActivity =>
|
||||||
|
!context.isInLockedView &&
|
||||||
|
context.currentAlbum != null &&
|
||||||
|
context.currentAlbum!.isActivityEnabled &&
|
||||||
|
context.currentAlbum!.isShared,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
ConsumerWidget buildButton(
|
Widget buildButton(
|
||||||
ActionButtonContext context, [
|
ActionButtonContext context, [
|
||||||
BuildContext? buildContext,
|
BuildContext? buildContext,
|
||||||
bool iconOnly = false,
|
bool iconOnly = false,
|
||||||
@@ -242,6 +294,9 @@ enum ActionButtonType {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
ActionButtonType.cast => CastActionButton(iconOnly: iconOnly, menuItem: menuItem),
|
ActionButtonType.cast => CastActionButton(iconOnly: iconOnly, menuItem: menuItem),
|
||||||
|
ActionButtonType.editImage => EditImageActionButton(iconOnly: iconOnly, menuItem: menuItem),
|
||||||
|
ActionButtonType.addTo => AddActionButton(originalTheme: context.originalTheme),
|
||||||
|
ActionButtonType.openActivity => OpenActivityActionButton(iconOnly: iconOnly, menuItem: menuItem),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,39 +327,77 @@ enum ActionButtonType {
|
|||||||
class ActionButtonBuilder {
|
class ActionButtonBuilder {
|
||||||
static const List<ActionButtonType> _actionTypes = ActionButtonType.values;
|
static const List<ActionButtonType> _actionTypes = ActionButtonType.values;
|
||||||
static const List<ActionButtonType> defaultViewerKebabMenuOrder = _actionTypes;
|
static const List<ActionButtonType> defaultViewerKebabMenuOrder = _actionTypes;
|
||||||
static const Set<ActionButtonType> defaultViewerBottomBarButtons = {
|
static const List<ActionButtonType> _defaultViewerBottomBarOrder = [
|
||||||
ActionButtonType.share,
|
ActionButtonType.share,
|
||||||
ActionButtonType.moveToLockFolder,
|
|
||||||
ActionButtonType.upload,
|
ActionButtonType.upload,
|
||||||
|
ActionButtonType.editImage,
|
||||||
|
ActionButtonType.addTo,
|
||||||
|
ActionButtonType.openActivity,
|
||||||
|
ActionButtonType.likeActivity,
|
||||||
|
ActionButtonType.deleteLocal,
|
||||||
ActionButtonType.delete,
|
ActionButtonType.delete,
|
||||||
ActionButtonType.archive,
|
ActionButtonType.removeFromLockFolder,
|
||||||
ActionButtonType.unarchive,
|
ActionButtonType.deletePermanent,
|
||||||
};
|
];
|
||||||
|
|
||||||
static List<Widget> build(ActionButtonContext context) {
|
static List<Widget> build(ActionButtonContext context) {
|
||||||
return _actionTypes.where((type) => type.shouldShow(context)).map((type) => type.buildButton(context)).toList();
|
return _actionTypes.where((type) => type.shouldShow(context)).map((type) => type.buildButton(context)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Widget> buildViewerKebabMenu(ActionButtonContext context, BuildContext buildContext, WidgetRef ref) {
|
static List<ActionButtonType> getViewerKebabMenuTypes(ActionButtonContext context) {
|
||||||
final visibleButtons = defaultViewerKebabMenuOrder
|
final visibleBottomBarButtons = getViewerBottomBarTypes(context);
|
||||||
.where((type) => !defaultViewerBottomBarButtons.contains(type) && type.shouldShow(context))
|
final excludedTypes = <ActionButtonType>{...visibleBottomBarButtons, ActionButtonType.addTo};
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (visibleButtons.isEmpty) {
|
if (visibleBottomBarButtons.contains(ActionButtonType.addTo)) {
|
||||||
|
excludedTypes.addAll([ActionButtonType.moveToLockFolder, ActionButtonType.archive, ActionButtonType.unarchive]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultViewerKebabMenuOrder
|
||||||
|
.where((type) => !excludedTypes.contains(type) && type.shouldShow(context))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<ActionButtonType> getViewerBottomBarTypes(ActionButtonContext context) {
|
||||||
|
final bottomBarContext = context.copyWith(buttonPosition: ButtonPosition.bottomBar);
|
||||||
|
return _defaultViewerBottomBarOrder.where((type) => type.shouldShow(bottomBarContext)).take(4).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Widget> buildViewerKebabMenu(ActionButtonContext context, BuildContext buildContext, WidgetRef ref) {
|
||||||
|
final visibleButtons = getViewerKebabMenuTypes(context);
|
||||||
|
return visibleButtons.toKebabMenuWidgets(context, buildContext, ref);
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<Widget> buildViewerBottomBar(ActionButtonContext context, BuildContext buildContext, WidgetRef ref) {
|
||||||
|
final visibleButtons = getViewerBottomBarTypes(context);
|
||||||
|
return visibleButtons.toBottomBarWidgets(context, buildContext, ref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension ActionButtonTypeListExtension on List<ActionButtonType> {
|
||||||
|
List<Widget> toKebabMenuWidgets(ActionButtonContext context, BuildContext buildContext, WidgetRef ref) {
|
||||||
|
if (isEmpty) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<Widget> result = [];
|
final List<Widget> result = [];
|
||||||
int? lastGroup;
|
int? lastGroup;
|
||||||
|
|
||||||
for (final type in visibleButtons) {
|
for (final type in this) {
|
||||||
if (lastGroup != null && type.kebabMenuGroup != lastGroup) {
|
if (lastGroup != null && type.kebabMenuGroup != lastGroup) {
|
||||||
result.add(const Divider(height: 1));
|
result.add(const Divider(height: 1));
|
||||||
}
|
}
|
||||||
result.add(type.buildButton(context, buildContext, false, true).build(buildContext, ref));
|
final widget = type.buildButton(context, buildContext, false, true);
|
||||||
|
result.add(widget is ConsumerWidget ? widget.build(buildContext, ref) : widget);
|
||||||
lastGroup = type.kebabMenuGroup;
|
lastGroup = type.kebabMenuGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Widget> toBottomBarWidgets(ActionButtonContext context, BuildContext buildContext, WidgetRef ref) {
|
||||||
|
return map((type) {
|
||||||
|
final widget = type.buildButton(context, buildContext, false, false);
|
||||||
|
return widget is ConsumerWidget ? widget.build(buildContext, ref) : widget;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:immich_mobile/constants/enums.dart';
|
import 'package:immich_mobile/constants/enums.dart';
|
||||||
@@ -962,4 +963,128 @@ void main() {
|
|||||||
expect(nonArchivedWidgets, isNotEmpty);
|
expect(nonArchivedWidgets, isNotEmpty);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('ActionButtonBuilder.getViewerBottomBarTypes', () {
|
||||||
|
test('should return correct button types for shared album with activity', () {
|
||||||
|
final remoteAsset = createRemoteAsset();
|
||||||
|
final album = createRemoteAlbum(isActivityEnabled: true, isShared: true);
|
||||||
|
final context = ActionButtonContext(
|
||||||
|
asset: remoteAsset,
|
||||||
|
isOwner: true,
|
||||||
|
isArchived: false,
|
||||||
|
isTrashEnabled: true,
|
||||||
|
isInLockedView: false,
|
||||||
|
currentAlbum: album,
|
||||||
|
advancedTroubleshooting: false,
|
||||||
|
isStacked: false,
|
||||||
|
source: ActionSource.viewer,
|
||||||
|
buttonPosition: ButtonPosition.bottomBar,
|
||||||
|
);
|
||||||
|
|
||||||
|
const expectedTypes = [
|
||||||
|
ActionButtonType.share,
|
||||||
|
ActionButtonType.addTo,
|
||||||
|
ActionButtonType.openActivity,
|
||||||
|
ActionButtonType.likeActivity,
|
||||||
|
];
|
||||||
|
|
||||||
|
final bottomBarTypes = ActionButtonBuilder.getViewerBottomBarTypes(context);
|
||||||
|
final kebabTypes = ActionButtonBuilder.getViewerKebabMenuTypes(context);
|
||||||
|
|
||||||
|
expect(const ListEquality().equals(bottomBarTypes, expectedTypes), isTrue);
|
||||||
|
expect(bottomBarTypes.any(kebabTypes.contains), isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return correct button types for local only asset', () {
|
||||||
|
final localAsset = createLocalAsset();
|
||||||
|
final context = ActionButtonContext(
|
||||||
|
asset: localAsset,
|
||||||
|
isOwner: true,
|
||||||
|
isArchived: false,
|
||||||
|
isTrashEnabled: true,
|
||||||
|
isInLockedView: false,
|
||||||
|
currentAlbum: null,
|
||||||
|
advancedTroubleshooting: false,
|
||||||
|
isStacked: false,
|
||||||
|
source: ActionSource.viewer,
|
||||||
|
buttonPosition: ButtonPosition.bottomBar,
|
||||||
|
);
|
||||||
|
|
||||||
|
const expectedTypes = [
|
||||||
|
ActionButtonType.share,
|
||||||
|
ActionButtonType.upload,
|
||||||
|
ActionButtonType.editImage,
|
||||||
|
ActionButtonType.deleteLocal,
|
||||||
|
];
|
||||||
|
|
||||||
|
final bottomBarTypes = ActionButtonBuilder.getViewerBottomBarTypes(context);
|
||||||
|
final kebabTypes = ActionButtonBuilder.getViewerKebabMenuTypes(
|
||||||
|
context.copyWith(buttonPosition: ButtonPosition.kebabMenu),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(const ListEquality().equals(bottomBarTypes, expectedTypes), isTrue);
|
||||||
|
expect(bottomBarTypes.any(kebabTypes.contains), isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return correct button types for locked view', () {
|
||||||
|
final remoteAsset = createRemoteAsset();
|
||||||
|
final context = ActionButtonContext(
|
||||||
|
asset: remoteAsset,
|
||||||
|
isOwner: true,
|
||||||
|
isArchived: false,
|
||||||
|
isTrashEnabled: false,
|
||||||
|
isInLockedView: true,
|
||||||
|
currentAlbum: null,
|
||||||
|
advancedTroubleshooting: false,
|
||||||
|
isStacked: false,
|
||||||
|
source: ActionSource.viewer,
|
||||||
|
buttonPosition: ButtonPosition.bottomBar,
|
||||||
|
);
|
||||||
|
|
||||||
|
const expectedTypes = [
|
||||||
|
ActionButtonType.share,
|
||||||
|
ActionButtonType.removeFromLockFolder,
|
||||||
|
ActionButtonType.deletePermanent,
|
||||||
|
];
|
||||||
|
|
||||||
|
final bottomBarTypes = ActionButtonBuilder.getViewerBottomBarTypes(context);
|
||||||
|
final kebabTypes = ActionButtonBuilder.getViewerKebabMenuTypes(
|
||||||
|
context.copyWith(buttonPosition: ButtonPosition.kebabMenu),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(const ListEquality().equals(bottomBarTypes, expectedTypes), isTrue);
|
||||||
|
expect(bottomBarTypes.any(kebabTypes.contains), isFalse);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should return correct button types for remote only asset', () {
|
||||||
|
final remoteAsset = createRemoteAsset();
|
||||||
|
final context = ActionButtonContext(
|
||||||
|
asset: remoteAsset,
|
||||||
|
isOwner: true,
|
||||||
|
isArchived: false,
|
||||||
|
isTrashEnabled: true,
|
||||||
|
isInLockedView: false,
|
||||||
|
currentAlbum: null,
|
||||||
|
advancedTroubleshooting: false,
|
||||||
|
isStacked: false,
|
||||||
|
source: ActionSource.viewer,
|
||||||
|
buttonPosition: ButtonPosition.bottomBar,
|
||||||
|
);
|
||||||
|
|
||||||
|
const expectedTypes = [
|
||||||
|
ActionButtonType.share,
|
||||||
|
ActionButtonType.editImage,
|
||||||
|
ActionButtonType.addTo,
|
||||||
|
ActionButtonType.delete,
|
||||||
|
];
|
||||||
|
|
||||||
|
final bottomBarTypes = ActionButtonBuilder.getViewerBottomBarTypes(context);
|
||||||
|
final kebabTypes = ActionButtonBuilder.getViewerKebabMenuTypes(
|
||||||
|
context.copyWith(buttonPosition: ButtonPosition.kebabMenu),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(const ListEquality().equals(bottomBarTypes, expectedTypes), isTrue);
|
||||||
|
expect(bottomBarTypes.any(kebabTypes.contains), isFalse);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user