1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-29 15:11:58 +00:00

combine album name

This commit is contained in:
Alex 2024-06-17 08:50:30 -07:00
parent a3e8701f0a
commit 6c343bf2ed
No known key found for this signature in database
GPG key ID: 53CD082B3A5E1082
2 changed files with 35 additions and 9 deletions

View file

@ -3,19 +3,23 @@
import 'package:photo_manager/photo_manager.dart'; import 'package:photo_manager/photo_manager.dart';
class BackupCandidate { class BackupCandidate {
final String albumName; final String id;
final List<String> albumName;
final AssetEntity asset; final AssetEntity asset;
BackupCandidate({ BackupCandidate({
required this.id,
required this.albumName, required this.albumName,
required this.asset, required this.asset,
}); });
BackupCandidate copyWith({ BackupCandidate copyWith({
String? albumName, String? id,
List<String>? albumName,
AssetEntity? asset, AssetEntity? asset,
}) { }) {
return BackupCandidate( return BackupCandidate(
id: id ?? this.id,
albumName: albumName ?? this.albumName, albumName: albumName ?? this.albumName,
asset: asset ?? this.asset, asset: asset ?? this.asset,
); );
@ -28,9 +32,11 @@ class BackupCandidate {
bool operator ==(covariant BackupCandidate other) { bool operator ==(covariant BackupCandidate other) {
if (identical(this, other)) return true; if (identical(this, other)) return true;
return other.albumName == albumName && other.asset == asset; return other.id == id &&
other.albumName == albumName &&
other.asset == asset;
} }
@override @override
int get hashCode => albumName.hashCode ^ asset.hashCode; int get hashCode => id.hashCode ^ albumName.hashCode ^ asset.hashCode;
} }

View file

@ -295,6 +295,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
final Set<BackupCandidate> assetsFromSelectedAlbums = {}; final Set<BackupCandidate> assetsFromSelectedAlbums = {};
final Set<BackupCandidate> assetsFromExcludedAlbums = {}; final Set<BackupCandidate> assetsFromExcludedAlbums = {};
/// Extracing assets from selected albums
for (final album in state.selectedBackupAlbums) { for (final album in state.selectedBackupAlbums) {
final assetCount = await album.albumEntity.assetCountAsync; final assetCount = await album.albumEntity.assetCountAsync;
@ -308,12 +309,17 @@ class BackupNotifier extends StateNotifier<BackUpState> {
); );
final candidate = assets.map( 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()); assetsFromSelectedAlbums.addAll(candidate.toSet());
} }
/// Extracing assets from excluded albums
for (final album in state.excludedBackupAlbums) { for (final album in state.excludedBackupAlbums) {
final assetCount = await album.albumEntity.assetCountAsync; final assetCount = await album.albumEntity.assetCountAsync;
@ -327,16 +333,20 @@ class BackupNotifier extends StateNotifier<BackUpState> {
); );
final candidate = assets.map( 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); assetsFromExcludedAlbums.addAll(candidate);
} }
final Set<BackupCandidate> allUniqueAssets = Set<BackupCandidate> allUniqueAssets =
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums); assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
final allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
final allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
if (allAssetsInDatabase == null) { if (allAssetsInDatabase == null) {
return; return;
} }
@ -353,6 +363,16 @@ class BackupNotifier extends StateNotifier<BackUpState> {
(e) => duplicatedAssetIds.contains(e.asset.id), (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) { if (allUniqueAssets.isEmpty) {
log.info("No assets are selected for back up"); log.info("No assets are selected for back up");
state = state.copyWith( state = state.copyWith(
@ -372,7 +392,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
// Save to persistent storage // Save to persistent storage
await _updatePersistentAlbumsSelection(); await _updatePersistentAlbumsSelection();
debugPrint("backup asset $allUniqueAssets", wrapWidth: 80); debugPrint("backup asset ${allUniqueAssets.length}", wrapWidth: 80);
} }
/// Get all necessary information for calculating the available albums, /// Get all necessary information for calculating the available albums,