Browse Source

neon_news: make FolderFeedsWrapper a record

pull/380/head
Nikolas Rimikis 1 year ago
parent
commit
ec862b7a1f
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 15
      packages/neon/neon_news/lib/sort/folders.dart
  2. 32
      packages/neon/neon_news/lib/widgets/folders_view.dart

15
packages/neon/neon_news/lib/sort/folders.dart

@ -2,8 +2,8 @@ part of '../neon_news.dart';
final foldersSortBox = SortBox<FoldersSortProperty, FolderFeedsWrapper>( final foldersSortBox = SortBox<FoldersSortProperty, FolderFeedsWrapper>(
{ {
FoldersSortProperty.alphabetical: (final folderFeedsWrapper) => folderFeedsWrapper.folder.name.toLowerCase(), FoldersSortProperty.alphabetical: (final folderFeedsWrapper) => folderFeedsWrapper.$1.name.toLowerCase(),
FoldersSortProperty.unreadCount: (final folderFeedsWrapper) => folderFeedsWrapper.feedsUnreadCountSum, FoldersSortProperty.unreadCount: (final folderFeedsWrapper) => folderFeedsWrapper.$3,
}, },
{ {
FoldersSortProperty.alphabetical: Box(FoldersSortProperty.unreadCount, SortBoxOrder.descending), FoldersSortProperty.alphabetical: Box(FoldersSortProperty.unreadCount, SortBoxOrder.descending),
@ -11,13 +11,4 @@ final foldersSortBox = SortBox<FoldersSortProperty, FolderFeedsWrapper>(
}, },
); );
class FolderFeedsWrapper { typedef FolderFeedsWrapper = (NextcloudNewsFolder folder, List<NextcloudNewsFeed> feeds, int unreadCount);
FolderFeedsWrapper(
this.folder,
this.feeds,
);
final NextcloudNewsFolder folder;
final List<NextcloudNewsFeed> feeds;
int get feedsUnreadCountSum => feeds.fold(0, (final a, final b) => a + b.unreadCount!);
}

32
packages/neon/neon_news/lib/widgets/folders_view.dart

@ -19,14 +19,12 @@ class NewsFoldersView extends StatelessWidget {
sortBoxOrderOption: bloc.options.foldersSortBoxOrderOption, sortBoxOrderOption: bloc.options.foldersSortBoxOrderOption,
input: feeds.data == null input: feeds.data == null
? null ? null
: folders.data : folders.data?.map((final folder) {
?.map( final feedsInFolder = feeds.data!.where((final feed) => feed.folderId == folder.id).toList();
(final folder) => FolderFeedsWrapper( final unreadCount = feedsInFolder.fold(0, (final a, final b) => a + b.unreadCount!);
folder,
feeds.data!.where((final feed) => feed.folderId == folder.id).toList(), return (folder, feedsInFolder, unreadCount);
), }).toList(),
)
.toList(),
builder: (final context, final sorted) => NeonListView<FolderFeedsWrapper>( builder: (final context, final sorted) => NeonListView<FolderFeedsWrapper>(
scrollKey: 'news-folders', scrollKey: 'news-folders',
withFloatingActionButton: true, withFloatingActionButton: true,
@ -44,10 +42,10 @@ class NewsFoldersView extends StatelessWidget {
final BuildContext context, final BuildContext context,
final FolderFeedsWrapper folderFeedsWrapper, final FolderFeedsWrapper folderFeedsWrapper,
) { ) {
final unreadCount = folderFeedsWrapper.feedsUnreadCountSum; final (folder, feeds, unreadCount) = folderFeedsWrapper;
return ListTile( return ListTile(
title: Text( title: Text(
folderFeedsWrapper.folder.name, folder.name,
style: unreadCount == 0 style: unreadCount == 0
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor) ? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
: null, : null,
@ -68,7 +66,7 @@ class NewsFoldersView extends StatelessWidget {
), ),
Center( Center(
child: Text( child: Text(
folderFeedsWrapper.feeds.length.toString(), feeds.length.toString(),
style: TextStyle( style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary, color: Theme.of(context).colorScheme.onPrimary,
), ),
@ -95,19 +93,19 @@ class NewsFoldersView extends StatelessWidget {
if (await showConfirmationDialog( if (await showConfirmationDialog(
context, context,
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
AppLocalizations.of(context).folderDeleteConfirm(folderFeedsWrapper.folder.name), AppLocalizations.of(context).folderDeleteConfirm(folder.name),
)) { )) {
bloc.deleteFolder(folderFeedsWrapper.folder.id); bloc.deleteFolder(folder.id);
} }
break; break;
case NewsFolderAction.rename: case NewsFolderAction.rename:
final result = await showRenameDialog( final result = await showRenameDialog(
context: context, context: context,
title: AppLocalizations.of(context).folderRename, title: AppLocalizations.of(context).folderRename,
value: folderFeedsWrapper.folder.name, value: folder.name,
); );
if (result != null) { if (result != null) {
bloc.renameFolder(folderFeedsWrapper.folder.id, result); bloc.renameFolder(folder.id, result);
} }
break; break;
} }
@ -115,7 +113,7 @@ class NewsFoldersView extends StatelessWidget {
), ),
onLongPress: () { onLongPress: () {
if (unreadCount > 0) { if (unreadCount > 0) {
bloc.markFolderAsRead(folderFeedsWrapper.folder.id); bloc.markFolderAsRead(folder.id);
} }
}, },
onTap: () async { onTap: () async {
@ -123,7 +121,7 @@ class NewsFoldersView extends StatelessWidget {
MaterialPageRoute( MaterialPageRoute(
builder: (final context) => NewsFolderPage( builder: (final context) => NewsFolderPage(
bloc: bloc, bloc: bloc,
folder: folderFeedsWrapper.folder, folder: folder,
), ),
), ),
); );

Loading…
Cancel
Save