Browse Source

Merge pull request #363 from Leptopoda/feature/adaptive-layout

Feature/adaptive layout
pull/360/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
77c42a7476
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 16
      packages/neon/neon/lib/src/pages/home.dart
  3. 6
      packages/neon/neon/lib/src/utils/app_implementation.dart
  4. 4
      packages/neon/neon_files/lib/neon_files.dart
  5. 20
      packages/neon/neon_files/lib/pages/main.dart
  6. 4
      packages/neon/neon_news/lib/neon_news.dart
  7. 21
      packages/neon/neon_news/lib/pages/main.dart
  8. 4
      packages/neon/neon_notes/lib/neon_notes.dart
  9. 16
      packages/neon/neon_notes/lib/pages/main.dart
  10. 4
      packages/neon/neon_notifications/lib/neon_notifications.dart
  11. 17
      packages/neon/neon_notifications/lib/pages/main.dart

4
packages/neon/neon/lib/src/blocs/apps.dart

@ -144,4 +144,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
return _blocs[appImplementation.id] = appImplementation.buildBloc(_account.client) as T; return _blocs[appImplementation.id] = appImplementation.buildBloc(_account.client) as T;
} }
List<Provider>? getAppProviders() => appImplementations.valueOrNull?.data
?.map((final appImplementation) => appImplementation.blocProvider(_account.client))
.toList();
} }

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

@ -150,7 +150,7 @@ class _HomePageState extends State<HomePage> {
], ],
), ),
), ),
body: app.buildPage(context, _appsBloc), body: app.page,
), ),
), ),
); );
@ -504,7 +504,7 @@ class _HomePageState extends State<HomePage> {
], ],
); );
final body = Builder( Widget body = Builder(
builder: (final context) => Row( builder: (final context) => Row(
children: [ children: [
if (navigationMode == NavigationMode.quickBar) ...[ if (navigationMode == NavigationMode.quickBar) ...[
@ -526,9 +526,7 @@ class _HomePageState extends State<HomePage> {
] else ...[ ] else ...[
if (activeAppIDSnapshot.hasData) ...[ if (activeAppIDSnapshot.hasData) ...[
Expanded( Expanded(
child: appImplementations.data! child: appImplementations.data!.find(activeAppIDSnapshot.data!)!.page,
.find(activeAppIDSnapshot.data!)!
.buildPage(context, _appsBloc),
), ),
], ],
], ],
@ -540,6 +538,14 @@ class _HomePageState extends State<HomePage> {
), ),
); );
final appProviders = _appsBloc.getAppProviders();
if (appProviders != null) {
body = MultiProvider(
providers: appProviders,
child: body,
);
}
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
if (_scaffoldKey.currentState!.isDrawerOpen) { if (_scaffoldKey.currentState!.isDrawerOpen) {

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

@ -24,9 +24,13 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppSpecificO
T buildBloc(final NextcloudClient client); T buildBloc(final NextcloudClient client);
Provider<T> blocProvider(final NextcloudClient client) => Provider<T>(
create: (final _) => buildBloc(client),
);
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc); BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc);
Widget buildPage(final BuildContext context, final AppsBloc appsBloc); Widget get page;
Widget buildIcon( Widget buildIcon(
final BuildContext context, { final BuildContext context, {

4
packages/neon/neon_files/lib/neon_files.dart

@ -62,9 +62,7 @@ class FilesApp extends AppImplementation<FilesBloc, FilesAppSpecificOptions> {
); );
@override @override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => FilesMainPage( Widget get page => const FilesMainPage();
bloc: appsBloc.getAppBloc(this),
);
@override @override
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null; BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null;

20
packages/neon/neon_files/lib/pages/main.dart

@ -2,22 +2,22 @@ part of '../neon_files.dart';
class FilesMainPage extends StatefulWidget { class FilesMainPage extends StatefulWidget {
const FilesMainPage({ const FilesMainPage({
required this.bloc,
super.key, super.key,
}); });
final FilesBloc bloc;
@override @override
State<FilesMainPage> createState() => _FilesMainPageState(); State<FilesMainPage> createState() => _FilesMainPageState();
} }
class _FilesMainPageState extends State<FilesMainPage> { class _FilesMainPageState extends State<FilesMainPage> {
late FilesBloc bloc;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
bloc = Provider.of<FilesBloc>(context, listen: false);
widget.bloc.errors.listen((final error) { bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error); NeonException.showSnackbar(context, error);
}); });
} }
@ -25,10 +25,10 @@ class _FilesMainPageState extends State<FilesMainPage> {
@override @override
Widget build(final BuildContext context) => Scaffold( Widget build(final BuildContext context) => Scaffold(
body: FilesBrowserView( body: FilesBrowserView(
bloc: widget.bloc.browser, bloc: bloc.browser,
filesBloc: widget.bloc, filesBloc: bloc,
onPickFile: (final details) async { onPickFile: (final details) async {
final sizeWarning = widget.bloc.options.downloadSizeWarning.value; final sizeWarning = bloc.options.downloadSizeWarning.value;
if (sizeWarning != null && details.size > sizeWarning) { if (sizeWarning != null && details.size > sizeWarning) {
// ignore: use_build_context_synchronously // ignore: use_build_context_synchronously
if (!(await showConfirmationDialog( if (!(await showConfirmationDialog(
@ -42,7 +42,7 @@ class _FilesMainPageState extends State<FilesMainPage> {
return; return;
} }
} }
widget.bloc.openFile(details.path, details.etag!, details.mimeType); bloc.openFile(details.path, details.etag!, details.mimeType);
}, },
), ),
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
@ -50,8 +50,8 @@ class _FilesMainPageState extends State<FilesMainPage> {
await showDialog( await showDialog(
context: context, context: context,
builder: (final context) => FilesChooseCreateDialog( builder: (final context) => FilesChooseCreateDialog(
bloc: widget.bloc, bloc: bloc,
basePath: widget.bloc.browser.path.value, basePath: bloc.browser.path.value,
), ),
); );
}, },

4
packages/neon/neon_news/lib/neon_news.dart

@ -68,9 +68,7 @@ class NewsApp extends AppImplementation<NewsBloc, NewsAppSpecificOptions> {
); );
@override @override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => NewsMainPage( Widget get page => const NewsMainPage();
bloc: appsBloc.getAppBloc(this),
);
@override @override
BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) => appsBloc.getAppBloc<NewsBloc>(this).unreadCounter; BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) => appsBloc.getAppBloc<NewsBloc>(this).unreadCounter;

21
packages/neon/neon_news/lib/pages/main.dart

@ -2,24 +2,23 @@ part of '../neon_news.dart';
class NewsMainPage extends StatefulWidget { class NewsMainPage extends StatefulWidget {
const NewsMainPage({ const NewsMainPage({
required this.bloc,
super.key, super.key,
}); });
final NewsBloc bloc;
@override @override
State<NewsMainPage> createState() => _NewsMainPageState(); State<NewsMainPage> createState() => _NewsMainPageState();
} }
class _NewsMainPageState extends State<NewsMainPage> { class _NewsMainPageState extends State<NewsMainPage> {
late int _index = widget.bloc.options.defaultCategoryOption.value.index; late NewsBloc bloc;
late int _index = bloc.options.defaultCategoryOption.value.index;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
final bloc = Provider.of<NewsBloc>(context, listen: false);
widget.bloc.errors.listen((final error) { bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error); NeonException.showSnackbar(context, error);
}); });
} }
@ -28,21 +27,21 @@ class _NewsMainPageState extends State<NewsMainPage> {
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final views = [ final views = [
NewsArticlesView( NewsArticlesView(
bloc: widget.bloc.mainArticlesBloc, bloc: bloc.mainArticlesBloc,
newsBloc: widget.bloc, newsBloc: bloc,
), ),
NewsFoldersView( NewsFoldersView(
bloc: widget.bloc, bloc: bloc,
), ),
NewsFeedsView( NewsFeedsView(
bloc: widget.bloc, bloc: bloc,
), ),
]; ];
final floatingActionButtons = [ final floatingActionButtons = [
null, null,
NewsFolderFloatingActionButton(bloc: widget.bloc), NewsFolderFloatingActionButton(bloc: bloc),
NewsFeedFloatingActionButton(bloc: widget.bloc), NewsFeedFloatingActionButton(bloc: bloc),
]; ];
return Scaffold( return Scaffold(

4
packages/neon/neon_notes/lib/neon_notes.dart

@ -58,9 +58,7 @@ class NotesApp extends AppImplementation<NotesBloc, NotesAppSpecificOptions> {
); );
@override @override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => NotesMainPage( Widget get page => const NotesMainPage();
bloc: appsBloc.getAppBloc(this),
);
@override @override
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null; BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc) => null;

16
packages/neon/neon_notes/lib/pages/main.dart

@ -2,24 +2,24 @@ part of '../neon_notes.dart';
class NotesMainPage extends StatefulWidget { class NotesMainPage extends StatefulWidget {
const NotesMainPage({ const NotesMainPage({
required this.bloc,
super.key, super.key,
}); });
final NotesBloc bloc;
@override @override
State<NotesMainPage> createState() => _NotesMainPageState(); State<NotesMainPage> createState() => _NotesMainPageState();
} }
class _NotesMainPageState extends State<NotesMainPage> { class _NotesMainPageState extends State<NotesMainPage> {
late int _index = widget.bloc.options.defaultCategoryOption.value.index; late NotesBloc bloc;
late int _index = bloc.options.defaultCategoryOption.value.index;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
widget.bloc.errors.listen((final error) { bloc = Provider.of<NotesBloc>(context, listen: false);
bloc.errors.listen((final error) {
handleNotesException(context, error); handleNotesException(context, error);
}); });
} }
@ -28,15 +28,15 @@ class _NotesMainPageState extends State<NotesMainPage> {
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final views = [ final views = [
NotesView( NotesView(
bloc: widget.bloc, bloc: bloc,
), ),
NotesCategoriesView( NotesCategoriesView(
bloc: widget.bloc, bloc: bloc,
), ),
]; ];
final floatingActionButtons = [ final floatingActionButtons = [
NotesFloatingActionButton(bloc: widget.bloc), NotesFloatingActionButton(bloc: bloc),
null, null,
]; ];

4
packages/neon/neon_notifications/lib/neon_notifications.dart

@ -37,9 +37,7 @@ class NotificationsApp extends NotificationsAppInterface {
); );
@override @override
Widget buildPage(final BuildContext context, final AppsBloc appsBloc) => NotificationsMainPage( Widget get page => const NotificationsMainPage();
bloc: appsBloc.getAppBloc(this),
);
@override @override
BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) => BehaviorSubject<int> getUnreadCounter(final AppsBloc appsBloc) =>

17
packages/neon/neon_notifications/lib/pages/main.dart

@ -2,34 +2,35 @@ part of '../neon_notifications.dart';
class NotificationsMainPage extends StatefulWidget { class NotificationsMainPage extends StatefulWidget {
const NotificationsMainPage({ const NotificationsMainPage({
required this.bloc,
super.key, super.key,
}); });
final NotificationsBloc bloc;
@override @override
State<NotificationsMainPage> createState() => _NotificationsMainPageState(); State<NotificationsMainPage> createState() => _NotificationsMainPageState();
} }
class _NotificationsMainPageState extends State<NotificationsMainPage> { class _NotificationsMainPageState extends State<NotificationsMainPage> {
late NotificationsBloc bloc;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
widget.bloc.errors.listen((final error) { bloc = Provider.of<NotificationsBloc>(context, listen: false);
bloc.errors.listen((final error) {
NeonException.showSnackbar(context, error); NeonException.showSnackbar(context, error);
}); });
} }
@override @override
Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotificationsNotification>>( Widget build(final BuildContext context) => ResultBuilder<List<NextcloudNotificationsNotification>>(
stream: widget.bloc.notifications, stream: bloc.notifications,
builder: (final context, final notifications) => Scaffold( builder: (final context, final notifications) => Scaffold(
resizeToAvoidBottomInset: false, resizeToAvoidBottomInset: false,
floatingActionButton: FloatingActionButton( floatingActionButton: FloatingActionButton(
onPressed: () async { onPressed: () async {
widget.bloc.deleteAllNotifications(); bloc.deleteAllNotifications();
}, },
tooltip: AppLocalizations.of(context).notificationsDismissAll, tooltip: AppLocalizations.of(context).notificationsDismissAll,
child: const Icon(MdiIcons.checkAll), child: const Icon(MdiIcons.checkAll),
@ -40,7 +41,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
items: notifications.data, items: notifications.data,
isLoading: notifications.loading, isLoading: notifications.loading,
error: notifications.error, error: notifications.error,
onRefresh: widget.bloc.refresh, onRefresh: bloc.refresh,
builder: _buildNotification, builder: _buildNotification,
), ),
), ),
@ -113,7 +114,7 @@ class _NotificationsMainPageState extends State<NotificationsMainPage> {
} }
}, },
onLongPress: () { onLongPress: () {
widget.bloc.deleteNotification(notification.notificationId); bloc.deleteNotification(notification.notificationId);
}, },
); );
} }

Loading…
Cancel
Save