uhf_scene_delete.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../uhf_app_i.h"
  2. void uhf_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
  3. UHFApp* uhf_app = context;
  4. if(type == InputTypeShort) {
  5. view_dispatcher_send_custom_event(uhf_app->view_dispatcher, result);
  6. }
  7. }
  8. void uhf_scene_delete_on_enter(void* context) {
  9. UHFApp* uhf_app = context;
  10. // Setup Custom Widget view
  11. char temp_str[64];
  12. snprintf(temp_str, sizeof(temp_str), "\e#Delete %s?\e#", uhf_app->uhf_device->dev_name);
  13. widget_add_text_box_element(
  14. uhf_app->widget, 0, 0, 128, 23, AlignCenter, AlignCenter, temp_str, false);
  15. widget_add_button_element(
  16. uhf_app->widget, GuiButtonTypeLeft, "Back", uhf_scene_delete_widget_callback, uhf_app);
  17. widget_add_button_element(
  18. uhf_app->widget, GuiButtonTypeRight, "Delete", uhf_scene_delete_widget_callback, uhf_app);
  19. view_dispatcher_switch_to_view(uhf_app->view_dispatcher, UHFViewWidget);
  20. }
  21. bool uhf_scene_delete_on_event(void* context, SceneManagerEvent event) {
  22. UHFApp* uhf_app = context;
  23. bool consumed = false;
  24. if(event.type == SceneManagerEventTypeCustom) {
  25. if(event.event == GuiButtonTypeLeft) {
  26. return scene_manager_previous_scene(uhf_app->scene_manager);
  27. } else if(event.event == GuiButtonTypeRight) {
  28. if(uhf_device_delete(uhf_app->uhf_device, true)) {
  29. scene_manager_next_scene(uhf_app->scene_manager, UHFSceneDeleteSuccess);
  30. } else {
  31. scene_manager_search_and_switch_to_previous_scene(
  32. uhf_app->scene_manager, UHFSceneStart);
  33. }
  34. consumed = true;
  35. }
  36. }
  37. return consumed;
  38. }
  39. void uhf_scene_delete_on_exit(void* context) {
  40. UHFApp* uhf_app = context;
  41. widget_reset(uhf_app->widget);
  42. }