Skip to content

Commit

Permalink
refactor(neon_framework): Expose AppImplementationOptions through Neo…
Browse files Browse the repository at this point in the history
…nProvider

Signed-off-by: provokateurin <[email protected]>
  • Loading branch information
provokateurin committed Jul 9, 2024
1 parent 9300bc6 commit 3b9f88c
Show file tree
Hide file tree
Showing 24 changed files with 88 additions and 62 deletions.
3 changes: 0 additions & 3 deletions packages/neon/neon_files/lib/src/blocs/browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ sealed class FilesBrowserBloc implements InteractiveBloc {

BehaviorSubject<PathUri> get uri;

FilesOptions get options;

/// Mode to operate the `FilesBrowserView` in.
FilesBrowserMode get mode;
}
Expand All @@ -65,7 +63,6 @@ class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc {
@override
final log = Logger('FilesBrowserBloc');

@override
final FilesOptions options;
final Account account;

Expand Down
3 changes: 0 additions & 3 deletions packages/neon/neon_files/lib/src/blocs/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ sealed class FilesBloc implements InteractiveBloc {

BehaviorSubject<BuiltList<FilesTask>> get tasks;

FilesOptions get options;

FilesBrowserBloc get browser;

FilesBrowserBloc getNewFilesBrowserBloc({PathUri? initialUri, FilesBrowserMode? mode});
Expand All @@ -68,7 +66,6 @@ class _FilesBloc extends InteractiveBloc implements FilesBloc {
@override
final log = Logger('FilesBloc');

@override
final FilesOptions options;
final Account account;
@override
Expand Down
8 changes: 6 additions & 2 deletions packages/neon/neon_files/lib/src/widgets/browser_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:neon_files/src/widgets/file_list_tile.dart';
import 'package:neon_files/src/widgets/navigator.dart';
import 'package:neon_framework/blocs.dart';
import 'package:neon_framework/sort_box.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:nextcloud/webdav.dart';

Expand All @@ -32,13 +33,16 @@ class FilesBrowserView extends StatefulWidget {

class _FilesBrowserViewState extends State<FilesBrowserView> {
late final StreamSubscription<Object> errorsSubscription;
late final FilesOptions options;

@override
void initState() {
errorsSubscription = widget.bloc.errors.listen((error) {
NeonError.showSnackbar(context, error);
});

options = NeonProvider.of<FilesOptions>(context);

super.initState();
}

Expand Down Expand Up @@ -72,8 +76,8 @@ class _FilesBrowserViewState extends State<FilesBrowserView> {
},
child: SortBoxBuilder(
sortBox: filesSortBox,
sortProperty: widget.bloc.options.filesSortPropertyOption,
sortBoxOrder: widget.bloc.options.filesSortBoxOrderOption,
sortProperty: options.filesSortPropertyOption,
sortBoxOrder: options.filesSortBoxOrderOption,
presort: const {
(property: FilesSortProperty.isFolder, order: SortBoxOrder.ascending),
},
Expand Down
3 changes: 2 additions & 1 deletion packages/neon/neon_files/lib/src/widgets/dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:image_picker/image_picker.dart';
import 'package:neon_files/l10n/localizations.dart';
import 'package:neon_files/src/blocs/browser.dart';
import 'package:neon_files/src/blocs/files.dart';
import 'package:neon_files/src/options.dart';
import 'package:neon_files/src/utils/dialog.dart';
import 'package:neon_files/src/widgets/browser_view.dart';
import 'package:neon_framework/platform.dart';
Expand Down Expand Up @@ -73,7 +74,7 @@ class _FilesChooseCreateModalState extends State<FilesChooseCreateModal> {
}

Future<bool> confirmUpload(int size) async {
final sizeWarning = widget.bloc.options.uploadSizeWarning.value;
final sizeWarning = NeonProvider.of<FilesOptions>(context).uploadSizeWarning.value;
if (sizeWarning != null) {
if (size > sizeWarning) {
final result = await showUploadConfirmationDialog(context, sizeWarning, size);
Expand Down
4 changes: 3 additions & 1 deletion packages/neon/neon_files/lib/src/widgets/file_list_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
import 'package:neon_files/src/blocs/browser.dart';
import 'package:neon_files/src/blocs/files.dart';
import 'package:neon_files/src/models/file_details.dart';
import 'package:neon_files/src/options.dart';
import 'package:neon_files/src/utils/dialog.dart';
import 'package:neon_files/src/utils/task.dart';
import 'package:neon_files/src/widgets/actions.dart';
import 'package:neon_files/src/widgets/file_preview.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';

class FileListTile extends StatelessWidget {
Expand All @@ -27,7 +29,7 @@ class FileListTile extends StatelessWidget {
if (details.isDirectory) {
browserBloc.setPath(details.uri);
} else if (browserBloc.mode == FilesBrowserMode.browser) {
final sizeWarning = bloc.options.downloadSizeWarning.value;
final sizeWarning = NeonProvider.of<FilesOptions>(context).downloadSizeWarning.value;
if (sizeWarning != null && details.size != null && details.size! > sizeWarning) {
final decision = await showDownloadConfirmationDialog(context, sizeWarning, details.size!);

Expand Down
3 changes: 2 additions & 1 deletion packages/neon/neon_files/lib/src/widgets/file_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:file_icons/file_icons.dart';
import 'package:flutter/material.dart';
import 'package:neon_files/src/blocs/files.dart';
import 'package:neon_files/src/models/file_details.dart';
import 'package:neon_files/src/options.dart';
import 'package:neon_framework/models.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
Expand Down Expand Up @@ -46,7 +47,7 @@ class FilePreview extends StatelessWidget {
}

return ValueListenableBuilder(
valueListenable: bloc.options.showPreviewsOption,
valueListenable: NeonProvider.of<FilesOptions>(context).showPreviewsOption,
builder: (context, showPreviews, _) {
if (showPreviews && (details.hasPreview ?? false)) {
final preview = FilePreviewImage(
Expand Down
3 changes: 0 additions & 3 deletions packages/neon/neon_news/lib/src/blocs/articles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ sealed class NewsArticlesBloc implements InteractiveBloc {

BehaviorSubject<FilterType> get filterType;

NewsOptions get options;

ListType? get listType;
}

Expand Down Expand Up @@ -80,7 +78,6 @@ class _NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBloc {
final log = Logger('NewsArticlesBloc');

final NewsBloc _newsBloc;
@override
final NewsOptions options;
final Account account;
final int? id;
Expand Down
2 changes: 0 additions & 2 deletions packages/neon/neon_news/lib/src/blocs/news.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ sealed class NewsBloc implements InteractiveBloc {

BehaviorSubject<int> get unreadCounter;

NewsOptions get options;

NewsMainArticlesBloc get mainArticlesBloc;
}

Expand Down
8 changes: 7 additions & 1 deletion packages/neon/neon_news/lib/src/pages/article.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:neon_framework/platform.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_news/l10n/localizations.dart';
import 'package:neon_news/src/blocs/article.dart';
import 'package:neon_news/src/blocs/articles.dart';
import 'package:neon_news/src/options.dart';
import 'package:share_plus/share_plus.dart';
import 'package:url_launcher/url_launcher_string.dart';
import 'package:wakelock_plus/wakelock_plus.dart';
Expand Down Expand Up @@ -89,7 +91,11 @@ class _NewsArticlePageState extends State<NewsArticlePage> {

Future<void> _startMarkAsReadTimer() async {
if (await widget.bloc.unread.first) {
if (widget.articlesBloc.options.articleDisableMarkAsReadTimeoutOption.value) {
if (!mounted) {
return;
}

if (NeonProvider.of<NewsOptions>(context).articleDisableMarkAsReadTimeoutOption.value) {
widget.bloc.markArticleAsRead();
} else {
_markAsReadTimer = Timer(const Duration(seconds: 3), () async {
Expand Down
3 changes: 2 additions & 1 deletion packages/neon/neon_news/lib/src/pages/feed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:neon_framework/models.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_news/src/blocs/articles.dart';
import 'package:neon_news/src/blocs/news.dart';
import 'package:neon_news/src/options.dart';
import 'package:neon_news/src/widgets/articles_view.dart';
import 'package:nextcloud/news.dart' as news;

Expand All @@ -27,7 +28,7 @@ class NewsFeedPage extends StatelessWidget {
child: NewsArticlesView(
bloc: NewsArticlesBloc(
newsBloc: bloc,
options: bloc.options,
options: NeonProvider.of<NewsOptions>(context),
account: NeonProvider.of<Account>(context),
id: feed.id,
listType: ListType.feed,
Expand Down
12 changes: 7 additions & 5 deletions packages/neon/neon_news/lib/src/pages/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_news/l10n/localizations.dart';
import 'package:neon_news/src/blocs/news.dart';
import 'package:neon_news/src/options.dart';
import 'package:neon_news/src/widgets/articles_view.dart';
import 'package:neon_news/src/widgets/feed_floating_action_button.dart';
import 'package:neon_news/src/widgets/feeds_view.dart';
Expand All @@ -23,13 +24,14 @@ class NewsMainPage extends StatefulWidget {

class _NewsMainPageState extends State<NewsMainPage> {
late NewsBloc bloc;
late int _index = bloc.options.defaultCategoryOption.value.index;
late int index;
late final StreamSubscription<Object> errorsSubscription;

@override
void initState() {
super.initState();
bloc = NeonProvider.of<NewsBloc>(context);
index = NeonProvider.of<NewsOptions>(context).defaultCategoryOption.value.index;

errorsSubscription = bloc.errors.listen((error) {
NeonError.showSnackbar(context, error);
Expand Down Expand Up @@ -67,10 +69,10 @@ class _NewsMainPageState extends State<NewsMainPage> {
return Scaffold(
resizeToAvoidBottomInset: false,
bottomNavigationBar: BottomNavigationBar(
currentIndex: _index,
currentIndex: index,
onTap: (index) {
setState(() {
_index = index;
this.index = index;
});
},
items: [
Expand All @@ -88,8 +90,8 @@ class _NewsMainPageState extends State<NewsMainPage> {
),
],
),
body: views[_index],
floatingActionButton: floatingActionButtons[_index],
body: views[index],
floatingActionButton: floatingActionButtons[index],
);
}
}
9 changes: 6 additions & 3 deletions packages/neon/neon_news/lib/src/widgets/articles_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class NewsArticlesView extends StatefulWidget {

class _NewsArticlesViewState extends State<NewsArticlesView> {
late final StreamSubscription<Object> errorsSubscription;
late final NewsOptions options;

@override
void initState() {
Expand All @@ -50,6 +51,8 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
errorsSubscription = widget.bloc.errors.listen((error) {
NeonError.showSnackbar(context, error);
});

options = NeonProvider.of<NewsOptions>(context);
}

@override
Expand All @@ -67,8 +70,8 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
subject: widget.bloc.articles,
builder: (context, articles) => SortBoxBuilder(
sortBox: articlesSortBox,
sortProperty: widget.newsBloc.options.articlesSortPropertyOption,
sortBoxOrder: widget.newsBloc.options.articlesSortBoxOrderOption,
sortProperty: options.articlesSortPropertyOption,
sortBoxOrder: options.articlesSortBoxOrderOption,
input: articles.data?.toList(),
builder: (context, sorted) => NeonListView(
scrollKey: 'news-articles',
Expand Down Expand Up @@ -219,7 +222,7 @@ class _NewsArticlesViewState extends State<NewsArticlesView> {
}
},
onTap: () async {
final viewType = widget.newsBloc.options.articleViewTypeOption.value;
final viewType = options.articleViewTypeOption.value;
String? bodyData;
try {
bodyData = _fixArticleBody(article.body);
Expand Down
7 changes: 5 additions & 2 deletions packages/neon/neon_news/lib/src/widgets/feeds_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_news/l10n/localizations.dart';
import 'package:neon_news/src/blocs/news.dart';
import 'package:neon_news/src/options.dart';
import 'package:neon_news/src/pages/feed.dart';
import 'package:neon_news/src/sort/feeds.dart';
import 'package:neon_news/src/utils/dialog.dart';
Expand All @@ -25,14 +26,16 @@ class NewsFeedsView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final options = NeonProvider.of<NewsOptions>(context);

return ResultBuilder.behaviorSubject(
subject: bloc.folders,
builder: (context, folders) => ResultBuilder.behaviorSubject(
subject: bloc.feeds,
builder: (context, feeds) => SortBoxBuilder(
sortBox: feedsSortBox,
sortProperty: bloc.options.feedsSortPropertyOption,
sortBoxOrder: bloc.options.feedsSortBoxOrderOption,
sortProperty: options.feedsSortPropertyOption,
sortBoxOrder: options.feedsSortBoxOrderOption,
input: folders.hasData ? feeds.data?.where((f) => folderID == null || f.folderId == folderID).toList() : null,
builder: (context, sorted) => NeonListView(
scrollKey: 'news-feeds',
Expand Down
24 changes: 16 additions & 8 deletions packages/neon/neon_news/lib/src/widgets/folder_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ class NewsFolderView extends StatefulWidget {
}

class _NewsFolderViewState extends State<NewsFolderView> {
late final option = widget.bloc.options.defaultFolderViewTypeOption;
late DefaultFolderViewType _viewType = option.value;
late final NewsOptions options;
late DefaultFolderViewType viewType;

@override
void initState() {
super.initState();

options = NeonProvider.of<NewsOptions>(context);
viewType = options.defaultFolderViewTypeOption.value;
}

@override
Widget build(BuildContext context) {
Expand All @@ -34,28 +42,28 @@ class _NewsFolderViewState extends State<NewsFolderView> {
margin: const EdgeInsets.symmetric(horizontal: 15),
child: DropdownButton(
isExpanded: true,
value: _viewType,
items: option.values.keys
value: viewType,
items: options.defaultFolderViewTypeOption.values.keys
.map(
(key) => DropdownMenuItem(
value: key,
child: Text(option.values[key]!(context)),
child: Text(options.defaultFolderViewTypeOption.values[key]!(context)),
),
)
.toList(),
onChanged: (value) {
setState(() {
_viewType = value!;
viewType = value!;
});
},
),
),
Expanded(
child: _viewType == DefaultFolderViewType.articles
child: viewType == DefaultFolderViewType.articles
? NewsArticlesView(
bloc: NewsArticlesBloc(
newsBloc: widget.bloc,
options: widget.bloc.options,
options: options,
account: NeonProvider.of<Account>(context),
id: widget.folder.id,
listType: ListType.folder,
Expand Down
8 changes: 6 additions & 2 deletions packages/neon/neon_news/lib/src/widgets/folders_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
import 'package:neon_framework/blocs.dart';
import 'package:neon_framework/sort_box.dart';
import 'package:neon_framework/theme.dart';
import 'package:neon_framework/utils.dart';
import 'package:neon_framework/widgets.dart';
import 'package:neon_news/l10n/localizations.dart';
import 'package:neon_news/src/blocs/news.dart';
import 'package:neon_news/src/options.dart';
import 'package:neon_news/src/pages/folder.dart';
import 'package:neon_news/src/sort/folders.dart';
import 'package:neon_news/src/utils/dialog.dart';
Expand All @@ -19,14 +21,16 @@ class NewsFoldersView extends StatelessWidget {

@override
Widget build(BuildContext context) {
final options = NeonProvider.of<NewsOptions>(context);

return ResultBuilder.behaviorSubject(
subject: bloc.folders,
builder: (context, folders) => ResultBuilder.behaviorSubject(
subject: bloc.feeds,
builder: (context, feeds) => SortBoxBuilder(
sortBox: foldersSortBox,
sortProperty: bloc.options.foldersSortPropertyOption,
sortBoxOrder: bloc.options.foldersSortBoxOrderOption,
sortProperty: options.foldersSortPropertyOption,
sortBoxOrder: options.foldersSortBoxOrderOption,
input: feeds.hasData
? [
...?folders.data,
Expand Down
Loading

0 comments on commit 3b9f88c

Please sign in to comment.