From 5360e26581d344978e980210ad5b6265b14cb648 Mon Sep 17 00:00:00 2001 From: objnull Date: Fri, 13 Sep 2024 13:10:38 -0400 Subject: [PATCH] Added import scene --- project/ui/app.h | 1 + project/ui/scenes/archive.c | 13 ++++- project/ui/scenes/import.c | 112 ++++++++++++++++++++++++++++++++++++ project/ui/scenes/import.h | 14 +++++ project/ui/ui.c | 10 +++- 5 files changed, 145 insertions(+), 5 deletions(-) create mode 100644 project/ui/scenes/import.c create mode 100644 project/ui/scenes/import.h diff --git a/project/ui/app.h b/project/ui/app.h index ce45a2d..2bfbdb2 100644 --- a/project/ui/app.h +++ b/project/ui/app.h @@ -39,6 +39,7 @@ typedef enum { FP_Scene_Create, FP_Scene_Type, FP_Scene_Archive, + FP_Scene_Import, FP_Scene_About, FP_Scene_Count // Last Index, says how many scenes there are } FP_Scene; diff --git a/project/ui/scenes/archive.c b/project/ui/scenes/archive.c index 1b63377..6844610 100644 --- a/project/ui/scenes/archive.c +++ b/project/ui/scenes/archive.c @@ -58,8 +58,17 @@ bool FP_Scene_Event_Archive(void* context, SceneManagerEvent event){ // We consumed it consumed = true; - // Not using the app - UNUSED(app); + // What did we choose? + switch (event.event) { + case FP_Scene_Archive_Event_Import: + scene_manager_next_scene( + app->scene_manager, + FP_Scene_Import + ); + break; + case FP_Scene_Archive_Event_Export: + break; + } } else { consumed = false; } diff --git a/project/ui/scenes/import.c b/project/ui/scenes/import.c new file mode 100644 index 0000000..cc4cdc3 --- /dev/null +++ b/project/ui/scenes/import.c @@ -0,0 +1,112 @@ +// Header +#include "import.h" + +// Functions +void FP_Scene_Callback_Import(DialogExResult result, void* context){ + // Setting context + FP_App* app = context; + + // Sending it to the scene manager + scene_manager_handle_custom_event(app->scene_manager, result); +} +void FP_Scene_Enter_Import(void* context){ + // Setting context + FP_App* app = context; + + // Setting selection + app->selection = 0; + + // Resetting scene + dialog_ex_reset(app->dialog); + + // Setting dialog content + dialog_ex_set_header( + app->dialog, + "Import Archive", + 0, 0, + AlignLeft, AlignTop + ); + dialog_ex_set_text( + app->dialog, + "Are you sure you want to import: /ext/apps_data/fpass/archive.txt?", + 5, 15, + AlignLeft, AlignTop + ); + dialog_ex_set_center_button_text( + app->dialog, + "Yes" + ); + dialog_ex_set_left_button_text( + app->dialog, + "No" + ); + + // Setting callback + dialog_ex_set_result_callback( + app->dialog, + FP_Scene_Callback_Import + ); + dialog_ex_set_context( + app->dialog, + app + ); + + // Sending view to Flipper + view_dispatcher_switch_to_view(app->view_dispatcher, FP_View_Dialog); +} +void FP_Scene_Exit_Import(void* context){ + // Setting context + FP_App* app = context; + + // Reset menu + submenu_reset(app->submenu); +} +bool FP_Scene_Event_Import(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; + + // Are we already good? + if (app->selection >= 1) { + scene_manager_previous_scene( + app->scene_manager + ); + } + + // What should we do? + switch (event.event) { + case DialogExResultCenter: // Yes + // Telling the user it worked! + dialog_ex_set_text( + app->dialog, + "Imported Successfully.", + 5, 15, + AlignLeft, AlignTop + ); + dialog_ex_set_center_button_text( + app->dialog, + "Okay" + ); + dialog_ex_set_left_button_text( + app->dialog, + NULL + ); + app->selection++; + + break; + case DialogExResultLeft: // No + scene_manager_previous_scene(app->scene_manager); + break; + } + } else { + consumed = false; + } + + // Return result + return consumed; +} \ No newline at end of file diff --git a/project/ui/scenes/import.h b/project/ui/scenes/import.h new file mode 100644 index 0000000..e1c5975 --- /dev/null +++ b/project/ui/scenes/import.h @@ -0,0 +1,14 @@ +// Define once +#ifndef H_S_IMPORT +#define H_S_IMPORT + +// Libraries +#include "../app.h" + +// Functions +void FP_Scene_Callback_Import(DialogExResult result, void* context); +void FP_Scene_Enter_Import(void* context); +void FP_Scene_Exit_Import(void* context); +bool FP_Scene_Event_Import(void* context, SceneManagerEvent event); + +#endif \ No newline at end of file diff --git a/project/ui/ui.c b/project/ui/ui.c index d34a148..e9a6838 100644 --- a/project/ui/ui.c +++ b/project/ui/ui.c @@ -11,6 +11,7 @@ #include "scenes/create.h" #include "scenes/type.h" #include "scenes/archive.h" +#include "scenes/import.h" // Handlers void (*const FP_Scene_Enter_Handlers[])(void*) = { @@ -22,7 +23,8 @@ void (*const FP_Scene_Enter_Handlers[])(void*) = { FP_Scene_Enter_Send, FP_Scene_Enter_Create, FP_Scene_Enter_Type, - FP_Scene_Enter_Archive + FP_Scene_Enter_Archive, + FP_Scene_Enter_Import }; bool (*const FP_Scene_Event_Handlers[])(void*, SceneManagerEvent) = { FP_Scene_Event_Auth, @@ -33,7 +35,8 @@ bool (*const FP_Scene_Event_Handlers[])(void*, SceneManagerEvent) = { FP_Scene_Event_Send, FP_Scene_Event_Create, FP_Scene_Event_Type, - FP_Scene_Event_Archive + FP_Scene_Event_Archive, + FP_Scene_Event_Import }; void (*const FP_Scene_Exit_Handlers[])(void*) = { FP_Scene_Exit_Auth, @@ -44,7 +47,8 @@ void (*const FP_Scene_Exit_Handlers[])(void*) = { FP_Scene_Exit_Send, FP_Scene_Exit_Create, FP_Scene_Exit_Type, - FP_Scene_Exit_Archive + FP_Scene_Exit_Archive, + FP_Scene_Exit_Import }; // Main Handler