2024-06-13 18:10:10 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_settings_ui/flutter_settings_ui.dart';
|
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-10-02 09:18:06 -04:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2024-08-23 04:21:46 -04:00
|
|
|
import 'package:vaani/settings/app_settings_provider.dart';
|
2024-09-25 03:13:42 -04:00
|
|
|
import 'package:vaani/settings/view/simple_settings_page.dart';
|
2024-08-23 04:21:46 -04:00
|
|
|
import 'package:vaani/shared/extensions/time_of_day.dart';
|
2024-06-13 18:10:10 -04:00
|
|
|
|
|
|
|
|
class AutoSleepTimerSettingsPage extends HookConsumerWidget {
|
|
|
|
|
const AutoSleepTimerSettingsPage({
|
|
|
|
|
super.key,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
|
|
|
final appSettings = ref.watch(appSettingsProvider);
|
2024-10-02 09:18:06 -04:00
|
|
|
final sleepTimerSettings = appSettings.sleepTimerSettings;
|
2024-06-13 18:10:10 -04:00
|
|
|
|
2024-10-02 09:18:06 -04:00
|
|
|
var enabled = sleepTimerSettings.autoTurnOnTimer &&
|
|
|
|
|
!sleepTimerSettings.alwaysAutoTurnOnTimer;
|
|
|
|
|
final selectedValueColor = enabled
|
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
|
: Theme.of(context).disabledColor;
|
2024-09-25 03:13:42 -04:00
|
|
|
return SimpleSettingsPage(
|
|
|
|
|
title: const Text('Auto Sleep Timer Settings'),
|
|
|
|
|
sections: [
|
|
|
|
|
SettingsSection(
|
|
|
|
|
margin: const EdgeInsetsDirectional.symmetric(
|
|
|
|
|
horizontal: 16.0,
|
|
|
|
|
vertical: 8.0,
|
|
|
|
|
),
|
|
|
|
|
tiles: [
|
|
|
|
|
SettingsTile.switchTile(
|
|
|
|
|
// initialValue: sleepTimerSettings.autoTurnOnTimer,
|
|
|
|
|
title: const Text('Auto Turn On Timer'),
|
|
|
|
|
description: const Text(
|
|
|
|
|
'Automatically turn on the sleep timer based on the time of day',
|
|
|
|
|
),
|
|
|
|
|
leading: sleepTimerSettings.autoTurnOnTimer
|
2024-10-02 09:18:06 -04:00
|
|
|
? const Icon(Symbols.time_auto)
|
|
|
|
|
: const Icon(Symbols.timer_off),
|
2024-09-25 03:13:42 -04:00
|
|
|
onToggle: (value) {
|
|
|
|
|
ref.read(appSettingsProvider.notifier).update(
|
2024-10-02 09:18:06 -04:00
|
|
|
appSettings.copyWith.sleepTimerSettings(
|
2024-09-25 03:13:42 -04:00
|
|
|
autoTurnOnTimer: value,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
initialValue: sleepTimerSettings.autoTurnOnTimer,
|
2024-06-13 18:10:10 -04:00
|
|
|
),
|
2024-09-25 03:13:42 -04:00
|
|
|
// auto turn on time settings, enabled only when autoTurnOnTimer is enabled
|
|
|
|
|
SettingsTile.navigation(
|
2024-10-02 09:18:06 -04:00
|
|
|
enabled: enabled,
|
|
|
|
|
leading: const Icon(Symbols.timer_play),
|
|
|
|
|
title: const Text('From'),
|
2024-09-25 03:13:42 -04:00
|
|
|
description: const Text(
|
|
|
|
|
'Turn on the sleep timer at the specified time',
|
|
|
|
|
),
|
|
|
|
|
onPressed: (context) async {
|
|
|
|
|
// navigate to the time picker
|
|
|
|
|
final selected = await showTimePicker(
|
|
|
|
|
context: context,
|
|
|
|
|
initialTime: sleepTimerSettings.autoTurnOnTime.toTimeOfDay(),
|
|
|
|
|
);
|
|
|
|
|
if (selected != null) {
|
2024-09-17 23:19:05 -04:00
|
|
|
ref.read(appSettingsProvider.notifier).update(
|
2024-10-02 09:18:06 -04:00
|
|
|
appSettings.copyWith.sleepTimerSettings(
|
2024-09-25 03:13:42 -04:00
|
|
|
autoTurnOnTime: selected.toDuration(),
|
2024-06-13 18:10:10 -04:00
|
|
|
),
|
|
|
|
|
);
|
2024-09-25 03:13:42 -04:00
|
|
|
}
|
|
|
|
|
},
|
2024-10-02 09:18:06 -04:00
|
|
|
trailing: Text(
|
2024-09-25 03:13:42 -04:00
|
|
|
sleepTimerSettings.autoTurnOnTime.toTimeOfDay().format(context),
|
2024-10-02 09:18:06 -04:00
|
|
|
style: TextStyle(color: selectedValueColor),
|
2024-06-13 18:10:10 -04:00
|
|
|
),
|
2024-09-25 03:13:42 -04:00
|
|
|
),
|
|
|
|
|
SettingsTile.navigation(
|
2024-10-02 09:18:06 -04:00
|
|
|
enabled: enabled,
|
|
|
|
|
leading: const Icon(Symbols.timer_pause),
|
|
|
|
|
title: const Text('Until'),
|
2024-09-25 03:13:42 -04:00
|
|
|
description: const Text(
|
|
|
|
|
'Turn off the sleep timer at the specified time',
|
2024-06-13 18:10:10 -04:00
|
|
|
),
|
2024-09-25 03:13:42 -04:00
|
|
|
onPressed: (context) async {
|
|
|
|
|
// navigate to the time picker
|
|
|
|
|
final selected = await showTimePicker(
|
|
|
|
|
context: context,
|
|
|
|
|
initialTime: sleepTimerSettings.autoTurnOffTime.toTimeOfDay(),
|
|
|
|
|
);
|
|
|
|
|
if (selected != null) {
|
|
|
|
|
ref.read(appSettingsProvider.notifier).update(
|
2024-10-02 09:18:06 -04:00
|
|
|
appSettings.copyWith.sleepTimerSettings(
|
2024-09-25 03:13:42 -04:00
|
|
|
autoTurnOffTime: selected.toDuration(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-10-02 09:18:06 -04:00
|
|
|
trailing: Text(
|
2024-09-25 03:13:42 -04:00
|
|
|
sleepTimerSettings.autoTurnOffTime
|
|
|
|
|
.toTimeOfDay()
|
|
|
|
|
.format(context),
|
2024-10-02 09:18:06 -04:00
|
|
|
style: TextStyle(color: selectedValueColor),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// switch tile for always auto turn on timer no matter what
|
|
|
|
|
SettingsTile.switchTile(
|
|
|
|
|
leading: const Icon(Symbols.all_inclusive),
|
|
|
|
|
title: const Text('Always Auto Turn On Timer'),
|
|
|
|
|
description: const Text(
|
|
|
|
|
'Always turn on the sleep timer, no matter what',
|
2024-06-13 18:10:10 -04:00
|
|
|
),
|
2024-10-02 09:18:06 -04:00
|
|
|
onToggle: (value) {
|
|
|
|
|
ref.read(appSettingsProvider.notifier).update(
|
|
|
|
|
appSettings.copyWith.sleepTimerSettings(
|
|
|
|
|
alwaysAutoTurnOnTimer: value,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
enabled: sleepTimerSettings.autoTurnOnTimer,
|
|
|
|
|
initialValue: sleepTimerSettings.alwaysAutoTurnOnTimer,
|
2024-09-25 03:13:42 -04:00
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
],
|
2024-06-13 18:10:10 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|