mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 18:07:50 -06:00
Finished inbox, fixed reverse sort order, bloc refactorings
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
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_mobile/core/widgets/documents_list_loading_widget.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/document.model.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/inbox/view/widgets/document_inbox_item.dart';
|
||||
import 'package:paperless_mobile/features/inbox/view/widgets/inbox_item.dart';
|
||||
import 'package:paperless_mobile/features/inbox/view/widgets/inbox_empty_widget.dart';
|
||||
import 'package:paperless_mobile/generated/l10n.dart';
|
||||
import 'package:paperless_mobile/util.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:paperless_mobile/extensions/dart_extensions.dart';
|
||||
|
||||
class InboxPage extends StatefulWidget {
|
||||
const InboxPage({super.key});
|
||||
@@ -30,7 +34,6 @@ class _InboxPageState extends State<InboxPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//TODO: Group by date (today, yseterday, etc.)
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(S.of(context).bottomNavInboxPageLabel),
|
||||
@@ -39,7 +42,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
onPressed: () => Navigator.pop(context),
|
||||
),
|
||||
bottom: PreferredSize(
|
||||
preferredSize: Size.fromHeight(14),
|
||||
preferredSize: const Size.fromHeight(14),
|
||||
child: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
return Align(
|
||||
@@ -49,7 +52,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
child: ColoredBox(
|
||||
color: Theme.of(context).colorScheme.secondaryContainer,
|
||||
child: Text(
|
||||
'${state.inboxItems.length} unseen',
|
||||
'${state.inboxItems.length} ${S.of(context).inboxPageUnseenText}',
|
||||
textAlign: TextAlign.start,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
).padded(const EdgeInsets.symmetric(horizontal: 4.0)),
|
||||
@@ -62,8 +65,11 @@ class _InboxPageState extends State<InboxPage> {
|
||||
),
|
||||
floatingActionButton: BlocBuilder<InboxCubit, InboxState>(
|
||||
builder: (context, state) {
|
||||
if (!state.isLoaded || state.inboxItems.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return FloatingActionButton.extended(
|
||||
label: Text("Mark all as seen"),
|
||||
label: Text(S.of(context).inboxPageMarkAllAsSeenLabel),
|
||||
icon: const Icon(Icons.done_all),
|
||||
onPressed: state.isLoaded && state.inboxItems.isNotEmpty
|
||||
? () => _onMarkAllAsSeen(
|
||||
@@ -81,51 +87,68 @@ class _InboxPageState extends State<InboxPage> {
|
||||
}
|
||||
|
||||
if (state.inboxItems.isEmpty) {
|
||||
return RefreshIndicator(
|
||||
key: _emptyStateRefreshIndicatorKey,
|
||||
onRefresh: () =>
|
||||
BlocProvider.of<InboxCubit>(context).reloadInbox(),
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('You do not have unseen documents.'),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
_emptyStateRefreshIndicatorKey.currentState?.show(),
|
||||
child: Text('Refresh'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
return InboxEmptyWidget(
|
||||
emptyStateRefreshIndicatorKey: _emptyStateRefreshIndicatorKey,
|
||||
);
|
||||
}
|
||||
|
||||
// Build a list of slivers alternating between SliverToBoxAdapter
|
||||
// (group header) and a SliverList (inbox items).
|
||||
final List<Widget> slivers = _groupByDate(state.inboxItems)
|
||||
.entries
|
||||
.map(
|
||||
(entry) => [
|
||||
SliverToBoxAdapter(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(32.0),
|
||||
child: Text(
|
||||
entry.key,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
textAlign: TextAlign.center,
|
||||
).padded(),
|
||||
),
|
||||
).padded(const EdgeInsets.only(top: 8.0)),
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
childCount: entry.value.length,
|
||||
(context, index) => _buildListItem(
|
||||
context,
|
||||
entry.value[index],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
.flattened
|
||||
.toList();
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () => BlocProvider.of<InboxCubit>(context).reloadInbox(),
|
||||
onRefresh: () => BlocProvider.of<InboxCubit>(context).loadInbox(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'Hint: Swipe left to mark a document as seen. This will remove all inbox tags from the document.', //TODO: INTL
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
).padded(
|
||||
const EdgeInsets.only(
|
||||
top: 4.0,
|
||||
left: 8.0,
|
||||
right: 8.0,
|
||||
bottom: 8.0,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: state.inboxItems.length,
|
||||
itemBuilder: (context, index) {
|
||||
final doc = state.inboxItems.elementAt(index);
|
||||
return _buildListItem(context, doc);
|
||||
},
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: Text(
|
||||
S.of(context).inboxPageUsageHintText,
|
||||
textAlign: TextAlign.center,
|
||||
style: Theme.of(context).textTheme.caption,
|
||||
).padded(
|
||||
const EdgeInsets.only(
|
||||
top: 8.0,
|
||||
left: 8.0,
|
||||
right: 8.0,
|
||||
bottom: 8.0,
|
||||
),
|
||||
),
|
||||
),
|
||||
...slivers
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -147,7 +170,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
).padded(),
|
||||
Text(
|
||||
'Mark as seen', //TODO: INTL
|
||||
S.of(context).inboxPageMarkAsSeenText,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
),
|
||||
@@ -156,7 +179,7 @@ class _InboxPageState extends State<InboxPage> {
|
||||
).padded(),
|
||||
confirmDismiss: (_) => _onItemDismissed(doc),
|
||||
key: UniqueKey(),
|
||||
child: DocumentInboxItem(document: doc),
|
||||
child: InboxItem(document: doc),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -167,9 +190,11 @@ class _InboxPageState extends State<InboxPage> {
|
||||
final isActionConfirmed = await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Confirm action'),
|
||||
title: Text(S
|
||||
.of(context)
|
||||
.inboxPageMarkAllAsSeenConfirmationDialogTitleText),
|
||||
content: Text(
|
||||
'Are you sure you want to mark all documents as seen? This will perform a bulk edit operation removing all inbox tags from the documents.\nThis action is not reversible! Are you sure you want to continue?',
|
||||
S.of(context).inboxPageMarkAllAsSeenConfirmationDialogText,
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
@@ -178,7 +203,10 @@ class _InboxPageState extends State<InboxPage> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text(S.of(context).genericActionOkLabel),
|
||||
child: Text(
|
||||
S.of(context).genericActionOkLabel,
|
||||
style: TextStyle(color: Theme.of(context).colorScheme.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -195,9 +223,9 @@ class _InboxPageState extends State<InboxPage> {
|
||||
await BlocProvider.of<InboxCubit>(context).remove(doc);
|
||||
showSnackBar(
|
||||
context,
|
||||
'Document removed from inbox.', //TODO: INTL
|
||||
S.of(context).inboxPageDocumentRemovedMessageText,
|
||||
action: SnackBarAction(
|
||||
label: 'UNDO', //TODO: INTL
|
||||
label: S.of(context).inboxPageUndoRemoveText,
|
||||
onPressed: () => _onUndoMarkAsSeen(doc, removedTags),
|
||||
),
|
||||
);
|
||||
@@ -225,4 +253,21 @@ class _InboxPageState extends State<InboxPage> {
|
||||
showErrorMessage(context, error, stackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, List<DocumentModel>> _groupByDate(
|
||||
Iterable<DocumentModel> documents,
|
||||
) {
|
||||
return groupBy<DocumentModel, String>(
|
||||
documents,
|
||||
(doc) {
|
||||
if (doc.added.isToday) {
|
||||
return S.of(context).inboxPageTodayText;
|
||||
}
|
||||
if (doc.added.isYesterday) {
|
||||
return S.of(context).inboxPageYesterdayText;
|
||||
}
|
||||
return DateFormat.yMMMMd().format(doc.added);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user