114 lines
2.8 KiB
Dart
114 lines
2.8 KiB
Dart
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/providers/core.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
import 'package:didvan/services/storage/storage.dart';
|
|
|
|
class GeneralSettingsState extends CoreProvier {
|
|
GeneralSettingsState() {
|
|
getSettingsFromStorage();
|
|
}
|
|
|
|
List<int> _notificationTimeRange = [0, 24];
|
|
String _fontFamily = 'Dana-FA';
|
|
double _fontSizeScale = 1;
|
|
String _brightness = 'light';
|
|
String time = "";
|
|
|
|
Future<void> getTime() async {
|
|
appState = AppState.busy;
|
|
|
|
final service = RequestService(
|
|
RequestHelper.notificationTime(),
|
|
);
|
|
await service.httpGet();
|
|
if (service.isSuccess) {
|
|
time = service.data('time');
|
|
|
|
appState = AppState.idle;
|
|
} else {
|
|
appState = AppState.failed;
|
|
}
|
|
|
|
update();
|
|
}
|
|
|
|
|
|
set notificationTimeRange(List<int> value) {
|
|
_notificationTimeRange = value;
|
|
StorageService.setValue(
|
|
key: 'notificationTimeRangeStart',
|
|
value: value[0],
|
|
);
|
|
StorageService.setValue(
|
|
key: 'notificationTimeRangeEnd',
|
|
value: value[1],
|
|
);
|
|
notifyListeners();
|
|
_setSilenceInterval();
|
|
}
|
|
|
|
List<int> get notificationTimeRange => _notificationTimeRange;
|
|
|
|
set fontFamily(String value) {
|
|
_fontFamily = value;
|
|
StorageService.setValue(
|
|
key: 'fontFamily',
|
|
value: value,
|
|
);
|
|
notifyListeners();
|
|
}
|
|
|
|
String get fontFamily => _fontFamily;
|
|
|
|
set fontSizeScale(double value) {
|
|
_fontSizeScale = value;
|
|
StorageService.setValue(
|
|
key: 'fontSizeScale',
|
|
value: value,
|
|
);
|
|
notifyListeners();
|
|
}
|
|
|
|
double get fontSizeScale => _fontSizeScale;
|
|
|
|
set brightness(String value) {
|
|
_brightness = value;
|
|
StorageService.setValue(
|
|
key: 'brightness',
|
|
value: value,
|
|
);
|
|
notifyListeners();
|
|
}
|
|
|
|
String get brightness => _brightness;
|
|
|
|
Future<void> _setSilenceInterval() async {
|
|
final service = RequestService(RequestHelper.silenceInterval, body: {
|
|
'start': notificationTimeRange[0],
|
|
'end': notificationTimeRange[1]
|
|
});
|
|
await service.put();
|
|
}
|
|
|
|
Future<void> getSettingsFromStorage() async {
|
|
appState = AppState.busy;
|
|
try {
|
|
_notificationTimeRange[0] = int.parse(
|
|
await StorageService.getValue(key: 'notificationTimeRangeStart'),
|
|
);
|
|
_notificationTimeRange[1] = int.parse(
|
|
await StorageService.getValue(key: 'notificationTimeRangeEnd'),
|
|
);
|
|
} catch (e) {
|
|
notificationTimeRange = [0, 0];
|
|
}
|
|
|
|
_fontFamily = await StorageService.getValue(key: 'fontFamily');
|
|
_brightness = await StorageService.getValue(key: 'brightness');
|
|
final scale = await StorageService.getValue(key: 'fontSizeScale');
|
|
_fontSizeScale = double.parse(scale);
|
|
appState = AppState.idle;
|
|
}
|
|
}
|