diff --git a/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart b/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart index aa50b6c24b7c3..74124f76ef663 100644 --- a/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart +++ b/mobile/lib/modules/home/ui/asset_grid/immich_asset_grid.dart @@ -23,7 +23,6 @@ class ImmichAssetGridState extends State { ItemPositionsListener.create(); bool _scrolling = false; - bool _multiselect = false; Set _selectedAssets = HashSet(); List get _assets { @@ -46,8 +45,8 @@ class ImmichAssetGridState extends State { .toSet(); } - void _callSelectionListener() { - widget.listener?.call(_multiselect, _getSelectedAssets()); + void _callSelectionListener(bool selectionActive) { + widget.listener?.call(selectionActive, _getSelectedAssets()); } void _selectAssets(List assets) { @@ -55,9 +54,7 @@ class ImmichAssetGridState extends State { for (var e in assets) { _selectedAssets.add(e.id); } - - _multiselect = true; - _callSelectionListener(); + _callSelectionListener(true); }); } @@ -66,26 +63,20 @@ class ImmichAssetGridState extends State { for (var e in assets) { _selectedAssets.remove(e.id); } - - if (_selectedAssets.isEmpty) { - _multiselect = false; - } - - _callSelectionListener(); + _callSelectionListener(_selectedAssets.isNotEmpty); }); } void _deselectAll() { setState(() { - _multiselect = false; _selectedAssets.clear(); }); - _callSelectionListener(); + _callSelectionListener(false); } bool _allAssetsSelected(List assets) { - return _multiselect && + return widget.selectionActive && assets.firstWhereOrNull((e) => !_selectedAssets.contains(e.id)) == null; } @@ -104,7 +95,7 @@ class ImmichAssetGridState extends State { return ThumbnailImage( asset: asset, assetList: _assets, - multiselectEnabled: _multiselect, + multiselectEnabled: widget.selectionActive, isSelected: _selectedAssets.contains(asset.id), onSelect: () => _selectAssets([asset]), onDeselect: () => _deselectAssets([asset]), @@ -137,7 +128,7 @@ class ImmichAssetGridState extends State { BuildContext context, String title, List assets) { return DailyTitleText( isoDate: title, - multiselectEnabled: _multiselect, + multiselectEnabled: widget.selectionActive, onSelect: () => _selectAssets(assets), onDeselect: () => _deselectAssets(assets), selected: _allAssetsSelected(assets), @@ -227,12 +218,23 @@ class ImmichAssetGridState extends State { ); } + + @override + void didUpdateWidget(ImmichAssetGrid oldWidget) { + super.didUpdateWidget(oldWidget); + if (!widget.selectionActive) { + setState(() { + _selectedAssets.clear(); + }); + } + } + @override Widget build(BuildContext context) { return Stack( children: [ _buildAssetGrid(), - if (_multiselect) _buildMultiSelectIndicator(), + if (widget.selectionActive) _buildMultiSelectIndicator(), ], ); } @@ -244,6 +246,7 @@ class ImmichAssetGrid extends StatefulWidget { final double margin; final bool showStorageIndicator; final ImmichAssetGridSelectionListener? listener; + final bool selectionActive; ImmichAssetGrid({ super.key, @@ -252,6 +255,7 @@ class ImmichAssetGrid extends StatefulWidget { required this.showStorageIndicator, this.listener, this.margin = 5.0, + this.selectionActive = false }); @override diff --git a/mobile/lib/modules/home/views/home_page.dart b/mobile/lib/modules/home/views/home_page.dart index 2e38ee08f7091..d3926f93abb6e 100644 --- a/mobile/lib/modules/home/views/home_page.dart +++ b/mobile/lib/modules/home/views/home_page.dart @@ -48,10 +48,12 @@ class HomePage extends HookConsumerWidget { void onShareAssets() { ref.watch(shareServiceProvider).shareAssets(selection.value.toList()); + multiselectEnabled.value = false; } void onDelete() { ref.watch(assetProvider.notifier).deleteAssets(selection.value); + multiselectEnabled.value = false; } return SafeArea( @@ -82,6 +84,7 @@ class HomePage extends HookConsumerWidget { showStorageIndicator: appSettingService .getSetting(AppSettingsEnum.storageIndicator), listener: selectionListener, + selectionActive: multiselectEnabled.value, ), ), if (multiselectEnabled.value) ...[