mirror of
https://github.com/immich-app/immich.git
synced 2025-11-17 06:42:34 +09:00
Some checks are pending
CodeQL / Analyze (javascript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Docker / pre-job (push) Waiting to run
Docker / Re-Tag ML () (push) Blocked by required conditions
Docker / Re-Tag ML (-armnn) (push) Blocked by required conditions
Docker / Re-Tag ML (-cuda) (push) Blocked by required conditions
Docker / Re-Tag ML (-openvino) (push) Blocked by required conditions
Docker / Re-Tag Server () (push) Blocked by required conditions
Docker / Build and Push ML (armnn, linux/arm64, -armnn) (push) Blocked by required conditions
Docker / Build and Push ML (cpu, linux/amd64,linux/arm64) (push) Blocked by required conditions
Docker / Build and Push ML (cuda, linux/amd64, -cuda) (push) Blocked by required conditions
Docker / Build and Push ML (openvino, linux/amd64, -openvino) (push) Blocked by required conditions
Docker / Build and Push Server (cpu, linux/amd64,linux/arm64) (push) Blocked by required conditions
Docker / Docker Build & Push Server Success (push) Blocked by required conditions
Docker / Docker Build & Push ML Success (push) Blocked by required conditions
Docs build / pre-job (push) Waiting to run
Docs build / Docs Build (push) Blocked by required conditions
Static Code Analysis / pre-job (push) Waiting to run
Static Code Analysis / Run Dart Code Analysis (push) Blocked by required conditions
Test / pre-job (push) Waiting to run
Test / Test & Lint Server (push) Blocked by required conditions
Test / Unit Test CLI (push) Blocked by required conditions
Test / Unit Test CLI (Windows) (push) Blocked by required conditions
Test / Test & Lint Web (push) Blocked by required conditions
Test / End-to-End Lint (push) Blocked by required conditions
Test / Medium Tests (Server) (push) Blocked by required conditions
Test / End-to-End Tests (Server & CLI) (push) Blocked by required conditions
Test / End-to-End Tests (Web) (push) Blocked by required conditions
Test / Unit Test Mobile (push) Blocked by required conditions
Test / Unit Test ML (push) Blocked by required conditions
Test / ShellCheck (push) Waiting to run
Test / OpenAPI Clients (push) Waiting to run
Test / TypeORM Checks (push) Waiting to run
refactor to use context helpers for consistency Co-authored-by: dvbthien <dvbthien@gmail.com>
151 lines
4.5 KiB
Dart
151 lines
4.5 KiB
Dart
import 'package:background_downloader/background_downloader.dart';
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
|
import 'package:immich_mobile/providers/asset_viewer/download.provider.dart';
|
|
|
|
class DownloadPanel extends ConsumerWidget {
|
|
const DownloadPanel({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final showProgress = ref.watch(
|
|
downloadStateProvider.select((state) => state.showProgress),
|
|
);
|
|
|
|
final tasks = ref
|
|
.watch(
|
|
downloadStateProvider.select((state) => state.taskProgress),
|
|
)
|
|
.entries
|
|
.toList();
|
|
|
|
onCancelDownload(String id) {
|
|
ref.watch(downloadStateProvider.notifier).cancelDownload(id);
|
|
}
|
|
|
|
return Positioned(
|
|
bottom: 140,
|
|
left: 16,
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 300),
|
|
child: showProgress
|
|
? ConstrainedBox(
|
|
constraints:
|
|
BoxConstraints.loose(Size(context.width - 32, 300)),
|
|
child: ListView.builder(
|
|
shrinkWrap: true,
|
|
itemCount: tasks.length,
|
|
itemBuilder: (context, index) {
|
|
final task = tasks[index];
|
|
return DownloadTaskTile(
|
|
progress: task.value.progress,
|
|
fileName: task.value.fileName,
|
|
status: task.value.status,
|
|
onCancelDownload: () => onCancelDownload(task.key),
|
|
);
|
|
},
|
|
),
|
|
)
|
|
: const SizedBox.shrink(key: ValueKey('no_progress')),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class DownloadTaskTile extends StatelessWidget {
|
|
final double progress;
|
|
final String fileName;
|
|
final TaskStatus status;
|
|
final VoidCallback onCancelDownload;
|
|
|
|
const DownloadTaskTile({
|
|
super.key,
|
|
required this.progress,
|
|
required this.fileName,
|
|
required this.status,
|
|
required this.onCancelDownload,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final progressPercent = (progress * 100).round();
|
|
|
|
getStatusText() {
|
|
switch (status) {
|
|
case TaskStatus.running:
|
|
return 'downloading'.tr();
|
|
case TaskStatus.complete:
|
|
return 'download_complete'.tr();
|
|
case TaskStatus.failed:
|
|
return 'download_failed'.tr();
|
|
case TaskStatus.canceled:
|
|
return 'download_canceled'.tr();
|
|
case TaskStatus.paused:
|
|
return 'download_paused'.tr();
|
|
case TaskStatus.enqueued:
|
|
return 'download_enqueue'.tr();
|
|
case TaskStatus.notFound:
|
|
return 'download_notfound'.tr();
|
|
case TaskStatus.waitingToRetry:
|
|
return 'download_waiting_to_retry'.tr();
|
|
}
|
|
}
|
|
|
|
return SizedBox(
|
|
key: const ValueKey('download_progress'),
|
|
width: context.width - 32,
|
|
child: Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: ListTile(
|
|
minVerticalPadding: 18,
|
|
leading: const Icon(Icons.video_file_outlined),
|
|
title: Text(
|
|
getStatusText(),
|
|
style: context.textTheme.labelLarge,
|
|
),
|
|
trailing: IconButton(
|
|
icon: Icon(Icons.close, color: context.colorScheme.onError),
|
|
onPressed: onCancelDownload,
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: context.colorScheme.error.withAlpha(200),
|
|
),
|
|
),
|
|
subtitle: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
fileName,
|
|
style: context.textTheme.labelMedium,
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: LinearProgressIndicator(
|
|
minHeight: 8.0,
|
|
value: progress,
|
|
borderRadius:
|
|
const BorderRadius.all(Radius.circular(10.0)),
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
'$progressPercent%',
|
|
style: context.textTheme.labelSmall,
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|