mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 16:07:57 -06:00
feat: Update translations, finish saved views rework, some other fixes
This commit is contained in:
@@ -9,19 +9,11 @@ class SavedViewChangedDialog extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text("Discard changes?"), //TODO: INTL
|
||||
content: Text(
|
||||
"Some filters of the currently active view have changed. By resetting the filter, these changes will be lost. Do you still wish to continue?", //TODO: INTL
|
||||
),
|
||||
title: Text(S.of(context)!.discardChanges),
|
||||
content: Text(S.of(context)!.savedViewChangedDialogContent),
|
||||
actionsOverflowButtonSpacing: 8,
|
||||
actions: [
|
||||
const DialogCancelButton(),
|
||||
// TextButton(
|
||||
// child: Text(S.of(context)!.saveChanges),
|
||||
// onPressed: () {
|
||||
// Navigator.pop(context, false);
|
||||
// },
|
||||
// ),
|
||||
DialogConfirmButton(
|
||||
label: S.of(context)!.resetFilter,
|
||||
style: DialogConfirmButtonStyle.danger,
|
||||
|
||||
@@ -3,7 +3,6 @@ import 'dart:math';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/selection/confirm_delete_saved_view_dialog.dart';
|
||||
import 'package:paperless_mobile/routes/typed/branches/saved_views_route.dart';
|
||||
|
||||
class SavedViewChip extends StatefulWidget {
|
||||
@@ -102,7 +101,6 @@ class _SavedViewChipState extends State<SavedViewChip>
|
||||
_buildLabel(context, effectiveForegroundColor)
|
||||
.paddedSymmetrically(
|
||||
horizontal: 12,
|
||||
vertical: 0,
|
||||
),
|
||||
],
|
||||
).paddedOnly(left: 8),
|
||||
@@ -120,6 +118,7 @@ class _SavedViewChipState extends State<SavedViewChip>
|
||||
|
||||
Widget _buildTrailing(Color effectiveForegroundColor) {
|
||||
return IconButton(
|
||||
padding: EdgeInsets.zero,
|
||||
icon: AnimatedBuilder(
|
||||
animation: _animation,
|
||||
builder: (context, child) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/widgets/hint_card.dart';
|
||||
import 'package:paperless_mobile/core/widgets/shimmer_placeholder.dart';
|
||||
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
|
||||
import 'package:paperless_mobile/features/documents/view/widgets/saved_views/saved_view_chip.dart';
|
||||
import 'package:paperless_mobile/features/saved_view/cubit/saved_view_cubit.dart';
|
||||
@@ -46,99 +46,185 @@ class _SavedViewsWidgetState extends State<SavedViewsWidget>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PageStorage(
|
||||
bucket: PageStorageBucket(),
|
||||
child: ExpansionTile(
|
||||
controller: widget.controller,
|
||||
tilePadding: const EdgeInsets.only(left: 8),
|
||||
trailing: RotationTransition(
|
||||
turns: _animation,
|
||||
child: const Icon(Icons.expand_more),
|
||||
).paddedOnly(right: 8),
|
||||
onExpansionChanged: (isExpanded) {
|
||||
if (isExpanded) {
|
||||
_animationController.forward();
|
||||
} else {
|
||||
_animationController.reverse().then((value) => setState(() {}));
|
||||
}
|
||||
},
|
||||
title: Text(
|
||||
S.of(context)!.views,
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
leading: Icon(
|
||||
Icons.saved_search,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
).padded(),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
BlocBuilder<SavedViewCubit, SavedViewState>(
|
||||
builder: (context, state) {
|
||||
return state.map(
|
||||
initial: (_) => const Placeholder(),
|
||||
loading: (_) => const Placeholder(),
|
||||
loaded: (value) {
|
||||
if (value.savedViews.isEmpty) {
|
||||
return Text(S.of(context)!.noItemsFound)
|
||||
.paddedOnly(left: 16);
|
||||
}
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 16),
|
||||
height: kMinInteractiveDimension,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) => true,
|
||||
child: CustomScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
slivers: [
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
SliverList.separated(
|
||||
itemBuilder: (context, index) {
|
||||
final view =
|
||||
value.savedViews.values.elementAt(index);
|
||||
final isSelected =
|
||||
(widget.filter.selectedView ?? -1) == view.id;
|
||||
return SavedViewChip(
|
||||
view: view,
|
||||
onViewSelected: widget.onViewSelected,
|
||||
selected: isSelected,
|
||||
hasChanged: isSelected &&
|
||||
view.toDocumentFilter() != widget.filter,
|
||||
onUpdateView: widget.onUpdateView,
|
||||
onDeleteView: widget.onDeleteView,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(width: 8),
|
||||
itemCount: value.savedViews.length,
|
||||
),
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
],
|
||||
return BlocBuilder<SavedViewCubit, SavedViewState>(
|
||||
builder: (context, state) {
|
||||
final selectedView = state.mapOrNull(
|
||||
loaded: (value) {
|
||||
if (widget.filter.selectedView != null) {
|
||||
return value.savedViews[widget.filter.selectedView!];
|
||||
}
|
||||
},
|
||||
);
|
||||
final selectedViewHasChanged = selectedView != null &&
|
||||
selectedView.toDocumentFilter() != widget.filter;
|
||||
return PageStorage(
|
||||
bucket: PageStorageBucket(),
|
||||
child: ExpansionTile(
|
||||
controller: widget.controller,
|
||||
tilePadding: const EdgeInsets.only(left: 8),
|
||||
trailing: RotationTransition(
|
||||
turns: _animation,
|
||||
child: const Icon(Icons.expand_more),
|
||||
).paddedOnly(right: 8),
|
||||
onExpansionChanged: (isExpanded) {
|
||||
if (isExpanded) {
|
||||
_animationController.forward();
|
||||
} else {
|
||||
_animationController.reverse().then((value) => setState(() {}));
|
||||
}
|
||||
},
|
||||
title: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Flexible(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
S.of(context)!.views,
|
||||
style: Theme.of(context).textTheme.labelLarge,
|
||||
),
|
||||
if (selectedView != null)
|
||||
Text(
|
||||
selectedView.name,
|
||||
style:
|
||||
Theme.of(context).textTheme.labelMedium?.copyWith(
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onBackground
|
||||
.withOpacity(0.5),
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
AnimatedScale(
|
||||
scale: selectedViewHasChanged ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 150),
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
final newView = selectedView!.copyWith(
|
||||
filterRules: FilterRule.fromFilter(widget.filter),
|
||||
);
|
||||
widget.onUpdateView(newView);
|
||||
},
|
||||
child: Text(S.of(context)!.saveChanges),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
leading: Icon(
|
||||
Icons.saved_search,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
).padded(),
|
||||
expandedCrossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
state
|
||||
.maybeMap(
|
||||
loaded: (value) {
|
||||
if (value.savedViews.isEmpty) {
|
||||
return Text(S.of(context)!.noItemsFound)
|
||||
.paddedOnly(left: 16);
|
||||
}
|
||||
|
||||
return SizedBox(
|
||||
height: kMinInteractiveDimension,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) => true,
|
||||
child: CustomScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
slivers: [
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
SliverList.separated(
|
||||
itemBuilder: (context, index) {
|
||||
final view =
|
||||
value.savedViews.values.elementAt(index);
|
||||
final isSelected =
|
||||
(widget.filter.selectedView ?? -1) ==
|
||||
view.id;
|
||||
return SavedViewChip(
|
||||
view: view,
|
||||
onViewSelected: widget.onViewSelected,
|
||||
selected: isSelected,
|
||||
hasChanged: isSelected &&
|
||||
view.toDocumentFilter() !=
|
||||
widget.filter,
|
||||
onUpdateView: widget.onUpdateView,
|
||||
onDeleteView: widget.onDeleteView,
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) =>
|
||||
const SizedBox(width: 8),
|
||||
itemCount: value.savedViews.length,
|
||||
),
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (_) => Text(S.of(context)!.couldNotLoadSavedViews)
|
||||
.paddedOnly(left: 16),
|
||||
orElse: _buildLoadingState,
|
||||
)
|
||||
.paddedOnly(top: 16),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Tooltip(
|
||||
message: S.of(context)!.createFromCurrentFilter,
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
CreateSavedViewRoute(widget.filter).push(context);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(S.of(context)!.newView),
|
||||
),
|
||||
).padded(4),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoadingState() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 16),
|
||||
height: kMinInteractiveDimension,
|
||||
child: NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) => true,
|
||||
child: ShimmerPlaceholder(
|
||||
child: CustomScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
slivers: [
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
SliverList.separated(
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
width: 130,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
color: Colors.white,
|
||||
),
|
||||
);
|
||||
},
|
||||
error: (_) => const Placeholder(),
|
||||
);
|
||||
},
|
||||
),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Tooltip(
|
||||
message: "Create from current filter", //TODO: INTL
|
||||
child: TextButton.icon(
|
||||
onPressed: () {
|
||||
CreateSavedViewRoute(widget.filter).push(context);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: Text(S.of(context)!.newView),
|
||||
separatorBuilder: (context, index) => const SizedBox(width: 8),
|
||||
),
|
||||
).padded(4),
|
||||
const SliverToBoxAdapter(
|
||||
child: SizedBox(width: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user