Merge pull request #210 from astubenbord/feature/enforce-pdf-upload

feat: Add setting to always upload scans as pdf
This commit is contained in:
Anton Stubenbord
2023-06-15 17:10:40 +02:00
committed by GitHub
17 changed files with 360 additions and 157 deletions

View File

@@ -29,6 +29,9 @@ class GlobalSettings with HiveObjectMixin {
@HiveField(6)
FileDownloadType defaultShareType;
@HiveField(7, defaultValue: false)
bool enforceSinglePagePdfUpload;
GlobalSettings({
required this.preferredLocaleSubtag,
this.preferredThemeMode = ThemeMode.system,
@@ -37,5 +40,6 @@ class GlobalSettings with HiveObjectMixin {
this.currentLoggedInUser,
this.defaultDownloadType = FileDownloadType.alwaysAsk,
this.defaultShareType = FileDownloadType.alwaysAsk,
this.enforceSinglePagePdfUpload = false,
});
}

View File

@@ -254,6 +254,9 @@ class _ScannerPageState extends State<ScannerPage>
void _onPrepareDocumentUpload(BuildContext context) async {
final file = await _assembleFileBytes(
context.read<DocumentScannerCubit>().state,
forcePdf: Hive.box<GlobalSettings>(HiveBoxes.globalSettings)
.getValue()!
.enforceSinglePagePdfUpload,
);
final uploadResult = await pushDocumentUploadPreparationPage(
context,

View File

@@ -1,36 +0,0 @@
import 'package:flutter/material.dart';
import 'package:paperless_mobile/features/settings/view/widgets/color_scheme_option_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/default_download_file_type_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/default_share_file_type_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/language_selection_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/theme_mode_setting.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
class ApplicationSettingsPage extends StatelessWidget {
const ApplicationSettingsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context)!.applicationSettings),
actions: const [
Padding(
padding: EdgeInsets.all(16.0),
child: Icon(Icons.public),
)
],
),
body: ListView(
children: const [
LanguageSelectionSetting(),
ThemeModeSetting(),
ColorSchemeOptionSetting(),
Divider(),
DefaultDownloadFileTypeSetting(),
DefaultShareFileTypeSetting(),
],
),
);
}
}

View File

@@ -1,27 +0,0 @@
import 'package:flutter/material.dart';
import 'package:paperless_mobile/features/settings/view/widgets/biometric_authentication_setting.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
class SecuritySettingsPage extends StatelessWidget {
const SecuritySettingsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context)!.security),
actions: const [
Padding(
padding: EdgeInsets.all(16.0),
child: Icon(Icons.person_outline),
)
],
),
body: ListView(
children: const [
BiometricAuthenticationSetting(),
],
),
);
}
}

View File

@@ -1,21 +0,0 @@
import 'package:flutter/material.dart';
import 'package:paperless_mobile/features/settings/view/widgets/clear_storage_settings.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
class StorageSettingsPage extends StatelessWidget {
const StorageSettingsPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(S.of(context)!.storage),
),
body: ListView(
children: const [
ClearCacheSetting(),
],
),
);
}
}

View File

@@ -1,7 +1,13 @@
import 'package:flutter/material.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/settings/view/pages/application_settings_page.dart';
import 'package:paperless_mobile/features/settings/view/pages/security_settings_page.dart';
import 'package:paperless_mobile/features/settings/view/widgets/biometric_authentication_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/clear_storage_settings.dart';
import 'package:paperless_mobile/features/settings/view/widgets/color_scheme_option_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/default_download_file_type_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/default_share_file_type_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/enforce_pdf_upload_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/language_selection_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/theme_mode_setting.dart';
import 'package:paperless_mobile/features/settings/view/widgets/user_settings_builder.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:provider/provider.dart';
@@ -15,6 +21,22 @@ class SettingsPage extends StatelessWidget {
appBar: AppBar(
title: Text(S.of(context)!.settings),
),
body: ListView(
children: [
_buildSectionHeader(context, S.of(context)!.appearance),
const LanguageSelectionSetting(),
const ThemeModeSetting(),
const ColorSchemeOptionSetting(),
_buildSectionHeader(context, S.of(context)!.security),
const BiometricAuthenticationSetting(),
_buildSectionHeader(context, S.of(context)!.behavior),
const DefaultDownloadFileTypeSetting(),
const DefaultShareFileTypeSetting(),
const EnforcePdfUploadSetting(),
_buildSectionHeader(context, S.of(context)!.storage),
const ClearCacheSetting(),
],
),
bottomNavigationBar: UserAccountBuilder(
builder: (context, user) {
assert(user != null);
@@ -63,28 +85,18 @@ class SettingsPage extends StatelessWidget {
);
},
),
body: ListView(
children: [
ListTile(
// leading: const Icon(Icons.style_outlined),
title: Text(S.of(context)!.applicationSettings),
subtitle: Text(S.of(context)!.languageAndVisualAppearance),
onTap: () => _goto(const ApplicationSettingsPage(), context),
),
ListTile(
// leading: const Icon(Icons.security_outlined),
title: Text(S.of(context)!.security),
subtitle: Text(S.of(context)!.biometricAuthentication),
onTap: () => _goto(const SecuritySettingsPage(), context),
),
// ListTile(
// // leading: const Icon(Icons.storage_outlined),
// title: Text(S.of(context)!.storage),
// subtitle:
// Text(S.of(context)!.mangeFilesAndStorageSpace),
// onTap: () => _goto(const StorageSettingsPage(), context),
// ),
],
);
}
Widget _buildSectionHeader(BuildContext context, String text) {
return Padding(
padding: const EdgeInsets.only(left: 16, top: 16),
child: Text(
text,
style: Theme.of(context)
.textTheme
.labelLarge
?.copyWith(color: Theme.of(context).colorScheme.primary),
),
);
}

