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()) {
|
if (originalPath.existsSync() && !tempPath.existsSync()) {
|
||||||
await originalPath.copy(tempPath.path);
|
|
||||||
await compressMedia();
|
await compressMedia();
|
||||||
}
|
}
|
||||||
if (tempPath.existsSync()) {
|
if (tempPath.existsSync()) {
|
||||||
await tempPath.copy(storedPath.path);
|
await tempPath.copy(storedPath.path);
|
||||||
} else {
|
} else {
|
||||||
Log.error(
|
Log.error(
|
||||||
'Could not store image neither tempPath nor originalPath exists.',
|
'Could not store image neither as tempPath does not exists.',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
unawaited(createThumbnail());
|
unawaited(createThumbnail());
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ Future<String?> saveImageToGallery(Uint8List imageBytes) async {
|
||||||
await Gal.putImageBytes(jpgImages);
|
await Gal.putImageBytes(jpgImages);
|
||||||
return null;
|
return null;
|
||||||
} on GalException catch (e) {
|
} on GalException catch (e) {
|
||||||
|
Log.error(e);
|
||||||
return e.type.message;
|
return e.type.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -52,6 +53,7 @@ Future<String?> saveVideoToGallery(String videoPath) async {
|
||||||
await Gal.putVideo(videoPath);
|
await Gal.putVideo(videoPath);
|
||||||
return null;
|
return null;
|
||||||
} on GalException catch (e) {
|
} on GalException catch (e) {
|
||||||
|
Log.error(e);
|
||||||
return e.type.message;
|
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/globals.dart';
|
||||||
import 'package:twonly/src/database/tables/mediafiles.table.dart';
|
import 'package:twonly/src/database/tables/mediafiles.table.dart';
|
||||||
import 'package:twonly/src/services/mediafiles/mediafile.service.dart';
|
import 'package:twonly/src/services/mediafiles/mediafile.service.dart';
|
||||||
|
import 'package:twonly/src/utils/log.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
|
|
||||||
class SaveToGalleryButton extends StatefulWidget {
|
class SaveToGalleryButton extends StatefulWidget {
|
||||||
|
|
@ -54,22 +55,24 @@ class SaveToGalleryButtonState extends State<SaveToGalleryButton> {
|
||||||
|
|
||||||
final storedMediaPath = widget.mediaService.storedPath;
|
final storedMediaPath = widget.mediaService.storedPath;
|
||||||
|
|
||||||
final storeToGallery = gUser.storeMediaFilesInGallery;
|
|
||||||
|
|
||||||
await widget.mediaService.storeMediaFile();
|
await widget.mediaService.storeMediaFile();
|
||||||
|
|
||||||
if (storeToGallery) {
|
if (gUser.storeMediaFilesInGallery) {
|
||||||
res = await saveVideoToGallery(storedMediaPath.path);
|
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) {
|
if (res == null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_imageSaved = true;
|
_imageSaved = true;
|
||||||
});
|
});
|
||||||
} else if (mounted && context.mounted) {
|
} else if (mounted && context.mounted) {
|
||||||
|
Log.error('Could not store media file in the gallery.');
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(res),
|
content: Text(res),
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
|
|
||||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||||
import 'package:flutter/material.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/services/api/mediafiles/download.service.dart';
|
||||||
import 'package:twonly/src/utils/misc.dart';
|
import 'package:twonly/src/utils/misc.dart';
|
||||||
import 'package:twonly/src/utils/storage.dart';
|
import 'package:twonly/src/utils/storage.dart';
|
||||||
|
|
@ -14,24 +15,6 @@ class DataAndStorageView extends StatefulWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class _DataAndStorageViewState extends State<DataAndStorageView> {
|
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(
|
Future<void> showAutoDownloadOptions(
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
ConnectivityResult connectionMode,
|
ConnectivityResult connectionMode,
|
||||||
|
|
@ -41,10 +24,11 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return AutoDownloadOptionsDialog(
|
return AutoDownloadOptionsDialog(
|
||||||
autoDownloadOptions: autoDownloadOptions,
|
autoDownloadOptions:
|
||||||
|
gUser.autoDownloadOptions ?? defaultAutoDownloadOptions,
|
||||||
connectionMode: connectionMode,
|
connectionMode: connectionMode,
|
||||||
onUpdate: () async {
|
onUpdate: () async {
|
||||||
await initAsync();
|
setState(() {});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
@ -53,14 +37,16 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
||||||
|
|
||||||
Future<void> toggleStoreInGallery() async {
|
Future<void> toggleStoreInGallery() async {
|
||||||
await updateUserdata((u) {
|
await updateUserdata((u) {
|
||||||
u.storeMediaFilesInGallery = !storeMediaFilesInGallery;
|
u.storeMediaFilesInGallery = !u.storeMediaFilesInGallery;
|
||||||
return u;
|
return u;
|
||||||
});
|
});
|
||||||
await initAsync();
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final autoDownloadOptions =
|
||||||
|
gUser.autoDownloadOptions ?? defaultAutoDownloadOptions;
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(context.lang.settingsStorageData),
|
title: Text(context.lang.settingsStorageData),
|
||||||
|
|
@ -72,7 +58,7 @@ class _DataAndStorageViewState extends State<DataAndStorageView> {
|
||||||
subtitle: Text(context.lang.settingsStorageDataStoreInGSubtitle),
|
subtitle: Text(context.lang.settingsStorageDataStoreInGSubtitle),
|
||||||
onTap: toggleStoreInGallery,
|
onTap: toggleStoreInGallery,
|
||||||
trailing: Switch(
|
trailing: Switch(
|
||||||
value: storeMediaFilesInGallery,
|
value: gUser.storeMediaFilesInGallery,
|
||||||
onChanged: (a) => toggleStoreInGallery(),
|
onChanged: (a) => toggleStoreInGallery(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -157,6 +143,14 @@ class _AutoDownloadOptionsDialogState extends State<AutoDownloadOptionsDialog> {
|
||||||
await _updateAutoDownloadSetting(DownloadMediaTypes.video, value);
|
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: [
|
actions: [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue