feat: Add new view type, WIP

This commit is contained in:
Anton Stubenbord
2023-02-12 19:31:04 +01:00
parent 681d551b56
commit 26b283b83a
3 changed files with 64 additions and 60 deletions

View File

@@ -18,7 +18,6 @@ import 'package:paperless_mobile/features/saved_view/cubit/saved_view_cubit.dart
import 'package:paperless_mobile/features/saved_view/view/add_saved_view_page.dart'; import 'package:paperless_mobile/features/saved_view/view/add_saved_view_page.dart';
import 'package:paperless_mobile/features/saved_view/view/saved_view_list.dart'; import 'package:paperless_mobile/features/saved_view/view/saved_view_list.dart';
import 'package:paperless_mobile/features/search_app_bar/view/search_app_bar.dart'; import 'package:paperless_mobile/features/search_app_bar/view/search_app_bar.dart';
import 'package:paperless_mobile/features/settings/model/view_type.dart';
import 'package:paperless_mobile/features/tasks/cubit/task_status_cubit.dart'; import 'package:paperless_mobile/features/tasks/cubit/task_status_cubit.dart';
import 'package:paperless_mobile/generated/l10n.dart'; import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/helpers/message_helpers.dart'; import 'package:paperless_mobile/helpers/message_helpers.dart';
@@ -243,17 +242,20 @@ class _DocumentsPageState extends State<DocumentsPage>
children: [ children: [
Builder( Builder(
builder: (context) { builder: (context) {
final itemHeight =
MediaQuery.sizeOf(context).height -
MediaQuery.viewInsetsOf(context).bottom -
MediaQuery.viewInsetsOf(context).top -
kToolbarHeight -
kTextTabBarHeight -
56;
return RefreshIndicator( return RefreshIndicator(
edgeOffset: kToolbarHeight + kTextTabBarHeight, edgeOffset: kToolbarHeight + kTextTabBarHeight,
onRefresh: _onReloadDocuments, onRefresh: _onReloadDocuments,
notificationPredicate: (_) => notificationPredicate: (_) =>
connectivityState.isConnected, connectivityState.isConnected,
child: child: CustomScrollView(
BlocBuilder<DocumentsCubit, DocumentsState>( key: const PageStorageKey<String>("documents"),
builder: (context, state) {
return CustomScrollView(
key: const PageStorageKey<String>(
"documents"),
slivers: <Widget>[ slivers: <Widget>[
SliverOverlapInjector( SliverOverlapInjector(
handle: NestedScrollView handle: NestedScrollView
@@ -261,8 +263,8 @@ class _DocumentsPageState extends State<DocumentsPage>
context), context),
), ),
_buildViewActions(), _buildViewActions(),
Builder( BlocBuilder<DocumentsCubit, DocumentsState>(
builder: (context) { builder: (context, state) {
if (state.hasLoaded && if (state.hasLoaded &&
state.documents.isEmpty) { state.documents.isEmpty) {
return SliverToBoxAdapter( return SliverToBoxAdapter(
@@ -279,6 +281,7 @@ class _DocumentsPageState extends State<DocumentsPage>
return SliverAdaptiveDocumentsView( return SliverAdaptiveDocumentsView(
viewType: state.viewType, viewType: state.viewType,
maxItemExtent: itemHeight,
onTap: _openDetails, onTap: _openDetails,
onSelected: context onSelected: context
.read<DocumentsCubit>() .read<DocumentsCubit>()
@@ -296,14 +299,11 @@ class _DocumentsPageState extends State<DocumentsPage>
hasLoaded: state.hasLoaded, hasLoaded: state.hasLoaded,
isLabelClickable: true, isLabelClickable: true,
isLoading: state.isLoading, isLoading: state.isLoading,
selectedDocumentIds: selectedDocumentIds: state.selectedIds,
state.selectedIds,
); );
}, },
), ),
], ],
);
},
), ),
); );
}, },

View File

@@ -23,6 +23,7 @@ abstract class AdaptiveDocumentsView extends StatelessWidget {
final void Function(int? id)? onCorrespondentSelected; final void Function(int? id)? onCorrespondentSelected;
final void Function(int? id)? onDocumentTypeSelected; final void Function(int? id)? onDocumentTypeSelected;
final void Function(int? id)? onStoragePathSelected; final void Function(int? id)? onStoragePathSelected;
final double maxItemExtent;
bool get showLoadingPlaceholder => (!hasLoaded && isLoading); bool get showLoadingPlaceholder => (!hasLoaded && isLoading);
const AdaptiveDocumentsView({ const AdaptiveDocumentsView({
@@ -41,6 +42,7 @@ abstract class AdaptiveDocumentsView extends StatelessWidget {
required this.isLoading, required this.isLoading,
required this.hasLoaded, required this.hasLoaded,
this.enableHeroAnimation = true, this.enableHeroAnimation = true,
required this.maxItemExtent,
}); });
} }
@@ -61,6 +63,7 @@ class SliverAdaptiveDocumentsView extends AdaptiveDocumentsView {
super.enableHeroAnimation, super.enableHeroAnimation,
required super.isLoading, required super.isLoading,
required super.hasLoaded, required super.hasLoaded,
super.maxItemExtent = double.infinity,
}); });
@override @override
@@ -71,7 +74,7 @@ class SliverAdaptiveDocumentsView extends AdaptiveDocumentsView {
case ViewType.list: case ViewType.list:
return _buildListView(); return _buildListView();
case ViewType.detailed: case ViewType.detailed:
return _buildFullView(); return _buildFullView(context);
} }
} }
@@ -104,18 +107,19 @@ class SliverAdaptiveDocumentsView extends AdaptiveDocumentsView {
); );
} }
Widget _buildFullView() { Widget _buildFullView(BuildContext context) {
if (showLoadingPlaceholder) { if (showLoadingPlaceholder) {
//TODO: Build detailed loading animation //TODO: Build detailed loading animation
return DocumentsListLoadingWidget.sliver(); return DocumentsListLoadingWidget.sliver();
} }
return SliverList( return SliverFixedExtentList(
itemExtent: maxItemExtent,
delegate: SliverChildBuilderDelegate( delegate: SliverChildBuilderDelegate(
childCount: documents.length, childCount: documents.length,
(context, index) { (context, index) {
final document = documents.elementAt(index); final document = documents.elementAt(index);
return LabelRepositoriesProvider( return LabelRepositoriesProvider(
child: DocumentDetailedItem( child: DocumentGridItem(
isLabelClickable: isLabelClickable, isLabelClickable: isLabelClickable,
document: document, document: document,
onTap: onTap, onTap: onTap,
@@ -185,6 +189,7 @@ class DefaultAdaptiveDocumentsView extends AdaptiveDocumentsView {
super.selectedDocumentIds, super.selectedDocumentIds,
super.viewType, super.viewType,
super.enableHeroAnimation = true, super.enableHeroAnimation = true,
super.maxItemExtent = double.infinity,
}); });
@override @override

View File

@@ -1,4 +1,3 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:paperless_mobile/features/documents/view/widgets/document_preview.dart'; import 'package:paperless_mobile/features/documents/view/widgets/document_preview.dart';
import 'package:paperless_mobile/features/documents/view/widgets/items/document_item.dart'; import 'package:paperless_mobile/features/documents/view/widgets/items/document_item.dart';