Browse Source

neon: Refactor app implementations to only override methods

pull/50/head
jld3103 2 years ago
parent
commit
74a2e6e144
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 43
      packages/neon/lib/src/apps/files/app.dart
  2. 41
      packages/neon/lib/src/apps/news/app.dart
  3. 40
      packages/neon/lib/src/apps/notes/app.dart
  4. 40
      packages/neon/lib/src/apps/notifications/app.dart
  5. 2
      packages/neon/lib/src/pages/home/home.dart
  6. 29
      packages/neon/lib/src/utils/app_implementation.dart

43
packages/neon/lib/src/apps/files/app.dart

@ -25,7 +25,6 @@ import 'package:path/path.dart' as p;
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:settings/settings.dart'; import 'package:settings/settings.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'dialogs/choose_create.dart'; part 'dialogs/choose_create.dart';
part 'dialogs/choose_folder.dart'; part 'dialogs/choose_folder.dart';
@ -40,23 +39,27 @@ part 'widgets/browser_view.dart';
part 'widgets/file_preview.dart'; part 'widgets/file_preview.dart';
class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> { class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
FilesApp( FilesApp(super.sharedPreferences, super.requestManager, super.platform);
final SharedPreferences sharedPreferences,
final RequestManager requestManager, @override
final NeonPlatform platform, String id = 'files';
) : super(
'files', @override
(final localizations) => localizations.filesName, String nameFromLocalization(AppLocalizations localizations) => localizations.filesName;
sharedPreferences,
FilesAppSpecificOptions.new, @override
(final options, final client) => FilesBloc( FilesAppSpecificOptions buildOptions(Storage storage) => FilesAppSpecificOptions(storage);
options,
requestManager, @override
client, FilesBloc buildBloc(NextcloudClient client) => FilesBloc(
platform, options,
), requestManager,
(final context, final bloc) => FilesMainPage( client,
bloc: bloc, platform,
), );
);
@override
Widget buildPage(BuildContext context, FilesBloc bloc) => FilesMainPage(
bloc: bloc,
);
} }

41
packages/neon/lib/src/apps/news/app.dart

@ -21,7 +21,6 @@ import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:settings/settings.dart'; import 'package:settings/settings.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sort_box/sort_box.dart'; import 'package:sort_box/sort_box.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
import 'package:wakelock/wakelock.dart'; import 'package:wakelock/wakelock.dart';
@ -48,22 +47,26 @@ part 'widgets/folder_view.dart';
part 'widgets/folders_view.dart'; part 'widgets/folders_view.dart';
class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> { class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
NewsApp( NewsApp(super.sharedPreferences, super.requestManager, super.platform);
final SharedPreferences sharedPreferences,
final RequestManager requestManager, @override
final NeonPlatform platform, String id = 'news';
) : super(
'news', @override
(final localizations) => localizations.newsName, String nameFromLocalization(AppLocalizations localizations) => localizations.newsName;
sharedPreferences,
(final storage) => NewsAppSpecificOptions(storage, platform), @override
(final options, final client) => NewsBloc( NewsAppSpecificOptions buildOptions(Storage storage) => NewsAppSpecificOptions(storage, platform);
options,
requestManager, @override
client, NewsBloc buildBloc(NextcloudClient client) => NewsBloc(
), options,
(final context, final bloc) => NewsMainPage( requestManager,
bloc: bloc, client,
), );
);
@override
Widget buildPage(BuildContext context, NewsBloc bloc) => NewsMainPage(
bloc: bloc,
);
} }

40
packages/neon/lib/src/apps/notes/app.dart

@ -15,7 +15,6 @@ import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:rxdart/rxdart.dart'; import 'package:rxdart/rxdart.dart';
import 'package:settings/settings.dart'; import 'package:settings/settings.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:sort_box/sort_box.dart'; import 'package:sort_box/sort_box.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
import 'package:wakelock/wakelock.dart'; import 'package:wakelock/wakelock.dart';
@ -35,21 +34,26 @@ part 'widgets/category_select.dart';
part 'widgets/notes_view.dart'; part 'widgets/notes_view.dart';
class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> { class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
NotesApp( NotesApp(super.sharedPreferences, super.requestManager, super.platform);
final SharedPreferences sharedPreferences,
final RequestManager requestManager, @override
) : super( String id = 'notes';
'notes',
(final localizations) => localizations.notesName, @override
sharedPreferences, String nameFromLocalization(AppLocalizations localizations) => localizations.notesName;
NotesAppSpecificOptions.new,
(final options, final client) => NotesBloc( @override
options, NotesAppSpecificOptions buildOptions(Storage storage) => NotesAppSpecificOptions(storage);
requestManager,
client, @override
), NotesBloc buildBloc(NextcloudClient client) => NotesBloc(
(final context, final bloc) => NotesMainPage( options,
bloc: bloc, requestManager,
), client,
); );
@override
Widget buildPage(BuildContext context, NotesBloc bloc) => NotesMainPage(
bloc: bloc,
);
} }

