-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement google drive video preview
- Loading branch information
1 parent
a351a6e
commit 3be95d2
Showing
6 changed files
with
169 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import 'package:data/extensions/iterable_extension.dart'; | ||
import 'package:data/models/app_process/app_process.dart'; | ||
import 'package:data/models/media/media.dart'; | ||
|
||
extension MediaListHelper on List<AppMedia> { | ||
void removeGoogleDriveRefFromMedias({List<String>? removeFromIds}) { | ||
for (int index = 0; index < length; index++) { | ||
if (this[index].isGoogleDriveStored && | ||
(removeFromIds?.contains(this[index].id) ?? true)) { | ||
removeAt(index); | ||
} else if (this[index].isCommonStored && | ||
(removeFromIds?.contains(this[index].id) ?? true)) { | ||
this[index] = this[index].copyWith( | ||
sources: this[index].sources.toList() | ||
..remove(AppMediaSource.googleDrive), | ||
thumbnailLink: null, | ||
driveMediaRefId: null, | ||
); | ||
} | ||
} | ||
} | ||
|
||
void addGoogleDriveRefInMedia( | ||
{required List<AppProcess> process, required List<String> processIds}) { | ||
updateWhere( | ||
where: (media) => processIds.contains(media.id), | ||
update: (media) { | ||
final res = process | ||
.where((element) => element.id == media.id) | ||
.first | ||
.response as AppMedia?; | ||
return media.copyWith( | ||
thumbnailLink: res?.thumbnailLink, | ||
driveMediaRefId: res?.id, | ||
sources: media.sources.toList()..add(AppMediaSource.googleDrive), | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void addLocalRefInMedias( | ||
{required List<AppProcess> process, required List<String> processIds}) { | ||
updateWhere( | ||
where: (media) => processIds.contains(media.id), | ||
update: (media) { | ||
final res = process | ||
.where((element) => element.id == media.id) | ||
.first | ||
.response as AppMedia?; | ||
|
||
if (res == null) return media; | ||
return res.copyWith( | ||
thumbnailLink: media.thumbnailLink, | ||
driveMediaRefId: media.id, | ||
sources: res.sources.toList()..add(AppMediaSource.googleDrive), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:photo_manager/photo_manager.dart'; | ||
import 'media.dart'; | ||
|
||
extension AppMediaExtension on AppMedia { | ||
Future<bool> get isExist async { | ||
return await File(path).exists(); | ||
} | ||
|
||
Future<Uint8List?> loadThumbnail({Size size = const Size(300, 300)}) async { | ||
var rootToken = RootIsolateToken.instance!; | ||
final ThumbNailParameter thumbNailParameter = | ||
ThumbNailParameter(rootToken, size, id, type); | ||
final bytes = await compute(_loadThumbnailInBackground, thumbNailParameter); | ||
return bytes; | ||
} | ||
|
||
FutureOr<Uint8List?> _loadThumbnailInBackground( | ||
ThumbNailParameter parameters) async { | ||
BackgroundIsolateBinaryMessenger.ensureInitialized(parameters.token); | ||
return await AssetEntity( | ||
id: parameters.id, | ||
typeInt: parameters.type.index, | ||
width: 0, | ||
height: 0, | ||
).thumbnailDataWithSize( | ||
ThumbnailSize( | ||
parameters.size.width.toInt(), | ||
parameters.size.height.toInt(), | ||
), | ||
format: ThumbnailFormat.png, | ||
quality: 70, | ||
); | ||
} | ||
|
||
AppMedia margeGoogleDriveMedia(AppMedia media){ | ||
return copyWith( | ||
thumbnailLink: media.thumbnailLink, | ||
driveMediaRefId: media.driveMediaRefId, | ||
sources: sources.toList()..add(AppMediaSource.googleDrive), | ||
); | ||
} | ||
|
||
bool get isGoogleDriveStored => | ||
sources.contains(AppMediaSource.googleDrive) && sources.length == 1; | ||
|
||
bool get isLocalStored => | ||
sources.contains(AppMediaSource.local) && sources.length == 1; | ||
|
||
bool get isCommonStored => sources.length > 1; | ||
} | ||
|
||
class ThumbNailParameter { | ||
final RootIsolateToken token; | ||
final Size size; | ||
final String id; | ||
final AppMediaType type; | ||
|
||
ThumbNailParameter(this.token, this.size, this.id, this.type); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters