Skip to content
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

feat: Implement User Settings Persistence (#91) #92

Merged
merged 9 commits into from
May 30, 2024
5 changes: 5 additions & 0 deletions lib/domain/preferences_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ abstract class PreferencesController {

String? getString(String key);

bool? getBool(String key);

void remove(String key);

void setString(String key, String value);

void setBool(String key, bool value);

}

// class PreferencesController extends PreferencesController {
Expand Down
6 changes: 6 additions & 0 deletions lib/infrastructure/preferences_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ class _PreferencesRepository extends PreferencesController {
@override
String? getString(String key) => preferences.getString(key);

@override
bool? getBool(String key) => preferences.getBool(key);

@override
void remove(String key) => preferences.remove(key);

@override
void setString(String key, String value) => preferences.setString(key, value);

@override
void setBool(String key, bool value) => preferences.setBool(key, value);
}
13 changes: 11 additions & 2 deletions lib/presentation/organisms/timer_organism.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:infinite_horizons/domain/player_controller.dart';
import 'package:infinite_horizons/domain/preferences_controller.dart';
import 'package:infinite_horizons/domain/study_type_abstract.dart';
import 'package:infinite_horizons/domain/vibration_controller.dart';
import 'package:infinite_horizons/domain/wake_lock_controller.dart';
Expand All @@ -15,6 +16,7 @@ class TimerOrganism extends StatefulWidget {
class _TimerOrganismState extends State<TimerOrganism>
with AutomaticKeepAliveClientMixin<TimerOrganism> {
HomeState state = HomeState.getReadyForStudy;
final PreferencesController _prefs = PreferencesController.instance;
vijaykarthiktk marked this conversation as resolved.
Show resolved Hide resolved

@override
bool get wantKeepAlive => true;
Expand All @@ -24,6 +26,10 @@ class _TimerOrganismState extends State<TimerOrganism>
@override
void initState() {
super.initState();
lockScreen = _prefs.getBool("isSilent") ?? lockScreen;
guyluz11 marked this conversation as resolved.
Show resolved Hide resolved
WakeLockController.instance.setWakeLock(lockScreen);
PlayerController.instance.setSilentState(!(_prefs.getBool("setSilentState") ?? true));
guyluz11 marked this conversation as resolved.
Show resolved Hide resolved

if (lockScreen) {
WakeLockController.instance.setWakeLock(true);
}
Expand Down Expand Up @@ -119,8 +125,10 @@ class _TimerOrganismState extends State<TimerOrganism>
text: 'sound',
offIcon: Icons.music_off_rounded,
onIcon: Icons.music_note_rounded,
onChange: (bool value) =>
PlayerController.instance.setSilentState(!value),
onChange: (bool value) {
PlayerController.instance.setSilentState(!value);
_prefs.setBool("setSilentState", value);
},
initialValue: !PlayerController.instance.isSilent(),
),
const SeparatorAtom(),
Expand All @@ -130,6 +138,7 @@ class _TimerOrganismState extends State<TimerOrganism>
onIcon: Icons.lock_open,
onChange: (bool value) {
lockScreen = value;
_prefs.setBool("isSilent", lockScreen);
WakeLockController.instance.setWakeLock(lockScreen);
},
initialValue: lockScreen,
Expand Down
Loading