mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 08:08:14 -06:00
Removed suggestions from inbox, added translations, added paging to inbox, visual updates, changed default matching algorithm to auto
This commit is contained in:
@@ -23,71 +23,104 @@ class InboxPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InboxPageState extends State<InboxPage> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
final _emptyStateRefreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initializeDateFormatting();
|
||||
_scrollController.addListener(_listenForLoadNewData);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.removeListener(_listenForLoadNewData);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _listenForLoadNewData() {
|
||||
final currState = context.read<InboxCubit>().state;
|
||||
if (_scrollController.offset >=
|
||||
_scrollController.position.maxScrollExtent * 0.75 &&
|
||||
!currState.isLoading &&
|
||||
!currState.isLastPageLoaded) {
|
||||
try {
|
||||
context.read<InboxCubit>().loadMore();
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
const _progressBarHeight = 4.0;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context).bottomNavInboxPageLabel),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
appBar: PreferredSize(
|
||||
preferredSize:
|
||||
const Size.fromHeight(kToolbarHeight + _progressBarHeight),
|
||||
child: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return AppBar(
|
||||
title: Text(S.of(context).bottomNavInboxPageLabel),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
actions: [
|
||||
if (state.hasLoaded)
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Text(
|
||||
state.value.isEmpty
|
||||
? '0'
|
||||
: '${state.value.first.count} ' +
|
||||
S.of(context).inboxPageUnseenText,
|
||||
textAlign: TextAlign.start,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
).paddedSymmetrically(horizontal: 4.0),
|
||||
),
|
||||
),
|
||||
).paddedSymmetrically(horizontal: 8)
|
||||
],
|
||||
bottom: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(4),
|
||||
child: state.isLoading && state.hasLoaded
|
||||
? const LinearProgressIndicator()
|
||||
: const SizedBox(height: _progressBarHeight),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Text(
|
||||
'${state.inboxItems.length} ${S.of(context).inboxPageUnseenText}',
|
||||
textAlign: TextAlign.start,
|
||||
style: Theme.of(context).textTheme.bodySmall,
|
||||
).paddedSymmetrically(horizontal: 4.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
).paddedSymmetrically(horizontal: 8)
|
||||
],
|
||||
),
|
||||
floatingActionButton: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
if (!state.isLoaded || state.inboxItems.isEmpty) {
|
||||
if (!state.hasLoaded || state.documents.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return FloatingActionButton.extended(
|
||||
label: Text(S.of(context).inboxPageMarkAllAsSeenLabel),
|
||||
icon: const Icon(Icons.done_all),
|
||||
onPressed: state.isLoaded && state.inboxItems.isNotEmpty
|
||||
onPressed: state.hasLoaded && state.documents.isNotEmpty
|
||||
? () => _onMarkAllAsSeen(
|
||||
state.inboxItems,
|
||||
state.documents,
|
||||
state.inboxTags,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
},
|
||||
),
|
||||
body: BlocConsumer<InboxCubit, InboxState>(
|
||||
listenWhen: (previous, current) =>
|
||||
!previous.isLoaded && current.isLoaded,
|
||||
listener: (context, state) =>
|
||||
context.read<InboxCubit>().loadSuggestions(),
|
||||
body: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
if (!state.isLoaded) {
|
||||
if (!state.hasLoaded) {
|
||||
return const DocumentsListLoadingWidget();
|
||||
}
|
||||
|
||||
if (state.inboxItems.isEmpty) {
|
||||
if (state.documents.isEmpty) {
|
||||
return InboxEmptyWidget(
|
||||
emptyStateRefreshIndicatorKey: _emptyStateRefreshIndicatorKey,
|
||||
);
|
||||
@@ -95,7 +128,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
|
||||
// Build a list of slivers alternating between SliverToBoxAdapter
|
||||
// (group header) and a SliverList (inbox items).
|
||||
final List<Widget> slivers = _groupByDate(state.inboxItems)
|
||||
final List<Widget> slivers = _groupByDate(state.documents)
|
||||
.entries
|
||||
.map(
|
||||
(entry) => [
|
||||
@@ -148,6 +181,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: CustomScrollView(
|
||||
controller: _scrollController,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: HintCard(
|
||||
@@ -157,7 +191,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
context.read<InboxCubit>().acknowledgeHint(),
|
||||
),
|
||||
),
|
||||
...slivers
|
||||
...slivers,
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -234,7 +268,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
|
||||
Future<bool> _onItemDismissed(DocumentModel doc) async {
|
||||
try {
|
||||
final removedTags = await context.read<InboxCubit>().remove(doc);
|
||||
final removedTags = await context.read<InboxCubit>().removeFromInbox(doc);
|
||||
showSnackBar(
|
||||
context,
|
||||
S.of(context).inboxPageDocumentRemovedMessageText,
|
||||
@@ -261,7 +295,9 @@ class _InboxPageState extends State<InboxPage> {
|
||||
Iterable<int> removedTags,
|
||||
) async {
|
||||
try {
|
||||
await context.read<InboxCubit>().undoRemove(document, removedTags);
|
||||
await context
|
||||
.read<InboxCubit>()
|
||||
.undoRemoveFromInbox(document, removedTags);
|
||||
} on PaperlessServerException catch (error, stackTrace) {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
|
||||
@@ -1,25 +1,18 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/repository/provider/label_repositories_provider.dart';
|
||||
import 'package:paperless_mobile/core/repository/state/impl/correspondent_repository_state.dart';
|
||||
import 'package:paperless_mobile/core/repository/state/impl/document_type_repository_state.dart';
|
||||
import 'package:paperless_mobile/extensions/date_time_extensions.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/document_details/view/pages/document_details_page.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/delete_document_confirmation_dialog.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/document_preview.dart';
|
||||
import 'package:paperless_mobile/features/inbox/bloc/inbox_cubit.dart';
|
||||
import 'package:paperless_mobile/features/inbox/bloc/state/inbox_state.dart';
|
||||
import 'package:paperless_mobile/features/labels/tags/view/widgets/tags_widget.dart';
|
||||
import 'package:paperless_mobile/features/labels/view/widgets/label_text.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/util.dart';
|
||||
|
||||
class InboxItem extends StatefulWidget {
|
||||
static const _a4AspectRatio = 1 / 1.4142;
|
||||
@@ -37,6 +30,8 @@ class InboxItem extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InboxItemState extends State<InboxItem> {
|
||||
// late final Future<FieldSuggestions> _fieldSuggestions;
|
||||
|
||||
bool _isAsnAssignLoading = false;
|
||||
|
||||
@override
|
||||
@@ -65,7 +60,7 @@ class _InboxItemState extends State<InboxItem> {
|
||||
}
|
||||
},
|
||||
child: SizedBox(
|
||||
height: 180,
|
||||
height: 200,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -128,54 +123,66 @@ class _InboxItemState extends State<InboxItem> {
|
||||
) ??
|
||||
false;
|
||||
if (shouldDelete) {
|
||||
context.read<InboxCubit>().deleteDocument(widget.document);
|
||||
context.read<InboxCubit>().delete(widget.document);
|
||||
}
|
||||
},
|
||||
),
|
||||
];
|
||||
return BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return Row(
|
||||
// return FutureBuilder<FieldSuggestions>(
|
||||
// future: _fieldSuggestions,
|
||||
// builder: (context, snapshot) {
|
||||
// List<Widget>? suggestions;
|
||||
// if (!snapshot.hasData) {
|
||||
// suggestions = [
|
||||
// const SizedBox(width: 4),
|
||||
// ];
|
||||
// } else {
|
||||
// if (snapshot.data!.hasSuggestions) {
|
||||
// suggestions = [
|
||||
// const SizedBox(width: 4),
|
||||
// ..._buildSuggestionChips(
|
||||
// chipShape,
|
||||
// snapshot.data!,
|
||||
// context.watch<InboxCubit>().state,
|
||||
// ),
|
||||
// ];
|
||||
// }
|
||||
// }
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.bolt_outlined),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Text(
|
||||
S.of(context).inboxPageQuickActionsLabel,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
indent: 16,
|
||||
endIndent: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...actions,
|
||||
if (state.suggestions[widget.document.id] != null) ...[
|
||||
const SizedBox(width: 4),
|
||||
..._buildSuggestionChips(
|
||||
chipShape,
|
||||
state.suggestions[widget.document.id]!,
|
||||
state,
|
||||
)
|
||||
]
|
||||
],
|
||||
const Icon(Icons.bolt_outlined),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Text(
|
||||
S.of(context).inboxPageQuickActionsLabel,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
const VerticalDivider(
|
||||
indent: 16,
|
||||
endIndent: 16,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 4.0),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
children: [
|
||||
...actions,
|
||||
// if (suggestions != null) ...suggestions,
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
// );
|
||||
// },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -274,97 +281,103 @@ class _InboxItemState extends State<InboxItem> {
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildSuggestionChips(
|
||||
OutlinedBorder chipShape,
|
||||
FieldSuggestions suggestions,
|
||||
InboxState state,
|
||||
) {
|
||||
return [
|
||||
...suggestions.correspondents
|
||||
.whereNot((e) => widget.document.correspondent == e)
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.person_outline),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableCorrespondents[e]?.name ?? ''),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(
|
||||
correspondent: e,
|
||||
overwriteCorrespondent: true,
|
||||
))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.documentTypes
|
||||
.whereNot((e) => widget.document.documentType == e)
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.description_outlined),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableDocumentTypes[e]?.name ?? ''),
|
||||
onPressed: () => context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document
|
||||
.copyWith(documentType: e, overwriteDocumentType: true))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.tags
|
||||
.whereNot((e) => widget.document.tags.contains(e))
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.label_outline),
|
||||
shape: chipShape,
|
||||
label: Text(state.availableTags[e]?.name ?? ''),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(
|
||||
tags: {...widget.document.tags, e}.toList(),
|
||||
overwriteTags: true,
|
||||
))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
},
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
...suggestions.dates
|
||||
.whereNot((e) => widget.document.created.isEqualToIgnoringDate(e))
|
||||
.map(
|
||||
(e) => ActionChip(
|
||||
avatar: const Icon(Icons.calendar_today_outlined),
|
||||
shape: chipShape,
|
||||
label: Text(
|
||||
"${S.of(context).documentCreatedPropertyLabel}: ${DateFormat.yMd().format(e)}",
|
||||
),
|
||||
onPressed: () => context
|
||||
.read<InboxCubit>()
|
||||
.updateDocument(widget.document.copyWith(created: e))
|
||||
.then((value) => showSnackBar(
|
||||
context,
|
||||
S
|
||||
.of(context)
|
||||
.inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
].expand((element) => [element, const SizedBox(width: 4)]).toList();
|
||||
}
|
||||
// List<Widget> _buildSuggestionChips(
|
||||
// OutlinedBorder chipShape,
|
||||
// FieldSuggestions suggestions,
|
||||
// InboxState state,
|
||||
// ) {
|
||||
// return [
|
||||
// ...suggestions.correspondents
|
||||
// .whereNot((e) => widget.document.correspondent == e)
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.person_outline),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableCorrespondents[e]?.name ?? ''),
|
||||
// onPressed: () {
|
||||
// context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(correspondent: () => e),
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.documentTypes
|
||||
// .whereNot((e) => widget.document.documentType == e)
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.description_outlined),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableDocumentTypes[e]?.name ?? ''),
|
||||
// onPressed: () => context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(documentType: () => e),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.tags
|
||||
// .whereNot((e) => widget.document.tags.contains(e))
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.label_outline),
|
||||
// shape: chipShape,
|
||||
// label: Text(state.availableTags[e]?.name ?? ''),
|
||||
// onPressed: () {
|
||||
// context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(
|
||||
// tags: {...widget.document.tags, e}.toList(),
|
||||
// ),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage));
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ...suggestions.dates
|
||||
// .whereNot((e) => widget.document.created.isEqualToIgnoringDate(e))
|
||||
// .map(
|
||||
// (e) => ActionChip(
|
||||
// avatar: const Icon(Icons.calendar_today_outlined),
|
||||
// shape: chipShape,
|
||||
// label: Text(
|
||||
// "${S.of(context).documentCreatedPropertyLabel}: ${DateFormat.yMd().format(e)}",
|
||||
// ),
|
||||
// onPressed: () => context
|
||||
// .read<InboxCubit>()
|
||||
// .update(
|
||||
// widget.document.copyWith(created: e),
|
||||
// shouldReload: false,
|
||||
// )
|
||||
// .then((value) => showSnackBar(
|
||||
// context,
|
||||
// S
|
||||
// .of(context)
|
||||
// .inboxPageSuggestionSuccessfullyAppliedMessage)),
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
||||
// ].expand((element) => [element, const SizedBox(width: 4)]).toList();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user