mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 09:28:41 +00:00
fix #298
This commit is contained in:
parent
85d755e46b
commit
5946420fd0
4 changed files with 31 additions and 33 deletions
|
|
@ -231,15 +231,14 @@ class MediaFileService {
|
|||
),
|
||||
);
|
||||
|
||||
if (originalPath.existsSync()) {
|
||||
await originalPath.copy(tempPath.path);
|
||||
if (originalPath.existsSync() && !tempPath.existsSync()) {
|
||||
await compressMedia();
|
||||
}
|
||||
if (tempPath.existsSync()) {
|
||||
await tempPath.copy(storedPath.path);
|
||||
} else {
|
||||
Log.error(
|
||||
'Could not store image neither tempPath nor originalPath exists.',
|
||||
'Could not store image neither as tempPath does not exists.',
|
||||
);
|
||||
}
|
||||
unawaited(createThumbnail());
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ Future<String?> saveImageToGallery(Uint8List imageBytes) async {
|
|||
await Gal.putImageBytes(jpgImages);
|
||||
return null;
|
||||
} on GalException catch (e) {
|
||||
Log.error(e);
|
||||
return e.type.message;
|
||||
}
|
||||
}
|
||||
|
|
@ -52,6 +53,7 @@ Future<String?> saveVideoToGallery(String videoPath) async {
|
|||
await Gal.putVideo(videoPath);
|
||||
return null;
|
||||
} on GalException catch (e) {
|
||||
Log.error(e);
|
||||
return e.type.message;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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 {
|
||||
|
|
@ -54,22 +55,24 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
|
|||
|
||||
final storedMediaPath = widget.mediaService.storedPath;
|
||||
|
||||
final storeToGallery = gUser.storeMediaFilesInGallery;
|
||||
|
||||
await widget.mediaService.storeMediaFile();
|
||||
|
||||
if (storeToGallery) {
|
||||
if (gUser.storeMediaFilesInGallery) {
|
||||
if (widget.mediaService.mediaFile.type == MediaType.video) {
|
||||
res = await saveVideoToGallery(storedMediaPath.path);
|
||||
} else {
|
||||
res = await saveImageToGallery(
|
||||
storedMediaPath.readAsBytesSync(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await widget.mediaService.compressMedia();
|
||||
await widget.mediaService.createThumbnail();
|
||||
|
||||
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),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:twonly/globals.dart';
|
||||
import 'package:twonly/src/services/api/mediafiles/download.service.dart';
|
||||
import 'package:twonly/src/utils/misc.dart';
|
||||
import 'package:twonly/src/utils/storage.dart';
|
||||
|
|
@ -14,24 +15,6 @@ class DataAndStorageView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _DataAndStorageViewState extends State<DataAndStorageView> {
|
||||
Map<String, List<String>> autoDownloadOptions = defaultAutoDownloadOptions;
|
||||
bool storeMediaFilesInGallery = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
Future<void> initAsync() async {
|
||||
final user = await getUser();
|
||||
if (user == null) return;
|
||||
setState(() {
|
||||
autoDownloadOptions =
|
||||
user.autoDownloadOptions ?? defaultAutoDownloadOptions;
|
||||
storeMediaFilesInGallery = user.storeMediaFilesInGallery;
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> showAutoDownloadOptions(
|
||||
BuildContext context,
|
||||
ConnectivityResult connectionMode,
|
||||
|
|
@ -41,10 +24,11 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
|||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AutoDownloadOptionsDialog(
|
||||
autoDownloadOptions: autoDownloadOptions,
|
||||
autoDownloadOptions:
|
||||
gUser.autoDownloadOptions ?? defaultAutoDownloadOptions,
|
||||
connectionMode: connectionMode,
|
||||
onUpdate: () async {
|
||||
await initAsync();
|
||||
setState(() {});
|
||||
},
|
||||
);
|
||||
},
|
||||
|
|
@ -53,14 +37,16 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
|||
|
||||
Future<void> toggleStoreInGallery() async {
|
||||
await updateUserdata((u) {
|
||||
u.storeMediaFilesInGallery = !storeMediaFilesInGallery;
|
||||
u.storeMediaFilesInGallery = !u.storeMediaFilesInGallery;
|
||||
return u;
|
||||
});
|
||||
await initAsync();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final autoDownloadOptions =
|
||||
gUser.autoDownloadOptions ?? defaultAutoDownloadOptions;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(context.lang.settingsStorageData),
|
||||
|
|
@ -72,7 +58,7 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
|||
subtitle: Text(context.lang.settingsStorageDataStoreInGSubtitle),
|
||||
onTap: toggleStoreInGallery,
|
||||
trailing: Switch(
|
||||
value: storeMediaFilesInGallery,
|
||||
value: gUser.storeMediaFilesInGallery,
|
||||
onChanged: (a) => toggleStoreInGallery(),
|
||||
),
|
||||
),
|
||||
|
|
@ -157,6 +143,14 @@ class _AutoDownloadOptionsDialogState extends State<AutoDownloadOptionsDialog> {
|
|||
await _updateAutoDownloadSetting(DownloadMediaTypes.video, value);
|
||||
},
|
||||
),
|
||||
CheckboxListTile(
|
||||
title: const Text('Audio'),
|
||||
value: autoDownloadOptions[widget.connectionMode.name]!
|
||||
.contains(DownloadMediaTypes.audio.name),
|
||||
onChanged: (bool? value) async {
|
||||
await _updateAutoDownloadSetting(DownloadMediaTypes.audio, value);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
|
|
|
|||
Loading…
Reference in a new issue