chore: Cleanup project structure, add debug output to build.gradle

This commit is contained in:
Anton Stubenbord
2023-10-27 12:28:26 +02:00
parent d785edcca0
commit af4359c38d
46 changed files with 96 additions and 100 deletions

View File

@@ -0,0 +1,83 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/model/info_message_exception.dart';
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
import 'package:paperless_mobile/features/login/model/login_form_credentials.dart';
import 'package:paperless_mobile/features/login/view/add_account_page.dart';
import 'package:paperless_mobile/features/settings/view/dialogs/switch_account_dialog.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/helpers/message_helpers.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
part 'add_account_route.g.dart';
@TypedGoRoute<AddAccountRoute>(
path: '/add-account',
name: R.addAccount,
)
class AddAccountRoute extends GoRouteData {
const AddAccountRoute();
static final $parentNavigatorKey = rootNavigatorKey;
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: AddAccountPage(
titleText: S.of(context)!.addAccount,
onSubmit:
(context, username, password, serverUrl, clientCertificate) async {
try {
final userId = await context.read<AuthenticationCubit>().addAccount(
credentials: LoginFormCredentials(
username: username,
password: password,
),
clientCertificate: clientCertificate,
serverUrl: serverUrl,
enableBiometricAuthentication: false,
locale: Intl.getCurrentLocale(),
);
final shoudSwitch = await showDialog<bool>(
context: context,
builder: (context) => const SwitchAccountDialog(),
) ??
false;
if (shoudSwitch) {
await context.read<AuthenticationCubit>().switchAccount(userId);
} else {
while (context.canPop()) {
context.pop();
}
}
} on PaperlessApiException catch (error, stackTrace) {
showErrorMessage(context, error, stackTrace);
// context.pop();
} on PaperlessFormValidationException catch (exception, stackTrace) {
if (exception.hasUnspecificErrorMessage()) {
showLocalizedError(context, exception.unspecificErrorMessage()!);
// context.pop();
} else {
showGenericError(
context,
exception.validationMessages.values.first,
stackTrace,
); //TODO: Check if we can show error message directly on field here.
}
} on InfoMessageException catch (error) {
showInfoMessage(context, error);
// context.pop();
} catch (unknownError, stackTrace) {
showGenericError(context, unknownError.toString(), stackTrace);
// context.pop();
}
},
submitText: S.of(context)!.addAccount,
),
);
}
}

View File

@@ -0,0 +1,28 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/logging/cubit/app_logs_cubit.dart';
import 'package:paperless_mobile/features/logging/view/app_logs_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/theme.dart';
part 'app_logs_route.g.dart';
@TypedGoRoute<AppLogsRoute>(path: '/app-logs')
class AppLogsRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
@override
Widget build(BuildContext context, GoRouterState state) {
return AnnotatedRegion(
value: buildOverlayStyle(Theme.of(context)),
child: BlocProvider(
create: (context) => AppLogsCubit(
DateTime.now(),
context.read(),
)..loadLogs(DateTime.now()),
child: AppLogsPage(key: state.pageKey),
),
);
}
}

View File

@@ -0,0 +1,18 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/changelogs/view/changelog_dialog.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/utils/dialog_page.dart';
part 'changelog_route.g.dart';
@TypedGoRoute<ChangelogRoute>(path: '/changelogs')
class ChangelogRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return DialogPage(
builder: (context) => const ChangelogDialog(),
);
}
}

View File

@@ -0,0 +1,212 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/document_bulk_action/cubit/document_bulk_action_cubit.dart';
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart';
import 'package:paperless_mobile/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_tags_widget.dart';
import 'package:paperless_mobile/features/document_details/cubit/document_details_cubit.dart';
import 'package:paperless_mobile/features/document_details/view/pages/document_details_page.dart';
import 'package:paperless_mobile/features/document_edit/cubit/document_edit_cubit.dart';
import 'package:paperless_mobile/features/document_edit/view/document_edit_page.dart';
import 'package:paperless_mobile/features/documents/view/pages/document_view.dart';
import 'package:paperless_mobile/features/documents/view/pages/documents_page.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/theme.dart';
class DocumentsBranch extends StatefulShellBranchData {
static final GlobalKey<NavigatorState> $navigatorKey = documentsNavigatorKey;
const DocumentsBranch();
}
class DocumentsRoute extends GoRouteData {
@override
Widget build(BuildContext context, GoRouterState state) {
return const DocumentsPage();
}
}
class DocumentDetailsRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final int id;
final bool isLabelClickable;
final String? queryString;
final String? thumbnailUrl;
final String? title;
const DocumentDetailsRoute({
required this.id,
this.isLabelClickable = true,
this.queryString,
this.thumbnailUrl,
this.title,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return BlocProvider(
create: (_) => DocumentDetailsCubit(
context.read(),
context.read(),
context.read(),
context.read(),
id: id,
)..initialize(),
lazy: false,
child: DocumentDetailsPage(
id: id,
isLabelClickable: isLabelClickable,
titleAndContentQueryString: queryString,
thumbnailUrl: thumbnailUrl,
title: title,
),
);
}
}
class EditDocumentRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final DocumentModel $extra;
const EditDocumentRoute(this.$extra);
@override
Widget build(BuildContext context, GoRouterState state) {
final theme = Theme.of(context);
return AnnotatedRegion<SystemUiOverlayStyle>(
value: buildOverlayStyle(
theme,
systemNavigationBarColor: theme.colorScheme.background,
),
child: BlocProvider(
create: (context) => DocumentEditCubit(
context.read(),
context.read(),
context.read(),
document: $extra,
)..loadFieldSuggestions(),
child: const DocumentEditPage(),
),
);
}
}
class DocumentPreviewRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final int id;
final String? title;
const DocumentPreviewRoute({
required this.id,
this.title,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return DocumentView(
documentBytes: context.read<PaperlessDocumentsApi>().downloadDocument(id),
title: title,
);
}
}
class BulkEditExtraWrapper {
final List<DocumentModel> selection;
final LabelType type;
const BulkEditExtraWrapper(this.selection, this.type);
}
class BulkEditDocumentsRoute extends GoRouteData {
/// Selection
final BulkEditExtraWrapper $extra;
BulkEditDocumentsRoute(this.$extra);
@override
Widget build(BuildContext context, GoRouterState state) {
return BlocProvider(
create: (_) => DocumentBulkActionCubit(
context.read(),
context.read(),
context.read(),
selection: $extra.selection,
),
child: BlocBuilder<DocumentBulkActionCubit, DocumentBulkActionState>(
builder: (context, state) {
return switch ($extra.type) {
LabelType.tag => const FullscreenBulkEditTagsWidget(),
_ => FullscreenBulkEditLabelPage(
options: switch ($extra.type) {
LabelType.correspondent => state.correspondents,
LabelType.documentType => state.documentTypes,
LabelType.storagePath => state.storagePaths,
_ => throw Exception("Parameter not allowed here."),
},
selection: state.selection,
labelMapper: (document) {
return switch ($extra.type) {
LabelType.correspondent => document.correspondent,
LabelType.documentType => document.documentType,
LabelType.storagePath => document.storagePath,
_ => throw Exception("Parameter not allowed here."),
};
},
leadingIcon: switch ($extra.type) {
LabelType.correspondent => const Icon(Icons.person_outline),
LabelType.documentType =>
const Icon(Icons.description_outlined),
LabelType.storagePath => const Icon(Icons.folder_outlined),
_ => throw Exception("Parameter not allowed here."),
},
hintText: S.of(context)!.startTyping,
onSubmit: switch ($extra.type) {
LabelType.correspondent => context
.read<DocumentBulkActionCubit>()
.bulkModifyCorrespondent,
LabelType.documentType => context
.read<DocumentBulkActionCubit>()
.bulkModifyDocumentType,
LabelType.storagePath => context
.read<DocumentBulkActionCubit>()
.bulkModifyStoragePath,
_ => throw Exception("Parameter not allowed here."),
},
assignMessageBuilder: (int count, String name) {
return switch ($extra.type) {
LabelType.correspondent => S
.of(context)!
.bulkEditCorrespondentAssignMessage(name, count),
LabelType.documentType => S
.of(context)!
.bulkEditDocumentTypeAssignMessage(count, name),
LabelType.storagePath => S
.of(context)!
.bulkEditDocumentTypeAssignMessage(count, name),
_ => throw Exception("Parameter not allowed here."),
};
},
removeMessageBuilder: (int count) {
return switch ($extra.type) {
LabelType.correspondent =>
S.of(context)!.bulkEditCorrespondentRemoveMessage(count),
LabelType.documentType =>
S.of(context)!.bulkEditDocumentTypeRemoveMessage(count),
LabelType.storagePath =>
S.of(context)!.bulkEditStoragePathRemoveMessage(count),
_ => throw Exception("Parameter not allowed here."),
};
},
),
};
},
),
);
}
}

View File

@@ -0,0 +1,17 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/inbox/view/pages/inbox_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
class InboxBranch extends StatefulShellBranchData {
static final GlobalKey<NavigatorState> $navigatorKey = inboxNavigatorKey;
const InboxBranch();
}
class InboxRoute extends GoRouteData {
@override
Widget build(BuildContext context, GoRouterState state) {
return const InboxPage();
}
}

View File

@@ -0,0 +1,89 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/add_correspondent_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/add_document_type_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/add_storage_path_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/add_tag_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/edit_correspondent_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/edit_document_type_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/edit_storage_path_page.dart';
import 'package:paperless_mobile/features/edit_label/view/impl/edit_tag_page.dart';
import 'package:paperless_mobile/features/labels/view/pages/labels_page.dart';
import 'package:paperless_mobile/features/linked_documents/cubit/linked_documents_cubit.dart';
import 'package:paperless_mobile/features/linked_documents/view/linked_documents_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
class LabelsBranch extends StatefulShellBranchData {
static final GlobalKey<NavigatorState> $navigatorKey = labelsNavigatorKey;
const LabelsBranch();
}
class LabelsRoute extends GoRouteData {
@override
Widget build(BuildContext context, GoRouterState state) {
return const LabelsPage();
}
}
class EditLabelRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final Label $extra;
const EditLabelRoute(this.$extra);
@override
Widget build(BuildContext context, GoRouterState state) {
return switch ($extra) {
Correspondent c => EditCorrespondentPage(correspondent: c),
DocumentType d => EditDocumentTypePage(documentType: d),
Tag t => EditTagPage(tag: t),
StoragePath s => EditStoragePathPage(storagePath: s),
};
}
}
class CreateLabelRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final LabelType $extra;
final String? name;
CreateLabelRoute(
this.$extra, {
this.name,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return switch ($extra) {
LabelType.correspondent => AddCorrespondentPage(initialName: name),
LabelType.documentType => AddDocumentTypePage(initialName: name),
LabelType.tag => AddTagPage(initialName: name),
LabelType.storagePath => AddStoragePathPage(initialName: name),
};
}
}
class LinkedDocumentsRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final DocumentFilter $extra;
const LinkedDocumentsRoute(this.$extra);
@override
Widget build(BuildContext context, GoRouterState state) {
return BlocProvider(
create: (context) => LinkedDocumentsCubit(
$extra,
context.read(),
context.read(),
context.read(),
context.read(),
),
child: const LinkedDocumentsPage(),
);
}
}

View File

@@ -0,0 +1,18 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/landing/view/landing_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
class LandingBranch extends StatefulShellBranchData {
static final GlobalKey<NavigatorState> $navigatorKey = landingNavigatorKey;
const LandingBranch();
}
class LandingRoute extends GoRouteData {
const LandingRoute();
@override
Widget build(BuildContext context, GoRouterState state) {
return const LandingPage();
}
}

View File

@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
part 'logging_out_route.g.dart';
@TypedGoRoute<LoggingOutRoute>(
path: "/logging-out",
name: R.loggingOut,
)
class LoggingOutRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
const LoggingOutRoute();
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: Scaffold(
body: Center(
child: Text(S.of(context)!.loggingOut),
),
),
);
}
}

View File

@@ -0,0 +1,165 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:paperless_mobile/core/database/hive/hive_extensions.dart';
import 'package:paperless_mobile/features/login/cubit/authentication_cubit.dart';
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
import 'package:paperless_mobile/features/login/view/login_page.dart';
import 'package:paperless_mobile/features/login/view/login_to_existing_account_page.dart';
import 'package:paperless_mobile/features/login/view/verify_identity_page.dart';
import 'package:paperless_mobile/features/login/view/widgets/login_transition_page.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
part 'login_route.g.dart';
@TypedGoRoute<LoginRoute>(
path: "/login",
name: R.login,
routes: [
TypedGoRoute<SwitchingAccountsRoute>(
path: "switching-account",
name: R.switchingAccount,
),
TypedGoRoute<AuthenticatingRoute>(
path: 'authenticating',
name: R.authenticating,
),
TypedGoRoute<VerifyIdentityRoute>(
path: 'verify-identity',
name: R.verifyIdentity,
),
TypedGoRoute<LoginToExistingAccountRoute>(
path: 'existing',
name: R.loginToExistingAccount,
),
TypedGoRoute<RestoringSessionRoute>(
path: 'restoring-session',
name: R.restoringSession,
),
],
)
class LoginRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
final String? serverUrl;
final String? username;
final String? password;
final ClientCertificate? $extra;
const LoginRoute({
this.serverUrl,
this.username,
this.password,
this.$extra,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return LoginPage(
initialServerUrl: serverUrl,
initialUsername: username,
initialPassword: password,
initialClientCertificate: $extra,
);
}
@override
FutureOr<String?> redirect(BuildContext context, GoRouterState state) {
if (context.read<AuthenticationCubit>().state.isAuthenticated) {
return "/landing";
}
return null;
}
}
class SwitchingAccountsRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
const SwitchingAccountsRoute();
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: LoginTransitionPage(
text: S.of(context)!.switchingAccountsPleaseWait,
),
);
}
}
class AuthenticatingRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
final String checkLoginStageName;
const AuthenticatingRoute(this.checkLoginStageName);
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
final stage = AuthenticatingStage.values.byName(checkLoginStageName);
final text = switch (stage) {
AuthenticatingStage.authenticating => S.of(context)!.authenticatingDots,
AuthenticatingStage.persistingLocalUserData =>
S.of(context)!.persistingUserInformation,
AuthenticatingStage.fetchingUserInformation =>
S.of(context)!.fetchingUserInformation,
};
return NoTransitionPage(
child: LoginTransitionPage(
text: text,
),
);
}
}
class VerifyIdentityRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
final String userId;
const VerifyIdentityRoute({required this.userId});
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: VerifyIdentityPage(userId: userId),
);
}
}
class LoginToExistingAccountRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
const LoginToExistingAccountRoute();
@override
FutureOr<String?> redirect(BuildContext context, GoRouterState state) {
if (Hive.localUserAccountBox.isEmpty) {
return "/login";
}
return null;
}
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return const NoTransitionPage(
child: LoginToExistingAccountPage(),
);
}
}
class RestoringSessionRoute extends GoRouteData {
static final $parentNavigatorKey = rootNavigatorKey;
const RestoringSessionRoute();
@override
Page<void> buildPage(BuildContext context, GoRouterState state) {
return NoTransitionPage(
child: LoginTransitionPage(
text: S.of(context)!.restoringSession,
),
);
}
}

View File

