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.

193 lines
6.6 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<NewsBloc, List<NextcloudNewsFolder>>(
stream: bloc.folders,
builder: (final context, final folders) => ResultBuilder<NewsBloc, List<NextcloudNewsFeed>>(
stream: bloc.feeds,
builder: (final context, final feeds) => Scaffold(
3 years ago
resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton(
onPressed: () async {
final result = await showDialog<List>(
context: context,
builder: (final context) => NewsAddFeedDialog(
bloc: bloc,
folderID: folderID,
),
);
if (result != null) {
bloc.addFeed(result[0] as String, result[1] as int?);
}
},
child: const Icon(Icons.add),
),
body: SortBoxBuilder<FeedsSortProperty, NextcloudNewsFeed>(
sortBox: feedsSortBox,
sortPropertyOption: bloc.options.feedsSortPropertyOption,
sortBoxOrderOption: bloc.options.feedsSortBoxOrderOption,
input: folders.data == null
? null
: feeds.data?.where((final f) => folderID == null || f.folderId == folderID).toList(),
builder: (final context, final sorted) => NeonListView<NextcloudNewsFeed>(
scrollKey: 'news-feeds',
withFloatingActionButton: true,
items: sorted,
isLoading: feeds.loading || folders.loading,
error: feeds.error ?? folders.error,
onRefresh: bloc.refresh,
builder: (final context, final feed) => _buildFeed(
context,
feed,
folders.data!,
),
3 years ago
),
),
),
),
);
Widget _buildFeed(
final BuildContext context,
final NextcloudNewsFeed feed,
final List<NextcloudNewsFolder> 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(AppLocalizations.of(context).newsUnreadArticles(feed.unreadCount!))
: Container(),
leading: NewsFeedIcon(
feed: feed,
borderRadius: const BorderRadius.all(Radius.circular(8)),
3 years ago
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (feed.updateErrorCount > 0) ...[
3 years ago
IconButton(
iconSize: 30,
onPressed: () async {
await showDialog(
context: context,
builder: (final context) => NewsFeedUpdateErrorDialog(
feed: feed,
),
);
},
icon: Text(
feed.updateErrorCount.toString(),
3 years ago
style: const TextStyle(
color: Colors.red,
),
),
),
],
PopupMenuButton<NewsFeedAction>(
3 years ago
itemBuilder: (final context) => [
PopupMenuItem(
value: NewsFeedAction.showURL,
3 years ago
child: Text(AppLocalizations.of(context).newsShowFeedURL),
),
PopupMenuItem(
value: NewsFeedAction.delete,
3 years ago
child: Text(AppLocalizations.of(context).delete),
),
PopupMenuItem(
value: NewsFeedAction.rename,
3 years ago
child: Text(AppLocalizations.of(context).rename),
),
if (folders.isNotEmpty) ...[
PopupMenuItem(
value: NewsFeedAction.move,
3 years ago
child: Text(AppLocalizations.of(context).move),
),
],
],
onSelected: (final action) async {
switch (action) {
case NewsFeedAction.showURL:
3 years ago
await showDialog(
context: context,
builder: (final context) => NewsFeedShowURLDialog(
feed: feed,
),
);
break;
case NewsFeedAction.delete:
// ignore: use_build_context_synchronously
3 years ago
if (await showConfirmationDialog(
context,
// ignore: use_build_context_synchronously
AppLocalizations.of(context).newsRemoveFeedConfirm(feed.title),
3 years ago
)) {
bloc.removeFeed(feed.id);
3 years ago
}
break;
case NewsFeedAction.rename:
3 years ago
final result = await showRenameDialog(
context: context,
title: AppLocalizations.of(context).newsRenameFeed,
value: feed.title,
3 years ago
);
if (result != null) {
bloc.renameFeed(feed.id, result);
3 years ago
}
break;
case NewsFeedAction.move:
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
}
break;
}
},
),
],
),
onLongPress: () {
if (feed.unreadCount! > 0) {
bloc.markFeedAsRead(feed.id);
3 years ago
}
},
onTap: () async {
await Navigator.of(context).push(
MaterialPageRoute(
builder: (final context) => NewsFeedPage(
bloc: bloc,
feed: feed,
),
),
);
},
);
}
enum NewsFeedAction {
3 years ago
showURL,
delete,
rename,
move,
}