You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
5.0 KiB
155 lines
5.0 KiB
2 years ago
|
part of '../neon_news.dart';
|
||
2 years ago
|
|
||
|
class NewsFoldersView extends StatelessWidget {
|
||
|
const NewsFoldersView({
|
||
|
required this.bloc,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final NewsBloc bloc;
|
||
|
|
||
|
@override
|
||
|
Widget build(final BuildContext context) => Scaffold(
|
||
|
resizeToAvoidBottomInset: false,
|
||
|
floatingActionButton: FloatingActionButton(
|
||
|
onPressed: () async {
|
||
|
final result = await showDialog<String>(
|
||
|
context: context,
|
||
|
builder: (final context) => const NewsCreateFolderDialog(),
|
||
|
);
|
||
|
if (result != null) {
|
||
|
bloc.createFolder(result);
|
||
|
}
|
||
|
},
|
||
|
child: const Icon(Icons.add),
|
||
|
),
|
||
2 years ago
|
body: ResultBuilder<NewsBloc, List<NextcloudNewsFolder>>(
|
||
2 years ago
|
stream: bloc.folders,
|
||
2 years ago
|
builder: (final context, final folders) => ResultBuilder<NewsBloc, List<NextcloudNewsFeed>>(
|
||
2 years ago
|
stream: bloc.feeds,
|
||
|
builder: (final context, final feeds) => SortBoxBuilder<FoldersSortProperty, FolderFeedsWrapper>(
|
||
2 years ago
|
sortBox: foldersSortBox,
|
||
|
sortPropertyOption: bloc.options.foldersSortPropertyOption,
|
||
|
sortBoxOrderOption: bloc.options.foldersSortBoxOrderOption,
|
||
2 years ago
|
input: feeds.data == null
|
||
2 years ago
|
? null
|
||
2 years ago
|
: folders.data
|
||
2 years ago
|
?.map(
|
||
|
(final folder) => FolderFeedsWrapper(
|
||
|
folder,
|
||
2 years ago
|
feeds.data!.where((final feed) => feed.folderId == folder.id).toList(),
|
||
2 years ago
|
),
|
||
2 years ago
|
)
|
||
|
.toList(),
|
||
|
builder: (final context, final sorted) => CustomListView<FolderFeedsWrapper>(
|
||
|
scrollKey: 'news-folders',
|
||
|
withFloatingActionButton: true,
|
||
|
items: sorted,
|
||
2 years ago
|
isLoading: feeds.loading || folders.loading,
|
||
|
error: feeds.error ?? folders.error,
|
||
2 years ago
|
onRefresh: bloc.refresh,
|
||
2 years ago
|
builder: _buildFolder,
|
||
2 years ago
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
Widget _buildFolder(
|
||
|
final BuildContext context,
|
||
|
final FolderFeedsWrapper folderFeedsWrapper,
|
||
|
) {
|
||
|
final unreadCount = feedsUnreadCountSum(folderFeedsWrapper.feeds);
|
||
|
return ListTile(
|
||
|
title: Text(
|
||
2 years ago
|
folderFeedsWrapper.folder.name,
|
||
2 years ago
|
style: unreadCount == 0
|
||
2 years ago
|
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
|
||
2 years ago
|
: null,
|
||
|
),
|
||
|
subtitle: unreadCount > 0
|
||
|
? Text(
|
||
|
AppLocalizations.of(context).newsUnreadArticles(unreadCount),
|
||
|
)
|
||
|
: Container(),
|
||
|
leading: SizedBox(
|
||
|
width: 48,
|
||
|
height: 48,
|
||
|
child: Stack(
|
||
|
children: [
|
||
|
Icon(
|
||
|
Icons.folder,
|
||
|
size: 48,
|
||
|
color: Theme.of(context).colorScheme.primary,
|
||
|
),
|
||
|
Center(
|
||
2 years ago
|
child: Text(
|
||
|
folderFeedsWrapper.feeds.length.toString(),
|
||
|
style: TextStyle(
|
||
|
color: Theme.of(context).colorScheme.onPrimary,
|
||
|
),
|
||
|
),
|
||
2 years ago
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
2 years ago
|
trailing: PopupMenuButton<NewsFolderAction>(
|
||
2 years ago
|
itemBuilder: (final context) => [
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFolderAction.delete,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).delete),
|
||
|
),
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFolderAction.rename,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).rename),
|
||
|
),
|
||
|
],
|
||
|
onSelected: (final action) async {
|
||
|
switch (action) {
|
||
2 years ago
|
case NewsFolderAction.delete:
|
||
2 years ago
|
// ignore: use_build_context_synchronously
|
||
2 years ago
|
if (await showConfirmationDialog(
|
||
|
context,
|
||
2 years ago
|
// ignore: use_build_context_synchronously
|
||
2 years ago
|
AppLocalizations.of(context).newsDeleteFolderConfirm(folderFeedsWrapper.folder.name),
|
||
2 years ago
|
)) {
|
||
2 years ago
|
bloc.deleteFolder(folderFeedsWrapper.folder.id);
|
||
2 years ago
|
}
|
||
|
break;
|
||
2 years ago
|
case NewsFolderAction.rename:
|
||
2 years ago
|
final result = await showRenameDialog(
|
||
|
context: context,
|
||
|
title: AppLocalizations.of(context).newsRenameFolder,
|
||
2 years ago
|
value: folderFeedsWrapper.folder.name,
|
||
2 years ago
|
);
|
||
|
if (result != null) {
|
||
2 years ago
|
bloc.renameFolder(folderFeedsWrapper.folder.id, result);
|
||
2 years ago
|
}
|
||
|
break;
|
||
|
}
|
||
|
},
|
||
|
),
|
||
|
onLongPress: () {
|
||
|
if (unreadCount > 0) {
|
||
2 years ago
|
bloc.markFolderAsRead(folderFeedsWrapper.folder.id);
|
||
2 years ago
|
}
|
||
|
},
|
||
|
onTap: () async {
|
||
|
await Navigator.of(context).push(
|
||
|
MaterialPageRoute(
|
||
|
builder: (final context) => NewsFolderPage(
|
||
|
bloc: bloc,
|
||
|
folder: folderFeedsWrapper.folder,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
enum NewsFolderAction {
|
||
2 years ago
|
delete,
|
||
|
rename,
|
||
|
}
|