40
packages/neon/lib/src/apps/notifications/app.dart

@ -8,27 +8,31 @@ import 'package:neon/src/apps/notifications/blocs/notifications.dart';
import 'package:neon/src/neon.dart'; import 'package:neon/src/neon.dart';
import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/nextcloud.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';
part 'options.dart'; part 'options.dart';
part 'pages/main.dart'; part 'pages/main.dart';
class NotificationsApp extends AppImplementation<NotificationsBloc, NotificationsAppSpecificOptions> { class NotificationsApp extends AppImplementation<NotificationsBloc, NotificationsAppSpecificOptions> {
NotificationsApp( NotificationsApp(super.sharedPreferences, super.requestManager, super.platform);
final SharedPreferences sharedPreferences,
final RequestManager requestManager, @override
) : super( String id = 'notifications';
'notifications',
(final localizations) => localizations.notificationsName, @override
sharedPreferences, String nameFromLocalization(AppLocalizations localizations) => localizations.notificationsName;
NotificationsAppSpecificOptions.new,
(final options, final client) => NotificationsBloc( @override
options, NotificationsAppSpecificOptions buildOptions(Storage storage) => NotificationsAppSpecificOptions(storage);
requestManager,
client, @override
), NotificationsBloc buildBloc(NextcloudClient client) => NotificationsBloc(
(final context, final bloc) => NotificationsMainPage( options,
bloc: bloc, requestManager,
), client,
); );
@override
Widget buildPage(BuildContext context, NotificationsBloc bloc) => NotificationsMainPage(
bloc: bloc,
);
} }

2
packages/neon/lib/src/pages/home/home.dart

@ -565,7 +565,7 @@ class _HomePageState extends State<HomePage> with tray.TrayListener, WindowListe
Expanded( Expanded(
child: appsData child: appsData
.singleWhere((final a) => a.id == activeAppIDSnapshot.data!) .singleWhere((final a) => a.id == activeAppIDSnapshot.data!)
.buildPage(context, _appsBloc), .buildPageFromAppsBloc(context, _appsBloc),
), ),
], ],
], ],

29
packages/neon/lib/src/utils/app_implementation.dart

@ -8,34 +8,35 @@ List<AppImplementation> getAppImplementations(
[ [
FilesApp(sharedPreferences, requestManager, platform), FilesApp(sharedPreferences, requestManager, platform),
NewsApp(sharedPreferences, requestManager, platform), NewsApp(sharedPreferences, requestManager, platform),
NotesApp(sharedPreferences, requestManager), NotesApp(sharedPreferences, requestManager, platform),
NotificationsApp(sharedPreferences, requestManager), NotificationsApp(sharedPreferences, requestManager, platform),
]; ];
abstract class AppImplementation<T extends RxBlocBase, R extends NextcloudAppSpecificOptions> { abstract class AppImplementation<T extends RxBlocBase, R extends NextcloudAppSpecificOptions> {
AppImplementation( AppImplementation(
this.id,
this.nameFromLocalization,
final SharedPreferences sharedPreferences, final SharedPreferences sharedPreferences,
final R Function(Storage) buildOptions, final this.requestManager,
this._buildBloc, final this.platform,
this._buildPage,
) { ) {
final storage = Storage('app-$id', sharedPreferences); final storage = Storage('app-$id', sharedPreferences);
options = buildOptions(storage); options = buildOptions(storage);
} }
final String Function(AppLocalizations) nameFromLocalization; String get id;
final RequestManager requestManager;
final NeonPlatform platform;
String nameFromLocalization(AppLocalizations localizations);
String name(BuildContext context) => nameFromLocalization(AppLocalizations.of(context)); String name(BuildContext context) => nameFromLocalization(AppLocalizations.of(context));
final String id;
late final R options; late final R options;
final T Function(R options, NextcloudClient client) _buildBloc; R buildOptions(Storage storage);
final Widget Function(BuildContext context, T bloc) _buildPage;
T buildBloc(final NextcloudClient client) => _buildBloc(options, client); T buildBloc(final NextcloudClient client);
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => Widget buildPage(BuildContext context, T bloc);
_buildPage(context, appsBloc.getAppBloc(this)); Widget buildPageFromAppsBloc(final BuildContext context, final AppsBloc appsBloc) =>
buildPage(context, appsBloc.getAppBloc(this));
Widget buildIcon( Widget buildIcon(
final BuildContext context, { final BuildContext context, {

Loading…
Cancel
Save