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