@@ -0,0 +1,39 @@
import 'package:flutter/src/widgets/framework.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/features/saved_view/view/add_saved_view_page.dart';
import 'package:paperless_mobile/features/saved_view/view/edit_saved_view_page.dart';
class SavedViewsRoute extends GoRouteData {
const SavedViewsRoute();
}
class CreateSavedViewRoute extends GoRouteData {
final DocumentFilter? $extra;
final bool? showOnDashboard;
final bool? showInSidebar;
const CreateSavedViewRoute({
this.$extra = const DocumentFilter(),
this.showOnDashboard,
this.showInSidebar,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return AddSavedViewPage(
initialFilter: $extra,
showInSidebar: showInSidebar,
showOnDashboard: showOnDashboard,
);
}
}
class EditSavedViewRoute extends GoRouteData {
final SavedView $extra;
const EditSavedViewRoute({required this.$extra});
@override
Widget build(BuildContext context, GoRouterState state) {
return EditSavedViewPage(savedView: $extra);
}
}

View File

@@ -0,0 +1,60 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/document_scan/view/scanner_page.dart';
import 'package:paperless_mobile/features/document_upload/cubit/document_upload_cubit.dart';
import 'package:paperless_mobile/features/document_upload/view/document_upload_preparation_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
class ScannerBranch extends StatefulShellBranchData {
static final GlobalKey<NavigatorState> $navigatorKey = scannerNavigatorKey;
const ScannerBranch();
}
class ScannerRoute extends GoRouteData {
const ScannerRoute();
@override
Widget build(BuildContext context, GoRouterState state) {
return const ScannerPage();
}
}
class DocumentUploadRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
final FutureOr<Uint8List> $extra;
final String? title;
final String? filename;
final String? fileExtension;
const DocumentUploadRoute({
required this.$extra,
this.title,
this.filename,
this.fileExtension,
});
@override
Widget build(BuildContext context, GoRouterState state) {
return BlocProvider(
create: (_) => DocumentUploadCubit(
context.read(),
context.read(),
context.read(),
context.read(),
),
child: DocumentUploadPreparationPage(
title: title,
fileExtension: fileExtension,
filename: filename,
fileBytes: $extra,
),
);
}
}

View File

@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/settings/view/settings_page.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
import 'package:paperless_mobile/theme.dart';
class SettingsRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
@override
Widget build(BuildContext context, GoRouterState state) {
return AnnotatedRegion<SystemUiOverlayStyle>(
value: buildOverlayStyle(
Theme.of(context),
systemNavigationBarColor: Theme.of(context).colorScheme.background,
),
child: const SettingsPage(),
);
}
}

View File

