mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 09:08:40 +00:00
move storing of the images into the mediafile service
This commit is contained in:
parent
d067a3c931
commit
24f45ce9bd
3 changed files with 10 additions and 43 deletions
|
|
@ -218,6 +218,15 @@ class MediaFileService {
|
|||
}
|
||||
if (tempPath.existsSync()) {
|
||||
await tempPath.copy(storedPath.path);
|
||||
if (gUser.storeMediaFilesInGallery) {
|
||||
if (mediaFile.type == MediaType.video) {
|
||||
await saveVideoToGallery(storedPath.path);
|
||||
} else {
|
||||
await saveImageToGallery(
|
||||
storedPath.readAsBytesSync(),
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log.error(
|
||||
'Could not store image neither as ${tempPath.path} does not exists.',
|
||||
|
|
|
|||
|
|
@ -2,10 +2,7 @@ import 'dart:async';
|
|||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:twonly/globals.dart';
|
||||
import 'package:twonly/src/database/tables/mediafiles.table.dart';
|
||||
import 'package:twonly/src/services/mediafiles/mediafile.service.dart';
|
||||
import 'package:twonly/src/utils/log.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
|
||||
class SaveToGalleryButton extends StatefulWidget {
|
||||
|
|
@ -48,37 +45,10 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
|
|||
});
|
||||
|
||||
await widget.storeImageAsOriginal();
|
||||
|
||||
String? res;
|
||||
|
||||
final storedMediaPath = widget.mediaService.storedPath;
|
||||
|
||||
await widget.mediaService.storeMediaFile();
|
||||
|
||||
if (gUser.storeMediaFilesInGallery) {
|
||||
if (widget.mediaService.mediaFile.type == MediaType.video) {
|
||||
res = await saveVideoToGallery(storedMediaPath.path);
|
||||
} else {
|
||||
res = await saveImageToGallery(
|
||||
storedMediaPath.readAsBytesSync(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (res == null) {
|
||||
setState(() {
|
||||
_imageSaved = true;
|
||||
});
|
||||
} else if (mounted && context.mounted) {
|
||||
Log.error('Could not store media file in the gallery.');
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(res),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
setState(() {
|
||||
_imageSaving = false;
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -357,18 +357,6 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
|||
);
|
||||
setState(() {
|
||||
imageSaved = true;
|
||||
});
|
||||
|
||||
if (gUser.storeMediaFilesInGallery) {
|
||||
if (currentMedia!.mediaFile.type == MediaType.video) {
|
||||
await saveVideoToGallery(currentMedia!.storedPath.path);
|
||||
} else if (currentMedia!.mediaFile.type == MediaType.image ||
|
||||
currentMedia!.mediaFile.type == MediaType.gif) {
|
||||
final imageBytes = await currentMedia!.storedPath.readAsBytes();
|
||||
await saveImageToGallery(imageBytes);
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
imageSaving = false;
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue