Skip to content

Commit

Permalink
Support multiple download (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k authored Apr 15, 2024
1 parent c524478 commit 20a0a6d
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 3 deletions.
3 changes: 3 additions & 0 deletions app/assets/locales/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
47 changes: 45 additions & 2 deletions app/lib/ui/flow/home/components/multi_selection_done_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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();
},
),
],
);
},
),
],
),
);
Expand Down
12 changes: 12 additions & 0 deletions app/lib/ui/flow/home/home_screen_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -276,6 +277,17 @@ class HomeViewStateNotifier extends StateNotifier<HomeViewState>
}
}

Future<void> downloadMediaFromGoogleDrive() async {
try {
final medias =
state.selectedMedias.where((element) => element.isGoogleDriveStored);
_googleDriveProcessRepo.downloadMediasFromGoogleDrive(
medias: medias.toList());
} catch (e) {
state = state.copyWith(error: e);
}
}

Future<void> backUpMediaOnGoogleDrive() async {
try {
if (!_authService.signedInWithGoogle) {
Expand Down
16 changes: 15 additions & 1 deletion app/lib/ui/flow/media_preview/components/top_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 20a0a6d

Please sign in to comment.