fix: Fix download and share

This commit is contained in:
Anton Stubenbord
2023-03-07 00:23:23 +01:00
parent 6188e18299
commit c7da398c53
2 changed files with 29 additions and 12 deletions

View File

@@ -78,22 +78,27 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
Future<ResultType> openDocumentInSystemViewer() async {
final cacheDir = await FileService.temporaryDirectory;
await FileService.clearDirectoryContent(PaperlessDirectoryType.temporary);
if (state.metaData == null) {
await loadMetaData();
}
final desc = FileDescription.fromPath(
state.metaData!.mediaFilename.replaceAll("/", " "));
await _api.downloadToFile(
state.document,
'${cacheDir.path}/${state.metaData!.mediaFilename}',
);
final fileName = "${desc.filename}.pdf";
final file = File("${cacheDir.path}/$fileName");
if (!file.existsSync()) {
file.createSync();
await _api.downloadToFile(
state.document,
file.path,
);
}
return OpenFilex.open(
'${cacheDir.path}/${state.metaData!.mediaFilename}',
file.path,
type: "application/pdf",
).then(
(value) => value.type,
);
).then((value) => value.type);
}
void replace(DocumentModel document) {
@@ -115,6 +120,18 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
state.metaData!.mediaFilename
.replaceAll("/", " "), // Flatten directory structure
);
if (!File(filePath).existsSync()) {
File(filePath).createSync();
} else {
return _notificationService.notifyFileDownload(
document: state.document,
filename: "${desc.filename}.${desc.extension}",
filePath: filePath,
finished: true,
locale: locale,
);
}
await _notificationService.notifyFileDownload(
document: state.document,
filename: "${desc.filename}.${desc.extension}",
@@ -122,6 +139,7 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
finished: false,
locale: locale,
);
await _api.downloadToFile(
state.document,
filePath,

View File

@@ -2,12 +2,10 @@ import 'dart:io';
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';
import 'package:paperless_mobile/helpers/message_helpers.dart';
@@ -61,10 +59,11 @@ class _DocumentDownloadButtonState extends State<DocumentDownloadButton> {
// Download was cancelled
return;
}
if (Platform.isAndroid && androidInfo!.version.sdkInt! < 30) {
if (Platform.isAndroid && androidInfo!.version.sdkInt! <= 29) {
final isGranted = await askForPermission(Permission.storage);
if (!isGranted) {
return;
//TODO: Tell user to grant permissions
}
}
setState(() => _isDownloadPending = true);