-
Notifications
You must be signed in to change notification settings - Fork 3
Settings panel #73
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
Merged
Merged
Settings panel #73
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7742b98
New sliverbar asset & app icon
89994fd
Removed old file
71ad1ef
Added loading indicator helper
898efab
Added settings route, page, bloc
06fb34b
Handle empty settings & Acquisition board
cc47c91
Fixes to import structure
76a9ae9
Fixes to import structure part 2
d2e926b
Merge remote-tracking branch 'origin/master' into mobile/app-user-set…
62a0670
Minor changes to settings text
d8a45ad
Removed unnecessary imports after adding part of ''
b953667
Update mobile/lib/src/application/settings/settings_cubit.dart
mateobelanger c230e63
Update mobile/lib/src/application/settings/settings_cubit.dart
mateobelanger b652929
Update mobile/lib/src/application/settings/settings_cubit.dart
mateobelanger 2eb2058
Update mobile/lib/src/application/settings/settings_cubit.dart
mateobelanger ee6c3b8
Added Sharedpreference property to cubit
85c9a7c
Merge remote-tracking branch 'origin/mobile/app-user-settings' into m…
40186af
Added genericity to Settings backbone
97094ca
Nit fix for formating
15ed171
Settings in Map<String, dynamic> and added Infrastructure layer
94437cc
Generic is the new fun
b24beef
Removed obsolete Acquisition board setting
a5bd02b
Added server url setting option
771d012
Merge remote-tracking branch 'origin/master' into mobile/app-user-set…
abf70be
Infrastructure getter gets only 1 setting at a time
35739d9
Renamed interface methods
8b200c7
more genericity
24c461d
Added URL server setting field, added infrastructure layer
2e75bb6
Renamed infrastructure getters & setters
3f665f9
Fixed rebase conflicts
d5c554a
Merge master into mobile/app-user-settings
6184dea
Added validation on Settings model
c3bd6d7
Library for infrastructure storage keys, Settings tile functions generic
2657711
added constants for max & min Age
e3e6cb8
Factory settings constructor with exceptions
ea3df86
Added validation on server address
45c94b1
Added validation and constants to age setting
445000e
Fixes
75bd04e
nit fix for launch config
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import 'package:bloc/bloc.dart'; | ||
| import 'package:equatable/equatable.dart'; | ||
| import 'package:polydodo/src/domain/settings/i_settings_repository.dart'; | ||
| import 'package:polydodo/src/domain/settings/settings.dart'; | ||
|
|
||
| part 'settings_state.dart'; | ||
|
|
||
| class SettingsCubit extends Cubit<SettingsState> { | ||
| final ISettingsRepository _repository; | ||
|
|
||
| SettingsCubit(this._repository) : super(SettingsLoadInProgress()) { | ||
| getSettings(); | ||
| } | ||
|
|
||
| Future<void> getSettings() async { | ||
| await emit(SettingsLoadSuccess(await _repository.read())); | ||
| } | ||
|
|
||
| Future<void> setAge(int newAge) async { | ||
| if (state is SettingsLoadSuccess) { | ||
| emit( | ||
| SettingsLoadSuccess( | ||
| await _repository.store( | ||
| (state as SettingsLoadSuccess).settings.copyWith(age: newAge), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Future<void> setSex(Sex newSex) async { | ||
| if (state is SettingsLoadSuccess) { | ||
| emit( | ||
| SettingsLoadSuccess( | ||
| await _repository.store( | ||
| (state as SettingsLoadSuccess).settings.copyWith(sex: newSex), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| Future<void> setServerAddress(String newServerAddress) async { | ||
| if (state is SettingsLoadSuccess) { | ||
| emit( | ||
| SettingsLoadSuccess( | ||
| await _repository.store( | ||
| (state as SettingsLoadSuccess) | ||
| .settings | ||
| .copyWith(serverAddress: newServerAddress), | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| part of 'settings_cubit.dart'; | ||
|
|
||
| abstract class SettingsState extends Equatable { | ||
| const SettingsState(); | ||
|
|
||
| @override | ||
| List<Object> get props => []; | ||
| } | ||
|
|
||
| class SettingsLoadInProgress extends SettingsState {} | ||
|
|
||
| class SettingsLoadSuccess extends SettingsState { | ||
| final Settings settings; | ||
|
|
||
| const SettingsLoadSuccess(this.settings); | ||
|
|
||
| @override | ||
| List<Object> get props => [settings]; | ||
|
|
||
| @override | ||
| String toString() => 'SettingsLoadSuccess { settings: $settings }'; | ||
| } | ||
|
|
||
| class SettingsLoadFailure extends SettingsState {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| RegExp IP_ADDRESS_REGEX = RegExp( | ||
| r'^(?=\d+\.\d+\.\d+\.\d+$)(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.?){4}$', | ||
| ); | ||
|
|
||
| const DEFAULT_AGE = 30; | ||
| const DEFAULT_SERVER_ADDRESS = '192.168.1.1'; | ||
|
|
||
| const MIN_AGE = 12; | ||
| const MAX_AGE = 125; | ||
| final MIN_BIRTH_DATE = DateTime.now().subtract(Duration(days: 365 * MAX_AGE)); | ||
| final MAX_BIRTH_DATE = DateTime.now().subtract(Duration(days: 365 * MIN_AGE)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| library settings_keys; | ||
|
|
||
| const String AGE = 'age'; | ||
| const String SERVER_ADDRESS = 'aerverAdress'; | ||
| const String SEX = 'serverAdress'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import 'package:polydodo/src/domain/settings/settings.dart'; | ||
|
|
||
| abstract class ISettingsRepository { | ||
| Future<Settings> read(); | ||
|
|
||
| Future<Settings> store(Settings newSettings); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import 'package:equatable/equatable.dart'; | ||
| import 'package:polydodo/src/common/constants.dart'; | ||
|
|
||
| part 'sex.dart'; | ||
|
|
||
| class Settings extends Equatable { | ||
| final int age; | ||
| final String serverAddress; | ||
| final Sex sex; | ||
|
|
||
| factory Settings({int age, String serverAddress, Sex sex}) { | ||
| age = age ?? DEFAULT_AGE; | ||
| serverAddress = serverAddress ?? DEFAULT_SERVER_ADDRESS; | ||
| sex = sex ?? Sex.NotSet; | ||
| if (age < MIN_AGE || age > MAX_AGE) { | ||
| throw AgeNotInValidIntervalException( | ||
| "L'âge configuré doit être entre 12 et 125 ans."); | ||
| } | ||
|
|
||
| if (!IP_ADDRESS_REGEX.hasMatch(serverAddress)) { | ||
| throw InvalidIPAddressException( | ||
| "L'adresse du serveur configurée doit être une adresse de format IPv4."); | ||
| } | ||
|
|
||
| return Settings._internal(age, serverAddress, sex); | ||
| } | ||
|
|
||
| Settings._internal(this.age, this.serverAddress, this.sex); | ||
|
|
||
| @override | ||
| List<Object> get props => [age, serverAddress, sex]; | ||
|
|
||
| Settings copyWith({int age, String serverAddress, Sex sex}) { | ||
| return Settings( | ||
| age: age ?? this.age, | ||
| serverAddress: serverAddress ?? this.serverAddress, | ||
| sex: sex ?? this.sex, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| class InvalidIPAddressException implements Exception { | ||
| String cause; | ||
| InvalidIPAddressException(this.cause); | ||
| } | ||
|
|
||
| class AgeNotInValidIntervalException implements Exception { | ||
| String cause; | ||
| AgeNotInValidIntervalException(this.cause); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| part of 'settings.dart'; | ||
|
|
||
| enum Sex { NotSet, Male, Female } |
31 changes: 31 additions & 0 deletions
31
mobile/lib/src/infrastructure/settings_repository/settings_repository.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import 'package:polydodo/src/common/settings_keys.dart' as settings_keys; | ||
| import 'package:polydodo/src/domain/settings/i_settings_repository.dart'; | ||
| import 'package:polydodo/src/domain/settings/settings.dart'; | ||
| import 'package:shared_preferences/shared_preferences.dart'; | ||
|
|
||
| class SettingsRepository extends ISettingsRepository { | ||
| SharedPreferences _prefs; | ||
|
|
||
| SettingsRepository(); | ||
|
|
||
| @override | ||
| Future<Settings> read() async { | ||
| _prefs = (await SharedPreferences.getInstance()); | ||
|
|
||
| return Settings( | ||
| age: _prefs.getInt(settings_keys.AGE), | ||
| serverAddress: _prefs.getString(settings_keys.SERVER_ADDRESS), | ||
| sex: Sex.values[(_prefs.getInt(settings_keys.SEX)) ?? Sex.NotSet.index], | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
| Future<Settings> store(Settings newSettings) async { | ||
| await _prefs.setInt(settings_keys.AGE, newSettings.age); | ||
| await _prefs.setString( | ||
| settings_keys.SERVER_ADDRESS, newSettings.serverAddress); | ||
| await _prefs.setInt(settings_keys.SEX, newSettings.sex.index); | ||
|
|
||
| return newSettings; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| part of 'navdrawer_widget.dart'; | ||
|
|
||
| enum NavdrawerTab { | ||
| BluetoothSelector, | ||
| Dashboard, | ||
| History, | ||
| RecordSleep, | ||
| Settings, | ||
| DeviceSelector, | ||
| History, | ||
| SleepSequenceStats | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
mobile/lib/src/presentation/pages/dashboard/dashboard_page.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.