mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 14:07:49 -06:00
Externalized API and models as own package
This commit is contained in:
@@ -1,29 +1,28 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/document.model.dart';
|
||||
import 'package:paperless_mobile/features/documents/repository/document_repository.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
|
||||
part 'document_details_state.dart';
|
||||
|
||||
class DocumentDetailsCubit extends Cubit<DocumentDetailsState> {
|
||||
final DocumentRepository _documentRepository;
|
||||
final PaperlessDocumentsApi _api;
|
||||
|
||||
DocumentDetailsCubit(this._documentRepository, DocumentModel initialDocument)
|
||||
DocumentDetailsCubit(this._api, DocumentModel initialDocument)
|
||||
: super(DocumentDetailsState(document: initialDocument));
|
||||
|
||||
Future<void> delete(DocumentModel document) async {
|
||||
await _documentRepository.delete(document);
|
||||
await _api.delete(document);
|
||||
emit(const DocumentDetailsState());
|
||||
}
|
||||
|
||||
Future<void> update(DocumentModel document) async {
|
||||
final updatedDocument = await _documentRepository.update(document);
|
||||
final updatedDocument = await _api.update(document);
|
||||
emit(DocumentDetailsState(document: updatedDocument));
|
||||
}
|
||||
|
||||
Future<void> assignAsn(DocumentModel document) async {
|
||||
if (document.archiveSerialNumber == null) {
|
||||
final int asn = await _documentRepository.findNextAsn();
|
||||
final int asn = await _api.findNextAsn();
|
||||
update(document.copyWith(archiveSerialNumber: asn));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,14 +7,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/date_symbol_data_local.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/widgets/highlighted_text.dart';
|
||||
import 'package:paperless_mobile/di_initializer.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/document_details/bloc/document_details_cubit.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/document.model.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/document_meta_data.model.dart';
|
||||
import 'package:paperless_mobile/features/documents/repository/document_repository.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/pages/document_edit_page.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/pages/document_view.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/delete_document_confirmation_dialog.dart';
|
||||
@@ -235,7 +232,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
|
||||
Widget _buildDocumentMetaDataView(DocumentModel document) {
|
||||
return FutureBuilder<DocumentMetaData>(
|
||||
future: getIt<DocumentRepository>().getMetaData(document),
|
||||
future: getIt<PaperlessDocumentsApi>().getMetaData(document),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@@ -295,7 +292,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
Future<void> _assignAsn(DocumentModel document) async {
|
||||
try {
|
||||
await BlocProvider.of<DocumentDetailsCubit>(context).assignAsn(document);
|
||||
} on ErrorMessage catch (error, stackTrace) {
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
}
|
||||
@@ -414,7 +411,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
return;
|
||||
}
|
||||
setState(() => _isDownloadPending = true);
|
||||
getIt<DocumentRepository>().download(document).then((bytes) async {
|
||||
getIt<PaperlessDocumentsApi>().download(document).then((bytes) async {
|
||||
final Directory dir = (await getExternalStorageDirectories(
|
||||
type: StorageDirectory.downloads))!
|
||||
.first;
|
||||
@@ -431,7 +428,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
///
|
||||
Future<void> _onShare(DocumentModel document) async {
|
||||
Uint8List documentBytes =
|
||||
await getIt<DocumentRepository>().download(document);
|
||||
await getIt<PaperlessDocumentsApi>().download(document);
|
||||
final dir = await getTemporaryDirectory();
|
||||
final String path = "${dir.path}/${document.originalFileName}";
|
||||
await File(path).writeAsBytes(documentBytes);
|
||||
@@ -459,7 +456,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
try {
|
||||
await BlocProvider.of<DocumentDetailsCubit>(context).delete(document);
|
||||
showSnackBar(context, S.of(context).documentDeleteSuccessMessage);
|
||||
} on ErrorMessage catch (error, stackTrace) {
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
} finally {
|
||||
// Document deleted => go back to primary route
|
||||
@@ -472,7 +469,7 @@ class _DocumentDetailsPageState extends State<DocumentDetailsPage> {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DocumentView(
|
||||
documentBytes: getIt<DocumentRepository>().getPreview(document.id),
|
||||
documentBytes: getIt<PaperlessDocumentsApi>().getPreview(document.id),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user