mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 02:07:57 -06:00
feat: Improve notifications, add donation button, improved asn form field
This commit is contained in:
@@ -4,6 +4,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/service/file_service.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/features/document_details/view/dialogs/select_file_type_dialog.dart';
|
||||
import 'package:paperless_mobile/features/settings/cubit/application_settings_cubit.dart';
|
||||
import 'package:paperless_mobile/features/settings/view/widgets/radio_settings_dialog.dart';
|
||||
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
|
||||
|
||||
@@ -34,6 +37,7 @@ class _DocumentDownloadButtonState extends State<DocumentDownloadButton> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IconButton(
|
||||
tooltip: S.of(context)!.downloadDocumentTooltip,
|
||||
icon: _isDownloadPending
|
||||
? const SizedBox(
|
||||
child: CircularProgressIndicator(),
|
||||
@@ -48,25 +52,10 @@ class _DocumentDownloadButtonState extends State<DocumentDownloadButton> {
|
||||
}
|
||||
|
||||
Future<void> _onDownload(DocumentModel document) async {
|
||||
final api = context.read<PaperlessDocumentsApi>();
|
||||
final meta = await widget.metaData;
|
||||
try {
|
||||
final downloadOriginal = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => RadioSettingsDialog(
|
||||
titleText: S.of(context)!.chooseFiletype,
|
||||
options: [
|
||||
RadioOption(
|
||||
value: true,
|
||||
label: S.of(context)!.original +
|
||||
" (${meta.originalMimeType.split("/").last})"),
|
||||
RadioOption(
|
||||
value: false,
|
||||
label: S.of(context)!.archivedPdf,
|
||||
),
|
||||
],
|
||||
initialValue: false,
|
||||
),
|
||||
builder: (context) => const SelectFileTypeDialog(),
|
||||
);
|
||||
if (downloadOriginal == null) {
|
||||
// Download was cancelled
|
||||
@@ -79,20 +68,14 @@ class _DocumentDownloadButtonState extends State<DocumentDownloadButton> {
|
||||
}
|
||||
}
|
||||
setState(() => _isDownloadPending = true);
|
||||
final bytes = await api.download(
|
||||
document,
|
||||
original: downloadOriginal,
|
||||
);
|
||||
final Directory dir = await FileService.downloadsDirectory;
|
||||
final fileExtension =
|
||||
downloadOriginal ? meta.mediaFilename.split(".").last : 'pdf';
|
||||
String filePath = "${dir.path}/${meta.mediaFilename}".split(".").first;
|
||||
filePath += ".$fileExtension";
|
||||
final createdFile = File(filePath);
|
||||
createdFile.createSync(recursive: true);
|
||||
createdFile.writeAsBytesSync(bytes);
|
||||
debugPrint("Downloaded file to $filePath");
|
||||
showSnackBar(context, S.of(context)!.documentSuccessfullyDownloaded);
|
||||
await context.read<DocumentDetailsCubit>().downloadDocument(
|
||||
downloadOriginal: downloadOriginal,
|
||||
locale: context
|
||||
.read<ApplicationSettingsCubit>()
|
||||
.state
|
||||
.preferredLocaleSubtag,
|
||||
);
|
||||
// showSnackBar(context, S.of(context)!.documentSuccessfullyDownloaded);
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user