FlippyPass/project/ui/scenes/view.c

93 lines
No EOL
2.3 KiB
C

// Header
#include "view.h"
// Structures
typedef enum {
FP_Scene_View_Event_Username,
FP_Scene_View_Event_Password,
FP_Scene_View_Event_BadUSB
} FP_Scene_View_Event;
// Functions
void FP_Scene_Callback_View(void* context, uint32_t index) {
// Setting context
FP_App* app = context;
// Sending it to the scene manager
scene_manager_handle_custom_event(app->scene_manager, index);
}
void FP_Scene_Enter_View(void* context) {
// Setting context
FP_App* app = context;
// Freeing Dialog
submenu_reset(app->submenu);
// Adding some content
submenu_add_item(
app->submenu,
"View Username",
FP_Scene_View_Event_Username,
FP_Scene_Callback_View,
app
);
submenu_add_item(
app->submenu,
"View Password",
FP_Scene_View_Event_Password,
FP_Scene_Callback_View,
app
);
submenu_add_item(
app->submenu,
"BadUSB",
FP_Scene_View_Event_BadUSB,
FP_Scene_Callback_View,
app
);
// Sending view to Flipper
view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_Submenu);
}
void FP_Scene_Exit_View(void* context) {
// Setting context
FP_App* app = context;
// Reset menu
submenu_reset(app->submenu);
}
bool FP_Scene_Event_View(void* context, SceneManagerEvent event) {
// Setting context
FP_App* app = context;
bool consumed = false;
// Switching based on event
if (event.type == SceneManagerEventTypeCustom) {
// We consumed it
consumed = true;
// What did we press?
switch (event.event) {
case FP_Scene_View_Event_Username:
app->temp = malloc(sizeof(char*));
app->temp = "Username";
scene_manager_next_scene(app->scene_manager, FP_Scene_Cred);
break;
case FP_Scene_View_Event_Password:
app->temp = malloc(sizeof(char*));
app->temp = "Password";
scene_manager_next_scene(app->scene_manager, FP_Scene_Cred);
break;
case FP_Scene_View_Event_BadUSB:
scene_manager_next_scene(app->scene_manager, FP_Scene_Send);
break;
default:
break;
}
} else {
consumed = false;
}
// Return result
return consumed;
}