mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-08 22:07:57 -06:00
fix: Add custom fields, translations, add app logs to login routes
This commit is contained in:
@@ -3,20 +3,24 @@ import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/bloc/loading_status.dart';
|
||||
import 'package:paperless_mobile/core/bloc/transient_error.dart';
|
||||
import 'package:paperless_mobile/features/logging/data/logger.dart';
|
||||
import 'package:paperless_mobile/core/model/info_message_exception.dart';
|
||||
import 'package:paperless_mobile/core/service/file_service.dart';
|
||||
import 'package:paperless_mobile/features/notifications/services/local_notification_service.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
part 'document_scanner_cubit.freezed.dart';
|
||||
part 'document_scanner_state.dart';
|
||||
|
||||
class DocumentScannerCubit extends Cubit<DocumentScannerState> {
|
||||
final LocalNotificationService _notificationService;
|
||||
|
||||
DocumentScannerCubit(this._notificationService)
|
||||
: super(const InitialDocumentScannerState());
|
||||
: super(const DocumentScannerState());
|
||||
|
||||
Future<void> initialize() async {
|
||||
logger.fd(
|
||||
@@ -24,7 +28,7 @@ class DocumentScannerCubit extends Cubit<DocumentScannerState> {
|
||||
className: runtimeType.toString(),
|
||||
methodName: "initialize",
|
||||
);
|
||||
emit(const RestoringDocumentScannerState());
|
||||
emit(const DocumentScannerState(status: LoadingStatus.loading));
|
||||
final tempDir = FileService.instance.temporaryScansDirectory;
|
||||
final allFiles = tempDir.list().whereType<File>();
|
||||
final scans =
|
||||
@@ -36,13 +40,14 @@ class DocumentScannerCubit extends Cubit<DocumentScannerState> {
|
||||
);
|
||||
emit(
|
||||
scans.isEmpty
|
||||
? const InitialDocumentScannerState()
|
||||
: LoadedDocumentScannerState(scans: scans),
|
||||
? const DocumentScannerState()
|
||||
: DocumentScannerState(scans: scans, status: LoadingStatus.loaded),
|
||||
);
|
||||
}
|
||||
|
||||
void addScan(File file) async {
|
||||
emit(LoadedDocumentScannerState(
|
||||
emit(DocumentScannerState(
|
||||
status: LoadingStatus.loaded,
|
||||
scans: [...state.scans, file],
|
||||
));
|
||||
}
|
||||
@@ -60,21 +65,22 @@ class DocumentScannerCubit extends Cubit<DocumentScannerState> {
|
||||
final scans = state.scans..remove(file);
|
||||
emit(
|
||||
scans.isEmpty
|
||||
? const InitialDocumentScannerState()
|
||||
: LoadedDocumentScannerState(scans: scans),
|
||||
? const DocumentScannerState()
|
||||
: DocumentScannerState(
|
||||
status: LoadingStatus.loaded,
|
||||
scans: scans,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> reset() async {
|
||||
try {
|
||||
Future.wait([
|
||||
for (final file in state.scans) file.delete(),
|
||||
]);
|
||||
Future.wait([for (final file in state.scans) file.delete()]);
|
||||
imageCache.clear();
|
||||
} catch (_) {
|
||||
throw const PaperlessApiException(ErrorCode.scanRemoveFailed);
|
||||
addError(TransientPaperlessApiError(code: ErrorCode.scanRemoveFailed));
|
||||
} finally {
|
||||
emit(const InitialDocumentScannerState());
|
||||
emit(const DocumentScannerState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +89,16 @@ class DocumentScannerCubit extends Cubit<DocumentScannerState> {
|
||||
String fileName,
|
||||
String locale,
|
||||
) async {
|
||||
var file = await FileService.instance.saveToFile(bytes, fileName);
|
||||
_notificationService.notifyFileSaved(
|
||||
filename: fileName,
|
||||
filePath: file.path,
|
||||
finished: true,
|
||||
locale: locale,
|
||||
);
|
||||
try {
|
||||
var file = await FileService.instance.saveToFile(bytes, fileName);
|
||||
_notificationService.notifyFileSaved(
|
||||
filename: fileName,
|
||||
filePath: file.path,
|
||||
finished: true,
|
||||
locale: locale,
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
addError(TransientMessageError(message: e.toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
part of 'document_scanner_cubit.dart';
|
||||
|
||||
sealed class DocumentScannerState {
|
||||
final List<File> scans;
|
||||
|
||||
const DocumentScannerState({
|
||||
this.scans = const [],
|
||||
});
|
||||
}
|
||||
|
||||
class InitialDocumentScannerState extends DocumentScannerState {
|
||||
const InitialDocumentScannerState();
|
||||
}
|
||||
|
||||
class RestoringDocumentScannerState extends DocumentScannerState {
|
||||
const RestoringDocumentScannerState({super.scans});
|
||||
}
|
||||
|
||||
class LoadedDocumentScannerState extends DocumentScannerState {
|
||||
const LoadedDocumentScannerState({super.scans});
|
||||
}
|
||||
|
||||
class ErrorDocumentScannerState extends DocumentScannerState {
|
||||
final String message;
|
||||
|
||||
const ErrorDocumentScannerState({
|
||||
required this.message,
|
||||
super.scans,
|
||||
});
|
||||
@freezed
|
||||
class DocumentScannerState with _$DocumentScannerState {
|
||||
const factory DocumentScannerState({
|
||||
@Default(LoadingStatus.initial) LoadingStatus status,
|
||||
@Default([]) List<File> scans,
|
||||
}) = _DocumentScannerState;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/constants.dart';
|
||||
import 'package:paperless_mobile/core/bloc/loading_status.dart';
|
||||
import 'package:paperless_mobile/core/database/hive/hive_config.dart';
|
||||
import 'package:paperless_mobile/core/database/tables/global_settings.dart';
|
||||
import 'package:paperless_mobile/core/global/constants.dart';
|
||||
@@ -78,13 +79,11 @@ class _ScannerPageState extends State<ScannerPage>
|
||||
],
|
||||
body: BlocBuilder<DocumentScannerCubit, DocumentScannerState>(
|
||||
builder: (context, state) {
|
||||
return switch (state) {
|
||||
InitialDocumentScannerState() => _buildEmptyState(),
|
||||
RestoringDocumentScannerState() => Center(
|
||||
child: Text("Restoring..."),
|
||||
),
|
||||
LoadedDocumentScannerState() => _buildImageGrid(state.scans),
|
||||
ErrorDocumentScannerState() => Placeholder(),
|
||||
return switch (state.status) {
|
||||
LoadingStatus.initial => _buildEmptyState(),
|
||||
LoadingStatus.loading => Center(child: Text("Restoring...")),
|
||||
LoadingStatus.loaded => _buildImageGrid(state.scans),
|
||||
LoadingStatus.error => Placeholder(),
|
||||
};
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user