forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
93 additions
and
343 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,81 +1,53 @@ | ||
#include "totp_input_text.h" | ||
#include <gui/view_i.h> | ||
|
||
void view_draw(View* view, Canvas* canvas) { | ||
furi_assert(view); | ||
if(view->draw_callback) { | ||
void* data = view_get_model(view); | ||
view->draw_callback(canvas, data); | ||
view_unlock_model(view); | ||
} | ||
} | ||
#include <gui/view_dispatcher.h> | ||
#include <gui/view.h> | ||
#include <gui/modules/text_input.h> | ||
|
||
bool view_input(View* view, InputEvent* event) { | ||
furi_assert(view); | ||
if(view->input_callback) { | ||
return view->input_callback(event, view->context); | ||
} else { | ||
return false; | ||
} | ||
} | ||
typedef struct { | ||
InputTextResult* result; | ||
ViewDispatcher* view_dispatcher; | ||
} InputTextContext; | ||
|
||
void view_unlock_model(View* view) { | ||
furi_assert(view); | ||
if(view->model_type == ViewModelTypeLocking) { | ||
ViewModelLocking* model = (ViewModelLocking*)(view->model); | ||
furi_check(furi_mutex_release(model->mutex) == FuriStatusOk); | ||
} | ||
static void commit_text_input_callback(void* ctx) { | ||
InputTextContext* context = ctx; | ||
context->result->user_input_length = strnlen(context->result->user_input, INPUT_BUFFER_SIZE); | ||
context->result->success = true; | ||
view_dispatcher_stop(context->view_dispatcher); | ||
} | ||
|
||
static void commit_text_input_callback(void* context) { | ||
InputTextSceneState* text_input_state = (InputTextSceneState*)context; | ||
if(text_input_state->callback != NULL) { | ||
InputTextSceneCallbackResult* result = malloc(sizeof(InputTextSceneCallbackResult)); | ||
furi_check(result != NULL); | ||
result->user_input_length = | ||
strnlen(text_input_state->text_input_buffer, INPUT_BUFFER_SIZE); | ||
result->user_input = malloc(result->user_input_length + 1); | ||
furi_check(result->user_input != NULL); | ||
result->callback_data = text_input_state->callback_data; | ||
strlcpy( | ||
result->user_input, | ||
text_input_state->text_input_buffer, | ||
result->user_input_length + 1); | ||
text_input_state->callback(result); | ||
} | ||
static bool back_event_callback(void* ctx) { | ||
InputTextContext* context = ctx; | ||
context->result->success = false; | ||
view_dispatcher_stop(context->view_dispatcher); | ||
return false; | ||
} | ||
|
||
InputTextSceneState* totp_input_text_activate(InputTextSceneContext* context) { | ||
InputTextSceneState* text_input_state = malloc(sizeof(InputTextSceneState)); | ||
furi_check(text_input_state != NULL); | ||
text_input_state->text_input = text_input_alloc(); | ||
text_input_state->text_input_view = text_input_get_view(text_input_state->text_input); | ||
text_input_state->callback = context->callback; | ||
text_input_state->callback_data = context->callback_data; | ||
text_input_set_header_text(text_input_state->text_input, context->header_text); | ||
void totp_input_text(Gui* gui, const char* header_text, InputTextResult* result) { | ||
ViewDispatcher* view_dispatcher = view_dispatcher_alloc(); | ||
TextInput* text_input = text_input_alloc(); | ||
InputTextContext context = {.result = result, .view_dispatcher = view_dispatcher}; | ||
text_input_set_header_text(text_input, header_text); | ||
text_input_set_result_callback( | ||
text_input_state->text_input, | ||
text_input, | ||
commit_text_input_callback, | ||
text_input_state, | ||
&text_input_state->text_input_buffer[0], | ||
&context, | ||
result->user_input, | ||
INPUT_BUFFER_SIZE, | ||
true); | ||
return text_input_state; | ||
} | ||
|
||
void totp_input_text_render(Canvas* const canvas, InputTextSceneState* text_input_state) { | ||
view_draw(text_input_state->text_input_view, canvas); | ||
} | ||
view_dispatcher_enable_queue(view_dispatcher); | ||
view_dispatcher_add_view(view_dispatcher, 0, text_input_get_view(text_input)); | ||
|
||
bool totp_input_text_handle_event(PluginEvent* const event, InputTextSceneState* text_input_state) { | ||
if(event->type == EventTypeKey) { | ||
view_input(text_input_state->text_input_view, &event->input); | ||
} | ||
view_dispatcher_attach_to_gui(view_dispatcher, gui, ViewDispatcherTypeFullscreen); | ||
|
||
return true; | ||
} | ||
view_dispatcher_set_navigation_event_callback(view_dispatcher, &back_event_callback); | ||
view_dispatcher_set_event_callback_context(view_dispatcher, &context); | ||
view_dispatcher_switch_to_view(view_dispatcher, 0); | ||
|
||
view_dispatcher_run(view_dispatcher); | ||
|
||
void totp_input_text_free(InputTextSceneState* state) { | ||
text_input_free(state->text_input); | ||
free(state); | ||
view_dispatcher_remove_view(view_dispatcher, 0); | ||
view_dispatcher_free(view_dispatcher); | ||
text_input_free(text_input); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,13 @@ | ||
#pragma once | ||
|
||
#include <gui/gui.h> | ||
#include <gui/view.h> | ||
#include <gui/modules/text_input.h> | ||
#include "../../../types/plugin_state.h" | ||
#include "../../../types/plugin_event.h" | ||
|
||
#define INPUT_BUFFER_SIZE (255) | ||
|
||
typedef struct { | ||
char* user_input; | ||
char user_input[INPUT_BUFFER_SIZE]; | ||
size_t user_input_length; | ||
void* callback_data; | ||
} InputTextSceneCallbackResult; | ||
bool success; | ||
} InputTextResult; | ||
|
||
typedef void (*InputTextSceneCallback)(InputTextSceneCallbackResult* result); | ||
|
||
typedef struct { | ||
InputTextSceneCallback callback; | ||
char* header_text; | ||
void* callback_data; | ||
} InputTextSceneContext; | ||
|
||
typedef struct { | ||
TextInput* text_input; | ||
View* text_input_view; | ||
char text_input_buffer[INPUT_BUFFER_SIZE]; | ||
InputTextSceneCallback callback; | ||
void* callback_data; | ||
} InputTextSceneState; | ||
|
||
InputTextSceneState* totp_input_text_activate(InputTextSceneContext* context); | ||
void totp_input_text_render(Canvas* const canvas, InputTextSceneState* text_input_state); | ||
bool totp_input_text_handle_event(PluginEvent* const event, InputTextSceneState* text_input_state); | ||
void totp_input_text_free(InputTextSceneState* state); | ||
void totp_input_text(Gui* gui, const char* header_text, InputTextResult* result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters