-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/saved filters reordering #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ba55ecc
feat(app): add event for reordering saved filters
fulleni a2a508a
feat(app): implement saved filters reordering in AppBloc
fulleni b7b9b87
Refactor(filters): implement reorderable UI for saved filters
fulleni c391cfe
refactor(filter): remove saved filter management from filter page
fulleni af8312f
feat(account): add entry point for saved filters management
fulleni 8ed6c8d
refactor(router): update route constants for saved filters
fulleni eb65f46
refactor(account): move saved filters management to account section
fulleni 7d9078f
feat(l10n): add localizations for saved filters feature
fulleni dfe48df
refactor(account): update saved filters tile and routing
fulleni 7c0e963
feat(localization): update localization keys for saved filters page
fulleni b73c10b
fix(account): use correct localization key for saved filters page title
fulleni 5ced3f1
feat(l10n): add Arabic translations for saved filters feature
fulleni 954b39b
build: l10n
fulleni c3c58f5
refactor(filters): relocate management and introduce reordering
fulleni c00b19e
feat(readme): update features description for saved filters and manag…
fulleni 09d6c11
refactor(router): move saved filters route under account section
fulleni 7cce4e2
style(account): update filter icon in account page
fulleni 59f0f3a
feat(account): disable default drag handles in saved filters list
fulleni d899176
style: format
fulleni 95e68bd
refactor(router): reorganize saved filters route definition
fulleni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| import 'package:core/core.dart'; | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:flutter_bloc/flutter_bloc.dart'; | ||
| import 'package:flutter_news_app_mobile_client_full_source_code/app/bloc/app_bloc.dart'; | ||
| import 'package:flutter_news_app_mobile_client_full_source_code/headlines-feed/widgets/save_filter_dialog.dart'; | ||
| import 'package:flutter_news_app_mobile_client_full_source_code/l10n/l10n.dart'; | ||
| import 'package:ui_kit/ui_kit.dart'; | ||
|
|
||
| /// {@template saved_filters_page} | ||
| /// A page for managing saved feed filters, allowing users to reorder, | ||
| /// rename, or delete them. | ||
| /// | ||
| /// Reordering is handled via a [ReorderableListView], which dispatches a | ||
| /// [SavedFiltersReordered] event to the [AppBloc] to persist the new order. | ||
| /// Renaming and deletion are handled via a [PopupMenuButton] on each list item. | ||
| /// {@endtemplate} | ||
| class SavedFiltersPage extends StatelessWidget { | ||
| /// {@macro saved_filters_page} | ||
| const SavedFiltersPage({super.key}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final l10n = AppLocalizationsX(context).l10n; | ||
| final theme = Theme.of(context); | ||
|
|
||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text( | ||
| // Use the correct localization key for the page title. | ||
| l10n.savedFiltersPageTitle, | ||
| style: theme.textTheme.titleLarge, | ||
| ), | ||
| ), | ||
| body: BlocBuilder<AppBloc, AppState>( | ||
| builder: (context, state) { | ||
| final savedFilters = state.userContentPreferences?.savedFilters ?? []; | ||
|
|
||
| if (savedFilters.isEmpty) { | ||
| return InitialStateWidget( | ||
| icon: Icons.filter_list_off_outlined, | ||
| headline: l10n.savedFiltersEmptyHeadline, | ||
| subheadline: l10n.savedFiltersEmptySubheadline, | ||
| ); | ||
| } | ||
|
|
||
| return ReorderableListView.builder( | ||
| // Disable the default trailing drag handles to use only the | ||
| // custom leading handle. | ||
| buildDefaultDragHandles: false, | ||
| itemCount: savedFilters.length, | ||
| itemBuilder: (context, index) { | ||
| final filter = savedFilters[index]; | ||
| return ListTile( | ||
| // A key is required for ReorderableListView to work correctly. | ||
| key: ValueKey(filter.id), | ||
| leading: ReorderableDragStartListener( | ||
| index: index, | ||
| child: const Icon(Icons.drag_handle), | ||
| ), | ||
| title: Text(filter.name), | ||
| trailing: PopupMenuButton<String>( | ||
| onSelected: (value) { | ||
| switch (value) { | ||
| case 'rename': | ||
| showDialog<void>( | ||
| context: context, | ||
| builder: (_) => SaveFilterDialog( | ||
| initialValue: filter.name, | ||
| onSave: (newName) { | ||
| final updatedFilter = filter.copyWith( | ||
| name: newName, | ||
| ); | ||
| context.read<AppBloc>().add( | ||
| SavedFilterUpdated(filter: updatedFilter), | ||
| ); | ||
| }, | ||
| ), | ||
| ); | ||
| case 'delete': | ||
| context.read<AppBloc>().add( | ||
| SavedFilterDeleted(filterId: filter.id), | ||
| ); | ||
| } | ||
| }, | ||
| itemBuilder: (BuildContext context) => | ||
| <PopupMenuEntry<String>>[ | ||
| PopupMenuItem<String>( | ||
| value: 'rename', | ||
| child: Text(l10n.savedFiltersMenuRename), | ||
| ), | ||
| PopupMenuItem<String>( | ||
| value: 'delete', | ||
| child: Text( | ||
| l10n.savedFiltersMenuDelete, | ||
| style: TextStyle(color: theme.colorScheme.error), | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ); | ||
| }, | ||
| onReorder: (oldIndex, newIndex) { | ||
| // This adjustment is necessary when moving an item downwards | ||
| // in the list. | ||
| if (oldIndex < newIndex) { | ||
| newIndex -= 1; | ||
| } | ||
|
|
||
| // Create a mutable copy of the list. | ||
| final reorderedList = List<SavedFilter>.from(savedFilters); | ||
|
|
||
| // Remove the item from its old position and insert it into the | ||
| // new position. | ||
| final movedFilter = reorderedList.removeAt(oldIndex); | ||
| reorderedList.insert(newIndex, movedFilter); | ||
|
|
||
| // Dispatch the event to the AppBloc to persist the new order. | ||
| context.read<AppBloc>().add( | ||
| SavedFiltersReordered(reorderedFilters: reorderedList), | ||
| ); | ||
| }, | ||
| ); | ||
| }, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.