This commit is contained in:
otsmr 2025-06-03 13:16:41 +02:00
parent 324b8a9758
commit b8aeb0e6ed
3 changed files with 67 additions and 55 deletions

View file

@ -7,19 +7,23 @@ import 'package:twonly/src/services/api/media_send.dart';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:twonly/src/utils/misc.dart'; import 'package:twonly/src/utils/misc.dart';
import 'package:twonly/src/utils/storage.dart';
class SaveToGalleryButton extends StatefulWidget { class SaveToGalleryButton extends StatefulWidget {
final Future<Uint8List?> Function() getMergedImage; final Future<Uint8List?> Function() getMergedImage;
final String? sendNextMediaToUserName; final String? sendNextMediaToUserName;
final File? videoFilePath; final File? videoFilePath;
final int? mediaUploadId; final int? mediaUploadId;
final bool isLoading;
const SaveToGalleryButton( const SaveToGalleryButton({
{super.key, super.key,
required this.getMergedImage, required this.getMergedImage,
required this.isLoading,
this.sendNextMediaToUserName, this.sendNextMediaToUserName,
this.mediaUploadId, this.mediaUploadId,
this.videoFilePath}); this.videoFilePath,
});
@override @override
State<SaveToGalleryButton> createState() => SaveToGalleryButtonState(); State<SaveToGalleryButton> createState() => SaveToGalleryButtonState();
@ -40,7 +44,9 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
? Theme.of(context).colorScheme.outline ? Theme.of(context).colorScheme.outline
: Theme.of(context).colorScheme.primary, : Theme.of(context).colorScheme.primary,
), ),
onPressed: () async { onPressed: (widget.isLoading)
? null
: () async {
setState(() { setState(() {
_imageSaving = true; _imageSaving = true;
}); });
@ -56,18 +62,25 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
List<int>.generate(32, (i) => random.nextInt(256))); List<int>.generate(32, (i) => random.nextInt(256)));
memoryPath = join(memoryPath, token); memoryPath = join(memoryPath, token);
} }
final user = await getUser();
if (user != null && (user.storeMediaFilesInGallery ?? true)) {}
bool storeToGallery = user?.storeMediaFilesInGallery ?? true;
if (widget.videoFilePath != null) { if (widget.videoFilePath != null) {
memoryPath += ".mp4"; memoryPath += ".mp4";
await File(widget.videoFilePath!.path).copy(memoryPath); await File(widget.videoFilePath!.path).copy(memoryPath);
if (storeToGallery) {
res = await saveVideoToGallery(widget.videoFilePath!.path); res = await saveVideoToGallery(widget.videoFilePath!.path);
}
} else { } else {
memoryPath += ".png"; memoryPath += ".png";
Uint8List? imageBytes = await widget.getMergedImage(); Uint8List? imageBytes = await widget.getMergedImage();
if (imageBytes == null || !mounted) return; if (imageBytes == null || !mounted) return;
await File(memoryPath).writeAsBytes(imageBytes); await File(memoryPath).writeAsBytes(imageBytes);
if (storeToGallery) {
res = await saveImageToGallery(imageBytes); res = await saveImageToGallery(imageBytes);
} }
}
if (res == null) { if (res == null) {
setState(() { setState(() {
_imageSaved = true; _imageSaved = true;
@ -86,7 +99,7 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
}, },
child: Row( child: Row(
children: [ children: [
_imageSaving (_imageSaving || widget.isLoading)
? SizedBox( ? SizedBox(
width: 12, width: 12,
height: 12, height: 12,

View file

@ -539,7 +539,7 @@ class _ShareImageEditorView extends State<ShareImageEditorView> {
mediaUploadId: mediaUploadId, mediaUploadId: mediaUploadId,
videoFilePath: widget.videoFilePath, videoFilePath: widget.videoFilePath,
sendNextMediaToUserName: sendNextMediaToUserName, sendNextMediaToUserName: sendNextMediaToUserName,
), isLoading: sendingOrLoadingImage),
if (sendNextMediaToUserName != null) SizedBox(width: 10), if (sendNextMediaToUserName != null) SizedBox(width: 10),
if (sendNextMediaToUserName != null) if (sendNextMediaToUserName != null)
OutlinedButton( OutlinedButton(

View file

@ -277,7 +277,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
}); });
} }
startTimer() { void startTimer() {
nextMediaTimer?.cancel(); nextMediaTimer?.cancel();
progressTimer?.cancel(); progressTimer?.cancel();
nextMediaTimer = Timer(canBeSeenUntil!.difference(DateTime.now()), () { nextMediaTimer = Timer(canBeSeenUntil!.difference(DateTime.now()), () {
@ -323,7 +323,6 @@ class _MediaViewerViewState extends State<MediaViewerView> {
imageSaved = true; imageSaved = true;
}); });
final user = await getUser(); final user = await getUser();
if (user != null && (user.storeMediaFilesInGallery ?? true)) { if (user != null && (user.storeMediaFilesInGallery ?? true)) {
if (videoPath != null) { if (videoPath != null) {
await saveVideoToGallery(videoPath!); await saveVideoToGallery(videoPath!);