-
Notifications
You must be signed in to change notification settings - Fork 3
Implemented history page night selection for deletion #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3d3e6cd
94d6963
37389a7
88fad13
631044d
8736329
f558366
4cde72b
d5f1ccb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<SleepSequenceHistoryState> { | ||
| final ISleepSequenceRepository _sleepHistoryRepository; | ||
| final SleepSequenceStatsCubit _sleepSequenceStatsCubit; | ||
| final StreamController<String> _selectText = | ||
| StreamController<String>.broadcast(); | ||
|
|
||
| List<SleepSequenceStats> _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(); | ||
|
MouradLachhab marked this conversation as resolved.
|
||
| } | ||
|
|
||
| Stream<String> get selectStream => _selectText.stream; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<SleepSequenceStats> history; | ||
|
|
||
| SleepSequenceHistoryLoaded(this.history); | ||
| } | ||
|
|
||
| class SleepSequenceHistoryEditInProgress extends SleepSequenceHistoryState { | ||
| final List<SleepSequenceStats> history; | ||
| final List<SleepSequenceStats> selectedSequences; | ||
|
|
||
| SleepSequenceHistoryEditInProgress(this.history, this.selectedSequences); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<SleepSequenceStatsState> { | ||
| String titleText = ''; | ||
|
|
||
| SleepSequenceStatsCubit() : super(SleepSequenceStatsInitial()); | ||
|
|
||
| void loadSleepSequence(SleepSequenceStats sequence) { | ||
| titleText = sequence.stringId; | ||
| emit(SleepSequenceStatsLoaded(sequence)); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import 'package:polydodo/src/domain/sleep_sequence/sleep_sequence_stats.dart'; | ||
|
|
||
| abstract class ISleepSequenceRepository { | ||
| List<SleepSequenceStats> getSleepSequences(); | ||
|
|
||
| void deleteSleepSequences(List<SleepSequenceStats> sequence); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<NightStats> _sleepHistoryPersistency = []; | ||
| final streamController = StreamController<List<NightStats>>(); | ||
| final nightStreamController = StreamController<NightStats>(); | ||
| class SleepHistoryRepository implements ISleepSequenceRepository { | ||
| final List<SleepSequenceStats> _sleepHistoryPersistency = []; | ||
| final sequenceStreamController = StreamController<SleepSequenceStats>(); | ||
|
|
||
| SleepHistoryRepository(); | ||
|
|
||
| @override | ||
| void initializeRepository() { | ||
| SleepHistoryRepository() { | ||
| _sleepHistoryPersistency.add(mock_data_1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Si le Repository est mock je propose qu'on le renomme MockSleepHistoryRepository. Lorsqu'on voudra implémenter la vrai version, on aura juste à créer une nouvelle classe SleepHistoryRepository et l'injecter dans l'app à la place de MockSleepRepository. |
||
|
|
||
| _sleepHistoryPersistency.add(mock_data_2); | ||
|
|
||
| streamController.add(_sleepHistoryPersistency); | ||
| } | ||
|
|
||
| @override | ||
| void selectNight(NightStats stat) { | ||
| nightStreamController.add(stat); | ||
| } | ||
|
|
||
| @override | ||
| Stream<NightStats> getSelectedNight() => nightStreamController.stream; | ||
| List<SleepSequenceStats> getSleepSequences() => _sleepHistoryPersistency; | ||
|
|
||
| @override | ||
| Stream<List<NightStats>> watch() { | ||
| return streamController.stream; | ||
| void deleteSleepSequences(List<SleepSequenceStats> sequences) { | ||
| for (var sequence in sequences) { | ||
| _sleepHistoryPersistency.remove(sequence); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,5 +3,5 @@ enum NavdrawerTab { | |
| RecordSleep, | ||
| BluetoothSelector, | ||
| History, | ||
| NightStats | ||
| SleepSequenceStats | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
J'imagine que ce sera async. Il faudrait probablement utiliser Future ISleepHistoryRepository::getSleepSequences(); J'imagine que les ajouts et suppression de la persistence retourneront aussi un Future.