Browse Source

Merge pull request #115 from jld3103/fix/news-article-without-url

Fix news article without url
pull/116/head
jld3103 2 years ago committed by GitHub
parent
commit
1e20e361ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/neon/lib/src/apps/news/blocs/article.dart
  2. 11
      packages/neon/lib/src/apps/news/pages/article.dart
  3. 13
      packages/neon/lib/src/apps/news/widgets/articles_view.dart
  4. 4
      packages/nextcloud/lib/src/nextcloud.openapi.dart
  5. 2
      packages/nextcloud/lib/src/nextcloud.openapi.g.dart
  6. 1
      packages/nextcloud/lib/src/nextcloud.openapi.json
  7. 1
      specs/news.json

2
packages/neon/lib/src/apps/news/blocs/article.dart

@ -64,7 +64,6 @@ class NewsArticleBloc extends $NewsArticleBloc {
_unreadSubject.add(article.unread); _unreadSubject.add(article.unread);
_starredSubject.add(article.starred); _starredSubject.add(article.starred);
url = article.url;
} }
void _wrapArticleAction(final Future Function() call) { void _wrapArticleAction(final Future Function() call) {
@ -79,7 +78,6 @@ class NewsArticleBloc extends $NewsArticleBloc {
final NextcloudClient _client; final NextcloudClient _client;
final NewsArticlesBloc _newsArticlesBloc; final NewsArticlesBloc _newsArticlesBloc;
late final String url;
final _unreadSubject = BehaviorSubject<bool>(); final _unreadSubject = BehaviorSubject<bool>();
final _starredSubject = BehaviorSubject<bool>(); final _starredSubject = BehaviorSubject<bool>();
final _errorsStreamController = StreamController<Exception>(); final _errorsStreamController = StreamController<Exception>();

11
packages/neon/lib/src/apps/news/pages/article.dart

@ -6,13 +6,16 @@ class NewsArticlePage extends StatefulWidget {
required this.articlesBloc, required this.articlesBloc,
required this.useWebView, required this.useWebView,
this.bodyData, this.bodyData,
this.url,
super.key, super.key,
}) : assert(useWebView || bodyData != null, 'bodyData has to be set when not using a WebView'); }) : assert(useWebView || bodyData != null, 'bodyData has to be set when not using a WebView'),
assert(!useWebView || url != null, 'url has to be set when using a WebView');
final NewsArticleBloc bloc; final NewsArticleBloc bloc;
final NewsArticlesBloc articlesBloc; final NewsArticlesBloc articlesBloc;
final bool useWebView; final bool useWebView;
final String? bodyData; final String? bodyData;
final String? url;
@override @override
State<NewsArticlePage> createState() => _NewsArticlePageState(); State<NewsArticlePage> createState() => _NewsArticlePageState();
@ -75,7 +78,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
return (await _webviewController!.currentUrl())!; return (await _webviewController!.currentUrl())!;
} }
return widget.bloc.url; return widget.url!;
} }
@override @override
@ -129,6 +132,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
); );
}, },
), ),
if (widget.url != null) ...[
IconButton( IconButton(
onPressed: () async { onPressed: () async {
await launchUrlString( await launchUrlString(
@ -145,6 +149,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
icon: const Icon(Icons.share), icon: const Icon(Icons.share),
), ),
], ],
],
), ),
body: widget.useWebView body: widget.useWebView
? Stack( ? Stack(
@ -155,7 +160,7 @@ class _NewsArticlePageState extends State<NewsArticlePage> {
javascriptMode: JavascriptMode.unrestricted, javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (final controller) async { onWebViewCreated: (final controller) async {
_webviewController = controller; _webviewController = controller;
await controller.loadUrl(widget.bloc.url); await controller.loadUrl(widget.url!);
}, },
onPageStarted: (final _) { onPageStarted: (final _) {
setState(() { setState(() {

13
packages/neon/lib/src/apps/news/widgets/articles_view.dart

@ -218,7 +218,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
debugPrint(s.toString()); debugPrint(s.toString());
} }
if (viewType == ArticleViewType.direct && bodyData != null) { if ((viewType == ArticleViewType.direct || article.url == null) && bodyData != null) {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (final context) => NewsArticlePage( builder: (final context) => NewsArticlePage(
@ -231,11 +231,13 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
articlesBloc: widget.bloc, articlesBloc: widget.bloc,
useWebView: false, useWebView: false,
bodyData: bodyData, bodyData: bodyData,
url: article.url,
), ),
), ),
); );
} else if (Provider.of<NeonPlatform>(context, listen: false).canUseWebView && } else if (viewType == ArticleViewType.internalBrowser &&
viewType == ArticleViewType.internalBrowser) { article.url != null &&
Provider.of<NeonPlatform>(context, listen: false).canUseWebView) {
await Navigator.of(context).push( await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (final context) => NewsArticlePage( builder: (final context) => NewsArticlePage(
@ -247,6 +249,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
), ),
articlesBloc: widget.bloc, articlesBloc: widget.bloc,
useWebView: true, useWebView: true,
url: article.url,
), ),
), ),
); );
@ -254,11 +257,13 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
if (article.unread) { if (article.unread) {
bloc.markArticleAsRead(article); bloc.markArticleAsRead(article);
} }
if (article.url != null) {
await launchUrlString( await launchUrlString(
article.url, article.url!,
mode: LaunchMode.externalApplication, mode: LaunchMode.externalApplication,
); );
} }
}
}, },
); );

4
packages/nextcloud/lib/src/nextcloud.openapi.dart

@ -1670,7 +1670,7 @@ class NewsArticle {
required this.id, required this.id,
required this.guid, required this.guid,
required this.guidHash, required this.guidHash,
required this.url, this.url,
required this.title, required this.title,
this.author, this.author,
required this.pubDate, required this.pubDate,
@ -1697,7 +1697,7 @@ class NewsArticle {
final String guidHash; final String guidHash;
final String url; final String? url;
final String title; final String title;

2
packages/nextcloud/lib/src/nextcloud.openapi.g.dart

@ -1002,7 +1002,7 @@ NewsArticle _$NewsArticleFromJson(Map<String, dynamic> json) => NewsArticle(
id: json['id'] as int, id: json['id'] as int,
guid: json['guid'] as String, guid: json['guid'] as String,
guidHash: json['guidHash'] as String, guidHash: json['guidHash'] as String,
url: json['url'] as String, url: json['url'] as String?,
title: json['title'] as String, title: json['title'] as String,
author: json['author'] as String?, author: json['author'] as String?,
pubDate: json['pubDate'] as int, pubDate: json['pubDate'] as int,

1
packages/nextcloud/lib/src/nextcloud.openapi.json

@ -1162,7 +1162,6 @@
"id", "id",
"guid", "guid",
"guidHash", "guidHash",
"url",
"title", "title",
"pubDate", "pubDate",
"body", "body",

1
specs/news.json

@ -144,7 +144,6 @@
"id", "id",
"guid", "guid",
"guidHash", "guidHash",
"url",
"title", "title",
"pubDate", "pubDate",
"body", "body",

Loading…
Cancel
Save