Skip to content

Commit

Permalink
Added option to turn off dnd
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Nov 7, 2024
1 parent 916cb3f commit 913ef3f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 20 deletions.
4 changes: 3 additions & 1 deletion lib/domain/controllers/dnd_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ abstract class DndController {

void init();

Future<void> enableDnd();
Future<void> enable();

Future<bool> isDnd();

Future<void> disable();
}
16 changes: 15 additions & 1 deletion lib/infrastructure/dnd_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class _DndRepository extends DndController {
void init() => supported = Platform.isAndroid;

@override
Future<void> enableDnd() async {
Future<void> enable() async {
if (!supported) {
return;
}
Expand All @@ -21,6 +21,20 @@ class _DndRepository extends DndController {
}
}

@override
Future<void> disable() async {
if (!supported) {
return;
}

if (await PermissionsController.instance
.isNotificationPolicyAccessGranted()) {
await FlutterDnd.setInterruptionFilter(
FlutterDnd.INTERRUPTION_FILTER_ALL,
);
}
}

@override
Future<bool> isDnd() async {
if (!supported) {
Expand Down
7 changes: 5 additions & 2 deletions lib/presentation/organisms/ready_for_session_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import 'package:infinite_horizons/domain/objects/work_type_abstract.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';

class ReadyForSessionOrganism extends StatefulWidget {
const ReadyForSessionOrganism(
this.onComplete, {
const ReadyForSessionOrganism({
required this.onComplete,
this.onNextPressed,
this.response,
});

final VoidCallback onComplete;
final String? response;
final VoidCallback? onNextPressed;

@override
State<ReadyForSessionOrganism> createState() =>
Expand All @@ -24,6 +26,7 @@ class _ReadyForSessionOrganismState extends State<ReadyForSessionOrganism> {
bool confettiGotPlayed = false;

void onPressed() {
widget.onNextPressed?.call();
setState(() {
nextPressed = true;
});
Expand Down
14 changes: 9 additions & 5 deletions lib/presentation/organisms/timer_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ class TimerOrganismState extends State<TimerOrganism> {
TimerState state = TimerStateManager.state;
bool renderSizedBox = false;

void onComplete() {
TimerStateManager.incrementState();
TimerStateManager.iterateOverTimerStates();
setCurrentState();
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -219,11 +225,9 @@ class TimerOrganismState extends State<TimerOrganism> {
initialValue: timePassed,
);
case TimerState.readyToStart:
return ReadyForSessionOrganism(() {
TimerStateManager.incrementState();
TimerStateManager.iterateOverTimerStates();
setCurrentState();
});
return ReadyForSessionOrganism(
onComplete: onComplete,
);
}
}

Expand Down
9 changes: 6 additions & 3 deletions lib/presentation/organisms/tips_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@ class _TipsOrganismState extends State<TipsOrganism> {
Icons.do_not_disturb_off_outlined,
onIcon: Icons.do_not_disturb_on_outlined,
onChange: (value) {
confettiController.play();
DndController.instance.enableDnd();
if (value) {
confettiController.play();
DndController.instance.enable();
return;
}
DndController.instance.disable();
},
initialValue: isDnd!,
trailing: IconButton(
Expand All @@ -134,7 +138,6 @@ class _TipsOrganismState extends State<TipsOrganism> {
),
icon: const Icon(Icons.arrow_forward),
),
lockOnToggleOn: true,
),
],
),
Expand Down
25 changes: 21 additions & 4 deletions lib/presentation/pages/intro_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ class _IntroPageState extends State<IntroPage> {
final GlobalKey<IntroductionScreenState> _introKey =
GlobalKey<IntroductionScreenState>();

bool showBackButton = true;
bool showNextButton = true;
bool isFinish = false;
IntroState state = IntroState.tips;
final Duration selectionTransitionDelay = const Duration(milliseconds: 200);

void onNextPressed() {
isFinish = true;
setState(() {
showBackButton = false;
});
}

void onIntroPageChange(int n) {
state = IntroState.getStateByPageNumber(n);
bool showNextButtonTemp = true;
Expand All @@ -42,10 +51,15 @@ class _IntroPageState extends State<IntroPage> {

void nextPage() => _introKey.currentState?.next();

void onDone(BuildContext context) => Navigator.of(context)
void onDone() => Navigator.of(context)
.push(MaterialPageRoute(builder: (context) => ActivityPage()));

void previousPage() => _introKey.currentState?.previous();
void previousPage() {
if (isFinish) {
return;
}
_introKey.currentState?.previous();
}

void onHorizontalDrag(DragEndDetails details) {
if (details.primaryVelocity == 0) {
Expand Down Expand Up @@ -120,10 +134,13 @@ class _IntroPageState extends State<IntroPage> {
}),
),
customPageViewModel(
bodyWidget: ReadyForSessionPage(() => onDone(context)),
bodyWidget: ReadyForSessionPage(
onDone: onDone,
onNextPressed: onNextPressed,
),
),
],
showBackButton: true,
showBackButton: showBackButton,
back: const Icon(Icons.arrow_back),
next: const Icon(Icons.arrow_forward),
scrollPhysics: const NeverScrollableScrollPhysics(),
Expand Down
13 changes: 9 additions & 4 deletions lib/presentation/pages/ready_for_session_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ import 'package:infinite_horizons/presentation/molecules/molecules.dart';
import 'package:infinite_horizons/presentation/organisms/organisms.dart';

class ReadyForSessionPage extends StatelessWidget {
const ReadyForSessionPage(this.callback);
const ReadyForSessionPage({
required this.onDone,
required this.onNextPressed,
});

final VoidCallback callback;
final VoidCallback onNextPressed;
final VoidCallback onDone;

void handleCallback() {
VibrationController.instance.vibrate(VibrationType.light);
callback();
onDone();
}

@override
Expand Down Expand Up @@ -41,7 +45,8 @@ class ReadyForSessionPage extends StatelessWidget {
scaffold: false,
title: 'start_session',
child: ReadyForSessionOrganism(
handleCallback,
onComplete: handleCallback,
onNextPressed: onNextPressed,
response: text,
),
);
Expand Down

0 comments on commit 913ef3f

Please sign in to comment.