diff --git a/lib/app.dart b/lib/app.dart index 21c5e32..ab84104 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -97,7 +97,7 @@ class _AppState extends State with WidgetsBindingObserver { controller: Main.bottomNavigator, navBarOverlap: const NavBarOverlap.none(), backgroundColor: Theme.of(context).colorScheme.primary, - handleAndroidBackButtonPress: false, + handleAndroidBackButtonPress: true, screenTransitionAnimation: const ScreenTransitionAnimation(curve: Curves.easeOutQuad, duration: Duration(milliseconds: 200)), tabs: [ diff --git a/lib/state/app/infrastructure/loadableState/view/loadable_state_consumer.dart b/lib/state/app/infrastructure/loadableState/view/loadable_state_consumer.dart index b0cdc65..00e24e3 100644 --- a/lib/state/app/infrastructure/loadableState/view/loadable_state_consumer.dart +++ b/lib/state/app/infrastructure/loadableState/view/loadable_state_consumer.dart @@ -17,13 +17,16 @@ class LoadableStateConsumer().state; + var loadableState = controllerByValue != null + ? controllerByValue!.state + : context.watch().state; if(!loadableState.isLoading && onLoad != null) { WidgetsBinding.instance.addPostFrameCallback((timeStamp) => onLoad!(loadableState.data)); diff --git a/lib/state/app/modules/files/bloc/files_bloc.dart b/lib/state/app/modules/files/bloc/files_bloc.dart index 8f2e68c..06c3960 100644 --- a/lib/state/app/modules/files/bloc/files_bloc.dart +++ b/lib/state/app/modules/files/bloc/files_bloc.dart @@ -1,6 +1,8 @@ import 'dart:developer'; +import 'package:sorted/sorted.dart'; + import '../../../infrastructure/utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc.dart'; import '../../../infrastructure/utilityWidgets/loadableHydratedBloc/loadable_hydrated_bloc_event.dart'; import '../repository/files_repository.dart'; @@ -36,6 +38,10 @@ class FilesBloc extends LoadableHydratedBloc [ + SortedComparable((file) => file.updatedAt ?? DateTime.now()), + ]; + @override FilesState fromNothing() => const FilesState(currentFolder: basePath, files: {}); diff --git a/lib/state/app/modules/files/view/files_view.dart b/lib/state/app/modules/files/view/files_view.dart index a1f888e..4498d1e 100644 --- a/lib/state/app/modules/files/view/files_view.dart +++ b/lib/state/app/modules/files/view/files_view.dart @@ -1,17 +1,9 @@ -import 'dart:developer'; - -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; -import 'package:jiffy/jiffy.dart'; - -import '../../../../../widget/centeredLeading.dart'; -import '../../../../../widget/list_view_util.dart'; import '../../../infrastructure/loadableState/loadable_state.dart'; -import '../../../infrastructure/loadableState/view/loadable_state_consumer.dart'; import '../../../infrastructure/utilityWidgets/bloc_module.dart'; import '../bloc/files_bloc.dart'; -import '../bloc/files_event.dart'; import '../bloc/files_state.dart'; +import 'folder_view.dart'; class FilesView extends StatelessWidget { const FilesView({super.key}); @@ -20,48 +12,6 @@ class FilesView extends StatelessWidget { Widget build(BuildContext context) => BlocModule>( create: (context) => FilesBloc(), autoRebuild: true, - child: (context, bloc, state) { - var goBackButton = !bloc.canGoBack() ? null : IconButton( - icon: const Icon(Icons.arrow_back), - onPressed: () { - bloc.add(EnterFolder(bloc.goBackLocation())); - }, - ); - return PopScope( - canPop: false, - onPopInvoked: (didPop) => bloc.add(EnterFolder(bloc.goBackLocation())), - child: Scaffold( - appBar: AppBar( - leading: goBackButton, - title: Text(bloc.getCurrentFolderName()), - - - actions: [ - IconButton(onPressed: () { - log(bloc.innerState?.toJson().toString() ?? 'leer'); - }, icon: const Icon(Icons.bug_report)), - IconButton(onPressed: () { - bloc.add(EnterFolder('/')); - }, icon: const Icon(Icons.home)), - ], - ), - body: LoadableStateConsumer( - child: (state, loading) => ListViewUtil.fromList(bloc.getVisibleFiles(), (file) => ListTile( - leading: CenteredLeading(Icon(file.isFolder ? Icons.folder : Icons.description_outlined)), - title: Text(file.name), - subtitle: file.isFolder - ? Text('geändert ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}') - : Text('${filesize(file.size)}, ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}'), - trailing: Icon(file.isFolder ? Icons.arrow_right : null), - onTap: () { - log(file.path); - if(!file.isFolder) return; - bloc.add(EnterFolder(file.path)); - }, - )) - ) - ), - ); - }, + child: (context, bloc, state) => FolderView(bloc), ); } diff --git a/lib/state/app/modules/files/view/folder_view.dart b/lib/state/app/modules/files/view/folder_view.dart new file mode 100644 index 0000000..07f1542 --- /dev/null +++ b/lib/state/app/modules/files/view/folder_view.dart @@ -0,0 +1,57 @@ +import 'dart:developer'; + +import 'package:filesize/filesize.dart'; +import 'package:flutter/material.dart'; +import 'package:jiffy/jiffy.dart'; + +import '../../../../../widget/centeredLeading.dart'; +import '../../../../../widget/list_view_util.dart'; +import '../../../infrastructure/loadableState/view/loadable_state_consumer.dart'; +import '../bloc/files_bloc.dart'; +import '../bloc/files_event.dart'; +import '../bloc/files_state.dart'; + +class FolderView extends StatelessWidget { + final FilesBloc bloc; + const FolderView(this.bloc, {super.key}); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar( + leading: !bloc.canGoBack() ? null : IconButton( + icon: const Icon(Icons.arrow_back), + onPressed: () { + bloc.add(EnterFolder(bloc.goBackLocation())); + Navigator.of(context).pop(); + }, + ), + title: Text(bloc.getCurrentFolderName()), + + actions: [ + IconButton(onPressed: () { + log(bloc.innerState?.toJson().toString() ?? 'leer'); + }, icon: const Icon(Icons.bug_report)), + IconButton(onPressed: () { + bloc.add(EnterFolder('/')); + }, icon: const Icon(Icons.home)), + ], + ), + body: LoadableStateConsumer( + controllerByValue: bloc, + child: (state, loading) => ListViewUtil.fromList(bloc.getVisibleFiles(), (file) => ListTile( + leading: CenteredLeading(Icon(file.isFolder ? Icons.folder : Icons.description_outlined)), + title: Text(file.name), + subtitle: file.isFolder + ? Text('geändert ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}') + : Text('${filesize(file.size)}, ${Jiffy.parseFromDateTime(file.updatedAt ?? DateTime.now()).fromNow()}'), + trailing: Icon(file.isFolder ? Icons.arrow_right : null), + onTap: () { + log(file.path); + if(!file.isFolder) return; + Navigator.of(context).push(MaterialPageRoute(builder: (context) => FolderView(bloc))); + bloc.add(EnterFolder(file.path)); + }, + )) + ) + ); +} diff --git a/lib/theming/lightAppTheme.dart b/lib/theming/lightAppTheme.dart index 97e9130..2c24ca4 100644 --- a/lib/theming/lightAppTheme.dart +++ b/lib/theming/lightAppTheme.dart @@ -8,6 +8,6 @@ class LightAppTheme { colorScheme: ColorScheme.fromSeed(seedColor: marianumRed), floatingActionButtonTheme: const FloatingActionButtonThemeData( foregroundColor: Colors.white - ) + ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index c74885e..422e69c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -104,6 +104,7 @@ dependencies: connectivity_plus: ^6.0.3 hydrated_bloc: ^9.1.5 dio: ^4.0.6 + sorted: ^2.1.0 dev_dependencies: flutter_test: