1
+ #include "flipp_pomodoro_app_i.h"
2
+
3
+ enum {
4
+ CustomEventConsumed = true,
5
+ CustomEventNotConsumed = false,
6
+ };
7
+
8
+ static bool flipp_pomodoro_app_back_event_callback (void * ctx ) {
9
+ furi_assert (ctx );
10
+ FlippPomodoroApp * app = ctx ;
11
+ return scene_manager_handle_back_event (app -> scene_manager );
12
+ };
13
+
14
+ static void flipp_pomodoro_app_tick_event_callback (void * ctx ) {
15
+ furi_assert (ctx );
16
+ FlippPomodoroApp * app = ctx ;
17
+
18
+ scene_manager_handle_custom_event (app -> scene_manager , FlippPomodoroAppCustomEventTimerTick );
19
+ };
20
+
21
+ static bool flipp_pomodoro_app_custom_event_callback (void * ctx , uint32_t event ) {
22
+ furi_assert (ctx );
23
+ FlippPomodoroApp * app = ctx ;
24
+
25
+ switch (event ) {
26
+ case FlippPomodoroAppCustomEventStageSkip :
27
+ flipp_pomodoro__toggle_stage (app -> state );
28
+ view_dispatcher_send_custom_event (
29
+ app -> view_dispatcher , FlippPomodoroAppCustomEventStateUpdated );
30
+ return CustomEventConsumed ;
31
+ case FlippPomodoroAppCustomEventStageComplete :
32
+ if (flipp_pomodoro__get_stage (app -> state ) == FlippPomodoroStageFocus ) {
33
+ // REGISTER a deed on work stage complete to get an acheivement
34
+ dolphin_deed (DolphinDeedPluginGameWin );
35
+ };
36
+
37
+ flipp_pomodoro__toggle_stage (app -> state );
38
+ notification_message (
39
+ app -> notification_app ,
40
+ stage_start_notification_sequence_map [flipp_pomodoro__get_stage (app -> state )]);
41
+ view_dispatcher_send_custom_event (
42
+ app -> view_dispatcher , FlippPomodoroAppCustomEventStateUpdated );
43
+ return CustomEventConsumed ;
44
+ default :
45
+ break ;
46
+ }
47
+ return scene_manager_handle_custom_event (app -> scene_manager , event );
48
+ };
49
+
50
+ FlippPomodoroApp * flipp_pomodoro_app_alloc () {
51
+ FlippPomodoroApp * app = malloc (sizeof (FlippPomodoroApp ));
52
+ app -> state = flipp_pomodoro__new ();
53
+
54
+ app -> scene_manager = scene_manager_alloc (& flipp_pomodoro_scene_handlers , app );
55
+ app -> gui = furi_record_open (RECORD_GUI );
56
+ app -> notification_app = furi_record_open (RECORD_NOTIFICATION );
57
+
58
+ app -> view_dispatcher = view_dispatcher_alloc ();
59
+ view_dispatcher_enable_queue (app -> view_dispatcher );
60
+ view_dispatcher_set_event_callback_context (app -> view_dispatcher , app );
61
+ view_dispatcher_set_custom_event_callback (
62
+ app -> view_dispatcher , flipp_pomodoro_app_custom_event_callback );
63
+ view_dispatcher_set_tick_event_callback (
64
+ app -> view_dispatcher , flipp_pomodoro_app_tick_event_callback , 1000 );
65
+ view_dispatcher_attach_to_gui (app -> view_dispatcher , app -> gui , ViewDispatcherTypeFullscreen );
66
+ view_dispatcher_set_navigation_event_callback (
67
+ app -> view_dispatcher , flipp_pomodoro_app_back_event_callback );
68
+
69
+ app -> timer_view = flipp_pomodoro_view_timer_alloc ();
70
+
71
+ view_dispatcher_add_view (
72
+ app -> view_dispatcher ,
73
+ FlippPomodoroAppViewTimer ,
74
+ flipp_pomodoro_view_timer_get_view (app -> timer_view ));
75
+
76
+ scene_manager_next_scene (app -> scene_manager , FlippPomodoroSceneTimer );
77
+
78
+ return app ;
79
+ };
80
+
81
+ void flipp_pomodoro_app_free (FlippPomodoroApp * app ) {
82
+ view_dispatcher_remove_view (app -> view_dispatcher , FlippPomodoroAppViewTimer );
83
+ view_dispatcher_free (app -> view_dispatcher );
84
+ scene_manager_free (app -> scene_manager );
85
+ flipp_pomodoro_view_timer_free (app -> timer_view );
86
+ free (app );
87
+ furi_record_close (RECORD_GUI );
88
+ furi_record_close (RECORD_NOTIFICATION );
89
+ };
90
+
91
+ int32_t flipp_pomodoro_app (void * p ) {
92
+ UNUSED (p );
93
+ FlippPomodoroApp * app = flipp_pomodoro_app_alloc ();
94
+
95
+ view_dispatcher_run (app -> view_dispatcher );
96
+
97
+ flipp_pomodoro_app_free (app );
98
+
99
+ return 0 ;
100
+ };
0 commit comments