diff --git a/mobile/lib/src/application/night_stats/night_stats_cubit.dart b/mobile/lib/src/application/night_stats/night_stats_cubit.dart deleted file mode 100644 index f672f00c..00000000 --- a/mobile/lib/src/application/night_stats/night_stats_cubit.dart +++ /dev/null @@ -1,15 +0,0 @@ -import 'package:bloc/bloc.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:polydodo/src/domain/sleep_history/i_sleep_history_repository.dart'; -import 'night_stats_state.dart'; - -class NightStatsCubit extends Cubit { - final ISleepHistoryRepository _sleepHistoryRepository; - - NightStatsCubit(this._sleepHistoryRepository) - : super(NightStatsStateInitial()) { - _sleepHistoryRepository - .getSelectedNight() - .listen((nightStat) => {emit(NightStatsLoaded(nightStat))}); - } -} diff --git a/mobile/lib/src/application/night_stats/night_stats_state.dart b/mobile/lib/src/application/night_stats/night_stats_state.dart deleted file mode 100644 index a6131c19..00000000 --- a/mobile/lib/src/application/night_stats/night_stats_state.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; - -abstract class NightStatsState {} - -class NightStatsStateInitial extends NightStatsState {} - -class NightStatsLoaded extends NightStatsState { - final NightStats stats; - - NightStatsLoaded(this.stats); -} diff --git a/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart b/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart deleted file mode 100644 index 29a7c661..00000000 --- a/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart +++ /dev/null @@ -1,33 +0,0 @@ -import 'dart:async'; - -import 'package:bloc/bloc.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:polydodo/src/domain/sleep_history/i_sleep_history_repository.dart'; -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; -import 'sleep_history_state.dart'; - -class SleepHistoryCubit extends Cubit { - final ISleepHistoryRepository _sleepHistoryRepository; - - StreamSubscription> _sleepHistoryStream; - // todo: remove this variable, also test that switch works correctly once UI is done - bool usingBluetooth = true; - - SleepHistoryCubit(this._sleepHistoryRepository) - : super(SleepHistoryInitial()) { - loadHistory(); - } - - void loadHistory() { - _sleepHistoryRepository.initializeRepository(); - - _sleepHistoryStream ??= _sleepHistoryRepository - .watch() - .asBroadcastStream() - .listen((history) => emit(SleepHistoryLoaded(history))); - } - - void selectNight(NightStats night) { - _sleepHistoryRepository.selectNight(night); - } -} diff --git a/mobile/lib/src/application/sleep_history/sleep_history_state.dart b/mobile/lib/src/application/sleep_history/sleep_history_state.dart deleted file mode 100644 index 1c5d7bab..00000000 --- a/mobile/lib/src/application/sleep_history/sleep_history_state.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; - -abstract class SleepHistoryState {} - -class SleepHistoryInitial extends SleepHistoryState {} - -class SleepHistoryLoaded extends SleepHistoryState { - final List history; - - SleepHistoryLoaded(this.history); -} diff --git a/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart b/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart new file mode 100644 index 00000000..e31c5ad8 --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart @@ -0,0 +1,72 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:polydodo/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart'; +import 'package:polydodo/src/domain/sleep_sequence/i_sleep_sequence_repository.dart'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; +import 'sleep_sequence_history_state.dart'; + +class SleepSequenceHistoryCubit extends Cubit { + final ISleepSequenceRepository _sleepHistoryRepository; + final SleepSequenceStatsCubit _sleepSequenceStatsCubit; + final StreamController _selectText = + StreamController.broadcast(); + + List _selectedSequences; + + SleepSequenceHistoryCubit( + this._sleepHistoryRepository, this._sleepSequenceStatsCubit) + : super(SleepSequenceHistoryInitial()) { + loadHistory(); + } + + void loadHistory() { + emit(SleepSequenceHistoryLoaded( + _sleepHistoryRepository.getSleepSequences())); + } + + void loadSleepSequence(SleepSequenceStats sequence) { + _sleepSequenceStatsCubit.loadSleepSequence(sequence); + } + + void toggleSelectMode() { + if (state is SleepSequenceHistoryEditInProgress) { + _disableSelection(); + } else { + _enableSelection(); + } + } + + void _enableSelection() { + _selectedSequences = []; + _selectText.add('Done'); + emit(SleepSequenceHistoryEditInProgress( + _sleepHistoryRepository.getSleepSequences(), _selectedSequences)); + } + + void _disableSelection() { + _selectedSequences = null; + _selectText.add('Select'); + emit(SleepSequenceHistoryLoaded( + _sleepHistoryRepository.getSleepSequences())); + } + + void toggleSelectSequenceForDeletion(SleepSequenceStats sequence) { + if (_selectedSequences.contains(sequence)) { + _selectedSequences.remove(sequence); + } else { + _selectedSequences.add(sequence); + } + + emit(SleepSequenceHistoryEditInProgress( + _sleepHistoryRepository.getSleepSequences(), _selectedSequences)); + } + + void deleteSelected() { + _sleepHistoryRepository.deleteSleepSequences(_selectedSequences); + _disableSelection(); + } + + Stream get selectStream => _selectText.stream; +} diff --git a/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_state.dart b/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_state.dart new file mode 100644 index 00000000..bfe3c7d3 --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_state.dart @@ -0,0 +1,18 @@ +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; + +abstract class SleepSequenceHistoryState {} + +class SleepSequenceHistoryInitial extends SleepSequenceHistoryState {} + +class SleepSequenceHistoryLoaded extends SleepSequenceHistoryState { + final List history; + + SleepSequenceHistoryLoaded(this.history); +} + +class SleepSequenceHistoryEditInProgress extends SleepSequenceHistoryState { + final List history; + final List selectedSequences; + + SleepSequenceHistoryEditInProgress(this.history, this.selectedSequences); +} diff --git a/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart b/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart new file mode 100644 index 00000000..d4068fff --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart @@ -0,0 +1,15 @@ +import 'package:bloc/bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; +import 'sleep_sequence_stats_state.dart'; + +class SleepSequenceStatsCubit extends Cubit { + String titleText = ''; + + SleepSequenceStatsCubit() : super(SleepSequenceStatsInitial()); + + void loadSleepSequence(SleepSequenceStats sequence) { + titleText = sequence.stringId; + emit(SleepSequenceStatsLoaded(sequence)); + } +} diff --git a/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_state.dart b/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_state.dart new file mode 100644 index 00000000..958922fd --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_state.dart @@ -0,0 +1,11 @@ +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; + +abstract class SleepSequenceStatsState {} + +class SleepSequenceStatsInitial extends SleepSequenceStatsState {} + +class SleepSequenceStatsLoaded extends SleepSequenceStatsState { + final SleepSequenceStats stats; + + SleepSequenceStatsLoaded(this.stats); +} diff --git a/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart b/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart deleted file mode 100644 index ac139f6f..00000000 --- a/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'night_stats.dart'; - -abstract class ISleepHistoryRepository { - void initializeRepository(); - - void selectNight(NightStats stat); - - Stream getSelectedNight(); - - Stream> watch(); -} diff --git a/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart b/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart new file mode 100644 index 00000000..53001468 --- /dev/null +++ b/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart @@ -0,0 +1,7 @@ +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; + +abstract class ISleepSequenceRepository { + List getSleepSequences(); + + void deleteSleepSequences(List sequence); +} diff --git a/mobile/lib/src/domain/sleep_history/night_stats.dart b/mobile/lib/src/domain/sleep_sequence/sleep_sequence_stats.dart similarity index 86% rename from mobile/lib/src/domain/sleep_history/night_stats.dart rename to mobile/lib/src/domain/sleep_sequence/sleep_sequence_stats.dart index 2af7ee09..18ed13ee 100644 --- a/mobile/lib/src/domain/sleep_history/night_stats.dart +++ b/mobile/lib/src/domain/sleep_sequence/sleep_sequence_stats.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:polydodo/src/domain/entity.dart'; import 'package:flutter/foundation.dart'; -class NightStats extends Entity { +class SleepSequenceStats extends Entity { final DateTimeRange recordingTime; final DateTime effectiveSleepTime; final double sleepEfficiency; @@ -12,7 +12,7 @@ class NightStats extends Entity { final int remLatency; final int numberTransitions; - NightStats( + SleepSequenceStats( {id, @required this.recordingTime, @required this.effectiveSleepTime, @@ -24,5 +24,5 @@ class NightStats extends Entity { @required this.numberTransitions}) : super(id); - String get fileName => id.toString(); + String get stringId => id.toString(); } diff --git a/mobile/lib/src/infrastructure/sleep_history/mock_data.dart b/mobile/lib/src/infrastructure/sleep_history/mock_data.dart index 41ee768c..f4719e87 100644 --- a/mobile/lib/src/infrastructure/sleep_history/mock_data.dart +++ b/mobile/lib/src/infrastructure/sleep_history/mock_data.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; import 'package:polydodo/src/domain/unique_id.dart'; -NightStats mock_data_1 = NightStats( +SleepSequenceStats mock_data_1 = SleepSequenceStats( id: UniqueId.from('test'), awakenings: 3, effectiveSleepTime: DateTime.now(), @@ -13,7 +13,7 @@ NightStats mock_data_1 = NightStats( sleepLatency: 10, waso: DateTime.now()); -NightStats mock_data_2 = NightStats( +SleepSequenceStats mock_data_2 = SleepSequenceStats( id: UniqueId.from('test2'), awakenings: 100, effectiveSleepTime: DateTime.now(), diff --git a/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart b/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart index a6ff51dd..4ead4c9e 100644 --- a/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart +++ b/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart @@ -1,35 +1,26 @@ import 'dart:async'; -import 'package:polydodo/src/domain/sleep_history/i_sleep_history_repository.dart'; -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; +import 'package:polydodo/src/domain/sleep_sequence/i_sleep_sequence_repository.dart'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; import 'package:polydodo/src/infrastructure/sleep_history/mock_data.dart'; -class SleepHistoryRepository implements ISleepHistoryRepository { - final List _sleepHistoryPersistency = []; - final streamController = StreamController>(); - final nightStreamController = StreamController(); +class SleepHistoryRepository implements ISleepSequenceRepository { + final List _sleepHistoryPersistency = []; + final sequenceStreamController = StreamController(); - SleepHistoryRepository(); - - @override - void initializeRepository() { + SleepHistoryRepository() { _sleepHistoryPersistency.add(mock_data_1); _sleepHistoryPersistency.add(mock_data_2); - - streamController.add(_sleepHistoryPersistency); - } - - @override - void selectNight(NightStats stat) { - nightStreamController.add(stat); } @override - Stream getSelectedNight() => nightStreamController.stream; + List getSleepSequences() => _sleepHistoryPersistency; @override - Stream> watch() { - return streamController.stream; + void deleteSleepSequences(List sequences) { + for (var sequence in sequences) { + _sleepHistoryPersistency.remove(sequence); + } } } diff --git a/mobile/lib/src/locator.dart b/mobile/lib/src/locator.dart index 72b997ef..7a0f1be4 100644 --- a/mobile/lib/src/locator.dart +++ b/mobile/lib/src/locator.dart @@ -2,11 +2,11 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:get_it/get_it.dart'; import 'package:polydodo/src/application/device/device_selector_cubit.dart'; import 'package:polydodo/src/application/eeg_data/data_cubit.dart'; -import 'package:polydodo/src/application/night_stats/night_stats_cubit.dart'; -import 'package:polydodo/src/application/sleep_history/sleep_history_cubit.dart'; +import 'package:polydodo/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart'; +import 'package:polydodo/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart'; import 'package:polydodo/src/domain/acquisition_device/i_acquisition_device_repository.dart'; import 'package:polydodo/src/domain/eeg_data/i_eeg_data_repository.dart'; -import 'package:polydodo/src/domain/sleep_history/i_sleep_history_repository.dart'; +import 'package:polydodo/src/domain/sleep_sequence/i_sleep_sequence_repository.dart'; import 'package:polydodo/src/infrastructure/connection_repositories/acquisition_device_repository.dart'; import 'package:polydodo/src/infrastructure/connection_repositories/eeg_data_repository.dart'; import 'package:polydodo/src/infrastructure/sleep_history/sleep_history_repository.dart'; @@ -19,7 +19,7 @@ void registerServices() { AcquisitionDeviceRepository()); _serviceLocator.registerSingleton(EEGDataRepository()); _serviceLocator - .registerSingleton(SleepHistoryRepository()); + .registerSingleton(SleepHistoryRepository()); } /// This function creates all the BlocProviders used in this app @@ -35,10 +35,10 @@ List createBlocProviders() => [ _serviceLocator.get(), ), ), - BlocProvider( - create: (context) => SleepHistoryCubit( - _serviceLocator.get())), - BlocProvider( - create: (context) => - NightStatsCubit(_serviceLocator.get())), + BlocProvider( + create: (context) => SleepSequenceStatsCubit()), + BlocProvider( + create: (context) => SleepSequenceHistoryCubit( + _serviceLocator.get(), + BlocProvider.of(context))), ]; diff --git a/mobile/lib/src/presentation/navigation/navdrawer_tabs.dart b/mobile/lib/src/presentation/navigation/navdrawer_tabs.dart index 01a01b17..9c392844 100644 --- a/mobile/lib/src/presentation/navigation/navdrawer_tabs.dart +++ b/mobile/lib/src/presentation/navigation/navdrawer_tabs.dart @@ -3,5 +3,5 @@ enum NavdrawerTab { RecordSleep, BluetoothSelector, History, - NightStats + SleepSequenceStats } diff --git a/mobile/lib/src/presentation/navigation/routes/router.dart b/mobile/lib/src/presentation/navigation/routes/router.dart index a4b0f1a3..f375a268 100644 --- a/mobile/lib/src/presentation/navigation/routes/router.dart +++ b/mobile/lib/src/presentation/navigation/routes/router.dart @@ -5,9 +5,8 @@ import 'package:polydodo/src/presentation/pages/dashboard/dashboard_page.dart'; import 'package:polydodo/src/presentation/pages/record_sleep/record_sleep_guide_page.dart'; import 'package:polydodo/src/presentation/pages/record_sleep/record_sleep_recording_page.dart'; import 'package:polydodo/src/presentation/pages/record_sleep/record_sleep_validate_page.dart'; - import 'package:polydodo/src/presentation/pages/sleep_history_page/sleep_history_page.dart'; -import 'package:polydodo/src/presentation/pages/night_stats_page/night_stats_page.dart'; +import 'package:polydodo/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart'; @MaterialAutoRouter( generateNavigationHelperExtension: true, @@ -32,6 +31,7 @@ import 'package:polydodo/src/presentation/pages/night_stats_page/night_stats_pag page: SleepHistoryPage, transitionsBuilder: TransitionsBuilders.fadeIn), CustomRoute( - page: NightStatsPage, transitionsBuilder: TransitionsBuilders.fadeIn), + page: SleepSequenceStatsPage, + transitionsBuilder: TransitionsBuilders.fadeIn), ]) class $Router {} diff --git a/mobile/lib/src/presentation/pages/night_stats_page/night_stats_page.dart b/mobile/lib/src/presentation/pages/night_stats_page/night_stats_page.dart deleted file mode 100644 index 9e04cd2e..00000000 --- a/mobile/lib/src/presentation/pages/night_stats_page/night_stats_page.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'dart:async'; - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:polydodo/src/application/night_stats/night_stats_cubit.dart'; -import 'package:polydodo/src/application/night_stats/night_stats_state.dart'; -import 'package:polydodo/src/presentation/navigation/navdrawer_tabs.dart'; -import 'package:polydodo/src/presentation/navigation/navdrawer_widget.dart'; -import 'package:polydodo/src/presentation/pages/night_stats_page/metric_section.dart'; -import 'package:polydodo/src/presentation/pages/night_stats_page/sleep_stages_section.dart'; - -// todo: Normalize information with website - -class NightStatsPage extends StatelessWidget { - final appBloc = AppPropertiesBloc(); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - backgroundColor: Colors.transparent, - shadowColor: Colors.transparent, - centerTitle: true, - iconTheme: IconThemeData(color: Colors.black), - title: StreamBuilder( - stream: appBloc.titleStream, - initialData: 'Night Stat', - builder: (context, snapshot) { - return Text( - snapshot.data, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.indigo, - ), - ); - }), - actions: [ - Padding( - padding: EdgeInsets.only(right: 20.0), - child: GestureDetector( - onTap: () {/* todo: Add export */}, - child: Icon( - Icons.share, - size: 26.0, - ), - )), - ], - ), - drawer: NavDrawer(activeTab: NavdrawerTab.NightStats), - body: BlocConsumer( - listener: (context, state) { - print(state.runtimeType); - }, - builder: (context, state) { - if (state is NightStatsLoaded) { - appBloc.updateTitle(state.stats.id.toString()); - - return SingleChildScrollView( - child: Column( - children: [ - buildMetricSection(state.stats), - buildSleepStagesSection(state.stats) - ], - ), - ); - } else { - return Container(); - } - }, - )); - } -} - -class AppPropertiesBloc { - final StreamController _title = StreamController(); - - Stream get titleStream => _title.stream; - - void updateTitle(String newTitle) { - _title.sink.add(newTitle); - } - - void dispose() { - _title.close(); - } -} diff --git a/mobile/lib/src/presentation/pages/record_sleep/record_sleep_widgets.dart b/mobile/lib/src/presentation/pages/record_sleep/record_sleep_widgets.dart index e69de29b..8b137891 100644 --- a/mobile/lib/src/presentation/pages/record_sleep/record_sleep_widgets.dart +++ b/mobile/lib/src/presentation/pages/record_sleep/record_sleep_widgets.dart @@ -0,0 +1 @@ + diff --git a/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart b/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart new file mode 100644 index 00000000..1bae6640 --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; + +Widget buildAppBar(var historyCubit) { + return AppBar( + backgroundColor: Colors.transparent, + shadowColor: Colors.transparent, + centerTitle: true, + iconTheme: IconThemeData(color: Colors.black), + title: Text( + 'History', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.indigo, + ), + ), + actions: [ + Padding( + padding: EdgeInsets.only(top: 20.0, right: 20.0), + child: GestureDetector( + onTap: () => historyCubit.toggleSelectMode(), + child: _buildSelectButton(historyCubit), + )), + ], + ); +} + +Widget _buildSelectButton(var historyCubit) { + return StreamBuilder( + stream: historyCubit.selectStream, + initialData: 'Select', + builder: (context, snapshot) { + return Text( + snapshot.data, + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.bold, + color: Colors.black, + ), + ); + }); +} diff --git a/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart new file mode 100644 index 00000000..965a9e1f --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart @@ -0,0 +1,42 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; +import 'package:polydodo/src/application/sleep_sequence_history/sleep_sequence_history_state.dart'; +import 'package:polydodo/src/presentation/navigation/routes/router.gr.dart'; + +Widget buildHistoryList(var context, var state, var historyCubit) { + return ListView.builder( + itemCount: state.history.length, + itemBuilder: (context, index) { + return _buildItemCard(context, state, historyCubit, index); + }); +} + +Widget _buildItemCard(var context, var state, var historyCubit, var index) { + return Card( + child: ListTile( + onTap: () => { + if (state is SleepSequenceHistoryEditInProgress) + { + historyCubit.toggleSelectSequenceForDeletion(state.history[index]), + } + else + { + historyCubit.loadSleepSequence(state.history[index]), + ExtendedNavigator.of(context).push(Routes.sleepSequenceStatsPage) + } + }, + title: Text(state.history[index].id.toString()), + trailing: _buildTrailing(state, state.history[index]), + )); +} + +Widget _buildTrailing(var state, var sequence) { + if (!(state is SleepSequenceHistoryEditInProgress)) { + return Icon(Icons.navigate_next); + } + + return state.selectedSequences.contains(sequence) + ? Icon(Icons.check_circle_outline, color: Colors.blue) + : Icon(Icons.check_circle_outline); +} diff --git a/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_page.dart b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_page.dart index 29e927fa..278fbb25 100644 --- a/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_page.dart +++ b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_page.dart @@ -1,56 +1,46 @@ -import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:polydodo/src/application/sleep_history/sleep_history_cubit.dart'; -import 'package:polydodo/src/application/sleep_history/sleep_history_state.dart'; +import 'package:polydodo/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart'; +import 'package:polydodo/src/application/sleep_sequence_history/sleep_sequence_history_state.dart'; import 'package:polydodo/src/presentation/navigation/navdrawer_tabs.dart'; import 'package:polydodo/src/presentation/navigation/navdrawer_widget.dart'; -import 'package:polydodo/src/presentation/navigation/routes/router.gr.dart'; +import 'package:polydodo/src/presentation/pages/sleep_history_page/app_bar.dart'; +import 'package:polydodo/src/presentation/pages/sleep_history_page/sleep_history_list.dart'; class SleepHistoryPage extends StatelessWidget { @override Widget build(BuildContext context) { + final historyCubit = BlocProvider.of(context); + return Scaffold( - appBar: AppBar( - backgroundColor: Colors.transparent, - shadowColor: Colors.transparent, - centerTitle: true, - iconTheme: IconThemeData(color: Colors.black), - title: Text( - 'History', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.indigo, - ), - ), - ), - drawer: NavDrawer(activeTab: NavdrawerTab.History), - body: BlocConsumer( - listener: (context, state) { + appBar: buildAppBar(historyCubit), + drawer: NavDrawer(activeTab: NavdrawerTab.History), + body: + BlocConsumer( + listener: (context, state) { print(state.runtimeType); - }, - builder: (context, state) { - if (state is SleepHistoryLoaded) { - return ListView.builder( - itemCount: state.history.length, - itemBuilder: (context, index) { - return Card( - child: ListTile( - onTap: () => { - BlocProvider.of(context) - .selectNight(state.history[index]), - ExtendedNavigator.of(context) - .replace(Routes.nightStatsPage) - }, - title: Text(state.history[index].id.toString()), - )); - }); - } else { - return Container(); - } - }, - ), - ); + }, builder: (context, state) { + return (state is SleepSequenceHistoryLoaded || + state is SleepSequenceHistoryEditInProgress) + ? buildHistoryList(context, state, historyCubit) + : Container(); + }), + floatingActionButton: _buildFloatingActionButton(historyCubit)); } } + +Widget _buildFloatingActionButton(var historyCubit) { + return BlocConsumer( + listener: (context, state) => {}, + builder: (context, state) { + return (state is SleepSequenceHistoryEditInProgress) + ? Visibility( + visible: (state.selectedSequences?.isNotEmpty ?? false), + child: FloatingActionButton( + onPressed: () => historyCubit.deleteSelected(), + child: Icon(Icons.delete), + backgroundColor: Colors.red, + )) + : Container(); + }); +} diff --git a/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart new file mode 100644 index 00000000..b699dc45 --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart @@ -0,0 +1,37 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +Widget buildAppBar(var statsCubit) { + return AppBar( + backgroundColor: Colors.transparent, + shadowColor: Colors.transparent, + centerTitle: true, + iconTheme: IconThemeData(color: Colors.black), + title: Text( + statsCubit.titleText, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.indigo, + ), + ), + leading: Builder(builder: (BuildContext context) { + return IconButton( + icon: Icon(Icons.arrow_back), + onPressed: () => ExtendedNavigator.of(context).pop(), + ); + }), + actions: [ + Padding( + padding: EdgeInsets.only(right: 20.0), + child: IconButton( + onPressed: () {/* todo: Add export */}, + icon: Icon( + Icons.share, + size: 26.0, + ), + )), + ], + ); +} diff --git a/mobile/lib/src/presentation/pages/night_stats_page/metric_section.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/metric_section.dart similarity index 92% rename from mobile/lib/src/presentation/pages/night_stats_page/metric_section.dart rename to mobile/lib/src/presentation/pages/sleep_sequence_stats_page/metric_section.dart index 2d2c223d..654ae0f0 100644 --- a/mobile/lib/src/presentation/pages/night_stats_page/metric_section.dart +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/metric_section.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:intl/intl.dart'; -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; -Container buildMetricSection(NightStats stats) { +Container buildMetricSection(SleepSequenceStats stats) { return Container( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, diff --git a/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart new file mode 100644 index 00000000..77dab75b --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart @@ -0,0 +1,41 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:polydodo/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart'; +import 'package:polydodo/src/application/sleep_sequence_stats/sleep_sequence_stats_state.dart'; +import 'package:polydodo/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart'; +import 'package:polydodo/src/presentation/pages/sleep_sequence_stats_page/metric_section.dart'; +import 'package:polydodo/src/presentation/pages/sleep_sequence_stats_page/sleep_stages_section.dart'; + +// todo: Normalize information with website + +class SleepSequenceStatsPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + var statsCubit = BlocProvider.of(context); + return Scaffold( + appBar: buildAppBar(statsCubit), + body: BlocConsumer( + listener: (context, state) { + print(state.runtimeType); + }, + builder: (context, state) { + return _buildStatsBody(context, state, statsCubit); + }, + )); + } +} + +Widget _buildStatsBody(var context, var state, var statsCubit) { + if (!(state is SleepSequenceStatsLoaded)) { + return Container(); + } + + return SingleChildScrollView( + child: Column( + children: [ + buildMetricSection(state.stats), + buildSleepStagesSection(state.stats) + ], + ), + ); +} diff --git a/mobile/lib/src/presentation/pages/night_stats_page/sleep_stages_section.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_stages_section.dart similarity index 91% rename from mobile/lib/src/presentation/pages/night_stats_page/sleep_stages_section.dart rename to mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_stages_section.dart index 1505c19d..8b49fb1e 100644 --- a/mobile/lib/src/presentation/pages/night_stats_page/sleep_stages_section.dart +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_stages_section.dart @@ -1,11 +1,11 @@ +import 'dart:ui'; + import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:percent_indicator/percent_indicator.dart'; -import 'package:polydodo/src/domain/sleep_history/night_stats.dart'; - -import 'dart:ui'; +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; -Container buildSleepStagesSection(NightStats stats) { +Container buildSleepStagesSection(SleepSequenceStats stats) { return Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly,