Skip to content

Commit

Permalink
[FL-3458] Add confirmation before exiting USB-UART (#3043)
Browse files Browse the repository at this point in the history
* Add confirmation before exiting USB-UART
* Redo the confirm view to be a scene to ignore the back button

Co-authored-by: hedger <[email protected]>
Co-authored-by: あく <[email protected]>
  • Loading branch information
3 people authored Sep 21, 2023
1 parent f46018b commit 182c8de
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
7 changes: 7 additions & 0 deletions applications/main/gpio/gpio_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ GpioApp* gpio_app_alloc() {

app->notifications = furi_record_open(RECORD_NOTIFICATION);

// Dialog view
app->dialog = dialog_ex_alloc();
view_dispatcher_add_view(
app->view_dispatcher, GpioAppViewExitConfirm, dialog_ex_get_view(app->dialog));

app->var_item_list = variable_item_list_alloc();
view_dispatcher_add_view(
app->view_dispatcher,
Expand Down Expand Up @@ -79,10 +84,12 @@ void gpio_app_free(GpioApp* app) {
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUart);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCfg);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewUsbUartCloseRpc);
view_dispatcher_remove_view(app->view_dispatcher, GpioAppViewExitConfirm);
variable_item_list_free(app->var_item_list);
widget_free(app->widget);
gpio_test_free(app->gpio_test);
gpio_usb_uart_free(app->gpio_usb_uart);
dialog_ex_free(app->dialog);

// View dispatcher
view_dispatcher_free(app->view_dispatcher);
Expand Down
3 changes: 3 additions & 0 deletions applications/main/gpio/gpio_app_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <notification/notification_messages.h>
#include <gui/modules/variable_item_list.h>
#include <gui/modules/widget.h>
#include <gui/modules/dialog_ex.h>
#include "views/gpio_test.h"
#include "views/gpio_usb_uart.h"
#include <assets_icons.h>
Expand All @@ -23,6 +24,7 @@ struct GpioApp {
ViewDispatcher* view_dispatcher;
SceneManager* scene_manager;
Widget* widget;
DialogEx* dialog;

VariableItemList* var_item_list;
VariableItem* var_item_flow;
Expand All @@ -39,4 +41,5 @@ typedef enum {
GpioAppViewUsbUart,
GpioAppViewUsbUartCfg,
GpioAppViewUsbUartCloseRpc,
GpioAppViewExitConfirm,
} GpioAppView;
1 change: 1 addition & 0 deletions applications/main/gpio/scenes/gpio_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ ADD_SCENE(gpio, test, Test)
ADD_SCENE(gpio, usb_uart, UsbUart)
ADD_SCENE(gpio, usb_uart_cfg, UsbUartCfg)
ADD_SCENE(gpio, usb_uart_close_rpc, UsbUartCloseRpc)
ADD_SCENE(gpio, exit_confirm, ExitConfirm)
44 changes: 44 additions & 0 deletions applications/main/gpio/scenes/gpio_scene_exit_confirm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "gpio_app_i.h"

void gpio_scene_exit_confirm_dialog_callback(DialogExResult result, void* context) {
GpioApp* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, result);
}

void gpio_scene_exit_confirm_on_enter(void* context) {
GpioApp* app = context;
DialogEx* dialog = app->dialog;

dialog_ex_set_context(dialog, app);
dialog_ex_set_left_button_text(dialog, "Exit");
dialog_ex_set_right_button_text(dialog, "Stay");
dialog_ex_set_header(dialog, "Exit USB-UART?", 22, 12, AlignLeft, AlignTop);
dialog_ex_set_result_callback(dialog, gpio_scene_exit_confirm_dialog_callback);

view_dispatcher_switch_to_view(app->view_dispatcher, GpioAppViewExitConfirm);
}

bool gpio_scene_exit_confirm_on_event(void* context, SceneManagerEvent event) {
GpioApp* app = context;
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
if(event.event == DialogExResultRight) {
consumed = scene_manager_previous_scene(app->scene_manager);
} else if(event.event == DialogExResultLeft) {
scene_manager_search_and_switch_to_previous_scene(app->scene_manager, GpioSceneStart);
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = true;
}

return consumed;
}

void gpio_scene_exit_confirm_on_exit(void* context) {
GpioApp* app = context;

// Clean view
dialog_ex_reset(app->dialog);
}
3 changes: 3 additions & 0 deletions applications/main/gpio/scenes/gpio_scene_usb_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ bool gpio_scene_usb_uart_on_event(void* context, SceneManagerEvent event) {
scene_manager_set_scene_state(app->scene_manager, GpioSceneUsbUart, 1);
scene_manager_next_scene(app->scene_manager, GpioSceneUsbUartCfg);
return true;
} else if(event.type == SceneManagerEventTypeBack) {
scene_manager_next_scene(app->scene_manager, GpioSceneExitConfirm);
return true;
} else if(event.type == SceneManagerEventTypeTick) {
uint32_t tx_cnt_last = scene_usb_uart->state.tx_cnt;
uint32_t rx_cnt_last = scene_usb_uart->state.rx_cnt;
Expand Down

0 comments on commit 182c8de

Please sign in to comment.