diff --git a/packages/neon/lib/src/apps/news/blocs/article.dart b/packages/neon/lib/src/apps/news/blocs/article.dart index c49aef88..e9907656 100644 --- a/packages/neon/lib/src/apps/news/blocs/article.dart +++ b/packages/neon/lib/src/apps/news/blocs/article.dart @@ -64,7 +64,6 @@ class NewsArticleBloc extends $NewsArticleBloc { _unreadSubject.add(article.unread); _starredSubject.add(article.starred); - url = article.url; } void _wrapArticleAction(final Future Function() call) { @@ -79,7 +78,6 @@ class NewsArticleBloc extends $NewsArticleBloc { final NextcloudClient _client; final NewsArticlesBloc _newsArticlesBloc; - late final String url; final _unreadSubject = BehaviorSubject(); final _starredSubject = BehaviorSubject(); final _errorsStreamController = StreamController(); diff --git a/packages/neon/lib/src/apps/news/pages/article.dart b/packages/neon/lib/src/apps/news/pages/article.dart index 15cf2410..a2b07e4e 100644 --- a/packages/neon/lib/src/apps/news/pages/article.dart +++ b/packages/neon/lib/src/apps/news/pages/article.dart @@ -6,13 +6,16 @@ class NewsArticlePage extends StatefulWidget { required this.articlesBloc, required this.useWebView, this.bodyData, + this.url, 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 NewsArticlesBloc articlesBloc; final bool useWebView; final String? bodyData; + final String? url; @override State createState() => _NewsArticlePageState(); @@ -75,7 +78,7 @@ class _NewsArticlePageState extends State { return (await _webviewController!.currentUrl())!; } - return widget.bloc.url; + return widget.url!; } @override @@ -129,21 +132,23 @@ class _NewsArticlePageState extends State { ); }, ), - IconButton( - onPressed: () async { - await launchUrlString( - await _getURL(), - mode: LaunchMode.externalApplication, - ); - }, - icon: const Icon(Icons.open_in_new), - ), - IconButton( - onPressed: () async { - await Share.share(await _getURL()); - }, - icon: const Icon(Icons.share), - ), + if (widget.url != null) ...[ + IconButton( + onPressed: () async { + await launchUrlString( + await _getURL(), + mode: LaunchMode.externalApplication, + ); + }, + icon: const Icon(Icons.open_in_new), + ), + IconButton( + onPressed: () async { + await Share.share(await _getURL()); + }, + icon: const Icon(Icons.share), + ), + ], ], ), body: widget.useWebView @@ -155,7 +160,7 @@ class _NewsArticlePageState extends State { javascriptMode: JavascriptMode.unrestricted, onWebViewCreated: (final controller) async { _webviewController = controller; - await controller.loadUrl(widget.bloc.url); + await controller.loadUrl(widget.url!); }, onPageStarted: (final _) { setState(() { diff --git a/packages/neon/lib/src/apps/news/widgets/articles_view.dart b/packages/neon/lib/src/apps/news/widgets/articles_view.dart index ffaa3317..6506185e 100644 --- a/packages/neon/lib/src/apps/news/widgets/articles_view.dart +++ b/packages/neon/lib/src/apps/news/widgets/articles_view.dart @@ -218,7 +218,7 @@ class _NewsArticlesViewState extends State { debugPrint(s.toString()); } - if (viewType == ArticleViewType.direct && bodyData != null) { + if ((viewType == ArticleViewType.direct || article.url == null) && bodyData != null) { await Navigator.of(context).push( MaterialPageRoute( builder: (final context) => NewsArticlePage( @@ -231,11 +231,13 @@ class _NewsArticlesViewState extends State { articlesBloc: widget.bloc, useWebView: false, bodyData: bodyData, + url: article.url, ), ), ); - } else if (Provider.of(context, listen: false).canUseWebView && - viewType == ArticleViewType.internalBrowser) { + } else if (viewType == ArticleViewType.internalBrowser && + article.url != null && + Provider.of(context, listen: false).canUseWebView) { await Navigator.of(context).push( MaterialPageRoute( builder: (final context) => NewsArticlePage( @@ -247,6 +249,7 @@ class _NewsArticlesViewState extends State { ), articlesBloc: widget.bloc, useWebView: true, + url: article.url, ), ), ); @@ -254,10 +257,12 @@ class _NewsArticlesViewState extends State { if (article.unread) { bloc.markArticleAsRead(article); } - await launchUrlString( - article.url, - mode: LaunchMode.externalApplication, - ); + if (article.url != null) { + await launchUrlString( + article.url!, + mode: LaunchMode.externalApplication, + ); + } } }, ); diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.dart b/packages/nextcloud/lib/src/nextcloud.openapi.dart index 287a07a3..ad82d30c 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.dart @@ -1670,7 +1670,7 @@ class NewsArticle { required this.id, required this.guid, required this.guidHash, - required this.url, + this.url, required this.title, this.author, required this.pubDate, @@ -1697,7 +1697,7 @@ class NewsArticle { final String guidHash; - final String url; + final String? url; final String title; diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart index 1c6f3595..6e83b080 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.g.dart +++ b/packages/nextcloud/lib/src/nextcloud.openapi.g.dart @@ -1002,7 +1002,7 @@ NewsArticle _$NewsArticleFromJson(Map json) => NewsArticle( id: json['id'] as int, guid: json['guid'] as String, guidHash: json['guidHash'] as String, - url: json['url'] as String, + url: json['url'] as String?, title: json['title'] as String, author: json['author'] as String?, pubDate: json['pubDate'] as int, diff --git a/packages/nextcloud/lib/src/nextcloud.openapi.json b/packages/nextcloud/lib/src/nextcloud.openapi.json index 0166ca15..6d290724 100644 --- a/packages/nextcloud/lib/src/nextcloud.openapi.json +++ b/packages/nextcloud/lib/src/nextcloud.openapi.json @@ -1162,7 +1162,6 @@ "id", "guid", "guidHash", - "url", "title", "pubDate", "body", diff --git a/specs/news.json b/specs/news.json index 2084e50e..770e483d 100644 --- a/specs/news.json +++ b/specs/news.json @@ -144,7 +144,6 @@ "id", "guid", "guidHash", - "url", "title", "pubDate", "body",