From 3d3e6cd7f9d0edeed6d40790f80c3d1bc37e14bd Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Thu, 5 Nov 2020 15:42:48 -0500 Subject: [PATCH 1/8] Implemented history page night selection for deletion --- .../sleep_history/sleep_history_cubit.dart | 33 ++++++- .../sleep_history/sleep_history_state.dart | 3 +- .../i_sleep_history_repository.dart | 4 +- .../sleep_history_repository.dart | 11 ++- .../pages/night_stats_page/app_bar.dart | 35 ++++++++ .../night_stats_page/night_stats_page.dart | 32 +------ .../pages/sleep_history_page/app_bar.dart | 42 +++++++++ .../sleep_history_list.dart | 46 ++++++++++ .../sleep_history_page.dart | 88 +++++++++++-------- 9 files changed, 219 insertions(+), 75 deletions(-) create mode 100644 mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart create mode 100644 mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart create mode 100644 mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart diff --git a/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart b/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart index 29a7c661..a6e67de3 100644 --- a/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart +++ b/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart @@ -9,9 +9,10 @@ import 'sleep_history_state.dart'; class SleepHistoryCubit extends Cubit { final ISleepHistoryRepository _sleepHistoryRepository; + List _localHistory; StreamSubscription> _sleepHistoryStream; - // todo: remove this variable, also test that switch works correctly once UI is done - bool usingBluetooth = true; + List _selectedNights; + bool _selectMode = false; SleepHistoryCubit(this._sleepHistoryRepository) : super(SleepHistoryInitial()) { @@ -24,10 +25,34 @@ class SleepHistoryCubit extends Cubit { _sleepHistoryStream ??= _sleepHistoryRepository .watch() .asBroadcastStream() - .listen((history) => emit(SleepHistoryLoaded(history))); + .listen((history) => { + _localHistory = history, + emit(SleepHistoryLoaded(history, _selectedNights)) + }); + } + + void viewNight(NightStats night) { + _sleepHistoryRepository.viewNight(night); + } + + void toggleSelectMode() { + _selectMode = !_selectMode; + + _selectedNights = _selectMode ? [] : null; + + emit(SleepHistoryLoaded(_localHistory, _selectedNights)); } void selectNight(NightStats night) { - _sleepHistoryRepository.selectNight(night); + var idx = _selectedNights.indexOf(night); + + idx == -1 ? _selectedNights.add(night) : _selectedNights.remove(night); + + emit(SleepHistoryLoaded(_localHistory, _selectedNights)); + } + + void deleteSelected() { + _sleepHistoryRepository.deleteNights(_selectedNights); + toggleSelectMode(); } } diff --git a/mobile/lib/src/application/sleep_history/sleep_history_state.dart b/mobile/lib/src/application/sleep_history/sleep_history_state.dart index 1c5d7bab..8448609e 100644 --- a/mobile/lib/src/application/sleep_history/sleep_history_state.dart +++ b/mobile/lib/src/application/sleep_history/sleep_history_state.dart @@ -6,6 +6,7 @@ class SleepHistoryInitial extends SleepHistoryState {} class SleepHistoryLoaded extends SleepHistoryState { final List history; + final List selectedNights; - SleepHistoryLoaded(this.history); + SleepHistoryLoaded(this.history, this.selectedNights); } 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 index ac139f6f..cec57714 100644 --- a/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart +++ b/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart @@ -3,9 +3,11 @@ import 'night_stats.dart'; abstract class ISleepHistoryRepository { void initializeRepository(); - void selectNight(NightStats stat); + void viewNight(NightStats stat); Stream getSelectedNight(); + void deleteNights(List nights); + Stream> watch(); } 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..142b8c5c 100644 --- a/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart +++ b/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart @@ -21,13 +21,22 @@ class SleepHistoryRepository implements ISleepHistoryRepository { } @override - void selectNight(NightStats stat) { + void viewNight(NightStats stat) { nightStreamController.add(stat); } @override Stream getSelectedNight() => nightStreamController.stream; + @override + void deleteNights(List nights) { + for (var night in nights) { + _sleepHistoryPersistency.remove(night); + } + + streamController.add(_sleepHistoryPersistency); + } + @override Stream> watch() { return streamController.stream; diff --git a/mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart b/mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart new file mode 100644 index 00000000..935b3dd7 --- /dev/null +++ b/mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart @@ -0,0 +1,35 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.dart'; + +Widget buildAppBar(var appBloc) { + return 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, + ), + )), + ], + ); +} 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 index 9e04cd2e..291fe327 100644 --- 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 @@ -6,6 +6,7 @@ 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/app_bar.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'; @@ -17,36 +18,7 @@ class NightStatsPage extends StatelessWidget { @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, - ), - )), - ], - ), + appBar: buildAppBar(appBloc), drawer: NavDrawer(activeTab: NavdrawerTab.NightStats), body: BlocConsumer( listener: (context, state) { 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..9f58404c --- /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, var appBloc) { + 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(appBloc), + )), + ], + ); +} + +Widget _buildSelectButton(var appBloc) { + return StreamBuilder( + stream: appBloc.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..bb1fe695 --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart @@ -0,0 +1,46 @@ +import 'package:auto_route/auto_route.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.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) { + var selectMode = state.selectedNights != null; + + return Card( + child: ListTile( + onTap: () => { + if (selectMode) + { + historyCubit.selectNight(state.history[index]), + } + else + { + historyCubit.viewNight(state.history[index]), + ExtendedNavigator.of(context).replace(Routes.nightStatsPage) + } + }, + title: Text(state.history[index].id.toString()), + trailing: _buildTrailing(state, selectMode, state.history[index]), + )); +} + +Widget _buildTrailing(var state, var selectMode, var night) { + if (selectMode) { + return state.selectedNights.contains(night) + ? Icon( + Icons.check_circle_outline, + color: Colors.blue, + ) + : Icon(Icons.check_circle_outline); + } else { + return Icon(Icons.navigate_next); + } +} 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..dd5adf14 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,68 @@ -import 'package:auto_route/auto_route.dart'; +import 'dart:async'; + 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/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 { + final appBloc = AppPropertiesBloc(); + @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, appBloc), + drawer: NavDrawer(activeTab: NavdrawerTab.History), + body: BlocConsumer( + listener: (context, state) { print(state.runtimeType); - }, - builder: (context, state) { + }, 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()), - )); - }); + appBloc.updateSelectText(state.selectedNights != null); + + return buildHistoryList(context, state, historyCubit); } else { return Container(); } - }, - ), - ); + }), + floatingActionButton: _buildFloatingActionButton(historyCubit)); } } + +class AppPropertiesBloc { + final StreamController _select = StreamController(); + + Stream get selectStream => _select.stream; + + void updateSelectText(bool selectMode) { + _select.sink.add(selectMode ? 'Done' : 'Select'); + } + + void dispose() { + _select.close(); + } +} + +Widget _buildFloatingActionButton(var historyCubit) { + return BlocConsumer( + listener: (context, state) => {}, + builder: (context, state) { + if (state is SleepHistoryLoaded) { + return Visibility( + visible: (state.selectedNights?.isNotEmpty ?? false), + child: FloatingActionButton( + onPressed: () => historyCubit.deleteSelected(), + child: Icon(Icons.delete), + backgroundColor: Colors.red, + )); + } else { + return Container(); + } + }); +} From 94d696367dd02a5dec0830167a8f54c0dfa26c95 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Sun, 8 Nov 2020 16:58:28 -0500 Subject: [PATCH 2/8] Changed night stats to Sleep sequence, removed localHistory and AppPropertiesBloc --- .../night_stats/night_stats_cubit.dart | 15 ----- .../night_stats/night_stats_state.dart | 11 --- .../sleep_history/sleep_history_cubit.dart | 58 ---------------- .../sleep_history/sleep_history_state.dart | 12 ---- .../sleep_sequence_history_cubit.dart | 67 +++++++++++++++++++ .../sleep_sequence_history_state.dart | 18 +++++ .../sleep_sequence_stats_cubit.dart | 24 +++++++ .../sleep_sequence_stats_state.dart | 11 +++ .../i_sleep_history_repository.dart | 13 ---- .../i_sleep_sequence_repository.dart | 10 +++ .../sleep_sequence_stats.dart} | 6 +- .../sleep_history/mock_data.dart | 6 +- .../sleep_history_repository.dart | 39 +++++------ mobile/lib/src/locator.dart | 20 +++--- .../navigation/navdrawer_tabs.dart | 2 +- .../navigation/routes/router.dart | 5 +- .../night_stats_page/night_stats_page.dart | 59 ---------------- .../pages/sleep_history_page/app_bar.dart | 8 +-- .../sleep_history_list.dart | 19 +++--- .../sleep_history_page.dart | 42 ++++-------- .../app_bar.dart | 6 +- .../metric_section.dart | 4 +- .../sleep_sequence_stats_page.dart | 42 ++++++++++++ .../sleep_stages_section.dart | 8 +-- 24 files changed, 241 insertions(+), 264 deletions(-) delete mode 100644 mobile/lib/src/application/night_stats/night_stats_cubit.dart delete mode 100644 mobile/lib/src/application/night_stats/night_stats_state.dart delete mode 100644 mobile/lib/src/application/sleep_history/sleep_history_cubit.dart delete mode 100644 mobile/lib/src/application/sleep_history/sleep_history_state.dart create mode 100644 mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart create mode 100644 mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_state.dart create mode 100644 mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart create mode 100644 mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_state.dart delete mode 100644 mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart create mode 100644 mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart rename mobile/lib/src/domain/{sleep_history/night_stats.dart => sleep_sequence/sleep_sequence_stats.dart} (86%) delete mode 100644 mobile/lib/src/presentation/pages/night_stats_page/night_stats_page.dart rename mobile/lib/src/presentation/pages/{night_stats_page => sleep_sequence_stats_page}/app_bar.dart (87%) rename mobile/lib/src/presentation/pages/{night_stats_page => sleep_sequence_stats_page}/metric_section.dart (92%) create mode 100644 mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart rename mobile/lib/src/presentation/pages/{night_stats_page => sleep_sequence_stats_page}/sleep_stages_section.dart (91%) 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 a6e67de3..00000000 --- a/mobile/lib/src/application/sleep_history/sleep_history_cubit.dart +++ /dev/null @@ -1,58 +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; - - List _localHistory; - StreamSubscription> _sleepHistoryStream; - List _selectedNights; - bool _selectMode = false; - - SleepHistoryCubit(this._sleepHistoryRepository) - : super(SleepHistoryInitial()) { - loadHistory(); - } - - void loadHistory() { - _sleepHistoryRepository.initializeRepository(); - - _sleepHistoryStream ??= _sleepHistoryRepository - .watch() - .asBroadcastStream() - .listen((history) => { - _localHistory = history, - emit(SleepHistoryLoaded(history, _selectedNights)) - }); - } - - void viewNight(NightStats night) { - _sleepHistoryRepository.viewNight(night); - } - - void toggleSelectMode() { - _selectMode = !_selectMode; - - _selectedNights = _selectMode ? [] : null; - - emit(SleepHistoryLoaded(_localHistory, _selectedNights)); - } - - void selectNight(NightStats night) { - var idx = _selectedNights.indexOf(night); - - idx == -1 ? _selectedNights.add(night) : _selectedNights.remove(night); - - emit(SleepHistoryLoaded(_localHistory, _selectedNights)); - } - - void deleteSelected() { - _sleepHistoryRepository.deleteNights(_selectedNights); - toggleSelectMode(); - } -} 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 8448609e..00000000 --- a/mobile/lib/src/application/sleep_history/sleep_history_state.dart +++ /dev/null @@ -1,12 +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; - final List selectedNights; - - SleepHistoryLoaded(this.history, this.selectedNights); -} 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..9713a3f6 --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_history/sleep_sequence_history_cubit.dart @@ -0,0 +1,67 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.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 StreamController _selectText = + StreamController.broadcast(); + + List _selectedSequences; + bool _selectMode = false; + + SleepSequenceHistoryCubit(this._sleepHistoryRepository) + : super(SleepSequenceHistoryInitial()) { + loadHistory(); + } + + void loadHistory() { + emit(SleepSequenceHistoryLoaded( + _sleepHistoryRepository.getSleepSequences())); + } + + void selectSleepSequenceForViewing(SleepSequenceStats sequence) { + _sleepHistoryRepository.selectSleepSequence(sequence); + } + + void toggleSelectMode() { + _selectMode = !_selectMode; + + _selectMode + ? { + _selectedSequences = [], + _selectText.add('Done'), + emit(SleepSequenceHistoryEditInProgress( + _sleepHistoryRepository.getSleepSequences(), + _selectedSequences)) + } + : { + _selectedSequences = null, + _selectText.add('Select'), + emit(SleepSequenceHistoryLoaded( + _sleepHistoryRepository.getSleepSequences())) + }; + } + + void selectSleepSequenceForDeletion(SleepSequenceStats sequence) { + var idx = _selectedSequences.indexOf(sequence); + + idx == -1 + ? _selectedSequences.add(sequence) + : _selectedSequences.remove(sequence); + + emit(SleepSequenceHistoryEditInProgress( + _sleepHistoryRepository.getSleepSequences(), _selectedSequences)); + } + + void deleteSelected() { + _sleepHistoryRepository.deleteSleepSequences(_selectedSequences); + toggleSelectMode(); + } + + 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..040a92b8 --- /dev/null +++ b/mobile/lib/src/application/sleep_sequence_stats/sleep_sequence_stats_cubit.dart @@ -0,0 +1,24 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:polydodo/src/domain/sleep_sequence/i_sleep_sequence_repository.dart'; +import 'sleep_sequence_stats_state.dart'; + +class SleepSequenceStatsCubit extends Cubit { + final ISleepSequenceRepository _sleepHistoryRepository; + final StreamController _titleText = + StreamController.broadcast(); + + SleepSequenceStatsCubit(this._sleepHistoryRepository) + : super(SleepSequenceStatsInitial()) { + _sleepHistoryRepository.getSelectedSleepSequence().listen( + (sleepSequence) => {emit(SleepSequenceStatsLoaded(sleepSequence))}); + } + + void updateTitle(String id) { + _titleText.add(id); + } + + Stream get titleStream => _titleText.stream; +} 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 cec57714..00000000 --- a/mobile/lib/src/domain/sleep_history/i_sleep_history_repository.dart +++ /dev/null @@ -1,13 +0,0 @@ -import 'night_stats.dart'; - -abstract class ISleepHistoryRepository { - void initializeRepository(); - - void viewNight(NightStats stat); - - Stream getSelectedNight(); - - void deleteNights(List nights); - - 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..41b91bcd --- /dev/null +++ b/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart @@ -0,0 +1,10 @@ +import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; + +abstract class ISleepSequenceRepository { + void selectSleepSequence(SleepSequenceStats sequence); + + List getSleepSequences(); + Stream getSelectedSleepSequence(); + + 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 142b8c5c..9347f610 100644 --- a/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart +++ b/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart @@ -1,44 +1,35 @@ 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 viewNight(NightStats stat) { - nightStreamController.add(stat); + void selectSleepSequence(SleepSequenceStats sequence) { + sequenceStreamController.add(sequence); } @override - Stream getSelectedNight() => nightStreamController.stream; + List getSleepSequences() => _sleepHistoryPersistency; @override - void deleteNights(List nights) { - for (var night in nights) { - _sleepHistoryPersistency.remove(night); - } - - streamController.add(_sleepHistoryPersistency); - } + Stream getSelectedSleepSequence() => + sequenceStreamController.stream; @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..dd1311ef 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) => SleepSequenceHistoryCubit( + _serviceLocator.get())), + BlocProvider( + create: (context) => SleepSequenceStatsCubit( + _serviceLocator.get())), ]; 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 134c94ef..86c8858d 100644 --- a/mobile/lib/src/presentation/navigation/routes/router.dart +++ b/mobile/lib/src/presentation/navigation/routes/router.dart @@ -3,8 +3,8 @@ import 'package:auto_route/auto_route_annotations.dart'; import 'package:polydodo/src/presentation/pages/bluetooth_page/bluetoothSelector_page.dart'; import 'package:polydodo/src/presentation/pages/dashboard/dashboard_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/record_sleep/record_sleep_guide_page.dart'; +import 'package:polydodo/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart'; @MaterialAutoRouter( generateNavigationHelperExtension: true, @@ -26,6 +26,7 @@ import 'package:polydodo/src/presentation/pages/record_sleep/record_sleep_guide_ 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 291fe327..00000000 --- a/mobile/lib/src/presentation/pages/night_stats_page/night_stats_page.dart +++ /dev/null @@ -1,59 +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/app_bar.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: buildAppBar(appBloc), - 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/sleep_history_page/app_bar.dart b/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart index 9f58404c..1bae6640 100644 --- a/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart +++ b/mobile/lib/src/presentation/pages/sleep_history_page/app_bar.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -Widget buildAppBar(var historyCubit, var appBloc) { +Widget buildAppBar(var historyCubit) { return AppBar( backgroundColor: Colors.transparent, shadowColor: Colors.transparent, @@ -19,15 +19,15 @@ Widget buildAppBar(var historyCubit, var appBloc) { padding: EdgeInsets.only(top: 20.0, right: 20.0), child: GestureDetector( onTap: () => historyCubit.toggleSelectMode(), - child: _buildSelectButton(appBloc), + child: _buildSelectButton(historyCubit), )), ], ); } -Widget _buildSelectButton(var appBloc) { +Widget _buildSelectButton(var historyCubit) { return StreamBuilder( - stream: appBloc.selectStream, + stream: historyCubit.selectStream, initialData: 'Select', builder: (context, snapshot) { return Text( 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 index bb1fe695..de026608 100644 --- 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 @@ -1,6 +1,7 @@ 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) { @@ -12,29 +13,27 @@ Widget buildHistoryList(var context, var state, var historyCubit) { } Widget _buildItemCard(var context, var state, var historyCubit, var index) { - var selectMode = state.selectedNights != null; - return Card( child: ListTile( onTap: () => { - if (selectMode) + if (state is SleepSequenceHistoryEditInProgress) { - historyCubit.selectNight(state.history[index]), + historyCubit.selectSleepSequenceForDeletion(state.history[index]), } else { - historyCubit.viewNight(state.history[index]), - ExtendedNavigator.of(context).replace(Routes.nightStatsPage) + historyCubit.selectSleepSequenceForViewing(state.history[index]), + ExtendedNavigator.of(context).replace(Routes.sleepSequenceStatsPage) } }, title: Text(state.history[index].id.toString()), - trailing: _buildTrailing(state, selectMode, state.history[index]), + trailing: _buildTrailing(state, state.history[index]), )); } -Widget _buildTrailing(var state, var selectMode, var night) { - if (selectMode) { - return state.selectedNights.contains(night) +Widget _buildTrailing(var state, var sequence) { + if (state is SleepSequenceHistoryEditInProgress) { + return state.selectedSequences.contains(sequence) ? Icon( Icons.check_circle_outline, color: Colors.blue, 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 dd5adf14..5cf1e1eb 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,31 +1,27 @@ -import 'dart:async'; - 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/pages/sleep_history_page/app_bar.dart'; import 'package:polydodo/src/presentation/pages/sleep_history_page/sleep_history_list.dart'; class SleepHistoryPage extends StatelessWidget { - final appBloc = AppPropertiesBloc(); - @override Widget build(BuildContext context) { - final historyCubit = BlocProvider.of(context); + final historyCubit = BlocProvider.of(context); return Scaffold( - appBar: buildAppBar(historyCubit, appBloc), + appBar: buildAppBar(historyCubit), drawer: NavDrawer(activeTab: NavdrawerTab.History), - body: BlocConsumer( - listener: (context, state) { + body: + BlocConsumer( + listener: (context, state) { print(state.runtimeType); }, builder: (context, state) { - if (state is SleepHistoryLoaded) { - appBloc.updateSelectText(state.selectedNights != null); - + if (state is SleepSequenceHistoryLoaded || + state is SleepSequenceHistoryEditInProgress) { return buildHistoryList(context, state, historyCubit); } else { return Container(); @@ -35,27 +31,13 @@ class SleepHistoryPage extends StatelessWidget { } } -class AppPropertiesBloc { - final StreamController _select = StreamController(); - - Stream get selectStream => _select.stream; - - void updateSelectText(bool selectMode) { - _select.sink.add(selectMode ? 'Done' : 'Select'); - } - - void dispose() { - _select.close(); - } -} - Widget _buildFloatingActionButton(var historyCubit) { - return BlocConsumer( + return BlocConsumer( listener: (context, state) => {}, builder: (context, state) { - if (state is SleepHistoryLoaded) { + if (state is SleepSequenceHistoryEditInProgress) { return Visibility( - visible: (state.selectedNights?.isNotEmpty ?? false), + visible: (state.selectedSequences?.isNotEmpty ?? false), child: FloatingActionButton( onPressed: () => historyCubit.deleteSelected(), child: Icon(Icons.delete), diff --git a/mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart similarity index 87% rename from mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart rename to mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart index 935b3dd7..05d3f490 100644 --- a/mobile/lib/src/presentation/pages/night_stats_page/app_bar.dart +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/app_bar.dart @@ -1,15 +1,15 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -Widget buildAppBar(var appBloc) { +Widget buildAppBar(var statsCubit) { return AppBar( backgroundColor: Colors.transparent, shadowColor: Colors.transparent, centerTitle: true, iconTheme: IconThemeData(color: Colors.black), title: StreamBuilder( - stream: appBloc.titleStream, - initialData: 'Night Stat', + stream: statsCubit.titleStream, + initialData: 'Sleep Sequence Stat', builder: (context, snapshot) { return Text( snapshot.data, 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..9c9406ad --- /dev/null +++ b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart @@ -0,0 +1,42 @@ +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/navigation/navdrawer_tabs.dart'; +import 'package:polydodo/src/presentation/navigation/navdrawer_widget.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), + drawer: NavDrawer(activeTab: NavdrawerTab.SleepSequenceStats), + body: BlocConsumer( + listener: (context, state) { + print(state.runtimeType); + }, + builder: (context, state) { + if (state is SleepSequenceStatsLoaded) { + statsCubit.updateTitle(state.stats.stringId); + + return SingleChildScrollView( + child: Column( + children: [ + buildMetricSection(state.stats), + buildSleepStagesSection(state.stats) + ], + ), + ); + } else { + return Container(); + } + }, + )); + } +} 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, From 88fad137fcda566dadc8a7ff7b829b0523c1fe55 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Mon, 9 Nov 2020 18:26:15 -0500 Subject: [PATCH 3/8] Added guard clauses and swapped ternary operators to if else --- .../sleep_sequence_history_cubit.dart | 35 +++++++++++-------- .../sleep_history_list.dart | 13 +++---- .../sleep_history_page.dart | 30 +++++++--------- .../sleep_sequence_stats_page.dart | 32 +++++++++-------- 4 files changed, 56 insertions(+), 54 deletions(-) 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 index 9713a3f6..9cf30a1b 100644 --- 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 @@ -31,20 +31,25 @@ class SleepSequenceHistoryCubit extends Cubit { void toggleSelectMode() { _selectMode = !_selectMode; - _selectMode - ? { - _selectedSequences = [], - _selectText.add('Done'), - emit(SleepSequenceHistoryEditInProgress( - _sleepHistoryRepository.getSleepSequences(), - _selectedSequences)) - } - : { - _selectedSequences = null, - _selectText.add('Select'), - emit(SleepSequenceHistoryLoaded( - _sleepHistoryRepository.getSleepSequences())) - }; + if (_selectMode) { + _enableSelection(); + } else { + _disableSelection(); + } + } + + void _enableSelection() { + _selectedSequences = []; + _selectText.add('Done'); + emit(SleepSequenceHistoryEditInProgress( + _sleepHistoryRepository.getSleepSequences(), _selectedSequences)); + } + + void _disableSelection() { + _selectedSequences = null; + _selectText.add('Select'); + emit(SleepSequenceHistoryLoaded( + _sleepHistoryRepository.getSleepSequences())); } void selectSleepSequenceForDeletion(SleepSequenceStats sequence) { @@ -60,7 +65,7 @@ class SleepSequenceHistoryCubit extends Cubit { void deleteSelected() { _sleepHistoryRepository.deleteSleepSequences(_selectedSequences); - toggleSelectMode(); + _disableSelection(); } Stream get selectStream => _selectText.stream; 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 index de026608..96eb70c3 100644 --- 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 @@ -32,14 +32,11 @@ Widget _buildItemCard(var context, var state, var historyCubit, var index) { } Widget _buildTrailing(var state, var sequence) { - if (state is SleepSequenceHistoryEditInProgress) { - return state.selectedSequences.contains(sequence) - ? Icon( - Icons.check_circle_outline, - color: Colors.blue, - ) - : Icon(Icons.check_circle_outline); - } else { + 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 5cf1e1eb..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 @@ -20,12 +20,10 @@ class SleepHistoryPage extends StatelessWidget { listener: (context, state) { print(state.runtimeType); }, builder: (context, state) { - if (state is SleepSequenceHistoryLoaded || - state is SleepSequenceHistoryEditInProgress) { - return buildHistoryList(context, state, historyCubit); - } else { - return Container(); - } + return (state is SleepSequenceHistoryLoaded || + state is SleepSequenceHistoryEditInProgress) + ? buildHistoryList(context, state, historyCubit) + : Container(); }), floatingActionButton: _buildFloatingActionButton(historyCubit)); } @@ -35,16 +33,14 @@ Widget _buildFloatingActionButton(var historyCubit) { return BlocConsumer( listener: (context, state) => {}, builder: (context, state) { - if (state is SleepSequenceHistoryEditInProgress) { - return Visibility( - visible: (state.selectedSequences?.isNotEmpty ?? false), - child: FloatingActionButton( - onPressed: () => historyCubit.deleteSelected(), - child: Icon(Icons.delete), - backgroundColor: Colors.red, - )); - } else { - return Container(); - } + 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/sleep_sequence_stats_page.dart b/mobile/lib/src/presentation/pages/sleep_sequence_stats_page/sleep_sequence_stats_page.dart index 9c9406ad..09810af4 100644 --- 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 @@ -22,21 +22,25 @@ class SleepSequenceStatsPage extends StatelessWidget { print(state.runtimeType); }, builder: (context, state) { - if (state is SleepSequenceStatsLoaded) { - statsCubit.updateTitle(state.stats.stringId); - - return SingleChildScrollView( - child: Column( - children: [ - buildMetricSection(state.stats), - buildSleepStagesSection(state.stats) - ], - ), - ); - } else { - return Container(); - } + return _buildStatsBody(context, state, statsCubit); }, )); } } + +Widget _buildStatsBody(var context, var state, var statsCubit) { + if (!(state is SleepSequenceStatsLoaded)) { + return Container(); + } + + statsCubit.updateTitle(state.stats.stringId); + + return SingleChildScrollView( + child: Column( + children: [ + buildMetricSection(state.stats), + buildSleepStagesSection(state.stats) + ], + ), + ); +} From 631044dae3d0a8ade468dae56cda814a63c1ce53 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Mon, 9 Nov 2020 19:45:11 -0500 Subject: [PATCH 4/8] Changed function to make it more clear we can select and deselect --- .../sleep_sequence_history_cubit.dart | 12 ++++++------ .../pages/sleep_history_page/sleep_history_list.dart | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) 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 index 9cf30a1b..b7d4bd73 100644 --- 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 @@ -52,12 +52,12 @@ class SleepSequenceHistoryCubit extends Cubit { _sleepHistoryRepository.getSleepSequences())); } - void selectSleepSequenceForDeletion(SleepSequenceStats sequence) { - var idx = _selectedSequences.indexOf(sequence); - - idx == -1 - ? _selectedSequences.add(sequence) - : _selectedSequences.remove(sequence); + void toggleSelectSequenceForDeletion(SleepSequenceStats sequence) { + if (_selectedSequences.contains(sequence)) { + _selectedSequences.remove(sequence); + } else { + _selectedSequences.add(sequence); + } emit(SleepSequenceHistoryEditInProgress( _sleepHistoryRepository.getSleepSequences(), _selectedSequences)); 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 index 96eb70c3..040ffc84 100644 --- 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 @@ -18,7 +18,7 @@ Widget _buildItemCard(var context, var state, var historyCubit, var index) { onTap: () => { if (state is SleepSequenceHistoryEditInProgress) { - historyCubit.selectSleepSequenceForDeletion(state.history[index]), + historyCubit.toggleSelectSequenceForDeletion(state.history[index]), } else { From 87363295d0744a9552bce78785d2294075c51eff Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Tue, 10 Nov 2020 11:12:42 -0500 Subject: [PATCH 5/8] Fixed _deleteSelected not setting select mode to false and replaced drawer by back button in sleep sequence stat page --- .../sleep_sequence_history_cubit.dart | 8 ++++---- .../pages/record_sleep/record_sleep_widgets.dart | 1 + .../sleep_history_page/sleep_history_list.dart | 2 +- .../pages/sleep_sequence_stats_page/app_bar.dart | 13 ++++++++++--- .../sleep_sequence_stats_page.dart | 2 -- 5 files changed, 16 insertions(+), 10 deletions(-) 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 index b7d4bd73..8241192d 100644 --- 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 @@ -29,16 +29,15 @@ class SleepSequenceHistoryCubit extends Cubit { } void toggleSelectMode() { - _selectMode = !_selectMode; - if (_selectMode) { - _enableSelection(); - } else { _disableSelection(); + } else { + _enableSelection(); } } void _enableSelection() { + _selectMode = true; _selectedSequences = []; _selectText.add('Done'); emit(SleepSequenceHistoryEditInProgress( @@ -46,6 +45,7 @@ class SleepSequenceHistoryCubit extends Cubit { } void _disableSelection() { + _selectMode = false; _selectedSequences = null; _selectText.add('Select'); emit(SleepSequenceHistoryLoaded( 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/sleep_history_list.dart b/mobile/lib/src/presentation/pages/sleep_history_page/sleep_history_list.dart index 040ffc84..99935bdd 100644 --- 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 @@ -23,7 +23,7 @@ Widget _buildItemCard(var context, var state, var historyCubit, var index) { else { historyCubit.selectSleepSequenceForViewing(state.history[index]), - ExtendedNavigator.of(context).replace(Routes.sleepSequenceStatsPage) + ExtendedNavigator.of(context).push(Routes.sleepSequenceStatsPage) } }, title: Text(state.history[index].id.toString()), 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 index 05d3f490..7eb9d332 100644 --- 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 @@ -1,3 +1,4 @@ +import 'package:auto_route/auto_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; @@ -20,12 +21,18 @@ Widget buildAppBar(var statsCubit) { ), ); }), + 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: GestureDetector( - onTap: () {/* todo: Add export */}, - child: Icon( + child: IconButton( + onPressed: () {/* todo: Add export */}, + icon: Icon( Icons.share, size: 26.0, ), 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 index 09810af4..8a399608 100644 --- 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 @@ -3,7 +3,6 @@ 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/navigation/navdrawer_tabs.dart'; -import 'package:polydodo/src/presentation/navigation/navdrawer_widget.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'; @@ -16,7 +15,6 @@ class SleepSequenceStatsPage extends StatelessWidget { var statsCubit = BlocProvider.of(context); return Scaffold( appBar: buildAppBar(statsCubit), - drawer: NavDrawer(activeTab: NavdrawerTab.SleepSequenceStats), body: BlocConsumer( listener: (context, state) { print(state.runtimeType); From f558366738c953124ec4ec351f80b858991736b5 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Tue, 10 Nov 2020 11:16:55 -0500 Subject: [PATCH 6/8] Removed unused import --- .../sleep_sequence_stats_page/sleep_sequence_stats_page.dart | 1 - 1 file changed, 1 deletion(-) 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 index 8a399608..c3f8190a 100644 --- 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 @@ -2,7 +2,6 @@ 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/navigation/navdrawer_tabs.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'; From 4cde72bb5d15573b48567377466bc4298b3913f1 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Tue, 10 Nov 2020 11:42:58 -0500 Subject: [PATCH 7/8] Removed _selectMode variable --- .../sleep_sequence_history/sleep_sequence_history_cubit.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 index 8241192d..aa637597 100644 --- 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 @@ -12,7 +12,6 @@ class SleepSequenceHistoryCubit extends Cubit { StreamController.broadcast(); List _selectedSequences; - bool _selectMode = false; SleepSequenceHistoryCubit(this._sleepHistoryRepository) : super(SleepSequenceHistoryInitial()) { @@ -29,7 +28,7 @@ class SleepSequenceHistoryCubit extends Cubit { } void toggleSelectMode() { - if (_selectMode) { + if (state is SleepSequenceHistoryEditInProgress) { _disableSelection(); } else { _enableSelection(); @@ -37,7 +36,6 @@ class SleepSequenceHistoryCubit extends Cubit { } void _enableSelection() { - _selectMode = true; _selectedSequences = []; _selectText.add('Done'); emit(SleepSequenceHistoryEditInProgress( @@ -45,7 +43,6 @@ class SleepSequenceHistoryCubit extends Cubit { } void _disableSelection() { - _selectMode = false; _selectedSequences = null; _selectText.add('Select'); emit(SleepSequenceHistoryLoaded( From d5f1ccbc0ec67020e4ae41542af688b826f1a854 Mon Sep 17 00:00:00 2001 From: MouradLachhab Date: Tue, 10 Nov 2020 20:44:09 -0500 Subject: [PATCH 8/8] Avoiding sleep sequence repository for loading passing directly through cubits --- .../sleep_sequence_history_cubit.dart | 9 +++++--- .../sleep_sequence_stats_cubit.dart | 21 ++++++------------- .../i_sleep_sequence_repository.dart | 3 --- .../sleep_history_repository.dart | 9 -------- mobile/lib/src/locator.dart | 8 +++---- .../sleep_history_list.dart | 2 +- .../sleep_sequence_stats_page/app_bar.dart | 21 +++++++------------ .../sleep_sequence_stats_page.dart | 2 -- 8 files changed, 25 insertions(+), 50 deletions(-) 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 index aa637597..e31c5ad8 100644 --- 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 @@ -2,18 +2,21 @@ 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) + SleepSequenceHistoryCubit( + this._sleepHistoryRepository, this._sleepSequenceStatsCubit) : super(SleepSequenceHistoryInitial()) { loadHistory(); } @@ -23,8 +26,8 @@ class SleepSequenceHistoryCubit extends Cubit { _sleepHistoryRepository.getSleepSequences())); } - void selectSleepSequenceForViewing(SleepSequenceStats sequence) { - _sleepHistoryRepository.selectSleepSequence(sequence); + void loadSleepSequence(SleepSequenceStats sequence) { + _sleepSequenceStatsCubit.loadSleepSequence(sequence); } void toggleSelectMode() { 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 index 040a92b8..d4068fff 100644 --- 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 @@ -1,24 +1,15 @@ -import 'dart:async'; - import 'package:bloc/bloc.dart'; import 'package:flutter_bloc/flutter_bloc.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_stats_state.dart'; class SleepSequenceStatsCubit extends Cubit { - final ISleepSequenceRepository _sleepHistoryRepository; - final StreamController _titleText = - StreamController.broadcast(); + String titleText = ''; - SleepSequenceStatsCubit(this._sleepHistoryRepository) - : super(SleepSequenceStatsInitial()) { - _sleepHistoryRepository.getSelectedSleepSequence().listen( - (sleepSequence) => {emit(SleepSequenceStatsLoaded(sleepSequence))}); - } + SleepSequenceStatsCubit() : super(SleepSequenceStatsInitial()); - void updateTitle(String id) { - _titleText.add(id); + void loadSleepSequence(SleepSequenceStats sequence) { + titleText = sequence.stringId; + emit(SleepSequenceStatsLoaded(sequence)); } - - Stream get titleStream => _titleText.stream; } 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 index 41b91bcd..53001468 100644 --- a/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart +++ b/mobile/lib/src/domain/sleep_sequence/i_sleep_sequence_repository.dart @@ -1,10 +1,7 @@ import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; abstract class ISleepSequenceRepository { - void selectSleepSequence(SleepSequenceStats sequence); - List getSleepSequences(); - Stream getSelectedSleepSequence(); void deleteSleepSequences(List sequence); } 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 9347f610..4ead4c9e 100644 --- a/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart +++ b/mobile/lib/src/infrastructure/sleep_history/sleep_history_repository.dart @@ -14,18 +14,9 @@ class SleepHistoryRepository implements ISleepSequenceRepository { _sleepHistoryPersistency.add(mock_data_2); } - @override - void selectSleepSequence(SleepSequenceStats sequence) { - sequenceStreamController.add(sequence); - } - @override List getSleepSequences() => _sleepHistoryPersistency; - @override - Stream getSelectedSleepSequence() => - sequenceStreamController.stream; - @override void deleteSleepSequences(List sequences) { for (var sequence in sequences) { diff --git a/mobile/lib/src/locator.dart b/mobile/lib/src/locator.dart index dd1311ef..7a0f1be4 100644 --- a/mobile/lib/src/locator.dart +++ b/mobile/lib/src/locator.dart @@ -35,10 +35,10 @@ List createBlocProviders() => [ _serviceLocator.get(), ), ), + BlocProvider( + create: (context) => SleepSequenceStatsCubit()), BlocProvider( create: (context) => SleepSequenceHistoryCubit( - _serviceLocator.get())), - BlocProvider( - create: (context) => SleepSequenceStatsCubit( - _serviceLocator.get())), + _serviceLocator.get(), + BlocProvider.of(context))), ]; 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 index 99935bdd..965a9e1f 100644 --- 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 @@ -22,7 +22,7 @@ Widget _buildItemCard(var context, var state, var historyCubit, var index) { } else { - historyCubit.selectSleepSequenceForViewing(state.history[index]), + historyCubit.loadSleepSequence(state.history[index]), ExtendedNavigator.of(context).push(Routes.sleepSequenceStatsPage) } }, 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 index 7eb9d332..b699dc45 100644 --- 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 @@ -8,19 +8,14 @@ Widget buildAppBar(var statsCubit) { shadowColor: Colors.transparent, centerTitle: true, iconTheme: IconThemeData(color: Colors.black), - title: StreamBuilder( - stream: statsCubit.titleStream, - initialData: 'Sleep Sequence Stat', - builder: (context, snapshot) { - return Text( - snapshot.data, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.indigo, - ), - ); - }), + 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), 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 index c3f8190a..77dab75b 100644 --- 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 @@ -30,8 +30,6 @@ Widget _buildStatsBody(var context, var state, var statsCubit) { return Container(); } - statsCubit.updateTitle(state.stats.stringId); - return SingleChildScrollView( child: Column( children: [