-
Notifications
You must be signed in to change notification settings - Fork 0
/
insults_app.c
133 lines (91 loc) · 4.33 KB
/
insults_app.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
#include "insults_app.h"
InsultsApp* insults_app_alloc(void) {
InsultsApp* insults_app = (InsultsApp*)malloc(sizeof(InsultsApp));
insults_app->gui = furi_record_open(RECORD_GUI);
insults_app->scene_manager = scene_manager_alloc(&scene_handlers, insults_app);
insults_app->view_dispatcher = view_dispatcher_alloc();
view_dispatcher_set_event_callback_context(insults_app->view_dispatcher, insults_app);
view_dispatcher_set_navigation_event_callback(
insults_app->view_dispatcher, insults_navigation_event_callback);
view_dispatcher_set_custom_event_callback(
insults_app->view_dispatcher, insults_custom_event_callback);
insults_app->insults_files = insults_files_alloc();
insults_app->start_menu = submenu_alloc();
submenu_add_item(
insults_app->start_menu,
"New insult",
InsultsSceneStartIndexNew,
insults_scene_start_submenu_callback,
insults_app);
submenu_add_item(
insults_app->start_menu,
"View saved",
InsultsSceneStartIndexSaved,
insults_scene_start_submenu_callback,
insults_app);
submenu_add_item(
insults_app->start_menu,
"Clear saved",
InsultsSceneStartIndexClear,
insults_scene_start_submenu_callback,
insults_app);
view_dispatcher_add_view(
insults_app->view_dispatcher, InsultsViewStart, submenu_get_view(insults_app->start_menu));
insults_app->insult_display = dialog_ex_alloc();
dialog_ex_set_context(insults_app->insult_display, insults_app);
dialog_ex_set_result_callback(
insults_app->insult_display, insults_scene_insult_dialog_callback);
dialog_ex_set_left_button_text(insults_app->insult_display, "Regenerate");
dialog_ex_set_right_button_text(insults_app->insult_display, "Save");
view_dispatcher_add_view(
insults_app->view_dispatcher,
InsultsViewInsult,
dialog_ex_get_view(insults_app->insult_display));
insults_app->saved_menu = submenu_alloc();
view_dispatcher_add_view(
insults_app->view_dispatcher, InsultsViewSaved, submenu_get_view(insults_app->saved_menu));
insults_app->saved_detail = dialog_ex_alloc();
dialog_ex_set_context(insults_app->saved_detail, insults_app);
dialog_ex_set_result_callback(
insults_app->saved_detail, insults_scene_saved_detail_dialog_callback);
dialog_ex_set_left_button_text(insults_app->saved_detail, "Delete");
view_dispatcher_add_view(
insults_app->view_dispatcher,
InsultsViewSavedDetail,
dialog_ex_get_view(insults_app->saved_detail));
insults_app->saved_empty = dialog_ex_alloc();
dialog_ex_set_text(insults_app->saved_empty, "<empty>", 64, 32, AlignCenter, AlignCenter);
view_dispatcher_add_view(
insults_app->view_dispatcher,
InsultsViewSavedEmpty,
dialog_ex_get_view(insults_app->saved_empty));
view_dispatcher_attach_to_gui(
insults_app->view_dispatcher, insults_app->gui, ViewDispatcherTypeFullscreen);
return insults_app;
}
void insults_app_free(InsultsApp* insults_app) {
view_dispatcher_remove_view(insults_app->view_dispatcher, InsultsViewSavedEmpty);
dialog_ex_free(insults_app->saved_empty);
view_dispatcher_remove_view(insults_app->view_dispatcher, InsultsViewSavedDetail);
dialog_ex_free(insults_app->saved_detail);
view_dispatcher_remove_view(insults_app->view_dispatcher, InsultsViewSaved);
submenu_free(insults_app->saved_menu);
view_dispatcher_remove_view(insults_app->view_dispatcher, InsultsViewInsult);
dialog_ex_free(insults_app->insult_display);
view_dispatcher_remove_view(insults_app->view_dispatcher, InsultsViewStart);
submenu_free(insults_app->start_menu);
insults_files_free(insults_app->insults_files);
view_dispatcher_free(insults_app->view_dispatcher);
scene_manager_free(insults_app->scene_manager);
furi_record_close(RECORD_GUI);
insults_app->gui = NULL;
free(insults_app);
}
bool insults_navigation_event_callback(void* context) {
InsultsApp* insults_app = (InsultsApp*)context;
return scene_manager_handle_back_event(insults_app->scene_manager);
}
bool insults_custom_event_callback(void* context, uint32_t event) {
InsultsApp* insults_app = (InsultsApp*)context;
return scene_manager_handle_custom_event(insults_app->scene_manager, event);
}