feat: Implement updated receive share logic

This commit is contained in:
Anton Stubenbord
2023-10-02 23:59:42 +02:00
parent 653344c9ee
commit 37ed8bbb04
47 changed files with 1695 additions and 730 deletions

View File

@@ -15,7 +15,6 @@ import 'package:paperless_mobile/features/settings/model/view_type.dart';
class HiveBoxes {
HiveBoxes._();
static const globalSettings = 'globalSettings';
static const authentication = 'authentication';
static const localUserCredentials = 'localUserCredentials';
static const localUserAccount = 'localUserAccount';
static const localUserAppState = 'localUserAppState';

View File

@@ -4,6 +4,11 @@ import 'dart:typed_data';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:paperless_mobile/core/config/hive/hive_config.dart';
import 'package:paperless_mobile/core/database/tables/global_settings.dart';
import 'package:paperless_mobile/core/database/tables/local_user_account.dart';
import 'package:paperless_mobile/core/database/tables/local_user_app_state.dart';
import 'package:paperless_mobile/core/database/tables/local_user_settings.dart';
///
/// Opens an encrypted box, calls [callback] with the now opened box, awaits
@@ -40,3 +45,16 @@ Future<Uint8List> _getEncryptedBoxKey() async {
final key = (await secureStorage.read(key: 'key'))!;
return base64Decode(key);
}
extension HiveBoxAccessors on HiveInterface {
Box<GlobalSettings> get settingsBox =>
box<GlobalSettings>(HiveBoxes.globalSettings);
Box<LocalUserAccount> get localUserAccountBox =>
box<LocalUserAccount>(HiveBoxes.localUserAccount);
Box<LocalUserAppState> get localUserAppStateBox =>
box<LocalUserAppState>(HiveBoxes.localUserAppState);
Box<LocalUserSettings> get localUserSettingsBox =>
box<LocalUserSettings>(HiveBoxes.localUserSettings);
Box<GlobalSettings> get globalSettingsBox =>
box<GlobalSettings>(HiveBoxes.globalSettings);
}

View File

@@ -32,6 +32,9 @@ class GlobalSettings with HiveObjectMixin {
@HiveField(7, defaultValue: false)
bool enforceSinglePagePdfUpload;
@HiveField(8, defaultValue: false)
bool skipDocumentPreprarationOnUpload;
GlobalSettings({
required this.preferredLocaleSubtag,
this.preferredThemeMode = ThemeMode.system,
@@ -41,5 +44,6 @@ class GlobalSettings with HiveObjectMixin {
this.defaultDownloadType = FileDownloadType.alwaysAsk,
this.defaultShareType = FileDownloadType.alwaysAsk,
this.enforceSinglePagePdfUpload = false,
this.skipDocumentPreprarationOnUpload = false,
});
}

View File

@@ -1 +1,8 @@
const supportedFileExtensions = ['pdf', 'png', 'tiff', 'gif', 'jpg', 'jpeg'];
const supportedFileExtensions = [
'.pdf',
'.png',
'.tiff',
'.gif',
'.jpg',
'.jpeg'
];

View File

@@ -3,9 +3,12 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:path_provider/path_provider.dart';
import 'package:rxdart/rxdart.dart';
import 'package:uuid/uuid.dart';
class FileService {
const FileService._();
static Future<File> saveToFile(
Uint8List bytes,
String filename,
@@ -19,16 +22,13 @@ class FileService {
}
static Future<Directory?> getDirectory(PaperlessDirectoryType type) {
switch (type) {
case PaperlessDirectoryType.documents:
return documentsDirectory;
case PaperlessDirectoryType.temporary:
return temporaryDirectory;
case PaperlessDirectoryType.scans:
return temporaryScansDirectory;
case PaperlessDirectoryType.download:
return downloadsDirectory;
}
return switch (type) {
PaperlessDirectoryType.documents => documentsDirectory,
PaperlessDirectoryType.temporary => temporaryDirectory,
PaperlessDirectoryType.scans => temporaryScansDirectory,
PaperlessDirectoryType.download => downloadsDirectory,
PaperlessDirectoryType.upload => uploadDirectory,
};
}
static Future<File> allocateTemporaryFile(
@@ -50,8 +50,8 @@ class FileService {
))!
.first;
} else if (Platform.isIOS) {
final appDir = await getApplicationDocumentsDirectory();
final dir = Directory('${appDir.path}/documents');
final dir = await getApplicationDocumentsDirectory()
.then((dir) => Directory('${dir.path}/documents'));
return dir.create(recursive: true);
} else {
throw UnsupportedError("Platform not supported.");
@@ -77,17 +77,32 @@ class FileService {
}
}
static Future<Directory> get uploadDirectory async {
final dir = await getApplicationDocumentsDirectory()
.then((dir) => Directory('${dir.path}/upload'));
return dir.create(recursive: true);
}
static Future<Directory> getConsumptionDirectory(
{required String userId}) async {
final uploadDir =
await uploadDirectory.then((dir) => Directory('${dir.path}/$userId'));
return uploadDir.create(recursive: true);
}
static Future<Directory> get temporaryScansDirectory async {
final tempDir = await temporaryDirectory;
final scansDir = Directory('${tempDir.path}/scans');
return scansDir.create(recursive: true);
}
static Future<void> clearUserData() async {
static Future<void> clearUserData({required String userId}) async {
final scanDir = await temporaryScansDirectory;
final tempDir = await temporaryDirectory;
final consumptionDir = await getConsumptionDirectory(userId: userId);
await scanDir.delete(recursive: true);
await tempDir.delete(recursive: true);
await consumptionDir.delete(recursive: true);
}
static Future<void> clearDirectoryContent(PaperlessDirectoryType type) async {
@@ -101,11 +116,20 @@ class FileService {
dir.listSync().map((item) => item.delete(recursive: true)),
);
}
static Future<List<File>> getAllFiles(Directory directory) {
return directory.list().whereType<File>().toList();
}
static Future<List<Directory>> getAllSubdirectories(Directory directory) {
return directory.list().whereType<Directory>().toList();
}
}
enum PaperlessDirectoryType {
documents,
temporary,
scans,
download;
download,
upload;
}

View File

@@ -0,0 +1,35 @@
import 'dart:async';
import 'package:flutter/material.dart';
class FutureOrBuilder<T> extends StatelessWidget {
final FutureOr<T>? futureOrValue;
final T? initialData;
final AsyncWidgetBuilder<T> builder;
const FutureOrBuilder({
super.key,
FutureOr<T>? future,
this.initialData,
required this.builder,
}) : futureOrValue = future;
@override
Widget build(BuildContext context) {
final futureOrValue = this.futureOrValue;
if (futureOrValue is T) {
return builder(
context,
AsyncSnapshot.withData(ConnectionState.done, futureOrValue),
);
} else {
return FutureBuilder(
future: futureOrValue,
initialData: initialData,
builder: builder,
);
}
}
}