mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 14:07:49 -06:00
fix: Fix download and share
This commit is contained in:
@@ -78,22 +78,27 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
|||||||
|
|
||||||
Future<ResultType> openDocumentInSystemViewer() async {
|
Future<ResultType> openDocumentInSystemViewer() async {
|
||||||
final cacheDir = await FileService.temporaryDirectory;
|
final cacheDir = await FileService.temporaryDirectory;
|
||||||
|
await FileService.clearDirectoryContent(PaperlessDirectoryType.temporary);
|
||||||
if (state.metaData == null) {
|
if (state.metaData == null) {
|
||||||
await loadMetaData();
|
await loadMetaData();
|
||||||
}
|
}
|
||||||
|
final desc = FileDescription.fromPath(
|
||||||
|
state.metaData!.mediaFilename.replaceAll("/", " "));
|
||||||
|
|
||||||
await _api.downloadToFile(
|
final fileName = "${desc.filename}.pdf";
|
||||||
state.document,
|
final file = File("${cacheDir.path}/$fileName");
|
||||||
'${cacheDir.path}/${state.metaData!.mediaFilename}',
|
|
||||||
);
|
|
||||||
|
|
||||||
|
if (!file.existsSync()) {
|
||||||
|
file.createSync();
|
||||||
|
await _api.downloadToFile(
|
||||||
|
state.document,
|
||||||
|
file.path,
|
||||||
|
);
|
||||||
|
}
|
||||||
return OpenFilex.open(
|
return OpenFilex.open(
|
||||||
'${cacheDir.path}/${state.metaData!.mediaFilename}',
|
file.path,
|
||||||
type: "application/pdf",
|
type: "application/pdf",
|
||||||
).then(
|
).then((value) => value.type);
|
||||||
(value) => value.type,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void replace(DocumentModel document) {
|
void replace(DocumentModel document) {
|
||||||
@@ -115,6 +120,18 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
|||||||
state.metaData!.mediaFilename
|
state.metaData!.mediaFilename
|
||||||
.replaceAll("/", " "), // Flatten directory structure
|
.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(
|
await _notificationService.notifyFileDownload(
|
||||||
document: state.document,
|
document: state.document,
|
||||||
filename: "${desc.filename}.${desc.extension}",
|
filename: "${desc.filename}.${desc.extension}",
|
||||||
@@ -122,6 +139,7 @@ class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
|||||||
finished: false,
|
finished: false,
|
||||||
locale: locale,
|
locale: locale,
|
||||||
);
|
);
|
||||||
|
|
||||||
await _api.downloadToFile(
|
await _api.downloadToFile(
|
||||||
state.document,
|
state.document,
|
||||||
filePath,
|
filePath,
|
||||||
|
|||||||
@@ -2,12 +2,10 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:paperless_api/paperless_api.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/extensions/flutter_extensions.dart';
|
||||||
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.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/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/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/generated/l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
import 'package:paperless_mobile/helpers/message_helpers.dart';
|
||||||
@@ -61,10 +59,11 @@ class _DocumentDownloadButtonState extends State<DocumentDownloadButton> {
|
|||||||
// Download was cancelled
|
// Download was cancelled
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Platform.isAndroid && androidInfo!.version.sdkInt! < 30) {
|
if (Platform.isAndroid && androidInfo!.version.sdkInt! <= 29) {
|
||||||
final isGranted = await askForPermission(Permission.storage);
|
final isGranted = await askForPermission(Permission.storage);
|
||||||
if (!isGranted) {
|
if (!isGranted) {
|
||||||
return;
|
return;
|
||||||
|
//TODO: Tell user to grant permissions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setState(() => _isDownloadPending = true);
|
setState(() => _isDownloadPending = true);
|
||||||
|
|||||||
Reference in New Issue
Block a user