Refactor mobile to use OpenApi generated SDK (#336)

This commit is contained in:
Alex 2022-07-13 07:23:48 -05:00 committed by GitHub
parent d69470e207
commit ae7e582ec8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
276 changed files with 14513 additions and 3003 deletions

View file

@ -12,8 +12,8 @@ import 'package:immich_mobile/modules/backup/providers/error_backup_list.provide
import 'package:immich_mobile/modules/backup/services/backup.service.dart';
import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
import 'package:immich_mobile/shared/models/server_info.model.dart';
import 'package:immich_mobile/shared/services/server_info.service.dart';
import 'package:openapi/api.dart';
import 'package:photo_manager/photo_manager.dart';
class BackupNotifier extends StateNotifier<BackUpState> {
@ -28,12 +28,12 @@ class BackupNotifier extends StateNotifier<BackUpState> {
allAssetsInDatabase: const [],
progressInPercentage: 0,
cancelToken: CancellationToken(),
serverInfo: ServerInfo(
serverInfo: ServerInfoResponseDto(
diskAvailable: "0",
diskAvailableRaw: 0,
diskSize: "0",
diskSizeRaw: 0,
diskUsagePercentage: 0.0,
diskUsagePercentage: 0,
diskUse: "0",
diskUseRaw: 0,
),
@ -113,7 +113,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
// Get all albums on the device
List<AvailableAlbum> availableAlbums = [];
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
hasAll: true, type: RequestType.common);
hasAll: true,
type: RequestType.common,
);
for (AssetPathEntity album in albums) {
AvailableAlbum availableAlbum = AvailableAlbum(albumEntity: album);
@ -156,7 +158,10 @@ class BackupNotifier extends StateNotifier<BackUpState> {
// Get album that contains all assets
var list = await PhotoManager.getAssetPathList(
hasAll: true, onlyAll: true, type: RequestType.common);
hasAll: true,
onlyAll: true,
type: RequestType.common,
);
AssetPathEntity albumHasAllAssets = list.first;
backupAlbumInfoBox.put(
@ -175,13 +180,15 @@ class BackupNotifier extends StateNotifier<BackUpState> {
for (var selectedAlbumId in backupAlbumInfo!.selectedAlbumIds) {
var albumAsset = await AssetPathEntity.fromId(selectedAlbumId);
state = state.copyWith(
selectedBackupAlbums: {...state.selectedBackupAlbums, albumAsset});
selectedBackupAlbums: {...state.selectedBackupAlbums, albumAsset},
);
}
for (var excludedAlbumId in backupAlbumInfo.excludedAlbumsIds) {
var albumAsset = await AssetPathEntity.fromId(excludedAlbumId);
state = state.copyWith(
excludedBackupAlbums: {...state.excludedBackupAlbums, albumAsset});
excludedBackupAlbums: {...state.excludedBackupAlbums, albumAsset},
);
}
} catch (e) {
debugPrint("[ERROR] Failed to generate album from id $e");
@ -211,8 +218,11 @@ class BackupNotifier extends StateNotifier<BackUpState> {
Set<AssetEntity> allUniqueAssets =
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
List<String> allAssetsInDatabase =
await _backupService.getDeviceBackupAsset();
var allAssetsInDatabase = await _backupService.getDeviceBackupAsset();
if (allAssetsInDatabase == null) {
return;
}
// Find asset that were backup from selected albums
Set<String> selectedAlbumsBackupAssets =
@ -328,23 +338,27 @@ class BackupNotifier extends StateNotifier<BackUpState> {
void cancelBackup() {
state.cancelToken.cancel();
state = state.copyWith(
backupProgress: BackUpProgressEnum.idle, progressInPercentage: 0.0);
backupProgress: BackUpProgressEnum.idle,
progressInPercentage: 0.0,
);
}
void _onAssetUploaded(String deviceAssetId, String deviceId) {
state = state.copyWith(selectedAlbumsBackupAssetsIds: {
...state.selectedAlbumsBackupAssetsIds,
deviceAssetId
}, allAssetsInDatabase: [
...state.allAssetsInDatabase,
deviceAssetId
]);
state = state.copyWith(
selectedAlbumsBackupAssetsIds: {
...state.selectedAlbumsBackupAssetsIds,
deviceAssetId
},
allAssetsInDatabase: [...state.allAssetsInDatabase, deviceAssetId],
);
if (state.allUniqueAssets.length -
state.selectedAlbumsBackupAssetsIds.length ==
0) {
state = state.copyWith(
backupProgress: BackUpProgressEnum.done, progressInPercentage: 0.0);
backupProgress: BackUpProgressEnum.done,
progressInPercentage: 0.0,
);
}
_updateServerInfo();
@ -352,24 +366,19 @@ class BackupNotifier extends StateNotifier<BackUpState> {
void _onUploadProgress(int sent, int total) {
state = state.copyWith(
progressInPercentage: (sent.toDouble() / total.toDouble() * 100));
progressInPercentage: (sent.toDouble() / total.toDouble() * 100),
);
}
Future<void> _updateServerInfo() async {
var serverInfo = await _serverInfoService.getServerInfo();
// Update server info
state = state.copyWith(
serverInfo: ServerInfo(
diskSize: serverInfo.diskSize,
diskUse: serverInfo.diskUse,
diskAvailable: serverInfo.diskAvailable,
diskSizeRaw: serverInfo.diskSizeRaw,
diskUseRaw: serverInfo.diskUseRaw,
diskAvailableRaw: serverInfo.diskAvailableRaw,
diskUsagePercentage: serverInfo.diskUsagePercentage,
),
);
if (serverInfo != null) {
state = state.copyWith(
serverInfo: serverInfo,
);
}
}
void resumeBackup() {