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
193 lines
6.6 KiB
2 years ago
|
part of '../neon_news.dart';
|
||
2 years ago
|
|
||
|
class NewsFeedsView extends StatelessWidget {
|
||
|
const NewsFeedsView({
|
||
|
required this.bloc,
|
||
|
this.folderID,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final NewsBloc bloc;
|
||
|
final int? folderID;
|
||
|
|
||
|
@override
|
||
2 years ago
|
Widget build(final BuildContext context) => 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) => Scaffold(
|
||
2 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),
|
||
|
),
|
||
2 years ago
|
body: SortBoxBuilder<FeedsSortProperty, NextcloudNewsFeed>(
|
||
2 years ago
|
sortBox: feedsSortBox,
|
||
|
sortPropertyOption: bloc.options.feedsSortPropertyOption,
|
||
|
sortBoxOrderOption: bloc.options.feedsSortBoxOrderOption,
|
||
2 years ago
|
input: folders.data == null
|
||
2 years ago
|
? null
|
||
2 years ago
|
: feeds.data?.where((final f) => folderID == null || f.folderId == folderID).toList(),
|
||
2 years ago
|
builder: (final context, final sorted) => CustomListView<NextcloudNewsFeed>(
|
||
2 years ago
|
scrollKey: 'news-feeds',
|
||
|
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: (final context, final feed) => _buildFeed(
|
||
|
context,
|
||
|
feed,
|
||
2 years ago
|
folders.data!,
|
||
2 years ago
|
),
|
||
2 years ago
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
|
||
|
Widget _buildFeed(
|
||
|
final BuildContext context,
|
||
2 years ago
|
final NextcloudNewsFeed feed,
|
||
|
final List<NextcloudNewsFolder> folders,
|
||
2 years ago
|
) =>
|
||
|
ListTile(
|
||
|
title: Text(
|
||
2 years ago
|
feed.title,
|
||
2 years ago
|
style: feed.unreadCount! == 0
|
||
2 years ago
|
? Theme.of(context).textTheme.titleMedium!.copyWith(color: Theme.of(context).disabledColor)
|
||
2 years ago
|
: null,
|
||
|
),
|
||
|
subtitle: feed.unreadCount! > 0
|
||
|
? Text(AppLocalizations.of(context).newsUnreadArticles(feed.unreadCount!))
|
||
|
: Container(),
|
||
|
leading: NewsFeedIcon(
|
||
|
feed: feed,
|
||
2 years ago
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||
2 years ago
|
),
|
||
|
trailing: Row(
|
||
|
mainAxisSize: MainAxisSize.min,
|
||
|
children: [
|
||
2 years ago
|
if (feed.updateErrorCount > 0) ...[
|
||
2 years ago
|
IconButton(
|
||
|
iconSize: 30,
|
||
|
onPressed: () async {
|
||
|
await showDialog(
|
||
|
context: context,
|
||
|
builder: (final context) => NewsFeedUpdateErrorDialog(
|
||
|
feed: feed,
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
icon: Text(
|
||
2 years ago
|
feed.updateErrorCount.toString(),
|
||
2 years ago
|
style: const TextStyle(
|
||
|
color: Colors.red,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
2 years ago
|
PopupMenuButton<NewsFeedAction>(
|
||
2 years ago
|
itemBuilder: (final context) => [
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFeedAction.showURL,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).newsShowFeedURL),
|
||
|
),
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFeedAction.delete,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).delete),
|
||
|
),
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFeedAction.rename,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).rename),
|
||
|
),
|
||
|
if (folders.isNotEmpty) ...[
|
||
|
PopupMenuItem(
|
||
2 years ago
|
value: NewsFeedAction.move,
|
||
2 years ago
|
child: Text(AppLocalizations.of(context).move),
|
||
|
),
|
||
|
],
|
||
|
],
|
||
|
onSelected: (final action) async {
|
||
|
switch (action) {
|
||
2 years ago
|
case NewsFeedAction.showURL:
|
||
2 years ago
|
await showDialog(
|
||
|
context: context,
|
||
|
builder: (final context) => NewsFeedShowURLDialog(
|
||
|
feed: feed,
|
||
|
),
|
||
|
);
|
||
|
break;
|
||
2 years ago
|
case NewsFeedAction.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).newsRemoveFeedConfirm(feed.title),
|
||
2 years ago
|
)) {
|
||
2 years ago
|
bloc.removeFeed(feed.id);
|
||
2 years ago
|
}
|
||
|
break;
|
||
2 years ago
|
case NewsFeedAction.rename:
|
||
2 years ago
|
final result = await showRenameDialog(
|
||
|
context: context,
|
||
|
title: AppLocalizations.of(context).newsRenameFeed,
|
||
2 years ago
|
value: feed.title,
|
||
2 years ago
|
);
|
||
|
if (result != null) {
|
||
2 years ago
|
bloc.renameFeed(feed.id, result);
|
||
2 years ago
|
}
|
||
|
break;
|
||
2 years ago
|
case NewsFeedAction.move:
|
||
2 years ago
|
final result = await showDialog<List<int?>>(
|
||
|
context: context,
|
||
|
builder: (final context) => NewsMoveFeedDialog(
|
||
|
folders: folders,
|
||
|
feed: feed,
|
||
|
),
|
||
|
);
|
||
|
if (result != null) {
|
||
2 years ago
|
bloc.moveFeed(feed.id, result[0]);
|
||
2 years ago
|
}
|
||
|
break;
|
||
|
}
|
||
|
},
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
onLongPress: () {
|
||
|
if (feed.unreadCount! > 0) {
|
||
2 years ago
|
bloc.markFeedAsRead(feed.id);
|
||
2 years ago
|
}
|
||
|
},
|
||
|
onTap: () async {
|
||
|
await Navigator.of(context).push(
|
||
|
MaterialPageRoute(
|
||
|
builder: (final context) => NewsFeedPage(
|
||
|
bloc: bloc,
|
||
|
feed: feed,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
|
||
2 years ago
|
enum NewsFeedAction {
|
||
2 years ago
|
showURL,
|
||
|
delete,
|
||
|
rename,
|
||
|
move,
|
||
|
}
|