mirror of
https://github.com/immich-app/immich.git
synced 2024-12-28 22:51:59 +00:00
combine album name
This commit is contained in:
parent
a3e8701f0a
commit
6c343bf2ed
2 changed files with 35 additions and 9 deletions
|
@ -3,19 +3,23 @@
|
|||
import 'package:photo_manager/photo_manager.dart';
|
||||
|
||||
class BackupCandidate {
|
||||
final String albumName;
|
||||
final String id;
|
||||
final List<String> albumName;
|
||||
final AssetEntity asset;
|
||||
|
||||
BackupCandidate({
|
||||
required this.id,
|
||||
required this.albumName,
|
||||
required this.asset,
|
||||
});
|
||||
|
||||
BackupCandidate copyWith({
|
||||
String? albumName,
|
||||
String? id,
|
||||
List<String>? albumName,
|
||||
AssetEntity? asset,
|
||||
}) {
|
||||
return BackupCandidate(
|
||||
id: id ?? this.id,
|
||||
albumName: albumName ?? this.albumName,
|
||||
asset: asset ?? this.asset,
|
||||
);
|
||||
|
@ -28,9 +32,11 @@ class BackupCandidate {
|
|||
bool operator ==(covariant BackupCandidate other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other.albumName == albumName && other.asset == asset;
|
||||
return other.id == id &&
|
||||
other.albumName == albumName &&
|
||||
other.asset == asset;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => albumName.hashCode ^ asset.hashCode;
|
||||
int get hashCode => id.hashCode ^ albumName.hashCode ^ asset.hashCode;
|
||||
}
|
||||
|
|
|
@ -295,6 +295,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||
final Set<BackupCandidate> assetsFromSelectedAlbums = {};
|
||||
final Set<BackupCandidate> assetsFromExcludedAlbums = {};
|
||||
|
||||
/// Extracing assets from selected albums
|
||||
for (final album in state.selectedBackupAlbums) {
|
||||
final assetCount = await album.albumEntity.assetCountAsync;
|
||||
|
||||
|
@ -308,12 +309,17 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||
);
|
||||
|
||||
final candidate = assets.map(
|
||||
(e) => BackupCandidate(albumName: album.albumEntity.name, asset: e),
|
||||
(e) => BackupCandidate(
|
||||
id: e.id,
|
||||
albumName: [album.albumEntity.name],
|
||||
asset: e,
|
||||
),
|
||||
);
|
||||
|
||||
assetsFromSelectedAlbums.addAll(candidate.toSet());
|
||||
}
|
||||
|
||||
/// Extracing assets from excluded albums
|
||||
for (final album in state.excludedBackupAlbums) {
|
||||
final assetCount = await album.albumEntity.assetCountAsync;
|
||||
|
||||
|
@ -327,16 +333,20 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||
);
|
||||
|
||||
final candidate = assets.map(
|
||||
(e) => BackupCandidate(albumName: album.albumEntity.name, asset: e),
|
||||
(e) => BackupCandidate(
|
||||
id: e.id,
|
||||
albumName: [album.albumEntity.name],
|
||||
asset: e,
|
||||
),
|
||||
);
|
||||
|
||||
assetsFromExcludedAlbums.addAll(candidate);
|
||||
}
|
||||
|
||||
final Set<BackupCandidate> allUniqueAssets =
|
||||
Set<BackupCandidate> allUniqueAssets =
|
||||
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
|
||||
final allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
|
||||
|
||||
final allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
|
||||
if (allAssetsInDatabase == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -353,6 +363,16 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||
(e) => duplicatedAssetIds.contains(e.asset.id),
|
||||
);
|
||||
|
||||
/// Merge different album name of the same id
|
||||
allUniqueAssets = allUniqueAssets.map((e) {
|
||||
final List<String> albumNames = allUniqueAssets
|
||||
.where((a) => a.id == e.id)
|
||||
.map((a) => a.albumName)
|
||||
.expand((e) => e)
|
||||
.toList();
|
||||
return e.copyWith(albumName: albumNames);
|
||||
}).toSet();
|
||||
|
||||
if (allUniqueAssets.isEmpty) {
|
||||
log.info("No assets are selected for back up");
|
||||
state = state.copyWith(
|
||||
|
@ -372,7 +392,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||
// Save to persistent storage
|
||||
await _updatePersistentAlbumsSelection();
|
||||
|
||||
debugPrint("backup asset $allUniqueAssets", wrapWidth: 80);
|
||||
debugPrint("backup asset ${allUniqueAssets.length}", wrapWidth: 80);
|
||||
}
|
||||
|
||||
/// Get all necessary information for calculating the available albums,
|
||||
|
|
Loading…
Reference in a new issue