2025-07-18 23:58:53 -05:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/models/album/local_album.model.dart';
|
|
|
|
|
import 'package:immich_mobile/domain/services/local_album.service.dart';
|
2025-07-21 15:30:51 -05:00
|
|
|
import 'package:immich_mobile/infrastructure/repositories/local_album.repository.dart';
|
2025-07-18 23:58:53 -05:00
|
|
|
import 'package:immich_mobile/providers/infrastructure/album.provider.dart';
|
|
|
|
|
|
2025-07-25 08:07:22 +05:30
|
|
|
final backupAlbumProvider = StateNotifierProvider<BackupAlbumNotifier, List<LocalAlbum>>(
|
2025-07-29 00:34:03 +05:30
|
|
|
(ref) => BackupAlbumNotifier(ref.watch(localAlbumServiceProvider)),
|
2025-07-18 23:58:53 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
class BackupAlbumNotifier extends StateNotifier<List<LocalAlbum>> {
|
|
|
|
|
BackupAlbumNotifier(this._localAlbumService) : super([]) {
|
|
|
|
|
getAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final LocalAlbumService _localAlbumService;
|
|
|
|
|
|
|
|
|
|
Future<void> getAll() async {
|
2025-07-25 08:07:22 +05:30
|
|
|
state = await _localAlbumService.getAll(sortBy: {SortLocalAlbumsBy.assetCount});
|
2025-07-18 23:58:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> selectAlbum(LocalAlbum album) async {
|
|
|
|
|
album = album.copyWith(backupSelection: BackupSelection.selected);
|
|
|
|
|
await _localAlbumService.update(album);
|
|
|
|
|
|
|
|
|
|
state = state
|
|
|
|
|
.map(
|
|
|
|
|
(currentAlbum) => currentAlbum.id == album.id
|
|
|
|
|
? currentAlbum.copyWith(backupSelection: BackupSelection.selected)
|
|
|
|
|
: currentAlbum,
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> deselectAlbum(LocalAlbum album) async {
|
|
|
|
|
album = album.copyWith(backupSelection: BackupSelection.none);
|
|
|
|
|
await _localAlbumService.update(album);
|
|
|
|
|
|
|
|
|
|
state = state
|
|
|
|
|
.map(
|
2025-07-25 08:07:22 +05:30
|
|
|
(currentAlbum) =>
|
|
|
|
|
currentAlbum.id == album.id ? currentAlbum.copyWith(backupSelection: BackupSelection.none) : currentAlbum,
|
2025-07-18 23:58:53 -05:00
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> excludeAlbum(LocalAlbum album) async {
|
|
|
|
|
album = album.copyWith(backupSelection: BackupSelection.excluded);
|
|
|
|
|
await _localAlbumService.update(album);
|
|
|
|
|
|
|
|
|
|
state = state
|
|
|
|
|
.map(
|
|
|
|
|
(currentAlbum) => currentAlbum.id == album.id
|
|
|
|
|
? currentAlbum.copyWith(backupSelection: BackupSelection.excluded)
|
|
|
|
|
: currentAlbum,
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
|
|
|
|
}
|