import 'package:background_downloader/background_downloader.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:immich_mobile/interfaces/download.interface.dart'; import 'package:immich_mobile/utils/download.dart'; final downloadRepositoryProvider = Provider((ref) => DownloadRepository()); class DownloadRepository implements IDownloadRepository { @override void Function(TaskStatusUpdate)? onImageDownloadStatus; @override void Function(TaskStatusUpdate)? onVideoDownloadStatus; @override void Function(TaskStatusUpdate)? onLivePhotoDownloadStatus; @override void Function(TaskProgressUpdate)? onTaskProgress; DownloadRepository() { FileDownloader().registerCallbacks( group: downloadGroupImage, taskStatusCallback: (update) => onImageDownloadStatus?.call(update), taskProgressCallback: (update) => onTaskProgress?.call(update), ); FileDownloader().registerCallbacks( group: downloadGroupVideo, taskStatusCallback: (update) => onVideoDownloadStatus?.call(update), taskProgressCallback: (update) => onTaskProgress?.call(update), ); FileDownloader().registerCallbacks( group: downloadGroupLivePhoto, taskStatusCallback: (update) => onLivePhotoDownloadStatus?.call(update), taskProgressCallback: (update) => onTaskProgress?.call(update), ); } @override Future download(DownloadTask task) { return FileDownloader().enqueue(task); } @override Future deleteAllTrackingRecords() { return FileDownloader().database.deleteAllRecords(); } @override Future cancel(String id) { return FileDownloader().cancelTaskWithId(id); } @override Future> getLiveVideoTasks() { return FileDownloader().database.allRecordsWithStatus( TaskStatus.complete, group: downloadGroupLivePhoto, ); } @override Future deleteRecordsWithIds(List ids) { return FileDownloader().database.deleteRecordsWithIds(ids); } }