mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(mobile): stack only through merging from timeline (#4598)
* mobile: remove stack selection page * mobile: require at-least 2 assets to stack * mobile: sort stack children by fileCreatedAt --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
013da0aa3d
commit
9b418642a6
5 changed files with 22 additions and 73 deletions
|
|
@ -4,33 +4,38 @@ class SelectionAssetState {
|
|||
final bool hasRemote;
|
||||
final bool hasLocal;
|
||||
final bool hasMerged;
|
||||
final int selectedCount;
|
||||
|
||||
const SelectionAssetState({
|
||||
this.hasRemote = false,
|
||||
this.hasLocal = false,
|
||||
this.hasMerged = false,
|
||||
this.selectedCount = 0,
|
||||
});
|
||||
|
||||
SelectionAssetState copyWith({
|
||||
bool? hasRemote,
|
||||
bool? hasLocal,
|
||||
bool? hasMerged,
|
||||
int? selectedCount,
|
||||
}) {
|
||||
return SelectionAssetState(
|
||||
hasRemote: hasRemote ?? this.hasRemote,
|
||||
hasLocal: hasLocal ?? this.hasLocal,
|
||||
hasMerged: hasMerged ?? this.hasMerged,
|
||||
selectedCount: selectedCount ?? this.selectedCount,
|
||||
);
|
||||
}
|
||||
|
||||
SelectionAssetState.fromSelection(Set<Asset> selection)
|
||||
: hasLocal = selection.any((e) => e.storage == AssetState.local),
|
||||
hasMerged = selection.any((e) => e.storage == AssetState.merged),
|
||||
hasRemote = selection.any((e) => e.storage == AssetState.remote);
|
||||
hasRemote = selection.any((e) => e.storage == AssetState.remote),
|
||||
selectedCount = selection.length;
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
'SelectionAssetState(hasRemote: $hasRemote, hasMerged: $hasMerged, hasMerged: $hasMerged)';
|
||||
'SelectionAssetState(hasRemote: $hasRemote, hasMerged: $hasMerged, hasMerged: $hasMerged, selectedCount: $selectedCount)';
|
||||
|
||||
@override
|
||||
bool operator ==(covariant SelectionAssetState other) {
|
||||
|
|
@ -38,10 +43,14 @@ class SelectionAssetState {
|
|||
|
||||
return other.hasRemote == hasRemote &&
|
||||
other.hasLocal == hasLocal &&
|
||||
other.hasMerged == hasMerged;
|
||||
other.hasMerged == hasMerged &&
|
||||
other.selectedCount == selectedCount;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
hasRemote.hashCode ^ hasLocal.hashCode ^ hasMerged.hashCode;
|
||||
hasRemote.hashCode ^
|
||||
hasLocal.hashCode ^
|
||||
hasMerged.hashCode ^
|
||||
selectedCount.hashCode;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class ControlBottomAppBar extends ConsumerWidget {
|
|||
}
|
||||
: null,
|
||||
),
|
||||
if (!hasLocal)
|
||||
if (!hasLocal && selectionAssetState.selectedCount > 1)
|
||||
ControlBoxButton(
|
||||
iconData: Icons.filter_none_rounded,
|
||||
label: "control_bottom_app_bar_stack".tr(),
|
||||
|
|
|
|||
|
|
@ -7,12 +7,10 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:immich_mobile/modules/album/models/asset_selection_page_result.model.dart';
|
||||
import 'package:immich_mobile/modules/album/providers/album.provider.dart';
|
||||
import 'package:immich_mobile/modules/album/providers/album_detail.provider.dart';
|
||||
import 'package:immich_mobile/modules/album/providers/shared_album.provider.dart';
|
||||
import 'package:immich_mobile/modules/album/services/album.service.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/providers/asset_stack.provider.dart';
|
||||
import 'package:immich_mobile/modules/asset_viewer/services/asset_stack.service.dart';
|
||||
import 'package:immich_mobile/modules/backup/providers/manual_upload.provider.dart';
|
||||
import 'package:immich_mobile/modules/home/models/selection_state.dart';
|
||||
|
|
@ -259,46 +257,15 @@ class HomePage extends HookConsumerWidget {
|
|||
void onStack() async {
|
||||
try {
|
||||
processing.value = true;
|
||||
if (!selectionEnabledHook.value) {
|
||||
if (!selectionEnabledHook.value || selection.value.length < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
final selectedAsset = selection.value.elementAt(0);
|
||||
|
||||
if (selection.value.length == 1) {
|
||||
final stackChildren =
|
||||
(await ref.read(assetStackProvider(selectedAsset).future))
|
||||
.toSet();
|
||||
AssetSelectionPageResult? returnPayload =
|
||||
await AutoRouter.of(context).push<AssetSelectionPageResult?>(
|
||||
AssetSelectionRoute(
|
||||
existingAssets: stackChildren,
|
||||
canDeselect: true,
|
||||
query: getAssetStackSelectionQuery(ref, selectedAsset),
|
||||
),
|
||||
);
|
||||
|
||||
if (returnPayload != null) {
|
||||
Set<Asset> selectedAssets = returnPayload.selectedAssets;
|
||||
// Do not add itself as its stack child
|
||||
selectedAssets.remove(selectedAsset);
|
||||
final removedChildren = stackChildren.difference(selectedAssets);
|
||||
final addedChildren = selectedAssets.difference(stackChildren);
|
||||
await ref.read(assetStackServiceProvider).updateStack(
|
||||
selectedAsset,
|
||||
childrenToAdd: addedChildren.toList(),
|
||||
childrenToRemove: removedChildren.toList(),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Merge assets
|
||||
selection.value.remove(selectedAsset);
|
||||
final selectedAssets = selection.value;
|
||||
await ref.read(assetStackServiceProvider).updateStack(
|
||||
selectedAsset,
|
||||
childrenToAdd: selectedAssets.toList(),
|
||||
);
|
||||
}
|
||||
final parent = selection.value.elementAt(0);
|
||||
selection.value.remove(parent);
|
||||
await ref.read(assetStackServiceProvider).updateStack(
|
||||
parent,
|
||||
childrenToAdd: selection.value.toList(),
|
||||
);
|
||||
} finally {
|
||||
processing.value = false;
|
||||
selectionEnabledHook.value = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue