A framework for building convergent cross-platform Nextcloud clients using Flutter.
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.

175 lines
5.9 KiB

part of '../neon_news.dart';
3 years ago
class NewsFeedsView extends StatelessWidget {
const NewsFeedsView({
required this.bloc,
this.folderID,
super.key,
});
final NewsBloc bloc;
final int? folderID;
@override
Widget build(final BuildContext context) => ResultBuilder<List<news.Folder>>.behaviorSubject(
subject: bloc.folders,
builder: (final context, final folders) => ResultBuilder<List<news.Feed>>.behaviorSubject(
subject: bloc.feeds,
builder: (final context, final feeds) => SortBoxBuilder<FeedsSortProperty, news.Feed>(
sortBox: feedsSortBox,
sortProperty: bloc.options.feedsSortPropertyOption,
sortBoxOrder: bloc.options.feedsSortBoxOrderOption,
input: folders.hasData
? feeds.data?.where((final f) => folderID == null || f.folderId == folderID).toList()
: null,
builder: (final context, final sorted) => NeonListView(
scrollKey: 'news-feeds',
isLoading: feeds.isLoading || folders.isLoading,
error: feeds.error ?? folders.error,
onRefresh: bloc.refresh,
itemCount: sorted.length,
itemBuilder: (final context, final index) => _buildFeed(
context,
sorted[index],
folders.requireData,
3 years ago
),
),
),
),
);
Widget _buildFeed(
final BuildContext context,
final news.Feed feed,
final List<news.Folder> folders,
3 years ago
) =>
ListTile(
title: Text(
feed.title,
3 years ago
style: feed.unreadCount! == 0
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
3 years ago
: null,
),
subtitle: feed.unreadCount! > 0
? Text(NewsLocalizations.of(context).articlesUnread(feed.unreadCount!))
: const SizedBox(),
leading: NewsFeedIcon(feed: feed),
3 years ago
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (feed.updateErrorCount > 0) ...[
3 years ago
IconButton(
onPressed: () async {
await showDialog<void>(
3 years ago
context: context,
builder: (final context) => NewsFeedUpdateErrorDialog(
feed: feed,
),
);
},
tooltip: NewsLocalizations.of(context).feedShowErrorMessage,
iconSize: 30,
3 years ago
icon: Text(
feed.updateErrorCount.toString(),
style: TextStyle(
color: Theme.of(context).colorScheme.error,
3 years ago
),
),
),
],
PopupMenuButton<NewsFeedAction>(
3 years ago
itemBuilder: (final context) => [
PopupMenuItem(
value: NewsFeedAction.showURL,
child: Text(NewsLocalizations.of(context).feedShowURL),
3 years ago
),
PopupMenuItem(
value: NewsFeedAction.delete,
child: Text(NewsLocalizations.of(context).actionDelete),
3 years ago
),
PopupMenuItem(
value: NewsFeedAction.rename,
child: Text(NewsLocalizations.of(context).actionRename),
3 years ago
),
if (folders.isNotEmpty) ...[
PopupMenuItem(
value: NewsFeedAction.move,
child: Text(NewsLocalizations.of(context).actionMove),
3 years ago
),
],
],
onSelected: (final action) async {
switch (action) {
case NewsFeedAction.showURL:
await showDialog<void>(
3 years ago
context: context,
builder: (final context) => NewsFeedShowURLDialog(
feed: feed,
),
);
case NewsFeedAction.delete:
if (!context.mounted) {
return;
}
3 years ago
if (await showConfirmationDialog(
context,
NewsLocalizations.of(context).feedRemoveConfirm(feed.title),
3 years ago
)) {
bloc.removeFeed(feed.id);
3 years ago
}
case NewsFeedAction.rename:
if (!context.mounted) {
return;
}
3 years ago
final result = await showRenameDialog(
context: context,
title: NewsLocalizations.of(context).feedRename,
value: feed.title,
3 years ago
);
if (result != null) {
bloc.renameFeed(feed.id, result);
3 years ago
}
case NewsFeedAction.move:
if (!context.mounted) {
return;
}
3 years ago
final result = await showDialog<List<int?>>(
context: context,
builder: (final context) => NewsMoveFeedDialog(
folders: folders,
feed: feed,
),
);
if (result != null) {
bloc.moveFeed(feed.id, result[0]);
3 years ago
}
}
},
),
],
),
onLongPress: () {
if (feed.unreadCount! > 0) {
bloc.markFeedAsRead(feed.id);
3 years ago
}
},
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute<void>(
3 years ago
builder: (final context) => NewsFeedPage(
bloc: bloc,
feed: feed,
),
),
);
},
);
}
enum NewsFeedAction {
3 years ago
showURL,
delete,
rename,
move,
}