View File

@@ -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);
}

View File

@@ -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();
},
);
});
}
}

View File

@@ -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>(

View File

@@ -816,13 +816,45 @@
"@export": {
"description": "Label for button that exports scanned images to pdf (before upload)"
},
"invalidFilenameCharacter": "Invalid character(s) found in filename: {characters}",
"invalidFilenameCharacter": "Caràcter(s) invàlids trobats a nom d'arxiu: {characters}",
"@invalidFilenameCharacter": {
"description": "For validating filename in export dialogue"
},
"exportScansToPdf": "Export scans to PDF",
"exportScansToPdf": "Exporta escanejos a PDF",
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "Els escanejos s'uniran en un únic document PDF.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -47,7 +47,7 @@
"@authenticateOnAppStart": {
"description": "Description of the biometric authentication settings tile"
},
"biometricAuthentication": "Biometrische Authentifizierung aktivieren",
"biometricAuthentication": "Biometrische Authentifizierung",
"@biometricAuthentication": {},
"authenticateToToggleBiometricAuthentication": "{mode, select, enable{Authentifizieren, um die biometrische Authentifizierung zu aktivieren} disable{Authentifizieren, um die biometrische Authentifizierung zu deaktivieren} other{}}",
"@authenticateToToggleBiometricAuthentication": {
@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "Alle Scans werden in eine einzige PDF-Datei zusammengeführt."
"allScansWillBeMerged": "Alle Scans werden in eine einzige PDF-Datei zusammengeführt.",
"behavior": "Verhalten",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Erscheinungsbild",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Cache leeren",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "{bytes} freigeben",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Berechne...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "{bytes} erfolgreich freigegeben.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Scans als PDF hochladen",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Einseitige Scans vor dem Hochladen immer in PDF umwandeln",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}

View File

@@ -824,5 +824,37 @@
"@exportScansToPdf": {
"description": "title of the alert dialog when exporting scans to pdf"
},
"allScansWillBeMerged": "All scans will be merged into a single PDF file."
"allScansWillBeMerged": "All scans will be merged into a single PDF file.",
"behavior": "Behavior",
"@behavior": {
"description": "Title of the settings concerning app beahvior"
},
"theme": "Theme",
"@theme": {
"description": "Title of the theme mode setting"
},
"clearCache": "Clear cache",
"@clearCache": {
"description": "Title of the clear cache setting"
},
"freeBytes": "Free {bytes}",
"@freeBytes": {
"description": "Text shown for clear storage settings"
},
"calculatingDots": "Calculating...",
"@calculatingDots": {
"description": "Text shown when the byte size is still being calculated"
},
"freedDiskSpace": "Successfully freed {bytes} of disk space.",
"@freedDiskSpace": {
"description": "Message shown after clearing storage"
},
"uploadScansAsPdf": "Upload scans as PDF",
"@uploadScansAsPdf": {
"description": "Title of the setting which toggles whether scans are always uploaded as pdf"
},
"convertSinglePageScanToPdf": "Always convert single page scans to PDF before uploading",
"@convertSinglePageScanToPdf": {
"description": "description of the upload scans as pdf setting"
}
}