@@ -0,0 +1,173 @@
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:hive_flutter/adapters.dart';
import 'package:paperless_api/paperless_api.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/database/tables/local_user_account.dart';
import 'package:paperless_mobile/core/factory/paperless_api_factory.dart';
import 'package:paperless_mobile/features/home/view/home_shell_widget.dart';
import 'package:paperless_mobile/features/sharing/cubit/receive_share_cubit.dart';
import 'package:paperless_mobile/features/sharing/view/widgets/event_listener_shell.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
import 'package:paperless_mobile/routing/routes/documents_route.dart';
import 'package:paperless_mobile/routing/routes/inbox_route.dart';
import 'package:paperless_mobile/routing/routes/labels_route.dart';
import 'package:paperless_mobile/routing/routes/landing_route.dart';
import 'package:paperless_mobile/routing/routes/saved_views_route.dart';
import 'package:paperless_mobile/routing/routes/scanner_route.dart';
import 'package:paperless_mobile/routing/routes/upload_queue_route.dart';
import 'package:paperless_mobile/routing/routes/shells/scaffold_shell_route.dart';
import 'package:paperless_mobile/routing/routes/settings_route.dart';
import 'package:provider/provider.dart';
/// Key used to access
part 'authenticated_route.g.dart';
@TypedShellRoute<AuthenticatedRoute>(
routes: [
TypedGoRoute<SettingsRoute>(
path: "/settings",
name: R.settings,
),
TypedGoRoute<UploadQueueRoute>(
path: "/upload-queue",
name: R.uploadQueue,
),
TypedGoRoute<SavedViewsRoute>(
path: "/saved-views",
routes: [
TypedGoRoute<CreateSavedViewRoute>(
path: "create",
name: R.createSavedView,
),
TypedGoRoute<EditSavedViewRoute>(
path: "edit",
name: R.editSavedView,
),
],
),
TypedStatefulShellRoute<ScaffoldShellRoute>(
branches: [
TypedStatefulShellBranch<LandingBranch>(
routes: [
TypedGoRoute<LandingRoute>(
path: "/landing",
name: R.landing,
)
],
),
TypedStatefulShellBranch<DocumentsBranch>(
routes: [
TypedGoRoute<DocumentsRoute>(
path: "/documents",
routes: [
TypedGoRoute<DocumentDetailsRoute>(
path: "details/:id",
name: R.documentDetails,
),
TypedGoRoute<EditDocumentRoute>(
path: "edit",
name: R.editDocument,
),
TypedGoRoute<BulkEditDocumentsRoute>(
path: "bulk-edit",
name: R.bulkEditDocuments,
),
TypedGoRoute<DocumentPreviewRoute>(
path: 'preview',
name: R.documentPreview,
),
],
)
],
),
TypedStatefulShellBranch<ScannerBranch>(
routes: [
TypedGoRoute<ScannerRoute>(
path: "/scanner",
name: R.scanner,
routes: [
TypedGoRoute<DocumentUploadRoute>(
path: "upload",
name: R.uploadDocument,
),
],
),
],
),
TypedStatefulShellBranch<LabelsBranch>(
routes: [
TypedGoRoute<LabelsRoute>(
path: "/labels",
name: R.labels,
routes: [
TypedGoRoute<EditLabelRoute>(
path: "edit",
name: R.editLabel,
),
TypedGoRoute<CreateLabelRoute>(
path: "create",
name: R.createLabel,
),
TypedGoRoute<LinkedDocumentsRoute>(
path: "linked-documents",
name: R.linkedDocuments,
),
],
),
],
),
TypedStatefulShellBranch<InboxBranch>(
routes: [
TypedGoRoute<InboxRoute>(
path: "/inbox",
name: R.inbox,
)
],
),
],
),
],
)
class AuthenticatedRoute extends ShellRouteData {
static final GlobalKey<NavigatorState> $navigatorKey = outerShellNavigatorKey;
const AuthenticatedRoute();
@override
Widget builder(
BuildContext context,
GoRouterState state,
Widget navigator,
) {
final currentUserId = Hive.box<GlobalSettings>(HiveBoxes.globalSettings)
.getValue()!
.loggedInUserId;
if (currentUserId == null) {
return const SizedBox.shrink();
}
final authenticatedUser =
Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).get(
currentUserId,
)!;
final apiFactory = context.read<PaperlessApiFactory>();
return HomeShellWidget(
localUserId: authenticatedUser.id,
paperlessApiVersion: authenticatedUser.apiVersion,
paperlessProviderFactory: apiFactory,
child: ChangeNotifierProvider(
create: (context) => ConsumptionChangeNotifier()
..loadFromConsumptionDirectory(userId: currentUserId),
child: EventListenerShell(
child: navigator,
),
),
);
}
}

View File

@@ -0,0 +1,35 @@
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:hive/hive.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/database/tables/local_user_account.dart';
import 'package:paperless_mobile/features/home/view/scaffold_with_navigation_bar.dart';
class ScaffoldShellRoute extends StatefulShellRouteData {
const ScaffoldShellRoute();
static Widget $navigatorContainerBuilder(BuildContext context,
StatefulNavigationShell navigationShell, List<Widget> children) {
return children[navigationShell.currentIndex];
}
@override
Widget builder(
BuildContext context,
GoRouterState state,
StatefulNavigationShell navigationShell,
) {
final currentUserId = Hive.box<GlobalSettings>(HiveBoxes.globalSettings)
.getValue()!
.loggedInUserId!;
final authenticatedUser =
Hive.box<LocalUserAccount>(HiveBoxes.localUserAccount).get(
currentUserId,
)!;
return ScaffoldWithNavigationBar(
authenticatedUser: authenticatedUser.paperlessUser,
navigationShell: navigationShell,
);
}
}

View File

@@ -0,0 +1,15 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:paperless_mobile/features/sharing/view/consumption_queue_view.dart';
import 'package:paperless_mobile/routing/navigation_keys.dart';
import 'package:paperless_mobile/routing/routes.dart';
class UploadQueueRoute extends GoRouteData {
static final GlobalKey<NavigatorState> $parentNavigatorKey =
outerShellNavigatorKey;
@override
Widget build(BuildContext context, GoRouterState state) {
return const ConsumptionQueueView();
}
}