Merge branch 'master' into caption
This commit is contained in:
commit
837a2b468e
2 changed files with 70 additions and 31 deletions
|
@ -415,47 +415,86 @@ class FadingAppBarState extends State<FadingAppBar> {
|
||||||
Future<void> _download(File file) async {
|
Future<void> _download(File file) async {
|
||||||
final dialog = createProgressDialog(context, "Downloading...");
|
final dialog = createProgressDialog(context, "Downloading...");
|
||||||
await dialog.show();
|
await dialog.show();
|
||||||
|
try {
|
||||||
final FileType type = file.fileType;
|
final FileType type = file.fileType;
|
||||||
// save and track image for livePhoto/image and video for FileType.video
|
final bool downloadLivePhotoOnDroid =
|
||||||
|
type == FileType.livePhoto && Platform.isAndroid;
|
||||||
|
AssetEntity savedAsset;
|
||||||
final io.File fileToSave = await getFile(file);
|
final io.File fileToSave = await getFile(file);
|
||||||
final savedAsset = type == FileType.video
|
if (type == FileType.image) {
|
||||||
? (await PhotoManager.editor.saveVideo(fileToSave, title: file.title))
|
savedAsset = await PhotoManager.editor
|
||||||
: (await PhotoManager.editor
|
.saveImageWithPath(fileToSave.path, title: file.title);
|
||||||
.saveImageWithPath(fileToSave.path, title: file.title));
|
} else if (type == FileType.video) {
|
||||||
|
savedAsset =
|
||||||
|
await PhotoManager.editor.saveVideo(fileToSave, title: file.title);
|
||||||
|
} else if (type == FileType.livePhoto) {
|
||||||
|
final io.File liveVideoFile =
|
||||||
|
await getFileFromServer(file, liveVideo: true);
|
||||||
|
if (liveVideoFile == null) {
|
||||||
|
throw AssertionError("Live video can not be null");
|
||||||
|
}
|
||||||
|
if (downloadLivePhotoOnDroid) {
|
||||||
|
await _saveLivePhotoOnDroid(fileToSave, liveVideoFile, file);
|
||||||
|
} else {
|
||||||
|
savedAsset = await PhotoManager.editor.darwin.saveLivePhoto(
|
||||||
|
imageFile: fileToSave,
|
||||||
|
videoFile: liveVideoFile,
|
||||||
|
title: file.title,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (savedAsset != null) {
|
||||||
// immediately track assetID to avoid duplicate upload
|
// immediately track assetID to avoid duplicate upload
|
||||||
await LocalSyncService.instance.trackDownloadedFile(savedAsset.id);
|
await LocalSyncService.instance.trackDownloadedFile(savedAsset.id);
|
||||||
file.localID = savedAsset.id;
|
|
||||||
await FilesDB.instance.insert(file);
|
|
||||||
|
|
||||||
if (type == FileType.livePhoto) {
|
|
||||||
final io.File liveVideo = await getFileFromServer(file, liveVideo: true);
|
|
||||||
if (liveVideo == null) {
|
|
||||||
_logger.warning("Failed to find live video" + file.tag);
|
|
||||||
} else {
|
|
||||||
final videoTitle = file_path.basenameWithoutExtension(file.title) +
|
|
||||||
file_path.extension(liveVideo.path);
|
|
||||||
final savedAsset = (await PhotoManager.editor.saveVideo(
|
|
||||||
liveVideo,
|
|
||||||
title: videoTitle,
|
|
||||||
));
|
|
||||||
final ignoreVideoFile = IgnoredFile(
|
final ignoreVideoFile = IgnoredFile(
|
||||||
savedAsset.id,
|
savedAsset.id,
|
||||||
savedAsset.title ?? videoTitle,
|
savedAsset.title ?? "",
|
||||||
savedAsset.relativePath ?? 'remoteDownload',
|
savedAsset.relativePath ?? 'remoteDownload',
|
||||||
"remoteDownload",
|
"remoteDownload",
|
||||||
);
|
);
|
||||||
debugPrint("IgnoreFile for auto-upload ${ignoreVideoFile.toString()}");
|
debugPrint("IgnoreFile for auto-upload ${ignoreVideoFile.toString()}");
|
||||||
await IgnoredFilesService.instance.cacheAndInsert([ignoreVideoFile]);
|
await IgnoredFilesService.instance.cacheAndInsert([ignoreVideoFile]);
|
||||||
|
file.localID = savedAsset.id;
|
||||||
|
await FilesDB.instance.insert(file);
|
||||||
|
Bus.instance.fire(LocalPhotosUpdatedEvent([file]));
|
||||||
|
} else if (!downloadLivePhotoOnDroid && savedAsset == null) {
|
||||||
|
_logger.severe('Failed to save assert of type $type');
|
||||||
|
}
|
||||||
|
showToast(context, "File saved to gallery");
|
||||||
|
await dialog.hide();
|
||||||
|
} catch (e) {
|
||||||
|
_logger.warning("Failed to save file", e);
|
||||||
|
await dialog.hide();
|
||||||
|
showGenericErrorDialog(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bus.instance.fire(LocalPhotosUpdatedEvent([file]));
|
Future<void> _saveLivePhotoOnDroid(
|
||||||
await dialog.hide();
|
io.File image, io.File video, File enteFile) async {
|
||||||
if (file.fileType == FileType.livePhoto) {
|
debugPrint("Downloading LivePhoto on Droid");
|
||||||
showToast(context, "Photo and video saved to gallery");
|
AssetEntity savedAsset = await PhotoManager.editor
|
||||||
} else {
|
.saveImageWithPath(image.path, title: enteFile.title);
|
||||||
showToast(context, "File saved to gallery");
|
IgnoredFile ignoreVideoFile = IgnoredFile(
|
||||||
}
|
savedAsset.id,
|
||||||
|
savedAsset.title ?? '',
|
||||||
|
savedAsset.relativePath ?? 'remoteDownload',
|
||||||
|
"remoteDownload",
|
||||||
|
);
|
||||||
|
await IgnoredFilesService.instance.cacheAndInsert([ignoreVideoFile]);
|
||||||
|
final videoTitle = file_path.basenameWithoutExtension(enteFile.title) +
|
||||||
|
file_path.extension(video.path);
|
||||||
|
savedAsset = (await PhotoManager.editor.saveVideo(
|
||||||
|
video,
|
||||||
|
title: videoTitle,
|
||||||
|
));
|
||||||
|
ignoreVideoFile = IgnoredFile(
|
||||||
|
savedAsset.id,
|
||||||
|
savedAsset.title ?? videoTitle,
|
||||||
|
savedAsset.relativePath ?? 'remoteDownload',
|
||||||
|
"remoteDownload",
|
||||||
|
);
|
||||||
|
await IgnoredFilesService.instance.cacheAndInsert([ignoreVideoFile]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _setAs(File file) async {
|
Future<void> _setAs(File file) async {
|
||||||
|
|
|
@ -934,7 +934,7 @@ packages:
|
||||||
name: photo_manager
|
name: photo_manager
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.1"
|
version: "2.5.0"
|
||||||
photo_view:
|
photo_view:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
Loading…
Reference in a new issue