From 20a0a6daab69cc44d07ea891bf4d76db9dd15747 Mon Sep 17 00:00:00 2001 From: Pratik Canopas <109139581+cp-pratik-k@users.noreply.github.com> Date: Mon, 15 Apr 2024 12:26:08 +0530 Subject: [PATCH] Support multiple download (#30) --- app/assets/locales/app_en.arb | 3 ++ .../multi_selection_done_button.dart | 47 ++++++++++++++++++- .../ui/flow/home/home_screen_view_model.dart | 12 +++++ .../media_preview/components/top_bar.dart | 16 ++++++- 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/app/assets/locales/app_en.arb b/app/assets/locales/app_en.arb index c467ea3..205015b 100644 --- a/app/assets/locales/app_en.arb +++ b/app/assets/locales/app_en.arb @@ -73,6 +73,9 @@ "download_require_text": "Download required", "download_require_message": "To watch the video, simply download it first. Tap the download button to begin downloading the video.", + "download_from_google_drive_text": "Download from Google Drive", + "download_from_google_drive_alert_message": " Are you sure you want to download this media? It will be saved to your gallery.", + "name_text": "Name", "size_text": "Size", "created_at_text": "Created at", diff --git a/app/lib/ui/flow/home/components/multi_selection_done_button.dart b/app/lib/ui/flow/home/components/multi_selection_done_button.dart index 32909b8..e18db56 100644 --- a/app/lib/ui/flow/home/components/multi_selection_done_button.dart +++ b/app/lib/ui/flow/home/components/multi_selection_done_button.dart @@ -2,6 +2,7 @@ import 'package:cloud_gallery/components/app_dialog.dart'; import 'package:cloud_gallery/domain/extensions/context_extensions.dart'; import 'package:cloud_gallery/ui/flow/home/home_screen_view_model.dart'; import 'package:data/models/media/media.dart'; +import 'package:data/models/media/media_extension.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -27,6 +28,10 @@ class MultiSelectionDoneButton extends ConsumerWidget { .any((element) => element.sources.contains(AppMediaSource.local)); final bool showUploadToDriveButton = selectedMedias.any( (element) => !element.sources.contains(AppMediaSource.googleDrive)); + + final bool showDownloadButton = + selectedMedias.any((element) => element.isGoogleDriveStored); + return FloatingActionButton( elevation: 3, backgroundColor: context.colorScheme.primary, @@ -51,7 +56,10 @@ class MultiSelectionDoneButton extends ConsumerWidget { ), if (showDeleteFromDeviceButton) AppSheetAction( - icon: const Icon(CupertinoIcons.delete), + icon: const Icon( + CupertinoIcons.delete, + size: 24, + ), title: context.l10n.common_delete_from_device, onPressed: () { showAppAlertDialog( @@ -80,7 +88,10 @@ class MultiSelectionDoneButton extends ConsumerWidget { ), if (showDeleteFromDriveButton) AppSheetAction( - icon: const Icon(CupertinoIcons.delete), + icon: const Icon( + CupertinoIcons.delete, + size: 24, + ), title: context.l10n.common_delete_from_google_drive, onPressed: () { showAppAlertDialog( @@ -107,6 +118,38 @@ class MultiSelectionDoneButton extends ConsumerWidget { ); }, ), + if (showDownloadButton) + AppSheetAction( + icon: Icon( + CupertinoIcons.cloud_download, + size: 24, + color: context.colorScheme.textSecondary, + ), + title: context.l10n.download_from_google_drive_text, + onPressed: () { + showAppAlertDialog( + context: context, + title: context.l10n.download_from_google_drive_text, + message: + context.l10n.download_from_google_drive_alert_message, + actions: [ + AppAlertAction( + title: context.l10n.common_cancel, + onPressed: () { + context.pop(); + }, + ), + AppAlertAction( + isDestructiveAction: true, + title: context.l10n.common_download, + onPressed: () { + context.pop(); + }, + ), + ], + ); + }, + ), ], ), ); diff --git a/app/lib/ui/flow/home/home_screen_view_model.dart b/app/lib/ui/flow/home/home_screen_view_model.dart index 3892933..8daa41f 100644 --- a/app/lib/ui/flow/home/home_screen_view_model.dart +++ b/app/lib/ui/flow/home/home_screen_view_model.dart @@ -3,6 +3,7 @@ import 'package:cloud_gallery/domain/extensions/map_extensions.dart'; import 'package:cloud_gallery/domain/extensions/media_list_extension.dart'; import 'package:data/models/app_process/app_process.dart'; import 'package:data/models/media/media.dart'; +import 'package:data/models/media/media_extension.dart'; import 'package:data/repositories/google_drive_process_repo.dart'; import 'package:data/services/auth_service.dart'; import 'package:data/services/google_drive_service.dart'; @@ -276,6 +277,17 @@ class HomeViewStateNotifier extends StateNotifier } } + Future downloadMediaFromGoogleDrive() async { + try { + final medias = + state.selectedMedias.where((element) => element.isGoogleDriveStored); + _googleDriveProcessRepo.downloadMediasFromGoogleDrive( + medias: medias.toList()); + } catch (e) { + state = state.copyWith(error: e); + } + } + Future backUpMediaOnGoogleDrive() async { try { if (!_authService.signedInWithGoogle) { diff --git a/app/lib/ui/flow/media_preview/components/top_bar.dart b/app/lib/ui/flow/media_preview/components/top_bar.dart index 58cea83..908fe39 100644 --- a/app/lib/ui/flow/media_preview/components/top_bar.dart +++ b/app/lib/ui/flow/media_preview/components/top_bar.dart @@ -44,10 +44,24 @@ class PreviewTopBar extends StatelessWidget { }, icon: Icon( CupertinoIcons.info, - color: context.colorScheme.textPrimary, + color: context.colorScheme.textSecondary, size: 22, ), ), + if(media.isGoogleDriveStored) + ActionButton( + onPressed: () { + notifier.downloadMediaFromGoogleDrive(media: media); + }, + icon: Padding( + padding: const EdgeInsets.all(4.0), + child: Icon( + CupertinoIcons.cloud_download, + color: context.colorScheme.textSecondary, + size: 22, + ), + ), + ), ActionButton( onPressed: () async { if (media.isCommonStored && media.driveMediaRefId != null) {