scene_confirm.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "app_i.h"
  2. #include <furi.h>
  3. #include <toolbox/path.h>
  4. #include "custom_event.h"
  5. static void
  6. scene_confirm_button_callback(GuiButtonType button_type, InputType input_type, void* context) {
  7. furi_assert(context);
  8. App* app = context;
  9. if(input_type == InputTypeShort) {
  10. if(button_type == GuiButtonTypeLeft) {
  11. view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventFileRejected);
  12. } else if(button_type == GuiButtonTypeRight) {
  13. view_dispatcher_send_custom_event(app->view_dispatcher, CustomEventFileConfirmed);
  14. }
  15. }
  16. }
  17. void scene_confirm_on_enter(void* context) {
  18. App* app = context;
  19. FuriString* file_name = furi_string_alloc();
  20. path_extract_filename(app->file_path, file_name, false);
  21. FuriString* label = furi_string_alloc_printf("Install\n%s?", furi_string_get_cstr(file_name));
  22. widget_add_string_multiline_element(
  23. app->widget, 64, 0, AlignCenter, AlignTop, FontPrimary, furi_string_get_cstr(label));
  24. furi_string_free(label);
  25. furi_string_free(file_name);
  26. widget_add_button_element(
  27. app->widget, GuiButtonTypeLeft, "Cancel", scene_confirm_button_callback, app);
  28. widget_add_button_element(
  29. app->widget, GuiButtonTypeRight, "Install", scene_confirm_button_callback, app);
  30. view_dispatcher_switch_to_view(app->view_dispatcher, ViewIdWidget);
  31. }
  32. bool scene_confirm_on_event(void* context, SceneManagerEvent event) {
  33. App* app = context;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeCustom) {
  36. if(event.event == CustomEventFileConfirmed) {
  37. scene_manager_next_scene(app->scene_manager, SceneInstall);
  38. } else if(event.event == CustomEventFileRejected) {
  39. furi_string_reset(app->file_path);
  40. scene_manager_previous_scene(app->scene_manager);
  41. }
  42. consumed = true;
  43. } else if(event.type == SceneManagerEventTypeBack) {
  44. consumed = true;
  45. }
  46. return consumed;
  47. }
  48. void scene_confirm_on_exit(void* context) {
  49. App* app = context;
  50. widget_reset(app->widget);
  51. }