From 4d8e9bafc6cb0f2b14816da51bb67dc6be6eccd5 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 31 Jul 2022 08:20:34 +0200 Subject: [PATCH] neon: Add option to disable mark as read timeout in news --- packages/neon/lib/l10n/en.arb | 1 + packages/neon/lib/l10n/localizations.dart | 6 ++++++ packages/neon/lib/l10n/localizations_en.dart | 3 +++ packages/neon/lib/src/apps/news/options.dart | 9 +++++++++ packages/neon/lib/src/apps/news/pages/article.dart | 14 +++++++++----- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/packages/neon/lib/l10n/en.arb b/packages/neon/lib/l10n/en.arb index 03fa3c0a..0cd3eb6d 100644 --- a/packages/neon/lib/l10n/en.arb +++ b/packages/neon/lib/l10n/en.arb @@ -231,6 +231,7 @@ "newsOptionsArticleViewTypeDirect": "Show text directly", "newsOptionsArticleViewTypeInternalBrowser": "Open in internal browser", "newsOptionsArticleViewTypeExternalBrowser": "Open in external browser", + "newsOptionsArticleDisableMarkAsReadTimeout": "Mark articles as read instantly", "newsOptionsDefaultArticlesFilter": "Articles to show by default", "newsOptionsArticlesSortProperty": "How to sort articles", "newsOptionsArticlesSortPropertyPublishDate": "Publish date", diff --git a/packages/neon/lib/l10n/localizations.dart b/packages/neon/lib/l10n/localizations.dart index e286aae6..6d0e6e6d 100644 --- a/packages/neon/lib/l10n/localizations.dart +++ b/packages/neon/lib/l10n/localizations.dart @@ -857,6 +857,12 @@ abstract class AppLocalizations { /// **'Open in external browser'** String get newsOptionsArticleViewTypeExternalBrowser; + /// No description provided for @newsOptionsArticleDisableMarkAsReadTimeout. + /// + /// In en, this message translates to: + /// **'Mark articles as read instantly'** + String get newsOptionsArticleDisableMarkAsReadTimeout; + /// No description provided for @newsOptionsDefaultArticlesFilter. /// /// In en, this message translates to: diff --git a/packages/neon/lib/l10n/localizations_en.dart b/packages/neon/lib/l10n/localizations_en.dart index d225ea64..be09b25f 100644 --- a/packages/neon/lib/l10n/localizations_en.dart +++ b/packages/neon/lib/l10n/localizations_en.dart @@ -419,6 +419,9 @@ class AppLocalizationsEn extends AppLocalizations { @override String get newsOptionsArticleViewTypeExternalBrowser => 'Open in external browser'; + @override + String get newsOptionsArticleDisableMarkAsReadTimeout => 'Mark articles as read instantly'; + @override String get newsOptionsDefaultArticlesFilter => 'Articles to show by default'; diff --git a/packages/neon/lib/src/apps/news/options.dart b/packages/neon/lib/src/apps/news/options.dart index 46ba29ea..c3c1766c 100644 --- a/packages/neon/lib/src/apps/news/options.dart +++ b/packages/neon/lib/src/apps/news/options.dart @@ -11,6 +11,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions { super.options = [ defaultCategoryOption, articleViewTypeOption, + articleDisableMarkAsReadTimeoutOption, defaultArticlesFilterOption, articlesSortPropertyOption, articlesSortBoxOrderOption, @@ -72,6 +73,14 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions { values: _articleViewTypeValuesSubject, ); + late final articleDisableMarkAsReadTimeoutOption = ToggleOption( + storage: super.storage, + category: articlesCategory, + key: 'article-disable-mark-as-read-timeout', + label: (final context) => AppLocalizations.of(context).newsOptionsArticleDisableMarkAsReadTimeout, + defaultValue: BehaviorSubject.seeded(false), + ); + late final defaultArticlesFilterOption = SelectOption( storage: super.storage, category: articlesCategory, diff --git a/packages/neon/lib/src/apps/news/pages/article.dart b/packages/neon/lib/src/apps/news/pages/article.dart index 0409ca9d..1b032802 100644 --- a/packages/neon/lib/src/apps/news/pages/article.dart +++ b/packages/neon/lib/src/apps/news/pages/article.dart @@ -57,11 +57,15 @@ class _NewsArticlePageState extends State { void _startMarkAsReadTimer() { if (article.unread!) { - _markAsReadTimer = Timer(const Duration(seconds: 3), () { - if (article.unread!) { - widget.bloc.markArticleAsRead(article); - } - }); + if (widget.bloc.newsBloc.options.articleDisableMarkAsReadTimeoutOption.value) { + widget.bloc.markArticleAsRead(article); + } else { + _markAsReadTimer = Timer(const Duration(seconds: 3), () { + if (article.unread!) { + widget.bloc.markArticleAsRead(article); + } + }); + } } }