2022-06-18 14:36:58 +02:00
|
|
|
import 'package:cancellation_token_http/http.dart';
|
2022-07-06 23:12:55 +02:00
|
|
|
import 'package:collection/collection.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
|
|
|
|
import 'package:immich_mobile/modules/backup/models/available_album.model.dart';
|
2022-07-06 23:12:55 +02:00
|
|
|
import 'package:immich_mobile/modules/backup/models/current_upload_asset.model.dart';
|
2022-05-06 14:22:23 +02:00
|
|
|
|
|
|
|
enum BackUpProgressEnum { idle, inProgress, done }
|
|
|
|
|
2022-07-06 23:12:55 +02:00
|
|
|
class BackUpState {
|
2022-05-06 14:22:23 +02:00
|
|
|
// enum
|
|
|
|
final BackUpProgressEnum backupProgress;
|
2022-06-25 22:12:47 +02:00
|
|
|
final List<String> allAssetsInDatabase;
|
2022-05-06 14:22:23 +02:00
|
|
|
final double progressInPercentage;
|
2022-06-18 14:36:58 +02:00
|
|
|
final CancellationToken cancelToken;
|
2022-07-13 14:23:48 +02:00
|
|
|
final ServerInfoResponseDto serverInfo;
|
2022-05-06 14:22:23 +02:00
|
|
|
|
|
|
|
/// All available albums on the device
|
|
|
|
final List<AvailableAlbum> availableAlbums;
|
|
|
|
final Set<AssetPathEntity> selectedBackupAlbums;
|
|
|
|
final Set<AssetPathEntity> excludedBackupAlbums;
|
|
|
|
|
|
|
|
/// Assets that are not overlapping in selected backup albums and excluded backup albums
|
|
|
|
final Set<AssetEntity> allUniqueAssets;
|
|
|
|
|
|
|
|
/// All assets from the selected albums that have been backup
|
|
|
|
final Set<String> selectedAlbumsBackupAssetsIds;
|
|
|
|
|
2022-07-06 23:12:55 +02:00
|
|
|
// Current Backup Asset
|
|
|
|
final CurrentUploadAsset currentUploadAsset;
|
|
|
|
|
2022-05-06 14:22:23 +02:00
|
|
|
const BackUpState({
|
|
|
|
required this.backupProgress,
|
2022-06-25 22:12:47 +02:00
|
|
|
required this.allAssetsInDatabase,
|
2022-05-06 14:22:23 +02:00
|
|
|
required this.progressInPercentage,
|
|
|
|
required this.cancelToken,
|
|
|
|
required this.serverInfo,
|
|
|
|
required this.availableAlbums,
|
|
|
|
required this.selectedBackupAlbums,
|
|
|
|
required this.excludedBackupAlbums,
|
|
|
|
required this.allUniqueAssets,
|
|
|
|
required this.selectedAlbumsBackupAssetsIds,
|
2022-07-06 23:12:55 +02:00
|
|
|
required this.currentUploadAsset,
|
2022-05-06 14:22:23 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
BackUpState copyWith({
|
|
|
|
BackUpProgressEnum? backupProgress,
|
2022-06-25 22:12:47 +02:00
|
|
|
List<String>? allAssetsInDatabase,
|
2022-05-06 14:22:23 +02:00
|
|
|
double? progressInPercentage,
|
2022-06-18 14:36:58 +02:00
|
|
|
CancellationToken? cancelToken,
|
2022-07-13 14:23:48 +02:00
|
|
|
ServerInfoResponseDto? serverInfo,
|
2022-05-06 14:22:23 +02:00
|
|
|
List<AvailableAlbum>? availableAlbums,
|
|
|
|
Set<AssetPathEntity>? selectedBackupAlbums,
|
|
|
|
Set<AssetPathEntity>? excludedBackupAlbums,
|
|
|
|
Set<AssetEntity>? allUniqueAssets,
|
|
|
|
Set<String>? selectedAlbumsBackupAssetsIds,
|
2022-07-06 23:12:55 +02:00
|
|
|
CurrentUploadAsset? currentUploadAsset,
|
2022-05-06 14:22:23 +02:00
|
|
|
}) {
|
|
|
|
return BackUpState(
|
|
|
|
backupProgress: backupProgress ?? this.backupProgress,
|
2022-06-25 22:12:47 +02:00
|
|
|
allAssetsInDatabase: allAssetsInDatabase ?? this.allAssetsInDatabase,
|
2022-05-06 14:22:23 +02:00
|
|
|
progressInPercentage: progressInPercentage ?? this.progressInPercentage,
|
|
|
|
cancelToken: cancelToken ?? this.cancelToken,
|
|
|
|
serverInfo: serverInfo ?? this.serverInfo,
|
|
|
|
availableAlbums: availableAlbums ?? this.availableAlbums,
|
|
|
|
selectedBackupAlbums: selectedBackupAlbums ?? this.selectedBackupAlbums,
|
|
|
|
excludedBackupAlbums: excludedBackupAlbums ?? this.excludedBackupAlbums,
|
|
|
|
allUniqueAssets: allUniqueAssets ?? this.allUniqueAssets,
|
2022-06-25 22:12:47 +02:00
|
|
|
selectedAlbumsBackupAssetsIds:
|
|
|
|
selectedAlbumsBackupAssetsIds ?? this.selectedAlbumsBackupAssetsIds,
|
2022-07-06 23:12:55 +02:00
|
|
|
currentUploadAsset: currentUploadAsset ?? this.currentUploadAsset,
|
2022-05-06 14:22:23 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
2022-07-06 23:12:55 +02:00
|
|
|
return 'BackUpState(backupProgress: $backupProgress, allAssetsInDatabase: $allAssetsInDatabase, progressInPercentage: $progressInPercentage, cancelToken: $cancelToken, serverInfo: $serverInfo, availableAlbums: $availableAlbums, selectedBackupAlbums: $selectedBackupAlbums, excludedBackupAlbums: $excludedBackupAlbums, allUniqueAssets: $allUniqueAssets, selectedAlbumsBackupAssetsIds: $selectedAlbumsBackupAssetsIds, currentUploadAsset: $currentUploadAsset)';
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool operator ==(Object other) {
|
|
|
|
if (identical(this, other)) return true;
|
|
|
|
final collectionEquals = const DeepCollectionEquality().equals;
|
|
|
|
|
|
|
|
return other is BackUpState &&
|
|
|
|
other.backupProgress == backupProgress &&
|
|
|
|
collectionEquals(other.allAssetsInDatabase, allAssetsInDatabase) &&
|
|
|
|
other.progressInPercentage == progressInPercentage &&
|
|
|
|
other.cancelToken == cancelToken &&
|
|
|
|
other.serverInfo == serverInfo &&
|
|
|
|
collectionEquals(other.availableAlbums, availableAlbums) &&
|
|
|
|
collectionEquals(other.selectedBackupAlbums, selectedBackupAlbums) &&
|
|
|
|
collectionEquals(other.excludedBackupAlbums, excludedBackupAlbums) &&
|
|
|
|
collectionEquals(other.allUniqueAssets, allUniqueAssets) &&
|
2022-07-13 14:23:48 +02:00
|
|
|
collectionEquals(
|
|
|
|
other.selectedAlbumsBackupAssetsIds,
|
|
|
|
selectedAlbumsBackupAssetsIds,
|
|
|
|
) &&
|
2022-07-06 23:12:55 +02:00
|
|
|
other.currentUploadAsset == currentUploadAsset;
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-07-06 23:12:55 +02:00
|
|
|
int get hashCode {
|
|
|
|
return backupProgress.hashCode ^
|
|
|
|
allAssetsInDatabase.hashCode ^
|
|
|
|
progressInPercentage.hashCode ^
|
|
|
|
cancelToken.hashCode ^
|
|
|
|
serverInfo.hashCode ^
|
|
|
|
availableAlbums.hashCode ^
|
|
|
|
selectedBackupAlbums.hashCode ^
|
|
|
|
excludedBackupAlbums.hashCode ^
|
|
|
|
allUniqueAssets.hashCode ^
|
|
|
|
selectedAlbumsBackupAssetsIds.hashCode ^
|
|
|
|
currentUploadAsset.hashCode;
|
2022-05-06 14:22:23 +02:00
|
|
|
}
|
|
|
|
}
|