mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-09-01 08:54:08 +00:00
reload news
This commit is contained in:
parent
5a953226a5
commit
64c7595b6a
1 changed files with 107 additions and 86 deletions
|
|
@ -19,6 +19,15 @@ class _NewsViewState extends State<NewsView> {
|
|||
super.initState();
|
||||
// Mark all as read when entering the page
|
||||
newsService.markAllAsRead();
|
||||
_reloadNews();
|
||||
}
|
||||
|
||||
Future<void> _reloadNews() async {
|
||||
await newsService.fetchFeed();
|
||||
await newsService.markAllAsRead();
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -29,16 +38,24 @@ class _NewsViewState extends State<NewsView> {
|
|||
appBar: AppBar(
|
||||
title: Text(context.lang.settingsHelpNews),
|
||||
),
|
||||
body: entries.isEmpty
|
||||
? Center(
|
||||
body: RefreshIndicator(
|
||||
onRefresh: _reloadNews,
|
||||
child: entries.isEmpty
|
||||
? SingleChildScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
child: Container(
|
||||
height: MediaQuery.of(context).size.height * 0.7,
|
||||
alignment: Alignment.center,
|
||||
child: Text(
|
||||
'No news articles found.',
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
itemCount: entries.length,
|
||||
itemBuilder: (context, index) {
|
||||
|
|
@ -91,7 +108,9 @@ class _NewsViewState extends State<NewsView> {
|
|||
if (entry.pubDate != null) ...[
|
||||
Text(
|
||||
DateFormat.yMMMMd(
|
||||
Localizations.localeOf(context).toString(),
|
||||
Localizations.localeOf(
|
||||
context,
|
||||
).toString(),
|
||||
).format(entry.pubDate!),
|
||||
style: Theme.of(context).textTheme.bodySmall
|
||||
?.copyWith(
|
||||
|
|
@ -114,7 +133,8 @@ class _NewsViewState extends State<NewsView> {
|
|||
overflow: TextOverflow.ellipsis,
|
||||
style: Theme.of(context).textTheme.bodyMedium
|
||||
?.copyWith(
|
||||
color: context.color.onSurface.withValues(
|
||||
color: context.color.onSurface
|
||||
.withValues(
|
||||
alpha: 0.8,
|
||||
),
|
||||
),
|
||||
|
|
@ -128,6 +148,7 @@ class _NewsViewState extends State<NewsView> {
|
|||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue