Able to load password into a dialog

This commit is contained in:
Maddox Werts 2024-09-05 17:53:44 -04:00
parent 5d12c26850
commit f03e37ab31
2 changed files with 73 additions and 7 deletions

View file

@ -14,7 +14,7 @@ typedef enum {
} FP_Scene;
/* Types of Views */
typedef enum { FP_View_Submenu, FP_View_Popup } FP_View;
typedef enum { FP_View_Submenu, FP_View_Dialog, FP_View_Popup } FP_View;
/* All events */
typedef enum {
@ -55,6 +55,13 @@ void FP_Scene_Callback_Overview(void* context, uint32_t index) {
// Sending it to the scene manager
scene_manager_handle_custom_event(app->scene_manager, index);
}
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_MainMenu(void* context) {
// Setting context
@ -108,7 +115,7 @@ void FP_Scene_Enter_Overview(void* context) {
submenu_add_item(
app->submenu,
app->manager->names[i],
0,
i,
FP_Scene_Callback_Overview,
app
);
@ -117,6 +124,26 @@ void FP_Scene_Enter_Overview(void* context) {
// Sending view to Flipper
view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_Submenu);
}
void FP_Scene_Enter_View(void* context) {
// Setting context
FP_App* app = context;
Password* current = app->manager->current;
// Freeing Dialog
dialog_ex_reset(app->dialog);
// Adding some content
dialog_ex_set_header(
app->dialog,
current->name,
0, 0,
AlignLeft,
AlignTop
);
// Sending view to Flipper
view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_Dialog);
}
void FP_Scene_Exit_MainMenu(void* context) {
// Setting context
@ -132,6 +159,13 @@ void FP_Scene_Exit_Overview(void* context) {
// Reset menu
submenu_reset(app->submenu);
}
void FP_Scene_Exit_View(void* context) {
// Setting context
FP_App* app = context;
// Reset menu
dialog_ex_reset(app->dialog);
}
bool FP_Scene_Event_MainMenu(void* context, SceneManagerEvent event) {
// Setting context
@ -171,8 +205,14 @@ bool FP_Scene_Event_Overview(void* context, SceneManagerEvent event) {
// We consumed it
consumed = true;
// DEBUG
FURI_LOG_D(TAG, "Opening password %li", event.event);
// Loading password
manager_loadpass(app->manager, app->manager->names[event.event]);
// Is the current password a fake?
if (!app->manager->current) {
FURI_LOG_E(TAG, "Password is NULL!");
furi_crash();
}
// Switch to password view screen
scene_manager_next_scene(app->scene_manager, FP_Scene_View);
@ -183,19 +223,41 @@ bool FP_Scene_Event_Overview(void* context, SceneManagerEvent event) {
// Return result
return consumed;
}
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;
// Switching based on event
UNUSED(app);
} else {
consumed = false;
}
// Return result
return consumed;
}
/* Handlers */
void (*const FP_Scene_Enter_Handlers[])(void*) = {
FP_Scene_Enter_MainMenu,
FP_Scene_Enter_Overview
FP_Scene_Enter_Overview,
FP_Scene_Enter_View
};
bool (*const FP_Scene_Event_Handlers[])(void*, SceneManagerEvent) = {
FP_Scene_Event_MainMenu,
FP_Scene_Event_Overview
FP_Scene_Event_Overview,
FP_Scene_Event_View
};
void (*const FP_Scene_Exit_Handlers[])(void*) = {
FP_Scene_Exit_MainMenu,
FP_Scene_Exit_Overview
FP_Scene_Exit_Overview,
FP_Scene_Exit_View
};
/* Event Handlers */
@ -243,6 +305,7 @@ FP_App* fp_app_init() {
view_dispatcher_enable_queue(result->view_dispatcher);
// Allocating all types of views
result->dialog = dialog_ex_alloc();
result->submenu = submenu_alloc();
result->popup = popup_alloc();
@ -253,6 +316,7 @@ FP_App* fp_app_init() {
// Adding views to dispatcher
view_dispatcher_add_view(result->view_dispatcher, FP_View_Submenu, submenu_get_view(result->submenu));
view_dispatcher_add_view(result->view_dispatcher, FP_View_Dialog, dialog_ex_get_view(result->dialog));
view_dispatcher_add_view(result->view_dispatcher, FP_View_Popup, popup_get_view(result->popup));
// Return app

View file

@ -10,6 +10,7 @@
#include <gui/scene_manager.h>
#include <gui/view_dispatcher.h>
#include <gui/modules/dialog_ex.h>
#include <gui/modules/submenu.h>
#include <gui/modules/popup.h>
@ -20,6 +21,7 @@
typedef struct {
SceneManager* scene_manager;
ViewDispatcher* view_dispatcher;
DialogEx* dialog;
Submenu* submenu;
Popup* popup;