mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-11 00:07:59 -06:00
feat: Add setting to always upload scans as pdf
This commit is contained in:
@@ -1,70 +1,60 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart' as cm;
|
||||
import 'package:paperless_mobile/core/service/file_service.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
import 'package:paperless_mobile/helpers/format_helpers.dart';
|
||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ClearCacheSetting extends StatelessWidget {
|
||||
class ClearCacheSetting extends StatefulWidget {
|
||||
const ClearCacheSetting({super.key});
|
||||
|
||||
@override
|
||||
State<ClearCacheSetting> createState() => _ClearCacheSettingState();
|
||||
}
|
||||
|
||||
class _ClearCacheSettingState extends State<ClearCacheSetting> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: const Text("Clear downloaded files"), //TODO: INTL
|
||||
subtitle: const Text(
|
||||
"Deletes all files downloaded from this app."), //TODO: INTL
|
||||
title: Text(S.of(context)!.clearCache),
|
||||
subtitle: FutureBuilder<String>(
|
||||
future: FileService.temporaryDirectory.then(_dirSize),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return Text(S.of(context)!.calculatingDots);
|
||||
}
|
||||
return Text(S.of(context)!.freeBytes(snapshot.data!));
|
||||
},
|
||||
),
|
||||
onTap: () async {
|
||||
final dir = await FileService.downloadsDirectory;
|
||||
final deletedSize = _dirSize(dir);
|
||||
final dir = await FileService.temporaryDirectory;
|
||||
final deletedSize = await _dirSize(dir);
|
||||
await dir.delete(recursive: true);
|
||||
// await context.read<cm.CacheManager>().emptyCache();
|
||||
showSnackBar(
|
||||
context,
|
||||
"Downloads successfully cleared, removed $deletedSize.",
|
||||
S.of(context)!.freedDiskSpace(deletedSize),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ClearDownloadsSetting extends StatelessWidget {
|
||||
const ClearDownloadsSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListTile(
|
||||
title: const Text("Clear downloads"), //TODO: INTL
|
||||
subtitle: const Text(
|
||||
"Remove downloaded files, scans and clear the cache's content"), //TODO: INTL
|
||||
onTap: () {
|
||||
FileService.documentsDirectory;
|
||||
FileService.downloadsDirectory;
|
||||
context.read<cm.CacheManager>().emptyCache();
|
||||
FileService.clearUserData();
|
||||
//TODO: Show notification about clearing (include size?)
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _dirSize(Directory dir) {
|
||||
Future<String> _dirSize(Directory dir) async {
|
||||
int totalSize = 0;
|
||||
try {
|
||||
if (dir.existsSync()) {
|
||||
if (await dir.exists()) {
|
||||
dir
|
||||
.listSync(recursive: true, followLinks: false)
|
||||
.forEach((FileSystemEntity entity) {
|
||||
.forEach((FileSystemEntity entity) async {
|
||||
if (entity is File) {
|
||||
totalSize += entity.lengthSync();
|
||||
totalSize += (await entity.length());
|
||||
}
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
} catch (error) {
|
||||
debugPrint(error.toString());
|
||||
}
|
||||
|
||||
return formatBytes(totalSize, 2);
|
||||
return formatBytes(totalSize, 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/global_settings_builder.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
class EnforcePdfUploadSetting extends StatelessWidget {
|
||||
const EnforcePdfUploadSetting({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GlobalSettingsBuilder(builder: (context, settings) {
|
||||
return SwitchListTile(
|
||||
title: Text(S.of(context)!.uploadScansAsPdf),
|
||||
subtitle: Text(S.of(context)!.convertSinglePageScanToPdf),
|
||||
value: settings.enforceSinglePagePdfUpload,
|
||||
onChanged: (value) {
|
||||
settings.enforceSinglePagePdfUpload = value;
|
||||
settings.save();
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class ThemeModeSetting extends StatelessWidget {
|
||||
return GlobalSettingsBuilder(
|
||||
builder: (context, settings) {
|
||||
return ListTile(
|
||||
title: Text(S.of(context)!.appearance),
|
||||
title: Text(S.of(context)!.theme),
|
||||
subtitle: Text(_mapThemeModeToLocalizedString(
|
||||
settings.preferredThemeMode, context)),
|
||||
onTap: () => showDialog<ThemeMode>(
|
||||
|
||||
Reference in New Issue
Block a user