Browse Source

refactor(neon,neon_files,neon_news,neon_notes,neon_notifications): make AppImplementation immutable and cleanup options initialization

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/654/head
Nikolas Rimikis 1 year ago
parent
commit
060eaf0baf
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 16
      packages/neon/neon/lib/src/models/app_implementation.dart
  2. 5
      packages/neon/neon/lib/src/models/notifications_interface.dart
  3. 2
      packages/neon/neon_files/lib/neon_files.dart
  4. 2
      packages/neon/neon_news/lib/neon_news.dart
  5. 2
      packages/neon/neon_notes/lib/neon_notes.dart
  6. 2
      packages/neon/neon_notifications/lib/neon_notifications.dart

16
packages/neon/neon/lib/src/models/app_implementation.dart

@ -2,6 +2,7 @@ import 'package:collection/collection.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:go_router/go_router.dart'; import 'package:go_router/go_router.dart';
import 'package:meta/meta.dart';
import 'package:neon/l10n/localizations.dart'; import 'package:neon/l10n/localizations.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/accounts.dart';
@ -12,11 +13,9 @@ import 'package:neon/src/widgets/drawer_destination.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
@immutable
abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions> { abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions> {
AppImplementation() { AppImplementation();
final storage = AppStorage('app-$id');
options = buildOptions(storage);
}
String get id; String get id;
LocalizationsDelegate get localizationsDelegate; LocalizationsDelegate get localizationsDelegate;
@ -25,10 +24,11 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
String nameFromLocalization(final AppLocalizations localizations) => localizations.appImplementationName(id); String nameFromLocalization(final AppLocalizations localizations) => localizations.appImplementationName(id);
String name(final BuildContext context) => nameFromLocalization(AppLocalizations.of(context)); String name(final BuildContext context) => nameFromLocalization(AppLocalizations.of(context));
late final R options;
@protected @protected
R buildOptions(final AppStorage storage); late final AppStorage storage = AppStorage('app-$id');
@mustBeOverridden
R get options;
final Map<String, T> _blocs = {}; final Map<String, T> _blocs = {};
@ -115,7 +115,7 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppOptions>
/// A custom theme that will be injected into the widget tree. /// A custom theme that will be injected into the widget tree.
/// ///
/// You can later acess it through `Theme.of(context).extension<ThemeName>()`. /// You can later acess it through `Theme.of(context).extension<ThemeName>()`.
ThemeExtension? theme; final ThemeExtension? theme = null;
} }
extension AppImplementationFind on Iterable<AppImplementation> { extension AppImplementationFind on Iterable<AppImplementation> {

5
packages/neon/neon/lib/src/models/notifications_interface.dart

@ -1,3 +1,4 @@
import 'package:meta/meta.dart';
import 'package:neon/src/bloc/bloc.dart'; import 'package:neon/src/bloc/bloc.dart';
import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/models/app_implementation.dart';
import 'package:neon/src/settings/models/nextcloud_app_options.dart'; import 'package:neon/src/settings/models/nextcloud_app_options.dart';
@ -5,6 +6,10 @@ import 'package:neon/src/settings/models/nextcloud_app_options.dart';
abstract interface class NotificationsAppInterface<T extends NotificationsBlocInterface, abstract interface class NotificationsAppInterface<T extends NotificationsBlocInterface,
R extends NotificationsOptionsInterface> extends AppImplementation<T, R> { R extends NotificationsOptionsInterface> extends AppImplementation<T, R> {
NotificationsAppInterface(); NotificationsAppInterface();
@override
@mustBeOverridden
R get options => throw UnimplementedError();
} }
abstract interface class NotificationsBlocInterface extends InteractiveBloc { abstract interface class NotificationsBlocInterface extends InteractiveBloc {

2
packages/neon/neon_files/lib/neon_files.dart

@ -56,7 +56,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
List<Locale> supportedLocales = AppLocalizations.supportedLocales; List<Locale> supportedLocales = AppLocalizations.supportedLocales;
@override @override
FilesAppSpecificOptions buildOptions(final AppStorage storage) => FilesAppSpecificOptions(storage); late final FilesAppSpecificOptions options = FilesAppSpecificOptions(storage);
@override @override
FilesBloc buildBloc(final Account account) => FilesBloc( FilesBloc buildBloc(final Account account) => FilesBloc(

2
packages/neon/neon_news/lib/neon_news.dart

@ -64,7 +64,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
List<Locale> supportedLocales = AppLocalizations.supportedLocales; List<Locale> supportedLocales = AppLocalizations.supportedLocales;
@override @override
NewsAppSpecificOptions buildOptions(final AppStorage storage) => NewsAppSpecificOptions(storage); late final NewsAppSpecificOptions options = NewsAppSpecificOptions(storage);
@override @override
NewsBloc buildBloc(final Account account) => NewsBloc( NewsBloc buildBloc(final Account account) => NewsBloc(

2
packages/neon/neon_notes/lib/neon_notes.dart

@ -54,7 +54,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate; LocalizationsDelegate localizationsDelegate = AppLocalizations.delegate;
@override @override
NotesAppSpecificOptions buildOptions(final AppStorage storage) => NotesAppSpecificOptions(storage); late final NotesAppSpecificOptions options = NotesAppSpecificOptions(storage);
@override @override
NotesBloc buildBloc(final Account account) => NotesBloc( NotesBloc buildBloc(final Account account) => NotesBloc(

2
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -34,7 +34,7 @@ class NotificationsApp extends AppImplementation<NotificationsBloc, Notification
List<Locale> supportedLocales = AppLocalizations.supportedLocales; List<Locale> supportedLocales = AppLocalizations.supportedLocales;
@override @override
NotificationsAppSpecificOptions buildOptions(final AppStorage storage) => NotificationsAppSpecificOptions(storage); late final NotificationsAppSpecificOptions options = NotificationsAppSpecificOptions(storage);
@override @override
NotificationsBloc buildBloc(final Account account) => NotificationsBloc( NotificationsBloc buildBloc(final Account account) => NotificationsBloc(

Loading…
Cancel
Save