-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpomodoro.c
183 lines (156 loc) · 6.09 KB
/
pomodoro.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "pomodoro.h"
#include <notification/notification_messages.h>
#define TAG "PomodoroApp"
enum PomodoroDebugSubmenuIndex {
PomodoroSubmenuIndex10,
PomodoroSubmenuIndex25,
PomodoroSubmenuIndex50,
PomodoroSubmenuIndex52,
};
void pomodoro_submenu_callback(void* context, uint32_t index) {
furi_assert(context);
Pomodoro* app = context;
if(index == PomodoroSubmenuIndex10) {
app->view_id = PomodoroView10;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView10);
}
if(index == PomodoroSubmenuIndex25) {
app->view_id = PomodoroView25;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView25);
}
if(index == PomodoroSubmenuIndex50) {
app->view_id = PomodoroView50;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView50);
}
if(index == PomodoroSubmenuIndex52) {
app->view_id = PomodoroView52;
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroView52);
}
}
void pomodoro_dialog_callback(DialogExResult result, void* context) {
furi_assert(context);
Pomodoro* app = context;
if(result == DialogExResultLeft) {
view_dispatcher_stop(app->view_dispatcher);
} else if(result == DialogExResultRight) {
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id); // Show last view
} else if(result == DialogExResultCenter) {
view_dispatcher_switch_to_view(app->view_dispatcher, PomodoroViewSubmenu);
}
}
uint32_t pomodoro_exit_confirm_view(void* context) {
UNUSED(context);
return PomodoroViewExitConfirm;
}
uint32_t pomodoro_exit(void* context) {
UNUSED(context);
return VIEW_NONE;
}
Pomodoro* pomodoro_app_alloc() {
Pomodoro* app = malloc(sizeof(Pomodoro));
// Gui
app->gui = furi_record_open(RECORD_GUI);
// Notifications
app->notifications = furi_record_open(RECORD_NOTIFICATION);
// View dispatcher
app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_enable_queue(app->view_dispatcher);
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
// Submenu view
app->submenu = submenu_alloc();
submenu_add_item(
app->submenu,
"Classic: 25 work 5 rest",
PomodoroSubmenuIndex25,
pomodoro_submenu_callback,
app);
submenu_add_item(
app->submenu,
"Long: 50 work 10 rest",
PomodoroSubmenuIndex50,
pomodoro_submenu_callback,
app);
submenu_add_item(
app->submenu,
"Sprint: 10 work 2 rest",
PomodoroSubmenuIndex10,
pomodoro_submenu_callback,
app);
submenu_add_item(
app->submenu,
"5217: 52 work 17 rest",
PomodoroSubmenuIndex52,
pomodoro_submenu_callback,
app);
view_set_previous_callback(submenu_get_view(app->submenu), pomodoro_exit);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroViewSubmenu, submenu_get_view(app->submenu));
// Dialog view
app->dialog = dialog_ex_alloc();
dialog_ex_set_result_callback(app->dialog, pomodoro_dialog_callback);
dialog_ex_set_context(app->dialog, app);
dialog_ex_set_left_button_text(app->dialog, "Exit");
dialog_ex_set_right_button_text(app->dialog, "Stay");
dialog_ex_set_center_button_text(app->dialog, "Menu");
dialog_ex_set_header(app->dialog, "Close Current App?", 16, 12, AlignLeft, AlignTop);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroViewExitConfirm, dialog_ex_get_view(app->dialog));
// 25 minutes view
app->pomodoro_25 = pomodoro_25_alloc();
view_set_previous_callback(pomodoro_25_get_view(app->pomodoro_25), pomodoro_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView25, pomodoro_25_get_view(app->pomodoro_25));
// 50 minutes view
app->pomodoro_50 = pomodoro_50_alloc();
view_set_previous_callback(pomodoro_50_get_view(app->pomodoro_50), pomodoro_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView50, pomodoro_50_get_view(app->pomodoro_50));
// 10 minutes view
app->pomodoro_10 = pomodoro_10_alloc();
view_set_previous_callback(pomodoro_10_get_view(app->pomodoro_10), pomodoro_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView10, pomodoro_10_get_view(app->pomodoro_10));
// 52 minutes view
app->pomodoro_52 = pomodoro_52_alloc();
view_set_previous_callback(pomodoro_52_get_view(app->pomodoro_52), pomodoro_exit_confirm_view);
view_dispatcher_add_view(
app->view_dispatcher, PomodoroView52, pomodoro_52_get_view(app->pomodoro_52));
// TODO switch to menu after Media is done
app->view_id = PomodoroViewSubmenu;
view_dispatcher_switch_to_view(app->view_dispatcher, app->view_id);
return app;
}
void pomodoro_app_free(Pomodoro* app) {
furi_assert(app);
// Reset notification
notification_internal_message(app->notifications, &sequence_reset_blue);
// Free views
view_dispatcher_remove_view(app->view_dispatcher, PomodoroViewSubmenu);
submenu_free(app->submenu);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroViewExitConfirm);
dialog_ex_free(app->dialog);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView25);
pomodoro_25_free(app->pomodoro_25);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView50);
pomodoro_50_free(app->pomodoro_50);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView10);
pomodoro_10_free(app->pomodoro_10);
view_dispatcher_remove_view(app->view_dispatcher, PomodoroView52);
pomodoro_52_free(app->pomodoro_52);
view_dispatcher_free(app->view_dispatcher);
// Close records
furi_record_close(RECORD_GUI);
app->gui = NULL;
furi_record_close(RECORD_NOTIFICATION);
app->notifications = NULL;
// Free rest
free(app);
}
int32_t pomodoro_app(void* p) {
UNUSED(p);
// Switch profile to Hid
Pomodoro* app = pomodoro_app_alloc();
view_dispatcher_run(app->view_dispatcher);
pomodoro_app_free(app);
return 0;
}