|
@@ -18,7 +18,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
: super(
|
|
: super(
|
|
BackUpState(
|
|
BackUpState(
|
|
backupProgress: BackUpProgressEnum.idle,
|
|
backupProgress: BackUpProgressEnum.idle,
|
|
- allAssetOnDatabase: const [],
|
|
|
|
|
|
+ allAssetsInDatabase: const [],
|
|
progressInPercentage: 0,
|
|
progressInPercentage: 0,
|
|
cancelToken: CancellationToken(),
|
|
cancelToken: CancellationToken(),
|
|
serverInfo: ServerInfo(
|
|
serverInfo: ServerInfo(
|
|
@@ -36,7 +36,9 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
allUniqueAssets: const {},
|
|
allUniqueAssets: const {},
|
|
selectedAlbumsBackupAssetsIds: const {},
|
|
selectedAlbumsBackupAssetsIds: const {},
|
|
),
|
|
),
|
|
- );
|
|
|
|
|
|
+ ) {
|
|
|
|
+ getBackupInfo();
|
|
|
|
+ }
|
|
|
|
|
|
final BackupService _backupService;
|
|
final BackupService _backupService;
|
|
final ServerInfoService _serverInfoService;
|
|
final ServerInfoService _serverInfoService;
|
|
@@ -93,7 +95,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
/// If this is the first time performing backup - set the default selected album to be
|
|
/// If this is the first time performing backup - set the default selected album to be
|
|
/// the one that has all assets (Recent on Android, Recents on iOS)
|
|
/// the one that has all assets (Recent on Android, Recents on iOS)
|
|
///
|
|
///
|
|
- Future<void> getBackupAlbumsInfo() async {
|
|
|
|
|
|
+ Future<void> _getBackupAlbumsInfo() async {
|
|
// Get all albums on the device
|
|
// Get all albums on the device
|
|
List<AvailableAlbum> availableAlbums = [];
|
|
List<AvailableAlbum> availableAlbums = [];
|
|
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
|
|
List<AssetPathEntity> albums = await PhotoManager.getAssetPathList(
|
|
@@ -177,7 +179,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
/// Find the assets that are not overlapping between the two sets
|
|
/// Find the assets that are not overlapping between the two sets
|
|
/// Those assets are unique and are used as the total assets
|
|
/// Those assets are unique and are used as the total assets
|
|
///
|
|
///
|
|
- void _updateBackupAssetCount() async {
|
|
|
|
|
|
+ Future<void> _updateBackupAssetCount() async {
|
|
Set<AssetEntity> assetsFromSelectedAlbums = {};
|
|
Set<AssetEntity> assetsFromSelectedAlbums = {};
|
|
Set<AssetEntity> assetsFromExcludedAlbums = {};
|
|
Set<AssetEntity> assetsFromExcludedAlbums = {};
|
|
|
|
|
|
@@ -195,27 +197,27 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
|
|
|
|
Set<AssetEntity> allUniqueAssets =
|
|
Set<AssetEntity> allUniqueAssets =
|
|
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
|
|
assetsFromSelectedAlbums.difference(assetsFromExcludedAlbums);
|
|
- List<String> allAssetOnDatabase =
|
|
|
|
|
|
+ List<String> allAssetsInDatabase =
|
|
await _backupService.getDeviceBackupAsset();
|
|
await _backupService.getDeviceBackupAsset();
|
|
|
|
|
|
// Find asset that were backup from selected albums
|
|
// Find asset that were backup from selected albums
|
|
Set<String> selectedAlbumsBackupAssets =
|
|
Set<String> selectedAlbumsBackupAssets =
|
|
Set.from(allUniqueAssets.map((e) => e.id));
|
|
Set.from(allUniqueAssets.map((e) => e.id));
|
|
selectedAlbumsBackupAssets
|
|
selectedAlbumsBackupAssets
|
|
- .removeWhere((assetId) => !allAssetOnDatabase.contains(assetId));
|
|
|
|
|
|
+ .removeWhere((assetId) => !allAssetsInDatabase.contains(assetId));
|
|
|
|
|
|
if (allUniqueAssets.isEmpty) {
|
|
if (allUniqueAssets.isEmpty) {
|
|
debugPrint("No Asset On Device");
|
|
debugPrint("No Asset On Device");
|
|
state = state.copyWith(
|
|
state = state.copyWith(
|
|
backupProgress: BackUpProgressEnum.idle,
|
|
backupProgress: BackUpProgressEnum.idle,
|
|
- allAssetOnDatabase: allAssetOnDatabase,
|
|
|
|
|
|
+ allAssetsInDatabase: allAssetsInDatabase,
|
|
allUniqueAssets: {},
|
|
allUniqueAssets: {},
|
|
selectedAlbumsBackupAssetsIds: selectedAlbumsBackupAssets,
|
|
selectedAlbumsBackupAssetsIds: selectedAlbumsBackupAssets,
|
|
);
|
|
);
|
|
return;
|
|
return;
|
|
} else {
|
|
} else {
|
|
state = state.copyWith(
|
|
state = state.copyWith(
|
|
- allAssetOnDatabase: allAssetOnDatabase,
|
|
|
|
|
|
+ allAssetsInDatabase: allAssetsInDatabase,
|
|
allUniqueAssets: allUniqueAssets,
|
|
allUniqueAssets: allUniqueAssets,
|
|
selectedAlbumsBackupAssetsIds: selectedAlbumsBackupAssets,
|
|
selectedAlbumsBackupAssetsIds: selectedAlbumsBackupAssets,
|
|
);
|
|
);
|
|
@@ -223,6 +225,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
|
|
|
|
// Save to persistent storage
|
|
// Save to persistent storage
|
|
_updatePersistentAlbumsSelection();
|
|
_updatePersistentAlbumsSelection();
|
|
|
|
+
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
|
|
|
|
///
|
|
///
|
|
@@ -230,10 +234,10 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
/// which albums are selected or excluded
|
|
/// which albums are selected or excluded
|
|
/// and then update the UI according to those information
|
|
/// and then update the UI according to those information
|
|
///
|
|
///
|
|
- void getBackupInfo() async {
|
|
|
|
- await getBackupAlbumsInfo();
|
|
|
|
- _updateServerInfo();
|
|
|
|
- _updateBackupAssetCount();
|
|
|
|
|
|
+ Future<void> getBackupInfo() async {
|
|
|
|
+ await _getBackupAlbumsInfo();
|
|
|
|
+ await _updateServerInfo();
|
|
|
|
+ await _updateBackupAssetCount();
|
|
}
|
|
}
|
|
|
|
|
|
///
|
|
///
|
|
@@ -256,11 +260,10 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
/// Invoke backup process
|
|
/// Invoke backup process
|
|
///
|
|
///
|
|
void startBackupProcess() async {
|
|
void startBackupProcess() async {
|
|
- _updateServerInfo();
|
|
|
|
- _updateBackupAssetCount();
|
|
|
|
-
|
|
|
|
state = state.copyWith(backupProgress: BackUpProgressEnum.inProgress);
|
|
state = state.copyWith(backupProgress: BackUpProgressEnum.inProgress);
|
|
|
|
|
|
|
|
+ await getBackupInfo();
|
|
|
|
+
|
|
var authResult = await PhotoManager.requestPermissionExtend();
|
|
var authResult = await PhotoManager.requestPermissionExtend();
|
|
if (authResult.isAuth) {
|
|
if (authResult.isAuth) {
|
|
await PhotoManager.clearFileCache();
|
|
await PhotoManager.clearFileCache();
|
|
@@ -271,10 +274,10 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
- Set<AssetEntity> assetsWillBeBackup = state.allUniqueAssets;
|
|
|
|
|
|
+ Set<AssetEntity> assetsWillBeBackup = Set.from(state.allUniqueAssets);
|
|
|
|
|
|
// Remove item that has already been backed up
|
|
// Remove item that has already been backed up
|
|
- for (var assetId in state.allAssetOnDatabase) {
|
|
|
|
|
|
+ for (var assetId in state.allAssetsInDatabase) {
|
|
assetsWillBeBackup.removeWhere((e) => e.id == assetId);
|
|
assetsWillBeBackup.removeWhere((e) => e.id == assetId);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -301,8 +304,8 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
state = state.copyWith(selectedAlbumsBackupAssetsIds: {
|
|
state = state.copyWith(selectedAlbumsBackupAssetsIds: {
|
|
...state.selectedAlbumsBackupAssetsIds,
|
|
...state.selectedAlbumsBackupAssetsIds,
|
|
deviceAssetId
|
|
deviceAssetId
|
|
- }, allAssetOnDatabase: [
|
|
|
|
- ...state.allAssetOnDatabase,
|
|
|
|
|
|
+ }, allAssetsInDatabase: [
|
|
|
|
+ ...state.allAssetsInDatabase,
|
|
deviceAssetId
|
|
deviceAssetId
|
|
]);
|
|
]);
|
|
|
|
|
|
@@ -321,7 +324,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|
progressInPercentage: (sent.toDouble() / total.toDouble() * 100));
|
|
progressInPercentage: (sent.toDouble() / total.toDouble() * 100));
|
|
}
|
|
}
|
|
|
|
|
|
- void _updateServerInfo() async {
|
|
|
|
|
|
+ Future<void> _updateServerInfo() async {
|
|
var serverInfo = await _serverInfoService.getServerInfo();
|
|
var serverInfo = await _serverInfoService.getServerInfo();
|
|
|
|
|
|
// Update server info
|
|
// Update server info
|