Skip to content

Commit

Permalink
desplay-drive-uploaded-media
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-pratik-k committed Feb 28, 2024
1 parent fc1fe90 commit 4302208
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class _LocalSourceViewState extends ConsumerState<GoogleDriveMediasScreen> {
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: context.colorScheme.outline,
image: DecorationImage(
image: NetworkImage(medias[index].path),
fit: BoxFit.cover,
),
),
);
},
Expand Down
1 change: 1 addition & 0 deletions app/lib/ui/flow/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _HomeScreenState extends ConsumerState<HomeScreen> {
const ScreenSourceSegmentControl(),
Expanded(
child: PageView(
restorationId: 'home_page_view',
onPageChanged: (value) {
notifier.updateMediaSource(
isChangedByScroll: true, source: MediaSource.values[value]);
Expand Down
5 changes: 2 additions & 3 deletions data/lib/models/media/media.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ class AppMedia with _$AppMedia {
DateTime? createdTime,
DateTime? modifiedTime,
AppMediaOrientation? orientation,
required double? latitude,
required double? longitude,
double? latitude,
double? longitude,
@Default(false) bool isLocal,
}) = _AppMedia;

factory AppMedia.fromJson(Map<String, dynamic> json) =>
_$AppMediaFromJson(json);
}

8 changes: 4 additions & 4 deletions data/lib/models/media/media.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ class _$AppMediaImpl implements _AppMedia {
this.createdTime,
this.modifiedTime,
this.orientation,
required this.latitude,
required this.longitude,
this.latitude,
this.longitude,
this.isLocal = false});

factory _$AppMediaImpl.fromJson(Map<String, dynamic> json) =>
Expand Down Expand Up @@ -377,8 +377,8 @@ abstract class _AppMedia implements AppMedia {
final DateTime? createdTime,
final DateTime? modifiedTime,
final AppMediaOrientation? orientation,
required final double? latitude,
required final double? longitude,
final double? latitude,
final double? longitude,
final bool isLocal}) = _$AppMediaImpl;

factory _AppMedia.fromJson(Map<String, dynamic> json) =
Expand Down
20 changes: 16 additions & 4 deletions data/lib/services/google_drive_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class GoogleDriveService {
q: "name='$_backUpFolderName' and mimeType='application/vnd.google-apps.folder'",
);

if (response.files?.isNotEmpty ?? false || response.files?.first.trashed == false) {
if (response.files?.isNotEmpty ??
false || response.files?.first.trashed == false) {
return response.files?.first.id;
} else {
final folder = drive.File(
Expand All @@ -52,16 +53,27 @@ class GoogleDriveService {
}
}

Future<List<AppMedia>> getDriveMedias({required String backUpFolderId}) async {
Future<List<AppMedia>> getDriveMedias(
{required String backUpFolderId}) async {
try {
final driveApi = await _getGoogleDriveAPI();

final response = await driveApi.files.list(
q: "'$backUpFolderId' in parents and trashed=false",
$fields:
"files(id, name, description, mimeType, thumbnailLink, webContentLink, createdTime, modifiedTime)",
);

print(response.files?.map((e) => e.toJson()).toList());
return [];
print(response.files?.map((e) => e.toJson()).toList());
return (response.files ?? [])
.map(
(e) => AppMedia(
id: e.id!,
path: e.thumbnailLink!,
type: AppMediaType.image,
),
)
.toList();
} catch (e) {
throw AppError.fromError(e);
}
Expand Down

0 comments on commit 4302208

Please sign in to comment.